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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3850, Thu May 12 18:05:47 2016 UTC revision 3851, Thu May 12 19:27:43 2016 UTC
# Line 8  Line 8 
8    
9  structure Env : sig  structure Env : sig
10    
11        type target_info = {
12            layout : int -> TreeTypes.vec_layout,
13            isInline : TreeOps.rator -> bool
14          }
15    
16    (* the translated bindings of LowIR variables.  If the variable has a vector type,    (* 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     * then it is bound to a vector of expression trees, otherwise it is bound to a
18     * single tree.     * single tree.
# Line 19  Line 24 
24      type t      type t
25    
26    (* create a new environment *)    (* create a new environment *)
27      val new : (int -> TreeTypes.vec_layout) -> t      val new : target_info -> t
28    
29    (* return the layout of a Low IR vector of a given width as a Tree IR composite vector *)    (* 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      val layoutVec : t -> int -> TreeTypes.vec_layout
31    
32        val isInlineOp : t -> TreeOps.rator -> bool
33    
34    (* get the binding for a variable *)    (* get the binding for a variable *)
35      val useVar : t -> LowIR.var -> binding      val useVar : t -> LowIR.var -> binding
36    
37    (* add a binding to the environment *)    (* add a binding to the environment *)
38      val bindVar : t * LowIR.var * TreeIR.exp -> unit      val bindVar : t * LowIR.var * binding -> unit
39    
40    (* set the definition of a variable, where the RHS is either a literal constant or a variable *)    (* set the definition of a variable, where the RHS is either a literal constant or a variable *)
41      val bindSimple : t * LowIR.var * TreeIR.exp -> unit      val bindSimple : t * LowIR.var * TreeIR.exp -> unit
# Line 36  Line 43 
43    (* at the end of a block, we need to assign any pending expressions to locals.  The    (* at the end of a block, we need to assign any pending expressions to locals.  The
44     * blkStms list and the resulting statement list are in reverse order.     * blkStms list and the resulting statement list are in reverse order.
45     *)     *)
46      val flushPending : t * TreeIR.stm list -> t * TreeIR.stm list      val flushPending : t * TreeIR.stm list -> TreeIR.stm list
47    
48    end = struct    end = struct
49    
50      structure VT = LowIR.Var.Tbl      structure VT = LowIR.Var.Tbl
51    
52        type target_info = {
53            layout : int -> TreeTypes.vec_layout,
54            isInline : TreeOps.rator -> bool
55          }
56    
57      datatype binding      datatype binding
58        = TREE of TreeIR.exp        = TREE of TreeIR.exp
59        | VEC of TreeTypes.vec_layout * TreeIR.exp list        | VEC of TreeTypes.vec_layout * TreeIR.exp list
60    
61      datatype t = E of {      datatype t = E of {
62          tbl : (bool * binding) VT.hash_table,          tbl : (bool * binding) VT.hash_table,
63          layout : int -> TreeTypes.vec_layout          info : target_info
64        }        }
65    
66      fun decCount (LowIR.V{useCnt, ...}) = let      fun decCount (LowIR.V{useCnt, ...}) = let
# Line 57  Line 69 
69              useCnt := n;  (n <= 0)              useCnt := n;  (n <= 0)
70            end            end
71    
72      fun new layout = E{      fun new info = E{
73              tbl = VT.mkTable (256, Fail "tbl"),              tbl = VT.mkTable (256, Fail "tbl"),
74              layout = layout              info = info
75            }            }
76    
77      fun layoutVec (E{layout, ...}) wid = layout wid      fun layoutVec (E{info={layout, ...}, ...}) wid = layout wid
78    
79        fun isInlineOp (E{info={isInline, ...}, ...}) rator = isInline rator
80    
81    (* use a variable.  If this is its last use, we remove it from the table *)    (* use a variable.  If this is its last use, we remove it from the table *)
82      fun useVar (env as E{tbl, ...}) = let      fun useVar (env as E{tbl, ...}) = let
# Line 87  Line 101 
101              use              use
102            end            end
103    
104      fun bindVar (E{tbl, ...}, x, b) = VT.insert tbl (x, (false, TREE b))      fun bindVar (E{tbl, ...}, x, b) = VT.insert tbl (x, (false, b))
105    
106      fun bindSimple (E{tbl, ...}, x, b) = VT.insert tbl (x, (true, TREE b))      fun bindSimple (E{tbl, ...}, x, b) = VT.insert tbl (x, (true, TREE b))
107    
108      fun flushPending (E{tbl, layout}, blkStms) = let      fun flushPending (E{tbl, ...}, blkStms) = let
109            fun doVar (x, (false, TREE e), stms) = let            fun doVar (x, (false, TREE e), stms) = let
110                  val t = Util.newLocalVar x                  val t = Util.newLocalVar x
111                  in                  in
# Line 102  Line 116 
116              | doVar (_, _, acc) = acc              | doVar (_, _, acc) = acc
117            val stms = VT.foldi doVar blkStms tbl            val stms = VT.foldi doVar blkStms tbl
118            in            in
119              (E{tbl=tbl, layout=layout}, stms)              stms
120            end            end
121    
122    end    end

Legend:
Removed from v.3850  
changed lines
  Added in v.3851

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