Skip to content

Commit 44e5b4e

Browse files
committed
IR: Reorder metadata bitcode serialization, NFC
Enumerate `MDNode`'s operands *before* the node itself, so that the reader requires less RAUW. Although this will cause different code paths to be hit in the reader, this should effectively be no functionality change. llvm-svn: 220340
1 parent 2174a9d commit 44e5b4e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

llvm/lib/Bitcode/Writer/ValueEnumerator.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -495,29 +495,31 @@ void ValueEnumerator::EnumerateMDNodeOperands(const MDNode *N) {
495495
void ValueEnumerator::EnumerateMetadata(const Value *MD) {
496496
assert((isa<MDNode>(MD) || isa<MDString>(MD)) && "Invalid metadata kind");
497497

498-
// Enumerate the type of this value.
499-
EnumerateType(MD->getType());
500-
498+
// Skip function-local nodes themselves, but walk their operands.
501499
const MDNode *N = dyn_cast<MDNode>(MD);
502-
503-
// In the module-level pass, skip function-local nodes themselves, but
504-
// do walk their operands.
505500
if (N && N->isFunctionLocal() && N->getFunction()) {
506501
EnumerateMDNodeOperands(N);
507502
return;
508503
}
509504

510-
// Check to see if it's already in!
511-
unsigned &MDValueID = MDValueMap[MD];
512-
if (MDValueID)
505+
// Insert a dummy ID to block the co-recursive call to
506+
// EnumerateMDNodeOperands() from re-visiting MD in a cyclic graph.
507+
//
508+
// Return early if there's already an ID.
509+
if (!MDValueMap.insert(std::make_pair(MD, 0)).second)
513510
return;
514511

515-
MDValues.push_back(MD);
516-
MDValueID = MDValues.size();
512+
// Enumerate the type of this value.
513+
EnumerateType(MD->getType());
517514

518-
// Enumerate all non-function-local operands.
515+
// Visit operands first to minimize RAUW.
519516
if (N)
520517
EnumerateMDNodeOperands(N);
518+
519+
// Replace the dummy ID inserted above with the correct one. MDValueMap may
520+
// have changed by inserting operands, so we need a fresh lookup here.
521+
MDValues.push_back(MD);
522+
MDValueMap[MD] = MDValues.size();
521523
}
522524

523525
/// EnumerateFunctionLocalMetadataa - Incorporate function-local metadata

0 commit comments

Comments
 (0)