Skip to content

Commit

Permalink
[LTO] Introduce new type alias ImportListsTy (NFC) (#106420)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kazutakahirata authored Aug 28, 2024
1 parent 1bde8e0 commit 4f15039
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
5 changes: 4 additions & 1 deletion llvm/include/llvm/Transforms/IPO/FunctionImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class FunctionImporter {
ImportMapTyImpl ImportMap;
};

// A map from destination modules to lists of imports.
using ImportListsTy = DenseMap<StringRef, ImportMapTy>;

/// 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.
Expand Down Expand Up @@ -211,7 +214,7 @@ void ComputeCrossModuleImport(
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
isPrevailing,
DenseMap<StringRef, FunctionImporter::ImportMapTy> &ImportLists,
FunctionImporter::ImportListsTy &ImportLists,
DenseMap<StringRef, FunctionImporter::ExportSetTy> &ExportLists);

/// PrevailingType enum used as a return type of callback passed
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/LTO/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,8 +1716,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
// Synthesize entry counts for functions in the CombinedIndex.
computeSyntheticCounts(ThinLTO.CombinedIndex);

DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists(
ThinLTO.ModuleMap.size());
FunctionImporter::ImportListsTy ImportLists(ThinLTO.ModuleMap.size());
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(
ThinLTO.ModuleMap.size());
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/LTO/ThinLTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ void ThinLTOCodeGenerator::promote(Module &TheModule, ModuleSummaryIndex &Index,
computePrevailingCopies(Index, PrevailingCopy);

// Generate import/export list
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
FunctionImporter::ImportListsTy ImportLists(ModuleCount);
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
IsPrevailing(PrevailingCopy), ImportLists,
Expand Down Expand Up @@ -745,7 +745,7 @@ void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule,
computePrevailingCopies(Index, PrevailingCopy);

// Generate import/export list
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
FunctionImporter::ImportListsTy ImportLists(ModuleCount);
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
IsPrevailing(PrevailingCopy), ImportLists,
Expand Down Expand Up @@ -785,7 +785,7 @@ void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
computePrevailingCopies(Index, PrevailingCopy);

// Generate import/export list
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
FunctionImporter::ImportListsTy ImportLists(ModuleCount);
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
IsPrevailing(PrevailingCopy), ImportLists,
Expand Down Expand Up @@ -823,7 +823,7 @@ void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName,
computePrevailingCopies(Index, PrevailingCopy);

// Generate import/export list
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
FunctionImporter::ImportListsTy ImportLists(ModuleCount);
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
IsPrevailing(PrevailingCopy), ImportLists,
Expand Down Expand Up @@ -874,7 +874,7 @@ void ThinLTOCodeGenerator::internalize(Module &TheModule,
computePrevailingCopies(Index, PrevailingCopy);

// Generate import/export list
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
FunctionImporter::ImportListsTy ImportLists(ModuleCount);
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
ComputeCrossModuleImport(Index, ModuleToDefinedGVSummaries,
IsPrevailing(PrevailingCopy), ImportLists,
Expand Down Expand Up @@ -1074,7 +1074,7 @@ void ThinLTOCodeGenerator::run() {

// Collect the import/export lists for all modules from the call-graph in the
// combined index.
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists(ModuleCount);
FunctionImporter::ImportListsTy ImportLists(ModuleCount);
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists(ModuleCount);
ComputeCrossModuleImport(*Index, ModuleToDefinedGVSummaries,
IsPrevailing(PrevailingCopy), ImportLists,
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/IPO/FunctionImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ collectImportStatistics(const ModuleSummaryIndex &Index,
#ifndef NDEBUG
static bool checkVariableImport(
const ModuleSummaryIndex &Index,
DenseMap<StringRef, FunctionImporter::ImportMapTy> &ImportLists,
FunctionImporter::ImportListsTy &ImportLists,
DenseMap<StringRef, FunctionImporter::ExportSetTy> &ExportLists) {
DenseSet<GlobalValue::GUID> FlattenedImports;

Expand Down Expand Up @@ -1152,7 +1152,7 @@ void llvm::ComputeCrossModuleImport(
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
isPrevailing,
DenseMap<StringRef, FunctionImporter::ImportMapTy> &ImportLists,
FunctionImporter::ImportListsTy &ImportLists,
DenseMap<StringRef, FunctionImporter::ExportSetTy> &ExportLists) {
auto MIS = ModuleImportsManager::create(isPrevailing, Index, &ExportLists);
// For each module that has function defined, compute the import/export lists.
Expand Down

0 comments on commit 4f15039

Please sign in to comment.