From ea072731d4d6f2e586de418be213803a65099470 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 30 Jun 2009 15:31:48 -0500 Subject: [PATCH] add branch splitting pass to compiler.cfg --- .../compiler/cfg/branch-splitting/authors.txt | 1 + .../branch-splitting/branch-splitting.factor | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 basis/compiler/cfg/branch-splitting/authors.txt create mode 100644 basis/compiler/cfg/branch-splitting/branch-splitting.factor diff --git a/basis/compiler/cfg/branch-splitting/authors.txt b/basis/compiler/cfg/branch-splitting/authors.txt new file mode 100644 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/basis/compiler/cfg/branch-splitting/authors.txt @@ -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 index 0000000000..2b3d88191c --- /dev/null +++ b/basis/compiler/cfg/branch-splitting/branch-splitting.factor @@ -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 ;