diff options
| author | Eric Christopher <echristo@gmail.com> | 2019-11-18 10:45:23 -0800 |
|---|---|---|
| committer | Eric Christopher <echristo@gmail.com> | 2019-11-18 10:46:48 -0800 |
| commit | 30e7ee3c4bac4a12ea584a879aa320bd4e035cc2 (patch) | |
| tree | 3c93193eeac41921667a7e2e05fd207cf19670dd /clang/lib | |
| parent | a77b66a05625ea4271c2d76f65428cce02e4699e (diff) | |
| download | bcm5719-llvm-30e7ee3c4bac4a12ea584a879aa320bd4e035cc2.tar.gz bcm5719-llvm-30e7ee3c4bac4a12ea584a879aa320bd4e035cc2.zip | |
Temporarily Revert "Add support for options -frounding-math, ftrapping-math, -ffp-model=, and -ffp-exception-behavior="
and a follow-up NFC rearrangement as it's causing a crash on valid. Testcase is on the original review thread.
This reverts commits af57dbf12e54f3a8ff48534bf1078f4de104c1cd and e6584b2b7b2de06f1e59aac41971760cac1e1b79
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 48 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 3 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 203 | ||||
| -rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 30 |
4 files changed, 9 insertions, 275 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index b853401ebdc..6f2bd8c16b3 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -33,8 +33,6 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Dominators.h" -#include "llvm/IR/FPEnv.h" -#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" #include "llvm/IR/Operator.h" @@ -89,7 +87,6 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext) FMF.setAllowReassoc(); } Builder.setFastMathFlags(FMF); - SetFPModel(); } CodeGenFunction::~CodeGenFunction() { @@ -105,51 +102,6 @@ CodeGenFunction::~CodeGenFunction() { CGM.getOpenMPRuntime().functionFinished(*this); } -// Map the LangOption for rounding mode into -// the corresponding enum in the IR. -static llvm::fp::RoundingMode ToConstrainedRoundingMD( - LangOptions::FPRoundingModeKind Kind) { - - switch (Kind) { - case LangOptions::FPR_ToNearest: return llvm::fp::rmToNearest; - case LangOptions::FPR_Downward: return llvm::fp::rmDownward; - case LangOptions::FPR_Upward: return llvm::fp::rmUpward; - case LangOptions::FPR_TowardZero: return llvm::fp::rmTowardZero; - case LangOptions::FPR_Dynamic: return llvm::fp::rmDynamic; - } - llvm_unreachable("Unsupported FP RoundingMode"); -} - -// Map the LangOption for exception behavior into -// the corresponding enum in the IR. -static llvm::fp::ExceptionBehavior ToConstrainedExceptMD( - LangOptions::FPExceptionModeKind Kind) { - - switch (Kind) { - case LangOptions::FPE_Ignore: return llvm::fp::ebIgnore; - case LangOptions::FPE_MayTrap: return llvm::fp::ebMayTrap; - case LangOptions::FPE_Strict: return llvm::fp::ebStrict; - } - llvm_unreachable("Unsupported FP Exception Behavior"); -} - -void CodeGenFunction::SetFPModel() { - auto fpRoundingMode = ToConstrainedRoundingMD( - getLangOpts().getFPRoundingMode()); - auto fpExceptionBehavior = ToConstrainedExceptMD( - getLangOpts().getFPExceptionMode()); - - if (fpExceptionBehavior == llvm::fp::ebIgnore && - fpRoundingMode == llvm::fp::rmToNearest) - // Constrained intrinsics are not used. - ; - else { - Builder.setIsFPConstrained(true); - Builder.setDefaultConstrainedRounding(fpRoundingMode); - Builder.setDefaultConstrainedExcept(fpExceptionBehavior); - } -} - CharUnits CodeGenFunction::getNaturalPointeeTypeAlignment(QualType T, LValueBaseInfo *BaseInfo, TBAAAccessInfo *TBAAInfo) { diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index b05475a3000..5c3d1764fad 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -4156,9 +4156,6 @@ public: /// point operation, expressed as the maximum relative error in ulp. void SetFPAccuracy(llvm::Value *Val, float Accuracy); - /// SetFPModel - Control floating point behavior via fp-model settings. - void SetFPModel(); - private: llvm::MDNode *getRangeForLoadFromType(QualType Ty); void EmitReturnOfRValue(RValue RV, QualType Ty); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index f5591c48d4e..2e3624e6cd2 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2283,18 +2283,9 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, bool AssociativeMath = false; bool ReciprocalMath = false; bool SignedZeros = true; - bool TrappingMath = false; // Implemented via -ffp-exception-behavior - bool TrappingMathPresent = false; // Is trapping-math in args, and not - // overriden by ffp-exception-behavior? - bool RoundingFPMath = false; - bool RoundingMathPresent = false; // Is rounding-math in args? - // -ffp-model values: strict, fast, precise - StringRef FPModel = ""; - // -ffp-exception-behavior options: strict, maytrap, ignore - StringRef FPExceptionBehavior = ""; + bool TrappingMath = true; StringRef DenormalFPMath = ""; StringRef FPContract = ""; - bool StrictFPModel = false; if (const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { CmdArgs.push_back("-mlimit-float-precision"); @@ -2302,82 +2293,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, } for (const Arg *A : Args) { - auto optID = A->getOption().getID(); - bool PreciseFPModel = false; - switch (optID) { - default: - break; - case options::OPT_ffp_model_EQ: { - StringRef Val = A->getValue(); - if (OFastEnabled && !Val.equals("fast")) { - // Only -ffp-model=fast is compatible with OFast, ignore. - D.Diag(clang::diag::warn_drv_overriding_flag_option) - << Args.MakeArgString("-ffp-model=" + Val) - << "-Ofast"; - break; - } - StrictFPModel = false; - PreciseFPModel = true; - // ffp-model= is a Driver option, it is entirely rewritten into more - // granular options before being passed into cc1. - // Use the gcc option in the switch below. - if (!FPModel.empty() && !FPModel.equals(Val)) { - D.Diag(clang::diag::warn_drv_overriding_flag_option) - << Args.MakeArgString("-ffp-model=" + FPModel) - << Args.MakeArgString("-ffp-model=" + Val); - FPContract = ""; - } - if (Val.equals("fast")) { - if (!FPContract.empty() && !FPContract.equals("fast")) - // FPContract has already been set to something else - // so warn about the override. - D.Diag(clang::diag::warn_drv_overriding_flag_option) - << Args.MakeArgString("-ffp-contract=" + FPContract) - << "-ffp-contract=fast"; - optID = options::OPT_ffast_math; - FPModel = Val; - FPContract = "fast"; - } else if (Val.equals("precise")) { - if (!FPContract.empty() && !FPContract.equals("fast")) - D.Diag(clang::diag::warn_drv_overriding_flag_option) - << Args.MakeArgString("-ffp-contract=" + FPContract) - << "-ffp-contract=fast"; - optID = options::OPT_ffp_contract; - FPModel = Val; - FPContract = "fast"; - PreciseFPModel = true; - } else if (Val.equals("strict")) { - StrictFPModel = true; - if (!FPContract.empty() && !FPContract.equals("strict")) - D.Diag(clang::diag::warn_drv_overriding_flag_option) - << Args.MakeArgString("-ffp-contract=" + FPContract) - << "-ffp-contract=strict"; - optID = options::OPT_frounding_math; - FPExceptionBehavior = "strict"; - FPModel = Val; - // -ffp-model=strict also enables fno-fast-math - HonorINFs = true; - HonorNaNs = true; - // Turning on -ffast-math (with either flag) removes the need for - // MathErrno. However, turning *off* -ffast-math merely restores the - // toolchain default (which may be false). - MathErrno = TC.IsMathErrnoDefault(); - AssociativeMath = false; - ReciprocalMath = false; - SignedZeros = true; - TrappingMath = true; - RoundingFPMath = true; - // -fno_fast_math restores default denormal and fpcontract handling - DenormalFPMath = ""; - FPContract = ""; - } else - D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; - break; - } - } - - switch (optID) { + switch (A->getOption().getID()) { // If this isn't an FP option skip the claim below default: continue; @@ -2394,72 +2310,20 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, case options::OPT_fno_reciprocal_math: ReciprocalMath = false; break; case options::OPT_fsigned_zeros: SignedZeros = true; break; case options::OPT_fno_signed_zeros: SignedZeros = false; break; - case options::OPT_ftrapping_math: - TrappingMath = true; - TrappingMathPresent = true; - FPExceptionBehavior = "strict"; - break; - case options::OPT_fno_trapping_math: - TrappingMath = false; - TrappingMathPresent = true; - FPExceptionBehavior = "ignore"; - break; - case options::OPT_frounding_math: - // The default setting for frounding-math is True and ffast-math - // sets fno-rounding-math, but we only want to use constrained - // floating point intrinsics if the option is specifically requested. - RoundingFPMath = true; - RoundingMathPresent = true; - break; - case options::OPT_fno_rounding_math: - RoundingFPMath = false; - RoundingMathPresent = false; - break; + case options::OPT_ftrapping_math: TrappingMath = true; break; + case options::OPT_fno_trapping_math: TrappingMath = false; break; case options::OPT_fdenormal_fp_math_EQ: DenormalFPMath = A->getValue(); break; - // Validate and pass through -ffp-contract option. + // Validate and pass through -fp-contract option. case options::OPT_ffp_contract: { StringRef Val = A->getValue(); - if (PreciseFPModel) { - // -ffp-model=precise enables ffp-contract=fast as a side effect - // the FPContract value has already been set to a string literal - // and the Val string isn't a pertinent value. - ; - } else if (Val.equals("fast") || Val.equals("on") || Val.equals("off")) + if (Val == "fast" || Val == "on" || Val == "off") FPContract = Val; else D.Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; - break; - } - - // Validate and pass through -ffp-model option. - case options::OPT_ffp_model_EQ: - // This should only occur in the error case - // since the optID has been replaced by a more granular - // floating point option. - break; - - // Validate and pass through -ffp-exception-behavior option. - case options::OPT_ffp_exception_behavior_EQ: { - StringRef Val = A->getValue(); - if (!TrappingMathPresent && !FPExceptionBehavior.empty() && - !FPExceptionBehavior.equals(Val)) - // Warn that previous value of option is overridden. - D.Diag(clang::diag::warn_drv_overriding_flag_option) - << Args.MakeArgString("-ffp-exception-behavior=" + FPExceptionBehavior) - << Args.MakeArgString("-ffp-exception-behavior=" + Val); - TrappingMathPresent = false; - if (Val.equals("ignore") || Val.equals("maytrap")) - FPExceptionBehavior = Val; - else if (Val.equals("strict")) { - FPExceptionBehavior = Val; - TrappingMath = TrappingMathPresent = true; - } else - D.Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName() << Val; break; } @@ -2478,14 +2342,12 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, ReciprocalMath = true; SignedZeros = false; TrappingMath = false; - FPExceptionBehavior = ""; break; case options::OPT_fno_unsafe_math_optimizations: AssociativeMath = false; ReciprocalMath = false; SignedZeros = true; TrappingMath = true; - FPExceptionBehavior = "strict"; // -fno_unsafe_math_optimizations restores default denormal handling DenormalFPMath = ""; break; @@ -2503,7 +2365,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, ReciprocalMath = true; SignedZeros = false; TrappingMath = false; - RoundingFPMath = false; // If fast-math is set then set the fp-contract mode to fast. FPContract = "fast"; break; @@ -2517,31 +2378,12 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, AssociativeMath = false; ReciprocalMath = false; SignedZeros = true; - TrappingMath = false; - RoundingFPMath = false; + TrappingMath = true; // -fno_fast_math restores default denormal and fpcontract handling DenormalFPMath = ""; FPContract = ""; break; } - if (StrictFPModel) { - // If -ffp-model=strict has been specified on command line but - // subsequent options conflict then emit warning diagnostic. - if (HonorINFs && HonorNaNs && - !AssociativeMath && !ReciprocalMath && - SignedZeros && TrappingMath && RoundingFPMath && - DenormalFPMath.empty() && FPContract.empty()) - // OK: Current Arg doesn't conflict with -ffp-model=strict - ; - else { - StrictFPModel = false; - FPModel = ""; - D.Diag(clang::diag::warn_drv_overriding_flag_option) - << "-ffp-model=strict" << - ((A->getNumValues() == 0) ? A->getSpelling() - : Args.MakeArgString(A->getSpelling() + A->getValue())); - } - } // If we handled this option claim it A->claim(); @@ -2569,11 +2411,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, if (ReciprocalMath) CmdArgs.push_back("-freciprocal-math"); - if (TrappingMath) { - // FP Exception Behavior is also set to strict - assert(FPExceptionBehavior.equals("strict")); - CmdArgs.push_back("-ftrapping-math"); - } else if (TrappingMathPresent) + if (!TrappingMath) CmdArgs.push_back("-fno-trapping-math"); if (!DenormalFPMath.empty()) @@ -2583,37 +2421,14 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, if (!FPContract.empty()) CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + FPContract)); - if (!RoundingFPMath) - CmdArgs.push_back(Args.MakeArgString("-fno-rounding-math")); - - if (RoundingFPMath && RoundingMathPresent) - CmdArgs.push_back(Args.MakeArgString("-frounding-math")); - - if (!FPExceptionBehavior.empty()) - CmdArgs.push_back(Args.MakeArgString("-ffp-exception-behavior=" + - FPExceptionBehavior)); - ParseMRecip(D, Args, CmdArgs); // -ffast-math enables the __FAST_MATH__ preprocessor macro, but check for the // individual features enabled by -ffast-math instead of the option itself as // that's consistent with gcc's behaviour. if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && - ReciprocalMath && !SignedZeros && !TrappingMath && !RoundingFPMath) { + ReciprocalMath && !SignedZeros && !TrappingMath) CmdArgs.push_back("-ffast-math"); - if (FPModel.equals("fast")) { - if (FPContract.equals("fast")) - // All set, do nothing. - ; - else if (FPContract.empty()) - // Enable -ffp-contract=fast - CmdArgs.push_back(Args.MakeArgString("-ffp-contract=fast")); - else - D.Diag(clang::diag::warn_drv_overriding_flag_option) - << "-ffp-model=fast" - << Args.MakeArgString("-ffp-contract=" + FPContract); - } - } // Handle __FINITE_MATH_ONLY__ similarly. if (!HonorINFs && !HonorNaNs) diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 26221a89818..79975722a47 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3148,36 +3148,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; } - if (Args.hasArg(OPT_frounding_math)) { - Opts.setFPRoundingMode(LangOptions::FPR_Dynamic); - } - - if (Args.hasArg(OPT_fno_rounding_math)) { - Opts.setFPRoundingMode(LangOptions::FPR_ToNearest); - } - - if (Args.hasArg(OPT_ftrapping_math)) { - Opts.setFPExceptionMode(LangOptions::FPE_Strict); - } - - if (Args.hasArg(OPT_fno_trapping_math)) { - Opts.setFPExceptionMode(LangOptions::FPE_Ignore); - } - - LangOptions::FPExceptionModeKind FPEB = LangOptions::FPE_Ignore; - if (Arg *A = Args.getLastArg(OPT_ffp_exception_behavior_EQ)) { - StringRef Val = A->getValue(); - if (Val.equals("ignore")) - FPEB = LangOptions::FPE_Ignore; - else if (Val.equals("maytrap")) - FPEB = LangOptions::FPE_MayTrap; - else if (Val.equals("strict")) - FPEB = LangOptions::FPE_Strict; - else - Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; - Opts.setFPExceptionMode(FPEB); - } - Opts.RetainCommentsFromSystemHeaders = Args.hasArg(OPT_fretain_comments_from_system_headers); |

