From 3b79d614964e59d4c03019172aa031e5224b7d16 Mon Sep 17 00:00:00 2001 From: Slava Pestov <slava@slava-pestovs-macbook-pro.local> Date: Wed, 27 May 2009 18:55:49 -0500 Subject: [PATCH] Add a new ##allocation union to remove some code duplication --- .../cfg/alias-analysis/alias-analysis.factor | 12 +--------- .../cfg/instructions/instructions.factor | 5 ++++- .../cfg/linearization/linearization.factor | 22 +++++++++---------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/basis/compiler/cfg/alias-analysis/alias-analysis.factor b/basis/compiler/cfg/alias-analysis/alias-analysis.factor index 8e1034fb0d..6b1e0c47b6 100644 --- a/basis/compiler/cfg/alias-analysis/alias-analysis.factor +++ b/basis/compiler/cfg/alias-analysis/alias-analysis.factor @@ -220,17 +220,7 @@ M: ##load-reference analyze-aliases* M: ##alien-global analyze-aliases* dup dst>> set-heap-ac ; -M: ##allot analyze-aliases* - #! A freshly allocated object is distinct from any other - #! object. - dup dst>> set-new-ac ; - -M: ##box-float analyze-aliases* - #! A freshly allocated object is distinct from any other - #! object. - dup dst>> set-new-ac ; - -M: ##box-alien analyze-aliases* +M: ##allocation analyze-aliases* #! A freshly allocated object is distinct from any other #! object. dup dst>> set-new-ac ; diff --git a/basis/compiler/cfg/instructions/instructions.factor b/basis/compiler/cfg/instructions/instructions.factor index 650bcb5795..747233dbba 100644 --- a/basis/compiler/cfg/instructions/instructions.factor +++ b/basis/compiler/cfg/instructions/instructions.factor @@ -160,6 +160,9 @@ INSN: ##set-alien-double < ##alien-setter ; ! Memory allocation INSN: ##allot < ##flushable size class { temp vreg } ; + +UNION: ##allocation ##allot ##box-float ##box-alien ##integer>bignum ; + INSN: ##write-barrier < ##effect card# table ; INSN: ##alien-global < ##read symbol library ; @@ -225,7 +228,7 @@ INSN: _epilogue stack-frame ; INSN: _label id ; -INSN: _gc ; +INSN: _gc live-in ; INSN: _branch label ; diff --git a/basis/compiler/cfg/linearization/linearization.factor b/basis/compiler/cfg/linearization/linearization.factor index 9d80a2b28e..64507779a4 100755 --- a/basis/compiler/cfg/linearization/linearization.factor +++ b/basis/compiler/cfg/linearization/linearization.factor @@ -1,9 +1,11 @@ -! Copyright (C) 2008 Slava Pestov. +! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel math accessors sequences namespaces make -combinators classes +combinators assocs +cpu.architecture compiler.cfg compiler.cfg.rpo +compiler.cfg.liveness compiler.cfg.instructions ; IN: compiler.cfg.linearization @@ -18,7 +20,7 @@ M: insn linearize-insn , drop ; : useless-branch? ( basic-block successor -- ? ) #! If our successor immediately follows us in RPO, then we #! don't need to branch. - [ number>> ] bi@ 1- = ; inline + [ number>> ] bi@ 1 - = ; inline : branch-to-branch? ( successor -- ? ) #! A branch to a block containing just a jump return is cloned. @@ -56,18 +58,14 @@ M: ##compare-float-branch linearize-insn binary-conditional _compare-float-branch emit-branch ; : gc? ( bb -- ? ) - instructions>> [ - class { - ##allot - ##integer>bignum - ##box-float - ##box-alien - } memq? - ] any? ; + instructions>> [ ##allocation? ] any? ; + +: object-pointer-regs ( basic-block -- vregs ) + live-in keys [ reg-class>> int-regs eq? ] filter ; : linearize-basic-block ( bb -- ) [ number>> _label ] - [ gc? [ _gc ] when ] + [ dup gc? [ object-pointer-regs _gc ] [ drop ] if ] [ linearize-insns ] tri ;