From 7ff99155c39edd73ebf1c6adfa023b1048fee9a4 Mon Sep 17 00:00:00 2001 From: rdivacky Date: Wed, 4 Nov 2009 14:58:56 +0000 Subject: Update LLVM to r86025. --- lib/Bitcode/Writer/ValueEnumerator.cpp | 45 ++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'lib/Bitcode/Writer/ValueEnumerator.cpp') diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 85aa5fa..d840d4a 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -14,6 +14,7 @@ #include "ValueEnumerator.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "llvm/Metadata.h" #include "llvm/Module.h" #include "llvm/TypeSymbolTable.h" @@ -222,7 +223,9 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) { EnumerateType(Type::getVoidTy(MD->getContext())); } return; - } else if (const NamedMDNode *N = dyn_cast(MD)) { + } + + if (const NamedMDNode *N = dyn_cast(MD)) { for(NamedMDNode::const_elem_iterator I = N->elem_begin(), E = N->elem_end(); I != E; ++I) { MetadataBase *M = *I; @@ -273,7 +276,8 @@ void ValueEnumerator::EnumerateValue(const Value *V) { // graph that don't go through a global variable. for (User::const_op_iterator I = C->op_begin(), E = C->op_end(); I != E; ++I) - EnumerateValue(*I); + if (!isa(*I)) // Don't enumerate BB operand to BlockAddress. + EnumerateValue(*I); // Finally, add the value. Doing this could make the ValueID reference be // dangling, don't reuse it. @@ -319,15 +323,20 @@ void ValueEnumerator::EnumerateOperandType(const Value *V) { // This constant may have operands, make sure to enumerate the types in // them. - for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) - EnumerateOperandType(C->getOperand(i)); + for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) { + const User *Op = C->getOperand(i); + + // Don't enumerate basic blocks here, this happens as operands to + // blockaddress. + if (isa(Op)) continue; + + EnumerateOperandType(cast(Op)); + } if (const MDNode *N = dyn_cast(V)) { - for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) { - Value *Elem = N->getElement(i); - if (Elem) + for (unsigned i = 0, e = N->getNumElements(); i != e; ++i) + if (Value *Elem = N->getElement(i)) EnumerateOperandType(Elem); - } } } else if (isa(V) || isa(V)) EnumerateValue(V); @@ -396,3 +405,23 @@ void ValueEnumerator::purgeFunction() { Values.resize(NumModuleValues); BasicBlocks.clear(); } + +static void IncorporateFunctionInfoGlobalBBIDs(const Function *F, + DenseMap &IDMap) { + unsigned Counter = 0; + for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) + IDMap[BB] = ++Counter; +} + +/// getGlobalBasicBlockID - This returns the function-specific ID for the +/// specified basic block. This is relatively expensive information, so it +/// should only be used by rare constructs such as address-of-label. +unsigned ValueEnumerator::getGlobalBasicBlockID(const BasicBlock *BB) const { + unsigned &Idx = GlobalBasicBlockIDs[BB]; + if (Idx != 0) + return Idx-1; + + IncorporateFunctionInfoGlobalBBIDs(BB->getParent(), GlobalBasicBlockIDs); + return getGlobalBasicBlockID(BB); +} + -- cgit v1.1