From 9f7b7089be854c323f8d9a4627d80e47adf496e6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 31 Dec 2009 18:40:32 +0000 Subject: [PATCH] change reassociate to use SmallVector for its key datastructures instead of std::vector. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92366 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/Reassociate.cpp | 33 +++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index a75d027c509..fe63381077f 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -59,7 +59,7 @@ namespace { #ifndef NDEBUG /// PrintOps - Print out the expression identified in the Ops list. /// -static void PrintOps(Instruction *I, const std::vector &Ops) { +static void PrintOps(Instruction *I, const SmallVectorImpl &Ops) { Module *M = I->getParent()->getParent()->getParent(); errs() << Instruction::getOpcodeName(I->getOpcode()) << " " << *Ops[0].Op->getType() << '\t'; @@ -89,11 +89,12 @@ namespace { void BuildRankMap(Function &F); unsigned getRank(Value *V); void ReassociateExpression(BinaryOperator *I); - void RewriteExprTree(BinaryOperator *I, std::vector &Ops, + void RewriteExprTree(BinaryOperator *I, SmallVectorImpl &Ops, unsigned Idx = 0); - Value *OptimizeExpression(BinaryOperator *I, std::vector &Ops); - Value *OptimizeAdd(Instruction *I, std::vector &Ops); - void LinearizeExprTree(BinaryOperator *I, std::vector &Ops); + Value *OptimizeExpression(BinaryOperator *I, + SmallVectorImpl &Ops); + Value *OptimizeAdd(Instruction *I, SmallVectorImpl &Ops); + void LinearizeExprTree(BinaryOperator *I, SmallVectorImpl &Ops); void LinearizeExpr(BinaryOperator *I); Value *RemoveFactorFromExpression(Value *V, Value *Factor); void ReassociateBB(BasicBlock *BB); @@ -253,7 +254,7 @@ void Reassociate::LinearizeExpr(BinaryOperator *I) { /// caller MUST use something like RewriteExprTree to put the values back in. /// void Reassociate::LinearizeExprTree(BinaryOperator *I, - std::vector &Ops) { + SmallVectorImpl &Ops) { Value *LHS = I->getOperand(0), *RHS = I->getOperand(1); unsigned Opcode = I->getOpcode(); @@ -325,7 +326,7 @@ void Reassociate::LinearizeExprTree(BinaryOperator *I, // linearized and optimized, emit them in-order. This function is written to be // tail recursive. void Reassociate::RewriteExprTree(BinaryOperator *I, - std::vector &Ops, + SmallVectorImpl &Ops, unsigned i) { if (i+2 == Ops.size()) { if (I->getOperand(0) != Ops[i].Op || @@ -478,7 +479,7 @@ static Instruction *ConvertShiftToMul(Instruction *Shl, // Scan backwards and forwards among values with the same rank as element i to // see if X exists. If X does not exist, return i. -static unsigned FindInOperandList(std::vector &Ops, unsigned i, +static unsigned FindInOperandList(SmallVectorImpl &Ops, unsigned i, Value *X) { unsigned XRank = Ops[i].Rank; unsigned e = Ops.size(); @@ -510,7 +511,7 @@ Value *Reassociate::RemoveFactorFromExpression(Value *V, Value *Factor) { BinaryOperator *BO = isReassociableOp(V, Instruction::Mul); if (!BO) return 0; - std::vector Factors; + SmallVector Factors; LinearizeExprTree(BO, Factors); bool FoundFactor = false; @@ -553,7 +554,8 @@ static void FindSingleUseMultiplyFactors(Value *V, /// instruction. This optimizes based on identities. If it can be reduced to /// a single Value, it is returned, otherwise the Ops list is mutated as /// necessary. -static Value *OptimizeAndOrXor(unsigned Opcode, std::vector &Ops) { +static Value *OptimizeAndOrXor(unsigned Opcode, + SmallVectorImpl &Ops) { // Scan the operand lists looking for X and ~X pairs, along with X,X pairs. // If we find any, we can simplify the expression. X&~X == 0, X|~X == -1. for (unsigned i = 0, e = Ops.size(); i != e; ++i) { @@ -598,7 +600,8 @@ static Value *OptimizeAndOrXor(unsigned Opcode, std::vector &Ops) { /// OptimizeAdd - Optimize a series of operands to an 'add' instruction. This /// optimizes based on identities. If it can be reduced to a single Value, it /// is returned, otherwise the Ops list is mutated as necessary. -Value *Reassociate::OptimizeAdd(Instruction *I, std::vector &Ops) { +Value *Reassociate::OptimizeAdd(Instruction *I, + SmallVectorImpl &Ops) { // Scan the operand lists looking for X and -X pairs. If we find any, we // can simplify the expression. X+-X == 0. for (unsigned i = 0, e = Ops.size(); i != e; ++i) { @@ -718,7 +721,7 @@ Value *Reassociate::OptimizeAdd(Instruction *I, std::vector &Ops) { } Value *Reassociate::OptimizeExpression(BinaryOperator *I, - std::vector &Ops) { + SmallVectorImpl &Ops) { // Now that we have the linearized expression tree, try to optimize it. // Start by folding any constants that we found. bool IterateOptimization = false; @@ -852,7 +855,7 @@ void Reassociate::ReassociateBB(BasicBlock *BB) { void Reassociate::ReassociateExpression(BinaryOperator *I) { // First, walk the expression tree, linearizing the tree, collecting - std::vector Ops; + SmallVector Ops; LinearizeExprTree(I, Ops); DEBUG(errs() << "RAIn:\t"; PrintOps(I, Ops); errs() << '\n'); @@ -885,8 +888,8 @@ void Reassociate::ReassociateExpression(BinaryOperator *I) { cast(I->use_back())->getOpcode() == Instruction::Add && isa(Ops.back().Op) && cast(Ops.back().Op)->isAllOnesValue()) { - Ops.insert(Ops.begin(), Ops.back()); - Ops.pop_back(); + ValueEntry Tmp = Ops.pop_back_val(); + Ops.insert(Ops.begin(), Tmp); } DEBUG(errs() << "RAOut:\t"; PrintOps(I, Ops); errs() << '\n');