[llvm-commits] [llvm] r93400 - in /llvm/trunk: include/llvm/Metadata.h lib/VMCore/Metadata.cpp
Victor Hernandez
vhernandez at apple.com
Mon Jan 18 12:37:48 PST 2010
Fixed in r93762.
Victor
On Jan 15, 2010, at 2:58 PM, Chris Lattner wrote:
>
> On Jan 13, 2010, at 5:45 PM, Victor Hernandez wrote:
>
>> Author: hernande
>> Date: Wed Jan 13 19:45:14 2010
>> New Revision: 93400
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=93400&view=rev
>> Log:
>> Add MDNode::getFunction(), which figures out the metadata's function, if it has function that it is local to.
>
> Ok.
>
>> +++ llvm/trunk/lib/VMCore/Metadata.cpp Wed Jan 13 19:45:14 2010
>> @@ -121,6 +121,40 @@
>> 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;
>
> You don't need F here except in the MDNode case. All the other cases should just "return BB->getParent();" for example. This allows you to unnest the "else if"s into a series of "if"s.
>
> Also, function mdnodes can never be cyclic, why do you need the smallptrset?
>
> -Chris
>
>> + // 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.
>> void MDNode::destroy() {
>> setValueSubclassData(getSubclassDataFromValue() | DestroyFlag);
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list