Skip to content

Commit 03e98d4

Browse files
committed
[DTLTO][LLVM] Store the Target Triple for ThinLTO modules.
This will be used for supplying a `-target=<triple>` option to clang for DTLTO. Note that If DTLTO is changed to use an optimisation tool that does not require an explicit triple to be passed then the triple handling can be removed entirely.
1 parent 8ed3637 commit 03e98d4

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

llvm/include/llvm/LTO/LTO.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ class ThinBackendProc {
228228
const FunctionImporter::ImportMapTy &ImportList,
229229
const FunctionImporter::ExportSetTy &ExportList,
230230
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
231-
MapVector<StringRef, BitcodeModule> &ModuleMap) = 0;
231+
MapVector<StringRef, BitcodeModule> &ModuleMap,
232+
DenseMap<StringRef, std::string> &ModuleTriples) = 0;
232233
Error wait() {
233234
BackendThreadPool.wait();
234235
if (Err)
@@ -426,6 +427,7 @@ class LTO {
426427
// The bitcode modules to compile, if specified by the LTO Config.
427428
std::optional<ModuleMapType> ModulesToCompile;
428429
DenseMap<GlobalValue::GUID, StringRef> PrevailingModuleForGUID;
430+
DenseMap<StringRef, std::string> ModuleTriples;
429431
} ThinLTO;
430432

431433
// The global resolution for a particular (mangled) symbol name. This is in
@@ -517,7 +519,8 @@ class LTO {
517519
bool LivenessFromIndex);
518520

519521
Error addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
520-
const SymbolResolution *&ResI, const SymbolResolution *ResE);
522+
const SymbolResolution *&ResI, const SymbolResolution *ResE,
523+
StringRef Triple);
521524

522525
Error runRegularLTO(AddStreamFn AddStream);
523526
Error runThinLTO(AddStreamFn AddStream, FileCache Cache,

llvm/lib/LTO/LTO.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ Error LTO::addModule(InputFile &Input, unsigned ModI,
783783
LTOInfo->HasSummary);
784784

785785
if (IsThinLTO)
786-
return addThinLTO(BM, ModSyms, ResI, ResE);
786+
return addThinLTO(BM, ModSyms, ResI, ResE, Input.getTargetTriple());
787787

788788
RegularLTO.EmptyCombinedModule = false;
789789
Expected<RegularLTOState::AddedModule> ModOrErr =
@@ -1030,7 +1030,7 @@ Error LTO::linkRegularLTO(RegularLTOState::AddedModule Mod,
10301030
// Add a ThinLTO module to the link.
10311031
Error LTO::addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
10321032
const SymbolResolution *&ResI,
1033-
const SymbolResolution *ResE) {
1033+
const SymbolResolution *ResE, StringRef Triple) {
10341034
const SymbolResolution *ResITmp = ResI;
10351035
for (const InputFile::Symbol &Sym : Syms) {
10361036
assert(ResITmp != ResE);
@@ -1090,6 +1090,8 @@ Error LTO::addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
10901090
"Expected at most one ThinLTO module per bitcode file",
10911091
inconvertibleErrorCode());
10921092

1093+
ThinLTO.ModuleTriples.insert({BM.getModuleIdentifier(), Triple.str()});
1094+
10931095
if (!Conf.ThinLTOModulesToCompile.empty()) {
10941096
if (!ThinLTO.ModulesToCompile)
10951097
ThinLTO.ModulesToCompile = ModuleMapType();
@@ -1496,7 +1498,8 @@ class InProcessThinBackend : public ThinBackendProc {
14961498
const FunctionImporter::ImportMapTy &ImportList,
14971499
const FunctionImporter::ExportSetTy &ExportList,
14981500
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
1499-
MapVector<StringRef, BitcodeModule> &ModuleMap) override {
1501+
MapVector<StringRef, BitcodeModule> &ModuleMap,
1502+
DenseMap<StringRef, std::string> & /*ModuleTriples*/) override {
15001503
StringRef ModulePath = BM.getModuleIdentifier();
15011504
assert(ModuleToDefinedGVSummaries.count(ModulePath));
15021505
const GVSummaryMapTy &DefinedGlobals =
@@ -1776,7 +1779,8 @@ class WriteIndexesThinBackend : public ThinBackendProc {
17761779
const FunctionImporter::ImportMapTy &ImportList,
17771780
const FunctionImporter::ExportSetTy &ExportList,
17781781
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
1779-
MapVector<StringRef, BitcodeModule> &ModuleMap) override {
1782+
MapVector<StringRef, BitcodeModule> &ModuleMap,
1783+
DenseMap<StringRef, std::string> & /*ModuleTriples*/) override {
17801784
StringRef ModulePath = BM.getModuleIdentifier();
17811785

17821786
// The contents of this file may be used as input to a native link, and must
@@ -2013,7 +2017,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
20132017
return BackendProcess->start(
20142018
RegularLTO.ParallelCodeGenParallelismLevel + I, Mod.second,
20152019
ImportLists[Mod.first], ExportLists[Mod.first],
2016-
ResolvedODR[Mod.first], ThinLTO.ModuleMap);
2020+
ResolvedODR[Mod.first], ThinLTO.ModuleMap, ThinLTO.ModuleTriples);
20172021
};
20182022

20192023
if (BackendProcess->getThreadCount() == 1 ||

0 commit comments

Comments
 (0)