From 9e6b46a9846cf5051c2aaef361af0fe1a76c856e Mon Sep 17 00:00:00 2001 From: David Truby Date: Wed, 3 Jul 2024 18:49:42 +0100 Subject: [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 --- flang/lib/Frontend/CompilerInvocation.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'flang/lib/Frontend/CompilerInvocation.cpp') 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 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)) { -- cgit v1.1