Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/low-to-tree/env.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/low-to-tree/env.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3856 - (view) (download)

1 : jhr 3834 (* env.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2016 The University of Chicago
6 :     * All rights reserved.
7 :     *)
8 :    
9 :     structure Env : sig
10 :    
11 : jhr 3851 type target_info = {
12 :     layout : int -> TreeTypes.vec_layout,
13 : jhr 3852 isInline : LowOps.rator -> bool
14 : jhr 3851 }
15 :    
16 : jhr 3834 (* the translated bindings of LowIR variables. If the variable has a vector type,
17 :     * then it is bound to a vector of expression trees, otherwise it is bound to a
18 :     * single tree.
19 :     *)
20 :     datatype binding
21 :     = TREE of TreeIR.exp (* variable bound to a target expression tree *)
22 :     | VEC of TreeTypes.vec_layout * TreeIR.exp list
23 :    
24 :     type t
25 :    
26 :     (* create a new environment *)
27 : jhr 3851 val new : target_info -> t
28 : jhr 3834
29 : jhr 3843 (* return the layout of a Low IR vector of a given width as a Tree IR composite vector *)
30 :     val layoutVec : t -> int -> TreeTypes.vec_layout
31 :    
32 : jhr 3852 val isInlineOp : t -> LowOps.rator -> bool
33 : jhr 3851
34 : jhr 3834 (* get the binding for a variable *)
35 :     val useVar : t -> LowIR.var -> binding
36 :    
37 :     (* add a binding to the environment *)
38 : jhr 3851 val bindVar : t * LowIR.var * binding -> unit
39 : jhr 3834
40 : jhr 3852 (* set the definition of a variable, where the RHS is a simple expression that can be
41 :     * replicated without code-size or performance hit (e.g., a literal or variable).
42 :     *)
43 :     val bindSimple : t * LowIR.var * binding -> unit
44 : jhr 3836
45 :     (* at the end of a block, we need to assign any pending expressions to locals. The
46 :     * blkStms list and the resulting statement list are in reverse order.
47 :     *)
48 : jhr 3851 val flushPending : t * TreeIR.stm list -> TreeIR.stm list
49 : jhr 3836
50 : jhr 3834 end = struct
51 :    
52 :     structure VT = LowIR.Var.Tbl
53 :    
54 : jhr 3851 type target_info = {
55 :     layout : int -> TreeTypes.vec_layout,
56 : jhr 3852 isInline : LowOps.rator -> bool
57 : jhr 3851 }
58 :    
59 : jhr 3834 datatype binding
60 :     = TREE of TreeIR.exp
61 :     | VEC of TreeTypes.vec_layout * TreeIR.exp list
62 :    
63 :     datatype t = E of {
64 : jhr 3836 tbl : (bool * binding) VT.hash_table,
65 : jhr 3851 info : target_info
66 : jhr 3834 }
67 :    
68 :     fun decCount (LowIR.V{useCnt, ...}) = let
69 :     val n = !useCnt - 1
70 :     in
71 :     useCnt := n; (n <= 0)
72 :     end
73 :    
74 : jhr 3851 fun new info = E{
75 : jhr 3843 tbl = VT.mkTable (256, Fail "tbl"),
76 : jhr 3851 info = info
77 : jhr 3843 }
78 : jhr 3834
79 : jhr 3851 fun layoutVec (E{info={layout, ...}, ...}) wid = layout wid
80 : jhr 3843
81 : jhr 3851 fun isInlineOp (E{info={isInline, ...}, ...}) rator = isInline rator
82 :    
83 : jhr 3856 (* use a variable. If this is its last use, we remove it from the table.
84 :     * NOTE: we assume that this function is _not_ called on variables that are
85 :     * in an equivalence class; those are handled in low-to-tree.sml.
86 :     *)
87 : jhr 3834 fun useVar (env as E{tbl, ...}) = let
88 :     val find = VT.find tbl
89 :     val remove = VT.remove tbl
90 :     fun use x = let
91 :     fun removeUnused () = if (decCount x) then ignore(VT.remove tbl x) else ()
92 :     in
93 : jhr 3856 case find x
94 :     of SOME(true, binding) => (removeUnused(); binding)
95 :     | SOME(false, binding) => (removeUnused(); binding)
96 :     | NONE => raise Fail(concat ["useVar(", LowIR.Var.toString x, ")"])
97 : jhr 3834 (* end case *)
98 :     end
99 :     in
100 :     use
101 :     end
102 :    
103 : jhr 3851 fun bindVar (E{tbl, ...}, x, b) = VT.insert tbl (x, (false, b))
104 : jhr 3834
105 : jhr 3852 fun bindSimple (E{tbl, ...}, x, b) = VT.insert tbl (x, (true, b))
106 : jhr 3836
107 : jhr 3851 fun flushPending (E{tbl, ...}, blkStms) = let
108 : jhr 3848 fun doVar (x, (false, TREE e), stms) = let
109 : jhr 3842 val t = Util.newLocalVar x
110 : jhr 3836 in
111 :     VT.insert tbl (x, (true, TREE(TreeIR.E_Var t)));
112 : jhr 3848 TreeIR.S_Assign(t, e)::stms
113 : jhr 3836 end
114 : jhr 3848 | doVar (x, (false, VEC(layout, es)), stms) = raise Fail "FIXME"
115 : jhr 3836 | doVar (_, _, acc) = acc
116 : jhr 3848 val stms = VT.foldi doVar blkStms tbl
117 : jhr 3836 in
118 : jhr 3851 stms
119 : jhr 3836 end
120 :    
121 : jhr 3834 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0