From d7e6457c3faf6c5530a4c8224e2dfcf91b57093b Mon Sep 17 00:00:00 2001 From: Victor Hernandez Date: Thu, 14 Jan 2010 19:54:11 +0000 Subject: [PATCH] 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 --- lib/Bitcode/Writer/ValueEnumerator.cpp | 54 +++++++++++++------------- lib/Bitcode/Writer/ValueEnumerator.h | 6 +-- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index ef0a61ee2a1..cb139e5e41f 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(*OI)) + if (MD->isFunctionLocal()) + // These will get enumerated during function-incorporation. + continue; + EnumerateOperandType(*OI); + } EnumerateType(I->getType()); if (const CallInst *CI = dyn_cast(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(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(V)) - return EnumerateMetadata(MB, isGlobal); + return EnumerateMetadata(MB); else if (const NamedMDNode *NMD = dyn_cast(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(*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(V)) - return EnumerateMetadata(MB, isGlobal); - if (const Constant *C = dyn_cast(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(Op)) continue; - EnumerateOperandType(cast(Op), isGlobal); + EnumerateOperandType(cast(Op)); } if (const MDNode *N = dyn_cast(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(V) || isa(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(*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 78ea81439cd..c50fe9ce767 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);