]> gitweb.factorcode.org Git - factor.git/commitdiff
add branch splitting pass to compiler.cfg
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 30 Jun 2009 20:31:48 +0000 (15:31 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 30 Jun 2009 20:31:48 +0000 (15:31 -0500)
basis/compiler/cfg/branch-splitting/authors.txt [new file with mode: 0644]
basis/compiler/cfg/branch-splitting/branch-splitting.factor [new file with mode: 0644]

diff --git a/basis/compiler/cfg/branch-splitting/authors.txt b/basis/compiler/cfg/branch-splitting/authors.txt
new file mode 100644 (file)
index 0000000..b4bd0e7
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
\ No newline at end of file
diff --git a/basis/compiler/cfg/branch-splitting/branch-splitting.factor b/basis/compiler/cfg/branch-splitting/branch-splitting.factor
new file mode 100644 (file)
index 0000000..2b3d881
--- /dev/null
@@ -0,0 +1,29 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors combinators.short-circuit compiler.cfg.def-use
+compiler.cfg.rpo kernel math sequences ;
+IN: compiler.cfg.branch-splitting
+
+: split-branch ( branch -- )
+    [
+        [ instructions>> ] [ predecessors>> ] bi [
+            instructions>> [ pop* ] [ push-all ] bi
+        ] with each
+    ] [
+        [ successors>> ] [ predecessors>> ] bi [
+            [ drop clone ] change-successors drop
+        ] with each
+    ] bi ;
+
+: split-branches? ( bb -- ? )
+    {
+        [ predecessors>> length 1 >= ]
+        [ successors>> length 1 <= ]
+        [ instructions>> [ defs-vregs ] any? not ]
+        [ instructions>> [ temp-vregs ] any? not ]
+    } 1&& ;
+
+: split-branches ( cfg -- cfg' )
+    dup [
+        dup split-branches? [ split-branch ] [ drop ] if
+    ] each-basic-block f >>post-order ;