[llvm] 7ca14f6 - [llvm] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 18 09:10:02 PST 2021
Author: Kazu Hirata
Date: 2021-11-18T09:09:52-08:00
New Revision: 7ca14f6044bfa46efdbb4d4080e36c3265a09a78
URL: https://github.com/llvm/llvm-project/commit/7ca14f6044bfa46efdbb4d4080e36c3265a09a78
DIFF: https://github.com/llvm/llvm-project/commit/7ca14f6044bfa46efdbb4d4080e36c3265a09a78.diff
LOG: [llvm] Use range-based for loops (NFC)
Added:
Modified:
llvm/lib/Analysis/MemorySSAUpdater.cpp
llvm/lib/Analysis/ObjCARCInstKind.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/CodeGen/StackProtector.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/TypeFinder.cpp
llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
llvm/lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp
llvm/lib/Target/NVPTX/NVPTXImageOptimizer.cpp
llvm/lib/Target/X86/X86LowerAMXType.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp
index 8de0adc0fd289..9c841883de6db 100644
--- a/llvm/lib/Analysis/MemorySSAUpdater.cpp
+++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp
@@ -296,9 +296,8 @@ static void setMemoryPhiValueForBlock(MemoryPhi *MP, const BasicBlock *BB,
assert(i != -1 && "Should have found the basic block in the phi");
// We can't just compare i against getNumOperands since one is signed and the
// other not. So use it to index into the block iterator.
- for (auto BBIter = MP->block_begin() + i; BBIter != MP->block_end();
- ++BBIter) {
- if (*BBIter != BB)
+ for (const BasicBlock *BlockBB : llvm::drop_begin(MP->blocks(), i)) {
+ if (BlockBB != BB)
break;
MP->setIncomingValue(i, NewDef);
++i;
diff --git a/llvm/lib/Analysis/ObjCARCInstKind.cpp b/llvm/lib/Analysis/ObjCARCInstKind.cpp
index 704d15f3280dc..f74a9f7f104fa 100644
--- a/llvm/lib/Analysis/ObjCARCInstKind.cpp
+++ b/llvm/lib/Analysis/ObjCARCInstKind.cpp
@@ -296,9 +296,8 @@ ARCInstKind llvm::objcarc::GetARCInstKind(const Value *V) {
// operand isn't actually being dereferenced, it is being stored to
// memory where we can no longer track who might read it and dereference
// it, so we have to consider it potentially used.
- for (User::const_op_iterator OI = I->op_begin(), OE = I->op_end();
- OI != OE; ++OI)
- if (IsPotentialRetainableObjPtr(*OI))
+ for (const Use &U : I->operands())
+ if (IsPotentialRetainableObjPtr(U))
return ARCInstKind::User;
}
}
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index fd77a8c80bb41..1e9a9197aed71 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -973,9 +973,8 @@ void ModuleBitcodeWriter::writeTypeTable() {
// STRUCT: [ispacked, eltty x N]
TypeVals.push_back(ST->isPacked());
// Output all of the element types.
- for (StructType::element_iterator I = ST->element_begin(),
- E = ST->element_end(); I != E; ++I)
- TypeVals.push_back(VE.getTypeID(*I));
+ for (Type *ET : ST->elements())
+ TypeVals.push_back(VE.getTypeID(ET));
if (ST->isLiteral()) {
Code = bitc::TYPE_CODE_STRUCT_ANON;
diff --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp
index d6d49c300d7ce..7445f77c955da 100644
--- a/llvm/lib/CodeGen/StackProtector.cpp
+++ b/llvm/lib/CodeGen/StackProtector.cpp
@@ -148,10 +148,8 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
return false;
bool NeedsProtector = false;
- for (StructType::element_iterator I = ST->element_begin(),
- E = ST->element_end();
- I != E; ++I)
- if (ContainsProtectableArray(*I, IsLarge, Strong, true)) {
+ for (Type *ET : ST->elements())
+ if (ContainsProtectableArray(ET, IsLarge, Strong, true)) {
// If the element is a protectable array and is large (>= SSPBufferSize)
// then we are done. If the protectable array is not large, then
// keep looking in case a subsequent element is a large array.
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index c7a46bd5fe253..7734c0a8de58a 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -555,16 +555,13 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
FunctionType *FTy = cast<FunctionType>(Ty);
print(FTy->getReturnType(), OS);
OS << " (";
- for (FunctionType::param_iterator I = FTy->param_begin(),
- E = FTy->param_end(); I != E; ++I) {
- if (I != FTy->param_begin())
- OS << ", ";
- print(*I, OS);
- }
- if (FTy->isVarArg()) {
- if (FTy->getNumParams()) OS << ", ";
- OS << "...";
+ ListSeparator LS;
+ for (Type *Ty : FTy->params()) {
+ OS << LS;
+ print(Ty, OS);
}
+ if (FTy->isVarArg())
+ OS << LS << "...";
OS << ')';
return;
}
@@ -634,12 +631,11 @@ void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
if (STy->getNumElements() == 0) {
OS << "{}";
} else {
- StructType::element_iterator I = STy->element_begin();
OS << "{ ";
- print(*I++, OS);
- for (StructType::element_iterator E = STy->element_end(); I != E; ++I) {
- OS << ", ";
- print(*I, OS);
+ ListSeparator LS;
+ for (Type *Ty : STy->elements()) {
+ OS << LS;
+ print(Ty, OS);
}
OS << " }";
diff --git a/llvm/lib/IR/TypeFinder.cpp b/llvm/lib/IR/TypeFinder.cpp
index 724b8f6b6ad2b..1f757d7dbf4e9 100644
--- a/llvm/lib/IR/TypeFinder.cpp
+++ b/llvm/lib/IR/TypeFinder.cpp
@@ -106,11 +106,9 @@ void TypeFinder::incorporateType(Type *Ty) {
StructTypes.push_back(STy);
// Add all unvisited subtypes to worklist for processing
- for (Type::subtype_reverse_iterator I = Ty->subtype_rbegin(),
- E = Ty->subtype_rend();
- I != E; ++I)
- if (VisitedTypes.insert(*I).second)
- TypeWorklist.push_back(*I);
+ for (Type *SubTy : llvm::reverse(Ty->subtypes()))
+ if (VisitedTypes.insert(SubTy).second)
+ TypeWorklist.push_back(SubTy);
} while (!TypeWorklist.empty());
}
diff --git a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
index 04522480b0e7e..ccaf1aac1ce01 100644
--- a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
@@ -1351,8 +1351,8 @@ bool PolynomialMultiplyRecognize::convertShiftsToLeft(BasicBlock *LoopB,
// be unshifted.
if (!commutesWithShift(R))
return false;
- for (auto I = R->user_begin(), E = R->user_end(); I != E; ++I) {
- auto *T = cast<Instruction>(*I);
+ for (User *U : R->users()) {
+ auto *T = cast<Instruction>(U);
// Skip users from outside of the loop. They will be handled later.
// Also, skip the right-shifts and phi nodes, since they mix early
// and late values.
diff --git a/llvm/lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp b/llvm/lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp
index 310536458de91..f973862a0c9b6 100644
--- a/llvm/lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp
@@ -386,8 +386,7 @@ void HexagonVectorLoopCarriedReuse::findValueToReuse() {
<< " can be reused\n");
SmallVector<Instruction *, 4> PNUsers;
- for (auto UI = PN->use_begin(), E = PN->use_end(); UI != E; ++UI) {
- Use &U = *UI;
+ for (Use &U : PN->uses()) {
Instruction *User = cast<Instruction>(U.getUser());
if (User->getParent() != BB)
@@ -415,9 +414,7 @@ void HexagonVectorLoopCarriedReuse::findValueToReuse() {
// rematerialized in OtherBB, we may find more such "fixup" opportunities
// in this block. So, we'll start over again.
for (Instruction *I : PNUsers) {
- for (auto UI = BEInst->use_begin(), E = BEInst->use_end(); UI != E;
- ++UI) {
- Use &U = *UI;
+ for (Use &U : BEInst->uses()) {
Instruction *BEUser = cast<Instruction>(U.getUser());
if (BEUser->getParent() != BB)
diff --git a/llvm/lib/Target/NVPTX/NVPTXImageOptimizer.cpp b/llvm/lib/Target/NVPTX/NVPTXImageOptimizer.cpp
index a846c2fada269..fc0d5cc6fbfa8 100644
--- a/llvm/lib/Target/NVPTX/NVPTXImageOptimizer.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXImageOptimizer.cpp
@@ -148,9 +148,8 @@ void NVPTXImageOptimizer::replaceWith(Instruction *From, ConstantInt *To) {
// We implement "poor man's DCE" here to make sure any code that is no longer
// live is actually unreachable and can be trivially eliminated by the
// unreachable block elimination pass.
- for (CallInst::use_iterator UI = From->use_begin(), UE = From->use_end();
- UI != UE; ++UI) {
- if (BranchInst *BI = dyn_cast<BranchInst>(*UI)) {
+ for (Use &U : From->uses()) {
+ if (BranchInst *BI = dyn_cast<BranchInst>(U)) {
if (BI->isUnconditional()) continue;
BasicBlock *Dest;
if (To->isZero())
diff --git a/llvm/lib/Target/X86/X86LowerAMXType.cpp b/llvm/lib/Target/X86/X86LowerAMXType.cpp
index 8e82119f71a38..7368b64efd9ae 100644
--- a/llvm/lib/Target/X86/X86LowerAMXType.cpp
+++ b/llvm/lib/Target/X86/X86LowerAMXType.cpp
@@ -345,10 +345,8 @@ bool X86LowerAMXType::visit() {
continue;
}
StoreInst *ST = nullptr;
- for (auto UI = Bitcast->use_begin(), UE = Bitcast->use_end();
- UI != UE;) {
- Value *I = (UI++)->getUser();
- ST = dyn_cast<StoreInst>(I);
+ for (Use &U : Bitcast->uses()) {
+ ST = dyn_cast<StoreInst>(U.getUser());
if (ST)
break;
}
More information about the llvm-commits
mailing list