From 0d7ab298896b0c2dfb769243e7067474884d258a Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 19 Jan 2015 23:18:34 +0000 Subject: [PATCH] IR: Cleanup MDNode field use, NFC Swap usage of `SubclassData32` and `MDNodeSubclassData`, and rename `MDNodeSubclassData` to `NumUnresolved`. Small drive-by cleanup to `countUnresolvedOperands()` since otherwise the name clash with local vars named `NumUnresolved` would be confusing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226523 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Metadata.h | 15 ++++++--------- lib/IR/Metadata.cpp | 33 ++++++++++++++------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h index e2bfcadc5cf..13f6e5ad5d7 100644 --- a/include/llvm/IR/Metadata.h +++ b/include/llvm/IR/Metadata.h @@ -684,14 +684,11 @@ class MDNode : public Metadata { void operator=(const MDNode &) LLVM_DELETED_FUNCTION; void *operator new(size_t) LLVM_DELETED_FUNCTION; -protected: - ContextAndReplaceableUses Context; - -private: unsigned NumOperands; + unsigned NumUnresolved; protected: - unsigned MDNodeSubclassData; + ContextAndReplaceableUses Context; void *operator new(size_t Size, unsigned NumOps); void operator delete(void *Mem); @@ -808,7 +805,7 @@ private: void resolve(); void resolveAfterOperandChange(Metadata *Old, Metadata *New); void decrementUnresolvedOperandCount(); - unsigned countUnresolvedOperands() const; + unsigned countUnresolvedOperands(); /// \brief Mutate this to be "uniqued". /// @@ -879,7 +876,7 @@ class MDTuple : public MDNode { } ~MDTuple() { dropAllReferences(); } - void setHash(unsigned Hash) { MDNodeSubclassData = Hash; } + void setHash(unsigned Hash) { SubclassData32 = Hash; } void recalculateHash(); static MDTuple *getImpl(LLVMContext &Context, ArrayRef MDs, @@ -887,7 +884,7 @@ class MDTuple : public MDNode { public: /// \brief Get the hash, if any. - unsigned getHash() const { return MDNodeSubclassData; } + unsigned getHash() const { return SubclassData32; } static MDTuple *get(LLVMContext &Context, ArrayRef MDs) { return getImpl(Context, MDs, Uniqued); @@ -978,7 +975,7 @@ public: getImpl(Context, Line, Column, Scope, InlinedAt, Temporary)); } - unsigned getLine() const { return MDNodeSubclassData; } + unsigned getLine() const { return SubclassData32; } unsigned getColumn() const { return SubclassData16; } Metadata *getScope() const { return getOperand(0); } Metadata *getInlinedAt() const { diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index 3613871207a..0ce704c7c3d 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -398,23 +398,20 @@ void MDNode::operator delete(void *Mem) { MDNode::MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, ArrayRef MDs) - : Metadata(ID, Storage), Context(Context), NumOperands(MDs.size()), - MDNodeSubclassData(0) { + : Metadata(ID, Storage), NumOperands(MDs.size()), NumUnresolved(0), + Context(Context) { for (unsigned I = 0, E = MDs.size(); I != E; ++I) setOperand(I, MDs[I]); if (isDistinct()) return; - if (isUniqued()) { - // Check whether any operands are unresolved, requiring re-uniquing. - unsigned NumUnresolved = countUnresolvedOperands(); - if (!NumUnresolved) + if (isUniqued()) + // Check whether any operands are unresolved, requiring re-uniquing. If + // not, don't support RAUW. + if (!countUnresolvedOperands()) return; - SubclassData32 = NumUnresolved; - } - this->Context.makeReplaceable(make_unique(Context)); } @@ -424,8 +421,8 @@ static bool isOperandUnresolved(Metadata *Op) { return false; } -unsigned MDNode::countUnresolvedOperands() const { - unsigned NumUnresolved = 0; +unsigned MDNode::countUnresolvedOperands() { + assert(NumUnresolved == 0 && "Expected unresolved ops to be uncounted"); for (const auto &Op : operands()) NumUnresolved += unsigned(isOperandUnresolved(Op)); return NumUnresolved; @@ -437,9 +434,7 @@ void MDNode::makeUniqued() { // Make this 'uniqued'. Storage = Uniqued; - if (unsigned NumUnresolved = countUnresolvedOperands()) - SubclassData32 = NumUnresolved; - else + if (!countUnresolvedOperands()) resolve(); assert(isUniqued() && "Expected this to be uniqued"); @@ -464,7 +459,7 @@ void MDNode::resolve() { // Move the map, so that this immediately looks resolved. auto Uses = Context.takeReplaceableUses(); - SubclassData32 = 0; + NumUnresolved = 0; assert(isResolved() && "Expected this to be resolved"); // Drop RAUW support. @@ -472,19 +467,19 @@ void MDNode::resolve() { } void MDNode::resolveAfterOperandChange(Metadata *Old, Metadata *New) { - assert(SubclassData32 != 0 && "Expected unresolved operands"); + assert(NumUnresolved != 0 && "Expected unresolved operands"); // Check if an operand was resolved. if (!isOperandUnresolved(Old)) { if (isOperandUnresolved(New)) // An operand was un-resolved! - ++SubclassData32; + ++NumUnresolved; } else if (!isOperandUnresolved(New)) decrementUnresolvedOperandCount(); } void MDNode::decrementUnresolvedOperandCount() { - if (!--SubclassData32) + if (!--NumUnresolved) // Last unresolved operand has just been resolved. resolve(); } @@ -694,7 +689,7 @@ MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line, assert(Line < (1u << 24) && "Expected 24-bit line"); assert(Column < (1u << 16) && "Expected 16-bit column"); - MDNodeSubclassData = Line; + SubclassData32 = Line; SubclassData16 = Column; } -- 2.40.0