Skip to content

Commit

Permalink
Fix bugs and emit guards for latches that cut through and go to loop …
Browse files Browse the repository at this point in the history
…headers that are not immediate parent
  • Loading branch information
VedantParanjape committed Nov 1, 2023
1 parent 530e2cc commit 423d300
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 615 deletions.
4 changes: 3 additions & 1 deletion include/blocks/loops.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include <unordered_set>

using namespace block;
class loop_info;
class loop {
public:
loop(std::shared_ptr<basic_block> header): header_block(header) {}
stmt::Ptr convert_to_ast_impl(dominator_analysis &dta_, std::vector<std::pair<std::shared_ptr<basic_block>, stmt_block::Ptr>> &return_blocks);
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);

struct loop_bounds_ {
stmt::Ptr ind_var;
Expand All @@ -33,6 +34,7 @@ class loop {
basic_block::cfg_block loop_latch_blocks;
basic_block::cfg_block loop_exit_blocks;
std::vector<std::shared_ptr<loop>> subloops;
while_stmt::Ptr structured_ast_loop;
};

class loop_info {
Expand Down
4 changes: 3 additions & 1 deletion src/blocks/basic_blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
work_list.pop_front();
// push the exit block to the work_list
work_list.push_front(exit_bb);

std::cerr << "inside if handler: " << bb->name << "\n";
// if there is a then_stmt, create a basic block for it
if (to<stmt_block>(if_stmt_->then_stmt)->stmts.size() != 0) {
auto then_bb = std::make_shared<basic_block>(std::to_string(++basic_block_count));
Expand All @@ -112,6 +112,7 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
bb->then_branch = then_bb;
// push the block to the work_list, to expand it further
work_list.push_front(then_bb);
std::cerr << "inside then" << "\n";
}
// if there is a else_stmt, create a basic block for it
if (to<stmt_block>(if_stmt_->else_stmt)->stmts.size() != 0) {
Expand All @@ -128,6 +129,7 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
bb->else_branch = else_bb;
// push the block to the work_list, to expand it further
work_list.insert(work_list.begin() + 1, else_bb);
std::cerr << "inside else" << "\n";
}

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

0 comments on commit 423d300

Please sign in to comment.