Use make_range(rbegin(), rend()) to allow foreach loops. NFC.

Instead of the pattern

for (auto I = x.rbegin(), E = x.end(); I != E; ++I)

we can use make_range to construct the reverse range and iterate using
that instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243163 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pete Cooper
2015-07-24 21:13:43 +00:00
parent d232d63fa2
commit 9f2f1650c4
10 changed files with 26 additions and 39 deletions

View File

@@ -115,9 +115,8 @@ void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
Entry = TypeInfos.size(); Entry = TypeInfos.size();
} }
for (std::vector<const GlobalValue *>::const_reverse_iterator for (const GlobalValue *GV : make_range(TypeInfos.rbegin(),
I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) { TypeInfos.rend())) {
const GlobalValue *GV = *I;
if (VerboseAsm) if (VerboseAsm)
Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--)); Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
Asm->EmitTTypeReference(GV, TTypeEncoding); Asm->EmitTTypeReference(GV, TTypeEncoding);

View File

@@ -804,8 +804,7 @@ std::string DwarfUnit::getParentContextString(const DIScope *Context) const {
// Reverse iterate over our list to go from the outermost construct to the // Reverse iterate over our list to go from the outermost construct to the
// innermost. // innermost.
for (auto I = Parents.rbegin(), E = Parents.rend(); I != E; ++I) { for (const DIScope *Ctx : make_range(Parents.rbegin(), Parents.rend())) {
const DIScope *Ctx = *I;
StringRef Name = Ctx->getName(); StringRef Name = Ctx->getName();
if (Name.empty() && isa<DINamespace>(Ctx)) if (Name.empty() && isa<DINamespace>(Ctx))
Name = "(anonymous namespace)"; Name = "(anonymous namespace)";

View File

@@ -662,9 +662,8 @@ void EHStreamer::emitTypeInfos(unsigned TTypeEncoding) {
Entry = TypeInfos.size(); Entry = TypeInfos.size();
} }
for (std::vector<const GlobalValue *>::const_reverse_iterator for (const GlobalValue *GV : make_range(TypeInfos.rbegin(),
I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) { TypeInfos.rend())) {
const GlobalValue *GV = *I;
if (VerboseAsm) if (VerboseAsm)
Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--)); Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
Asm->EmitTTypeReference(GV, TTypeEncoding); Asm->EmitTTypeReference(GV, TTypeEncoding);

View File

@@ -101,26 +101,23 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) {
// Loop over all instructions in all blocks, from bottom to top, so that it's // Loop over all instructions in all blocks, from bottom to top, so that it's
// more likely that chains of dependent but ultimately dead instructions will // more likely that chains of dependent but ultimately dead instructions will
// be cleaned up. // be cleaned up.
for (MachineFunction::reverse_iterator I = MF.rbegin(), E = MF.rend(); for (MachineBasicBlock &MBB : make_range(MF.rbegin(), MF.rend())) {
I != E; ++I) {
MachineBasicBlock *MBB = &*I;
// Start out assuming that reserved registers are live out of this block. // Start out assuming that reserved registers are live out of this block.
LivePhysRegs = MRI->getReservedRegs(); LivePhysRegs = MRI->getReservedRegs();
// Add live-ins from sucessors to LivePhysRegs. Normally, physregs are not // Add live-ins from sucessors to LivePhysRegs. Normally, physregs are not
// live across blocks, but some targets (x86) can have flags live out of a // live across blocks, but some targets (x86) can have flags live out of a
// block. // block.
for (MachineBasicBlock::succ_iterator S = MBB->succ_begin(), for (MachineBasicBlock::succ_iterator S = MBB.succ_begin(),
E = MBB->succ_end(); S != E; S++) E = MBB.succ_end(); S != E; S++)
for (MachineBasicBlock::livein_iterator LI = (*S)->livein_begin(); for (MachineBasicBlock::livein_iterator LI = (*S)->livein_begin();
LI != (*S)->livein_end(); LI++) LI != (*S)->livein_end(); LI++)
LivePhysRegs.set(*LI); LivePhysRegs.set(*LI);
// Now scan the instructions and delete dead ones, tracking physreg // Now scan the instructions and delete dead ones, tracking physreg
// liveness as we go. // liveness as we go.
for (MachineBasicBlock::reverse_iterator MII = MBB->rbegin(), for (MachineBasicBlock::reverse_iterator MII = MBB.rbegin(),
MIE = MBB->rend(); MII != MIE; ) { MIE = MBB.rend(); MII != MIE; ) {
MachineInstr *MI = &*MII; MachineInstr *MI = &*MII;
// If the instruction is dead, delete it! // If the instruction is dead, delete it!
@@ -132,7 +129,7 @@ bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) {
MI->eraseFromParentAndMarkDBGValuesForRemoval(); MI->eraseFromParentAndMarkDBGValuesForRemoval();
AnyChanges = true; AnyChanges = true;
++NumDeletes; ++NumDeletes;
MIE = MBB->rend(); MIE = MBB.rend();
// MII is now pointing to the next instruction to process, // MII is now pointing to the next instruction to process,
// so don't increment it. // so don't increment it.
continue; continue;

View File

@@ -559,12 +559,11 @@ void ExeDepsFix::processUndefReads(MachineBasicBlock *MBB) {
MachineInstr *UndefMI = UndefReads.back().first; MachineInstr *UndefMI = UndefReads.back().first;
unsigned OpIdx = UndefReads.back().second; unsigned OpIdx = UndefReads.back().second;
for (MachineBasicBlock::reverse_iterator I = MBB->rbegin(), E = MBB->rend(); for (MachineInstr &I : make_range(MBB->rbegin(), MBB->rend())) {
I != E; ++I) {
// Update liveness, including the current instruction's defs. // Update liveness, including the current instruction's defs.
LiveRegSet.stepBackward(*I); LiveRegSet.stepBackward(I);
if (UndefMI == &*I) { if (UndefMI == &I) {
if (!LiveRegSet.contains(UndefMI->getOperand(OpIdx).getReg())) if (!LiveRegSet.contains(UndefMI->getOperand(OpIdx).getReg()))
TII->breakPartialRegDependency(UndefMI, OpIdx, TRI); TII->breakPartialRegDependency(UndefMI, OpIdx, TRI);

View File

@@ -232,8 +232,7 @@ static UseListOrderStack predictUseListOrder(const Module *M) {
// We want to visit the functions backward now so we can list function-local // We want to visit the functions backward now so we can list function-local
// constants in the last Function they're used in. Module-level constants // constants in the last Function they're used in. Module-level constants
// have already been visited above. // have already been visited above.
for (auto I = M->rbegin(), E = M->rend(); I != E; ++I) { for (const Function &F : make_range(M->rbegin(), M->rend())) {
const Function &F = *I;
if (F.isDeclaration()) if (F.isDeclaration())
continue; continue;
for (const BasicBlock &BB : F) for (const BasicBlock &BB : F)

View File

@@ -151,10 +151,9 @@ static MachineInstr *getLastNonPseudo(MachineBasicBlock &MBB,
// If there is no non-pseudo in the current block, loop back around and try // If there is no non-pseudo in the current block, loop back around and try
// the previous block (if there is one). // the previous block (if there is one).
while ((FMBB = getBBFallenThrough(FMBB, TII))) { while ((FMBB = getBBFallenThrough(FMBB, TII))) {
for (auto I = FMBB->rbegin(), E = FMBB->rend(); I != E; ++I) { for (MachineInstr &I : make_range(FMBB->rbegin(), FMBB->rend()))
if (!I->isPseudo()) if (!I.isPseudo())
return &*I; return &I;
}
} }
// There was no previous non-pseudo in the fallen through blocks // There was no previous non-pseudo in the fallen through blocks

View File

@@ -242,11 +242,11 @@ void Float2Int::walkBackwards(const SmallPtrSetImpl<Instruction*> &Roots) {
// Walk forwards down the list of seen instructions, so we visit defs before // Walk forwards down the list of seen instructions, so we visit defs before
// uses. // uses.
void Float2Int::walkForwards() { void Float2Int::walkForwards() {
for (auto It = SeenInsts.rbegin(), E = SeenInsts.rend(); It != E; ++It) { for (auto &It : make_range(SeenInsts.rbegin(), SeenInsts.rend())) {
if (It->second != unknownRange()) if (It.second != unknownRange())
continue; continue;
Instruction *I = It->first; Instruction *I = It.first;
std::function<ConstantRange(ArrayRef<ConstantRange>)> Op; std::function<ConstantRange(ArrayRef<ConstantRange>)> Op;
switch (I->getOpcode()) { switch (I->getOpcode()) {
// FIXME: Handle select and phi nodes. // FIXME: Handle select and phi nodes.
@@ -507,9 +507,8 @@ Value *Float2Int::convert(Instruction *I, Type *ToTy) {
// Perform dead code elimination on the instructions we just modified. // Perform dead code elimination on the instructions we just modified.
void Float2Int::cleanup() { void Float2Int::cleanup() {
for (auto I = ConvertedInsts.rbegin(), E = ConvertedInsts.rend(); for (auto &I : make_range(ConvertedInsts.rbegin(), ConvertedInsts.rend()))
I != E; ++I) I.first->eraseFromParent();
I->first->eraseFromParent();
} }
bool Float2Int::runOnFunction(Function &F) { bool Float2Int::runOnFunction(Function &F) {

View File

@@ -164,9 +164,7 @@ public:
// Delete the instructions backwards, as it has a reduced likelihood of // Delete the instructions backwards, as it has a reduced likelihood of
// having to update as many def-use and use-def chains. // having to update as many def-use and use-def chains.
for (auto I = Unused.rbegin(), E = Unused.rend(); I != E; ++I) { for (auto *Inst : make_range(Unused.rbegin(), Unused.rend())) {
auto *Inst = *I;
if (!Inst->use_empty()) if (!Inst->use_empty())
Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
Inst->eraseFromParent(); Inst->eraseFromParent();

View File

@@ -851,9 +851,8 @@ updateInlinedAtInfo(DebugLoc DL, DILocation *InlinedAtNode, LLVMContext &Ctx,
// Starting from the top, rebuild the nodes to point to the new inlined-at // Starting from the top, rebuild the nodes to point to the new inlined-at
// location (then rebuilding the rest of the chain behind it) and update the // location (then rebuilding the rest of the chain behind it) and update the
// map of already-constructed inlined-at nodes. // map of already-constructed inlined-at nodes.
for (auto I = InlinedAtLocations.rbegin(), E = InlinedAtLocations.rend(); for (const DILocation *MD : make_range(InlinedAtLocations.rbegin(),
I != E; ++I) { InlinedAtLocations.rend())) {
const DILocation *MD = *I;
Last = IANodes[MD] = DILocation::getDistinct( Last = IANodes[MD] = DILocation::getDistinct(
Ctx, MD->getLine(), MD->getColumn(), MD->getScope(), Last); Ctx, MD->getLine(), MD->getColumn(), MD->getScope(), Last);
} }