From 7711aff1a597d4dcc9d714a27b656c3ee6d0ee01 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 4 Sep 2005 21:07:59 +0000 Subject: [PATCH] tweaking stack shuffle compilation --- library/bootstrap/boot-stage1.factor | 2 + library/compiler/compiler.factor | 39 ++++--------- library/compiler/intrinsics.factor | 76 ++++++------------------- library/compiler/linearizer.factor | 9 +-- library/compiler/ppc/stack.factor | 3 - library/compiler/vops.factor | 11 ++-- library/compiler/x86/stack.factor | 50 ++++++---------- library/inference/dataflow.factor | 17 ++++-- library/inference/kill-literals.factor | 47 +-------------- library/inference/known-words.factor | 36 ------------ library/inference/optimizer.factor | 6 +- library/inference/print-dataflow.factor | 20 +++---- library/inference/words.factor | 6 -- library/test/compiler/optimizer.factor | 5 -- library/test/compiler/stack.factor | 18 ++++++ library/tools/debugger.factor | 2 + native/factor.h | 7 ++- 17 files changed, 101 insertions(+), 253 deletions(-) diff --git a/library/bootstrap/boot-stage1.factor b/library/bootstrap/boot-stage1.factor index c82cdb2034..1ba7a1ed02 100644 --- a/library/bootstrap/boot-stage1.factor +++ b/library/bootstrap/boot-stage1.factor @@ -124,6 +124,7 @@ sequences io vectors words ; "/library/inference/optimizer.factor" "/library/inference/inline-methods.factor" "/library/inference/known-words.factor" + "/library/inference/stack.factor" "/library/inference/call-optimizers.factor" "/library/inference/print-dataflow.factor" @@ -132,6 +133,7 @@ sequences io vectors words ; "/library/compiler/xt.factor" "/library/compiler/vops.factor" "/library/compiler/linearizer.factor" + "/library/compiler/stack.factor" "/library/compiler/intrinsics.factor" "/library/compiler/simplifier.factor" "/library/compiler/generator.factor" diff --git a/library/compiler/compiler.factor b/library/compiler/compiler.factor index 989a5e6788..45c927fd93 100644 --- a/library/compiler/compiler.factor +++ b/library/compiler/compiler.factor @@ -6,21 +6,14 @@ kernel lists math namespaces prettyprint sequences words ; : supported-cpu? ( -- ? ) cpu "unknown" = not ; -: check-architecture ( -- ) - supported-cpu? [ - "Unsupported CPU; compiler disabled" throw - ] unless ; - -: compiling ( word -- word parameter ) - check-architecture "Compiling " write dup . dup word-def ; - GENERIC: (compile) ( word -- ) M: word (compile) drop ; M: compound (compile) ( word -- ) #! Should be called inside the with-compiler scope. - compiling dataflow optimize linearize simplify generate ; + "Compiling " write dup . + dup word-def dataflow optimize linearize simplify generate ; : precompile ( word -- ) #! Print linear IR of word. @@ -40,30 +33,18 @@ M: compound (compile) ( word -- ) #! Compile the most recently defined word. "compile" get [ word compile ] when ; parsing -: cannot-compile ( word error -- ) - "Cannot compile " write swap . print-error ; - : try-compile ( word -- ) - [ compile ] [ [ cannot-compile ] when* ] catch ; + [ compile ] [ error. ] catch ; : compile-all ( -- ) [ try-compile ] each-word ; : recompile ( word -- ) dup update-xt compile ; -: compile-1 ( quot -- word ) - #! Compute a quotation into an uninterned word, for testing - #! purposes. - gensym [ swap define-compound ] keep dup compile execute ; - -\ dataflow profile -\ optimize profile -\ linearize profile -\ simplify profile -\ generate profile -\ kill-node profile -\ partial-eval profile -\ inline-method profile -\ apply-identities profile -\ subst-values profile -\ split-branch profile +: compile-1 ( quot -- ) + #! Compute and call a quotation. + "compile" get [ + gensym [ swap define-compound ] keep dup compile execute + ] [ + call + ] ifte ; diff --git a/library/compiler/intrinsics.factor b/library/compiler/intrinsics.factor index cfeb6f8f92..f480fbe7f0 100644 --- a/library/compiler/intrinsics.factor +++ b/library/compiler/intrinsics.factor @@ -10,50 +10,6 @@ sequences vectors words ; #! Can fixnum operations take immediate operands? cpu "x86" = ; -\ dup [ - drop - in-1 - 1 %inc-d , - out-1 -] "intrinsic" set-word-prop - -\ swap [ - drop - in-2 - 0 0 %replace-d , - 1 1 %replace-d , -] "intrinsic" set-word-prop - -\ over [ - drop - 0 1 %peek-d , - 1 %inc-d , - out-1 -] "intrinsic" set-word-prop - -\ pick [ - drop - 0 2 %peek-d , - 1 %inc-d , - out-1 -] "intrinsic" set-word-prop - -\ >r [ - drop - in-1 - 1 %inc-r , - 1 %dec-d , - 0 0 %replace-r , -] "intrinsic" set-word-prop - -\ r> [ - drop - 0 0 %peek-r , - 1 %inc-d , - 1 %dec-r , - out-1 -] "intrinsic" set-word-prop - : node-peek ( node -- value ) node-in-d peek ; : type-tag ( type -- tag ) @@ -80,13 +36,13 @@ sequences vectors words ; \ slot [ dup slot@ [ - 1 %dec-d , + -1 %inc-d, in-1 0 swap slot@ %fast-slot , ] [ drop in-2 - 1 %dec-d , + -1 %inc-d, 0 %untag , 1 0 %slot , ] ifte out-1 @@ -94,14 +50,14 @@ sequences vectors words ; \ set-slot [ dup slot@ [ - 1 %dec-d , + -1 %inc-d, in-2 - 2 %dec-d , + -2 %inc-d, slot@ >r 0 1 r> %fast-set-slot , ] [ drop in-3 - 3 %dec-d , + -3 %inc-d, 1 %untag , 0 1 2 %set-slot , ] ifte @@ -125,17 +81,17 @@ sequences vectors words ; ] "intrinsic" set-word-prop \ getenv [ - 1 %dec-d , + -1 %inc-d, node-peek literal-value 0 swap %getenv , - 1 %inc-d , + 1 %inc-d, out-1 ] "intrinsic" set-word-prop \ setenv [ - 1 %dec-d , + -1 %inc-d, in-1 node-peek literal-value 0 swap %setenv , - 1 %dec-d , + -1 %inc-d, ] "intrinsic" set-word-prop : value/vreg-list ( in -- list ) @@ -149,7 +105,7 @@ sequences vectors words ; : load-inputs ( node -- in ) dup node-in-d values>vregs - [ length swap node-out-d length - %dec-d , ] keep ; + [ >r node-out-d length r> length - %inc-d, ] keep ; : binary-op-reg ( node op -- ) >r load-inputs first2 swap dup r> execute , @@ -159,7 +115,7 @@ sequences vectors words ; dup literal? [ literal-value immediate? ] [ drop f ] ifte ; : binary-op-imm ( imm op -- ) - 1 %dec-d , in-1 + -1 %inc-d, in-1 >r 0 dup r> execute , 0 0 %replace-d , ; inline @@ -192,7 +148,7 @@ sequences vectors words ; ] each : fast-fixnum* ( n -- ) - 1 %dec-d , + -1 %inc-d, in-1 log2 0 0 %fixnum<< , 0 0 %replace-d , ; @@ -218,7 +174,7 @@ sequences vectors words ; ! be EDX there. drop in-2 - 1 %dec-d , + -1 %inc-d, 1 0 2 %fixnum-mod , 2 0 %replace-d , ] "intrinsic" set-word-prop @@ -250,7 +206,7 @@ sequences vectors words ; : slow-shift ( -- ) \ fixnum-shift %call , ; : negative-shift ( n -- ) - 1 %dec-d , + -1 %inc-d, in-1 dup cell -8 * <= [ drop 0 2 %fixnum-sgn , @@ -262,7 +218,7 @@ sequences vectors words ; : positive-shift ( n -- ) dup cell 8 * tag-bits - <= [ - 1 %dec-d , + -1 %inc-d, in-1 0 0 %fixnum<< , out-1 @@ -272,7 +228,7 @@ sequences vectors words ; : fast-shift ( n -- ) dup 0 = [ - 1 %dec-d , + -1 %inc-d, drop ] [ dup 0 < [ diff --git a/library/compiler/linearizer.factor b/library/compiler/linearizer.factor index 69403c4b00..8f485b2898 100644 --- a/library/compiler/linearizer.factor +++ b/library/compiler/linearizer.factor @@ -56,14 +56,11 @@ M: literal load-value ( vreg n value -- ) : push-1 ( value -- ) 0 swap push-literal ; M: #push linearize-node* ( node -- ) - node-out-d dup length dup %inc-d , + node-out-d dup length dup %inc-d, 1 - swap [ push-1 0 over %replace-d , ] each drop ; -M: #drop linearize-node* ( node -- ) - node-in-d length %dec-d , ; - : ifte-head ( label -- ) - in-1 1 %dec-d , 0 %jump-t , ; + in-1 -1 %inc-d, 0 %jump-t , ; M: #ifte linearize-node* ( node -- ) node-children first2 @@ -76,7 +73,7 @@ M: #ifte linearize-node* ( node -- ) #! Output the jump table insn and return a list of #! label/branch pairs. in-1 - 1 %dec-d , + -1 %inc-d, 0 %untag-fixnum , 0 %dispatch , [