aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorTom Eccles <Tom.Eccles@arm.com>2022-10-31 11:30:32 +0000
committerKiran Chandramohan <kiran.chandramohan@arm.com>2022-10-31 11:32:31 +0000
commita784de783af5096e593c5e214c2c78215fe303f5 (patch)
tree2a28ce1db23ec96938387b793fb90b0fa1efc785 /flang/lib/Frontend/CompilerInvocation.cpp
parent0fe945300524ab0d92842f236cfee867204aed14 (diff)
downloadllvm-a784de783af5096e593c5e214c2c78215fe303f5.zip
llvm-a784de783af5096e593c5e214c2c78215fe303f5.tar.gz
llvm-a784de783af5096e593c5e214c2c78215fe303f5.tar.bz2
[flang] Add -ffp-contract option processing
Only add the option processing and store the result. No attributes are added to FIR yet. Only the "off" and "fast" options are supported. "fast-honor-pragmas" is not applicable because we do not implement `#pragma clang fp contract()` in Fortran [1]. "on" is not supported because it is unclear how to fuse only within individual statements. gfortran also does not implement "on": treating it as an "off". Currently the default value is "off" to preserve existing behavior. gfortran uses "fast" by default and that may be the right thing for flang-new after further discussion in the future, but that can be changed separately. gfortran's documentation is available [[ https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html | here ]]. [1] https://clang.llvm.org/docs/LanguageExtensions.html#extensions-to-specify-floating-point-flags Reviewed By: vzakhari, awarzynski Differential Revision: https://reviews.llvm.org/D136080
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 761300b..3a64086 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -658,6 +658,42 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
return diags.getNumErrors() == numErrorsBefore;
}
+/// Parses all floating point related arguments and populates the
+/// CompilerInvocation accordingly.
+/// Returns false if new errors are generated.
+///
+/// \param [out] invoc Stores the processed arguments
+/// \param [in] args The compiler invocation arguments to parse
+/// \param [out] diags DiagnosticsEngine to report erros with
+static bool parseFloatingPointArgs(CompilerInvocation &invoc,
+ llvm::opt::ArgList &args,
+ clang::DiagnosticsEngine &diags) {
+ LangOptions &opts = invoc.getLangOpts();
+ const unsigned diagUnimplemented = diags.getCustomDiagID(
+ clang::DiagnosticsEngine::Warning, "%0 is not currently implemented");
+
+ if (const llvm::opt::Arg *a =
+ args.getLastArg(clang::driver::options::OPT_ffp_contract)) {
+ const llvm::StringRef val = a->getValue();
+ enum LangOptions::FPModeKind fpContractMode;
+
+ if (val == "off")
+ fpContractMode = LangOptions::FPM_Off;
+ else if (val == "fast")
+ fpContractMode = LangOptions::FPM_Fast;
+ else {
+ diags.Report(clang::diag::err_drv_unsupported_option_argument)
+ << a->getOption().getName() << val;
+ return false;
+ }
+
+ diags.Report(diagUnimplemented) << a->getOption().getName();
+ opts.setFPContractMode(fpContractMode);
+ }
+
+ return true;
+}
+
bool CompilerInvocation::createFromArgs(
CompilerInvocation &res, llvm::ArrayRef<const char *> commandLineArgs,
clang::DiagnosticsEngine &diags) {
@@ -712,6 +748,8 @@ bool CompilerInvocation::createFromArgs(
res.frontendOpts.mlirArgs =
args.getAllArgValues(clang::driver::options::OPT_mmlir);
+ success &= parseFloatingPointArgs(res, args, diags);
+
return success;
}