2009-07-10 00:14:26 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2008-10-19 02:10:21 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-07-24 06:30:30 -04:00
|
|
|
USING: namespaces assocs kernel accessors
|
2009-08-27 01:06:19 -04:00
|
|
|
sorting sets sequences arrays
|
2009-08-08 05:02:18 -04:00
|
|
|
cpu.architecture
|
2009-08-27 01:06:19 -04:00
|
|
|
sequences.deep
|
2009-07-14 21:43:06 -04:00
|
|
|
compiler.cfg
|
2009-07-22 04:08:28 -04:00
|
|
|
compiler.cfg.rpo
|
2009-09-02 07:22:37 -04:00
|
|
|
compiler.cfg.def-use
|
2009-07-24 06:30:30 -04:00
|
|
|
compiler.cfg.instructions
|
2008-10-22 22:59:07 -04:00
|
|
|
compiler.cfg.value-numbering.graph
|
|
|
|
compiler.cfg.value-numbering.expressions
|
2008-10-23 03:49:26 -04:00
|
|
|
compiler.cfg.value-numbering.simplify
|
|
|
|
compiler.cfg.value-numbering.rewrite ;
|
2008-10-19 02:10:21 -04:00
|
|
|
IN: compiler.cfg.value-numbering
|
|
|
|
|
2009-08-08 21:02:56 -04:00
|
|
|
! Local value numbering.
|
|
|
|
|
2009-07-24 07:08:07 -04:00
|
|
|
: >copy ( insn -- insn/##copy )
|
2009-09-02 07:22:37 -04:00
|
|
|
dup defs-vreg dup vreg>vn vn>vreg
|
2009-08-08 05:02:18 -04:00
|
|
|
2dup eq? [ 2drop ] [ any-rep \ ##copy new-insn nip ] if ;
|
2009-07-10 00:14:26 -04:00
|
|
|
|
2009-07-24 06:30:30 -04:00
|
|
|
GENERIC: process-instruction ( insn -- insn' )
|
|
|
|
|
|
|
|
M: insn process-instruction
|
|
|
|
dup rewrite
|
2009-09-02 07:22:37 -04:00
|
|
|
[ process-instruction ]
|
|
|
|
[ dup defs-vreg [ dup number-values >copy ] when ] ?if ;
|
2009-07-10 00:14:26 -04:00
|
|
|
|
2009-08-27 01:06:19 -04:00
|
|
|
M: array process-instruction
|
|
|
|
[ process-instruction ] map ;
|
|
|
|
|
2009-05-26 20:56:56 -04:00
|
|
|
: value-numbering-step ( insns -- insns' )
|
2009-07-22 04:08:28 -04:00
|
|
|
init-value-graph
|
2009-08-27 01:06:19 -04:00
|
|
|
[ process-instruction ] map flatten ;
|
2009-05-26 20:31:19 -04:00
|
|
|
|
2009-05-29 14:11:34 -04:00
|
|
|
: value-numbering ( cfg -- cfg' )
|
2009-08-08 21:02:56 -04:00
|
|
|
[ value-numbering-step ] local-optimization
|
|
|
|
|
|
|
|
cfg-changed predecessors-changed ;
|