]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.cfg.dominance: add algorithm for computing iterated dominance frontiers
authorSlava Pestov <slava@shill.local>
Wed, 22 Jul 2009 11:07:51 +0000 (06:07 -0500)
committerSlava Pestov <slava@shill.local>
Wed, 22 Jul 2009 11:07:51 +0000 (06:07 -0500)
basis/compiler/cfg/dominance/dominance-tests.factor
basis/compiler/cfg/dominance/dominance.factor

index 210d5614c26608233acade0bad5130448b3ff92a..d73871c25f5f387481828f2fe4790f9b7e2811ea 100644 (file)
@@ -74,3 +74,25 @@ V{ } 5 test-bb
 [ ] [ test-dominance ] unit-test
 
 [ t ] [ 0 5 [a,b] [ get dom-parent 0 get eq? ] all? ] unit-test
+
+V{ } 0 test-bb
+V{ } 1 test-bb
+V{ } 2 test-bb
+V{ } 3 test-bb
+V{ } 4 test-bb
+V{ } 5 test-bb
+V{ } 6 test-bb
+
+0 get 1 get 5 get V{ } 2sequence >>successors drop
+1 get 2 get 3 get V{ } 2sequence >>successors drop
+2 get 4 get 1vector >>successors drop
+3 get 4 get 1vector >>successors drop
+4 get 6 get 1vector >>successors drop
+5 get 6 get 1vector >>successors drop
+
+[ ] [ test-dominance ] unit-test
+
+[ t ] [
+    2 get 3 get 2array iterated-dom-frontier
+    4 get 6 get 2array set=
+] unit-test
\ No newline at end of file
index 9c8fc796197d74608fccd4e6f1d5434d2b868a4a..73d9f58eec70822982faa289723ca8937c6b9571 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs combinators sets math fry kernel math.order
-namespaces sequences sorting compiler.cfg.rpo ;
+dlists deques namespaces sequences sorting compiler.cfg.rpo ;
 IN: compiler.cfg.dominance
 
 ! Reference:
@@ -85,8 +85,31 @@ PRIVATE>
 
 PRIVATE>
 
-: compute-dominance ( cfg -- cfg' )
+: compute-dominance ( cfg -- )
     [ compute-dom-parents compute-dom-children ]
     [ compute-dom-frontiers ]
-    [ ]
-    tri ;
+    bi ;
+
+<PRIVATE
+
+SYMBOLS: work-list visited ;
+
+: add-to-work-list ( bb -- )
+    dom-frontier work-list get push-all-front ;
+
+: iterated-dom-frontier-step ( bb -- )
+    dup visited get key? [ drop ] [
+        [ visited get conjoin ]
+        [ add-to-work-list ] bi
+    ] if ;
+
+PRIVATE>
+
+: iterated-dom-frontier ( bbs -- bbs' )
+    [
+        <dlist> work-list set
+        H{ } clone visited set
+        [ add-to-work-list ] each
+        work-list get [ iterated-dom-frontier-step ] slurp-deque
+        visited get keys
+    ] with-scope ;
\ No newline at end of file