diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1892,7 +1892,7 @@ [funsafe_math_optimizations.KeyPath]>, NegFlag>; defm approx_func : BoolFOption<"approx-func", LangOpts<"ApproxFunc">, DefaultFalse, - PosFlag, NegFlag>; diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -85,6 +85,7 @@ 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(); @@ -122,6 +123,12 @@ 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 @@ -136,6 +143,9 @@ if (!HonorNaNs) CmdArgs.push_back("-menable-no-nans"); + + if (ApproxFunc) + CmdArgs.push_back("-fapprox-func"); } void Flang::ConstructJob(Compilation &C, const JobAction &JA, diff --git a/flang/include/flang/Frontend/LangOptions.def b/flang/include/flang/Frontend/LangOptions.def --- a/flang/include/flang/Frontend/LangOptions.def +++ b/flang/include/flang/Frontend/LangOptions.def @@ -25,6 +25,8 @@ 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 diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -708,6 +708,12 @@ 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; } diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -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= Set endian conversion of data for unformatted files diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90 --- a/flang/test/Driver/driver-help.f90 +++ b/flang/test/Driver/driver-help.f90 @@ -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= Set endian conversion of data for unformatted files @@ -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= Set endian conversion of data for unformatted files diff --git a/flang/test/Driver/flang_fp_opts.f90 b/flang/test/Driver/flang_fp_opts.f90 --- a/flang/test/Driver/flang_fp_opts.f90 +++ b/flang/test/Driver/flang_fp_opts.f90 @@ -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 diff --git a/flang/test/Driver/frontend-forwarding.f90 b/flang/test/Driver/frontend-forwarding.f90 --- a/flang/test/Driver/frontend-forwarding.f90 +++ b/flang/test/Driver/frontend-forwarding.f90 @@ -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 @@ -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"