diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h index 4d0a04ea623..81dcef984f5 100644 --- a/include/llvm/IR/Metadata.h +++ b/include/llvm/IR/Metadata.h @@ -761,9 +761,6 @@ public: private: void handleChangedOperand(void *Ref, Metadata *New); - bool hasUnresolvedOperands() const { return SubclassData32; } - void incrementUnresolvedOperands() { ++SubclassData32; } - void decrementUnresolvedOperands() { --SubclassData32; } void resolve(); }; diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index 34ecf3dfc2d..9cc258771db 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -228,8 +228,7 @@ void ReplaceableMetadataImpl::resolveAllUses(bool ResolveUsers) { continue; if (OwnerMD->isResolved()) continue; - OwnerMD->decrementUnresolvedOperands(); - if (!OwnerMD->hasUnresolvedOperands()) + if (!--OwnerMD->SubclassData32) OwnerMD->resolve(); } } @@ -418,12 +417,15 @@ GenericMDNode::GenericMDNode(LLVMContext &C, ArrayRef Vals, return; // Check whether any operands are unresolved, requiring re-uniquing. + unsigned NumUnresolved = 0; for (const auto &Op : operands()) - if (isOperandUnresolved(Op)) - incrementUnresolvedOperands(); + NumUnresolved += unsigned(isOperandUnresolved(Op)); - if (hasUnresolvedOperands()) - ReplaceableUses.reset(new ReplaceableMetadataImpl); + if (!NumUnresolved) + return; + + ReplaceableUses.reset(new ReplaceableMetadataImpl); + SubclassData32 = NumUnresolved; } GenericMDNode::~GenericMDNode() { @@ -545,12 +547,13 @@ void GenericMDNode::handleChangedOperand(void *Ref, Metadata *New) { Store.insert(this); if (!isResolved()) { + assert(SubclassData32 != 0 && "Expected unresolved operands"); + // Check if the last unresolved operand has just been resolved; if so, // resolve this as well. if (isOperandUnresolved(Old)) { if (!isOperandUnresolved(New)) { - decrementUnresolvedOperands(); - if (!hasUnresolvedOperands()) + if (!--SubclassData32) resolve(); } } else {