diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 82 | ||||
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 36 |
3 files changed, 78 insertions, 53 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index b8444bc86d7..0d23bcaab56 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3903,12 +3903,13 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { NameVals.clear(); } - if (!Index.typeIds().empty()) { - for (auto &S : Index.typeIds()) { - // Skip if not referenced in any GV summary within this index file. - if (!ReferencedTypeIds.count(GlobalValue::getGUID(S.first))) - continue; - writeTypeIdSummaryRecord(NameVals, StrtabBuilder, S.first, S.second); + // Walk the GUIDs that were referenced, and write the + // corresponding type id records. + for (auto &T : ReferencedTypeIds) { + auto TidIter = Index.typeIds().equal_range(T); + for (auto It = TidIter.first; It != TidIter.second; ++It) { + writeTypeIdSummaryRecord(NameVals, StrtabBuilder, It->second.first, + It->second.second); Stream.EmitRecord(bitc::FS_TYPE_ID, NameVals); NameVals.clear(); } diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 536dbe064fc..387154ecfe5 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -705,6 +705,10 @@ private: DenseMap<GlobalValue::GUID, unsigned> GUIDMap; unsigned GUIDNext = 0; + /// TypeIdMap - The slot map for type ids used in the summary index. + StringMap<unsigned> TypeIdMap; + unsigned TypeIdNext = 0; + public: /// Construct from a module. /// @@ -736,6 +740,7 @@ public: int getAttributeGroupSlot(AttributeSet AS); int getModulePathSlot(StringRef Path); int getGUIDSlot(GlobalValue::GUID GUID); + int getTypeIdSlot(StringRef Id); /// If you'd like to deal with a function instead of just a module, use /// this method to get its data into the SlotTracker. @@ -790,6 +795,7 @@ private: inline void CreateModulePathSlot(StringRef Path); void CreateGUIDSlot(GlobalValue::GUID GUID); + void CreateTypeIdSlot(StringRef Id); /// Add all of the module level global variables (and their initializers) /// and function declarations, but not the contents of those functions. @@ -1026,8 +1032,12 @@ void SlotTracker::processIndex() { for (auto &GlobalList : *TheIndex) CreateGUIDSlot(GlobalList.first); - for (auto &TId : TheIndex->typeIds()) - CreateGUIDSlot(GlobalValue::getGUID(TId.first)); + // Start numbering the TypeIds after the GUIDs. + TypeIdNext = GUIDNext; + + for (auto TidIter = TheIndex->typeIds().begin(); + TidIter != TheIndex->typeIds().end(); TidIter++) + CreateTypeIdSlot(TidIter->second.first); ST_DEBUG("end processIndex!\n"); } @@ -1133,6 +1143,15 @@ int SlotTracker::getGUIDSlot(GlobalValue::GUID GUID) { return I == GUIDMap.end() ? -1 : (int)I->second; } +int SlotTracker::getTypeIdSlot(StringRef Id) { + // Check for uninitialized state and do lazy initialization. + initializeIndexIfNeeded(); + + // Find the TypeId string in the map + auto I = TypeIdMap.find(Id); + return I == TypeIdMap.end() ? -1 : (int)I->second; +} + /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. void SlotTracker::CreateModuleSlot(const GlobalValue *V) { assert(V && "Can't insert a null Value into SlotTracker!"); @@ -1203,6 +1222,11 @@ void SlotTracker::CreateGUIDSlot(GlobalValue::GUID GUID) { GUIDMap[GUID] = GUIDNext++; } +/// Create a new slot for the specified Id +void SlotTracker::CreateTypeIdSlot(StringRef Id) { + TypeIdMap[Id] = TypeIdNext++; +} + //===----------------------------------------------------------------------===// // AsmWriter Implementation //===----------------------------------------------------------------------===// @@ -2656,12 +2680,12 @@ void AssemblyWriter::printModuleSummaryIndex() { } // Print the TypeIdMap entries. - for (auto &TId : TheIndex->typeIds()) { - auto GUID = GlobalValue::getGUID(TId.first); - Out << "^" << Machine.getGUIDSlot(GUID) << " = typeid: (name: \"" - << TId.first << "\""; - printTypeIdSummary(TId.second); - Out << ") ; guid = " << GUID << "\n"; + for (auto TidIter = TheIndex->typeIds().begin(); + TidIter != TheIndex->typeIds().end(); TidIter++) { + Out << "^" << Machine.getTypeIdSlot(TidIter->second.first) + << " = typeid: (name: \"" << TidIter->second.first << "\""; + printTypeIdSummary(TidIter->second.second); + Out << ") ; guid = " << TidIter->first << "\n"; } } @@ -2894,12 +2918,19 @@ void AssemblyWriter::printTypeIdInfo( Out << "typeTests: ("; FieldSeparator FS; for (auto &GUID : TIDInfo.TypeTests) { - Out << FS; - auto Slot = Machine.getGUIDSlot(GUID); - if (Slot != -1) - Out << "^" << Slot; - else + auto TidIter = TheIndex->typeIds().equal_range(GUID); + if (TidIter.first == TidIter.second) { + Out << FS; Out << GUID; + continue; + } + // Print all type id that correspond to this GUID. + for (auto It = TidIter.first; It != TidIter.second; ++It) { + Out << FS; + auto Slot = Machine.getTypeIdSlot(It->second.first); + assert(Slot != -1); + Out << "^" << Slot; + } } Out << ")"; } @@ -2925,14 +2956,25 @@ void AssemblyWriter::printTypeIdInfo( } void AssemblyWriter::printVFuncId(const FunctionSummary::VFuncId VFId) { - Out << "vFuncId: ("; - auto Slot = Machine.getGUIDSlot(VFId.GUID); - if (Slot != -1) - Out << "^" << Slot; - else + auto TidIter = TheIndex->typeIds().equal_range(VFId.GUID); + if (TidIter.first == TidIter.second) { + Out << "vFuncId: ("; Out << "guid: " << VFId.GUID; - Out << ", offset: " << VFId.Offset; - Out << ")"; + Out << ", offset: " << VFId.Offset; + Out << ")"; + return; + } + // Print all type id that correspond to this GUID. + FieldSeparator FS; + for (auto It = TidIter.first; It != TidIter.second; ++It) { + Out << FS; + Out << "vFuncId: ("; + auto Slot = Machine.getTypeIdSlot(It->second.first); + assert(Slot != -1); + Out << "^" << Slot; + Out << ", offset: " << VFId.Offset; + Out << ")"; + } } void AssemblyWriter::printNonConstVCalls( diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 68d210cb7d7..50d0075a608 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -56,12 +56,6 @@ static cl::opt<bool> DumpThinCGSCCs("dump-thin-cg-sccs", cl::init(false), cl::Hidden, cl::desc("Dump the SCCs in the ThinLTO index's callgraph")); -// The values are (type identifier, summary) pairs. -typedef DenseMap< - GlobalValue::GUID, - TinyPtrVector<const std::pair<const std::string, TypeIdSummary> *>> - TypeIdSummariesByGuidTy; - // Returns a unique hash for the Module considering the current list of // export/import and other global analysis results. // The hash is produced in \p Key. @@ -71,7 +65,6 @@ static void computeCacheKey( const FunctionImporter::ExportSetTy &ExportList, const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR, const GVSummaryMapTy &DefinedGlobals, - const TypeIdSummariesByGuidTy &TypeIdSummariesByGuid, const std::set<GlobalValue::GUID> &CfiFunctionDefs, const std::set<GlobalValue::GUID> &CfiFunctionDecls) { // Compute the unique hash for this entry. @@ -255,10 +248,9 @@ static void computeCacheKey( // Include the hash for all type identifiers used by this module. for (GlobalValue::GUID TId : UsedTypeIds) { - auto SummariesI = TypeIdSummariesByGuid.find(TId); - if (SummariesI != TypeIdSummariesByGuid.end()) - for (auto *Summary : SummariesI->second) - AddTypeIdSummary(Summary->first, Summary->second); + auto TidIter = Index.typeIds().equal_range(TId); + for (auto It = TidIter.first; It != TidIter.second; ++It) + AddTypeIdSummary(It->second.first, It->second.second); } AddUnsigned(UsedCfiDefs.size()); @@ -917,7 +909,6 @@ class InProcessThinBackend : public ThinBackendProc { ThreadPool BackendThreadPool; AddStreamFn AddStream; NativeObjectCache Cache; - TypeIdSummariesByGuidTy TypeIdSummariesByGuid; std::set<GlobalValue::GUID> CfiFunctionDefs; std::set<GlobalValue::GUID> CfiFunctionDecls; @@ -933,12 +924,6 @@ public: : ThinBackendProc(Conf, CombinedIndex, ModuleToDefinedGVSummaries), BackendThreadPool(ThinLTOParallelismLevel), AddStream(std::move(AddStream)), Cache(std::move(Cache)) { - // Create a mapping from type identifier GUIDs to type identifier summaries. - // This allows backends to use the type identifier GUIDs stored in the - // function summaries to determine which type identifier summaries affect - // each function without needing to compute GUIDs in each backend. - for (auto &TId : CombinedIndex.typeIds()) - TypeIdSummariesByGuid[GlobalValue::getGUID(TId.first)].push_back(&TId); for (auto &Name : CombinedIndex.cfiFunctionDefs()) CfiFunctionDefs.insert( GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(Name))); @@ -954,8 +939,7 @@ public: const FunctionImporter::ExportSetTy &ExportList, const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR, const GVSummaryMapTy &DefinedGlobals, - MapVector<StringRef, BitcodeModule> &ModuleMap, - const TypeIdSummariesByGuidTy &TypeIdSummariesByGuid) { + MapVector<StringRef, BitcodeModule> &ModuleMap) { auto RunThinBackend = [&](AddStreamFn AddStream) { LTOLLVMContext BackendContext(Conf); Expected<std::unique_ptr<Module>> MOrErr = BM.parseModule(BackendContext); @@ -978,8 +962,8 @@ public: SmallString<40> Key; // The module may be cached, this helps handling it. computeCacheKey(Key, Conf, CombinedIndex, ModuleID, ImportList, ExportList, - ResolvedODR, DefinedGlobals, TypeIdSummariesByGuid, - CfiFunctionDefs, CfiFunctionDecls); + ResolvedODR, DefinedGlobals, CfiFunctionDefs, + CfiFunctionDecls); if (AddStreamFn CacheAddStream = Cache(Task, Key)) return RunThinBackend(CacheAddStream); @@ -1003,11 +987,10 @@ public: const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR, const GVSummaryMapTy &DefinedGlobals, - MapVector<StringRef, BitcodeModule> &ModuleMap, - const TypeIdSummariesByGuidTy &TypeIdSummariesByGuid) { + MapVector<StringRef, BitcodeModule> &ModuleMap) { Error E = runThinLTOBackendThread( AddStream, Cache, Task, BM, CombinedIndex, ImportList, ExportList, - ResolvedODR, DefinedGlobals, ModuleMap, TypeIdSummariesByGuid); + ResolvedODR, DefinedGlobals, ModuleMap); if (E) { std::unique_lock<std::mutex> L(ErrMu); if (Err) @@ -1017,8 +1000,7 @@ public: } }, BM, std::ref(CombinedIndex), std::ref(ImportList), std::ref(ExportList), - std::ref(ResolvedODR), std::ref(DefinedGlobals), std::ref(ModuleMap), - std::ref(TypeIdSummariesByGuid)); + std::ref(ResolvedODR), std::ref(DefinedGlobals), std::ref(ModuleMap)); return Error::success(); } |