aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO
diff options
context:
space:
mode:
authorShoaib Meenai <smeenai@fb.com>2023-03-24 17:34:14 -0700
committerShoaib Meenai <smeenai@fb.com>2023-03-25 21:37:42 -0700
commit377e1311d50c7e5b5aab3db081938e0d0ceebdfc (patch)
tree42695adc7a9504adff62416306a1a19664de54f4 /llvm/lib/LTO
parent943df86c82b1450bde45678757b7c39e459bc6ad (diff)
downloadllvm-377e1311d50c7e5b5aab3db081938e0d0ceebdfc.zip
llvm-377e1311d50c7e5b5aab3db081938e0d0ceebdfc.tar.gz
llvm-377e1311d50c7e5b5aab3db081938e0d0ceebdfc.tar.bz2
[ThinLTO] Only import for non-prevailing interposable global variables
This logic was added in https://reviews.llvm.org/D95943 specifically to handle an issue for non-prevailing global variables. It turns out that it adds a new issue for prevailing glboal variables, since those could be replaced by an available_externally definition and hence incorrectly omitted from the output object file. Limit the import to non-prevailing global variables to fix this, as suggested by @tejohnson. The bulk of the diff is mechanical changes to thread isPrevailing through to where it's needed and ensure it's available before the relevant calls; the actual logic change itself is straightforward. Fixes https://github.com/llvm/llvm-project/issues/61677 Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D146876
Diffstat (limited to 'llvm/lib/LTO')
-rw-r--r--llvm/lib/LTO/LTO.cpp2
-rw-r--r--llvm/lib/LTO/ThinLTOCodeGenerator.cpp51
2 files changed, 37 insertions, 16 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index ee6b8c3..4d6a620 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1553,7 +1553,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
if (Conf.OptLevel > 0)
ComputeCrossModuleImport(ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
- ImportLists, ExportLists);
+ isPrevailing, ImportLists, ExportLists);
// Figure out which symbols need to be internalized. This also needs to happen
// at -O0 because summary-based DCE is implemented using internalization, and
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 144cc5a..0549098 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -714,15 +714,17 @@ void ThinLTOCodeGenerator::promote(Module &TheModule, ModuleSummaryIndex &Index,
// Compute "dead" symbols, we don't want to import/export these!
computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
+ // Compute prevailing symbols
+ DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
+ computePrevailingCopies(Index, PrevailingCopy);
+
// Generate import/export list
StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
- ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
+ ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
+ IsPrevailing(PrevailingCopy), ImportLists,
ExportLists);
- DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
- computePrevailingCopies(Index, PrevailingCopy);
-
// Resolve prevailing symbols
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols,
@@ -764,10 +766,15 @@ void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule,
// Compute "dead" symbols, we don't want to import/export these!
computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
+ // Compute prevailing symbols
+ DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
+ computePrevailingCopies(Index, PrevailingCopy);
+
// Generate import/export list
StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
- ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
+ ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
+ IsPrevailing(PrevailingCopy), ImportLists,
ExportLists);
auto &ImportList = ImportLists[TheModule.getModuleIdentifier()];
@@ -799,10 +806,15 @@ void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
// Compute "dead" symbols, we don't want to import/export these!
computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
+ // Compute prevailing symbols
+ DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
+ computePrevailingCopies(Index, PrevailingCopy);
+
// Generate import/export list
StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
- ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
+ ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
+ IsPrevailing(PrevailingCopy), ImportLists,
ExportLists);
llvm::gatherImportedSummariesForModule(
@@ -832,10 +844,15 @@ void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName,
// Compute "dead" symbols, we don't want to import/export these!
computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
+ // Compute prevailing symbols
+ DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
+ computePrevailingCopies(Index, PrevailingCopy);
+
// Generate import/export list
StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
- ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
+ ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
+ IsPrevailing(PrevailingCopy), ImportLists,
ExportLists);
std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
@@ -874,10 +891,15 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
// Compute "dead" symbols, we don't want to import/export these!
computeDeadSymbolsInIndex(Index, GUIDPreservedSymbols);
+ // Compute prevailing symbols
+ DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
+ computePrevailingCopies(Index, PrevailingCopy);
+
// Generate import/export list
StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
- ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, ImportLists,
+ ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
+ IsPrevailing(PrevailingCopy), ImportLists,
ExportLists);
auto &ExportList = ExportLists[ModuleIdentifier];
@@ -886,9 +908,6 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
if (ExportList.empty() && GUIDPreservedSymbols.empty())
return;
- DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
- computePrevailingCopies(Index, PrevailingCopy);
-
// Resolve prevailing symbols
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
resolvePrevailingInIndex(Index, ResolvedODR, GUIDPreservedSymbols,
@@ -1068,11 +1087,16 @@ void ThinLTOCodeGenerator::run() {
for (auto GUID : ExportedGUIDs)
GUIDPreservedSymbols.insert(GUID);
+ // Compute prevailing symbols
+ DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
+ computePrevailingCopies(*Index, PrevailingCopy);
+
// Collect the import/export lists for all modules from the call-graph in the
// combined index.
StringMap<FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
StringMap<FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
- ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries, ImportLists,
+ ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries,
+ IsPrevailing(PrevailingCopy), ImportLists,
ExportLists);
// We use a std::map here to be able to have a defined ordering when
@@ -1081,9 +1105,6 @@ void ThinLTOCodeGenerator::run() {
// on the index, and nuke this map.
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
- DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;
- computePrevailingCopies(*Index, PrevailingCopy);
-
// Resolve prevailing symbols, this has to be computed early because it
// impacts the caching.
resolvePrevailingInIndex(*Index, ResolvedODR, GUIDPreservedSymbols,