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

SCM Repository

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

Annotation of /branches/vis15/src/compiler/tree-ir/tree-ir.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4317 - (view) (download)

1 : jhr 3691 (* tree-ir.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 :     * This representation restores the block structure and nested expression syntax
9 :     * of the source language.
10 :     *)
11 :    
12 :     structure TreeIR =
13 :     struct
14 :    
15 : jhr 3757 structure Op = TreeOps
16 : jhr 3750 structure Ty = TreeTypes
17 : jhr 3691
18 : jhr 3861 type target_info = {
19 : jhr 4317 layout : int -> TreeTypes.vec_layout,
20 :     isInline : LowOps.rator -> bool
21 : jhr 3861 }
22 :    
23 : jhr 3691 datatype program = Program of {
24 :     props : Properties.t list,
25 : jhr 4317 target : target_info, (* target-specific info about representation invariants *)
26 : jhr 3691 consts : global_var list, (* large constant variables *)
27 :     inputs : input list, (* global input variables *)
28 :     constInit : block, (* code that initializes constants and inputs *)
29 :     globals : global_var list, (* other global variables *)
30 : jhr 4317 funcs : func_def list, (* user-defined functions *)
31 : jhr 3995 globInit : block, (* CFG to initialize other globals (if any) *)
32 : jhr 3691 strand : strand, (* the strand definition *)
33 :     create : create, (* initial strand creation *)
34 : jhr 4317 init : block option, (* optional global initially code *)
35 : jhr 3995 update : block option (* optional global update code. *)
36 : jhr 3691 }
37 :    
38 : jhr 4163 and func_def = Func of {
39 : jhr 4317 name : func,
40 :     params : var list,
41 :     body : block
42 : jhr 4163 }
43 :    
44 : jhr 3691 and strand = Strand of {
45 :     name : Atom.atom,
46 :     params : var list,
47 :     state : state_var list,
48 : jhr 3952 stateInit : method,
49 :     initM : method option,
50 :     updateM : method,
51 :     stabilizeM : method option
52 : jhr 3691 }
53 :    
54 : jhr 3952 and method = Method of {
55 : jhr 4317 needsW : bool, (* does the method need the world (e.g., to print) *)
56 :     hasG : bool, (* does the method contain references to globals? *)
57 :     body : block (* the method body *)
58 :     }
59 : jhr 3952
60 : jhr 3691 and block = Block of {
61 : jhr 4317 locals : var list ref, (* the local variables that are used in this block *)
62 : jhr 3691 body : stm list
63 :     }
64 :    
65 :     and stm
66 :     = S_Comment of string list
67 : jhr 4317 | S_Assign of bool * var * exp (* assignment; the boolean is true for var decls *)
68 : jhr 3844 | S_MAssign of var list * exp
69 : jhr 3691 | S_GAssign of global_var * exp
70 :     | S_IfThen of exp * block
71 :     | S_IfThenElse of exp * block * block
72 : jhr 3924 | S_For of var * exp * exp * block
73 : jhr 3691 | S_Foreach of var * exp * block
74 :     (* special Diderot forms *)
75 : jhr 3894 | S_LoadNrrd of var * APITypes.t * string
76 : jhr 3691 | S_Input of global_var * string * string option * exp option (* get input *)
77 :     | S_InputNrrd of global_var * string * string option * string option (* get image/seq input *)
78 :     | S_New of Atom.atom * exp list (* new strand creation *)
79 : jhr 3767 | S_Save of state_var * exp (* save strand state *)
80 : jhr 3810 | S_Print of Ty.t list * exp list
81 : jhr 4168 | S_Return of exp
82 : jhr 3691 (* return functions for methods *)
83 :     | S_Active
84 :     | S_Stabilize
85 :     | S_Die
86 :    
87 :     and exp
88 :     = E_Global of global_var
89 : jhr 3852 | E_State of exp option * state_var
90 : jhr 3691 | E_Var of var
91 :     | E_Lit of Literal.t
92 :     | E_Op of Op.rator * exp list
93 : jhr 4317 | E_Apply of func * exp list (* user-defined function application *)
94 :     | E_Vec of int * int * exp list (* vector value; the ints are the width and the
95 :     * padded width
96 :     *)
97 :     | E_Cons of exp list * Ty.t (* in-memory tensor value *)
98 : jhr 3810 | E_Seq of exp list * Ty.t
99 : jhr 4317 | E_Pack of Ty.vec_layout * exp list (* pack vector pieces into composite vector value *)
100 :     | E_VLoad of Ty.vec_layout * exp * int (* load a piece of a composite vector value from
101 :     * a tensor. The integer specifies the index of
102 :     * the piece.
103 :     *)
104 : jhr 3691
105 :     and global_var = GV of {
106 : jhr 3813 name : string, (* name (should be unique) *)
107 :     ty : Ty.t, (* type *)
108 : jhr 4317 xty : APITypes.t option, (* external type (for inputs and outputs) *)
109 : jhr 3832 input : bool, (* is an input variable *)
110 :     output : bool, (* is the output value of the strand *)
111 :     varying : bool (* varies over the execution of the program *)
112 : jhr 3691 }
113 :    
114 :     and state_var = SV of {
115 : jhr 3813 name : string, (* name (should be unique) *)
116 :     ty : Ty.t, (* type *)
117 : jhr 4317 xty : APITypes.t option, (* external type (for outputs) *)
118 : jhr 3832 varying : bool (* varies over the lifetime of the strand *)
119 : jhr 3691 }
120 :    
121 :     and var = V of {
122 :     name : string, (* name (should be unique) *)
123 :     id : Stamp.stamp, (* unique ID *)
124 : jhr 3813 ty : Ty.t (* type *)
125 : jhr 3691 }
126 :    
127 : jhr 4163 and func = FV of {
128 :     name : string, (* name (should be unique) *)
129 :     id : Stamp.stamp, (* unique ID *)
130 :     ty : Ty.t, (* return type *)
131 : jhr 4174 paramTys : Ty.t list, (* parameter types *)
132 : jhr 4317 needsW : bool, (* does the function need the world (e.g., to print) *)
133 :     hasG : bool (* does the function contain references to globals? *)
134 : jhr 4163 }
135 :    
136 : jhr 3691 withtype input = global_var Inputs.input
137 : jhr 4045 and create = block Create.t
138 : jhr 3691
139 : jhr 4251 fun emptyBlk (Block{body=[], ...}) = true
140 :     | emptyBlk _ = false
141 :    
142 : jhr 3691 end

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