[llvm] 1457e78 - [llvm] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 5 08:33:14 PST 2021
Author: Kazu Hirata
Date: 2021-12-05T08:33:02-08:00
New Revision: 1457e7835202bece055210ccf3e21727d8c94753
URL: https://github.com/llvm/llvm-project/commit/1457e7835202bece055210ccf3e21727d8c94753
DIFF: https://github.com/llvm/llvm-project/commit/1457e7835202bece055210ccf3e21727d8c94753.diff
LOG: [llvm] Use range-based for loops (NFC)
Added:
Modified:
llvm/lib/Analysis/AliasAnalysis.cpp
llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
llvm/lib/CodeGen/EarlyIfConversion.cpp
llvm/lib/CodeGen/InlineSpiller.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp
index d030f74481cf0..af63692fb7b8d 100644
--- a/llvm/lib/Analysis/AliasAnalysis.cpp
+++ b/llvm/lib/Analysis/AliasAnalysis.cpp
@@ -249,11 +249,11 @@ ModRefInfo AAResults::getModRefInfo(const CallBase *Call,
bool IsMustAlias = true;
ModRefInfo AllArgsMask = ModRefInfo::NoModRef;
if (doesAccessArgPointees(MRB)) {
- for (auto AI = Call->arg_begin(), AE = Call->arg_end(); AI != AE; ++AI) {
- const Value *Arg = *AI;
+ for (const auto &I : llvm::enumerate(Call->args())) {
+ const Value *Arg = I.value();
if (!Arg->getType()->isPointerTy())
continue;
- unsigned ArgIdx = std::distance(Call->arg_begin(), AI);
+ unsigned ArgIdx = I.index();
MemoryLocation ArgLoc =
MemoryLocation::getForArgument(Call, ArgIdx, TLI);
AliasResult ArgAlias = alias(ArgLoc, Loc, AAQI);
diff --git a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
index d7bcb0d7f575e..d96541584274c 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
@@ -107,9 +107,9 @@ static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
// Check to see if we have a blockinfo record for this record, with a name.
if (const BitstreamBlockInfo::BlockInfo *Info =
BlockInfo.getBlockInfo(BlockID)) {
- for (unsigned i = 0, e = Info->RecordNames.size(); i != e; ++i)
- if (Info->RecordNames[i].first == CodeID)
- return Info->RecordNames[i].second.c_str();
+ for (const std::pair<unsigned, std::string> &RN : Info->RecordNames)
+ if (RN.first == CodeID)
+ return RN.second.c_str();
}
if (CurStreamType != LLVMIRBitstream)
@@ -646,16 +646,14 @@ void BitcodeAnalyzer::printStats(BCDumpOptions O,
// Emit per-block stats.
O.OS << "Per-block Summary:\n";
- for (std::map<unsigned, PerBlockIDStats>::iterator I = BlockIDStats.begin(),
- E = BlockIDStats.end();
- I != E; ++I) {
- O.OS << " Block ID #" << I->first;
+ for (const auto &Stat : BlockIDStats) {
+ O.OS << " Block ID #" << Stat.first;
if (Optional<const char *> BlockName =
- GetBlockName(I->first, BlockInfo, CurStreamType))
+ GetBlockName(Stat.first, BlockInfo, CurStreamType))
O.OS << " (" << *BlockName << ")";
O.OS << ":\n";
- const PerBlockIDStats &Stats = I->second;
+ const PerBlockIDStats &Stats = Stat.second;
O.OS << " Num Instances: " << Stats.NumInstances << "\n";
O.OS << " Total Size: ";
printSize(O.OS, Stats.NumBits);
@@ -694,8 +692,8 @@ void BitcodeAnalyzer::printStats(BCDumpOptions O,
O.OS << "\tRecord Histogram:\n";
O.OS << "\t\t Count # Bits b/Rec % Abv Record Kind\n";
- for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) {
- const PerRecordStats &RecStats = Stats.CodeFreq[FreqPairs[i].second];
+ for (const auto &FreqPair : FreqPairs) {
+ const PerRecordStats &RecStats = Stats.CodeFreq[FreqPair.second];
O.OS << format("\t\t%7d %9lu", RecStats.NumInstances,
(unsigned long)RecStats.TotalBits);
@@ -714,10 +712,10 @@ void BitcodeAnalyzer::printStats(BCDumpOptions O,
O.OS << " ";
if (Optional<const char *> CodeName = GetCodeName(
- FreqPairs[i].second, I->first, BlockInfo, CurStreamType))
+ FreqPair.second, Stat.first, BlockInfo, CurStreamType))
O.OS << *CodeName << "\n";
else
- O.OS << "UnknownCode" << FreqPairs[i].second << "\n";
+ O.OS << "UnknownCode" << FreqPair.second << "\n";
}
O.OS << "\n";
}
diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
index 07e0708e68c36..711d32c88f583 100644
--- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -541,9 +541,8 @@ void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
const char *Name) const {
OS << "Map Name: " << Name << "\n";
OS << "Size: " << Map.size() << "\n";
- for (ValueMapType::const_iterator I = Map.begin(),
- E = Map.end(); I != E; ++I) {
- const Value *V = I->first;
+ for (const auto &I : Map) {
+ const Value *V = I.first;
if (V->hasName())
OS << "Value: " << V->getName();
else
@@ -569,10 +568,10 @@ void ValueEnumerator::print(raw_ostream &OS, const MetadataMapType &Map,
const char *Name) const {
OS << "Map Name: " << Name << "\n";
OS << "Size: " << Map.size() << "\n";
- for (auto I = Map.begin(), E = Map.end(); I != E; ++I) {
- const Metadata *MD = I->first;
- OS << "Metadata: slot = " << I->second.ID << "\n";
- OS << "Metadata: function = " << I->second.F << "\n";
+ for (const auto &I : Map) {
+ const Metadata *MD = I.first;
+ OS << "Metadata: slot = " << I.second.ID << "\n";
+ OS << "Metadata: function = " << I.second.F << "\n";
MD->print(OS);
OS << "\n";
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
index a9fb31d42679d..3ade262d9af23 100644
--- a/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
@@ -112,16 +112,12 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
EmitCamlGlobal(M, AP, "frametable");
int NumDescriptors = 0;
- for (GCModuleInfo::FuncInfoVec::iterator I = Info.funcinfo_begin(),
- IE = Info.funcinfo_end();
- I != IE; ++I) {
- GCFunctionInfo &FI = **I;
- if (FI.getStrategy().getName() != getStrategy().getName())
+ for (std::unique_ptr<GCFunctionInfo> &FI :
+ llvm::make_range(Info.funcinfo_begin(), Info.funcinfo_end())) {
+ if (FI->getStrategy().getName() != getStrategy().getName())
// this function is managed by some other GC
continue;
- for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) {
- NumDescriptors++;
- }
+ NumDescriptors += FI->size();
}
if (NumDescriptors >= 1 << 16) {
@@ -131,35 +127,34 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
AP.emitInt16(NumDescriptors);
AP.emitAlignment(IntPtrSize == 4 ? Align(4) : Align(8));
- for (GCModuleInfo::FuncInfoVec::iterator I = Info.funcinfo_begin(),
- IE = Info.funcinfo_end();
- I != IE; ++I) {
- GCFunctionInfo &FI = **I;
- if (FI.getStrategy().getName() != getStrategy().getName())
+ for (std::unique_ptr<GCFunctionInfo> &FI :
+ llvm::make_range(Info.funcinfo_begin(), Info.funcinfo_end())) {
+ if (FI->getStrategy().getName() != getStrategy().getName())
// this function is managed by some other GC
continue;
- uint64_t FrameSize = FI.getFrameSize();
+ uint64_t FrameSize = FI->getFrameSize();
if (FrameSize >= 1 << 16) {
// Very rude!
- report_fatal_error("Function '" + FI.getFunction().getName() +
+ report_fatal_error("Function '" + FI->getFunction().getName() +
"' is too large for the ocaml GC! "
"Frame size " +
Twine(FrameSize) +
">= 65536.\n"
"(" +
- Twine(reinterpret_cast<uintptr_t>(&FI)) + ")");
+ Twine(reinterpret_cast<uintptr_t>(FI.get())) + ")");
}
AP.OutStreamer->AddComment("live roots for " +
- Twine(FI.getFunction().getName()));
+ Twine(FI->getFunction().getName()));
AP.OutStreamer->AddBlankLine();
- for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) {
- size_t LiveCount = FI.live_size(J);
+ for (GCFunctionInfo::iterator J = FI->begin(), JE = FI->end(); J != JE;
+ ++J) {
+ size_t LiveCount = FI->live_size(J);
if (LiveCount >= 1 << 16) {
// Very rude!
- report_fatal_error("Function '" + FI.getFunction().getName() +
+ report_fatal_error("Function '" + FI->getFunction().getName() +
"' is too large for the ocaml GC! "
"Live root count " +
Twine(LiveCount) + " >= 65536.");
@@ -169,8 +164,8 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
AP.emitInt16(FrameSize);
AP.emitInt16(LiveCount);
- for (GCFunctionInfo::live_iterator K = FI.live_begin(J),
- KE = FI.live_end(J);
+ for (GCFunctionInfo::live_iterator K = FI->live_begin(J),
+ KE = FI->live_end(J);
K != KE; ++K) {
if (K->StackOffset >= 1 << 16) {
// Very rude!
diff --git a/llvm/lib/CodeGen/EarlyIfConversion.cpp b/llvm/lib/CodeGen/EarlyIfConversion.cpp
index 90883212a2750..0b5469b02637c 100644
--- a/llvm/lib/CodeGen/EarlyIfConversion.cpp
+++ b/llvm/lib/CodeGen/EarlyIfConversion.cpp
@@ -210,9 +210,9 @@ bool SSAIfConv::canSpeculateInstrs(MachineBasicBlock *MBB) {
// Check all instructions, except the terminators. It is assumed that
// terminators never have side effects or define any used register values.
- for (MachineBasicBlock::iterator I = MBB->begin(),
- E = MBB->getFirstTerminator(); I != E; ++I) {
- if (I->isDebugInstr())
+ for (MachineInstr &MI :
+ llvm::make_range(MBB->begin(), MBB->getFirstTerminator())) {
+ if (MI.isDebugInstr())
continue;
if (++InstrCount > BlockInstrLimit && !Stress) {
@@ -222,28 +222,28 @@ bool SSAIfConv::canSpeculateInstrs(MachineBasicBlock *MBB) {
}
// There shouldn't normally be any phis in a single-predecessor block.
- if (I->isPHI()) {
- LLVM_DEBUG(dbgs() << "Can't hoist: " << *I);
+ if (MI.isPHI()) {
+ LLVM_DEBUG(dbgs() << "Can't hoist: " << MI);
return false;
}
// Don't speculate loads. Note that it may be possible and desirable to
// speculate GOT or constant pool loads that are guaranteed not to trap,
// but we don't support that for now.
- if (I->mayLoad()) {
- LLVM_DEBUG(dbgs() << "Won't speculate load: " << *I);
+ if (MI.mayLoad()) {
+ LLVM_DEBUG(dbgs() << "Won't speculate load: " << MI);
return false;
}
// We never speculate stores, so an AA pointer isn't necessary.
bool DontMoveAcrossStore = true;
- if (!I->isSafeToMove(nullptr, DontMoveAcrossStore)) {
- LLVM_DEBUG(dbgs() << "Can't speculate: " << *I);
+ if (!MI.isSafeToMove(nullptr, DontMoveAcrossStore)) {
+ LLVM_DEBUG(dbgs() << "Can't speculate: " << MI);
return false;
}
// Check for any dependencies on Head instructions.
- if (!InstrDependenciesAllowIfConv(&(*I)))
+ if (!InstrDependenciesAllowIfConv(&MI))
return false;
}
return true;
diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp
index fc5ac45752ca5..c975013db8c8d 100644
--- a/llvm/lib/CodeGen/InlineSpiller.cpp
+++ b/llvm/lib/CodeGen/InlineSpiller.cpp
@@ -686,9 +686,7 @@ void InlineSpiller::reMaterializeAll() {
// Remove any values that were completely rematted.
for (Register Reg : RegsToSpill) {
LiveInterval &LI = LIS.getInterval(Reg);
- for (LiveInterval::vni_iterator I = LI.vni_begin(), E = LI.vni_end();
- I != E; ++I) {
- VNInfo *VNI = *I;
+ for (VNInfo *VNI : llvm::make_range(LI.vni_begin(), LI.vni_end())) {
if (VNI->isUnused() || VNI->isPHIDef() || UsedValues.count(VNI))
continue;
MachineInstr *MI = LIS.getInstructionFromIndex(VNI->def);
More information about the llvm-commits
mailing list