[flang-commits] [flang] 0fb763e - [flang] Add -f[no-]honor-infinities and -menable-no-infs
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Thu Nov 3 03:40:52 PDT 2022
Author: Tom Eccles
Date: 2022-11-03T10:38:09Z
New Revision: 0fb763e7d0a4b8c9f5978675e7556ae50716d695
URL: https://github.com/llvm/llvm-project/commit/0fb763e7d0a4b8c9f5978675e7556ae50716d695
DIFF: https://github.com/llvm/llvm-project/commit/0fb763e7d0a4b8c9f5978675e7556ae50716d695.diff
LOG: [flang] Add -f[no-]honor-infinities and -menable-no-infs
Only add the option processing and store the result. No attributes are
added to FIR yet.
This patch follows Clang in forwarding -fno-honor-infinities as
-menable-no-infs.
Reviewed By: kiranchandramohan awarzynski vzakhari
Differential Revision: https://reviews.llvm.org/D137072
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.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 3e15c55ed52ea..65cd6e85da4e1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5444,9 +5444,6 @@ def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
HelpText<"Specify which frame pointers to retain.">, Values<"all,non-leaf,none">,
NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, NormalizedValues<["All", "NonLeaf", "None"]>,
MarshallingInfoEnum<CodeGenOpts<"FramePointer">, "None">;
-def menable_no_infinities : Flag<["-"], "menable-no-infs">,
- HelpText<"Allow optimization to assume there are no infinities.">,
- MarshallingInfoFlag<LangOpts<"NoHonorInfs">>, ImpliedByAnyOf<[ffinite_math_only.KeyPath]>;
def menable_no_nans : Flag<["-"], "menable-no-nans">,
HelpText<"Allow optimization to assume there are no NaNs.">,
MarshallingInfoFlag<LangOpts<"NoHonorNaNs">>, ImpliedByAnyOf<[ffinite_math_only.KeyPath]>;
@@ -6060,6 +6057,10 @@ def split_dwarf_output : Separate<["-"], "split-dwarf-output">,
let Flags = [CC1Option, FC1Option, NoDriverOption] in {
+def menable_no_infinities : Flag<["-"], "menable-no-infs">,
+ HelpText<"Allow optimization to assume there are no infinities.">,
+ MarshallingInfoFlag<LangOpts<"NoHonorInfs">>, ImpliedByAnyOf<[ffinite_math_only.KeyPath]>;
+
def pic_level : Separate<["-"], "pic-level">,
HelpText<"Value for __PIC__">,
MarshallingInfoInt<LangOpts<"PICLevel">>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 6c6895da61299..14547b6f409aa 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -83,6 +83,7 @@ void Flang::AddPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
ArgStringList &CmdArgs) {
StringRef FPContract;
+ bool HonorINFs = true;
if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
const StringRef Val = A->getValue();
@@ -101,8 +102,30 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
<< A->getOption().getName() << Val;
}
+ for (const Arg *A : Args) {
+ auto optId = A->getOption().getID();
+ switch (optId) {
+ // if this isn't an FP option, skip the claim below
+ default:
+ continue;
+
+ case options::OPT_fhonor_infinities:
+ HonorINFs = true;
+ break;
+ case options::OPT_fno_honor_infinities:
+ HonorINFs = false;
+ break;
+ }
+
+ // If we handled this option claim it
+ A->claim();
+ }
+
if (!FPContract.empty())
CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + FPContract));
+
+ if (!HonorINFs)
+ CmdArgs.push_back("-menable-no-infs");
}
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 c4d0ec5329b2e..96e9ea63f1964 100644
--- a/flang/include/flang/Frontend/LangOptions.def
+++ b/flang/include/flang/Frontend/LangOptions.def
@@ -21,5 +21,8 @@ LANGOPT(Name, Bits, Default)
ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Off) ///< FP Contract Mode (off/fast)
+/// Permit floating point optimization without regard to infinities
+LANGOPT(NoHonorInfs, 1, false)
+
#undef LANGOPT
#undef ENUM_LANGOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 3a64086be33d3..10c73169d0d02 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -691,6 +691,12 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
opts.setFPContractMode(fpContractMode);
}
+ if (const llvm::opt::Arg *a =
+ args.getLastArg(clang::driver::options::OPT_menable_no_infinities)) {
+ diags.Report(diagUnimplemented) << a->getOption().getName();
+ opts.NoHonorInfs = true;
+ }
+
return true;
}
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index 3ab509c7129e9..068985bc6d56e 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -130,6 +130,7 @@
! HELP-FC1-NEXT: -init-only Only execute frontend initialization
! HELP-FC1-NEXT: -I <dir> Add directory to the end of the list of include search paths
! HELP-FC1-NEXT: -load <dsopath> Load the named plugin (dynamic shared object)
+! HELP-FC1-NEXT: -menable-no-infs Allow optimization to assume there are no infinities.
! HELP-FC1-NEXT: -mllvm <value> Additional arguments to forward to LLVM's option processing
! HELP-FC1-NEXT: -mmlir <value> Additional arguments to forward to MLIR's option processing
! HELP-FC1-NEXT: -module-dir <dir> Put MODULE files in <dir>
diff --git a/flang/test/Driver/flang_fp_opts.f90 b/flang/test/Driver/flang_fp_opts.f90
index 34987f4b0c438..272ef8495b957 100644
--- a/flang/test/Driver/flang_fp_opts.f90
+++ b/flang/test/Driver/flang_fp_opts.f90
@@ -1,4 +1,5 @@
! Test for handling of floating point options within the frontend driver
-! RUN: %flang_fc1 -ffp-contract=fast %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -ffp-contract=fast -menable-no-infs %s 2>&1 | FileCheck %s
! CHECK: ffp-contract= is not currently implemented
+! CHECK: menable-no-infs is not currently implemented
diff --git a/flang/test/Driver/frontend-forwarding.f90 b/flang/test/Driver/frontend-forwarding.f90
index b956940fd7d29..0c3fd6c48ee20 100644
--- a/flang/test/Driver/frontend-forwarding.f90
+++ b/flang/test/Driver/frontend-forwarding.f90
@@ -9,6 +9,7 @@
! RUN: -flarge-sizes \
! RUN: -fconvert=little-endian \
! RUN: -ffp-contract=fast \
+! RUN: -fno-honor-infinities \
! RUN: -mllvm -print-before-all\
! RUN: -P \
! RUN: | FileCheck %s
@@ -20,5 +21,6 @@
! CHECK: "-fdefault-real-8"
! CHECK: "-flarge-sizes"
! CHECK: "-ffp-contract=fast"
+! CHECK: "-menable-no-infs"
! CHECK: "-fconvert=little-endian"
! CHECK: "-mllvm" "-print-before-all"
More information about the flang-commits
mailing list