forked from OSchip/llvm-project
Add MDNode::getIfExists(), an efficient way to determine if a value is used by metadata (since metadata does not appear in a value's use list)
llvm-svn: 94492
This commit is contained in:
parent
907bdbb6be
commit
7e8ce9afbc
|
|
@ -112,7 +112,7 @@ protected:
|
|||
bool isFunctionLocal);
|
||||
|
||||
static MDNode *getMDNode(LLVMContext &C, Value *const *Vals, unsigned NumVals,
|
||||
FunctionLocalness FL);
|
||||
FunctionLocalness FL, bool Insert = true);
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
static MDNode *get(LLVMContext &Context, Value *const *Vals,
|
||||
|
|
@ -122,6 +122,9 @@ public:
|
|||
static MDNode *getWhenValsUnresolved(LLVMContext &Context, Value *const *Vals,
|
||||
unsigned NumVals, bool isFunctionLocal);
|
||||
|
||||
static MDNode *getIfExists(LLVMContext &Context, Value *const *Vals,
|
||||
unsigned NumVals);
|
||||
|
||||
/// getOperand - Return specified operand.
|
||||
Value *getOperand(unsigned i) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -186,15 +186,22 @@ void MDNode::destroy() {
|
|||
}
|
||||
|
||||
MDNode *MDNode::getMDNode(LLVMContext &Context, Value *const *Vals,
|
||||
unsigned NumVals, FunctionLocalness FL) {
|
||||
unsigned NumVals, FunctionLocalness FL,
|
||||
bool Insert) {
|
||||
LLVMContextImpl *pImpl = Context.pImpl;
|
||||
FoldingSetNodeID ID;
|
||||
for (unsigned i = 0; i != NumVals; ++i)
|
||||
ID.AddPointer(Vals[i]);
|
||||
|
||||
void *InsertPoint;
|
||||
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
|
||||
if (!N) {
|
||||
MDNode *N = NULL;
|
||||
|
||||
if ((N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint)))
|
||||
return N;
|
||||
|
||||
if (!Insert)
|
||||
return NULL;
|
||||
|
||||
bool isFunctionLocal = false;
|
||||
switch (FL) {
|
||||
case FL_Unknown:
|
||||
|
|
@ -222,7 +229,7 @@ MDNode *MDNode::getMDNode(LLVMContext &Context, Value *const *Vals,
|
|||
|
||||
// InsertPoint will have been set by the FindNodeOrInsertPos call.
|
||||
pImpl->MDNodeSet.InsertNode(N, InsertPoint);
|
||||
}
|
||||
|
||||
return N;
|
||||
}
|
||||
|
||||
|
|
@ -235,6 +242,11 @@ MDNode *MDNode::getWhenValsUnresolved(LLVMContext &Context, Value*const* Vals,
|
|||
return getMDNode(Context, Vals, NumVals, isFunctionLocal ? FL_Yes : FL_No);
|
||||
}
|
||||
|
||||
MDNode *MDNode::getIfExists(LLVMContext &Context, Value *const *Vals,
|
||||
unsigned NumVals) {
|
||||
return getMDNode(Context, Vals, NumVals, FL_Unknown, false);
|
||||
}
|
||||
|
||||
/// getOperand - Return specified operand.
|
||||
Value *MDNode::getOperand(unsigned i) const {
|
||||
return *getOperandPtr(const_cast<MDNode*>(this), i);
|
||||
|
|
|
|||
Loading…
Reference in New Issue