From: Rafael Espindola Date: Wed, 13 Oct 2010 02:08:17 +0000 (+0000) Subject: Fix PR8313 by changing ValueToValueMap use a TrackingVH. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6688c4a742b3d4ad511e35b463c2fe0f8abc04ab;p=oota-llvm.git Fix PR8313 by changing ValueToValueMap use a TrackingVH. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116390 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Transforms/Utils/ValueMapper.h b/include/llvm/Transforms/Utils/ValueMapper.h index 5274112897b..dd320a3fb4c 100644 --- a/include/llvm/Transforms/Utils/ValueMapper.h +++ b/include/llvm/Transforms/Utils/ValueMapper.h @@ -20,7 +20,7 @@ namespace llvm { class Value; class Instruction; - typedef ValueMap ValueToValueMapTy; + typedef ValueMap > ValueToValueMapTy; Value *MapValue(const Value *V, ValueToValueMapTy &VM, bool ModuleLevelChanges); diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index f43186edae4..80da08611dc 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -216,7 +216,7 @@ namespace { /// anything that it can reach. void PruningFunctionCloner::CloneBlock(const BasicBlock *BB, std::vector &ToClone){ - Value *&BBEntry = VMap[BB]; + TrackingVH &BBEntry = VMap[BB]; // Have we already cloned this block? if (BBEntry) return; @@ -262,8 +262,10 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB, // If the condition was a known constant in the callee... ConstantInt *Cond = dyn_cast(BI->getCondition()); // Or is a known constant in the caller... - if (Cond == 0) - Cond = dyn_cast_or_null(VMap[BI->getCondition()]); + if (Cond == 0) { + Value *V = VMap[BI->getCondition()]; + Cond = dyn_cast_or_null(V); + } // Constant fold to uncond branch! if (Cond) { @@ -276,8 +278,10 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB, } else if (const SwitchInst *SI = dyn_cast(OldTI)) { // If switching on a value known constant in the caller. ConstantInt *Cond = dyn_cast(SI->getCondition()); - if (Cond == 0) // Or known constant after constant prop in the callee... - Cond = dyn_cast_or_null(VMap[SI->getCondition()]); + if (Cond == 0) { // Or known constant after constant prop in the callee... + Value *V = VMap[SI->getCondition()]; + Cond = dyn_cast_or_null(V); + } if (Cond) { // Constant fold to uncond branch! BasicBlock *Dest = SI->getSuccessor(SI->findCaseValue(Cond)); VMap[OldTI] = BranchInst::Create(Dest, NewBB); @@ -394,7 +398,8 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, SmallVector PHIToResolve; for (Function::const_iterator BI = OldFunc->begin(), BE = OldFunc->end(); BI != BE; ++BI) { - BasicBlock *NewBB = cast_or_null(VMap[BI]); + Value *V = VMap[BI]; + BasicBlock *NewBB = cast_or_null(V); if (NewBB == 0) continue; // Dead block. // Add the new block to the new function. @@ -474,8 +479,9 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, OPN = PHIToResolve[phino]; PHINode *PN = cast(VMap[OPN]); for (unsigned pred = 0, e = NumPreds; pred != e; ++pred) { + Value *V = VMap[PN->getIncomingBlock(pred)]; if (BasicBlock *MappedBlock = - cast_or_null(VMap[PN->getIncomingBlock(pred)])) { + cast_or_null(V)) { Value *InVal = MapValue(PN->getIncomingValue(pred), VMap, ModuleLevelChanges); assert(InVal && "Unknown input value?"); diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index fc4bde77d4f..9455e532b0e 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -22,7 +22,7 @@ using namespace llvm; Value *llvm::MapValue(const Value *V, ValueToValueMapTy &VM, bool ModuleLevelChanges) { - Value *&VMSlot = VM[V]; + TrackingVH &VMSlot = VM[V]; if (VMSlot) return VMSlot; // Does it exist in the map yet? // NOTE: VMSlot can be invalidated by any reference to VM, which can grow the