Skip to content

Commit 7d37172

Browse files
[NFCI][BitcodeReader]Read real GUID from VI as opposed to storing it in map (llvm#107735)
Currently, `ValueIdToValueInfoMap` [1] stores `std::tuple<ValueInfo, GlobalValue::GUID /* original GUID */, GlobalValue::GUID /* real GUID*/ >`. This change updates the stored value type to `std::pair<ValueInfo, GlobalValue::GUID /* original GUID */>`, and reads real GUID from ValueInfo. When an entry is inserted into `ValueIdToValueInfoMap`, ValueInfo is created or inserted using real GUID [2]. ValueInfo keeps a pointer to GlobalValueMap [3], using either `GUID` or `{GUID, Name}` [4] when reading per-module summaries to create a combined summary. [1] owned by per module-summary bitcode reader https://github.com/llvm/llvm-project/blob/caebb4562ce634a22f7b13480b19cffc2a6a6730/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L947-L950 [2] [first](https://github.com/llvm/llvm-project/blob/caebb4562ce634a22f7b13480b19cffc2a6a6730/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L7130-L7133), [second](https://github.com/llvm/llvm-project/blob/caebb4562ce634a22f7b13480b19cffc2a6a6730/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L7221-L7222), [third](https://github.com/llvm/llvm-project/blob/caebb4562ce634a22f7b13480b19cffc2a6a6730/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L7622-L7623) [3] https://github.com/llvm/llvm-project/blob/caebb4562ce634a22f7b13480b19cffc2a6a6730/llvm/include/llvm/IR/ModuleSummaryIndex.h#L1427-L1431 [4] https://github.com/llvm/llvm-project/blob/caebb4562ce634a22f7b13480b19cffc2a6a6730/llvm/include/llvm/IR/ModuleSummaryIndex.h#L1631 and https://github.com/llvm/llvm-project/blob/caebb4562ce634a22f7b13480b19cffc2a6a6730/llvm/include/llvm/IR/ModuleSummaryIndex.h#L1621 --------- Co-authored-by: Kazu Hirata <[email protected]>
1 parent 60f052e commit 7d37172

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -943,10 +943,8 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase {
943943
// they are recorded in the summary index being built.
944944
// We save a GUID which refers to the same global as the ValueInfo, but
945945
// ignoring the linkage, i.e. for values other than local linkage they are
946-
// identical (this is the second tuple member).
947-
// The third tuple member is the real GUID of the ValueInfo.
948-
DenseMap<unsigned,
949-
std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>>
946+
// identical (this is the second member). ValueInfo has the real GUID.
947+
DenseMap<unsigned, std::pair<ValueInfo, GlobalValue::GUID>>
950948
ValueIdToValueInfoMap;
951949

952950
/// Map populated during module path string table parsing, from the
@@ -998,7 +996,7 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase {
998996
parseParamAccesses(ArrayRef<uint64_t> Record);
999997

1000998
template <bool AllowNullValueInfo = false>
1001-
std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
999+
std::pair<ValueInfo, GlobalValue::GUID>
10021000
getValueInfoFromValueId(unsigned ValueId);
10031001

10041002
void addThisModule();
@@ -7102,7 +7100,7 @@ ModuleSummaryIndexBitcodeReader::getThisModule() {
71027100
}
71037101

71047102
template <bool AllowNullValueInfo>
7105-
std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
7103+
std::pair<ValueInfo, GlobalValue::GUID>
71067104
ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned ValueId) {
71077105
auto VGI = ValueIdToValueInfoMap[ValueId];
71087106
// We can have a null value info for memprof callsite info records in
@@ -7129,10 +7127,10 @@ void ModuleSummaryIndexBitcodeReader::setValueGUID(
71297127
// UseStrtab is false for legacy summary formats and value names are
71307128
// created on stack. In that case we save the name in a string saver in
71317129
// the index so that the value name can be recorded.
7132-
ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7130+
ValueIdToValueInfoMap[ValueID] = std::make_pair(
71337131
TheIndex.getOrInsertValueInfo(
71347132
ValueGUID, UseStrtab ? ValueName : TheIndex.saveString(ValueName)),
7135-
OriginalNameID, ValueGUID);
7133+
OriginalNameID);
71367134
}
71377135

71387136
// Specialized value symbol table parser used when reading module index
@@ -7220,8 +7218,8 @@ Error ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
72207218
GlobalValue::GUID RefGUID = Record[1];
72217219
// The "original name", which is the second value of the pair will be
72227220
// overriden later by a FS_COMBINED_ORIGINAL_NAME in the combined index.
7223-
ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7224-
TheIndex.getOrInsertValueInfo(RefGUID), RefGUID, RefGUID);
7221+
ValueIdToValueInfoMap[ValueID] =
7222+
std::make_pair(TheIndex.getOrInsertValueInfo(RefGUID), RefGUID);
72257223
break;
72267224
}
72277225
}
@@ -7621,8 +7619,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
76217619
} else {
76227620
RefGUID = Record[1];
76237621
}
7624-
ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7625-
TheIndex.getOrInsertValueInfo(RefGUID), RefGUID, RefGUID);
7622+
ValueIdToValueInfoMap[ValueID] =
7623+
std::make_pair(TheIndex.getOrInsertValueInfo(RefGUID), RefGUID);
76267624
break;
76277625
}
76287626
// FS_PERMODULE is legacy and does not have support for the tail call flag.
@@ -7680,9 +7678,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
76807678
// the prevailing copy of a symbol. The linker doesn't resolve local
76817679
// linkage values so don't check whether those are prevailing.
76827680
auto LT = (GlobalValue::LinkageTypes)Flags.Linkage;
7683-
if (IsPrevailing &&
7684-
!GlobalValue::isLocalLinkage(LT) &&
7685-
!IsPrevailing(std::get<2>(VIAndOriginalGUID))) {
7681+
if (IsPrevailing && !GlobalValue::isLocalLinkage(LT) &&
7682+
!IsPrevailing(VIAndOriginalGUID.first.getGUID())) {
76867683
PendingCallsites.clear();
76877684
PendingAllocs.clear();
76887685
}

0 commit comments

Comments
 (0)