[PATCH] D134013: [lld][thinlto] Include -mllvm options in the thinlto cache key
Mircea Trofin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 15 21:08:59 PDT 2022
mtrofin created this revision.
mtrofin added reviewers: tejohnson, MaskRay, aeubanks.
Herald added subscribers: ormris, StephenFan, steven_wu, hiraditya, arichardson, inglorion, emaste.
Herald added a project: All.
mtrofin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
They may modify thinlto optimization.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134013
Files:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LTO.cpp
lld/test/ELF/lto/cache.ll
llvm/include/llvm/LTO/Config.h
llvm/lib/LTO/LTO.cpp
Index: llvm/lib/LTO/LTO.cpp
===================================================================
--- llvm/lib/LTO/LTO.cpp
+++ llvm/lib/LTO/LTO.cpp
@@ -131,6 +131,8 @@
AddUnsigned(*Conf.CodeModel);
else
AddUnsigned(-1);
+ for (const auto &S : Conf.MllvmArgs)
+ AddString(S);
AddUnsigned(Conf.CGOptLevel);
AddUnsigned(Conf.CGFileType);
AddUnsigned(Conf.OptLevel);
Index: llvm/include/llvm/LTO/Config.h
===================================================================
--- llvm/include/llvm/LTO/Config.h
+++ llvm/include/llvm/LTO/Config.h
@@ -48,6 +48,7 @@
TargetOptions Options;
std::vector<std::string> MAttrs;
std::vector<std::string> PassPlugins;
+ std::vector<std::string> MllvmArgs;
/// For adding passes that run right before codegen.
std::function<void(legacy::PassManager &)> PreCodeGenPassesHook;
Optional<Reloc::Model> RelocModel = Reloc::PIC_;
Index: lld/test/ELF/lto/cache.ll
===================================================================
--- lld/test/ELF/lto/cache.ll
+++ lld/test/ELF/lto/cache.ll
@@ -51,6 +51,23 @@
; CHECK: llvmcache-newer
; CHECK-NOT: llvmcache-old
+; Check that mllvm options participate in the cache key
+; RUN: rm -rf %t.cache
+; RUN: mkdir %t.cache
+; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o
+; RUN: ls %t.cache | count 3
+; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default
+; RUN: ls %t.cache | count 5
+; Adding another option resuls in 2 more cache entries
+; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
+; RUN: ls %t.cache | count 7
+; Changing order may matter - e.g. if overriding -mllvm options - so we get 2 more entries
+; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -max-devirt-iterations=1 -mllvm -enable-ml-inliner=default
+; RUN: ls %t.cache | count 9
+; Going back to a pre-cached order doesn't create more entries.
+; RUN: ld.lld --thinlto-cache-dir=%t.cache -o %t3 %t2.o %t.o -mllvm -enable-ml-inliner=default -mllvm -max-devirt-iterations=1
+; RUN: ls %t.cache | count 9
+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Index: lld/ELF/LTO.cpp
===================================================================
--- lld/ELF/LTO.cpp
+++ lld/ELF/LTO.cpp
@@ -79,6 +79,8 @@
c.Options = initTargetOptionsFromCodeGenFlags();
c.Options.RelaxELFRelocations = true;
c.Options.EmitAddrsig = true;
+ for (const auto C : config->mllvmOpts)
+ c.MllvmArgs.emplace_back(C.str());
// Always emit a section per function/datum with LTO.
c.Options.FunctionSections = true;
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -1347,8 +1347,10 @@
config->passPlugins = args::getStrings(args, OPT_load_pass_plugins);
// Parse -mllvm options.
- for (auto *arg : args.filtered(OPT_mllvm))
+ for (auto *arg : args.filtered(OPT_mllvm)) {
parseClangOption(arg->getValue(), arg->getSpelling());
+ config->mllvmOpts.insert(config->mllvmOpts.end(), arg->getValue());
+ }
// --threads= takes a positive integer and provides the default value for
// --thinlto-jobs=.
Index: lld/ELF/Config.h
===================================================================
--- lld/ELF/Config.h
+++ lld/ELF/Config.h
@@ -152,6 +152,7 @@
llvm::SmallVector<llvm::StringRef, 0> undefined;
llvm::SmallVector<SymbolVersion, 0> dynamicList;
llvm::SmallVector<uint8_t, 0> buildIdVector;
+ llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;
llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>,
uint64_t>
callGraphProfile;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134013.460626.patch
Type: text/x-patch
Size: 3833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220916/b4244210/attachment.bin>
More information about the llvm-commits
mailing list