diff options
Diffstat (limited to 'llvm/include/llvm/IR/ModuleSummaryIndex.h')
-rw-r--r-- | llvm/include/llvm/IR/ModuleSummaryIndex.h | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h index 9cf8c751e6c..778907b05eb 100644 --- a/llvm/include/llvm/IR/ModuleSummaryIndex.h +++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h @@ -23,6 +23,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/TinyPtrVector.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/Module.h" #include "llvm/Support/Allocator.h" @@ -753,6 +754,11 @@ using ModulePathStringTableTy = StringMap<std::pair<uint64_t, ModuleHash>>; /// a particular module, and provide efficient access to their summary. using GVSummaryMapTy = DenseMap<GlobalValue::GUID, GlobalValueSummary *>; +/// Map of a type GUID to type id string and summary (multimap used +/// in case of GUID conflicts). +using TypeIdSummaryMapTy = + std::multimap<GlobalValue::GUID, std::pair<std::string, TypeIdSummary>>; + /// Class to hold module path string table and global value map, /// and encapsulate methods for operating on them. class ModuleSummaryIndex { @@ -764,9 +770,9 @@ private: /// Holds strings for combined index, mapping to the corresponding module ID. ModulePathStringTableTy ModulePathStringTable; - /// Mapping from type identifiers to summary information for that type - /// identifier. - std::map<std::string, TypeIdSummary> TypeIdMap; + /// Mapping from type identifier GUIDs to type identifier and its summary + /// information. + TypeIdSummaryMapTy TypeIdMap; /// Mapping from original ID to GUID. If original ID can map to multiple /// GUIDs, it will be mapped to 0. @@ -1079,23 +1085,29 @@ public: return ModulePathStringTable.count(M.getModuleIdentifier()); } - const std::map<std::string, TypeIdSummary> &typeIds() const { - return TypeIdMap; - } + const TypeIdSummaryMapTy &typeIds() const { return TypeIdMap; } - /// This accessor should only be used when exporting because it can mutate the - /// map. + /// Return an existing or new TypeIdSummary entry for \p TypeId. + /// This accessor can mutate the map and therefore should not be used in + /// the ThinLTO backends. TypeIdSummary &getOrInsertTypeIdSummary(StringRef TypeId) { - return TypeIdMap[TypeId]; + auto TidIter = TypeIdMap.equal_range(GlobalValue::getGUID(TypeId)); + for (auto It = TidIter.first; It != TidIter.second; ++It) + if (It->second.first == TypeId) + return It->second.second; + auto It = TypeIdMap.insert( + {GlobalValue::getGUID(TypeId), {TypeId, TypeIdSummary()}}); + return It->second.second; } /// This returns either a pointer to the type id summary (if present in the /// summary map) or null (if not present). This may be used when importing. const TypeIdSummary *getTypeIdSummary(StringRef TypeId) const { - auto I = TypeIdMap.find(TypeId); - if (I == TypeIdMap.end()) - return nullptr; - return &I->second; + auto TidIter = TypeIdMap.equal_range(GlobalValue::getGUID(TypeId)); + for (auto It = TidIter.first; It != TidIter.second; ++It) + if (It->second.first == TypeId) + return &It->second.second; + return nullptr; } /// Collect for the given module the list of functions it defines |