-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate idom_map and add loop info pass skeleton
This commit does the following things: 1) Cleans up the basic_block def by adding a typedef. 2) Adds code to generate a idom map, which makes it easy to iterate over the dominator tree. 3) Implements a skeleton class for loop analysis pass. 4) Adds relevant tests to builder_context.cpp to test the dominator_tree APIs 5) Rename the dominator_tree class to dominator_analysis class.
- Loading branch information
1 parent
994ff9f
commit 3e3518e
Showing
8 changed files
with
138 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
#ifndef BASIC_BLOCKS_H | ||
#define BASIC_BLOCKS_H | ||
#include "blocks/block_visitor.h" | ||
#include "blocks/stmt.h" | ||
#include <vector> | ||
#include <deque> | ||
#include <string> | ||
|
||
class basic_block { | ||
public: | ||
typedef std::vector<std::shared_ptr<basic_block>> cfg_block; | ||
basic_block(std::string label): name(label) {}; | ||
|
||
std::vector<std::shared_ptr<basic_block>> predecessor; | ||
std::vector<std::shared_ptr<basic_block>> successor; | ||
cfg_block predecessor; | ||
cfg_block successor; | ||
block::expr::Ptr branch_expr; | ||
block::stmt::Ptr parent; | ||
unsigned int index; | ||
unsigned int id; | ||
std::string name; | ||
}; | ||
|
||
std::vector<std::shared_ptr<basic_block>> generate_basic_blocks(block::stmt_block::Ptr ast); | ||
basic_block::cfg_block generate_basic_blocks(block::stmt_block::Ptr ast); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef LOOP_H | ||
#define LOOP_H | ||
#include "blocks/block_visitor.h" | ||
#include "blocks/basic_blocks.h" | ||
#include "blocks/dominance.h" | ||
#include "blocks/stmt.h" | ||
|
||
using namespace block; | ||
class loop { | ||
public: | ||
loop() = default; | ||
|
||
private: | ||
struct loop_bounds_ { | ||
stmt::Ptr ind_var; | ||
// MISS: intial value of ind var | ||
stmt::Ptr steps_ind_var; | ||
// MISS: value of the step | ||
// MISS: final value of the step | ||
stmt::Ptr cond_ind_var; | ||
// MISS: direction of step | ||
stmt::Ptr entry_stmt; | ||
} loop_bounds; | ||
|
||
basic_block::cfg_block exit_bbs; | ||
}; | ||
|
||
class loop_info { | ||
public: | ||
loop_info(basic_block::cfg_block ast, dominator_analysis dt): parent_ast(ast), dta(dt) { | ||
analyze(); | ||
} | ||
private: | ||
basic_block::cfg_block parent_ast; | ||
dominator_analysis dta; | ||
// discover loops during traversal of the abstract syntax tree | ||
void analyze(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "blocks/loops.h" | ||
#include <algorithm> | ||
|
||
void loop_info::analyze() { | ||
std::vector<int> idom = dta.get_idom(); | ||
for (unsigned int i = 0; i < idom.size(); i++) { | ||
std::cout << i << " : " << idom[i] << "\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters