[flang-commits] [flang] b5e93e3 - [flang] Add -f[no-]honor-nans and -menable-no-nans
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Fri Nov 4 10:25:01 PDT 2022
Author: Tom Eccles
Date: 2022-11-04T17:22:34Z
New Revision: b5e93e390c06602cb03121ad875e2855253e2937
URL: https://github.com/llvm/llvm-project/commit/b5e93e390c06602cb03121ad875e2855253e2937
DIFF: https://github.com/llvm/llvm-project/commit/b5e93e390c06602cb03121ad875e2855253e2937.diff
LOG: [flang] Add -f[no-]honor-nans and -menable-no-nans
Only add the option processing and store the result. No attributes are
added to FIR yet.
Differential Revision: https://reviews.llvm.org/D137325
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 65cd6e85da4e1..bc0b89190af0b 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_nans : Flag<["-"], "menable-no-nans">,
- HelpText<"Allow optimization to assume there are no NaNs.">,
- MarshallingInfoFlag<LangOpts<"NoHonorNaNs">>, ImpliedByAnyOf<[ffinite_math_only.KeyPath]>;
def mreassociate : Flag<["-"], "mreassociate">,
HelpText<"Allow reassociation transformations for floating-point instructions">,
MarshallingInfoFlag<LangOpts<"AllowFPReassoc">>, ImpliedByAnyOf<[funsafe_math_optimizations.KeyPath]>;
@@ -6057,6 +6054,9 @@ def split_dwarf_output : Separate<["-"], "split-dwarf-output">,
let Flags = [CC1Option, FC1Option, NoDriverOption] in {
+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]>;
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]>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 14547b6f409aa..f66a024c7ffa2 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -84,6 +84,7 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
ArgStringList &CmdArgs) {
StringRef FPContract;
bool HonorINFs = true;
+ bool HonorNaNs = true;
if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
const StringRef Val = A->getValue();
@@ -115,6 +116,12 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
case options::OPT_fno_honor_infinities:
HonorINFs = false;
break;
+ case options::OPT_fhonor_nans:
+ HonorNaNs = true;
+ break;
+ case options::OPT_fno_honor_nans:
+ HonorNaNs = false;
+ break;
}
// If we handled this option claim it
@@ -126,6 +133,9 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
if (!HonorINFs)
CmdArgs.push_back("-menable-no-infs");
+
+ if (!HonorNaNs)
+ CmdArgs.push_back("-menable-no-nans");
}
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 96e9ea63f1964..6bafc0613d3bd 100644
--- a/flang/include/flang/Frontend/LangOptions.def
+++ b/flang/include/flang/Frontend/LangOptions.def
@@ -23,6 +23,8 @@ ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Off) ///< FP Contract Mode (off/
/// Permit floating point optimization without regard to infinities
LANGOPT(NoHonorInfs, 1, false)
+/// Permit floating point optimization without regard to NaN
+LANGOPT(NoHonorNaNs, 1, false)
#undef LANGOPT
#undef ENUM_LANGOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 252e1a7e697a5..cce97caea5159 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -702,6 +702,12 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
opts.NoHonorInfs = true;
}
+ if (const llvm::opt::Arg *a =
+ args.getLastArg(clang::driver::options::OPT_menable_no_nans)) {
+ diags.Report(diagUnimplemented) << a->getOption().getName();
+ opts.NoHonorNaNs = true;
+ }
+
return true;
}
diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index 068985bc6d56e..587c0ec2ffcb5 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -131,6 +131,7 @@
! 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: -menable-no-nans Allow optimization to assume there are no NaNs.
! 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 272ef8495b957..79f1ba796a4a0 100644
--- a/flang/test/Driver/flang_fp_opts.f90
+++ b/flang/test/Driver/flang_fp_opts.f90
@@ -1,5 +1,10 @@
! Test for handling of floating point options within the frontend driver
-! RUN: %flang_fc1 -ffp-contract=fast -menable-no-infs %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 \
+! RUN: -ffp-contract=fast \
+! RUN: -menable-no-infs \
+! RUN: -menable-no-nans \
+! 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
diff --git a/flang/test/Driver/frontend-forwarding.f90 b/flang/test/Driver/frontend-forwarding.f90
index 0c3fd6c48ee20..1160509a500c3 100644
--- a/flang/test/Driver/frontend-forwarding.f90
+++ b/flang/test/Driver/frontend-forwarding.f90
@@ -10,6 +10,7 @@
! RUN: -fconvert=little-endian \
! RUN: -ffp-contract=fast \
! RUN: -fno-honor-infinities \
+! RUN: -fno-honor-nans \
! RUN: -mllvm -print-before-all\
! RUN: -P \
! RUN: | FileCheck %s
@@ -22,5 +23,6 @@
! CHECK: "-flarge-sizes"
! CHECK: "-ffp-contract=fast"
! CHECK: "-menable-no-infs"
+! CHECK: "-menable-no-nans"
! CHECK: "-fconvert=little-endian"
! CHECK: "-mllvm" "-print-before-all"
More information about the flang-commits
mailing list