diff options
author | David Truby <david.truby@arm.com> | 2024-07-03 18:49:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-03 18:49:42 +0100 |
commit | 9e6b46a9846cf5051c2aaef361af0fe1a76c856e (patch) | |
tree | a511c6b9dc1b2301d526e133f8b65f053c85b34a /flang/lib/Frontend/CompilerInvocation.cpp | |
parent | 845dee36ba4161df153ba05009cea615e20eda5a (diff) | |
download | llvm-9e6b46a9846cf5051c2aaef361af0fe1a76c856e.zip llvm-9e6b46a9846cf5051c2aaef361af0fe1a76c856e.tar.gz llvm-9e6b46a9846cf5051c2aaef361af0fe1a76c856e.tar.bz2 |
[flang] Implement -mcmodel flag (#95411)
This patch implements the -mcmodel flag from clang, allowing the Code
Model to be changed for the LLVM module. The same set of mcmodel
flags are accepted as in clang and the same Code Model attributes are
added to the LLVM module for those flags.
Also add `-mlarge-data-threshold` for x86-64, which is automatically set
by the shared command-line code (see below). This is also added as an
attribute into the LLVM module and on the target machine.
A function is created for `addMCModel` that is copied out of clang's
argument handling so that it can be shared with flang.
---------
Co-authored-by: Mats Petersson <mats.petersson@arm.com>
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index f96d72f..e2d60ad 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -32,6 +32,7 @@ #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" +#include "llvm/Support/CodeGen.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/Path.h" @@ -386,6 +387,29 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts, opts.IsPIE = 1; } + // -mcmodel option. + if (const llvm::opt::Arg *a = + args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) { + llvm::StringRef modelName = a->getValue(); + std::optional<llvm::CodeModel::Model> codeModel = getCodeModel(modelName); + + if (codeModel.has_value()) + opts.CodeModel = modelName; + else + diags.Report(clang::diag::err_drv_invalid_value) + << a->getAsString(args) << modelName; + } + + if (const llvm::opt::Arg *arg = args.getLastArg( + clang::driver::options::OPT_mlarge_data_threshold_EQ)) { + uint64_t LDT; + if (llvm::StringRef(arg->getValue()).getAsInteger(/*Radix=*/10, LDT)) { + diags.Report(clang::diag::err_drv_invalid_value) + << arg->getSpelling() << arg->getValue(); + } + opts.LargeDataThreshold = LDT; + } + // This option is compatible with -f[no-]underscoring in gfortran. if (args.hasFlag(clang::driver::options::OPT_fno_underscoring, clang::driver::options::OPT_funderscoring, false)) { |