]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler.cfg.gvn.comparisons: fix premature cfg modifications
authorAlex Vondrak <ajvondrak@csupomona.edu>
Sat, 18 Jun 2011 23:16:09 +0000 (16:16 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 12 Sep 2012 22:14:08 +0000 (15:14 -0700)
extra/compiler/cfg/gvn/comparisons/comparisons.factor
extra/compiler/cfg/gvn/gvn.factor
extra/compiler/cfg/gvn/rewrite/rewrite.factor

index 109a694b48d5edfe874158049574d64fa58da546..9437c83a4f34539d583e9149e11ec5ba828e89d8 100644 (file)
@@ -98,9 +98,10 @@ UNION: general-compare-insn scalar-compare-insn ##test-vector ;
     } cond ;
 
 : fold-branch ( ? -- insn )
-    drop
-    ! 0 1 ?
-    ! basic-block get [ nth 1vector ] change-successors drop
+    final-iteration? get [
+        0 1 ?
+        basic-block get [ nth 1vector ] change-successors drop
+    ] [ drop ] if
     \ ##branch new-insn ;
 
 : fold-compare-imm-branch ( insn -- insn/f )
@@ -257,10 +258,10 @@ M: ##compare-integer-imm rewrite
     [ src1>> vreg>insn [ src1>> ] [ src2>> ] bi ] [ cc>> ] bi ; inline
 
 : simplify-test ( insn -- insn )
-    dup (simplify-test) drop [ >>src1 ] [ >>src2 ] bi* ; inline
+    [ dst>> ] [ (simplify-test) ] [ temp>> ] tri \ ##test new-insn ; inline
 
 : simplify-test-branch ( insn -- insn )
-    dup (simplify-test) drop [ >>src1 ] [ >>src2 ] bi* ; inline
+    (simplify-test) \ ##test-branch new-insn ; inline
 
 : (simplify-test-imm) ( insn -- src1 src2 cc )
     [ src1>> vreg>insn [ src1>> ] [ src2>> ] bi ] [ cc>> ] bi ; inline
index bc63fd0f99203aee0aca05e2a5d10caa02541b27..56ea3023d2e86d05ba144506907bf6d711ea652b 100644 (file)
@@ -51,13 +51,14 @@ M: array process-instruction
 
 ! FIXME there's going to be trouble with certain rewrites that
 ! modify the cfg / instructions destructively; namely those in
-! comparisons.factor, alien.factor, and slots.factor
+! alien.factor and slots.factor
 
 : value-numbering-iteration ( cfg -- )
     clear-exprs
     [ value-numbering-step drop ] simple-analysis ;
 
 : identify-redundancies ( cfg -- )
+    final-iteration? off
     init-value-graph
     '[
         changed? off
@@ -66,6 +67,7 @@ M: array process-instruction
     ] loop ;
 
 : eliminate-redundancies ( cfg -- )
+    final-iteration? on
     clear-exprs
     [ value-numbering-step ] simple-optimization ;
 
index dbbfe86df21e8f7f21a8549f1ef2f5bd0303dd94..2d62bb6c194953404fe95c30b547445f317efa59 100644 (file)
@@ -11,6 +11,10 @@ GENERIC: rewrite ( insn -- insn/f )
 
 M: insn rewrite drop f ;
 
+! Boolean to track when it's safe to alter the CFG in a rewrite
+! method (i.e., after we've already iterated till fixpoint)
+SYMBOL: final-iteration?
+
 ! Utilities
 GENERIC: insn>integer ( insn -- n )