Skip to content

Commit

Permalink
[flang] Add -f[no-]approx-func
Browse files Browse the repository at this point in the history
Only add the option processing and store the result. No attributes are
added to FIR yet.

Differential Revision: https://reviews.llvm.org/D137326
  • Loading branch information
tblah committed Nov 4, 2022
1 parent b5e93e3 commit 36b37a1
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/Options.td
Expand Up @@ -1892,7 +1892,7 @@ defm reciprocal_math : BoolFOption<"reciprocal-math",
[funsafe_math_optimizations.KeyPath]>,
NegFlag<SetFalse>>;
defm approx_func : BoolFOption<"approx-func", LangOpts<"ApproxFunc">, DefaultFalse,
PosFlag<SetTrue, [CC1Option], "Allow certain math function calls to be replaced "
PosFlag<SetTrue, [CC1Option, FC1Option, FlangOption], "Allow certain math function calls to be replaced "
"with an approximately equivalent calculation",
[funsafe_math_optimizations.KeyPath]>,
NegFlag<SetFalse>>;
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Driver/ToolChains/Flang.cpp
Expand Up @@ -85,6 +85,7 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
StringRef FPContract;
bool HonorINFs = true;
bool HonorNaNs = true;
bool ApproxFunc = false;

if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
const StringRef Val = A->getValue();
Expand Down Expand Up @@ -122,6 +123,12 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
case options::OPT_fno_honor_nans:
HonorNaNs = false;
break;
case options::OPT_fapprox_func:
ApproxFunc = true;
break;
case options::OPT_fno_approx_func:
ApproxFunc = false;
break;
}

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

if (!HonorNaNs)
CmdArgs.push_back("-menable-no-nans");

if (ApproxFunc)
CmdArgs.push_back("-fapprox-func");
}

void Flang::ConstructJob(Compilation &C, const JobAction &JA,
Expand Down
2 changes: 2 additions & 0 deletions flang/include/flang/Frontend/LangOptions.def
Expand Up @@ -25,6 +25,8 @@ ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Off) ///< FP Contract Mode (off/
LANGOPT(NoHonorInfs, 1, false)
/// Permit floating point optimization without regard to NaN
LANGOPT(NoHonorNaNs, 1, false)
/// Allow math functions to be replaced with an approximately equivalent calculation
LANGOPT(ApproxFunc, 1, false)

#undef LANGOPT
#undef ENUM_LANGOPT
6 changes: 6 additions & 0 deletions flang/lib/Frontend/CompilerInvocation.cpp
Expand Up @@ -708,6 +708,12 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
opts.NoHonorNaNs = true;
}

if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_fapprox_func)) {
diags.Report(diagUnimplemented) << a->getOption().getName();
opts.ApproxFunc = true;
}

return true;
}

Expand Down
1 change: 1 addition & 0 deletions flang/test/Driver/driver-help-hidden.f90
Expand Up @@ -22,6 +22,7 @@
! CHECK-NEXT: -E Only run the preprocessor
! CHECK-NEXT: -falternative-parameter-statement
! CHECK-NEXT: Enable the old style PARAMETER statement
! CHECK-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation
! CHECK-NEXT: -fbackslash Specify that backslash in string introduces an escape character
! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics
! CHECK-NEXT: -fconvert=<value> Set endian conversion of data for unformatted files
Expand Down
2 changes: 2 additions & 0 deletions flang/test/Driver/driver-help.f90
Expand Up @@ -22,6 +22,7 @@
! HELP-NEXT: -E Only run the preprocessor
! HELP-NEXT: -falternative-parameter-statement
! HELP-NEXT: Enable the old style PARAMETER statement
! HELP-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation
! HELP-NEXT: -fbackslash Specify that backslash in string introduces an escape character
! HELP-NEXT: -fcolor-diagnostics Enable colors in diagnostics
! HELP-NEXT: -fconvert=<value> Set endian conversion of data for unformatted files
Expand Down Expand Up @@ -79,6 +80,7 @@
! HELP-FC1-NEXT: -E Only run the preprocessor
! HELP-FC1-NEXT: -falternative-parameter-statement
! HELP-FC1-NEXT: Enable the old style PARAMETER statement
! HELP-FC1-NEXT: -fapprox-func Allow certain math function calls to be replaced with an approximately equivalent calculation
! HELP-FC1-NEXT: -fbackslash Specify that backslash in string introduces an escape character
! HELP-FC1-NEXT: -fcolor-diagnostics Enable colors in diagnostics
! HELP-FC1-NEXT: -fconvert=<value> Set endian conversion of data for unformatted files
Expand Down
2 changes: 2 additions & 0 deletions flang/test/Driver/flang_fp_opts.f90
Expand Up @@ -4,7 +4,9 @@
! RUN: -ffp-contract=fast \
! RUN: -menable-no-infs \
! RUN: -menable-no-nans \
! RUN: -fapprox-func \
! RUN: %s 2>&1 | FileCheck %s
! CHECK: ffp-contract= is not currently implemented
! CHECK: menable-no-infs is not currently implemented
! CHECK: menable-no-nans is not currently implemented
! CHECK: fapprox-func is not currently implemented
2 changes: 2 additions & 0 deletions flang/test/Driver/frontend-forwarding.f90
Expand Up @@ -11,6 +11,7 @@
! RUN: -ffp-contract=fast \
! RUN: -fno-honor-infinities \
! RUN: -fno-honor-nans \
! RUN: -fapprox-func \
! RUN: -mllvm -print-before-all\
! RUN: -P \
! RUN: | FileCheck %s
Expand All @@ -24,5 +25,6 @@
! CHECK: "-ffp-contract=fast"
! CHECK: "-menable-no-infs"
! CHECK: "-menable-no-nans"
! CHECK: "-fapprox-func"
! CHECK: "-fconvert=little-endian"
! CHECK: "-mllvm" "-print-before-all"

0 comments on commit 36b37a1

Please sign in to comment.