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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/simple/simple.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/simple/simple.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3501 - (view) (download)

1 : jhr 3416 (* simple.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 :     * All rights reserved.
7 :     *
8 :     * A simplified AST representation of a Diderot program. This representation has the property
9 :     * that the arguments to ifs, operators, etc. are variables and that the rhs of assignments
10 :     * consist of a single operation. It is not, however, a single-assignment representation.
11 :     *)
12 :    
13 :     structure Simple =
14 :     struct
15 :    
16 : jhr 3430 type var = SimpleVar.t
17 :    
18 : jhr 3416 (* types with the meta variables resolved *)
19 :     type ty = SimpleTypes.ty
20 :    
21 :     (* resolved meta-variable arguments to basis functions *)
22 :     datatype meta_arg = datatype SimpleTypes.meta_arg
23 :    
24 : jhr 3454 datatype input_init
25 : jhr 3456 = NoDefault (* uninitialized input *)
26 :     | ConstExpr (* initialized to constant. The actual initialization
27 :     * is handled in the constInit block.
28 :     *)
29 : jhr 3454 | LoadSeq of string (* load a sequence from a file *)
30 :     | Proxy of string * ImageInfo.info (* input image specified by proxy *)
31 :     | Image of ImageInfo.info (* input image w/o proxy *)
32 : jhr 3416
33 : jhr 3446 datatype input = INP of { (* global input variable *)
34 :     var : var, (* the global variable *)
35 :     desc : string option, (* the optional descriptor *)
36 : jhr 3456 init : input_init (* the optional default value *)
37 : jhr 3416 }
38 :    
39 :     datatype program = Program of {
40 : jhr 3431 props : Properties.t list,
41 : jhr 3456 consts : var list, (* constant variables *)
42 : jhr 3446 inputs : input list, (* input globals *)
43 : jhr 3456 constInit : block, (* code that initializes constants and inputs *)
44 : jhr 3416 globals : var list, (* non-input globals *)
45 :     funcs : func list,
46 : jhr 3451 init : block,
47 : jhr 3446 strand : strand,
48 : jhr 3453 create : create,
49 : jhr 3430 update : block option
50 : jhr 3416 }
51 :    
52 :     and func = Func of {
53 :     f : var,
54 :     params : var list,
55 :     body : block
56 :     }
57 :    
58 :     and strand = Strand of {
59 :     name : Atom.atom,
60 :     params : var list,
61 :     state : var list,
62 :     stateInit : block,
63 : jhr 3451 initM : block option,
64 :     updateM : block,
65 :     stabilizeM : block option
66 : jhr 3416 }
67 :    
68 : jhr 3453 (* initial-strands creation; the stmt will be a loop nest with a "new" as the body *)
69 : jhr 3485 and create = Create of {
70 : jhr 3501 dim : int option, (* grid dimension; NONE for collections *)
71 :     code : block (* the loop nest for creating the strands *)
72 : jhr 3485 }
73 : jhr 3453
74 : jhr 3501 and block = Block of {
75 :     code : stmt list, (* the body of the block *)
76 :     props : PropList.holder (* property list *)
77 :     }
78 : jhr 3416
79 :     and stmt
80 : jhr 3465 = S_Var of var * exp option (* introduce a local variable. The uninitialized *)
81 :     (* form is needed for the results of conditional *)
82 :     (* expressions *)
83 : jhr 3416 | S_Assign of var * exp
84 :     | S_IfThenElse of var * block * block
85 : jhr 3451 | S_Foreach of var * var * block
86 : jhr 3416 | S_New of Atom.atom * var list
87 :     | S_Continue
88 :     | S_Die
89 :     | S_Stabilize
90 :     | S_Return of var
91 :     | S_Print of var list
92 : jhr 3465 (* FIXME: to support fusion of reductions, we'll have to add tuples or change S_Return
93 :     * to support multiple return values.
94 :     *)
95 : jhr 3462 | S_MapReduce of { (* parallel map-reduce *)
96 :     results : var list, (* the results of reduction phase *)
97 :     reductions : AST.var list, (* the reduction operators (one per result) *)
98 :     body : func, (* a function that implements map part *)
99 :     args : var list, (* the invariant arguments to the map phase *)
100 :     source : AST.var (* the set of strands that we map over *)
101 :     }
102 : jhr 3416
103 :     and exp
104 :     = E_Var of var
105 : jhr 3446 | E_Lit of Literal.t
106 : jhr 3456 | E_Select of var * var (* strand-field selection *)
107 : jhr 3416 | E_Apply of var * var list * ty (* user-defined function *)
108 :     | E_Prim of AST.var * meta_arg list * var list * ty (* Diderot builtin *)
109 : jhr 3452 | E_Tensor of var list * ty
110 : jhr 3416 | E_Seq of var list * ty (* sequence (ty is result type) *)
111 :     | E_Slice of var * var option list * ty (* tensor slicing (ty is result type) *)
112 :     | E_Coerce of {srcTy : ty, dstTy : ty, x : var}
113 :     | E_LoadSeq of ty * string
114 :     | E_LoadImage of ty * string * ImageInfo.info
115 :    
116 : jhr 3446 fun typeOf (E_Var x) = SimpleVar.typeOf x
117 : jhr 3416 | typeOf (E_Lit lit) = (case lit
118 :     of (Literal.Int _) => SimpleTypes.T_Int
119 : jhr 3446 | (Literal.Real _) => SimpleTypes.T_Tensor[]
120 : jhr 3416 | (Literal.String s) => SimpleTypes.T_String
121 :     | (Literal.Bool _) => SimpleTypes.T_Bool
122 :     (* end case *))
123 : jhr 3456 | typeOf (E_Select(_, fld)) = SimpleVar.typeOf fld
124 : jhr 3416 | typeOf (E_Apply(_, _, ty)) = ty
125 :     | typeOf (E_Prim(_, _, _, ty)) = ty
126 : jhr 3452 | typeOf (E_Tensor(_, ty)) = ty
127 : jhr 3416 | typeOf (E_Seq(_, ty)) = ty
128 :     | typeOf (E_Slice(_, _, ty)) = ty
129 :     | typeOf (E_Coerce{dstTy, ...}) = dstTy
130 :     | typeOf (E_LoadSeq(ty, _)) = ty
131 :     | typeOf (E_LoadImage(ty, _, _)) = ty
132 :    
133 : jhr 3501 fun newProp initFn = PropList.newProp (fn (Block{props, ...}) => props, initFn)
134 :     fun newFlag () = PropList.newFlag (fn (Block{props, ...}) => props)
135 :    
136 : jhr 3416 end

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