From: Chris Lattner Date: Tue, 31 Mar 2009 22:13:29 +0000 (+0000) Subject: Make the key of ValueRankMap an AssertingVH, so that we die violently X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=d3c7b7359d4992b9ab9f8e12ccd0a9b7d2446566;p=oota-llvm.git Make the key of ValueRankMap an AssertingVH, so that we die violently if it dangles. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68150 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index 8f9ff6d4886..293cf9248b7 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -32,6 +32,7 @@ #include "llvm/Support/CFG.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/ValueHandle.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/Statistic.h" #include @@ -71,7 +72,7 @@ static void PrintOps(Instruction *I, const std::vector &Ops) { namespace { class VISIBILITY_HIDDEN Reassociate : public FunctionPass { std::map RankMap; - std::map ValueRankMap; + std::map, unsigned> ValueRankMap; bool MadeChange; public: static char ID; // Pass identification, replacement for typeid @@ -138,7 +139,7 @@ void Reassociate::BuildRankMap(Function &F) { // Assign distinct ranks to function arguments for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) - ValueRankMap[I] = ++i; + ValueRankMap[&*I] = ++i; ReversePostOrderTraversal RPOT(&F); for (ReversePostOrderTraversal::rpo_iterator I = RPOT.begin(), @@ -151,7 +152,7 @@ void Reassociate::BuildRankMap(Function &F) { // all different in the block. for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) if (isUnmovableInstruction(I)) - ValueRankMap[I] = ++BBRank; + ValueRankMap[&*I] = ++BBRank; } } @@ -197,7 +198,7 @@ static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) { /// LowerNegateToMultiply - Replace 0-X with X*-1. /// static Instruction *LowerNegateToMultiply(Instruction *Neg, - std::map &ValueRankMap) { + std::map, unsigned> &ValueRankMap) { Constant *Cst = ConstantInt::getAllOnesValue(Neg->getType()); Instruction *Res = BinaryOperator::CreateMul(Neg->getOperand(1), Cst, "",Neg); @@ -427,7 +428,7 @@ static bool ShouldBreakUpSubtract(Instruction *Sub) { /// only used by an add, transform this into (X+(0-Y)) to promote better /// reassociation. static Instruction *BreakUpSubtract(Instruction *Sub, - std::map &ValueRankMap) { + std::map, unsigned> &ValueRankMap) { // Convert a subtract into an add and a neg instruction... so that sub // instructions can be commuted with other add instructions... // @@ -452,7 +453,7 @@ static Instruction *BreakUpSubtract(Instruction *Sub, /// by one, change this into a multiply by a constant to assist with further /// reassociation. static Instruction *ConvertShiftToMul(Instruction *Shl, - std::map &ValueRankMap){ + std::map, unsigned> &ValueRankMap) { // If an operand of this shift is a reassociable multiply, or if the shift // is used by a reassociable multiply or add, turn into a multiply. if (isReassociableOp(Shl->getOperand(0), Instruction::Mul) ||