diff options
author | Teresa Johnson <tejohnson@google.com> | 2018-07-02 22:09:23 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2018-07-02 22:09:23 +0000 |
commit | 8fc766681d8172a81604276f3afdd47a1d3b6625 (patch) | |
tree | fa4a4b5295a21e331c97f07f9b9645e47f470862 /llvm/lib/IR/AsmWriter.cpp | |
parent | 696ce3770b741ef7f913b5eda73f0b2fda24e75c (diff) | |
download | bcm5719-llvm-8fc766681d8172a81604276f3afdd47a1d3b6625.tar.gz bcm5719-llvm-8fc766681d8172a81604276f3afdd47a1d3b6625.zip |
[ThinLTO] Fix printing of module paths for distributed backend indexes
Summary:
In the individual index files emitted for distributed ThinLTO backends,
the module path ids are not contiguous. Assign slots to module paths in
order to handle this better and also to get contiguous numbering in the
summary assembly.
Reviewers: davidxl, dexonsmith
Subscribers: mehdi_amini, inglorion, eraman, llvm-commits, steven_wu
Differential Revision: https://reviews.llvm.org/D48698
llvm-svn: 336148
Diffstat (limited to 'llvm/lib/IR/AsmWriter.cpp')
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index ba8db2bf41b..736a836b490 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -696,6 +696,10 @@ private: DenseMap<AttributeSet, unsigned> asMap; unsigned asNext = 0; + /// ModulePathMap - The slot map for Module paths used in the summary index. + StringMap<unsigned> ModulePathMap; + unsigned ModulePathNext = 0; + /// GUIDMap - The slot map for GUIDs used in the summary index. DenseMap<GlobalValue::GUID, unsigned> GUIDMap; unsigned GUIDNext = 0; @@ -729,6 +733,7 @@ public: int getGlobalSlot(const GlobalValue *V); int getMetadataSlot(const MDNode *N); int getAttributeGroupSlot(AttributeSet AS); + int getModulePathSlot(StringRef Path); int getGUIDSlot(GlobalValue::GUID GUID); /// If you'd like to deal with a function instead of just a module, use @@ -782,6 +787,7 @@ private: /// Insert the specified AttributeSet into the slot table. void CreateAttributeSetSlot(AttributeSet AS); + inline void CreateModulePathSlot(StringRef Path); void CreateGUIDSlot(GlobalValue::GUID GUID); /// Add all of the module level global variables (and their initializers) @@ -1005,8 +1011,16 @@ void SlotTracker::processIndex() { assert(TheIndex); // The first block of slots are just the module ids, which start at 0 and are - // assigned consecutively. Start numbering the GUIDs after the module ids. - GUIDNext = TheIndex->modulePaths().size(); + // assigned consecutively. Since the StringMap iteration order isn't + // guaranteed, use a std::map to order by module ID before assigning slots. + std::map<uint64_t, StringRef> ModuleIdToPathMap; + for (auto &ModPath : TheIndex->modulePaths()) + ModuleIdToPathMap[ModPath.second.first] = ModPath.first(); + for (auto &ModPair : ModuleIdToPathMap) + CreateModulePathSlot(ModPair.second); + + // Start numbering the GUIDs after the module ids. + GUIDNext = ModulePathNext; for (auto &GlobalList : *TheIndex) CreateGUIDSlot(GlobalList.first); @@ -1100,6 +1114,15 @@ int SlotTracker::getAttributeGroupSlot(AttributeSet AS) { return AI == asMap.end() ? -1 : (int)AI->second; } +int SlotTracker::getModulePathSlot(StringRef Path) { + // Check for uninitialized state and do lazy initialization. + initializeIndex(); + + // Find the Module path in the map + auto I = ModulePathMap.find(Path); + return I == ModulePathMap.end() ? -1 : (int)I->second; +} + int SlotTracker::getGUIDSlot(GlobalValue::GUID GUID) { // Check for uninitialized state and do lazy initialization. initializeIndex(); @@ -1169,6 +1192,11 @@ void SlotTracker::CreateAttributeSetSlot(AttributeSet AS) { asMap[AS] = DestSlot; } +/// Create a new slot for the specified Module +void SlotTracker::CreateModulePathSlot(StringRef Path) { + ModulePathMap[Path] = ModulePathNext++; +} + /// Create a new slot for the specified GUID void SlotTracker::CreateGUIDSlot(GlobalValue::GUID GUID) { GUIDMap[GUID] = GUIDNext++; @@ -2574,23 +2602,19 @@ void AssemblyWriter::printModuleSummaryIndex() { Out << "\n"; - // Print module path entries, using the module id as the slot number. To - // print in order, add paths to a vector indexed by module id. + // Print module path entries. To print in order, add paths to a vector + // indexed by module slot. std::vector<std::pair<std::string, ModuleHash>> moduleVec; std::string RegularLTOModuleName = "[Regular LTO]"; moduleVec.resize(TheIndex->modulePaths().size()); - for (auto &ModPath : TheIndex->modulePaths()) { - // A module id of -1 is a special entry for a regular LTO module created - // during the thin link. - if (ModPath.second.first == -1u) - moduleVec[TheIndex->modulePaths().size() - 1] = - std::make_pair(RegularLTOModuleName, ModPath.second.second); - else { - assert(ModPath.second.first < moduleVec.size()); - moduleVec[ModPath.second.first] = - std::make_pair(ModPath.first(), ModPath.second.second); - } - } + for (auto &ModPath : TheIndex->modulePaths()) + moduleVec[Machine.getModulePathSlot(ModPath.first())] = std::make_pair( + // A module id of -1 is a special entry for a regular LTO module created + // during the thin link. + ModPath.second.first == -1u ? RegularLTOModuleName + : (std::string)ModPath.first(), + ModPath.second.second); + unsigned i = 0; for (auto &ModPair : moduleVec) { Out << "^" << i++ << " = module: ("; @@ -2937,7 +2961,7 @@ void AssemblyWriter::printSummary(const GlobalValueSummary &Summary) { GlobalValueSummary::GVFlags GVFlags = Summary.flags(); GlobalValue::LinkageTypes LT = (GlobalValue::LinkageTypes)GVFlags.Linkage; Out << getSummaryKindName(Summary.getSummaryKind()) << ": "; - Out << "(module: ^" << TheIndex->getModuleId(Summary.modulePath()) + Out << "(module: ^" << Machine.getModulePathSlot(Summary.modulePath()) << ", flags: ("; Out << "linkage: " << getLinkageName(LT); Out << ", notEligibleToImport: " << GVFlags.NotEligibleToImport; |