|
19 | 19 | #include "llvm/IR/BasicBlock.h"
|
20 | 20 | #include "llvm/IR/CFG.h"
|
21 | 21 | #include "llvm/IR/Function.h"
|
| 22 | +#include "llvm/IR/InstIterator.h" |
22 | 23 | #include "llvm/IR/Instructions.h"
|
23 | 24 | #include "llvm/IR/LLVMContext.h"
|
24 | 25 | #include "llvm/IR/Module.h"
|
@@ -47,9 +48,9 @@ namespace {
|
47 | 48 | AU.addPreservedID(BreakCriticalEdgesID);
|
48 | 49 | }
|
49 | 50 |
|
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()) { |
53 | 54 | const Instruction *UI = cast<Instruction>(U);
|
54 | 55 | if (UI->getParent() != BB || isa<PHINode>(UI))
|
55 | 56 | return true;
|
@@ -90,33 +91,26 @@ bool RegToMem::runOnFunction(Function &F) {
|
90 | 91 | // Find the escaped instructions. But don't create stack slots for
|
91 | 92 | // allocas in entry block.
|
92 | 93 | 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); |
101 | 97 |
|
102 | 98 | // Demote escaped instructions
|
103 | 99 | NumRegsDemoted += WorkList.size();
|
104 |
| - for (Instruction *ilb : WorkList) |
105 |
| - DemoteRegToStack(*ilb, false, AllocaInsertionPoint); |
| 100 | + for (Instruction *I : WorkList) |
| 101 | + DemoteRegToStack(*I, false, AllocaInsertionPoint); |
106 | 102 |
|
107 | 103 | WorkList.clear();
|
108 | 104 |
|
109 | 105 | // 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); |
115 | 109 |
|
116 | 110 | // Demote phi nodes
|
117 | 111 | 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); |
120 | 114 |
|
121 | 115 | return true;
|
122 | 116 | }
|
|
0 commit comments