diff options
author | Lang Hames <lhames@gmail.com> | 2012-07-06 00:59:19 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2012-07-06 00:59:19 +0000 |
commit | c9686716d2ceb5518178dca98670ec34c472a1be (patch) | |
tree | b4201afe672b4090ac1699d9190a28341428fa59 /lib | |
parent | 36cbfbfce889642057bd007eac3569ea9f58e1e8 (diff) |
Add -ffp-contract = { fast | on | off } command line option support.
This flag sets the 'fp-contract' mode, which controls the formation of fused
floating point operations. Available modes are:
- Fast: Form fused operations anywhere.
- On: Form fused operations where allowed by FP_CONTRACT. This is the default
mode.
- Off: Don't form fused operations (in future this may be relaxed to forming
fused operations where it can be proved that the result won't be
affected).
Currently clang doesn't support the FP_CONTRACT pragma, so the 'On' and 'Off'
modes are equivalent.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159794 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/BackendUtil.cpp | 13 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 18 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 17 |
3 files changed, 48 insertions, 0 deletions
diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 5a97875ef4..0a1915b485 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -351,6 +351,19 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action, Options.FloatABIType = llvm::FloatABI::Default; } + // Set FP fusion mode. + switch (LangOpts.getFPContractMode()) { + case LangOptions::FPC_Off: + Options.AllowFPOpFusion = llvm::FPOpFusion::Strict; + break; + case LangOptions::FPC_On: + Options.AllowFPOpFusion = llvm::FPOpFusion::Standard; + break; + case LangOptions::FPC_Fast: + Options.AllowFPOpFusion = llvm::FPOpFusion::Fast; + break; + } + Options.LessPreciseFPMADOption = CodeGenOpts.LessPreciseFPMAD; Options.NoInfsFPMath = CodeGenOpts.NoInfsFPMath; Options.NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 98beb2234a..dd198a1e9d 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1805,6 +1805,24 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, !TrappingMath) CmdArgs.push_back("-menable-unsafe-fp-math"); + + // Validate and pass through -fp-contract option. + if (Arg *A = Args.getLastArg(options::OPT_ffast_math, + options::OPT_ffp_contract)) { + if (A->getOption().getID() == options::OPT_ffp_contract) { + StringRef Val = A->getValue(Args); + if (Val == "fast" || Val == "on" || Val == "off") { + CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + Val)); + } else { + D.Diag(diag::err_drv_unsupported_option_argument) + << A->getOption().getName() << Val; + } + } else { // A is OPT_ffast_math + // If fast-math is set then set the fp-contract mode to fast. + CmdArgs.push_back(Args.MakeArgString("-ffp-contract=fast")); + } + } + // We separately look for the '-ffast-math' flag, and if we find it, tell the // frontend to provide the appropriate preprocessor macros. This is distinct // from enabling any optimizations as it induces a language change which must diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 943cb20e2d..cf08913e3b 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -759,6 +759,11 @@ static void LangOptsToArgs(const LangOptions &Opts, ToArgsList &Res) { Res.push_back("-ftrapv-handler", Opts.OverflowHandler); break; } + switch (Opts.getFPContractMode()) { + case LangOptions::FPC_Off: Res.push_back("-ffp-contract=off"); break; + case LangOptions::FPC_On: Res.push_back("-ffp-contract=on"); break; + case LangOptions::FPC_Fast: Res.push_back("-ffp-contract=fast"); break; + } if (Opts.HeinousExtensions) Res.push_back("-fheinous-gnu-extensions"); // Optimize is implicit. @@ -1975,6 +1980,18 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Diags.Report(diag::err_drv_invalid_value) << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis; + if (Arg *A = Args.getLastArg(OPT_ffp_contract)) { + StringRef Val = A->getValue(Args); + if (Val == "fast") + Opts.setFPContractMode(LangOptions::FPC_Fast); + else if (Val == "on") + Opts.setFPContractMode(LangOptions::FPC_On); + else if (Val == "off") + Opts.setFPContractMode(LangOptions::FPC_Off); + else + Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; + } + if (Args.hasArg(OPT_fvisibility_inlines_hidden)) Opts.InlineVisibilityHidden = 1; |