Skip to content

Commit 5d46d7e

Browse files
committed
[PDB] Use one func id DenseMap instead of per-source maps, NFC
This avoids some DenseMap copies when /Zi is in use, and results in fewer data structures. Differential Revision: https://reviews.llvm.org/D88617
1 parent 9d1c8c0 commit 5d46d7e

File tree

4 files changed

+36
-29
lines changed

4 files changed

+36
-29
lines changed

lld/COFF/DebugTypes.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,6 @@ Error UsePrecompSource::mergeInPrecompHeaderObj() {
525525
precompSrc->tpiMap.begin() +
526526
precompDependency.getTypesCount());
527527

528-
if (config->debugGHashes)
529-
funcIdToType = precompSrc->funcIdToType; // FIXME: Save copy
530-
531528
return Error::success();
532529
}
533530

@@ -612,7 +609,7 @@ void TpiSource::fillIsItemIndexFromDebugT() {
612609
});
613610
}
614611

615-
void TpiSource::mergeTypeRecord(CVType ty) {
612+
void TpiSource::mergeTypeRecord(TypeIndex curIndex, CVType ty) {
616613
// Decide if the merged type goes into TPI or IPI.
617614
bool isItem = isIdRecord(ty.kind());
618615
MergedInfo &merged = isItem ? mergedIpi : mergedTpi;
@@ -637,6 +634,25 @@ void TpiSource::mergeTypeRecord(CVType ty) {
637634
uint32_t pdbHash = check(pdb::hashTypeRecord(CVType(newRec)));
638635
merged.recSizes.push_back(static_cast<uint16_t>(newSize));
639636
merged.recHashes.push_back(pdbHash);
637+
638+
// Retain a mapping from PDB function id to PDB function type. This mapping is
639+
// used during symbol procesing to rewrite S_GPROC32_ID symbols to S_GPROC32
640+
// symbols.
641+
if (ty.kind() == LF_FUNC_ID || ty.kind() == LF_MFUNC_ID) {
642+
bool success = ty.length() >= 12;
643+
TypeIndex funcId = curIndex;
644+
if (success)
645+
success &= remapTypeIndex(funcId, TiRefKind::IndexRef);
646+
TypeIndex funcType =
647+
*reinterpret_cast<const TypeIndex *>(&newRec.data()[8]);
648+
if (success) {
649+
funcIdToType.push_back({funcId, funcType});
650+
} else {
651+
StringRef fname = file ? file->getName() : "<unknown PDB>";
652+
warn("corrupt LF_[M]FUNC_ID record 0x" + utohexstr(curIndex.getIndex()) +
653+
" in " + fname);
654+
}
655+
}
640656
}
641657

642658
void TpiSource::mergeUniqueTypeRecords(ArrayRef<uint8_t> typeRecords,
@@ -655,27 +671,9 @@ void TpiSource::mergeUniqueTypeRecords(ArrayRef<uint8_t> typeRecords,
655671
forEachTypeChecked(typeRecords, [&](const CVType &ty) {
656672
if (nextUniqueIndex != uniqueTypes.end() &&
657673
*nextUniqueIndex == ghashIndex) {
658-
mergeTypeRecord(ty);
674+
mergeTypeRecord(beginIndex + ghashIndex, ty);
659675
++nextUniqueIndex;
660676
}
661-
if (ty.kind() == LF_FUNC_ID || ty.kind() == LF_MFUNC_ID) {
662-
bool success = ty.length() >= 12;
663-
TypeIndex srcFuncIdIndex = beginIndex + ghashIndex;
664-
TypeIndex funcId = srcFuncIdIndex;
665-
TypeIndex funcType;
666-
if (success) {
667-
funcType = *reinterpret_cast<const TypeIndex *>(&ty.data()[8]);
668-
success &= remapTypeIndex(funcId, TiRefKind::IndexRef);
669-
success &= remapTypeIndex(funcType, TiRefKind::TypeRef);
670-
}
671-
if (success) {
672-
funcIdToType.insert({funcId, funcType});
673-
} else {
674-
StringRef fname = file ? file->getName() : "<unknown PDB>";
675-
warn("corrupt LF_[M]FUNC_ID record 0x" +
676-
utohexstr(srcFuncIdIndex.getIndex()) + " in " + fname);
677-
}
678-
}
679677
++ghashIndex;
680678
});
681679
assert(nextUniqueIndex == uniqueTypes.end() &&
@@ -758,7 +756,6 @@ void TypeServerSource::remapTpiWithGHashes(GHashState *g) {
758756
ipiSrc->tpiMap = tpiMap;
759757
ipiSrc->ipiMap = ipiMap;
760758
ipiSrc->mergeUniqueTypeRecords(typeArrayToBytes(ipi.typeArray()));
761-
funcIdToType = ipiSrc->funcIdToType; // FIXME: Save copy
762759
}
763760
}
764761

@@ -775,7 +772,6 @@ void UseTypeServerSource::remapTpiWithGHashes(GHashState *g) {
775772
TypeServerSource *tsSrc = *maybeTsSrc;
776773
tpiMap = tsSrc->tpiMap;
777774
ipiMap = tsSrc->ipiMap;
778-
funcIdToType = tsSrc->funcIdToType; // FIXME: Save copy
779775
}
780776

781777
void PrecompSource::loadGHashes() {
@@ -1102,6 +1098,13 @@ void TypeMerger::mergeTypesWithGHash() {
11021098
source->remapTpiWithGHashes(&ghashState);
11031099
});
11041100

1101+
// Build a global map of from function ID to function type.
1102+
for (TpiSource *source : TpiSource::instances) {
1103+
for (auto idToType : source->funcIdToType)
1104+
funcIdToType.insert(idToType);
1105+
source->funcIdToType.clear();
1106+
}
1107+
11051108
TpiSource::clearGHashes();
11061109
}
11071110

lld/COFF/DebugTypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class TpiSource {
7272
void remapRecord(MutableArrayRef<uint8_t> rec,
7373
ArrayRef<llvm::codeview::TiReference> typeRefs);
7474

75-
void mergeTypeRecord(llvm::codeview::CVType ty);
75+
void mergeTypeRecord(TypeIndex curIndex, llvm::codeview::CVType ty);
7676

7777
// Merge the type records listed in uniqueTypes. beginIndex is the TypeIndex
7878
// of the first record in this source, typically 0x1000. When PCHs are
@@ -164,7 +164,7 @@ class TpiSource {
164164

165165
/// When ghashing is used, record the mapping from LF_[M]FUNC_ID to function
166166
/// type index here. Both indices are PDB indices, not object type indexes.
167-
llvm::DenseMap<TypeIndex, TypeIndex> funcIdToType;
167+
std::vector<std::pair<TypeIndex, TypeIndex>> funcIdToType;
168168

169169
/// Indicates if a type record is an item index or a type index.
170170
llvm::BitVector isItemIndex;

lld/COFF/PDB.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ static void translateIdSymbols(MutableArrayRef<uint8_t> &recordData,
334334
// in both cases we just need the second type index.
335335
if (!ti->isSimple() && !ti->isNoneType()) {
336336
if (config->debugGHashes) {
337-
auto idToType = source->funcIdToType.find(*ti);
338-
if (idToType == source->funcIdToType.end()) {
337+
auto idToType = tMerger.funcIdToType.find(*ti);
338+
if (idToType == tMerger.funcIdToType.end()) {
339339
warn(formatv("S_[GL]PROC32_ID record in {0} refers to PDB item "
340340
"index {1:X} which is not a LF_[M]FUNC_ID record",
341341
source->file->getName(), ti->getIndex()));

lld/COFF/TypeMerger.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class TypeMerger {
4545
/// indices in each TpiSource.
4646
void mergeTypesWithGHash();
4747

48+
/// Map from PDB function id type indexes to PDB function type indexes.
49+
/// Populated after mergeTypesWithGHash.
50+
llvm::DenseMap<TypeIndex, TypeIndex> funcIdToType;
51+
4852
/// Type records that will go into the PDB TPI stream.
4953
llvm::codeview::MergingTypeTableBuilder typeTable;
5054

0 commit comments

Comments
 (0)