Skip to content

Commit 1ab9eac

Browse files
WIP v4: got the insert loop latches/exits correctly and added while loop simplifications
1 parent 9d91203 commit 1ab9eac

File tree

3 files changed

+86
-37
lines changed

3 files changed

+86
-37
lines changed

include/blocks/basic_blocks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class basic_block {
2222
unsigned int ast_depth;
2323
unsigned int id;
2424
std::string name;
25-
// static std::map<block::stmt::Ptr, std::shared_ptr<basic_block>> ast_to_basic_block_map;
25+
static std::map<block::stmt::Ptr, std::shared_ptr<basic_block>> ast_to_basic_block_map;
2626
};
2727

2828
basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast);

src/blocks/basic_blocks.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using namespace block;
55

6+
std::map<block::stmt::Ptr, std::shared_ptr<basic_block>> basic_block::ast_to_basic_block_map = {};
7+
68
basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
79
std::deque<std::shared_ptr<basic_block>> work_list;
810
basic_block::cfg_block return_list;
@@ -13,7 +15,6 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
1315
for (auto st: ast->stmts) {
1416
auto bb = std::make_shared<basic_block>(std::to_string(basic_block_count));
1517
bb->parent = st;
16-
// bb->ast_to_basic_block_map[bb->parent] = bb;
1718
bb->ast_index = ast_index_counter++;
1819
bb->ast_depth = 0;
1920
work_list.push_back(bb);
@@ -41,7 +42,6 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
4142
for (auto st: stmt_block_->stmts) {
4243
stmt_block_list.push_back(std::make_shared<basic_block>(std::to_string(basic_block_count++)));
4344
stmt_block_list.back()->parent = st;
44-
// stmt_block_list.back()->ast_to_basic_block_map[bb->parent] = stmt_block_list.back();
4545
stmt_block_list.back()->ast_index = ast_index_counter++;
4646
stmt_block_list.back()->ast_depth = bb->ast_depth + 1;
4747
}
@@ -83,8 +83,6 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
8383
exit_bb->parent = std::make_shared<stmt_block>();
8484
// mark the basic block as exit block
8585
exit_bb->is_exit_block = true;
86-
// add mapping in ast to bb map
87-
// exit_bb->ast_to_basic_block_map[exit_bb->parent] = exit_bb;
8886
// set the ast depth of the basic block
8987
exit_bb->ast_depth = bb->ast_depth;
9088
// check if this is the last block, if yes the successor will be empty
@@ -104,8 +102,6 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
104102
auto then_bb = std::make_shared<basic_block>(std::to_string(++basic_block_count));
105103
// set the parent of this block as the then stmts
106104
then_bb->parent = if_stmt_->then_stmt;
107-
// add mapping in ast to bb map
108-
// then_bb->ast_to_basic_block_map[then_bb->parent] = then_bb;
109105
// set the ast depth of the basic block
110106
then_bb->ast_depth = bb->ast_depth;
111107
// set the successor of this block to be the exit block
@@ -122,8 +118,6 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
122118
auto else_bb = std::make_shared<basic_block>(std::to_string(++basic_block_count));
123119
// set the parent of this block as the else stmts
124120
else_bb->parent = if_stmt_->else_stmt;
125-
// add mapping in ast to bb map
126-
// else_bb->ast_to_basic_block_map[else_bb->parent] = else_bb;
127121
// set the ast depth of the basic block
128122
else_bb->ast_depth = bb->ast_depth;
129123
// set the successor of this block to be the exit block
@@ -203,5 +197,10 @@ basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast) {
203197
return_list[i]->id = i;
204198
}
205199

200+
// step 7: populate the ast -> bb map
201+
for (auto bb: return_list) {
202+
bb->ast_to_basic_block_map[bb->parent] = bb;
203+
}
204+
206205
return return_list;
207206
}

0 commit comments

Comments
 (0)