: split-instructions? ( insns -- ? ) [ irrelevant? not ] count 5 <= ;
: short-tail-block? ( bb -- ? )
- [ successors>> empty? ] [ instructions>> length 2 = ] bi and ;
+ { [ successors>> empty? ] [ instructions>> length 2 = ] } 1&& ;
: short-block? ( bb -- ? )
! If block is empty, always split
! Copyright (C) 2008, 2010 Slava Pestov.
! See https://factorcode.org/license.txt for BSD license.
USING: accessors alien byte-arrays classes.algebra combinators
-compiler.cfg.instructions compiler.cfg.instructions.syntax
-compiler.cfg.registers compiler.constants effects kernel layouts
-math namespaces parser sequences splitting words ;
+combinators.short-circuit compiler.cfg.instructions
+compiler.cfg.instructions.syntax compiler.cfg.registers
+compiler.constants effects kernel layouts math namespaces parser
+sequences splitting words ;
IN: compiler.cfg.hats
<<
PRIVATE>
insn-classes get [
- dup [ insn-def-slots length 1 = ] [ name>> "##" head? ] bi and
+ dup { [ insn-def-slots length 1 = ] [ name>> "##" head? ] } 1&&
[ define-hat ] [ drop ] if
] each
! Copyright (C) 2009, 2010 Slava Pestov.
! See https://factorcode.org/license.txt for BSD license.
-USING: accessors assocs combinators
+USING: accessors assocs combinators combinators.short-circuit
compiler.cfg.linear-scan.allocation.splitting
compiler.cfg.linear-scan.allocation.state
compiler.cfg.linear-scan.live-intervals
dup first-use n>> swap [ fix-lower-bound ] change-ranges drop ;
: last-use-rep ( live-interval -- rep )
- last-use [ def-rep>> ] [ use-rep>> ] bi or ; inline
+ last-use { [ def-rep>> ] [ use-rep>> ] } 1|| ; inline
: assign-spill ( live-interval -- )
dup last-use-rep dup [
! Copyright (C) 2008, 2010 Slava Pestov.
! See https://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs classes.algebra combinators
-compiler.tree compiler.tree.dead-code.liveness
-compiler.tree.propagation.info fry kernel locals math math.private
-namespaces sequences stack-checker.backend stack-checker.dependencies
-words ;
+combinators.short-circuit compiler.tree
+compiler.tree.dead-code.liveness compiler.tree.propagation.info
+fry kernel locals math math.private namespaces sequences
+stack-checker.backend stack-checker.dependencies words ;
IN: compiler.tree.dead-code.simple
: flushable-call? ( #call -- ? )
[ filter-live ] change-in-r
[ filter-live ] change-out-r
[ filter-mapping ] change-mapping
- dup [ in-d>> empty? ] [ in-r>> empty? ] bi and [ drop f ] when ;
+ dup { [ in-d>> empty? ] [ in-r>> empty? ] } 1&& [ drop f ] when ;
M: #copy remove-dead-code*
[ in-d>> ] [ out-d>> ] bi
{ [ dup #>r? ] [ drop \ >R , ] }
{ [ dup #r>? ] [ drop \ R> , ] }
{
- [ dup [ in-r>> empty? ] [ out-r>> empty? ] bi and ]
+ [ dup { [ in-r>> empty? ] [ out-r>> empty? ] } 1&& ]
[
shuffle-effect dup pretty-shuffle
[ % ] [ shuffle-node boa , ] ?if
SYMBOL: allocations
-: (allocation) ( -- allocations )
- allocations get ; inline
-
: allocation ( value -- allocation )
- (allocation) at ;
+ allocations get at ;
: record-allocation ( allocation value -- )
- (allocation) set-at ;
+ allocations get set-at ;
: record-allocations ( allocations values -- )
- (allocation) '[ _ set-at ] 2each ;
+ allocations get '[ _ set-at ] 2each ;
SYMBOL: slot-accesses
: equate-values ( value1 value2 -- )
escaping-values get equate ;
+DEFER: add-escaping-values
+
: add-escaping-value ( value -- )
- [
- allocation {
- { [ dup not ] [ drop ] }
- { [ dup t eq? ] [ drop ] }
- [ [ add-escaping-value ] each ]
- } cond
- ]
+ [ allocation dup boolean? [ drop ] [ add-escaping-values ] if ]
[ +escaping+ equate-values ] bi ;
: add-escaping-values ( values -- )
DEFER: copy-value
: copy-allocation ( allocation -- allocation' )
- {
- { [ dup not ] [ ] }
- { [ dup t eq? ] [ ] }
- [ [ <value> [ introduce-value ] [ copy-value ] [ ] tri ] map ]
- } cond ;
+ dup boolean? [
+ [ <value> [ introduce-value ] [ copy-value ] [ ] tri ] map
+ ] unless ;
+
+:: (copy-value) ( from to allocations -- )
+ from to equate-values
+ from allocations at copy-allocation to allocations set-at ;
: copy-value ( from to -- )
- [ equate-values ]
- [ [ allocation copy-allocation ] dip record-allocation ]
- 2bi ;
+ allocations get (copy-value) ;
: copy-values ( from to -- )
- [ copy-value ] 2each ;
+ allocations get '[ _ (copy-value) ] 2each ;
: copy-slot-value ( out slot# in -- )
- allocation {
- { [ dup not ] [ 3drop ] }
- { [ dup t eq? ] [ 3drop ] }
- [ nth swap copy-value ]
- } cond ;
+ allocation dup boolean?
+ [ 3drop ] [ nth swap copy-value ] if ;
SYMBOL: escaping-allocations
: congruent? ( alloc1 alloc2 -- ? )
{
- { [ 2dup [ f eq? ] either? ] [ eq? ] }
- { [ 2dup [ t eq? ] either? ] [ eq? ] }
+ { [ 2dup [ boolean? ] either? ] [ eq? ] }
{ [ 2dup [ length ] bi@ = not ] [ 2drop f ] }
[ [ [ allocation ] bi@ congruent? ] 2all? ]
} cond ;
GENERIC: optimize-modular-arithmetic* ( node -- nodes )
M: #push optimize-modular-arithmetic*
- dup [ out-d>> first modular-value? ] [ literal>> real? ] bi and
+ dup { [ out-d>> first modular-value? ] [ literal>> real? ] } 1&&
[ [ >fixnum ] change-literal ] when ;
: redundant->fixnum? ( #call -- ? )
M: curried already-inlined-quot? quot>> already-inlined-quot? ;
M: composed already-inlined-quot?
- [ first>> already-inlined-quot? ]
- [ second>> already-inlined-quot? ] bi or ;
+ {
+ [ first>> already-inlined-quot? ]
+ [ second>> already-inlined-quot? ]
+ } 1|| ;
M: quotation already-inlined-quot? already-inlined? ;
! Copyright (C) 2008 Slava Pestov.
! See https://factorcode.org/license.txt for BSD license.
-USING: accessors assocs compiler.tree compiler.tree.def-use
-compiler.utilities grouping kernel namespaces sequences sets
-stack-checker.branches ;
+USING: accessors assocs combinators.short-circuit compiler.tree
+compiler.tree.def-use compiler.utilities grouping kernel
+namespaces sequences sets stack-checker.branches ;
IN: compiler.tree.propagation.copy
SYMBOL: copies
: resolve-copy ( copy -- val ) copies get compress-path ;
-: resolve-copies ( copies -- vals )
- copies get [ compress-path ] curry map ;
+: resolve-copies ( copies -- vals ) copies get '[ _ compress-path ] map ;
: is-copy-of ( val copy -- ) copies get set-at ;
-: are-copies-of ( vals copies -- ) [ is-copy-of ] 2each ;
+: are-copies-of ( vals copies -- ) copies get '[ _ set-at ] 2each ;
: introduce-value ( val -- ) copies get conjoin ;
-: introduce-values ( vals -- )
- copies get [ conjoin ] curry each ;
+: introduce-values ( vals -- ) copies get '[ _ conjoin ] each ;
GENERIC: compute-copy-equiv* ( node -- )
M: #renaming compute-copy-equiv* inputs/outputs are-copies-of ;
: compute-phi-equiv ( inputs outputs -- )
- [
+ copies get '[
swap remove-bottom resolve-copies
dup [ f ] [ all-equal? ] if-empty
- [ first swap is-copy-of ] [ 2drop ] if
+ [ first swap _ set-at ] [ 2drop ] if
] 2each ;
M: #phi compute-copy-equiv*
: empty-set? ( info -- ? )
{
[ class>> null-class? ]
- [ [ interval>> empty-interval? ] [ class>> real class<= ] bi and ]
+ [ { [ interval>> empty-interval? ] [ class>> real class<= ] } 1&& ]
} 1|| ;
! Hardcoding classes is kind of a hack.
DEFER: (value-info-intersect)
: intersect-slot ( info1 info2 -- info )
- {
- { [ dup not ] [ nip ] }
- { [ over not ] [ drop ] }
- [ (value-info-intersect) ]
- } cond ;
+ 2dup and [ (value-info-intersect) ] [ 2drop f ] if ;
: intersect-slots ( info1 info2 -- slots )
[ slots>> ] bi@ {
DEFER: (value-info-union)
: union-slot ( info1 info2 -- info )
- {
- { [ dup not ] [ nip ] }
- { [ over not ] [ drop ] }
- [ (value-info-union) ]
- } cond ;
+ 2dup and [ (value-info-union) ] [ 2drop f ] if ;
: union-slots ( info1 info2 -- slots )
[ slots>> ] bi@
: value-info ( value -- info )
value-info* drop ;
+: (set-value-info) ( info value assoc -- )
+ [ resolve-copy ] dip last set-at ;
+
: set-value-info ( info value -- )
- resolve-copy value-infos get last set-at ;
+ value-infos get (set-value-info) ;
-: refine-value-info ( info value -- )
- resolve-copy value-infos get
+: set-value-infos ( infos values -- )
+ value-infos get '[ _ (set-value-info) ] 2each ;
+
+: (refine-value-info) ( info value assoc -- )
+ [ resolve-copy ] dip
[ assoc-stack [ value-info-intersect ] when* ] 2keep
last set-at ;
+: refine-value-info ( info value -- )
+ value-infos get (refine-value-info) ;
+
+: refine-value-infos ( infos values -- )
+ value-infos get '[ _ (refine-value-info) ] 2each ;
+
: value-literal ( value -- obj ? )
value-info >literal< ;
! Copyright (C) 2008, 2010 Slava Pestov.
! See https://factorcode.org/license.txt for BSD license.
-USING: accessors classes.algebra combinators compiler.tree
+USING: accessors classes.algebra combinators
+combinators.short-circuit compiler.tree
compiler.tree.combinators compiler.tree.propagation.constraints
compiler.tree.propagation.copy compiler.tree.propagation.info
compiler.tree.propagation.nodes compiler.tree.propagation.simple
label>> enter-recursive>> node-output-infos ;
: generalize-return-interval ( info -- info' )
- dup [ literal?>> ] [ class>> null-class? ] bi or
+ dup { [ literal?>> ] [ class>> null-class? ] } 1||
[ clone dup class>> class-interval >>interval ] unless ;
: generalize-return ( infos -- infos' )
[ literal>> <literal-info> ] [ out-d>> first ] bi
set-value-info ;
-: refine-value-infos ( classes/f values -- )
- [ refine-value-info ] 2each ;
-
-: set-value-infos ( infos values -- )
- [ set-value-info ] 2each ;
-
M: #declare propagate-before
! We need to force the caller word to recompile when the
! classes mentioned in the declaration are redefined, since
label>> dup not-a-loop? [ drop ] [
recursive-nesting get <reversed> [
2dup label>> eq? [ 2drop f ] [
- [ label>> not-a-loop? ] [ tail?>> not ] bi or
+ { [ label>> not-a-loop? ] [ tail?>> not ] } 1||
[ not-a-loop changed? on ] [ drop ] if t
] if
] with all? drop
M: #alien-callback unbox-tuples* ;
: unbox-tuples ( nodes -- nodes )
- (allocation) escaping-allocations get
+ allocations get escaping-allocations get
[ nip key? ] curry assoc-all?
[ [ unbox-tuples* ] map-nodes ] unless ;