]> gitweb.factorcode.org Git - factor.git/commitdiff
Split off local-optimization combinator into compiler.cfg.local, factor out CFG ...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 31 May 2009 17:20:46 +0000 (12:20 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 31 May 2009 17:20:46 +0000 (12:20 -0500)
19 files changed:
basis/compiler/cfg/alias-analysis/alias-analysis.factor
basis/compiler/cfg/checker/checker.factor
basis/compiler/cfg/debugger/debugger.factor
basis/compiler/cfg/def-use/def-use.factor
basis/compiler/cfg/gc-checks/authors.txt [new file with mode: 0644]
basis/compiler/cfg/gc-checks/gc-checks.factor [new file with mode: 0644]
basis/compiler/cfg/height/height.factor
basis/compiler/cfg/linearization/linearization.factor
basis/compiler/cfg/liveness/liveness.factor
basis/compiler/cfg/local/authors.txt [new file with mode: 0644]
basis/compiler/cfg/local/local.factor [new file with mode: 0644]
basis/compiler/cfg/mr/authors.txt [new file with mode: 0644]
basis/compiler/cfg/mr/mr.factor [new file with mode: 0644]
basis/compiler/cfg/rpo/rpo.factor
basis/compiler/cfg/stack-analysis/stack-analysis-tests.factor
basis/compiler/cfg/stack-analysis/stack-analysis.factor
basis/compiler/cfg/value-numbering/value-numbering.factor
basis/compiler/cfg/write-barrier/write-barrier.factor
basis/compiler/compiler.factor

index 384fd65c1a612db35fc3075d9689b2e3a86ca9c3..2385a4c65a0f40da8c868139f781c79d885360bf 100644 (file)
@@ -4,7 +4,7 @@ USING: kernel math namespaces assocs hashtables sequences arrays
 accessors vectors combinators sets classes compiler.cfg
 compiler.cfg.registers compiler.cfg.instructions
 compiler.cfg.copy-prop compiler.cfg.rpo
-compiler.cfg.liveness ;
+compiler.cfg.liveness compiler.cfg.local ;
 IN: compiler.cfg.alias-analysis
 
 ! We try to eliminate redundant slot operations using some simple heuristics.
index bf5adc2d55bf52f6075b1060935b16a1ab044901..b0a279c11b94ba98e54709d93586f2ff47780d2f 100644 (file)
@@ -54,5 +54,5 @@ ERROR: undefined-values uses defs ;
     compute-liveness
     [ entry>> live-in assoc-empty? [ bad-live-in ] unless ]
     [ [ check-basic-block ] each-basic-block ]
-    [ build-mr check-mr ]
+    [ flatten-cfg check-mr ]
     tri ;
index 5c106bfaee13ce61b2b5aed1e951f310706fee8f..cb569377589cdba3ca8101715078ccc017bf5c93 100644 (file)
@@ -7,7 +7,8 @@ parser compiler.tree.builder compiler.tree.optimizer
 compiler.cfg.builder compiler.cfg.linearization
 compiler.cfg.registers compiler.cfg.stack-frame
 compiler.cfg.linear-scan compiler.cfg.two-operand
-compiler.cfg.optimizer ;
+compiler.cfg.liveness compiler.cfg.optimizer
+compiler.cfg.mr ;
 IN: compiler.cfg.debugger
 
 GENERIC: test-cfg ( quot -- cfgs )
@@ -18,20 +19,14 @@ M: callable test-cfg
 M: word test-cfg
     [ build-tree optimize-tree ] keep build-cfg ;
 
-SYMBOL: allocate-registers?
-
 : test-mr ( quot -- mrs )
     test-cfg [
         optimize-cfg
-        convert-two-operand
-        allocate-registers? get [ linear-scan ] when
         build-mr
-        allocate-registers? get [ build-stack-frame ] when
     ] map ;
 
 : insn. ( insn -- )
-    tuple>array allocate-registers? get [ but-last ] unless
-    [ pprint bl ] each nl ;
+    tuple>array [ pprint bl ] each nl ;
 
 : mr. ( mrs -- )
     [
index 17e49f59a80aba0e04ffdfb00f2dcb627f34d9cb..28351ca7b2472d9f3a88bb9a78b3ba44f987ca79 100644 (file)
@@ -54,6 +54,7 @@ M: ##phi uses-vregs inputs>> ;
 M: _conditional-branch uses-vregs [ src1>> ] [ src2>> ] bi 2array ;
 M: _compare-imm-branch uses-vregs src1>> 1array ;
 M: _dispatch uses-vregs src>> 1array ;
+M: _gc uses-vregs live-in>> ;
 M: insn uses-vregs drop f ;
 
 ! Instructions that use vregs
@@ -67,4 +68,5 @@ UNION: vreg-insn
 ##compare-imm-branch
 _conditional-branch
 _compare-imm-branch
-_dispatch ;
+_dispatch
+_gc ;
diff --git a/basis/compiler/cfg/gc-checks/authors.txt b/basis/compiler/cfg/gc-checks/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/compiler/cfg/gc-checks/gc-checks.factor b/basis/compiler/cfg/gc-checks/gc-checks.factor
new file mode 100644 (file)
index 0000000..7a47da0
--- /dev/null
@@ -0,0 +1,22 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors kernel sequences assocs
+cpu.architecture compiler.cfg.rpo
+compiler.cfg.liveness compiler.cfg.instructions ;
+IN: compiler.cfg.gc-checks
+
+: gc? ( bb -- ? )
+    instructions>> [ ##allocation? ] any? ;
+
+: object-pointer-regs ( basic-block -- vregs )
+    live-in keys [ reg-class>> int-regs eq? ] filter ;
+
+: insert-gc-check ( basic-block -- )
+    dup gc? [
+        dup
+        [ swap object-pointer-regs \ _gc new-insn suffix ]
+        change-instructions drop
+    ] [ drop ] if ;
+
+: insert-gc-checks ( cfg -- cfg' )
+    dup [ insert-gc-check ] each-basic-block ;
\ No newline at end of file
index b91120ccfd86a88e9218fa4a97f6aaff648b72c2..14a0a547152f7fa0e5012ca2cc7f1ee776f658a6 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors math namespaces sequences kernel fry
 compiler.cfg compiler.cfg.registers compiler.cfg.instructions
-compiler.cfg.liveness ;
+compiler.cfg.liveness compiler.cfg.local ;
 IN: compiler.cfg.height
 
 ! Combine multiple stack height changes into one at the
index 5ad8be29533411370d2a4e5d55dd37bef6acbc5a..2e09e493db84e8a361cc0649fa9305e4eb84d304 100755 (executable)
@@ -12,20 +12,10 @@ IN: compiler.cfg.linearization
 ! Convert CFG IR to machine IR.
 GENERIC: linearize-insn ( basic-block insn -- )
 
-: linearize-insns ( bb insns -- )
-    dup instructions>> [ linearize-insn ] with each ;
-
-: gc? ( bb -- ? )
-    instructions>> [ ##allocation? ] any? ;
-
-: object-pointer-regs ( basic-block -- vregs )
-    live-in keys [ reg-class>> int-regs eq? ] filter ;
-
 : linearize-basic-block ( bb -- )
     [ number>> _label ]
-    [ dup gc? [ object-pointer-regs _gc ] [ drop ] if ]
-    [ linearize-insns ]
-    tri ;
+    [ dup instructions>> [ linearize-insn ] with each ]
+    bi ;
 
 M: insn linearize-insn , drop ;
 
@@ -85,6 +75,6 @@ M: ##dispatch linearize-insn
         bi
     ] { } make ;
 
-: build-mr ( cfg -- mr )
+: flatten-cfg ( cfg -- mr )
     [ linearize-basic-blocks ] [ word>> ] [ label>> ] tri
     <mr> ;
index 72609cf4d97507b9b8b5286281001a14c326b281..6c40bb37821bbfea213504b7f72c102f7dafd405 100644 (file)
@@ -76,6 +76,3 @@ SYMBOL: work-list
     H{ } clone live-outs set
     dup post-order add-to-work-list
     work-list get [ liveness-step ] slurp-deque ;
-
-: local-optimization ( cfg init-quot: ( live-in -- ) insn-quot: ( insns -- insns' ) -- cfg' )
-    [ dup ] 2dip '[ _ _ optimize-basic-block ] each-basic-block ;
\ No newline at end of file
diff --git a/basis/compiler/cfg/local/authors.txt b/basis/compiler/cfg/local/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/compiler/cfg/local/local.factor b/basis/compiler/cfg/local/local.factor
new file mode 100644 (file)
index 0000000..bf336a8
--- /dev/null
@@ -0,0 +1,10 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: fry accessors kernel assocs compiler.cfg.liveness compiler.cfg.rpo ;
+IN: compiler.cfg.local
+
+: optimize-basic-block ( bb init-quot insn-quot -- )
+    [ '[ live-in keys @ ] ] [ '[ _ change-instructions drop ] ] bi* bi ; inline
+
+: local-optimization ( cfg init-quot: ( live-in -- ) insn-quot: ( insns -- insns' ) -- cfg' )
+    [ dup ] 2dip '[ _ _ optimize-basic-block ] each-basic-block ;
diff --git a/basis/compiler/cfg/mr/authors.txt b/basis/compiler/cfg/mr/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/compiler/cfg/mr/mr.factor b/basis/compiler/cfg/mr/mr.factor
new file mode 100644 (file)
index 0000000..49f7c79
--- /dev/null
@@ -0,0 +1,14 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: compiler.cfg.linearization compiler.cfg.two-operand
+compiler.cfg.liveness compiler.cfg.gc-checks compiler.cfg.linear-scan
+compiler.cfg.stack-frame compiler.cfg.rpo ;
+IN: compiler.cfg.mr
+
+: build-mr ( cfg -- mr )
+    convert-two-operand
+    compute-liveness
+    insert-gc-checks
+    linear-scan
+    flatten-cfg
+    build-stack-frame ;
\ No newline at end of file
index d01f5ee864bdb3eb90a6025eac3174578c833584..c6ea2ee8b19b2b61232e3e60dabbd7599c0f36c0 100644 (file)
@@ -34,6 +34,3 @@ SYMBOL: visited
 
 : each-basic-block ( cfg quot -- )
     [ reverse-post-order ] dip each ; inline
-
-: optimize-basic-block ( bb init-quot insn-quot -- )
-    [ '[ live-in keys @ ] ] [ '[ _ change-instructions drop ] ] bi* bi ; inline
index bd0e539173c7671912d7ab0480c1aadaf4700675..383bd2e637da8a876c9645221b60ea6d9c6399ac 100644 (file)
@@ -31,7 +31,7 @@ IN: compiler.cfg.stack-analysis.tests
     dup check-for-redundant-ops ;
 
 : linearize ( cfg -- mr )
-    build-mr instructions>> ;
+    flatten-cfg instructions>> ;
 
 [ ] [ [ ] test-stack-analysis drop ] unit-test
 
index dfc99883c4bddad1bf33d5b176575e7c70761add..c1ed2615c3a9db257c65fd3a58e7a4706453bce7 100644 (file)
@@ -98,9 +98,13 @@ UNION: sync-if-back-edge
     ##compare-imm-branch
     ##dispatch ;
 
+SYMBOL: local-only?
+
+t local-only? set-global
+
 M: sync-if-back-edge visit
     basic-block get [ successors>> ] [ number>> ] bi
-    '[ number>> _ < ] any?
+    '[ number>> _ < local-only? get or ] any?
     [ sync-state ] when
     , ;
 
index cc62c0f0c18c5e31e72acc6b393ed7d192b72fff..9f5473c62ff461cf76a3c2c7e8dc98312f94a2ae 100644 (file)
@@ -2,6 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: namespaces assocs biassocs classes kernel math accessors
 sorting sets sequences
+compiler.cfg.local
 compiler.cfg.liveness
 compiler.cfg.value-numbering.graph
 compiler.cfg.value-numbering.expressions
index 52d5170138bf61c03d02daf10bd5ee2e5b3f88d1..b260b0464e4bbe4e0f0f6401af451c7ec498a3bf 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel accessors namespaces assocs sets sequences locals
 compiler.cfg compiler.cfg.instructions compiler.cfg.copy-prop
-compiler.cfg.liveness ;
+compiler.cfg.liveness compiler.cfg.local ;
 IN: compiler.cfg.write-barrier
 
 ! Eliminate redundant write barrier hits.
index ae58c3bd3e42d7474482a821877d9a31c9be3292..eee00bfccb0ecc1388473d92384f603da2a51533 100644 (file)
@@ -3,13 +3,20 @@
 USING: accessors kernel namespaces arrays sequences io words fry
 continuations vocabs assocs dlists definitions math graphs generic
 generic.single combinators deques search-deques macros
-source-files.errors stack-checker stack-checker.state
-stack-checker.inlining stack-checker.errors combinators.short-circuit
-compiler.errors compiler.units compiler.tree.builder
-compiler.tree.optimizer compiler.cfg.builder compiler.cfg.optimizer
-compiler.cfg.linearization compiler.cfg.two-operand
-compiler.cfg.linear-scan compiler.cfg.stack-frame compiler.cfg.rpo
-compiler.codegen compiler.utilities ;
+source-files.errors combinators.short-circuit
+
+stack-checker stack-checker.state stack-checker.inlining stack-checker.errors
+
+compiler.errors compiler.units compiler.utilities
+
+compiler.tree.builder
+compiler.tree.optimizer
+
+compiler.cfg.builder
+compiler.cfg.optimizer
+compiler.cfg.mr
+
+compiler.codegen ;
 IN: compiler
 
 SYMBOL: compile-queue
@@ -146,10 +153,7 @@ t compile-dependencies? set-global
 : backend ( nodes word -- )
     build-cfg [
         optimize-cfg
-        convert-two-operand
-        linear-scan
         build-mr
-        build-stack-frame
         generate
         save-asm
     ] each ;