eliminate temporary vectors
authorChris Lattner <sabre@nondot.org>
Wed, 31 Jan 2007 04:40:53 +0000 (04:40 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 31 Jan 2007 04:40:53 +0000 (04:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33693 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp
lib/Transforms/Scalar/InstructionCombining.cpp

index 3bfa15cde6a1c60851a5a53d424e5e1dc18b90ee..f76c152b8adade83c50204aed7cafa3a24dc2b01 100644 (file)
@@ -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 <algorithm>
@@ -443,11 +444,12 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV) {
     // Form a shorter GEP if needed.
     if (GEP->getNumOperands() > 3)
       if (ConstantExpr *CE = dyn_cast<ConstantExpr>(GEP)) {
-        std::vector<Constant*> Idxs;
+        SmallVector<Constant*, 8> 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<Constant>(NewPtr), Idxs);
+        NewPtr = ConstantExpr::getGetElementPtr(cast<Constant>(NewPtr),
+                                                &Idxs[0], Idxs.size());
       } else {
         GetElementPtrInst *GEPI = cast<GetElementPtrInst>(GEP);
         std::vector<Value*> Idxs;
@@ -576,16 +578,17 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) {
       }
     } else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(I)) {
       // Should handle GEP here.
-      std::vector<Constant*> Indices;
-      Indices.reserve(GEPI->getNumOperands()-1);
+      SmallVector<Constant*, 8> Idxs;
+      Idxs.reserve(GEPI->getNumOperands()-1);
       for (unsigned i = 1, e = GEPI->getNumOperands(); i != e; ++i)
         if (Constant *C = dyn_cast<Constant>(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<GetElementPtrInst>(CurInst)) {
       Constant *P = getVal(Values, GEP->getOperand(0));
-      std::vector<Constant*> GEPOps;
+      SmallVector<Constant*, 8> 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<LoadInst>(CurInst)) {
       if (LI->isVolatile()) return false;  // no volatile accesses.
       InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)),
index adbc29613d04da843b9c73b9c316e6625a8fa2d9..c11d249f1f50bb63ced7f595f16b960b55eb123d 100644 (file)
@@ -173,9 +173,10 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
               /*empty*/;
             if (isa<SequentialType>(*GTI)) {
               // Pull the last index out of the constant expr GEP.
-              std::vector<Value*> CEIdxs(CE->op_begin()+1, CE->op_end()-1);
+              SmallVector<Value*, 8> 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);
index 3ce0f6f403b8001772e1673615519ef556bd3a73..39841d6cee798a91301a309dff7c51f172e9bc20 100644 (file)
@@ -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 <algorithm>
@@ -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<Constant*> Indices;
+    SmallVector<Constant*, 8> Indices;
     User::op_iterator I = GEP.idx_begin(), E = GEP.idx_end();
     for (; I != E && isa<Constant>(*I); ++I)
       Indices.push_back(cast<Constant>(*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<ArrayType>(SrcPTy))
         if (Constant *CSrc = dyn_cast<Constant>(CastOp))
           if (ASrcTy->getNumElements() != 0) {
-            std::vector<Value*> 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<PointerType>(CastOp->getType());
             SrcPTy = SrcTy->getElementType();
           }
@@ -8188,8 +8191,9 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
       if (const ArrayType *ASrcTy = dyn_cast<ArrayType>(SrcPTy))
         if (Constant *CSrc = dyn_cast<Constant>(CastOp))
           if (ASrcTy->getNumElements() != 0) {
-            std::vector<Value*> 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<PointerType>(CastOp->getType());
             SrcPTy = SrcTy->getElementType();
           }