Skip to content

Commit 423d300

Browse files
Fix bugs and emit guards for latches that cut through and go to loop headers that are not immediate parent
1 parent 530e2cc commit 423d300

File tree

4 files changed

+145
-615
lines changed

4 files changed

+145
-615
lines changed

include/blocks/loops.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
#include <unordered_set>
88

99
using namespace block;
10+
class loop_info;
1011
class loop {
1112
public:
1213
loop(std::shared_ptr<basic_block> header): header_block(header) {}
13-
stmt::Ptr convert_to_ast_impl(dominator_analysis &dta_, std::vector<std::pair<std::shared_ptr<basic_block>, stmt_block::Ptr>> &return_blocks);
14+
stmt::Ptr convert_to_ast_impl(loop_info &li, dominator_analysis &dta_, std::vector<std::pair<std::shared_ptr<basic_block>, stmt_block::Ptr>> &return_blocks, stmt::Ptr &jump_condition_def, stmt::Ptr &jump_condition_block);
1415

1516
struct loop_bounds_ {
1617
stmt::Ptr ind_var;
@@ -33,6 +34,7 @@ class loop {
3334
basic_block::cfg_block loop_latch_blocks;
3435
basic_block::cfg_block loop_exit_blocks;
3536
std::vector<std::shared_ptr<loop>> subloops;
37+
while_stmt::Ptr structured_ast_loop;
3638
};
3739

3840
class loop_info {

src/blocks/basic_blocks.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
9696
work_list.pop_front();
9797
// push the exit block to the work_list
9898
work_list.push_front(exit_bb);
99-
99+
std::cerr << "inside if handler: " << bb->name << "\n";
100100
// if there is a then_stmt, create a basic block for it
101101
if (to<stmt_block>(if_stmt_->then_stmt)->stmts.size() != 0) {
102102
auto then_bb = std::make_shared<basic_block>(std::to_string(++basic_block_count));
@@ -112,6 +112,7 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
112112
bb->then_branch = then_bb;
113113
// push the block to the work_list, to expand it further
114114
work_list.push_front(then_bb);
115+
std::cerr << "inside then" << "\n";
115116
}
116117
// if there is a else_stmt, create a basic block for it
117118
if (to<stmt_block>(if_stmt_->else_stmt)->stmts.size() != 0) {
@@ -128,6 +129,7 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
128129
bb->else_branch = else_bb;
129130
// push the block to the work_list, to expand it further
130131
work_list.insert(work_list.begin() + 1, else_bb);
132+
std::cerr << "inside else" << "\n";
131133
}
132134

133135
// if there is no then/else block, then have the exit block as successor as well.

0 commit comments

Comments
 (0)