https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/81173
This refactors the fast-math handling in the clang driver, moving the settings into a lambda that is shared by the -ffp-model=fast and -ffast-math code. Previously the -ffp-model=fast handler changed the local option variable and fell through to the -ffast-math handler. This refactoring is intended to prepare the way for decoupling the -ffp-model=fast settings from the -ffast-math settings and possibly introduce a less aggressive fp-model. >From 21299e729ad71cdb1c2a2737508ffc2ee6b21d0f Mon Sep 17 00:00:00 2001 From: Andy Kaylor <andrew.kay...@intel.com> Date: Thu, 8 Feb 2024 10:44:22 -0800 Subject: [PATCH] [NFC] Refactor fast-math handling for clang driver This refactors the fast-math handling in the clang driver, moving the settings into a lambda that is shared by the -ffp-model=fast and -ffast-math code. Previously the -ffp-model=fast handler changed the local option variable and fell through to the -ffast-math handler. This refactoring is intended to prepare the way for decoupling the -ffp-model=fast settings from the -ffast-math settings and possibly introduce a less aggressive fp-model. --- clang/lib/Driver/ToolChains/Clang.cpp | 40 +++++++++++++++------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 942ebbc4106078..4459d86e77d5d9 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2778,6 +2778,26 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_None; std::string ComplexRangeStr = ""; + // Lambda to set fast-math options. This is also used by -ffp-model=fast + auto applyFastMath = [&]() { + HonorINFs = false; + HonorNaNs = false; + MathErrno = false; + AssociativeMath = true; + ReciprocalMath = true; + ApproxFunc = true; + SignedZeros = false; + TrappingMath = false; + RoundingFPMath = false; + FPExceptionBehavior = ""; + // If fast-math is set then set the fp-contract mode to fast. + FPContract = "fast"; + // ffast-math enables limited range rules for complex multiplication and + // division. + Range = LangOptions::ComplexRangeKind::CX_Limited; + SeenUnsafeMathModeOption = true; + }; + if (const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { CmdArgs.push_back("-mlimit-float-precision"); CmdArgs.push_back(A->getValue()); @@ -2842,9 +2862,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, << Args.MakeArgString("-ffp-model=" + FPModel) << Args.MakeArgString("-ffp-model=" + Val); if (Val.equals("fast")) { - optID = options::OPT_ffast_math; FPModel = Val; - FPContract = "fast"; + applyFastMath(); } else if (Val.equals("precise")) { optID = options::OPT_ffp_contract; FPModel = Val; @@ -3061,22 +3080,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, continue; [[fallthrough]]; case options::OPT_ffast_math: { - HonorINFs = false; - HonorNaNs = false; - MathErrno = false; - AssociativeMath = true; - ReciprocalMath = true; - ApproxFunc = true; - SignedZeros = false; - TrappingMath = false; - RoundingFPMath = false; - FPExceptionBehavior = ""; - // If fast-math is set then set the fp-contract mode to fast. - FPContract = "fast"; - SeenUnsafeMathModeOption = true; - // ffast-math enables fortran rules for complex multiplication and - // division. - Range = LangOptions::ComplexRangeKind::CX_Limited; + applyFastMath(); break; } case options::OPT_fno_fast_math: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits