Commit 3a0e6b26 authored by Jürg Billeter's avatar Jürg Billeter

Only generate depth-first list once per method in flow analyzer

Improves performance.
parent 9ab2e259
...@@ -173,9 +173,11 @@ public class Vala.FlowAnalyzer : CodeVisitor { ...@@ -173,9 +173,11 @@ public class Vala.FlowAnalyzer : CodeVisitor {
} }
void analyze_body (BasicBlock entry_block) { void analyze_body (BasicBlock entry_block) {
build_dominator_tree (entry_block); var block_list = get_depth_first_list (entry_block);
build_dominator_frontier (entry_block);
insert_phi_functions (entry_block); build_dominator_tree (block_list, entry_block);
build_dominator_frontier (block_list, entry_block);
insert_phi_functions (block_list, entry_block);
check_variables (entry_block); check_variables (entry_block);
} }
...@@ -195,10 +197,9 @@ public class Vala.FlowAnalyzer : CodeVisitor { ...@@ -195,10 +197,9 @@ public class Vala.FlowAnalyzer : CodeVisitor {
} }
} }
void build_dominator_tree (BasicBlock entry_block) { void build_dominator_tree (List<BasicBlock> block_list, BasicBlock entry_block) {
// set dom(n) = {E,1,2...,N,X} forall n // set dom(n) = {E,1,2...,N,X} forall n
var dom = new HashMap<BasicBlock, Set<BasicBlock>> (); var dom = new HashMap<BasicBlock, Set<BasicBlock>> ();
var block_list = get_depth_first_list (entry_block);
foreach (BasicBlock block in block_list) { foreach (BasicBlock block in block_list) {
var block_set = new HashSet<BasicBlock> (); var block_set = new HashSet<BasicBlock> ();
foreach (BasicBlock b in block_list) { foreach (BasicBlock b in block_list) {
...@@ -283,8 +284,7 @@ public class Vala.FlowAnalyzer : CodeVisitor { ...@@ -283,8 +284,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
} }
} }
void build_dominator_frontier (BasicBlock entry_block) { void build_dominator_frontier (List<BasicBlock> block_list, BasicBlock entry_block) {
var block_list = get_depth_first_list (entry_block);
for (int i = block_list.size - 1; i >= 0; i--) { for (int i = block_list.size - 1; i >= 0; i--) {
var block = block_list[i]; var block = block_list[i];
...@@ -306,9 +306,9 @@ public class Vala.FlowAnalyzer : CodeVisitor { ...@@ -306,9 +306,9 @@ public class Vala.FlowAnalyzer : CodeVisitor {
} }
} }
Map<LocalVariable, Set<BasicBlock>> get_assignment_map (BasicBlock entry_block) { Map<LocalVariable, Set<BasicBlock>> get_assignment_map (List<BasicBlock> block_list, BasicBlock entry_block) {
var map = new HashMap<LocalVariable, Set<BasicBlock>> (); var map = new HashMap<LocalVariable, Set<BasicBlock>> ();
foreach (BasicBlock block in get_depth_first_list (entry_block)) { foreach (BasicBlock block in block_list) {
var defined_variables = new ArrayList<LocalVariable> (); var defined_variables = new ArrayList<LocalVariable> ();
foreach (CodeNode node in block.get_nodes ()) { foreach (CodeNode node in block.get_nodes ()) {
node.get_defined_variables (defined_variables); node.get_defined_variables (defined_variables);
...@@ -326,15 +326,15 @@ public class Vala.FlowAnalyzer : CodeVisitor { ...@@ -326,15 +326,15 @@ public class Vala.FlowAnalyzer : CodeVisitor {
return map; return map;
} }
void insert_phi_functions (BasicBlock entry_block) { void insert_phi_functions (List<BasicBlock> block_list, BasicBlock entry_block) {
var assign = get_assignment_map (entry_block); var assign = get_assignment_map (block_list, entry_block);
int counter = 0; int counter = 0;
var work_list = new ArrayList<BasicBlock> (); var work_list = new ArrayList<BasicBlock> ();
var added = new HashMap<BasicBlock, int> (); var added = new HashMap<BasicBlock, int> ();
var phi = new HashMap<BasicBlock, int> (); var phi = new HashMap<BasicBlock, int> ();
foreach (BasicBlock block in get_depth_first_list (entry_block)) { foreach (BasicBlock block in block_list) {
added.set (block, 0); added.set (block, 0);
phi.set (block, 0); phi.set (block, 0);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment