forked from OSchip/llvm-project
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. llvm-svn: 226523
This commit is contained in:
parent
8647529250
commit
909131b95f
|
@ -684,15 +684,12 @@ class MDNode : public Metadata {
|
||||||
void operator=(const MDNode &) LLVM_DELETED_FUNCTION;
|
void operator=(const MDNode &) LLVM_DELETED_FUNCTION;
|
||||||
void *operator new(size_t) LLVM_DELETED_FUNCTION;
|
void *operator new(size_t) LLVM_DELETED_FUNCTION;
|
||||||
|
|
||||||
|
unsigned NumOperands;
|
||||||
|
unsigned NumUnresolved;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ContextAndReplaceableUses Context;
|
ContextAndReplaceableUses Context;
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned NumOperands;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
unsigned MDNodeSubclassData;
|
|
||||||
|
|
||||||
void *operator new(size_t Size, unsigned NumOps);
|
void *operator new(size_t Size, unsigned NumOps);
|
||||||
void operator delete(void *Mem);
|
void operator delete(void *Mem);
|
||||||
|
|
||||||
|
@ -808,7 +805,7 @@ private:
|
||||||
void resolve();
|
void resolve();
|
||||||
void resolveAfterOperandChange(Metadata *Old, Metadata *New);
|
void resolveAfterOperandChange(Metadata *Old, Metadata *New);
|
||||||
void decrementUnresolvedOperandCount();
|
void decrementUnresolvedOperandCount();
|
||||||
unsigned countUnresolvedOperands() const;
|
unsigned countUnresolvedOperands();
|
||||||
|
|
||||||
/// \brief Mutate this to be "uniqued".
|
/// \brief Mutate this to be "uniqued".
|
||||||
///
|
///
|
||||||
|
@ -879,7 +876,7 @@ class MDTuple : public MDNode {
|
||||||
}
|
}
|
||||||
~MDTuple() { dropAllReferences(); }
|
~MDTuple() { dropAllReferences(); }
|
||||||
|
|
||||||
void setHash(unsigned Hash) { MDNodeSubclassData = Hash; }
|
void setHash(unsigned Hash) { SubclassData32 = Hash; }
|
||||||
void recalculateHash();
|
void recalculateHash();
|
||||||
|
|
||||||
static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
|
||||||
|
@ -887,7 +884,7 @@ class MDTuple : public MDNode {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \brief Get the hash, if any.
|
/// \brief Get the hash, if any.
|
||||||
unsigned getHash() const { return MDNodeSubclassData; }
|
unsigned getHash() const { return SubclassData32; }
|
||||||
|
|
||||||
static MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
static MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
|
||||||
return getImpl(Context, MDs, Uniqued);
|
return getImpl(Context, MDs, Uniqued);
|
||||||
|
@ -978,7 +975,7 @@ public:
|
||||||
getImpl(Context, Line, Column, Scope, InlinedAt, Temporary));
|
getImpl(Context, Line, Column, Scope, InlinedAt, Temporary));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned getLine() const { return MDNodeSubclassData; }
|
unsigned getLine() const { return SubclassData32; }
|
||||||
unsigned getColumn() const { return SubclassData16; }
|
unsigned getColumn() const { return SubclassData16; }
|
||||||
Metadata *getScope() const { return getOperand(0); }
|
Metadata *getScope() const { return getOperand(0); }
|
||||||
Metadata *getInlinedAt() const {
|
Metadata *getInlinedAt() const {
|
||||||
|
|
|
@ -398,23 +398,20 @@ void MDNode::operator delete(void *Mem) {
|
||||||
|
|
||||||
MDNode::MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
|
MDNode::MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
|
||||||
ArrayRef<Metadata *> MDs)
|
ArrayRef<Metadata *> MDs)
|
||||||
: Metadata(ID, Storage), Context(Context), NumOperands(MDs.size()),
|
: Metadata(ID, Storage), NumOperands(MDs.size()), NumUnresolved(0),
|
||||||
MDNodeSubclassData(0) {
|
Context(Context) {
|
||||||
for (unsigned I = 0, E = MDs.size(); I != E; ++I)
|
for (unsigned I = 0, E = MDs.size(); I != E; ++I)
|
||||||
setOperand(I, MDs[I]);
|
setOperand(I, MDs[I]);
|
||||||
|
|
||||||
if (isDistinct())
|
if (isDistinct())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isUniqued()) {
|
if (isUniqued())
|
||||||
// Check whether any operands are unresolved, requiring re-uniquing.
|
// Check whether any operands are unresolved, requiring re-uniquing. If
|
||||||
unsigned NumUnresolved = countUnresolvedOperands();
|
// not, don't support RAUW.
|
||||||
if (!NumUnresolved)
|
if (!countUnresolvedOperands())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SubclassData32 = NumUnresolved;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->Context.makeReplaceable(make_unique<ReplaceableMetadataImpl>(Context));
|
this->Context.makeReplaceable(make_unique<ReplaceableMetadataImpl>(Context));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,8 +421,8 @@ static bool isOperandUnresolved(Metadata *Op) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned MDNode::countUnresolvedOperands() const {
|
unsigned MDNode::countUnresolvedOperands() {
|
||||||
unsigned NumUnresolved = 0;
|
assert(NumUnresolved == 0 && "Expected unresolved ops to be uncounted");
|
||||||
for (const auto &Op : operands())
|
for (const auto &Op : operands())
|
||||||
NumUnresolved += unsigned(isOperandUnresolved(Op));
|
NumUnresolved += unsigned(isOperandUnresolved(Op));
|
||||||
return NumUnresolved;
|
return NumUnresolved;
|
||||||
|
@ -437,9 +434,7 @@ void MDNode::makeUniqued() {
|
||||||
|
|
||||||
// Make this 'uniqued'.
|
// Make this 'uniqued'.
|
||||||
Storage = Uniqued;
|
Storage = Uniqued;
|
||||||
if (unsigned NumUnresolved = countUnresolvedOperands())
|
if (!countUnresolvedOperands())
|
||||||
SubclassData32 = NumUnresolved;
|
|
||||||
else
|
|
||||||
resolve();
|
resolve();
|
||||||
|
|
||||||
assert(isUniqued() && "Expected this to be uniqued");
|
assert(isUniqued() && "Expected this to be uniqued");
|
||||||
|
@ -464,7 +459,7 @@ void MDNode::resolve() {
|
||||||
|
|
||||||
// Move the map, so that this immediately looks resolved.
|
// Move the map, so that this immediately looks resolved.
|
||||||
auto Uses = Context.takeReplaceableUses();
|
auto Uses = Context.takeReplaceableUses();
|
||||||
SubclassData32 = 0;
|
NumUnresolved = 0;
|
||||||
assert(isResolved() && "Expected this to be resolved");
|
assert(isResolved() && "Expected this to be resolved");
|
||||||
|
|
||||||
// Drop RAUW support.
|
// Drop RAUW support.
|
||||||
|
@ -472,19 +467,19 @@ void MDNode::resolve() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MDNode::resolveAfterOperandChange(Metadata *Old, Metadata *New) {
|
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.
|
// Check if an operand was resolved.
|
||||||
if (!isOperandUnresolved(Old)) {
|
if (!isOperandUnresolved(Old)) {
|
||||||
if (isOperandUnresolved(New))
|
if (isOperandUnresolved(New))
|
||||||
// An operand was un-resolved!
|
// An operand was un-resolved!
|
||||||
++SubclassData32;
|
++NumUnresolved;
|
||||||
} else if (!isOperandUnresolved(New))
|
} else if (!isOperandUnresolved(New))
|
||||||
decrementUnresolvedOperandCount();
|
decrementUnresolvedOperandCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MDNode::decrementUnresolvedOperandCount() {
|
void MDNode::decrementUnresolvedOperandCount() {
|
||||||
if (!--SubclassData32)
|
if (!--NumUnresolved)
|
||||||
// Last unresolved operand has just been resolved.
|
// Last unresolved operand has just been resolved.
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
@ -694,7 +689,7 @@ MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
|
||||||
assert(Line < (1u << 24) && "Expected 24-bit line");
|
assert(Line < (1u << 24) && "Expected 24-bit line");
|
||||||
assert(Column < (1u << 16) && "Expected 16-bit column");
|
assert(Column < (1u << 16) && "Expected 16-bit column");
|
||||||
|
|
||||||
MDNodeSubclassData = Line;
|
SubclassData32 = Line;
|
||||||
SubclassData16 = Column;
|
SubclassData16 = Column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue