1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors classes kernel math namespaces sorting
4 compiler.vops compiler.cfg.vn.graph ;
5 IN: compiler.cfg.vn.expressions
7 ! Referentially-transparent expressions
9 TUPLE: nullary-expr < expr ;
10 TUPLE: unary-expr < expr in ;
11 TUPLE: binary-expr < expr in1 in2 ;
12 TUPLE: commutative-expr < binary-expr ;
13 TUPLE: boolean-expr < unary-expr code ;
14 TUPLE: constant-expr < expr value ;
15 TUPLE: literal-expr < unary-expr object ;
18 TUPLE: peek-expr < expr loc ;
20 SYMBOL: input-expr-counter
22 : next-input-expr ( -- n )
23 input-expr-counter [ dup 1 + ] change ;
25 ! Expressions whose values are inputs to the basic block. We
26 ! can eliminate a second computation having the same 'n' as
27 ! the first one; we can also eliminate input-exprs whose
29 TUPLE: input-expr < expr n ;
31 GENERIC: >expr ( insn -- expr )
33 M: %literal-table >expr
34 class nullary-expr boa ;
37 [ class ] [ value>> ] bi constant-expr boa ;
40 [ class ] [ in>> vreg>vn ] [ object>> ] tri literal-expr boa ;
43 [ class ] [ in>> vreg>vn ] bi unary-expr boa ;
46 [ class ] [ in1>> vreg>vn ] [ in2>> vreg>vn ] tri
49 M: commutative-op >expr
50 [ class ] [ in1>> vreg>vn ] [ in2>> vreg>vn ] tri
51 sort-pair commutative-expr boa ;
54 [ class ] [ in>> vreg>vn ] [ code>> ] tri
58 [ class ] [ stack-loc ] bi peek-expr boa ;
61 class next-input-expr input-expr boa ;
63 : init-expressions ( -- )
64 0 input-expr-counter set ;