Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ 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>; Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ 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, Index: flang/include/flang/Frontend/LangOptions.def =================================================================== --- flang/include/flang/Frontend/LangOptions.def +++ 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 Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -703,6 +703,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; } Index: flang/test/Driver/driver-help-hidden.f90 =================================================================== --- flang/test/Driver/driver-help-hidden.f90 +++ 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 Index: flang/test/Driver/driver-help.f90 =================================================================== --- flang/test/Driver/driver-help.f90 +++ 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 Index: flang/test/Driver/flang_fp_opts.f90 =================================================================== --- flang/test/Driver/flang_fp_opts.f90 +++ 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 Index: flang/test/Driver/frontend-forwarding.f90 =================================================================== --- flang/test/Driver/frontend-forwarding.f90 +++ 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"