From f2c8f2824a364d6e547e8303591c4e1985dfd097 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 28 Jul 2009 07:37:50 -0500 Subject: [PATCH] compiler.cfg.coalescing: some cleanups --- .../compiler/cfg/coalescing/coalescing.factor | 15 +++++++-- .../cfg/coalescing/copies/copies.factor | 21 ------------ .../process-blocks/process-blocks.factor | 32 ++++++++++--------- .../cfg/coalescing/renaming/renaming.factor | 2 +- 4 files changed, 30 insertions(+), 40 deletions(-) delete mode 100644 basis/compiler/cfg/coalescing/copies/copies.factor diff --git a/basis/compiler/cfg/coalescing/coalescing.factor b/basis/compiler/cfg/coalescing/coalescing.factor index 86dee8a3be..5deb375572 100644 --- a/basis/compiler/cfg/coalescing/coalescing.factor +++ b/basis/compiler/cfg/coalescing/coalescing.factor @@ -1,17 +1,17 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs fry kernel locals math math.order -sequences namespaces sets +sequences namespaces sets make compiler.cfg.rpo compiler.cfg.def-use compiler.cfg.utilities compiler.cfg.dominance compiler.cfg.instructions compiler.cfg.liveness.ssa +compiler.cfg.parallel-copy compiler.cfg.critical-edges compiler.cfg.coalescing.state compiler.cfg.coalescing.forest -compiler.cfg.coalescing.copies compiler.cfg.coalescing.renaming compiler.cfg.coalescing.live-ranges compiler.cfg.coalescing.process-blocks ; @@ -29,7 +29,7 @@ SYMBOL: seen :: visit-renaming ( dst assoc src bb -- ) src seen get key? [ - src dst bb waiting-for push-at + dst src bb waiting-for set-at src assoc delete-at ] [ src seen get conjoin ] if ; @@ -41,6 +41,15 @@ SYMBOL: seen ] assoc-each ] assoc-each ; +: insert-copies ( -- ) + waiting get [ + [ instructions>> building ] dip '[ + building get pop + _ parallel-copy + , + ] with-variable + ] assoc-each ; + : remove-phis-from-block ( bb -- ) instructions>> [ ##phi? not ] filter-here ; diff --git a/basis/compiler/cfg/coalescing/copies/copies.factor b/basis/compiler/cfg/coalescing/copies/copies.factor deleted file mode 100644 index 5df2684f72..0000000000 --- a/basis/compiler/cfg/coalescing/copies/copies.factor +++ /dev/null @@ -1,21 +0,0 @@ -! Copyright (C) 2009 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors assocs hashtables fry kernel make namespaces -sequences compiler.cfg.coalescing.state compiler.cfg.parallel-copy ; -IN: compiler.cfg.coalescing.copies - -: compute-copies ( assoc -- assoc' ) - dup assoc-size [ - '[ - [ 2dup eq? [ 2drop ] [ _ 2dup key? [ "OOPS" throw ] [ set-at ] if ] if ] with each - ] assoc-each - ] keep ; - -: insert-copies ( -- ) - waiting get [ - [ instructions>> building ] dip '[ - building get pop - _ compute-copies parallel-copy - , - ] with-variable - ] assoc-each ; \ No newline at end of file diff --git a/basis/compiler/cfg/coalescing/process-blocks/process-blocks.factor b/basis/compiler/cfg/coalescing/process-blocks/process-blocks.factor index 005c71f357..cc7b923105 100644 --- a/basis/compiler/cfg/coalescing/process-blocks/process-blocks.factor +++ b/basis/compiler/cfg/coalescing/process-blocks/process-blocks.factor @@ -47,7 +47,7 @@ SYMBOLS: phi-union unioned-blocks ; 2nip processed-name ; :: trivial-interference ( bb src dst -- ) - dst src bb waiting-for push-at + src dst bb waiting-for set-at src used-by-another get push ; :: add-to-renaming-set ( bb src dst -- ) @@ -118,20 +118,21 @@ SYMBOLS: visited work-list ; [ push-all-front ] keep [ work-list set ] [ process-df-nodes ] bi ; -:: add-local-interferences ( bb ##phi -- ) +: add-local-interferences ( ##phi -- ) ! bb contains the phi node. If the input is defined in the same ! block as the phi node, we have to check for interference. ! This can only happen if the value is carried by a back edge. - phi-union get [ - drop dup def-of bb eq? - [ ##phi dst>> 2array , ] [ drop ] if - ] assoc-each ; + + ! XXX: in the LLVM version they only add an interference if + ! the operand is defined in the same block as the ##phi, but + ! this doesn't work here. Investigate + [ phi-union get ] dip dst>> '[ drop _ 2array , ] assoc-each ; -: compute-local-interferences ( bb ##phi -- pairs ) +: compute-local-interferences ( ##phi -- pairs ) [ - [ phi-union get keys compute-dom-forest process-phi-union drop ] + [ phi-union get keys compute-dom-forest process-phi-union ] [ add-local-interferences ] - 2bi + bi ] { } make ; :: insert-copies-for-interference ( ##phi src -- ) @@ -149,13 +150,14 @@ SYMBOLS: visited work-list ; dst>> phi-union get swap renaming-sets get set-at phi-union get [ drop processed-name ] assoc-each ; -:: process-phi ( bb ##phi -- ) +: process-phi ( ##phi -- ) H{ } clone phi-union set H{ } clone unioned-blocks set - ##phi inputs>> ##phi dst>> '[ _ process-phi-operand ] assoc-each - ##phi bb ##phi compute-local-interferences process-local-interferences - ##phi add-renaming-set ; + [ [ inputs>> ] [ dst>> ] bi '[ _ process-phi-operand ] assoc-each ] + [ dup compute-local-interferences process-local-interferences ] + [ add-renaming-set ] + tri ; : process-block ( bb -- ) - dup instructions>> - [ dup ##phi? [ process-phi t ] [ 2drop f ] if ] with all? drop ; + instructions>> + [ dup ##phi? [ process-phi t ] [ drop f ] if ] all? drop ; diff --git a/basis/compiler/cfg/coalescing/renaming/renaming.factor b/basis/compiler/cfg/coalescing/renaming/renaming.factor index 848d0a4df0..15062d17c4 100644 --- a/basis/compiler/cfg/coalescing/renaming/renaming.factor +++ b/basis/compiler/cfg/coalescing/renaming/renaming.factor @@ -37,7 +37,7 @@ IN: compiler.cfg.coalescing.renaming : rename-copies ( -- ) waiting renamings get '[ [ - [ _ [ ?at drop ] [ '[ _ ?at drop ] map ] bi-curry bi* ] assoc-map + [ [ _ ?at drop ] bi@ ] assoc-map ] assoc-map ] change ;