diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 3bfa15cde6a..f76c152b8ad 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -25,6 +25,7 @@ #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/Debug.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" #include @@ -443,11 +444,12 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV) { // Form a shorter GEP if needed. if (GEP->getNumOperands() > 3) if (ConstantExpr *CE = dyn_cast(GEP)) { - std::vector Idxs; + SmallVector Idxs; Idxs.push_back(NullInt); for (unsigned i = 3, e = CE->getNumOperands(); i != e; ++i) Idxs.push_back(CE->getOperand(i)); - NewPtr = ConstantExpr::getGetElementPtr(cast(NewPtr), Idxs); + NewPtr = ConstantExpr::getGetElementPtr(cast(NewPtr), + &Idxs[0], Idxs.size()); } else { GetElementPtrInst *GEPI = cast(GEP); std::vector Idxs; @@ -576,16 +578,17 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) { } } else if (GetElementPtrInst *GEPI = dyn_cast(I)) { // Should handle GEP here. - std::vector Indices; - Indices.reserve(GEPI->getNumOperands()-1); + SmallVector Idxs; + Idxs.reserve(GEPI->getNumOperands()-1); for (unsigned i = 1, e = GEPI->getNumOperands(); i != e; ++i) if (Constant *C = dyn_cast(GEPI->getOperand(i))) - Indices.push_back(C); + Idxs.push_back(C); else break; - if (Indices.size() == GEPI->getNumOperands()-1) + if (Idxs.size() == GEPI->getNumOperands()-1) Changed |= OptimizeAwayTrappingUsesOfValue(GEPI, - ConstantExpr::getGetElementPtr(NewV, Indices)); + ConstantExpr::getGetElementPtr(NewV, &Idxs[0], + Idxs.size())); if (GEPI->use_empty()) { Changed = true; GEPI->eraseFromParent(); @@ -1744,10 +1747,10 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, getVal(Values, SI->getOperand(2))); } else if (GetElementPtrInst *GEP = dyn_cast(CurInst)) { Constant *P = getVal(Values, GEP->getOperand(0)); - std::vector GEPOps; + SmallVector GEPOps; for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i) GEPOps.push_back(getVal(Values, GEP->getOperand(i))); - InstResult = ConstantExpr::getGetElementPtr(P, GEPOps); + InstResult = ConstantExpr::getGetElementPtr(P, &GEPOps[0], GEPOps.size()); } else if (LoadInst *LI = dyn_cast(CurInst)) { if (LI->isVolatile()) return false; // no volatile accesses. InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)), diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index adbc29613d0..c11d249f1f5 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -173,9 +173,10 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN, /*empty*/; if (isa(*GTI)) { // Pull the last index out of the constant expr GEP. - std::vector CEIdxs(CE->op_begin()+1, CE->op_end()-1); + SmallVector CEIdxs(CE->op_begin()+1, CE->op_end()-1); Constant *NCE = ConstantExpr::getGetElementPtr(CE->getOperand(0), - CEIdxs); + &CEIdxs[0], + CEIdxs.size()); GetElementPtrInst *NGEPI = new GetElementPtrInst(NCE, Constant::getNullValue(Type::Int32Ty), NewAdd, GEPI->getName(), GEPI); diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 3ce0f6f403b..39841d6cee7 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -50,6 +50,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/PatternMatch.h" #include "llvm/Support/Compiler.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/STLExtras.h" #include @@ -7797,13 +7798,14 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // constants, we can promote this to a constexpr instead of an instruction. // Scan for nonconstants... - std::vector Indices; + SmallVector Indices; User::op_iterator I = GEP.idx_begin(), E = GEP.idx_end(); for (; I != E && isa(*I); ++I) Indices.push_back(cast(*I)); if (I == E) { // If they are all constants... - Constant *CE = ConstantExpr::getGetElementPtr(GV, Indices); + Constant *CE = ConstantExpr::getGetElementPtr(GV, + &Indices[0],Indices.size()); // Replace all uses of the GEP with the new constexpr... return ReplaceInstUsesWith(GEP, CE); @@ -8001,8 +8003,9 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI) { if (const ArrayType *ASrcTy = dyn_cast(SrcPTy)) if (Constant *CSrc = dyn_cast(CastOp)) if (ASrcTy->getNumElements() != 0) { - std::vector Idxs(2, Constant::getNullValue(Type::Int32Ty)); - CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs); + Value *Idxs[2]; + Idxs[0] = Idxs[1] = Constant::getNullValue(Type::Int32Ty); + CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs, 2); SrcTy = cast(CastOp->getType()); SrcPTy = SrcTy->getElementType(); } @@ -8188,8 +8191,9 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) { if (const ArrayType *ASrcTy = dyn_cast(SrcPTy)) if (Constant *CSrc = dyn_cast(CastOp)) if (ASrcTy->getNumElements() != 0) { - std::vector Idxs(2, Constant::getNullValue(Type::Int32Ty)); - CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs); + Value* Idxs[2]; + Idxs[0] = Idxs[1] = Constant::getNullValue(Type::Int32Ty); + CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs, 2); SrcTy = cast(CastOp->getType()); SrcPTy = SrcTy->getElementType(); }