[llvm-commits] [llvm] r93977 - in /llvm/trunk: include/llvm/Metadata.h lib/VMCore/AsmWriter.cpp lib/VMCore/Metadata.cpp
Victor Hernandez
vhernandez at apple.com
Tue Jan 19 20:45:57 PST 2010
Author: hernande
Date: Tue Jan 19 22:45:57 2010
New Revision: 93977
URL: http://llvm.org/viewvc/llvm-project?rev=93977&view=rev
Log:
Refactor common parts of MDNode::getFunction() and assertLocalFunction() into getFunctionForValue()
Modified:
llvm/trunk/include/llvm/Metadata.h
llvm/trunk/lib/VMCore/AsmWriter.cpp
llvm/trunk/lib/VMCore/Metadata.cpp
Modified: llvm/trunk/include/llvm/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=93977&r1=93976&r2=93977&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Metadata.h (original)
+++ llvm/trunk/include/llvm/Metadata.h Tue Jan 19 22:45:57 2010
@@ -156,7 +156,7 @@
// function-local operand, return the first such operand's parent function.
// Otherwise, return null. getFunction() should not be used for performance-
// critical code because it recursively visits all the MDNode's operands.
- Function *getFunction() const;
+ const Function *getFunction() const;
// destroy - Delete this node. Only when there are no uses.
void destroy();
Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=93977&r1=93976&r2=93977&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Tue Jan 19 22:45:57 2010
@@ -2062,7 +2062,7 @@
else
W.printAlias(cast<GlobalAlias>(GV));
} else if (const MDNode *N = dyn_cast<MDNode>(this)) {
- Function *F = N->getFunction();
+ const Function *F = N->getFunction();
SlotTracker SlotTable(F);
AssemblyWriter W(OS, SlotTable, F ? getModuleFromVal(F) : 0, AAW);
W.printMDNodeBody(N);
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=93977&r1=93976&r2=93977&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Tue Jan 19 22:45:57 2010
@@ -121,32 +121,27 @@
Op->~MDNodeOperand();
}
+static const Function *getFunctionForValue(Value *V) {
+ if (!V) return NULL;
+ if (Instruction *I = dyn_cast<Instruction>(V))
+ return I->getParent()->getParent();
+ if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) return BB->getParent();
+ if (Argument *A = dyn_cast<Argument>(V)) return A->getParent();
+ return NULL;
+}
+
#ifndef NDEBUG
-static Function *assertLocalFunction(const MDNode *N) {
+static const Function *assertLocalFunction(const MDNode *N) {
if (!N->isFunctionLocal()) return NULL;
- Function *F = NULL;
+ const Function *F = NULL, *NewF = NULL;
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)) {
- if (F) assert(F == I->getParent()->getParent() &&
- "inconsistent function-local metadata");
- else F = I->getParent()->getParent();
- } else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
- if (F) assert(F == BB->getParent() &&
- "inconsistent function-local metadata");
- else F = BB->getParent();
- } else if (Argument *A = dyn_cast<Argument>(V)) {
- if (F) assert(F == A->getParent() &&
- "inconsistent function-local metadata");
- else F = A->getParent();
- } else if (MDNode *MD = dyn_cast<MDNode>(V)) {
- if (Function *NewF = assertLocalFunction(MD)) {
- if (F) assert(F == NewF && "inconsistent function-local metadata");
- else F = NewF;
- }
+ if (Value *V = N->getOperand(i)) {
+ if (MDNode *MD = dyn_cast<MDNode>(V)) NewF = assertLocalFunction(MD);
+ else NewF = getFunctionForValue(V);
}
+ if (F && NewF) assert(F == NewF && "inconsistent function-local metadata");
+ else if (!F) F = NewF;
}
return F;
}
@@ -156,24 +151,19 @@
// function-local operand, return the first such operand's parent function.
// Otherwise, return null. getFunction() should not be used for performance-
// critical code because it recursively visits all the MDNode's operands.
-Function *MDNode::getFunction() const {
+const Function *MDNode::getFunction() const {
#ifndef NDEBUG
return assertLocalFunction(this);
#endif
-
if (!isFunctionLocal()) return NULL;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
- Value *V = getOperand(i);
- if (!V) continue;
- if (Instruction *I = dyn_cast<Instruction>(V))
- return I->getParent()->getParent();
- if (BasicBlock *BB = dyn_cast<BasicBlock>(V))
- return BB->getParent();
- if (Argument *A = dyn_cast<Argument>(V))
- return A->getParent();
- if (MDNode *MD = dyn_cast<MDNode>(V))
- if (Function *F = MD->getFunction()) return F;
+ if (Value *V = getOperand(i)) {
+ if (MDNode *MD = dyn_cast<MDNode>(V))
+ if (const Function *F = MD->getFunction()) return F;
+ else
+ return getFunctionForValue(V);
+ }
}
return NULL;
}
More information about the llvm-commits
mailing list