mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-30 04:18:16 +00:00
Add MDNode::getFunction(), which figures out the metadata's function, if it has function that it is local to.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93400 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -151,6 +151,11 @@ public:
|
|||||||
bool isFunctionLocal() const {
|
bool isFunctionLocal() const {
|
||||||
return (getSubclassDataFromValue() & FunctionLocalBit) != 0;
|
return (getSubclassDataFromValue() & FunctionLocalBit) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getFunction - If this metadata is function-local and recursively has a
|
||||||
|
// function-local operand, return the first such operand's parent function.
|
||||||
|
// Otherwise, return null.
|
||||||
|
Function *getFunction() const;
|
||||||
|
|
||||||
// destroy - Delete this node. Only when there are no uses.
|
// destroy - Delete this node. Only when there are no uses.
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|||||||
@@ -121,6 +121,40 @@ MDNode::~MDNode() {
|
|||||||
Op->~MDNodeOperand();
|
Op->~MDNodeOperand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Function *getFunctionHelper(const MDNode *N,
|
||||||
|
SmallPtrSet<const MDNode *, 32> &Visited) {
|
||||||
|
assert(N->isFunctionLocal() && "Should only be called on function-local MD");
|
||||||
|
Function *F = NULL;
|
||||||
|
// Only visit each MDNode once.
|
||||||
|
if (!Visited.insert(N)) return F;
|
||||||
|
|
||||||
|
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
|
||||||
|
Value *V = N->getOperand(i);
|
||||||
|
if (!V) continue;
|
||||||
|
if (Instruction *I = dyn_cast<Instruction>(V))
|
||||||
|
F = I->getParent()->getParent();
|
||||||
|
else if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
|
||||||
|
F = BB->getParent();
|
||||||
|
else if (Argument *A = dyn_cast<Argument>(V))
|
||||||
|
F = A->getParent();
|
||||||
|
else if (MDNode *MD = dyn_cast<MDNode>(V))
|
||||||
|
if (MD->isFunctionLocal())
|
||||||
|
F = getFunctionHelper(MD, Visited);
|
||||||
|
if (F) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return F;
|
||||||
|
}
|
||||||
|
|
||||||
|
// getFunction - If this metadata is function-local and recursively has a
|
||||||
|
// function-local operand, return the first such operand's parent function.
|
||||||
|
// Otherwise, return null.
|
||||||
|
Function *MDNode::getFunction() const {
|
||||||
|
if (!isFunctionLocal()) return NULL;
|
||||||
|
SmallPtrSet<const MDNode *, 32> Visited;
|
||||||
|
return getFunctionHelper(this, Visited);
|
||||||
|
}
|
||||||
|
|
||||||
// destroy - Delete this node. Only when there are no uses.
|
// destroy - Delete this node. Only when there are no uses.
|
||||||
void MDNode::destroy() {
|
void MDNode::destroy() {
|
||||||
setValueSubclassData(getSubclassDataFromValue() | DestroyFlag);
|
setValueSubclassData(getSubclassDataFromValue() | DestroyFlag);
|
||||||
|
|||||||
Reference in New Issue
Block a user