Skip to content

Commit

Permalink
Add code to populate the basic block predecessors
Browse files Browse the repository at this point in the history
  • Loading branch information
VedantParanjape committed May 16, 2023
1 parent 51a3213 commit c6141d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/blocks/basic_blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,12 @@ std::vector<std::shared_ptr<basic_block>> generate_basic_blocks(block::stmt_bloc
}
}

// step 5: populate the predecessors
for (auto bb: return_list) {
for (auto succ: bb->successor) {
succ->predecessor.push_back(bb);
}
}

return return_list;
}
6 changes: 5 additions & 1 deletion src/blocks/loop_finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ void loop_finder::visit(stmt_block::Ptr a) {

std::cout << "++++++ basic blocks ++++++ \n";
for (auto bb: BBs) {
std::cout << bb->name << ":" << "\n";
std::cout << bb->name << ":" << " ; ";
for (auto pred: bb->predecessor) {
std::cout << pred->name << ", ";
}
std::cout << "\n";
if (bb->branch_expr) {
std::cout << " ";
bb->branch_expr->dump(std::cout, 0);
Expand Down

0 comments on commit c6141d5

Please sign in to comment.