]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.cfg: more silly optimizations
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 14 May 2010 22:18:29 +0000 (18:18 -0400)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 14 May 2010 22:37:09 +0000 (18:37 -0400)
basis/compiler/cfg/dce/dce.factor
basis/compiler/cfg/gc-checks/gc-checks.factor
basis/compiler/cfg/representations/rewrite/rewrite.factor
basis/compiler/cfg/rpo/rpo.factor
basis/compiler/cfg/ssa/construction/construction.factor
basis/compiler/cfg/ssa/destruction/destruction.factor

index b4fcd018f491849bf7140e3c5453a72f02fef7f5..c6b3819fb06d1aeae4e872387336a52a1892838c 100644 (file)
@@ -49,9 +49,11 @@ M: ##write-barrier-imm build-liveness-graph
 M: ##allot build-liveness-graph
     [ dst>> allocations get adjoin ] [ call-next-method ] bi ;
 
-M: insn build-liveness-graph
+M: vreg-insn build-liveness-graph
     dup defs-vreg dup [ add-edges ] [ 2drop ] if ;
 
+M: insn build-liveness-graph drop ;
+
 GENERIC: compute-live-vregs ( insn -- )
 
 : (record-live) ( vregs -- )
@@ -87,9 +89,11 @@ M: ##fixnum-sub compute-live-vregs record-live ;
 
 M: ##fixnum-mul compute-live-vregs record-live ;
 
-M: insn compute-live-vregs
+M: vreg-insn compute-live-vregs
     dup defs-vreg [ drop ] [ record-live ] if ;
 
+M: insn compute-live-vregs drop ;
+
 GENERIC: live-insn? ( insn -- ? )
 
 M: ##set-slot live-insn? obj>> live-vreg? ;
@@ -106,7 +110,9 @@ M: ##fixnum-sub live-insn? drop t ;
 
 M: ##fixnum-mul live-insn? drop t ;
 
-M: insn live-insn? defs-vreg [ live-vreg? ] [ t ] if* ;
+M: vreg-insn live-insn? defs-vreg [ live-vreg? ] [ t ] if* ;
+
+M: insn live-insn? defs-vreg drop t ;
 
 : eliminate-dead-code ( cfg -- cfg' )
     ! Even though we don't use predecessors directly, we depend
@@ -116,7 +122,7 @@ M: insn live-insn? defs-vreg [ live-vreg? ] [ t ] if* ;
 
     init-dead-code
     dup
-    [ [ instructions>> [ build-liveness-graph ] each ] each-basic-block ]
-    [ [ instructions>> [ compute-live-vregs ] each ] each-basic-block ]
-    [ [ instructions>> [ live-insn? ] filter! drop ] each-basic-block ]
+    [ [ [ build-liveness-graph ] each ] simple-analysis ]
+    [ [ [ compute-live-vregs ] each ] simple-analysis ]
+    [ [ [ live-insn? ] filter! ] simple-optimization ]
     tri ;
index 0ebda513a2366f5eaef2432e6312cb4a00bb8200..255e5476e684992d433e6ef530d12f204422fb0d 100644 (file)
@@ -22,7 +22,8 @@ IN: compiler.cfg.gc-checks
 ! can contain tagged pointers.
 
 : insert-gc-check? ( bb -- ? )
-    instructions>> [ ##allocation? ] any? ;
+    dup kill-block?>>
+    [ drop f ] [ instructions>> [ ##allocation? ] any? ] if ;
 
 : blocks-with-gc ( cfg -- bbs )
     post-order [ insert-gc-check? ] filter ;
index 06444c66f84134d3754e4bddbecbce83f9f7cc0d..b997c35e2ec87676ae8cdb9f628af6b645bb11d9 100644 (file)
@@ -89,15 +89,13 @@ M: ##copy conversions-for-insn , ;
 
 M: insn conversions-for-insn , ;
 
-: conversions-for-block ( bb -- )
+: conversions-for-block ( insns -- insns )
     [
-        [
-            alternatives get clear-assoc
-            [ conversions-for-insn ] each
-        ] V{ } make
-    ] change-instructions drop ;
+        alternatives get clear-assoc
+        [ conversions-for-insn ] each
+    ] V{ } make ;
 
 : insert-conversions ( cfg -- )
     H{ } clone alternatives set
     V{ } clone renaming-set set
-    [ conversions-for-block ] each-basic-block ;
+    [ conversions-for-block ] simple-optimization ;
index 6d449540f2a082b53a9dba9841be600e4f8e9a31..711657e8e589d1196d248c8ba55db6f2d18bea3e 100644 (file)
@@ -44,5 +44,13 @@ SYMBOL: visited
 : simple-optimization ( ... cfg quot: ( ... insns -- ... insns' ) -- ... )
     '[ _ optimize-basic-block ] each-basic-block ; inline
 
+: analyze-basic-block ( bb quot -- )
+    over kill-block?>> [ 2drop ] [
+        [ dup basic-block set instructions>> ] dip call
+    ] if ; inline
+
+: simple-analysis ( ... cfg quot: ( ... insns -- ... ) -- ... )
+    '[ _ analyze-basic-block ] each-basic-block ; inline
+
 : needs-post-order ( cfg -- cfg' )
     dup post-order drop ;
index 03c85c1f5e18c79220826523ea987bff46135fe4..526587dabecb71013b3218850b5966979c482fba 100644 (file)
@@ -1,4 +1,4 @@
-! Copyright (C) 2009 Slava Pestov.
+! Copyright (C) 2009, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: namespaces kernel accessors sequences fry assocs
 sets math combinators
@@ -42,10 +42,9 @@ SYMBOL: defs-multi
     H{ } clone defs set
     H{ } clone defs-multi set
     [
-        dup instructions>> [
-            compute-insn-defs
-        ] with each
-    ] each-basic-block ;
+        [ basic-block get ] dip
+        [ compute-insn-defs ] with each
+    ] simple-analysis ;
 
 ! Maps basic blocks to sequences of vregs
 SYMBOL: inserting-phi-nodes
@@ -88,7 +87,9 @@ RENAMING: ssa-rename [ gen-name ] [ top-name ] [ ]
 
 GENERIC: rename-insn ( insn -- )
 
-M: insn rename-insn
+M: insn rename-insn drop ;
+
+M: vreg-insn rename-insn
     [ ssa-rename-insn-uses ]
     [ ssa-rename-insn-defs ]
     bi ;
index ede012eb2fe88b485c16952e5c584efde0bc7332..b4cca42ad630266fce6f8e4e73463603f0e73d46 100644 (file)
@@ -76,7 +76,9 @@ GENERIC: prepare-insn ( insn -- )
 
 : try-to-coalesce ( dst src -- ) 2array copies get push ;
 
-M: insn prepare-insn
+M: insn prepare-insn drop ;
+
+M: vreg-insn prepare-insn
     [ temp-vregs [ leader-map get conjoin ] each ]
     [
         [ defs-vreg ] [ uses-vregs ] bi