aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorNadeem, Usman <mnadeem@quicinc.com>2023-02-01 15:09:23 -0800
committerNadeem, Usman <mnadeem@quicinc.com>2023-03-09 13:27:43 -0800
commit0fdfb65e2624aa151cb07a9c842331f7af9a21ca (patch)
treec18e354998634bc4c2f3352929c938b76a81b36a /flang/lib/Frontend/CompilerInvocation.cpp
parent8be84e1e31126a60b585a53a2943d0a6eafe4be2 (diff)
downloadllvm-0fdfb65e2624aa151cb07a9c842331f7af9a21ca.zip
llvm-0fdfb65e2624aa151cb07a9c842331f7af9a21ca.tar.gz
llvm-0fdfb65e2624aa151cb07a9c842331f7af9a21ca.tar.bz2
[Flang] Add support to use LTO specific pipelines
Thin and full LTO modes use different pre-link pipelines compared to regular compilation. This patch adds support for calling those pipelines. This patch closely mimics Clang's implementation with the exception that I changed the codegen option name from `PrepareForLTO` to `PrepareForFullLTO` to be more precise. With this patch: - Compilation for full LTO should be as we expect (except possibly missing optimizations enabled by module summaries which we do not produce yet). - thinLTO uses the correct prelink pipeline but will use the postlink backend for fullLTO due to missing metadata and summary in the llvm module. I have added a warning regarding this: `flang-new: warning: the option '-flto=thin' is a work in progress`. Differential Revision: https://reviews.llvm.org/D142420 Change-Id: I6b94b775b5b8e93340e520c5cd4bf60834b2e209
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--flang/lib/Frontend/CompilerInvocation.cpp46
1 files changed, 29 insertions, 17 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index d043444..6e963e2 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -139,35 +139,47 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
args.filtered(clang::driver::options::OPT_fembed_offload_object_EQ))
opts.OffloadObjects.push_back(a->getValue());
+ // -flto=full/thin option.
+ if (const llvm::opt::Arg *a =
+ args.getLastArg(clang::driver::options::OPT_flto_EQ)) {
+ llvm::StringRef s = a->getValue();
+ assert((s == "full" || s == "thin") && "Unknown LTO mode.");
+ if (s == "full")
+ opts.PrepareForFullLTO = true;
+ else
+ opts.PrepareForThinLTO = true;
+ }
+
// -mrelocation-model option.
- if (const llvm::opt::Arg *A =
+ if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_mrelocation_model)) {
- llvm::StringRef ModelName = A->getValue();
- auto RM = llvm::StringSwitch<std::optional<llvm::Reloc::Model>>(ModelName)
- .Case("static", llvm::Reloc::Static)
- .Case("pic", llvm::Reloc::PIC_)
- .Case("dynamic-no-pic", llvm::Reloc::DynamicNoPIC)
- .Case("ropi", llvm::Reloc::ROPI)
- .Case("rwpi", llvm::Reloc::RWPI)
- .Case("ropi-rwpi", llvm::Reloc::ROPI_RWPI)
- .Default(std::nullopt);
- if (RM.has_value())
- opts.setRelocationModel(*RM);
+ llvm::StringRef modelName = a->getValue();
+ auto relocModel =
+ llvm::StringSwitch<std::optional<llvm::Reloc::Model>>(modelName)
+ .Case("static", llvm::Reloc::Static)
+ .Case("pic", llvm::Reloc::PIC_)
+ .Case("dynamic-no-pic", llvm::Reloc::DynamicNoPIC)
+ .Case("ropi", llvm::Reloc::ROPI)
+ .Case("rwpi", llvm::Reloc::RWPI)
+ .Case("ropi-rwpi", llvm::Reloc::ROPI_RWPI)
+ .Default(std::nullopt);
+ if (relocModel.has_value())
+ opts.setRelocationModel(*relocModel);
else
diags.Report(clang::diag::err_drv_invalid_value)
- << A->getAsString(args) << ModelName;
+ << a->getAsString(args) << modelName;
}
// -pic-level and -pic-is-pie option.
- if (int PICLevel = getLastArgIntValue(
+ if (int picLevel = getLastArgIntValue(
args, clang::driver::options::OPT_pic_level, 0, diags)) {
- if (PICLevel > 2)
+ if (picLevel > 2)
diags.Report(clang::diag::err_drv_invalid_value)
<< args.getLastArg(clang::driver::options::OPT_pic_level)
->getAsString(args)
- << PICLevel;
+ << picLevel;
- opts.PICLevel = PICLevel;
+ opts.PICLevel = picLevel;
if (args.hasArg(clang::driver::options::OPT_pic_is_pie))
opts.IsPIE = 1;
}