[llvm] 302313a - [Transforms] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 8 22:34:24 PST 2021
Author: Kazu Hirata
Date: 2021-02-08T22:33:53-08:00
New Revision: 302313a264c4e49507789919982cdb20277b2c3c
URL: https://github.com/llvm/llvm-project/commit/302313a264c4e49507789919982cdb20277b2c3c
DIFF: https://github.com/llvm/llvm-project/commit/302313a264c4e49507789919982cdb20277b2c3c.diff
LOG: [Transforms] Use range-based for loops (NFC)
Added:
Modified:
llvm/lib/Transforms/IPO/ExtractGV.cpp
llvm/lib/Transforms/IPO/StripSymbols.cpp
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/ExtractGV.cpp b/llvm/lib/Transforms/IPO/ExtractGV.cpp
index b45766a8e783..ba0efd46af16 100644
--- a/llvm/lib/Transforms/IPO/ExtractGV.cpp
+++ b/llvm/lib/Transforms/IPO/ExtractGV.cpp
@@ -82,24 +82,23 @@ namespace {
// be conservative and simple.
// Visit the GlobalVariables.
- for (Module::global_iterator I = M.global_begin(), E = M.global_end();
- I != E; ++I) {
- bool Delete =
- deleteStuff == (bool)Named.count(&*I) && !I->isDeclaration() &&
- (!I->isConstant() || !keepConstInit);
+ for (GlobalVariable &GV : M.globals()) {
+ bool Delete = deleteStuff == (bool)Named.count(&GV) &&
+ !GV.isDeclaration() &&
+ (!GV.isConstant() || !keepConstInit);
if (!Delete) {
- if (I->hasAvailableExternallyLinkage())
+ if (GV.hasAvailableExternallyLinkage())
continue;
- if (I->getName() == "llvm.global_ctors")
+ if (GV.getName() == "llvm.global_ctors")
continue;
}
- makeVisible(*I, Delete);
+ makeVisible(GV, Delete);
if (Delete) {
// Make this a declaration and drop it's comdat.
- I->setInitializer(nullptr);
- I->setComdat(nullptr);
+ GV.setInitializer(nullptr);
+ GV.setComdat(nullptr);
}
}
diff --git a/llvm/lib/Transforms/IPO/StripSymbols.cpp b/llvm/lib/Transforms/IPO/StripSymbols.cpp
index 4fc71847a070..168740a1158e 100644
--- a/llvm/lib/Transforms/IPO/StripSymbols.cpp
+++ b/llvm/lib/Transforms/IPO/StripSymbols.cpp
@@ -213,11 +213,10 @@ static bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {
findUsedValues(M.getGlobalVariable("llvm.used"), llvmUsedValues);
findUsedValues(M.getGlobalVariable("llvm.compiler.used"), llvmUsedValues);
- for (Module::global_iterator I = M.global_begin(), E = M.global_end();
- I != E; ++I) {
- if (I->hasLocalLinkage() && llvmUsedValues.count(&*I) == 0)
- if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
- I->setName(""); // Internal symbols can't participate in linkage
+ for (GlobalVariable &GV : M.globals()) {
+ if (GV.hasLocalLinkage() && llvmUsedValues.count(&GV) == 0)
+ if (!PreserveDbgInfo || !GV.getName().startswith("llvm.dbg"))
+ GV.setName(""); // Internal symbols can't participate in linkage
}
for (Function &I : M) {
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 4b485a0ad85e..5526739a016f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -661,13 +661,12 @@ bool InstCombinerImpl::simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I) {
break;
// Replace uses of the select or its condition with the known values.
- for (Instruction::op_iterator I = BBI->op_begin(), E = BBI->op_end();
- I != E; ++I) {
- if (*I == SI) {
- replaceUse(*I, SI->getOperand(NonNullOperand));
+ for (Use &Op : BBI->operands()) {
+ if (Op == SI) {
+ replaceUse(Op, SI->getOperand(NonNullOperand));
Worklist.push(&*BBI);
- } else if (*I == SelectCond) {
- replaceUse(*I, NonNullOperand == 1 ? ConstantInt::getTrue(CondTy)
+ } else if (Op == SelectCond) {
+ replaceUse(Op, NonNullOperand == 1 ? ConstantInt::getTrue(CondTy)
: ConstantInt::getFalse(CondTy));
Worklist.push(&*BBI);
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
index 7718c8b0eedd..37c7e6135501 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
@@ -479,8 +479,8 @@ LLVM_NODISCARD Optional<Negator::Result> Negator::run(Value *Root) {
if (!Negated) {
// We must cleanup newly-inserted instructions, to avoid any potential
// endless combine looping.
- llvm::for_each(llvm::reverse(NewInstructions),
- [&](Instruction *I) { I->eraseFromParent(); });
+ for (Instruction *I : llvm::reverse(NewInstructions))
+ I->eraseFromParent();
return llvm::None;
}
return std::make_pair(ArrayRef<Instruction *>(NewInstructions), Negated);
@@ -523,8 +523,8 @@ LLVM_NODISCARD Value *Negator::Negate(bool LHSIsZero, Value *Root,
NegatorNumInstructionsNegatedSuccess += Res->first.size();
// They are in def-use order, so nothing fancy, just insert them in order.
- llvm::for_each(Res->first,
- [&](Instruction *I) { IC.Builder.Insert(I, I->getName()); });
+ for (Instruction *I : Res->first)
+ IC.Builder.Insert(I, I->getName());
// And return the new root.
return Res->second;
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 518e909e8ab4..6ed63812998a 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3083,9 +3083,8 @@ Instruction *InstCombinerImpl::visitExtractValueInst(ExtractValueInst &EV) {
SmallVector<Value*, 4> Indices;
// Prefix an i32 0 since we need the first element.
Indices.push_back(Builder.getInt32(0));
- for (ExtractValueInst::idx_iterator I = EV.idx_begin(), E = EV.idx_end();
- I != E; ++I)
- Indices.push_back(Builder.getInt32(*I));
+ for (unsigned Idx : EV.indices())
+ Indices.push_back(Builder.getInt32(Idx));
// We need to insert these at the location of the old load, not at that of
// the extractvalue.
diff --git a/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp b/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp
index 7f7f2dc89b7e..74e4eb07b219 100644
--- a/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp
+++ b/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.cpp
@@ -110,9 +110,8 @@ bool llvm::objcarc::CanUse(const Instruction *Inst, const Value *Ptr,
}
// Check each operand for a match.
- for (User::const_op_iterator OI = Inst->op_begin(), OE = Inst->op_end();
- OI != OE; ++OI) {
- const Value *Op = *OI;
+ for (const Use &U : Inst->operands()) {
+ const Value *Op = U;
if (IsPotentialRetainableObjPtr(Op, *PA.getAA()) && PA.related(Ptr, Op))
return true;
}
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 5a3b9e999019..37fce501a23e 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -289,9 +289,8 @@ GVN::Expression GVN::ValueTable::createExpr(Instruction *I) {
Expression e;
e.type = I->getType();
e.opcode = I->getOpcode();
- for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
- OI != OE; ++OI)
- e.varargs.push_back(lookupOrAdd(*OI));
+ for (Use &Op : I->operands())
+ e.varargs.push_back(lookupOrAdd(Op));
if (I->isCommutative()) {
// Ensure that commutative instructions that only
diff er by a permutation
// of their operands get the same value number by sorting the operand value
@@ -362,9 +361,8 @@ GVN::Expression GVN::ValueTable::createExtractvalueExpr(ExtractValueInst *EI) {
// Not a recognised intrinsic. Fall back to producing an extract value
// expression.
e.opcode = EI->getOpcode();
- for (Instruction::op_iterator OI = EI->op_begin(), OE = EI->op_end();
- OI != OE; ++OI)
- e.varargs.push_back(lookupOrAdd(*OI));
+ for (Use &Op : EI->operands())
+ e.varargs.push_back(lookupOrAdd(Op));
append_range(e.varargs, EI->indices());
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index d6223415c154..9d8b7c1c07e7 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1072,8 +1072,8 @@ static Instruction *getDebugLocFromInstOrOperands(Instruction *I) {
if (I->getDebugLoc() != Empty)
return I;
- for (User::op_iterator OI = I->op_begin(), OE = I->op_end(); OI != OE; ++OI) {
- if (Instruction *OpInst = dyn_cast<Instruction>(*OI))
+ for (Use &Op : I->operands()) {
+ if (Instruction *OpInst = dyn_cast<Instruction>(Op))
if (OpInst->getDebugLoc() != Empty)
return OpInst;
}
More information about the llvm-commits
mailing list