From d65a7480428ce618cc9d1f8461e0441c31bbc27f Mon Sep 17 00:00:00 2001 From: slava Date: Mon, 3 Apr 2006 07:22:33 +0000 Subject: [PATCH] Phasing out basic block optimizer; moved %inc-d/r merge optimization to templates --- library/alien/alien-callback.factor | 2 +- library/alien/alien-invoke.factor | 2 +- library/compiler/intrinsics.factor | 11 +++++--- library/compiler/linearizer.factor | 42 +++++++++++++++-------------- library/compiler/templates.factor | 17 +++++------- library/compiler/vops.factor | 30 --------------------- 6 files changed, 39 insertions(+), 65 deletions(-) diff --git a/library/alien/alien-callback.factor b/library/alien/alien-callback.factor index 41c2fe8878..fef4d10f6c 100644 --- a/library/alien/alien-callback.factor +++ b/library/alien/alien-callback.factor @@ -60,7 +60,7 @@ M: alien-callback-error summary ( error -- ) ] make-linear ; M: alien-callback linearize* ( node -- ) - compile-gc linearize-callback iterate-next ; + end-basic-block compile-gc linearize-callback iterate-next ; M: alien-callback stack-reserve* alien-callback-parameters stack-space ; diff --git a/library/alien/alien-invoke.factor b/library/alien/alien-invoke.factor index 5b5fa66851..853939cc47 100644 --- a/library/alien/alien-invoke.factor +++ b/library/alien/alien-invoke.factor @@ -64,7 +64,7 @@ M: alien-invoke-error summary ( error -- ) ] if ; M: alien-invoke linearize* ( node -- ) - compile-gc + end-basic-block compile-gc dup alien-invoke-parameters objects>registers dup alien-invoke-dlsym %alien-invoke , dup linearize-cleanup box-return diff --git a/library/compiler/intrinsics.factor b/library/compiler/intrinsics.factor index ea06bf04aa..80180fabb2 100644 --- a/library/compiler/intrinsics.factor +++ b/library/compiler/intrinsics.factor @@ -51,6 +51,7 @@ namespaces sequences words ; "val" get "obj" get "slot" get %set-slot , ] with-template ] if + end-basic-block T{ vreg f 1 } %write-barrier , ] "intrinsic" set-word-prop @@ -67,7 +68,8 @@ namespaces sequences words ; ] "intrinsic" set-word-prop \ type [ - { { 0 "in" } } { "in" } [ "in" get %type , ] with-template + { { 0 "in" } } { "in" } + [ end-basic-block "in" get %type , ] with-template ] "intrinsic" set-word-prop \ tag [ @@ -97,7 +99,7 @@ namespaces sequences words ; : (binary-op) ( node in -- ) { "x" } [ - >r "y" get "x" get dup r> execute , + end-basic-block >r "y" get "x" get dup r> execute , ] with-template ; inline : binary-op ( node op -- ) @@ -118,7 +120,7 @@ namespaces sequences words ; : binary-jump ( node label op -- ) rot dup binary-in { } [ - >r >r "y" get "x" get r> r> execute , + end-basic-block >r >r "y" get "x" get r> r> execute , ] with-template ; inline { @@ -140,6 +142,7 @@ namespaces sequences words ; ! hard-coded to put its output in vreg 2, which happends to ! be EDX there. { { 0 "x" } { 1 "y" } } { "out" } [ + end-basic-block T{ vreg f 2 } "out" set "y" get "x" get "out" get %fixnum-mod , ] with-template @@ -148,6 +151,7 @@ namespaces sequences words ; \ fixnum/mod [ ! See the remark on fixnum-mod for vreg usage { { 0 "x" } { 1 "y" } } { "quo" "rem" } [ + end-basic-block T{ vreg f 0 } "quo" set T{ vreg f 2 } "rem" set "y" get "x" get 2array @@ -191,6 +195,7 @@ namespaces sequences words ; ] if ; \ fixnum-shift [ + end-basic-block dup literal-immediate? [ [ node-in-d peek value-literal ] keep fast-shift ] [ diff --git a/library/compiler/linearizer.factor b/library/compiler/linearizer.factor index 07342de807..3a8ff3d7a5 100644 --- a/library/compiler/linearizer.factor +++ b/library/compiler/linearizer.factor @@ -27,7 +27,7 @@ UNION: #terminal POSTPONE: f #return #values #terminal-merge ; GENERIC: linearize* ( node -- next ) : linearize-child ( node -- ) - [ node@ linearize* ] iterate-nodes ; + [ node@ linearize* ] iterate-nodes end-basic-block ; ! A map from words to linear IR. SYMBOL: linearized @@ -44,9 +44,7 @@ SYMBOL: renamed-labels : linearize-1 ( word node -- ) swap [ - dup stack-reserve %prologue , - linearize-child - end-basic-block + dup stack-reserve %prologue , linearize-child ] make-linear ; : init-linearizer ( -- ) @@ -61,6 +59,7 @@ SYMBOL: renamed-labels M: node linearize* ( node -- next ) drop iterate-next ; : linearize-call ( label -- next ) + end-basic-block tail-call? [ %jump , f ] [ %call , iterate-next ] if ; : rename-label ( label -- label ) @@ -86,9 +85,10 @@ M: #label linearize* ( node -- next ) [ node-param "if-intrinsic" word-prop ] [ drop f ] if ; : linearize-if ( node label -- next ) -