-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[ThinLTO] Use a set rather than a map to track exported ValueInfos. #97360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,8 +400,7 @@ class GlobalsImporter final { | |
// later, in ComputeCrossModuleImport, after import decisions are | ||
// complete, which is more efficient than adding them here. | ||
if (ExportLists) | ||
(*ExportLists)[RefSummary->modulePath()][VI] = | ||
GlobalValueSummary::Definition; | ||
(*ExportLists)[RefSummary->modulePath()].insert(VI); | ||
|
||
// If variable is not writeonly we attempt to recursively analyze | ||
// its references in order to import referenced constants. | ||
|
@@ -582,7 +581,7 @@ class WorkloadImportsManager : public ModuleImportsManager { | |
GlobalValueSummary::Definition; | ||
GVI.onImportingSummary(*GVS); | ||
if (ExportLists) | ||
(*ExportLists)[ExportingModule][VI] = GlobalValueSummary::Definition; | ||
(*ExportLists)[ExportingModule].insert(VI); | ||
} | ||
LLVM_DEBUG(dbgs() << "[Workload] Done\n"); | ||
} | ||
|
@@ -818,10 +817,8 @@ static void computeImportForFunction( | |
// Since definition takes precedence over declaration for the same VI, | ||
// try emplace <VI, declaration> pair without checking insert result. | ||
// If insert doesn't happen, there must be an existing entry keyed by | ||
// VI. | ||
if (ExportLists) | ||
(*ExportLists)[DeclSourceModule].try_emplace( | ||
VI, GlobalValueSummary::Declaration); | ||
// VI. Note `ExportLists` only keeps track of exports due to imported | ||
// definitions. | ||
ImportList[DeclSourceModule].try_emplace( | ||
VI.getGUID(), GlobalValueSummary::Declaration); | ||
} | ||
|
@@ -892,7 +889,7 @@ static void computeImportForFunction( | |
// later, in ComputeCrossModuleImport, after import decisions are | ||
// complete, which is more efficient than adding them here. | ||
if (ExportLists) | ||
(*ExportLists)[ExportModulePath][VI] = GlobalValueSummary::Definition; | ||
(*ExportLists)[ExportModulePath].insert(VI); | ||
} | ||
|
||
auto GetAdjustedThreshold = [](unsigned Threshold, bool IsHotCallsite) { | ||
|
@@ -998,19 +995,29 @@ static bool isGlobalVarSummary(const ModuleSummaryIndex &Index, | |
return false; | ||
} | ||
|
||
template <class T> | ||
static unsigned numGlobalVarSummaries(const ModuleSummaryIndex &Index, T &Cont, | ||
unsigned &DefinedGVS, | ||
unsigned &DefinedFS) { | ||
// Return the number of global summaries in ExportSet. | ||
static unsigned | ||
numGlobalVarSummaries(const ModuleSummaryIndex &Index, | ||
FunctionImporter::ExportSetTy &ExportSet) { | ||
unsigned NumGVS = 0; | ||
for (auto &VI : ExportSet) | ||
if (isGlobalVarSummary(Index, VI.getGUID())) | ||
++NumGVS; | ||
return NumGVS; | ||
} | ||
|
||
// Given ImportMap, return the number of global summaries and record the number | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
// of defined function summaries as output parameter. | ||
static unsigned | ||
numGlobalVarSummaries(const ModuleSummaryIndex &Index, | ||
FunctionImporter::FunctionsToImportTy &ImportMap, | ||
unsigned &DefinedFS) { | ||
unsigned NumGVS = 0; | ||
DefinedGVS = 0; | ||
DefinedFS = 0; | ||
for (auto &[GUID, Type] : Cont) { | ||
if (isGlobalVarSummary(Index, GUID)) { | ||
if (Type == GlobalValueSummary::Definition) | ||
++DefinedGVS; | ||
for (auto &[GUID, Type] : ImportMap) { | ||
if (isGlobalVarSummary(Index, GUID)) | ||
++NumGVS; | ||
} else if (Type == GlobalValueSummary::Definition) | ||
else if (Type == GlobalValueSummary::Definition) | ||
++DefinedFS; | ||
} | ||
return NumGVS; | ||
|
@@ -1046,7 +1053,7 @@ static bool checkVariableImport( | |
}; | ||
|
||
for (auto &ExportPerModule : ExportLists) | ||
for (auto &[VI, Unused] : ExportPerModule.second) | ||
for (auto &VI : ExportPerModule.second) | ||
if (!FlattenedImports.count(VI.getGUID()) && | ||
IsReadOrWriteOnlyVarNeedingImporting(ExportPerModule.first, VI)) | ||
return false; | ||
|
@@ -1079,14 +1086,12 @@ void llvm::ComputeCrossModuleImport( | |
// since we may import the same values multiple times into different modules | ||
// during the import computation. | ||
for (auto &ELI : ExportLists) { | ||
// `NewExports` tracks the VI that gets exported because the full definition | ||
// of its user/referencer gets exported. | ||
FunctionImporter::ExportSetTy NewExports; | ||
const auto &DefinedGVSummaries = | ||
ModuleToDefinedGVSummaries.lookup(ELI.first); | ||
for (auto &[EI, Type] : ELI.second) { | ||
// If a variable is exported as a declaration, its 'refs' and 'calls' are | ||
// not further exported. | ||
if (Type == GlobalValueSummary::Declaration) | ||
continue; | ||
for (auto &EI : ELI.second) { | ||
// Find the copy defined in the exporting module so that we can mark the | ||
// values it references in that specific definition as exported. | ||
// Below we will add all references and called values, without regard to | ||
|
@@ -1105,31 +1110,22 @@ void llvm::ComputeCrossModuleImport( | |
// we convert such variables initializers to "zeroinitializer". | ||
// See processGlobalForThinLTO. | ||
if (!Index.isWriteOnly(GVS)) | ||
for (const auto &VI : GVS->refs()) { | ||
// Try to emplace the declaration entry. If a definition entry | ||
// already exists for key `VI`, this is a no-op. | ||
NewExports.try_emplace(VI, GlobalValueSummary::Declaration); | ||
} | ||
for (const auto &VI : GVS->refs()) | ||
NewExports.insert(VI); | ||
} else { | ||
auto *FS = cast<FunctionSummary>(S); | ||
for (const auto &Edge : FS->calls()) { | ||
// Try to emplace the declaration entry. If a definition entry | ||
// already exists for key `VI`, this is a no-op. | ||
NewExports.try_emplace(Edge.first, GlobalValueSummary::Declaration); | ||
} | ||
for (const auto &Ref : FS->refs()) { | ||
// Try to emplace the declaration entry. If a definition entry | ||
// already exists for key `VI`, this is a no-op. | ||
NewExports.try_emplace(Ref, GlobalValueSummary::Declaration); | ||
} | ||
for (const auto &Edge : FS->calls()) | ||
NewExports.insert(Edge.first); | ||
for (const auto &Ref : FS->refs()) | ||
NewExports.insert(Ref); | ||
} | ||
} | ||
// Prune list computed above to only include values defined in the | ||
// exporting module. We do this after the above insertion since we may hit | ||
// the same ref/call target multiple times in above loop, and it is more | ||
// efficient to avoid a set lookup each time. | ||
for (auto EI = NewExports.begin(); EI != NewExports.end();) { | ||
if (!DefinedGVSummaries.count(EI->first.getGUID())) | ||
if (!DefinedGVSummaries.count(EI->getGUID())) | ||
NewExports.erase(EI++); | ||
else | ||
++EI; | ||
|
@@ -1144,29 +1140,22 @@ void llvm::ComputeCrossModuleImport( | |
for (auto &ModuleImports : ImportLists) { | ||
auto ModName = ModuleImports.first; | ||
auto &Exports = ExportLists[ModName]; | ||
unsigned DefinedGVS = 0, DefinedFS = 0; | ||
unsigned NumGVS = | ||
numGlobalVarSummaries(Index, Exports, DefinedGVS, DefinedFS); | ||
LLVM_DEBUG(dbgs() << "* Module " << ModName << " exports " << DefinedFS | ||
<< " function as definitions, " | ||
<< Exports.size() - NumGVS - DefinedFS | ||
<< " functions as declarations, " << DefinedGVS | ||
<< " var definitions and " << NumGVS - DefinedGVS | ||
<< " var declarations. Imports from " | ||
<< ModuleImports.second.size() << " modules.\n"); | ||
unsigned NumGVS = numGlobalVarSummaries(Index, Exports); | ||
LLVM_DEBUG(dbgs() << "* Module " << ModName << " exports " | ||
<< Exports.size() - NumGVS << " functions and " << NumGVS | ||
<< " vars. Imports from " << ModuleImports.second.size() | ||
<< " modules.\n"); | ||
for (auto &Src : ModuleImports.second) { | ||
auto SrcModName = Src.first; | ||
unsigned DefinedGVS = 0, DefinedFS = 0; | ||
unsigned DefinedFS = 0; | ||
unsigned NumGVSPerMod = | ||
numGlobalVarSummaries(Index, Src.second, DefinedGVS, DefinedFS); | ||
numGlobalVarSummaries(Index, Src.second, DefinedFS); | ||
LLVM_DEBUG(dbgs() << " - " << DefinedFS << " function definitions and " | ||
<< Src.second.size() - NumGVSPerMod - DefinedFS | ||
<< " function declarations imported from " << SrcModName | ||
<< "\n"); | ||
LLVM_DEBUG(dbgs() << " - " << DefinedGVS << " global vars definition and " | ||
<< NumGVSPerMod - DefinedGVS | ||
<< " global vars declaration imported from " | ||
<< SrcModName << "\n"); | ||
LLVM_DEBUG(dbgs() << " - " << NumGVSPerMod | ||
<< " global vars imported from " << SrcModName << "\n"); | ||
} | ||
} | ||
#endif | ||
|
@@ -1180,17 +1169,14 @@ static void dumpImportListForModule(const ModuleSummaryIndex &Index, | |
<< ImportList.size() << " modules.\n"); | ||
for (auto &Src : ImportList) { | ||
auto SrcModName = Src.first; | ||
unsigned DefinedGVS = 0, DefinedFS = 0; | ||
unsigned NumGVSPerMod = | ||
numGlobalVarSummaries(Index, Src.second, DefinedGVS, DefinedFS); | ||
unsigned DefinedFS = 0; | ||
unsigned NumGVSPerMod = numGlobalVarSummaries(Index, Src.second, DefinedFS); | ||
LLVM_DEBUG(dbgs() << " - " << DefinedFS << " function definitions and " | ||
<< Src.second.size() - DefinedFS - NumGVSPerMod | ||
<< " function declarations imported from " << SrcModName | ||
<< "\n"); | ||
LLVM_DEBUG(dbgs() << " - " << DefinedGVS << " var definitions and " | ||
<< NumGVSPerMod - DefinedGVS | ||
<< " var declarations imported from " << SrcModName | ||
<< "\n"); | ||
LLVM_DEBUG(dbgs() << " - " << NumGVSPerMod << " vars imported from " | ||
<< SrcModName << "\n"); | ||
} | ||
} | ||
#endif | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"global variable summaries" (to distinguish from global value summaries).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.