diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h index a9e54fd84c9..47d5939c4c1 100644 --- a/include/llvm/IR/Metadata.h +++ b/include/llvm/IR/Metadata.h @@ -843,6 +843,7 @@ private: void resolve(); void resolveAfterOperandChange(Metadata *Old, Metadata *New); void decrementUnresolvedOperandCount(); + unsigned countUnresolvedOperands() const; void deleteAsSubclass(); UniquableMDNode *uniquify(); diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index 01394137e8e..0e258623368 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -421,10 +421,7 @@ UniquableMDNode::UniquableMDNode(LLVMContext &C, unsigned ID, return; // Check whether any operands are unresolved, requiring re-uniquing. - unsigned NumUnresolved = 0; - for (const auto &Op : operands()) - NumUnresolved += unsigned(isOperandUnresolved(Op)); - + unsigned NumUnresolved = countUnresolvedOperands(); if (!NumUnresolved) return; @@ -432,6 +429,13 @@ UniquableMDNode::UniquableMDNode(LLVMContext &C, unsigned ID, SubclassData32 = NumUnresolved; } +unsigned UniquableMDNode::countUnresolvedOperands() const { + unsigned NumUnresolved = 0; + for (const auto &Op : operands()) + NumUnresolved += unsigned(isOperandUnresolved(Op)); + return NumUnresolved; +} + void UniquableMDNode::resolve() { assert(isUniqued() && "Expected this to be uniqued"); assert(!isResolved() && "Expected this to be unresolved");