]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Generate reverse postorder instead of preorder list in flow analyzer
authorJürg Billeter <j@bitron.ch>
Wed, 23 Dec 2009 19:46:41 +0000 (20:46 +0100)
committerJürg Billeter <j@bitron.ch>
Wed, 23 Dec 2009 19:46:41 +0000 (20:46 +0100)
vala/valabasicblock.vala
vala/valaflowanalyzer.vala

index 498622c8964d9f2c0347e8eb16f33ffc32380eb6..c69f6c663a4481138bea74dfb18f93d260db18ed 100644 (file)
@@ -40,6 +40,8 @@ public class Vala.BasicBlock {
 
        Set<PhiFunction> phi_functions = new HashSet<PhiFunction> ();
 
+       public bool postorder_visited { get; set; }
+
        public BasicBlock () {
        }
 
index 870a9e1ce16597f7d02f3a5de1cb07dba3fa7e42..5cb8f1fbf79aa4d3c93b480200e65287d59681b0 100644 (file)
@@ -181,6 +181,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                check_variables (entry_block);
        }
 
+       // generates reverse postorder list
        List<BasicBlock> get_depth_first_list (BasicBlock entry_block) {
                var list = new ArrayList<BasicBlock> ();
                depth_first_traverse (entry_block, list);
@@ -188,13 +189,14 @@ public class Vala.FlowAnalyzer : CodeVisitor {
        }
 
        void depth_first_traverse (BasicBlock current, List<BasicBlock> list) {
-               if (current in list) {
+               if (current.postorder_visited) {
                        return;
                }
-               list.add (current);
+               current.postorder_visited = true;
                foreach (BasicBlock succ in current.get_successors ()) {
                        depth_first_traverse (succ, list);
                }
+               list.insert (0, current);
        }
 
        void build_dominator_tree (List<BasicBlock> block_list, BasicBlock entry_block) {