aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorVictor Hernandez <vhernandez@apple.com>2010-01-14 19:54:11 +0000
committerVictor Hernandez <vhernandez@apple.com>2010-01-14 19:54:11 +0000
commitd7e6457c3faf6c5530a4c8224e2dfcf91b57093b (patch)
tree0a39b99e44760793fc1e4d5b47a1ddd349053f23 /lib/Bitcode
parent3cd7c3db9926c1db3b55599c01c75e8ecc6bd096 (diff)
downloadexternal_llvm-d7e6457c3faf6c5530a4c8224e2dfcf91b57093b.zip
external_llvm-d7e6457c3faf6c5530a4c8224e2dfcf91b57093b.tar.gz
external_llvm-d7e6457c3faf6c5530a4c8224e2dfcf91b57093b.tar.bz2
Simplify code that chooses when to enumerate function-local metadata operands
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93446 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Writer/ValueEnumerator.cpp54
-rw-r--r--lib/Bitcode/Writer/ValueEnumerator.h6
2 files changed, 31 insertions, 29 deletions
diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp
index ef0a61e..cb139e5 100644
--- a/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -91,8 +91,13 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
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 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
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 @@ void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
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 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD, bool isGlobal) {
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 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD, bool isGlobal) {
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 @@ void ValueEnumerator::EnumerateValue(const Value *V, bool isGlobal) {
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 @@ void ValueEnumerator::EnumerateType(const Type *Ty) {
// 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 @@ void ValueEnumerator::EnumerateOperandType(const Value *V, bool isGlobal) {
// 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 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
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);
diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h
index 78ea814..c50fe9c 100644
--- a/lib/Bitcode/Writer/ValueEnumerator.h
+++ b/lib/Bitcode/Writer/ValueEnumerator.h
@@ -127,11 +127,11 @@ public:
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);