[llvm-commits] [llvm] r93446 - in /llvm/trunk/lib/Bitcode/Writer: ValueEnumerator.cpp ValueEnumerator.h
Victor Hernandez
vhernandez at apple.com
Thu Jan 14 11:54:11 PST 2010
Author: hernande
Date: Thu Jan 14 13:54:11 2010
New Revision: 93446
URL: http://llvm.org/viewvc/llvm-project?rev=93446&view=rev
Log:
Simplify code that chooses when to enumerate function-local metadata operands
Modified:
llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h
Modified: llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp?rev=93446&r1=93445&r2=93446&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp Thu Jan 14 13:54:11 2010
@@ -91,8 +91,13 @@
for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){
for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
- OI != E; ++OI)
- EnumerateOperandType(*OI, true);
+ OI != E; ++OI) {
+ if (MDNode *MD = dyn_cast<MDNode>(*OI))
+ if (MD->isFunctionLocal())
+ // These will get enumerated during function-incorporation.
+ continue;
+ EnumerateOperandType(*OI);
+ }
EnumerateType(I->getType());
if (const CallInst *CI = dyn_cast<CallInst>(I))
EnumerateAttributes(CI->getAttributes());
@@ -103,7 +108,7 @@
MDs.clear();
I->getAllMetadata(MDs);
for (unsigned i = 0, e = MDs.size(); i != e; ++i)
- EnumerateMetadata(MDs[i].second, true);
+ EnumerateMetadata(MDs[i].second);
}
}
@@ -224,7 +229,7 @@
MDValueMap[MD] = Values.size();
}
-void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD, bool isGlobal) {
+void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) {
// Check to see if it's already in!
unsigned &MDValueID = MDValueMap[MD];
if (MDValueID) {
@@ -237,16 +242,14 @@
EnumerateType(MD->getType());
if (const MDNode *N = dyn_cast<MDNode>(MD)) {
- if ((isGlobal && !N->isFunctionLocal()) ||
- (!isGlobal && N->isFunctionLocal())) {
- MDValues.push_back(std::make_pair(MD, 1U));
- MDValueMap[MD] = MDValues.size();
- MDValueID = MDValues.size();
- for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
- if (Value *V = N->getOperand(i))
- EnumerateValue(V);
- else
- EnumerateType(Type::getVoidTy(MD->getContext()));
+ MDValues.push_back(std::make_pair(MD, 1U));
+ MDValueMap[MD] = MDValues.size();
+ MDValueID = MDValues.size();
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
+ if (Value *V = N->getOperand(i))
+ EnumerateValue(V);
+ else
+ EnumerateType(Type::getVoidTy(MD->getContext()));
}
return;
}
@@ -257,10 +260,10 @@
MDValueID = MDValues.size();
}
-void ValueEnumerator::EnumerateValue(const Value *V, bool isGlobal) {
+void ValueEnumerator::EnumerateValue(const Value *V) {
assert(!V->getType()->isVoidTy() && "Can't insert void values!");
if (const MetadataBase *MB = dyn_cast<MetadataBase>(V))
- return EnumerateMetadata(MB, isGlobal);
+ return EnumerateMetadata(MB);
else if (const NamedMDNode *NMD = dyn_cast<NamedMDNode>(V))
return EnumerateNamedMDNode(NMD);
@@ -294,7 +297,7 @@
for (User::const_op_iterator I = C->op_begin(), E = C->op_end();
I != E; ++I)
if (!isa<BasicBlock>(*I)) // Don't enumerate BB operand to BlockAddress.
- EnumerateValue(*I, isGlobal);
+ EnumerateValue(*I);
// Finally, add the value. Doing this could make the ValueID reference be
// dangling, don't reuse it.
@@ -331,14 +334,9 @@
// Enumerate the types for the specified value. If the value is a constant,
// walk through it, enumerating the types of the constant.
-void ValueEnumerator::EnumerateOperandType(const Value *V, bool isGlobal) {
+void ValueEnumerator::EnumerateOperandType(const Value *V) {
EnumerateType(V->getType());
- // During function-incorporation, only enumerate metadata operands.
- if (!isGlobal)
- if (const MetadataBase *MB = dyn_cast<MetadataBase>(V))
- return EnumerateMetadata(MB, isGlobal);
-
if (const Constant *C = dyn_cast<Constant>(V)) {
// If this constant is already enumerated, ignore it, we know its type must
// be enumerated.
@@ -353,13 +351,13 @@
// blockaddress.
if (isa<BasicBlock>(Op)) continue;
- EnumerateOperandType(cast<Constant>(Op), isGlobal);
+ EnumerateOperandType(cast<Constant>(Op));
}
if (const MDNode *N = dyn_cast<MDNode>(V)) {
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
if (Value *Elem = N->getOperand(i))
- EnumerateOperandType(Elem, isGlobal);
+ EnumerateOperandType(Elem);
}
} else if (isa<MDString>(V) || isa<MDNode>(V))
EnumerateValue(V);
@@ -414,7 +412,11 @@
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
OI != E; ++OI) {
- EnumerateOperandType(*OI, false);
+ if (MDNode *MD = dyn_cast<MDNode>(*OI))
+ if (!MD->isFunctionLocal())
+ // These were already enumerated during ValueEnumerator creation.
+ continue;
+ EnumerateOperandType(*OI);
}
if (!I->getType()->isVoidTy())
EnumerateValue(I);
Modified: llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h?rev=93446&r1=93445&r2=93446&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h (original)
+++ llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h Thu Jan 14 13:54:11 2010
@@ -127,11 +127,11 @@
private:
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
- void EnumerateMetadata(const MetadataBase *MD, bool isGlobal);
+ void EnumerateMetadata(const MetadataBase *MD);
void EnumerateNamedMDNode(const NamedMDNode *NMD);
- void EnumerateValue(const Value *V, bool isGlobal = true);
+ void EnumerateValue(const Value *V);
void EnumerateType(const Type *T);
- void EnumerateOperandType(const Value *V, bool isGlobal);
+ void EnumerateOperandType(const Value *V);
void EnumerateAttributes(const AttrListPtr &PAL);
void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);
More information about the llvm-commits
mailing list