From 5197aca215a1be80d8f00cd458a32d7f684a8fa7 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 20 Aug 2009 18:15:41 -0500 Subject: [PATCH 1/3] compiler.cfg.dataflow-analysis: when intersecting sets, treat uninitialized sets as universal rather than empty; reduces number of stack instructions generated by 1% --- .../compiler/cfg/dataflow-analysis/dataflow-analysis.factor | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/basis/compiler/cfg/dataflow-analysis/dataflow-analysis.factor b/basis/compiler/cfg/dataflow-analysis/dataflow-analysis.factor index 275a4585b0..dde44fd15d 100644 --- a/basis/compiler/cfg/dataflow-analysis/dataflow-analysis.factor +++ b/basis/compiler/cfg/dataflow-analysis/dataflow-analysis.factor @@ -23,7 +23,11 @@ GENERIC# compute-in-set 2 ( bb out-sets dfa -- set ) M: kill-block compute-in-set 3drop f ; M:: basic-block compute-in-set ( bb out-sets dfa -- set ) - bb dfa predecessors [ out-sets at ] map bb dfa join-sets ; + ! Only consider initialized sets. + bb dfa predecessors + [ out-sets key? ] filter + [ out-sets at ] map + bb dfa join-sets ; :: update-in-set ( bb in-sets out-sets dfa -- ? ) bb out-sets dfa compute-in-set From 9ab8734441eb9849daf4c04ee5996258e2cf8d3a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 21 Aug 2009 18:48:34 -0500 Subject: [PATCH 2/3] cpu.ppc: work in progress --- basis/cpu/ppc/ppc.factor | 64 +++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/basis/cpu/ppc/ppc.factor b/basis/cpu/ppc/ppc.factor index dfcb68dfc1..eba2099399 100644 --- a/basis/cpu/ppc/ppc.factor +++ b/basis/cpu/ppc/ppc.factor @@ -89,11 +89,8 @@ HOOK: reserved-area-size os ( -- n ) : local@ ( n -- x ) reserved-area-size param-save-size + + ; inline -: spill-integer@ ( n -- offset ) - spill-integer-offset local@ ; - -: spill-float@ ( n -- offset ) - spill-float-offset local@ ; +: spill@ ( n -- offset ) + spill-offset local@ ; ! Some FP intrinsics need a temporary scratch area in the stack ! frame, 8 bytes in size. This is in the param-save area so it @@ -275,9 +272,11 @@ M:: ppc %float>integer ( dst src -- ) fp-scratch-reg 1 0 scratch@ STFD dst 1 4 scratch@ LWZ ; -M: ppc %copy ( dst src -- ) MR ; - -M: ppc %copy-float ( dst src -- ) FMR ; +M: ppc %copy ( dst src rep -- ) + { + { int-rep [ MR ] } + { double-float-rep [ FMR ] } + } case ; M: ppc %unbox-float ( dst src -- ) float-offset LFD ; @@ -478,11 +477,29 @@ M: ppc %compare-branch (%compare) %branch ; M: ppc %compare-imm-branch (%compare-imm) %branch ; M: ppc %compare-float-branch (%compare-float) %branch ; -M: ppc %spill-integer ( src n -- ) spill-integer@ 1 swap STW ; -M: ppc %reload-integer ( dst n -- ) spill-integer@ 1 swap LWZ ; +: load-from-frame ( dst n rep -- ) + { + { int-rep [ [ 1 ] dip LWZ ] } + { single-float-rep [ [ 1 ] dip LFS ] } + { double-float-rep [ [ 1 ] dip LFD ] } + { stack-params [ [ 0 1 ] dip LWZ [ 0 1 ] dip param@ STW ] } + } case ; -M: ppc %spill-float ( src n -- ) spill-float@ 1 swap STFD ; -M: ppc %reload-float ( dst n -- ) spill-float@ 1 swap LFD ; +: next-param@ ( n -- x ) param@ stack-frame get total-size>> + ; + +: store-to-frame ( src n rep -- ) + { + { int-rep [ [ 1 ] dip STW ] } + { single-float-rep [ [ 1 ] dip STFS ] } + { double-float-rep [ [ 1 ] dip STFD ] } + { stack-params [ [ [ 0 1 ] dip next-param@ LWZ 0 1 ] dip STW ] } + } case ; + +M: ppc %spill ( src n rep -- ) + [ spill@ ] dip store-to-frame ; + +M: ppc %reload ( dst n rep -- ) + [ spill@ ] dip load-from-frame ; M: ppc %loop-entry ; @@ -490,26 +507,11 @@ M: int-regs return-reg drop 3 ; M: int-regs param-regs drop { 3 4 5 6 7 8 9 10 } ; M: float-regs return-reg drop 1 ; -M: int-regs %save-param-reg drop 1 rot local@ STW ; -M: int-regs %load-param-reg drop 1 rot local@ LWZ ; +M:: ppc %save-param-reg ( stack reg rep -- ) + reg stack local@ rep store-to-frame ; -M: single-float-rep %save-param-reg drop 1 rot local@ STFS ; -M: single-float-rep %load-param-reg 1 rot local@ LFS ; - -M: double-float-rep %save-param-reg drop 1 rot local@ STFD ; -M: double-float-rep %load-param-reg 1 rot local@ LFD ; - -M: stack-params %load-param-reg ( stack reg rep -- ) - drop [ 0 1 rot local@ LWZ 0 1 ] dip param@ STW ; - -: next-param@ ( n -- x ) param@ stack-frame get total-size>> + ; - -M: stack-params %save-param-reg ( stack reg rep -- ) - #! Funky. Read the parameter from the caller's stack frame. - #! This word is used in callbacks - drop - [ 0 1 ] dip next-param@ LWZ - [ 0 1 ] dip local@ STW ; +M:: ppc %load-param-reg ( stack reg rep -- ) + reg stack local@ rep load-from-frame ; M: ppc %prepare-unbox ( -- ) ! First parameter is top of stack From 1961b4da16c319c4f7682ff65e2de32e2e654ca9 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 21 Aug 2009 20:15:19 -0500 Subject: [PATCH 3/3] next-fastcall-param word was not being called; on x86 its equivalent to inc but on ppc there is more logic, this fixes FFI on PowerPC --- basis/compiler/codegen/codegen.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basis/compiler/codegen/codegen.factor b/basis/compiler/codegen/codegen.factor index d1a09394cd..d1b5558beb 100755 --- a/basis/compiler/codegen/codegen.factor +++ b/basis/compiler/codegen/codegen.factor @@ -267,7 +267,7 @@ M: ##alien-global generate-insn %alien-global ; ! ##alien-invoke -GENERIC: next-fastcall-param ( reg-class -- ) +GENERIC: next-fastcall-param ( rep -- ) : ?dummy-stack-params ( rep -- ) dummy-stack-params? [ rep-size cell align stack-params +@ ] [ drop ] if ; @@ -300,7 +300,7 @@ M: reg-class reg-class-full? stack-params dup ; : alloc-fastcall-param ( rep -- n reg-class rep ) - [ reg-class-of [ get ] [ inc ] [ ] tri ] keep ; + [ [ reg-class-of get ] [ reg-class-of ] [ next-fastcall-param ] tri ] keep ; : alloc-parameter ( parameter -- reg rep ) c-type-rep dup reg-class-of reg-class-full?