]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/compiler/cfg/gvn/avail/avail.factor
factor: trim using lists
[factor.git] / extra / compiler / cfg / gvn / avail / avail.factor
index 9c0b4ab2f048460bf10b1cc458ab1922bf5530ef..c72cbc51d75e905434371576dca86f8fe304c9cd 100644 (file)
@@ -1,26 +1,38 @@
 ! Copyright (C) 2011 Alex Vondrak.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs compiler.cfg
-compiler.cfg.dataflow-analysis compiler.cfg.def-use hashtables
-kernel namespaces sequences ;
+compiler.cfg.dataflow-analysis compiler.cfg.def-use
+compiler.cfg.gvn.graph compiler.cfg.renaming.functor
+compiler.utilities hashtables kernel namespaces sequences ;
 IN: compiler.cfg.gvn.avail
 
-! assoc mapping basic blocks to the set of value numbers that
-! are defined in the block
-SYMBOL: bbs>defns
-
-! : defined ( bb -- vns ) bbs>defns get at ;
-
 : defined ( bb -- vregs )
-    instructions>> [ defs-vregs ] map concat [ dup ] H{ } map>assoc ;
+    instructions>> [ defs-vregs ] map concat unique ;
+
+! This doesn't propagate across "kill blocks".  Not sure if
+! that's right, though I may as well assume as much.
 
 FORWARD-ANALYSIS: avail
 
-M: avail-analysis transfer-set drop defined assoc-union ;
+M: avail transfer-set drop defined assoc-union ;
+
+: available? ( vn -- ? ) basic-block get avail-in key? ;
+
+: best-vreg ( available-vregs -- vreg )
+    [ f ] [ infimum ] if-empty ;
+
+: >avail-vreg ( vreg -- vreg/f )
+    final-iteration? get [
+        congruence-class [ available? ] filter best-vreg
+    ] when ;
+
+: available-uses? ( insn -- ? )
+    uses-vregs [ >avail-vreg ] all? ;
+
+: with-available-uses? ( quot -- ? )
+    keep swap [ available-uses? ] [ drop f ] if ; inline
 
-: available? ( vn -- ? )
-    basic-block get avail-ins get at key? ;
+: make-available ( vreg -- )
+    basic-block get avail-ins get [ dupd clone ?set-at ] assocs:change-at ;
 
-: make-available ( insn -- insn )
-    dup dst>>
-    basic-block get avail-ins get [ dupd ?set-at ] change-at ;
+RENAMING: >avail [ ] [ dup >avail-vreg swap or ] [ ]