This revision was automatically updated to reflect the committed changes.
Closed by commit rG36b37a1ed561: [flang] Add -f[no-]approx-func (authored by 
tblah).
Herald added projects: clang, Flang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137326/new/

https://reviews.llvm.org/D137326

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/LangOptions.def
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/flang_fp_opts.f90
  flang/test/Driver/frontend-forwarding.f90

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"
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/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=<value>      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=<value>      Set endian conversion of data for unformatted files
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=<value>      Set endian conversion of data for unformatted files
Index: flang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ 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;
 }
 
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: 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: 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<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>>;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to