Skip to content

Commit 36b37a1

Browse files
committed
[flang] Add -f[no-]approx-func
Only add the option processing and store the result. No attributes are added to FIR yet. Differential Revision: https://reviews.llvm.org/D137326
1 parent b5e93e3 commit 36b37a1

File tree

8 files changed

+26
-1
lines changed

8 files changed

+26
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ defm reciprocal_math : BoolFOption<"reciprocal-math",
18921892
[funsafe_math_optimizations.KeyPath]>,
18931893
NegFlag<SetFalse>>;
18941894
defm approx_func : BoolFOption<"approx-func", LangOpts<"ApproxFunc">, DefaultFalse,
1895-
PosFlag<SetTrue, [CC1Option], "Allow certain math function calls to be replaced "
1895+
PosFlag<SetTrue, [CC1Option, FC1Option, FlangOption], "Allow certain math function calls to be replaced "
18961896
"with an approximately equivalent calculation",
18971897
[funsafe_math_optimizations.KeyPath]>,
18981898
NegFlag<SetFalse>>;

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
8585
StringRef FPContract;
8686
bool HonorINFs = true;
8787
bool HonorNaNs = true;
88+
bool ApproxFunc = false;
8889

8990
if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
9091
const StringRef Val = A->getValue();
@@ -122,6 +123,12 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
122123
case options::OPT_fno_honor_nans:
123124
HonorNaNs = false;
124125
break;
126+
case options::OPT_fapprox_func:
127+
ApproxFunc = true;
128+
break;
129+
case options::OPT_fno_approx_func:
130+
ApproxFunc = false;
131+
break;
125132
}
126133

127134
// If we handled this option claim it
@@ -136,6 +143,9 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
136143

137144
if (!HonorNaNs)
138145
CmdArgs.push_back("-menable-no-nans");
146+
147+
if (ApproxFunc)
148+
CmdArgs.push_back("-fapprox-func");
139149
}
140150

141151
void Flang::ConstructJob(Compilation &C, const JobAction &JA,

flang/include/flang/Frontend/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Off) ///< FP Contract Mode (off/
2525
LANGOPT(NoHonorInfs, 1, false)
2626
/// Permit floating point optimization without regard to NaN
2727
LANGOPT(NoHonorNaNs, 1, false)
28+
/// Allow math functions to be replaced with an approximately equivalent calculation
29+
LANGOPT(ApproxFunc, 1, false)
2830

2931
#undef LANGOPT
3032
#undef ENUM_LANGOPT

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,12 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
708708
opts.NoHonorNaNs = true;
709709
}
710710

711+
if (const llvm::opt::Arg *a =
712+
args.getLastArg(clang::driver::options::OPT_fapprox_func)) {
713+
diags.Report(diagUnimplemented) << a->getOption().getName();
714+
opts.ApproxFunc = true;
715+
}
716+
711717
return true;
712718
}
713719

flang/test/Driver/driver-help-hidden.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
! CHECK-NEXT: -E Only run the preprocessor
2323
! CHECK-NEXT: -falternative-parameter-statement
2424
! CHECK-NEXT: Enable the old style PARAMETER statement
25+
! CHECK-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation
2526
! CHECK-NEXT: -fbackslash Specify that backslash in string introduces an escape character
2627
! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics
2728
! CHECK-NEXT: -fconvert=<value> Set endian conversion of data for unformatted files

flang/test/Driver/driver-help.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
! HELP-NEXT: -E Only run the preprocessor
2323
! HELP-NEXT: -falternative-parameter-statement
2424
! HELP-NEXT: Enable the old style PARAMETER statement
25+
! HELP-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation
2526
! HELP-NEXT: -fbackslash Specify that backslash in string introduces an escape character
2627
! HELP-NEXT: -fcolor-diagnostics Enable colors in diagnostics
2728
! HELP-NEXT: -fconvert=<value> Set endian conversion of data for unformatted files
@@ -79,6 +80,7 @@
7980
! HELP-FC1-NEXT: -E Only run the preprocessor
8081
! HELP-FC1-NEXT: -falternative-parameter-statement
8182
! HELP-FC1-NEXT: Enable the old style PARAMETER statement
83+
! HELP-FC1-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation
8284
! HELP-FC1-NEXT: -fbackslash Specify that backslash in string introduces an escape character
8385
! HELP-FC1-NEXT: -fcolor-diagnostics Enable colors in diagnostics
8486
! HELP-FC1-NEXT: -fconvert=<value> Set endian conversion of data for unformatted files

flang/test/Driver/flang_fp_opts.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
! RUN: -ffp-contract=fast \
55
! RUN: -menable-no-infs \
66
! RUN: -menable-no-nans \
7+
! RUN: -fapprox-func \
78
! RUN: %s 2>&1 | FileCheck %s
89
! CHECK: ffp-contract= is not currently implemented
910
! CHECK: menable-no-infs is not currently implemented
1011
! CHECK: menable-no-nans is not currently implemented
12+
! CHECK: fapprox-func is not currently implemented

flang/test/Driver/frontend-forwarding.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
! RUN: -ffp-contract=fast \
1212
! RUN: -fno-honor-infinities \
1313
! RUN: -fno-honor-nans \
14+
! RUN: -fapprox-func \
1415
! RUN: -mllvm -print-before-all\
1516
! RUN: -P \
1617
! RUN: | FileCheck %s
@@ -24,5 +25,6 @@
2425
! CHECK: "-ffp-contract=fast"
2526
! CHECK: "-menable-no-infs"
2627
! CHECK: "-menable-no-nans"
28+
! CHECK: "-fapprox-func"
2729
! CHECK: "-fconvert=little-endian"
2830
! CHECK: "-mllvm" "-print-before-all"

0 commit comments

Comments
 (0)