1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel sequences make combinators
4 compiler.cfg.registers compiler.cfg.instructions
5 compiler.cfg.rpo cpu.architecture ;
6 IN: compiler.cfg.two-operand
8 ! This pass runs before SSA coalescing and normalizes instructions
9 ! to fit the x86 two-address scheme. Since the input is in SSA,
10 ! it suffices to convert
19 ! We don't bother with ##add, ##add-imm, ##sub-imm or ##mul-imm
20 ! since x86 has LEA and IMUL instructions which are effectively
21 ! three-operand addition and multiplication, respectively.
23 UNION: two-operand-insn
56 GENERIC: convert-two-operand* ( insn -- )
58 : emit-copy ( dst src -- )
59 dup rep-of ##copy ; inline
61 M: two-operand-insn convert-two-operand*
62 [ [ dst>> ] [ src1>> ] bi emit-copy ]
64 dup [ src1>> ] [ src2>> ] bi = [ dup dst>> >>src2 ] when
68 M: ##not convert-two-operand*
69 [ [ dst>> ] [ src>> ] bi emit-copy ]
73 M: insn convert-two-operand* , ;
75 : (convert-two-operand) ( insns -- insns' )
76 dup first kill-vreg-insn? [
77 [ [ convert-two-operand* ] each ] V{ } make
80 : convert-two-operand ( cfg -- cfg' )
81 two-operand? [ [ (convert-two-operand) ] local-optimization ] when ;