Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions llvm/include/llvm/IR/ModuleSummaryIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ using GVSummaryPtrSet = std::unordered_set<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>>;
std::multimap<GlobalValue::GUID, std::pair<StringRef, TypeIdSummary>>;

/// The following data structures summarize type metadata information.
/// For type metadata overview see https://llvm.org/docs/TypeMetadata.html.
Expand Down Expand Up @@ -1351,6 +1351,9 @@ class ModuleSummaryIndex {
/// Holds strings for combined index, mapping to the corresponding module ID.
ModulePathStringTableTy ModulePathStringTable;

BumpPtrAllocator TypeIdSaverAlloc;
UniqueStringSaver TypeIdSaver;

/// Mapping from type identifier GUIDs to type identifier and its summary
/// information. Produced by thin link.
TypeIdSummaryMapTy TypeIdMap;
Expand All @@ -1359,7 +1362,7 @@ class ModuleSummaryIndex {
/// with that type identifier's metadata. Produced by per module summary
/// analysis and consumed by thin link. For more information, see description
/// above where TypeIdCompatibleVtableInfo is defined.
std::map<std::string, TypeIdCompatibleVtableInfo, std::less<>>
std::map<StringRef, TypeIdCompatibleVtableInfo, std::less<>>
TypeIdCompatibleVtableMap;

/// Mapping from original ID to GUID. If original ID can map to multiple
Expand Down Expand Up @@ -1455,8 +1458,9 @@ class ModuleSummaryIndex {
// See HaveGVs variable comment.
ModuleSummaryIndex(bool HaveGVs, bool EnableSplitLTOUnit = false,
bool UnifiedLTO = false)
: HaveGVs(HaveGVs), EnableSplitLTOUnit(EnableSplitLTOUnit),
UnifiedLTO(UnifiedLTO), Saver(Alloc) {}
: TypeIdSaver(TypeIdSaverAlloc), HaveGVs(HaveGVs),
EnableSplitLTOUnit(EnableSplitLTOUnit), UnifiedLTO(UnifiedLTO),
Saver(Alloc) {}

// Current version for the module summary in bitcode files.
// The BitcodeSummaryVersion should be bumped whenever we introduce changes
Expand Down Expand Up @@ -1829,8 +1833,8 @@ class ModuleSummaryIndex {
for (auto &[GUID, TypeIdPair] : make_range(TidIter))
if (TypeIdPair.first == TypeId)
return TypeIdPair.second;
auto It = TypeIdMap.insert(
{GlobalValue::getGUID(TypeId), {std::string(TypeId), TypeIdSummary()}});
auto It = TypeIdMap.insert({GlobalValue::getGUID(TypeId),
{TypeIdSaver.save(TypeId), TypeIdSummary()}});
return It->second.second;
}

Expand Down Expand Up @@ -1859,7 +1863,7 @@ class ModuleSummaryIndex {
/// the ThinLTO backends.
TypeIdCompatibleVtableInfo &
getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId) {
return TypeIdCompatibleVtableMap[std::string(TypeId)];
return TypeIdCompatibleVtableMap[TypeIdSaver.save(TypeId)];
}

/// For the given \p TypeId, this returns the TypeIdCompatibleVtableMap
Expand Down
20 changes: 17 additions & 3 deletions llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ template <> struct CustomMappingTraits<TypeIdSummaryMapTy> {
static void inputOne(IO &io, StringRef Key, TypeIdSummaryMapTy &V) {
TypeIdSummary TId;
io.mapRequired(Key.str().c_str(), TId);
V.insert({GlobalValue::getGUID(Key), {std::string(Key), TId}});
V.insert({GlobalValue::getGUID(Key), {Key, TId}});
}
static void output(IO &io, TypeIdSummaryMapTy &V) {
for (auto &TidIter : V)
io.mapRequired(TidIter.second.first.c_str(), TidIter.second.second);
io.mapRequired(TidIter.second.first.str().c_str(), TidIter.second.second);
}
};

Expand All @@ -327,7 +327,21 @@ template <> struct MappingTraits<ModuleSummaryIndex> {
if (!io.outputting())
CustomMappingTraits<GlobalValueSummaryMapTy>::fixAliaseeLinks(
index.GlobalValueMap);
io.mapOptional("TypeIdMap", index.TypeIdMap);

if (io.outputting()) {
io.mapOptional("TypeIdMap", index.TypeIdMap);
} else {
TypeIdSummaryMapTy TypeIdMap;
io.mapOptional("TypeIdMap", TypeIdMap);
for (auto &[TypeGUID, TypeIdSummaryMap] : TypeIdMap) {
// Save type id references in index and point TypeIdMap to use the
// references owned by index.
StringRef KeyRef = index.TypeIdSaver.save(TypeIdSummaryMap.first);
index.TypeIdMap.insert(
{TypeGUID, {KeyRef, std::move(TypeIdSummaryMap.second)}});
}
}

io.mapOptional("WithGlobalValueDeadStripping",
index.WithGlobalValueDeadStripping);

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4165,7 +4165,7 @@ static void writeWholeProgramDevirtResolution(

static void writeTypeIdSummaryRecord(SmallVector<uint64_t, 64> &NameVals,
StringTableBuilder &StrtabBuilder,
const std::string &Id,
StringRef Id,
const TypeIdSummary &Summary) {
NameVals.push_back(StrtabBuilder.add(Id));
NameVals.push_back(Id.size());
Expand All @@ -4184,7 +4184,7 @@ static void writeTypeIdSummaryRecord(SmallVector<uint64_t, 64> &NameVals,

static void writeTypeIdCompatibleVtableSummaryRecord(
SmallVector<uint64_t, 64> &NameVals, StringTableBuilder &StrtabBuilder,
const std::string &Id, const TypeIdCompatibleVtableInfo &Summary,
StringRef Id, const TypeIdCompatibleVtableInfo &Summary,
ValueEnumerator &VE) {
NameVals.push_back(StrtabBuilder.add(Id));
NameVals.push_back(Id.size());
Expand Down
Loading