Skip to content

Commit 86e0c1a

Browse files
tammeladavemgreen
authored andcommitted
[NFC][Reg2Mem] modernize loops iterators
This patch updates the Reg2Mem loops to use more modern iterators. Differential Revision: https://reviews.llvm.org/D90122
1 parent 70a495c commit 86e0c1a

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

llvm/lib/Transforms/Scalar/Reg2Mem.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/IR/BasicBlock.h"
2020
#include "llvm/IR/CFG.h"
2121
#include "llvm/IR/Function.h"
22+
#include "llvm/IR/InstIterator.h"
2223
#include "llvm/IR/Instructions.h"
2324
#include "llvm/IR/LLVMContext.h"
2425
#include "llvm/IR/Module.h"
@@ -47,9 +48,9 @@ namespace {
4748
AU.addPreservedID(BreakCriticalEdgesID);
4849
}
4950

50-
bool valueEscapes(const Instruction *Inst) const {
51-
const BasicBlock *BB = Inst->getParent();
52-
for (const User *U : Inst->users()) {
51+
bool valueEscapes(const Instruction &Inst) const {
52+
const BasicBlock *BB = Inst.getParent();
53+
for (const User *U : Inst.users()) {
5354
const Instruction *UI = cast<Instruction>(U);
5455
if (UI->getParent() != BB || isa<PHINode>(UI))
5556
return true;
@@ -90,33 +91,26 @@ bool RegToMem::runOnFunction(Function &F) {
9091
// Find the escaped instructions. But don't create stack slots for
9192
// allocas in entry block.
9293
std::list<Instruction*> WorkList;
93-
for (BasicBlock &ibb : F)
94-
for (BasicBlock::iterator iib = ibb.begin(), iie = ibb.end(); iib != iie;
95-
++iib) {
96-
if (!(isa<AllocaInst>(iib) && iib->getParent() == BBEntry) &&
97-
valueEscapes(&*iib)) {
98-
WorkList.push_front(&*iib);
99-
}
100-
}
94+
for (Instruction &I : instructions(F))
95+
if (!(isa<AllocaInst>(I) && I.getParent() == BBEntry) && valueEscapes(I))
96+
WorkList.push_front(&I);
10197

10298
// Demote escaped instructions
10399
NumRegsDemoted += WorkList.size();
104-
for (Instruction *ilb : WorkList)
105-
DemoteRegToStack(*ilb, false, AllocaInsertionPoint);
100+
for (Instruction *I : WorkList)
101+
DemoteRegToStack(*I, false, AllocaInsertionPoint);
106102

107103
WorkList.clear();
108104

109105
// Find all phi's
110-
for (BasicBlock &ibb : F)
111-
for (BasicBlock::iterator iib = ibb.begin(), iie = ibb.end(); iib != iie;
112-
++iib)
113-
if (isa<PHINode>(iib))
114-
WorkList.push_front(&*iib);
106+
for (BasicBlock &BB : F)
107+
for (auto &Phi : BB.phis())
108+
WorkList.push_front(&Phi);
115109

116110
// Demote phi nodes
117111
NumPhisDemoted += WorkList.size();
118-
for (Instruction *ilb : WorkList)
119-
DemotePHIToStack(cast<PHINode>(ilb), AllocaInsertionPoint);
112+
for (Instruction *I : WorkList)
113+
DemotePHIToStack(cast<PHINode>(I), AllocaInsertionPoint);
120114

121115
return true;
122116
}

0 commit comments

Comments
 (0)