From c6141d5c2247ca91f642b689923c464360f2e853 Mon Sep 17 00:00:00 2001 From: Vedant Paranjape <22630228+VedantParanjape@users.noreply.github.com> Date: Wed, 17 May 2023 00:28:42 +0530 Subject: [PATCH] Add code to populate the basic block predecessors --- src/blocks/basic_blocks.cpp | 7 +++++++ src/blocks/loop_finder.cpp | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/blocks/basic_blocks.cpp b/src/blocks/basic_blocks.cpp index 2457703..f70093f 100644 --- a/src/blocks/basic_blocks.cpp +++ b/src/blocks/basic_blocks.cpp @@ -153,5 +153,12 @@ std::vector> 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; } \ No newline at end of file diff --git a/src/blocks/loop_finder.cpp b/src/blocks/loop_finder.cpp index 464d7b8..92d39f4 100644 --- a/src/blocks/loop_finder.cpp +++ b/src/blocks/loop_finder.cpp @@ -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);