Skip to content

Commit 73159a9

Browse files
author
Andy Kaylor
authored
[NFC] Refactor fast-math handling for clang driver (#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.
1 parent 2fcfc97 commit 73159a9

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,6 +2778,26 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
27782778
LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_None;
27792779
std::string ComplexRangeStr = "";
27802780

2781+
// Lambda to set fast-math options. This is also used by -ffp-model=fast
2782+
auto applyFastMath = [&]() {
2783+
HonorINFs = false;
2784+
HonorNaNs = false;
2785+
MathErrno = false;
2786+
AssociativeMath = true;
2787+
ReciprocalMath = true;
2788+
ApproxFunc = true;
2789+
SignedZeros = false;
2790+
TrappingMath = false;
2791+
RoundingFPMath = false;
2792+
FPExceptionBehavior = "";
2793+
// If fast-math is set then set the fp-contract mode to fast.
2794+
FPContract = "fast";
2795+
// ffast-math enables limited range rules for complex multiplication and
2796+
// division.
2797+
Range = LangOptions::ComplexRangeKind::CX_Limited;
2798+
SeenUnsafeMathModeOption = true;
2799+
};
2800+
27812801
if (const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
27822802
CmdArgs.push_back("-mlimit-float-precision");
27832803
CmdArgs.push_back(A->getValue());
@@ -2842,9 +2862,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
28422862
<< Args.MakeArgString("-ffp-model=" + FPModel)
28432863
<< Args.MakeArgString("-ffp-model=" + Val);
28442864
if (Val.equals("fast")) {
2845-
optID = options::OPT_ffast_math;
28462865
FPModel = Val;
2847-
FPContract = "fast";
2866+
applyFastMath();
28482867
} else if (Val.equals("precise")) {
28492868
optID = options::OPT_ffp_contract;
28502869
FPModel = Val;
@@ -3061,22 +3080,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
30613080
continue;
30623081
[[fallthrough]];
30633082
case options::OPT_ffast_math: {
3064-
HonorINFs = false;
3065-
HonorNaNs = false;
3066-
MathErrno = false;
3067-
AssociativeMath = true;
3068-
ReciprocalMath = true;
3069-
ApproxFunc = true;
3070-
SignedZeros = false;
3071-
TrappingMath = false;
3072-
RoundingFPMath = false;
3073-
FPExceptionBehavior = "";
3074-
// If fast-math is set then set the fp-contract mode to fast.
3075-
FPContract = "fast";
3076-
SeenUnsafeMathModeOption = true;
3077-
// ffast-math enables fortran rules for complex multiplication and
3078-
// division.
3079-
Range = LangOptions::ComplexRangeKind::CX_Limited;
3083+
applyFastMath();
30803084
break;
30813085
}
30823086
case options::OPT_fno_fast_math:

0 commit comments

Comments
 (0)