Skip to content

Commit 3b9707d

Browse files
[llvm] Convert for_each to range-based for loops (NFC)
1 parent 4c78386 commit 3b9707d

File tree

10 files changed

+36
-51
lines changed

10 files changed

+36
-51
lines changed

llvm/include/llvm/Analysis/LoopInfoImpl.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,11 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
314314
"Loop block has no in-loop predecessors!");
315315

316316
SmallVector<BlockT *, 2> OutsideLoopPreds;
317-
std::for_each(GraphTraits<Inverse<BlockT *>>::child_begin(BB),
318-
GraphTraits<Inverse<BlockT *>>::child_end(BB),
319-
[&](BlockT *B) {
320-
if (!contains(B))
321-
OutsideLoopPreds.push_back(B);
322-
});
317+
for (BlockT *B :
318+
llvm::make_range(GraphTraits<Inverse<BlockT *>>::child_begin(BB),
319+
GraphTraits<Inverse<BlockT *>>::child_end(BB)))
320+
if (!contains(B))
321+
OutsideLoopPreds.push_back(B);
323322

324323
if (BB == getHeader()) {
325324
assert(!OutsideLoopPreds.empty() && "Loop is unreachable!");

llvm/lib/CodeGen/MachineOutliner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,10 @@ bool MachineOutliner::outline(Module &M,
855855
MBB.erase(std::next(StartIt), std::next(EndIt));
856856

857857
// Keep track of what we removed by marking them all as -1.
858-
std::for_each(Mapper.UnsignedVec.begin() + C.getStartIdx(),
859-
Mapper.UnsignedVec.begin() + C.getEndIdx() + 1,
860-
[](unsigned &I) { I = static_cast<unsigned>(-1); });
858+
for (unsigned &I :
859+
llvm::make_range(Mapper.UnsignedVec.begin() + C.getStartIdx(),
860+
Mapper.UnsignedVec.begin() + C.getEndIdx() + 1))
861+
I = static_cast<unsigned>(-1);
861862
OutlinedSomething = true;
862863

863864
// Statistics.

llvm/lib/ObjCopy/ELF/ELFObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,8 @@ Error SymbolTableSection::removeSectionReferences(
750750
}
751751

752752
void SymbolTableSection::updateSymbols(function_ref<void(Symbol &)> Callable) {
753-
std::for_each(std::begin(Symbols) + 1, std::end(Symbols),
754-
[Callable](SymPtr &Sym) { Callable(*Sym); });
753+
for (SymPtr &Sym : llvm::drop_begin(Symbols))
754+
Callable(*Sym);
755755
std::stable_partition(
756756
std::begin(Symbols), std::end(Symbols),
757757
[](const SymPtr &Sym) { return Sym->Binding == STB_LOCAL; });

llvm/lib/TableGen/TGLexer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef<std::string> Macros) : SrcMgr(SM) {
5555
std::make_unique<std::vector<PreprocessorControlDesc>>());
5656

5757
// Put all macros defined in the command line into the DefinedMacros set.
58-
std::for_each(Macros.begin(), Macros.end(),
59-
[this](const std::string &MacroName) {
60-
DefinedMacros.insert(MacroName);
61-
});
58+
for (const std::string &MacroName : Macros)
59+
DefinedMacros.insert(MacroName);
6260
}
6361

6462
SMLoc TGLexer::getLoc() const {

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6955,10 +6955,8 @@ outliner::OutlinedFunction AArch64InstrInfo::getOutliningCandidateInfo(
69556955
unsigned FlagsSetInAll = 0xF;
69566956

69576957
// Compute liveness information for each candidate, and set FlagsSetInAll.
6958-
std::for_each(RepeatedSequenceLocs.begin(), RepeatedSequenceLocs.end(),
6959-
[&FlagsSetInAll](outliner::Candidate &C) {
6960-
FlagsSetInAll &= C.Flags;
6961-
});
6958+
for (outliner::Candidate &C : RepeatedSequenceLocs)
6959+
FlagsSetInAll &= C.Flags;
69626960

69636961
// According to the AArch64 Procedure Call Standard, the following are
69646962
// undefined on entry/exit from a function call:
@@ -7314,8 +7312,8 @@ bool AArch64InstrInfo::isMBBSafeToOutlineFrom(MachineBasicBlock &MBB,
73147312
"Suitable Machine Function for outlining must track liveness");
73157313
LiveRegUnits LRU(getRegisterInfo());
73167314

7317-
std::for_each(MBB.rbegin(), MBB.rend(),
7318-
[&LRU](MachineInstr &MI) { LRU.accumulate(MI); });
7315+
for (MachineInstr &MI : llvm::reverse(MBB))
7316+
LRU.accumulate(MI);
73197317

73207318
// Check if each of the unsafe registers are available...
73217319
bool W16AvailableInBlock = LRU.available(AArch64::W16);

llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5861,9 +5861,8 @@ outliner::OutlinedFunction ARMBaseInstrInfo::getOutliningCandidateInfo(
58615861

58625862
// Compute liveness information for each candidate, and set FlagsSetInAll.
58635863
const TargetRegisterInfo &TRI = getRegisterInfo();
5864-
std::for_each(
5865-
RepeatedSequenceLocs.begin(), RepeatedSequenceLocs.end(),
5866-
[&FlagsSetInAll](outliner::Candidate &C) { FlagsSetInAll &= C.Flags; });
5864+
for (outliner::Candidate &C : RepeatedSequenceLocs)
5865+
FlagsSetInAll &= C.Flags;
58675866

58685867
// According to the ARM Procedure Call Standard, the following are
58695868
// undefined on entry/exit from a function call:
@@ -6214,8 +6213,8 @@ bool ARMBaseInstrInfo::isMBBSafeToOutlineFrom(MachineBasicBlock &MBB,
62146213

62156214
LiveRegUnits LRU(getRegisterInfo());
62166215

6217-
std::for_each(MBB.rbegin(), MBB.rend(),
6218-
[&LRU](MachineInstr &MI) { LRU.accumulate(MI); });
6216+
for (MachineInstr &MI : llvm::reverse(MBB))
6217+
LRU.accumulate(MI);
62196218

62206219
// Check if each of the unsafe registers are available...
62216220
bool R12AvailableInBlock = LRU.available(ARM::R12);

llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,8 @@ static void convertToParamAS(Value *OldUser, Value *Param) {
207207
// We've created a new instruction. Queue users of the old instruction to
208208
// be converted and the instruction itself to be deleted. We can't delete
209209
// the old instruction yet, because it's still in use by a load somewhere.
210-
llvm::for_each(
211-
I.OldInstruction->users(), [NewInst, &ItemsToConvert](Value *V) {
212-
ItemsToConvert.push_back({cast<Instruction>(V), NewInst});
213-
});
210+
for (Value *V : I.OldInstruction->users())
211+
ItemsToConvert.push_back({cast<Instruction>(V), NewInst});
214212

215213
InstructionsToDelete.push_back(I.OldInstruction);
216214
}
@@ -223,8 +221,8 @@ static void convertToParamAS(Value *OldUser, Value *Param) {
223221
// E.g if we have Value = Load(BitCast(GEP(arg))), InstructionsToDelete will
224222
// have {GEP,BitCast}. GEP can't be deleted first, because it's still used by
225223
// the BitCast.
226-
llvm::for_each(reverse(InstructionsToDelete),
227-
[](Instruction *I) { I->eraseFromParent(); });
224+
for (Instruction *I : llvm::reverse(InstructionsToDelete))
225+
I->eraseFromParent();
228226
}
229227

230228
// Adjust alignment of arguments passed byval in .param address space. We can
@@ -351,9 +349,8 @@ void NVPTXLowerArgs::handleByValParam(Argument *Arg) {
351349
Value *ArgInParamAS = new AddrSpaceCastInst(
352350
Arg, PointerType::get(StructType, ADDRESS_SPACE_PARAM), Arg->getName(),
353351
FirstInst);
354-
llvm::for_each(UsersToUpdate, [ArgInParamAS](Value *V) {
352+
for (Value *V : UsersToUpdate)
355353
convertToParamAS(V, ArgInParamAS);
356-
});
357354
LLVM_DEBUG(dbgs() << "No need to copy " << *Arg << "\n");
358355

359356
// Further optimizations require target lowering info.

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,9 +2432,8 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) {
24322432
}
24332433

24342434
// Emit aliasing label for global variable.
2435-
llvm::for_each(GOAliasMap[GV], [this](const GlobalAlias *Alias) {
2435+
for (const GlobalAlias *Alias : GOAliasMap[GV])
24362436
OutStreamer->emitLabel(getSymbol(Alias));
2437-
});
24382437

24392438
emitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer());
24402439
}
@@ -2449,10 +2448,8 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() {
24492448
cast<MCSymbolXCOFF>(CurrentFnDescSym)->getRepresentedCsect());
24502449

24512450
// Emit aliasing label for function descriptor csect.
2452-
llvm::for_each(GOAliasMap[&MF->getFunction()],
2453-
[this](const GlobalAlias *Alias) {
2454-
OutStreamer->emitLabel(getSymbol(Alias));
2455-
});
2451+
for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()])
2452+
OutStreamer->emitLabel(getSymbol(Alias));
24562453

24572454
// Emit function entry point address.
24582455
OutStreamer->emitValue(MCSymbolRefExpr::create(CurrentFnSym, OutContext),
@@ -2476,11 +2473,9 @@ void PPCAIXAsmPrinter::emitFunctionEntryLabel() {
24762473
PPCAsmPrinter::emitFunctionEntryLabel();
24772474

24782475
// Emit aliasing label for function entry point label.
2479-
llvm::for_each(
2480-
GOAliasMap[&MF->getFunction()], [this](const GlobalAlias *Alias) {
2481-
OutStreamer->emitLabel(
2482-
getObjFileLowering().getFunctionEntryPointSymbol(Alias, TM));
2483-
});
2476+
for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()])
2477+
OutStreamer->emitLabel(
2478+
getObjFileLowering().getFunctionEntryPointSymbol(Alias, TM));
24842479
}
24852480

24862481
void PPCAIXAsmPrinter::emitPGORefs() {

llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ bool PPCFrameLowering::spillCalleeSavedRegisters(
23932393

23942394
// Map each VSR to GPRs to be spilled with into it. Single VSR can contain one
23952395
// or two GPRs, so we need table to record information for later save/restore.
2396-
llvm::for_each(CSI, [&](const CalleeSavedInfo &Info) {
2396+
for (const CalleeSavedInfo &Info : CSI) {
23972397
if (Info.isSpilledToReg()) {
23982398
auto &SpilledVSR =
23992399
VSRContainingGPRs.FindAndConstruct(Info.getDstReg()).second;
@@ -2404,7 +2404,7 @@ bool PPCFrameLowering::spillCalleeSavedRegisters(
24042404
else
24052405
SpilledVSR.second = Info.getReg();
24062406
}
2407-
});
2407+
}
24082408

24092409
for (const CalleeSavedInfo &I : CSI) {
24102410
Register Reg = I.getReg();

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,9 @@ static StringRef solveTypeName(Type *Ty) {
855855
auto Name = Ty->getStructName();
856856

857857
SmallString<16> Buffer(Name);
858-
for_each(Buffer, [](auto &Iter) {
858+
for (auto &Iter : Buffer)
859859
if (Iter == '.' || Iter == ':')
860860
Iter = '_';
861-
});
862861
auto *MDName = MDString::get(Ty->getContext(), Buffer.str());
863862
return MDName->getString();
864863
}
@@ -2794,10 +2793,9 @@ void coro::buildCoroutineFrame(Function &F, Shape &Shape) {
27942793
auto *V = Iter.first;
27952794
SmallVector<DbgValueInst *, 16> DVIs;
27962795
findDbgValues(DVIs, V);
2797-
llvm::for_each(DVIs, [&](DbgValueInst *DVI) {
2796+
for (DbgValueInst *DVI : DVIs)
27982797
if (Checker.isDefinitionAcrossSuspend(*V, DVI))
27992798
FrameData.Spills[V].push_back(DVI);
2800-
});
28012799
}
28022800

28032801
LLVM_DEBUG(dumpSpills("Spills", FrameData.Spills));

0 commit comments

Comments
 (0)