Add a way to replace a field inside a metadata node. This can be

used to incrementally update a created node without needing a
temporary node and RAUW.

llvm-svn: 150571
This commit is contained in:
Eric Christopher 2012-02-15 09:09:29 +00:00
parent 643575d4a9
commit 6be42e9898
2 changed files with 8 additions and 0 deletions

View File

@ -135,6 +135,9 @@ public:
/// deleteTemporary - Deallocate a node created by getTemporary. The
/// node must not have any users.
static void deleteTemporary(MDNode *N);
/// replaceOperandWith - Replace a specific operand.
void replaceOperandWith(unsigned i, Value *NewVal);
/// getOperand - Return specified operand.
Value *getOperand(unsigned i) const;

View File

@ -87,6 +87,11 @@ static MDNodeOperand *getOperandPtr(MDNode *N, unsigned Op) {
return reinterpret_cast<MDNodeOperand*>(N+1)+Op;
}
void MDNode::replaceOperandWith(unsigned i, Value *Val) {
MDNodeOperand *Op = getOperandPtr(this, i);
replaceOperand(Op, Val);
}
MDNode::MDNode(LLVMContext &C, ArrayRef<Value*> Vals, bool isFunctionLocal)
: Value(Type::getMetadataTy(C), Value::MDNodeVal) {
NumOperands = Vals.size();