]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.cfg.gvn: experiment to scan for available vregs when rewriting
authorAlex Vondrak <ajvondrak@csupomona.edu>
Fri, 10 Aug 2012 20:20:01 +0000 (13:20 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 20 Sep 2012 00:28:13 +0000 (17:28 -0700)
instructions instead of relying on the availability of the canonical
leader; untested

extra/compiler/cfg/gvn/avail/avail.factor
extra/compiler/cfg/gvn/graph/graph.factor
extra/compiler/cfg/gvn/gvn-tests.factor
extra/compiler/cfg/gvn/gvn.factor

index fa7de59e6fe82d1b56cd1a477d29b8639893db39..75388f9ce0eb83f9eca6cad4e3b89ab4a8d22e99 100644 (file)
@@ -7,6 +7,7 @@ compiler.cfg.dataflow-analysis
 compiler.cfg.def-use
 compiler.cfg.gvn.graph
 compiler.cfg.predecessors
+compiler.cfg.renaming.functor
 compiler.cfg.rpo ;
 FROM: assocs => change-at ;
 FROM: namespaces => set ;
@@ -22,20 +23,23 @@ FORWARD-ANALYSIS: avail
 
 M: avail-analysis transfer-set drop defined assoc-union ;
 
-! Strict idea of availability, for now.  Would like to see if
-! searching the VN congruence classes for the smallest
-! available vn would work at all / better.
+: available? ( vn -- ? ) basic-block get avail-in key? ;
 
-: available? ( vn -- ? )
+: best-vreg ( available-vregs -- vreg )
+    [ f ] [ infimum ] if-empty ;
+
+: >avail-vreg ( vreg -- vreg/f )
     final-iteration? get [
-        basic-block get avail-in key?
-    ] [ drop t ] if ;
+        congruence-class [ available? ] filter best-vreg
+    ] when ;
 
 : available-uses? ( insn -- ? )
-    uses-vregs [ available? ] all? ;
+    uses-vregs [ >avail-vreg ] all? ;
 
 : with-available-uses? ( quot -- ? )
     keep swap [ available-uses? ] [ drop f ] if ; inline
 
 : make-available ( vreg -- )
     basic-block get avail-ins get [ dupd clone ?set-at ] change-at ;
+
+RENAMING: >avail [ ] [ dup >avail-vreg swap or ] [ ]
index 76f4bedbfc4c715ed8be84b98f2e43815ab496df..ca59011b1b398937e650d79f58537a37a9c2c74a 100644 (file)
@@ -15,6 +15,10 @@ SYMBOL: exprs>vns
 ! assoc mapping value numbers to instructions
 SYMBOL: vns>insns
 
+! assoc mapping each value number to a sequence of vregs
+! sharing that value number (i.e., the congruence class)
+SYMBOL: vns>vregs
+
 ! boolean to track whether vregs>vns changes
 SYMBOL: changed?
 
@@ -31,10 +35,18 @@ SYMBOL: final-iteration?
 
 : vreg>insn ( vreg -- insn ) vreg>vn vn>insn ;
 
+: congruence-class ( vreg -- vregs )
+    vreg>vn vns>vregs get at ;
+
 : clear-exprs ( -- )
     exprs>vns get clear-assoc
     vns>insns get clear-assoc ;
 
+: compute-congruence-classes ( -- )
+    vregs>vns get H{ } clone [
+        [ push-at ] curry assoc-each
+    ] keep vns>vregs set ;
+
 : init-value-graph ( -- )
     0 input-expr-counter set
     H{ } clone vregs>vns set
index 7fbb2c6d3176c11b899fd388200a2867b6ee4ddf..3fbd86f91f2d21ed463ff867fc2d6f946b9f05eb 100644 (file)
@@ -3152,9 +3152,9 @@ cpu x86? [
     ] unit-test
 ] when
 
-! FIXME rewrite redundancy elimination to search for available
-! registers that compute the same value number, instead of just
-! relying on the availability of the canonical leader
+! Make sure to search for available registers that compute the
+! same value number, instead of just relying on the
+! availability of the canonical leader.
 
 V{ T{ ##branch } } 0 test-bb
 
@@ -3189,13 +3189,11 @@ test-diamond
     value-numbering drop
 ] unit-test
 
-! ##load-integer cannot be turned into a ##copy because the
-! canonical leader for the value 100 is unavailable.
+! First ##load-integer cannot be turned into a ##copy because
+! the canonical leader for the value 100 is unavailable, but
+! the rest should still be redundant.
 [ t ] [ 4 get instructions>> first ##load-integer? ] unit-test
-
-! Not fixed yet; and would need to change if value-numbering
-! subsumed copy-prop.
-! [ t ] [ 4 get instructions>> rest [ ##copy? ] all? ] unit-test
+[ 1 ] [ 4 get instructions>> [ ##load-integer? ] count ] unit-test
 
 ! Global optimization
 V{ T{ ##prologue } T{ ##branch } } 0 test-bb
index ef449ce4591208ce275eecec2121600347d238ff..0486058d37d6022ebee378395fccf9c410ebcf40 100644 (file)
@@ -23,7 +23,7 @@ IN: compiler.cfg.gvn
 
 GENERIC: simplify ( insn -- insn' )
 
-M: insn simplify dup rewrite [ simplify ] [ ] ?if ;
+M: insn simplify dup rewrite [ simplify ] [ dup >avail-insn-uses ] ?if ;
 M: array simplify [ simplify ] map ;
 M: ##copy simplify ;
 
@@ -96,7 +96,7 @@ M: ##copy gcse defs-available ;
     ] [ drop defs-available ] if ;
 
 : eliminate-redundancy ( insn -- insn' )
-    dup >expr exprs>vns get at
+    dup >expr exprs>vns get at >avail-vreg
     [ ?eliminate ] [ defs-available ] if* ;
 
 M: ##phi gcse
@@ -113,6 +113,7 @@ M: insn gcse
 
 : eliminate-common-subexpressions ( cfg -- )
     final-iteration? on
+    compute-congruence-classes
     dup compute-avail-sets
     [ gcse-step ] simple-optimization ;