Make MDNode use CallbackVH. Also change MDNode to store Value* instead of

Constant* in preperation of a future change to support holding non-Constants
in an MDNode.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71407 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky
2009-05-10 20:57:05 +00:00
parent af3fdb5dc4
commit cb33799b9f
12 changed files with 270 additions and 105 deletions

View File

@@ -17,6 +17,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
#include "llvm/MDNode.h"
#include "llvm/Module.h"
#include "llvm/AutoUpgrade.h"
#include "llvm/ADT/SmallString.h"
@@ -287,12 +288,10 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
UserCS->getType()->isPacked());
} else if (isa<ConstantVector>(UserC)) {
NewC = ConstantVector::get(&NewOps[0], NewOps.size());
} else if (isa<ConstantExpr>(UserC)) {
} else {
assert(isa<ConstantExpr>(UserC) && "Must be a ConstantExpr.");
NewC = cast<ConstantExpr>(UserC)->getWithOperands(&NewOps[0],
NewOps.size());
} else {
assert(isa<MDNode>(UserC) && "Must be a metadata node.");
NewC = MDNode::get(&NewOps[0], NewOps.size());
}
UserC->replaceAllUsesWith(NewC);
@@ -300,6 +299,8 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
NewOps.clear();
}
// Update all ValueHandles, they should be the only users at this point.
Placeholder->replaceAllUsesWith(RealVal);
delete Placeholder;
}
}
@@ -1017,10 +1018,13 @@ bool BitcodeReader::ParseConstants() {
return Error("Invalid CST_MDNODE record");
unsigned Size = Record.size();
SmallVector<Constant*, 8> Elts;
SmallVector<Value*, 8> Elts;
for (unsigned i = 0; i != Size; i += 2) {
const Type *Ty = getTypeByID(Record[i], false);
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], Ty));
if (Ty != Type::VoidTy)
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], Ty));
else
Elts.push_back(NULL);
}
V = MDNode::get(&Elts[0], Elts.size());
break;

View File

@@ -19,6 +19,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
#include "llvm/MDNode.h"
#include "llvm/Module.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ValueSymbolTable.h"
@@ -706,9 +707,14 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
}
} else if (const MDNode *N = dyn_cast<MDNode>(C)) {
Code = bitc::CST_CODE_MDNODE;
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Record.push_back(VE.getTypeID(N->getOperand(i)->getType()));
Record.push_back(VE.getValueID(N->getOperand(i)));
for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) {
if (N->getElement(i)) {
Record.push_back(VE.getTypeID(N->getElement(i)->getType()));
Record.push_back(VE.getValueID(N->getElement(i)));
} else {
Record.push_back(VE.getTypeID(Type::VoidTy));
Record.push_back(0);
}
}
} else {
assert(0 && "Unknown constant!");

View File

@@ -14,6 +14,7 @@
#include "ValueEnumerator.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/MDNode.h"
#include "llvm/Module.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ValueSymbolTable.h"
@@ -200,6 +201,18 @@ void ValueEnumerator::EnumerateValue(const Value *V) {
// Finally, add the value. Doing this could make the ValueID reference be
// dangling, don't reuse it.
Values.push_back(std::make_pair(V, 1U));
ValueMap[V] = Values.size();
return;
} else if (const MDNode *N = dyn_cast<MDNode>(C)) {
for (MDNode::const_elem_iterator I = N->elem_begin(), E = N->elem_end();
I != E; ++I) {
if (*I)
EnumerateValue(*I);
else
EnumerateType(Type::VoidTy);
}
Values.push_back(std::make_pair(V, 1U));
ValueMap[V] = Values.size();
return;
@@ -244,6 +257,11 @@ void ValueEnumerator::EnumerateOperandType(const Value *V) {
// them.
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
EnumerateOperandType(C->getOperand(i));
if (const MDNode *N = dyn_cast<MDNode>(V)) {
for (unsigned i = 0, e = N->getNumElements(); i != e; ++i)
EnumerateOperandType(N->getElement(i));
}
}
}