33 #define DEBUG_NAME "compiler2/LoopSimplificationPass"
43 void LoopSimplificationPass::check_loop(
Loop *
loop)
const {
47 BeginInst* header = loop->get_header();
48 if (LT->get_Loop(header) !=
loop) {
49 LOG(
"Loop with shared header:" << header <<
nl);
56 alloc::set<BeginInst*>::type outer_edges;
58 for (BeginInst::PredecessorListTy::const_iterator
i = header->pred_begin(),
59 e = header->pred_end();
i !=
e; ++
i) {
62 Loop *pred_loop = LT->get_Loop(pred);
64 if (!LT->is_inner_loop(pred_loop,loop)) {
68 outer_edges.insert(pred);
72 BeginInst* new_header =
new BeginInst();
74 EndInst* new_exit =
new GOTOInst(new_header,header);
75 for (alloc::set<BeginInst*>::type::iterator
i = outer_edges.begin(),
e = outer_edges.end() ;
77 EndInst *end = (*i)->get_EndInst();
78 assert(end &&
"Can not replace a successor of a BeginInst without an EndInst!");
79 end->replace_succ(header, new_header);
84 loop->header = new_header;
86 LT->loop_map[new_header] =
loop;
93 for (Instruction::DepListTy::const_iterator
i = header->dep_begin(),
94 e = header->dep_end();
i !=
e; ++
i) {
97 PHIInst *phi = I->to_PHIInst();
99 LOG(
"PHI: " << phi <<
nl);
115 bool LoopSimplificationPass::run(JITData &JD) {
119 LT = get_Pass<LoopPass>();
128 LOG(
"Verify LoopSimplificationPass result" <<
nl);
130 alloc::list<Loop*>::type loops(LT->loop_begin(), LT->loop_end());
131 while(!loops.empty()) {
132 Loop *loop = loops.front();
134 assert(LT->get_Loop(loop->get_header()) == loop);
145 PassUsage& LoopSimplificationPass::get_PassUsage(PassUsage &PU)
const {
151 char LoopSimplificationPass::ID = 0;
154 static PassRegistry<LoopSimplificationPass>
X(
"LoopSimplificationPass");
LoopPassBase< BeginInst > LoopPass
LoopSetTy::iterator loop_iterator
void add_Instruction(Instruction *I)
Add instructions to a Method.
LoopBase< BeginInst > Loop
#define LOG(STMT)
Analogous to DEBUG.
void add_bb(BeginInst *bi)
Add a BeginInst.
static PassRegistry< BasicBlockSchedulingPass > X("BasicBlockSchedulingPass")