File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 44#include " blocks/basic_blocks.h"
55#include " blocks/dominance.h"
66#include " blocks/stmt.h"
7+ #include < unordered_set>
78
89using namespace block ;
910class loop {
@@ -23,9 +24,10 @@ class loop {
2324 } loop_bounds;
2425
2526 basic_block::cfg_block blocks;
27+ std::unordered_set<int > blocks_id_map;
2628 std::shared_ptr<loop> parent_loop;
2729 std::shared_ptr<basic_block> header_block;
28- std::shared_ptr<basic_block> backedge_block ;
30+ basic_block::cfg_block loop_latch_blocks ;
2931 std::vector<std::shared_ptr<loop>> subloops;
3032};
3133
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ void loop_info::analyze() {
8484 }
8585 new_loop->subloops .reserve (num_subloops);
8686 new_loop->blocks .reserve (num_blocks);
87+ new_loop->blocks_id_map .reserve (num_blocks);
8788 }
8889 }
8990
@@ -108,7 +109,21 @@ void loop_info::analyze() {
108109
109110 while (subloop) {
110111 subloop->blocks .push_back (dta.cfg_ [bb_id]);
112+ subloop->blocks_id_map .insert (dta.cfg_ [bb_id]->id );
111113 subloop = subloop->parent_loop ;
112114 }
113115 }
116+
117+ // Populate the loop latches
118+ for (auto loop: loops) {
119+ if (!loop->header_block )
120+ continue ;
121+
122+ std::shared_ptr<basic_block> header = loop->header_block ;
123+ for (auto children: header->predecessor ) {
124+ if (loop->blocks_id_map .count (children->id )) {
125+ loop->loop_latch_blocks .push_back (children);
126+ }
127+ }
128+ }
114129}
Original file line number Diff line number Diff line change @@ -371,11 +371,17 @@ block::stmt::Ptr builder_context::extract_ast_from_function_impl(void) {
371371 std::cerr << " ++++++ loop " << loop_num++ << " ++++++ \n " ;
372372
373373 std::cerr << " loop headers: " << loop->header_block ->id << " \n " ;
374+
374375 std::cerr << " blocks: " ;
375376 for (auto bb: loop->blocks ) std::cerr << bb->id << " " ;
376377 std::cerr << " \n " ;
377- // std::cerr << "backedge: " << loop->backedge_block->id << "\n";
378+
379+ std::cerr << " loop latches: " ;
380+ for (auto bb: loop->loop_latch_blocks ) std::cerr << bb->id << " " ;
381+ std::cerr << " \n " ;
382+
378383 std::cerr << " parent loop: (loop header: " << (loop->parent_loop ? (int )loop->parent_loop ->header_block ->id : -1 ) << " )\n " ;
384+
379385 std::cerr << " subloops: " ;
380386 for (auto subl: loop->subloops ) std::cerr << " (loop header: " << subl->header_block ->id << " ) " ;
381387 std::cerr << " \n " ;
You can’t perform that action at this time.
0 commit comments