[llvm] 3b9707d - [llvm] Convert for_each to range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 5 12:07:20 PDT 2022
Author: Kazu Hirata
Date: 2022-06-05T12:07:14-07:00
New Revision: 3b9707dbc0e3b5c0441fbea4d1a05a249d5e1483
URL: https://github.com/llvm/llvm-project/commit/3b9707dbc0e3b5c0441fbea4d1a05a249d5e1483
DIFF: https://github.com/llvm/llvm-project/commit/3b9707dbc0e3b5c0441fbea4d1a05a249d5e1483.diff
LOG: [llvm] Convert for_each to range-based for loops (NFC)
Added:
Modified:
llvm/include/llvm/Analysis/LoopInfoImpl.h
llvm/lib/CodeGen/MachineOutliner.cpp
llvm/lib/ObjCopy/ELF/ELFObject.cpp
llvm/lib/TableGen/TGLexer.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/LoopInfoImpl.h b/llvm/include/llvm/Analysis/LoopInfoImpl.h
index 05ac3e51b41a..fdaa6df8832f 100644
--- a/llvm/include/llvm/Analysis/LoopInfoImpl.h
+++ b/llvm/include/llvm/Analysis/LoopInfoImpl.h
@@ -314,12 +314,11 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
"Loop block has no in-loop predecessors!");
SmallVector<BlockT *, 2> OutsideLoopPreds;
- std::for_each(GraphTraits<Inverse<BlockT *>>::child_begin(BB),
- GraphTraits<Inverse<BlockT *>>::child_end(BB),
- [&](BlockT *B) {
- if (!contains(B))
- OutsideLoopPreds.push_back(B);
- });
+ for (BlockT *B :
+ llvm::make_range(GraphTraits<Inverse<BlockT *>>::child_begin(BB),
+ GraphTraits<Inverse<BlockT *>>::child_end(BB)))
+ if (!contains(B))
+ OutsideLoopPreds.push_back(B);
if (BB == getHeader()) {
assert(!OutsideLoopPreds.empty() && "Loop is unreachable!");
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index 6e4c98ac5068..7ab69968b607 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -855,9 +855,10 @@ bool MachineOutliner::outline(Module &M,
MBB.erase(std::next(StartIt), std::next(EndIt));
// Keep track of what we removed by marking them all as -1.
- std::for_each(Mapper.UnsignedVec.begin() + C.getStartIdx(),
- Mapper.UnsignedVec.begin() + C.getEndIdx() + 1,
- [](unsigned &I) { I = static_cast<unsigned>(-1); });
+ for (unsigned &I :
+ llvm::make_range(Mapper.UnsignedVec.begin() + C.getStartIdx(),
+ Mapper.UnsignedVec.begin() + C.getEndIdx() + 1))
+ I = static_cast<unsigned>(-1);
OutlinedSomething = true;
// Statistics.
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index a5d7884985a4..d0e101e08ef3 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -750,8 +750,8 @@ Error SymbolTableSection::removeSectionReferences(
}
void SymbolTableSection::updateSymbols(function_ref<void(Symbol &)> Callable) {
- std::for_each(std::begin(Symbols) + 1, std::end(Symbols),
- [Callable](SymPtr &Sym) { Callable(*Sym); });
+ for (SymPtr &Sym : llvm::drop_begin(Symbols))
+ Callable(*Sym);
std::stable_partition(
std::begin(Symbols), std::end(Symbols),
[](const SymPtr &Sym) { return Sym->Binding == STB_LOCAL; });
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index 25079fe33edb..d3be6cae0ac8 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -55,10 +55,8 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef<std::string> Macros) : SrcMgr(SM) {
std::make_unique<std::vector<PreprocessorControlDesc>>());
// Put all macros defined in the command line into the DefinedMacros set.
- std::for_each(Macros.begin(), Macros.end(),
- [this](const std::string &MacroName) {
- DefinedMacros.insert(MacroName);
- });
+ for (const std::string &MacroName : Macros)
+ DefinedMacros.insert(MacroName);
}
SMLoc TGLexer::getLoc() const {
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 1c44976814de..9f647d66c5a7 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -6955,10 +6955,8 @@ outliner::OutlinedFunction AArch64InstrInfo::getOutliningCandidateInfo(
unsigned FlagsSetInAll = 0xF;
// Compute liveness information for each candidate, and set FlagsSetInAll.
- std::for_each(RepeatedSequenceLocs.begin(), RepeatedSequenceLocs.end(),
- [&FlagsSetInAll](outliner::Candidate &C) {
- FlagsSetInAll &= C.Flags;
- });
+ for (outliner::Candidate &C : RepeatedSequenceLocs)
+ FlagsSetInAll &= C.Flags;
// According to the AArch64 Procedure Call Standard, the following are
// undefined on entry/exit from a function call:
@@ -7314,8 +7312,8 @@ bool AArch64InstrInfo::isMBBSafeToOutlineFrom(MachineBasicBlock &MBB,
"Suitable Machine Function for outlining must track liveness");
LiveRegUnits LRU(getRegisterInfo());
- std::for_each(MBB.rbegin(), MBB.rend(),
- [&LRU](MachineInstr &MI) { LRU.accumulate(MI); });
+ for (MachineInstr &MI : llvm::reverse(MBB))
+ LRU.accumulate(MI);
// Check if each of the unsafe registers are available...
bool W16AvailableInBlock = LRU.available(AArch64::W16);
diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
index 44dfd00d4963..e73118aadfc8 100644
--- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
@@ -5861,9 +5861,8 @@ outliner::OutlinedFunction ARMBaseInstrInfo::getOutliningCandidateInfo(
// Compute liveness information for each candidate, and set FlagsSetInAll.
const TargetRegisterInfo &TRI = getRegisterInfo();
- std::for_each(
- RepeatedSequenceLocs.begin(), RepeatedSequenceLocs.end(),
- [&FlagsSetInAll](outliner::Candidate &C) { FlagsSetInAll &= C.Flags; });
+ for (outliner::Candidate &C : RepeatedSequenceLocs)
+ FlagsSetInAll &= C.Flags;
// According to the ARM Procedure Call Standard, the following are
// undefined on entry/exit from a function call:
@@ -6214,8 +6213,8 @@ bool ARMBaseInstrInfo::isMBBSafeToOutlineFrom(MachineBasicBlock &MBB,
LiveRegUnits LRU(getRegisterInfo());
- std::for_each(MBB.rbegin(), MBB.rend(),
- [&LRU](MachineInstr &MI) { LRU.accumulate(MI); });
+ for (MachineInstr &MI : llvm::reverse(MBB))
+ LRU.accumulate(MI);
// Check if each of the unsafe registers are available...
bool R12AvailableInBlock = LRU.available(ARM::R12);
diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
index 19b04f49d76c..0a19455e0c1d 100644
--- a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
@@ -207,10 +207,8 @@ static void convertToParamAS(Value *OldUser, Value *Param) {
// We've created a new instruction. Queue users of the old instruction to
// be converted and the instruction itself to be deleted. We can't delete
// the old instruction yet, because it's still in use by a load somewhere.
- llvm::for_each(
- I.OldInstruction->users(), [NewInst, &ItemsToConvert](Value *V) {
- ItemsToConvert.push_back({cast<Instruction>(V), NewInst});
- });
+ for (Value *V : I.OldInstruction->users())
+ ItemsToConvert.push_back({cast<Instruction>(V), NewInst});
InstructionsToDelete.push_back(I.OldInstruction);
}
@@ -223,8 +221,8 @@ static void convertToParamAS(Value *OldUser, Value *Param) {
// E.g if we have Value = Load(BitCast(GEP(arg))), InstructionsToDelete will
// have {GEP,BitCast}. GEP can't be deleted first, because it's still used by
// the BitCast.
- llvm::for_each(reverse(InstructionsToDelete),
- [](Instruction *I) { I->eraseFromParent(); });
+ for (Instruction *I : llvm::reverse(InstructionsToDelete))
+ I->eraseFromParent();
}
// Adjust alignment of arguments passed byval in .param address space. We can
@@ -351,9 +349,8 @@ void NVPTXLowerArgs::handleByValParam(Argument *Arg) {
Value *ArgInParamAS = new AddrSpaceCastInst(
Arg, PointerType::get(StructType, ADDRESS_SPACE_PARAM), Arg->getName(),
FirstInst);
- llvm::for_each(UsersToUpdate, [ArgInParamAS](Value *V) {
+ for (Value *V : UsersToUpdate)
convertToParamAS(V, ArgInParamAS);
- });
LLVM_DEBUG(dbgs() << "No need to copy " << *Arg << "\n");
// Further optimizations require target lowering info.
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index eb8ec6257615..ff313a125bc4 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2432,9 +2432,8 @@ void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) {
}
// Emit aliasing label for global variable.
- llvm::for_each(GOAliasMap[GV], [this](const GlobalAlias *Alias) {
+ for (const GlobalAlias *Alias : GOAliasMap[GV])
OutStreamer->emitLabel(getSymbol(Alias));
- });
emitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer());
}
@@ -2449,10 +2448,8 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() {
cast<MCSymbolXCOFF>(CurrentFnDescSym)->getRepresentedCsect());
// Emit aliasing label for function descriptor csect.
- llvm::for_each(GOAliasMap[&MF->getFunction()],
- [this](const GlobalAlias *Alias) {
- OutStreamer->emitLabel(getSymbol(Alias));
- });
+ for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()])
+ OutStreamer->emitLabel(getSymbol(Alias));
// Emit function entry point address.
OutStreamer->emitValue(MCSymbolRefExpr::create(CurrentFnSym, OutContext),
@@ -2476,11 +2473,9 @@ void PPCAIXAsmPrinter::emitFunctionEntryLabel() {
PPCAsmPrinter::emitFunctionEntryLabel();
// Emit aliasing label for function entry point label.
- llvm::for_each(
- GOAliasMap[&MF->getFunction()], [this](const GlobalAlias *Alias) {
- OutStreamer->emitLabel(
- getObjFileLowering().getFunctionEntryPointSymbol(Alias, TM));
- });
+ for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()])
+ OutStreamer->emitLabel(
+ getObjFileLowering().getFunctionEntryPointSymbol(Alias, TM));
}
void PPCAIXAsmPrinter::emitPGORefs() {
diff --git a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
index 577bb1a4ad4b..a4561bf1589e 100644
--- a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
@@ -2393,7 +2393,7 @@ bool PPCFrameLowering::spillCalleeSavedRegisters(
// Map each VSR to GPRs to be spilled with into it. Single VSR can contain one
// or two GPRs, so we need table to record information for later save/restore.
- llvm::for_each(CSI, [&](const CalleeSavedInfo &Info) {
+ for (const CalleeSavedInfo &Info : CSI) {
if (Info.isSpilledToReg()) {
auto &SpilledVSR =
VSRContainingGPRs.FindAndConstruct(Info.getDstReg()).second;
@@ -2404,7 +2404,7 @@ bool PPCFrameLowering::spillCalleeSavedRegisters(
else
SpilledVSR.second = Info.getReg();
}
- });
+ }
for (const CalleeSavedInfo &I : CSI) {
Register Reg = I.getReg();
diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index 32241f318be8..f1caa5e98a3d 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -855,10 +855,9 @@ static StringRef solveTypeName(Type *Ty) {
auto Name = Ty->getStructName();
SmallString<16> Buffer(Name);
- for_each(Buffer, [](auto &Iter) {
+ for (auto &Iter : Buffer)
if (Iter == '.' || Iter == ':')
Iter = '_';
- });
auto *MDName = MDString::get(Ty->getContext(), Buffer.str());
return MDName->getString();
}
@@ -2794,10 +2793,9 @@ void coro::buildCoroutineFrame(Function &F, Shape &Shape) {
auto *V = Iter.first;
SmallVector<DbgValueInst *, 16> DVIs;
findDbgValues(DVIs, V);
- llvm::for_each(DVIs, [&](DbgValueInst *DVI) {
+ for (DbgValueInst *DVI : DVIs)
if (Checker.isDefinitionAcrossSuspend(*V, DVI))
FrameData.Spills[V].push_back(DVI);
- });
}
LLVM_DEBUG(dumpSpills("Spills", FrameData.Spills));
More information about the llvm-commits
mailing list