From 1ea65d9a37990a4f08fce100dbcbbbc591dc8f96 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 27 Aug 2024 22:27:34 -0700 Subject: [PATCH] [LTO] Introduce new type alias ImportListsTy (NFC) The background is as follows. I'm planning to reduce the memory footprint of ThinLTO indexing by changing ImportMapTy, the data structure used for an import list. Once this patch lands, I'm planning to change the type slightly. The new type alias allows us to update the type without touching many places. --- llvm/include/llvm/Transforms/IPO/FunctionImport.h | 5 ++++- llvm/lib/LTO/LTO.cpp | 3 +-- llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 12 ++++++------ llvm/lib/Transforms/IPO/FunctionImport.cpp | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h index b5b969220df85..c06d96bbe62e2 100644 --- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h +++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h @@ -149,6 +149,9 @@ class FunctionImporter { ImportMapTyImpl ImportMap; }; + // A map from destination modules to lists of imports. + using ImportListsTy = DenseMap; + /// The set contains an entry for every global value that the module exports. /// Depending on the user context, this container is allowed to contain /// definitions, declarations or a mix of both. @@ -211,7 +214,7 @@ void ComputeCrossModuleImport( const DenseMap &ModuleToDefinedGVSummaries, function_ref isPrevailing, - DenseMap &ImportLists, + FunctionImporter::ImportListsTy &ImportLists, DenseMap &ExportLists); /// PrevailingType enum used as a return type of callback passed diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index bd031338e8f39..09dfec03cb0c3 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -1716,8 +1716,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache, // Synthesize entry counts for functions in the CombinedIndex. computeSyntheticCounts(ThinLTO.CombinedIndex); - DenseMap ImportLists( - ThinLTO.ModuleMap.size()); + FunctionImporter::ImportListsTy ImportLists(ThinLTO.ModuleMap.size()); DenseMap ExportLists( ThinLTO.ModuleMap.size()); StringMap> ResolvedODR; diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index f74202781a5f4..9d5a62fe10c8d 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -693,7 +693,7 @@ void ThinLTOCodeGenerator::promote(Module &TheModule, ModuleSummaryIndex &Index, computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - DenseMap ImportLists(ModuleCount); + FunctionImporter::ImportListsTy ImportLists(ModuleCount); DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, @@ -745,7 +745,7 @@ void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule, computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - DenseMap ImportLists(ModuleCount); + FunctionImporter::ImportListsTy ImportLists(ModuleCount); DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, @@ -785,7 +785,7 @@ void ThinLTOCodeGenerator::gatherImportedSummariesForModule( computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - DenseMap ImportLists(ModuleCount); + FunctionImporter::ImportListsTy ImportLists(ModuleCount); DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, @@ -823,7 +823,7 @@ void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName, computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - DenseMap ImportLists(ModuleCount); + FunctionImporter::ImportListsTy ImportLists(ModuleCount); DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, @@ -874,7 +874,7 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule, computePrevailingCopies(Index, PrevailingCopy); // Generate import/export list - DenseMap ImportLists(ModuleCount); + FunctionImporter::ImportListsTy ImportLists(ModuleCount); DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, @@ -1074,7 +1074,7 @@ void ThinLTOCodeGenerator::run() { // Collect the import/export lists for all modules from the call-graph in the // combined index. - DenseMap ImportLists(ModuleCount); + FunctionImporter::ImportListsTy ImportLists(ModuleCount); DenseMap ExportLists(ModuleCount); ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries, IsPrevailing(PrevailingCopy), ImportLists, diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index 512f771a873aa..6227b085f13a6 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1111,7 +1111,7 @@ collectImportStatistics(const ModuleSummaryIndex &Index, #ifndef NDEBUG static bool checkVariableImport( const ModuleSummaryIndex &Index, - DenseMap &ImportLists, + FunctionImporter::ImportListsTy &ImportLists, DenseMap &ExportLists) { DenseSet FlattenedImports; @@ -1152,7 +1152,7 @@ void llvm::ComputeCrossModuleImport( const DenseMap &ModuleToDefinedGVSummaries, function_ref isPrevailing, - DenseMap &ImportLists, + FunctionImporter::ImportListsTy &ImportLists, DenseMap &ExportLists) { auto MIS = ModuleImportsManager::create(isPrevailing, Index, &ExportLists); // For each module that has function defined, compute the import/export lists.