Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Eccles <tom.eccles@arm.com>2022-10-19 13:51:31 +0300
committerTom Eccles <tom.eccles@arm.com>2022-11-04 20:22:35 +0300
commitd0d4b635786d510cd919cadbeb7e5e19983242cf (patch)
tree38cd877bb2440c8befbdf38d4ce92b5e047ed07e
parentc4dc3c029416a25103d631e8dc5422f65c076376 (diff)
[flang] add -f[no-]reciprocal-math
Only add the option processing and store the result. No attributes are added to FIR yet. Differential Revision: https://reviews.llvm.org/D137330
-rw-r--r--clang/include/clang/Driver/Options.td2
-rw-r--r--clang/lib/Driver/ToolChains/Flang.cpp10
-rw-r--r--flang/include/flang/Frontend/LangOptions.def2
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp6
-rw-r--r--flang/test/Driver/driver-help-hidden.f901
-rw-r--r--flang/test/Driver/driver-help.f902
-rw-r--r--flang/test/Driver/flang_fp_opts.f902
-rw-r--r--flang/test/Driver/frontend-forwarding.f902
8 files changed, 26 insertions, 1 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 77c84396fa99..608840b2d369 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1888,7 +1888,7 @@ def fassociative_math : Flag<["-"], "fassociative-math">, Group<f_Group>;
def fno_associative_math : Flag<["-"], "fno-associative-math">, Group<f_Group>;
defm reciprocal_math : BoolFOption<"reciprocal-math",
LangOpts<"AllowRecip">, DefaultFalse,
- PosFlag<SetTrue, [CC1Option], "Allow division operations to be reassociated",
+ PosFlag<SetTrue, [CC1Option, FC1Option, FlangOption], "Allow division operations to be reassociated",
[funsafe_math_optimizations.KeyPath]>,
NegFlag<SetFalse>>;
defm approx_func : BoolFOption<"approx-func", LangOpts<"ApproxFunc">, DefaultFalse,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index f51972773a55..43f6a82c33c4 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -88,6 +88,7 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
bool ApproxFunc = false;
bool SignedZeros = true;
bool AssociativeMath = false;
+ bool ReciprocalMath = false;
if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
const StringRef Val = A->getValue();
@@ -143,6 +144,12 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
case options::OPT_fno_associative_math:
AssociativeMath = false;
break;
+ case options::OPT_freciprocal_math:
+ ReciprocalMath = true;
+ break;
+ case options::OPT_fno_reciprocal_math:
+ ReciprocalMath = false;
+ break;
}
// If we handled this option claim it
@@ -166,6 +173,9 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
if (AssociativeMath && !SignedZeros)
CmdArgs.push_back("-mreassociate");
+
+ if (ReciprocalMath)
+ CmdArgs.push_back("-freciprocal-math");
}
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 059e3d18dfc8..024db6109d6a 100644
--- a/flang/include/flang/Frontend/LangOptions.def
+++ b/flang/include/flang/Frontend/LangOptions.def
@@ -31,6 +31,8 @@ LANGOPT(ApproxFunc, 1, false)
LANGOPT(NoSignedZeros, 1, false)
/// Allow reassociation transformations for floating-point instructions
LANGOPT(AssociativeMath, 1, false)
+/// Allow division operations to be reassociated
+LANGOPT(ReciprocalMath, 1, false)
#undef LANGOPT
#undef ENUM_LANGOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 8c0bdcd185b6..bb87ea285a26 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -726,6 +726,12 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
opts.AssociativeMath = true;
}
+ if (const llvm::opt::Arg *a =
+ args.getLastArg(clang::driver::options::OPT_freciprocal_math)) {
+ diags.Report(diagUnimplemented) << a->getOption().getName();
+ opts.ReciprocalMath = true;
+ }
+
return true;
}
diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index b3913e99d138..3bce2a57caa1 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -48,6 +48,7 @@
! CHECK-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
! CHECK-NEXT: -fopenacc Enable OpenACC
! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
+! CHECK-NEXT: -freciprocal-math Allow division operations to be reassociated
! CHECK-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages
! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
! CHECK-NEXT: -help Display available options
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index 32b6f7615dec..8d24deee0b1a 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -46,6 +46,7 @@
! HELP-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
! HELP-NEXT: -fopenacc Enable OpenACC
! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
+! HELP-NEXT: -freciprocal-math Allow division operations to be reassociated
! HELP-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages
! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
! HELP-NEXT: -help Display available options
@@ -128,6 +129,7 @@
! HELP-FC1-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
! HELP-FC1-NEXT: -fopenacc Enable OpenACC
! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
+! HELP-FC1-NEXT: -freciprocal-math Allow division operations to be reassociated
! HELP-FC1-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages
! HELP-FC1-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
! HELP-FC1-NEXT: -help Display available options
diff --git a/flang/test/Driver/flang_fp_opts.f90 b/flang/test/Driver/flang_fp_opts.f90
index bbe886bcec87..0dc31f6f7649 100644
--- a/flang/test/Driver/flang_fp_opts.f90
+++ b/flang/test/Driver/flang_fp_opts.f90
@@ -7,6 +7,7 @@
! RUN: -fapprox-func \
! RUN: -fno-signed-zeros \
! RUN: -mreassociate \
+! RUN: -freciprocal-math \
! RUN: %s 2>&1 | FileCheck %s
! CHECK: ffp-contract= is not currently implemented
! CHECK: menable-no-infs is not currently implemented
@@ -14,3 +15,4 @@
! CHECK: fapprox-func is not currently implemented
! CHECK: fno-signed-zeros is not currently implemented
! CHECK: mreassociate is not currently implemented
+! CHECK: freciprocal-math is not currently implemented
diff --git a/flang/test/Driver/frontend-forwarding.f90 b/flang/test/Driver/frontend-forwarding.f90
index de3ed6ddbfca..9d1d7cb8d3c8 100644
--- a/flang/test/Driver/frontend-forwarding.f90
+++ b/flang/test/Driver/frontend-forwarding.f90
@@ -14,6 +14,7 @@
! RUN: -fapprox-func \
! RUN: -fno-signed-zeros \
! RUN: -fassociative-math \
+! RUN: -freciprocal-math \
! RUN: -mllvm -print-before-all\
! RUN: -P \
! RUN: | FileCheck %s
@@ -30,5 +31,6 @@
! CHECK: "-fapprox-func"
! CHECK: "-fno-signed-zeros"
! CHECK: "-mreassociate"
+! CHECK: "-freciprocal-math"
! CHECK: "-fconvert=little-endian"
! CHECK: "-mllvm" "-print-before-all"