Author: Tom Eccles Date: 2022-11-04T17:22:35Z New Revision: d0d4b635786d510cd919cadbeb7e5e19983242cf
URL: https://github.com/llvm/llvm-project/commit/d0d4b635786d510cd919cadbeb7e5e19983242cf DIFF: https://github.com/llvm/llvm-project/commit/d0d4b635786d510cd919cadbeb7e5e19983242cf.diff LOG: [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 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 77c84396fa995..608840b2d3691 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 f51972773a553..43f6a82c33c49 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 059e3d18dfc8a..024db6109d6a1 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 8c0bdcd185b6c..bb87ea285a265 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 b3913e99d1387..3bce2a57caa1a 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 32b6f7615deca..8d24deee0b1ad 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 bbe886bcec878..0dc31f6f7649e 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 de3ed6ddbfca8..9d1d7cb8d3c88 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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits