Skip to content

Commit

Permalink
[ThinLTOCodeGenerator] Avoid Rehash StringMap in ThreadPool
Browse files Browse the repository at this point in the history
Summary:
During threaded thinLTO, it is possible that the entry for current
module doesn't exist in StringMaps (like ExportLists, ResolvedODR,
etc.). Using operator[] might trigger a rehash for the StringMap, which
might happen on multiple threads at the same time.

rdar://problem/43846199

Reviewers: tejohnson, mehdi_amini, kromanova, pcc

Reviewed By: tejohnson

Subscribers: dang, inglorion, eraman, dexonsmith, llvm-commits

Differential Revision: https://reviews.llvm.org/D52049

llvm-svn: 342263
  • Loading branch information
cachemeifyoucan committed Sep 14, 2018
1 parent 5f6789e commit ec53c89
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions llvm/lib/LTO/ThinLTOCodeGenerator.cpp
Expand Up @@ -950,11 +950,15 @@ void ThinLTOCodeGenerator::run() {
// Changes are made in the index, consumed in the ThinLTO backends.
internalizeAndPromoteInIndex(ExportLists, GUIDPreservedSymbols, *Index);

// Make sure that every module has an entry in the ExportLists and
// ResolvedODR maps to enable threaded access to these maps below.
for (auto &DefinedGVSummaries : ModuleToDefinedGVSummaries) {
ExportLists[DefinedGVSummaries.first()];
ResolvedODR[DefinedGVSummaries.first()];
// Make sure that every module has an entry in the ExportLists, ImportList,
// GVSummary and ResolvedODR maps to enable threaded access to these maps
// below.
for (auto &Module : Modules) {
auto ModuleIdentifier = Module.getBufferIdentifier();
ExportLists[ModuleIdentifier];
ImportLists[ModuleIdentifier];
ResolvedODR[ModuleIdentifier];
ModuleToDefinedGVSummaries[ModuleIdentifier];
}

// Compute the ordering we will process the inputs: the rough heuristic here
Expand Down

0 comments on commit ec53c89

Please sign in to comment.