[clang] 36b37a1 - [flang] Add -f[no-]approx-func

Tom Eccles via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 4 10:25:06 PDT 2022


Author: Tom Eccles
Date: 2022-11-04T17:22:34Z
New Revision: 36b37a1ed561404a32a4b4b6e2bd92d915894a7c

URL: https://github.com/llvm/llvm-project/commit/36b37a1ed561404a32a4b4b6e2bd92d915894a7c
DIFF: https://github.com/llvm/llvm-project/commit/36b37a1ed561404a32a4b4b6e2bd92d915894a7c.diff

LOG: [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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index bc0b89190af0b..72aa93644865b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -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>>;

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index f66a024c7ffa2..0e82194999c5e 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -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();
@@ -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
@@ -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,

diff  --git a/flang/include/flang/Frontend/LangOptions.def b/flang/include/flang/Frontend/LangOptions.def
index 6bafc0613d3bd..4a5c47f0da637 100644
--- a/flang/include/flang/Frontend/LangOptions.def
+++ b/flang/include/flang/Frontend/LangOptions.def
@@ -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

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index cce97caea5159..dd461c740e3ba 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -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;
 }
 

diff  --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index d2dc82ea1b526..3c249e4f4c7d8 100644
--- 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=<value>      Set endian conversion of data for unformatted files

diff  --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index 587c0ec2ffcb5..3ca3d065e2e30 100644
--- 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=<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

diff  --git a/flang/test/Driver/flang_fp_opts.f90 b/flang/test/Driver/flang_fp_opts.f90
index 79f1ba796a4a0..3b9d0f2d09794 100644
--- 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
index 1160509a500c3..ed0e89a69ca27 100644
--- 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"


        


More information about the cfe-commits mailing list