From 5605a1eeddeb87abdf39a60bc59303c5dc978154 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 15 Jul 2022 23:58:11 -0700 Subject: [PATCH] Use drop_begin (NFC) --- llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp | 4 ++-- mlir/lib/Target/Cpp/TranslateToCpp.cpp | 3 +-- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 16 +++++++--------- mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp index 975eb88..05f3143 100644 --- a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp +++ b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp @@ -1213,8 +1213,8 @@ void SystemZXPLINKFrameLowering::emitPrologue(MachineFunction &MF, // Mark the FramePtr as live at the beginning of every block except // the entry block. (We'll have marked R8 as live on entry when // saving the GPRs.) - for (auto I = std::next(MF.begin()), E = MF.end(); I != E; ++I) - I->addLiveIn(Regs.getFramePointerRegister()); + for (MachineBasicBlock &B : llvm::drop_begin(MF)) + B.addLiveIn(Regs.getFramePointerRegister()); } } diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp index b3878eb..3b3fba1 100644 --- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp +++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp @@ -645,8 +645,7 @@ static LogicalResult printOperation(CppEmitter &emitter, } // Declare variables for basic block arguments. - for (auto it = std::next(blocks.begin()); it != blocks.end(); ++it) { - Block &block = *it; + for (Block &block : llvm::drop_begin(blocks)) { for (BlockArgument &arg : block.getArguments()) { if (emitter.hasValueInScope(arg)) return functionOp.emitOpError(" block argument #") diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 182274e..4855571 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -485,17 +485,15 @@ void mlir::LLVM::detail::connectPHINodes(Region ®ion, const ModuleTranslation &state) { // Skip the first block, it cannot be branched to and its arguments correspond // to the arguments of the LLVM function. - for (auto it = std::next(region.begin()), eit = region.end(); it != eit; - ++it) { - Block *bb = &*it; - llvm::BasicBlock *llvmBB = state.lookupBlock(bb); + for (Block &bb : llvm::drop_begin(region)) { + llvm::BasicBlock *llvmBB = state.lookupBlock(&bb); auto phis = llvmBB->phis(); - auto numArguments = bb->getNumArguments(); + auto numArguments = bb.getNumArguments(); assert(numArguments == std::distance(phis.begin(), phis.end())); for (auto &numberedPhiNode : llvm::enumerate(phis)) { auto &phiNode = numberedPhiNode.value(); unsigned index = numberedPhiNode.index(); - for (auto *pred : bb->getPredecessors()) { + for (auto *pred : bb.getPredecessors()) { // Find the LLVM IR block that contains the converted terminator // instruction and use it in the PHI node. Note that this block is not // necessarily the same as state.lookupBlock(pred), some operations @@ -504,9 +502,9 @@ void mlir::LLVM::detail::connectPHINodes(Region ®ion, llvm::Instruction *terminator = state.lookupBranch(pred->getTerminator()); assert(terminator && "missing the mapping for a terminator"); - phiNode.addIncoming( - state.lookupValue(getPHISourceValue(bb, pred, numArguments, index)), - terminator->getParent()); + phiNode.addIncoming(state.lookupValue(getPHISourceValue( + &bb, pred, numArguments, index)), + terminator->getParent()); } } } diff --git a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp index cdf7fc5..ad1724f 100644 --- a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp +++ b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp @@ -420,7 +420,7 @@ LogicalResult Serializer::processLoopOp(spirv::LoopOp loopOp) { // properly. We don't need to assign for the entry block, which is just for // satisfying MLIR region's structural requirement. auto &body = loopOp.body(); - for (Block &block : llvm::make_range(std::next(body.begin(), 1), body.end())) + for (Block &block : llvm::drop_begin(body)) getOrCreateBlockID(&block); auto *headerBlock = loopOp.getHeaderBlock(); -- 2.7.4