From: Gabor Greif Date: Thu, 29 May 2008 01:59:18 +0000 (+0000) Subject: convert more operand loops to iterator formulation X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5e46321d665d6b1f445aff70d8eabb4870a6cf0e;p=oota-llvm.git convert more operand loops to iterator formulation git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51663 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 7feb1744a06..26ff8d703a2 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -262,8 +262,9 @@ bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg, bool isByVal) const { } // Ensure that all of the indices are constants. SmallVector Operands; - for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i) - if (ConstantInt *C = dyn_cast(GEP->getOperand(i))) + for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); + i != e; ++i) + if (ConstantInt *C = dyn_cast(*i)) Operands.push_back(C); else return false; // Not a constant operand GEP! diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 0da0c97bfb8..5c96317a8a5 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -704,8 +704,9 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) { // Should handle GEP here. 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))) + for (User::op_iterator i = GEPI->op_begin() + 1, e = GEPI->op_end(); + i != e; ++i) + if (Constant *C = dyn_cast(*i)) Idxs.push_back(C); else break; @@ -984,8 +985,8 @@ static bool GlobalLoadUsesSimpleEnoughForHeapSRA(GlobalVariable *GV, if (LoadInst *LI = dyn_cast(*UI)) { // We permit two users of the load: setcc comparing against the null // pointer, and a getelementptr of a specific form. - for (Value::use_iterator UI = LI->use_begin(), E = LI->use_end(); UI != E; - ++UI) { + for (Value::use_iterator UI = LI->use_begin(), E = LI->use_end(); + UI != E; ++UI) { // Comparison against null is ok. if (ICmpInst *ICI = dyn_cast(*UI)) { if (!isa(ICI->getOperand(1))) @@ -1279,9 +1280,10 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, else if (GetElementPtrInst *GEPI =dyn_cast(StoredOnceVal)){ // "getelementptr Ptr, 0, 0, 0" is really just a cast. bool IsJustACast = true; - for (unsigned i = 1, e = GEPI->getNumOperands(); i != e; ++i) - if (!isa(GEPI->getOperand(i)) || - !cast(GEPI->getOperand(i))->isNullValue()) { + for (User::op_iterator i = GEPI->op_begin() + 1, e = GEPI->op_end(); + i != e; ++i) + if (!isa(*i) || + !cast(*i)->isNullValue()) { IsJustACast = false; break; } @@ -1606,8 +1608,9 @@ static bool OnlyCalledDirectly(Function *F) { if (!isa(User) && !isa(User)) return false; // See if the function address is passed as an argument. - for (unsigned i = 1, e = User->getNumOperands(); i != e; ++i) - if (User->getOperand(i) == F) return false; + for (User::op_iterator i = User->op_begin() + 1, e = User->op_end(); + i != e; ++i) + if (*i == F) return false; } return true; } @@ -1712,8 +1715,8 @@ GlobalVariable *GlobalOpt::FindGlobalCtors(Module &M) { if (!I->hasInitializer()) return 0; ConstantArray *CA = dyn_cast(I->getInitializer()); if (!CA) return 0; - for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) - if (ConstantStruct *CS = dyn_cast(CA->getOperand(i))) { + for (User::op_iterator i = CA->op_begin(), e = CA->op_end(); i != e; ++i) + if (ConstantStruct *CS = dyn_cast(*i)) { if (isa(CS->getOperand(1))) continue; @@ -1740,8 +1743,8 @@ static std::vector ParseGlobalCtors(GlobalVariable *GV) { ConstantArray *CA = cast(GV->getInitializer()); std::vector Result; Result.reserve(CA->getNumOperands()); - for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) { - ConstantStruct *CS = cast(CA->getOperand(i)); + for (User::op_iterator i = CA->op_begin(), e = CA->op_end(); i != e; ++i) { + ConstantStruct *CS = cast(*i); Result.push_back(dyn_cast(CS->getOperand(1))); } return Result; @@ -1854,8 +1857,8 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val, // Break up the constant into its elements. if (ConstantStruct *CS = dyn_cast(Init)) { - for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) - Elts.push_back(CS->getOperand(i)); + for (User::op_iterator i = CS->op_begin(), e = CS->op_end(); i != e; ++i) + Elts.push_back(cast(*i)); } else if (isa(Init)) { for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) Elts.push_back(Constant::getNullValue(STy->getElementType(i))); @@ -1882,8 +1885,8 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val, // Break up the array into elements. std::vector Elts; if (ConstantArray *CA = dyn_cast(Init)) { - for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) - Elts.push_back(CA->getOperand(i)); + for (User::op_iterator i = CA->op_begin(), e = CA->op_end(); i != e; ++i) + Elts.push_back(cast(*i)); } else if (isa(Init)) { Constant *Elt = Constant::getNullValue(ATy->getElementType()); Elts.assign(ATy->getNumElements(), Elt); @@ -2011,8 +2014,9 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, } else if (GetElementPtrInst *GEP = dyn_cast(CurInst)) { Constant *P = getVal(Values, GEP->getOperand(0)); SmallVector GEPOps; - for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i) - GEPOps.push_back(getVal(Values, GEP->getOperand(i))); + for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); + i != e; ++i) + GEPOps.push_back(getVal(Values, *i)); InstResult = ConstantExpr::getGetElementPtr(P, &GEPOps[0], GEPOps.size()); } else if (LoadInst *LI = dyn_cast(CurInst)) { if (LI->isVolatile()) return false; // no volatile accesses. @@ -2036,8 +2040,9 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, if (!Callee) return false; // Cannot resolve. std::vector Formals; - for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i) - Formals.push_back(getVal(Values, CI->getOperand(i))); + for (User::op_iterator i = CI->op_begin() + 1, e = CI->op_end(); + i != e; ++i) + Formals.push_back(getVal(Values, *i)); if (Callee->isDeclaration()) { // If this is a function we can constant fold, do it.