Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[blocks] Add dominance analysis over CFGs #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions include/blocks/dominance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef DOMINANCE_H
#define DOMINANCE_H
#include "blocks/block_visitor.h"
#include "blocks/basic_blocks.h"
#include "blocks/stmt.h"
#include <map>
#include <vector>
#include <stack>
#include <string>
#include <bitset>
#include <algorithm>

namespace block {
class dominator_analysis {
public:
dominator_analysis(basic_block::cfg_block cfg, bool is_postdom = false);
basic_block::cfg_block cfg_;
bool is_postdom_;
int max_depth;
unsigned int max_depth_bb_id;
std::vector<int> &get_postorder_bb_map();
std::vector<int> &get_postorder();
std::vector<int> &get_preorder_bb_map();
std::vector<int> &get_preorder();
std::vector<int> &get_idom();
std::map<int, std::vector<int>> &get_idom_map();
std::vector<int> &get_postorder_idom_map();
int get_idom(int bb_id);
std::vector<int> get_idom_map(int bb_id);
int get_postorder_idom_map(int idom_id);
bool dominates(int bb1_id, int bb2_id);
bool is_reachable_from_entry(int bb_id);
void analyze();

private:
std::vector<int> idom;
std::map<int, std::vector<int>> idom_map;
std::vector<int> postorder_idom;
std::vector<int> postorder;
std::vector<int> postorder_bb_map;
std::vector<int> preorder;
std::vector<int> preorder_bb_map;
void reverse_cfg();
void postorder_idom_helper(std::vector<bool> &visited, int id);
void postorder_dfs_helper(std::vector<bool> &visited_bbs, int id, int depth);
void postorder_dfs(bool reverse_cfg);
void preorder_dfs_helper(std::vector<bool> &visited_bbs, int id);
void preorder_dfs(bool reverse_cfg);
int intersect(int bb1_id, int bb2_id);
};

void dump(dominator_analysis &dom);
} // namespace block

#endif
1 change: 1 addition & 0 deletions include/builder/builder_context.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef BUILDER_CONTEXT
#define BUILDER_CONTEXT
#include "blocks/basic_blocks.h"
#include "blocks/dominance.h"
#include "blocks/expr.h"
#include "blocks/stmt.h"
#include "builder/forward_declarations.h"
Expand Down
Loading
Loading