[clang] [NFC] Refactor fast-math handling for clang driver (PR #81173)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 8 10:59:03 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-driver
Author: Andy Kaylor (andykaylor)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/81173.diff
1 Files Affected:
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+22-18)
``````````diff
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:
``````````
</details>
https://github.com/llvm/llvm-project/pull/81173
More information about the cfe-commits
mailing list