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

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/tree-il/low-to-tree-fn.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/tree-il/low-to-tree-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2377 - (view) (download)

1 : jhr 1115 (* low-to-tree-fn.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * This module translates the LowIL representation of a program (i.e., a pure CFG) to
7 :     * a block-structured AST with nested expressions.
8 :     *
9 :     * NOTE: this translation is pretty dumb about variable coalescing (i.e., it doesn't do any).
10 :     *)
11 :    
12 :     functor LowToTreeFn (Target : sig
13 :    
14 : jhr 1640 val supportsPrinting : unit -> bool (* does the target support the Print op? *)
15 :    
16 : jhr 1115 (* tests for whether various expression forms can appear inline *)
17 : jhr 2356 val inlineCons : int -> bool (* can n'th-order tensor construction appear inline *)
18 :     val inlineMatrixExp : bool (* can matrix-valued expressions appear inline? *)
19 : jhr 1115
20 :     end) : sig
21 :    
22 :     val translate : LowIL.program -> TreeIL.program
23 :    
24 :     end = struct
25 :    
26 :     structure IL = LowIL
27 :     structure Ty = LowILTypes
28 :     structure V = LowIL.Var
29 : jhr 1640 structure StV = LowIL.StateVar
30 : jhr 1115 structure Op = LowOps
31 :     structure Nd = LowIL.Node
32 :     structure CFG = LowIL.CFG
33 :     structure T = TreeIL
34 :     structure VA = VarAnalysis
35 :    
36 :     (* create new tree IL variables *)
37 :     local
38 :     fun newVar (name, kind, ty) = T.V{
39 : jhr 2356 name = name,
40 :     id = Stamp.new(),
41 :     kind = kind,
42 :     ty = ty
43 :     }
44 : jhr 1115 val cnt = ref 0
45 :     fun genName prefix = let
46 : jhr 2356 val n = !cnt
47 :     in
48 :     cnt := n+1;
49 :     String.concat[prefix, "_", Int.toString n]
50 :     end
51 : jhr 1115 in
52 :     fun newGlobal x = newVar ("G_" ^ V.name x, T.VK_Global, V.ty x)
53 :     fun newParam x = newVar (genName("p_" ^ V.name x), T.VK_Local, V.ty x)
54 :     fun newLocal x = newVar (genName("l_" ^ V.name x), T.VK_Local, V.ty x)
55 :     fun newIter x = newVar (genName("i_" ^ V.name x), T.VK_Local, V.ty x)
56 :     end
57 :    
58 : jhr 1640 (* associate Tree IL state variables with Low IL variables using properties *)
59 :     local
60 :     fun mkStateVar x = T.SV{
61 :     name = StV.name x,
62 :     id = Stamp.new(),
63 :     ty = StV.ty x,
64 :     varying = VA.isVarying x,
65 :     output = StV.isOutput x
66 :     }
67 :     in
68 :     val {getFn = getStateVar, ...} = StV.newProp mkStateVar
69 :     end
70 :    
71 : jhr 1115 fun mkBlock stms = T.Block{locals=[], body=stms}
72 :     fun mkIf (x, stms, []) = T.S_IfThen(x, mkBlock stms)
73 :     | mkIf (x, stms1, stms2) = T.S_IfThenElse(x, mkBlock stms1, mkBlock stms2)
74 :    
75 :     (* an environment that tracks bindings of variables to target expressions and the list
76 :     * of locals that have been defined.
77 :     *)
78 :     local
79 :     structure VT = V.Tbl
80 :     fun decCount (IL.V{useCnt, ...}) = let
81 : jhr 2356 val n = !useCnt - 1
82 :     in
83 :     useCnt := n; (n <= 0)
84 :     end
85 : jhr 1115 datatype target_binding
86 : jhr 2356 = GLOB of T.var (* variable is global *)
87 :     | TREE of T.exp (* variable bound to target expression tree *)
88 :     | DEF of T.exp (* either a target variable or constant for a defined variable *)
89 : jhr 1115 datatype env = E of {
90 : jhr 2356 tbl : target_binding VT.hash_table,
91 :     locals : T.var list
92 :     }
93 : jhr 1115 in
94 :     (* DEBUG *)
95 :     fun bindToString binding = (case binding
96 :     of GLOB y => "GLOB " ^ T.Var.name y
97 : jhr 2356 | TREE e => "TREE"
98 :     | DEF(T.E_Var y) => "DEF " ^ T.Var.name y
99 :     | DEF e => "DEF"
100 : jhr 1115 (* end case *))
101 :     fun dumpEnv (E{tbl, ...}) = let
102 :     fun prEntry (x, binding) =
103 : jhr 2356 print(concat[" ", IL.Var.toString x, " --> ", bindToString binding, "\n"])
104 : jhr 1115 in
105 : jhr 2356 print "*** dump environment\n";
106 :     VT.appi prEntry tbl;
107 :     print "***\n"
108 : jhr 1115 end
109 :     (* DEBUG *)
110 :    
111 :     fun newEnv () = E{tbl = VT.mkTable (512, Fail "tbl"), locals=[]}
112 :    
113 :     (* use a variable. If it is a pending expression, we remove it from the table *)
114 :     fun useVar (env as E{tbl, ...}) x = (case VT.find tbl x
115 : jhr 2356 of SOME(GLOB x') => T.E_Var x'
116 :     | SOME(TREE e) => (
117 : jhr 1115 (*print(concat["useVar ", V.toString x, " ==> TREE\n"]);*)
118 : jhr 2356 ignore(VT.remove tbl x);
119 :     e)
120 :     | SOME(DEF e) => (
121 : jhr 1115 (*print(concat["useVar ", V.toString x, " ==> ", bindToString(DEF e), "; use count = ", Int.toString(V.useCount x), "\n"]);*)
122 : jhr 2356 (* if this is the last use of x, then remove it from the table *)
123 :     if (decCount x) then ignore(VT.remove tbl x) else ();
124 :     e)
125 :     | NONE => (
126 : jhr 1115 dumpEnv env;
127 :     raise Fail(concat ["useVar(", V.toString x, ")"])
128 :     )
129 : jhr 2356 (* end case *))
130 : jhr 1115
131 :     (* record a local variable *)
132 :     fun addLocal (E{tbl, locals}, x) = E{tbl=tbl, locals=x::locals}
133 :    
134 :     fun global (E{tbl, ...}, x, x') = VT.insert tbl (x, GLOB x')
135 :    
136 :     (* insert a pending expression into the table. Note that x should only be used once! *)
137 :     fun insert (env as E{tbl, ...}, x, exp) = (
138 : jhr 2356 VT.insert tbl (x, TREE exp);
139 :     env)
140 : jhr 1115
141 :     fun rename (env as E{tbl, ...}, x, x') = (
142 : jhr 2356 VT.insert tbl (x, DEF(T.E_Var x'));
143 :     env)
144 : jhr 1115
145 :     fun peekGlobal (E{tbl, ...}, x) = (case VT.find tbl x
146 : jhr 2356 of SOME(GLOB x') => SOME x'
147 :     | _ => NONE
148 :     (* end case *))
149 : jhr 1115
150 :     fun bindLocal (env, lhs, rhs) = if (V.useCount lhs = 1)
151 : jhr 2356 then (insert(env, lhs, rhs), [])
152 :     else let
153 :     val t = newLocal lhs
154 :     in
155 :     (rename(addLocal(env, t), lhs, t), [T.S_Assign([t], rhs)])
156 :     end
157 : jhr 1115
158 :     fun bind (env, lhs, rhs) = (case peekGlobal (env, lhs)
159 : jhr 2356 of SOME x => (env, [T.S_Assign([x], rhs)])
160 :     | NONE => bindLocal (env, lhs, rhs)
161 :     (* end case *))
162 : jhr 1115
163 :     (* set the definition of a variable, where the RHS is either a literal constant or a variable *)
164 :     fun bindSimple (env as E{tbl, ...}, lhs, rhs) = (
165 : jhr 2356 case peekGlobal (env, lhs)
166 :     of SOME x => (env, [T.S_Assign([x], rhs)])
167 :     | NONE => (VT.insert tbl (lhs, DEF rhs); (env, []))
168 :     (* end case *))
169 : jhr 1115
170 :     (* at the end of a block, we need to assign any pending expressions to locals. The
171 :     * blkStms list and the resulting statement list are in reverse order.
172 :     *)
173 :     fun flushPending (E{tbl, locals}, blkStms) = let
174 : jhr 2356 fun doVar (x, TREE e, (locals, stms)) = let
175 :     val t = newLocal x
176 :     in
177 :     VT.insert tbl (x, DEF(T.E_Var t));
178 :     (t::locals, T.S_Assign([t], e)::stms)
179 :     end
180 :     | doVar (_, _, acc) = acc
181 :     val (locals, stms) = VT.foldi doVar (locals, blkStms) tbl
182 :     in
183 :     (E{tbl=tbl, locals=locals}, stms)
184 :     end
185 : jhr 1115
186 :     fun doPhi ((lhs, rhs), (env, predBlks : T.stm list list)) = let
187 : jhr 2356 (* t will be the variable in the continuation of the JOIN *)
188 :     val t = newLocal lhs
189 :     val predBlks = ListPair.map
190 :     (fn (x, stms) => T.S_Assign([t], useVar env x)::stms)
191 :     (rhs, predBlks)
192 :     in
193 :     (rename (addLocal(env, t), lhs, t), predBlks)
194 :     end
195 : jhr 1115
196 :     fun endScope (E{locals, ...}, stms) = T.Block{
197 : jhr 2356 locals = List.rev locals,
198 :     body = stms
199 :     }
200 : jhr 1115
201 :     end
202 :    
203 :     (* Certain IL operators cannot be compiled to inline expressions. Return
204 :     * false for those and true for all others.
205 :     *)
206 :     fun isInlineOp rator = let
207 : jhr 2356 fun chkTensorTy (Ty.TensorTy[]) = true
208 :     | chkTensorTy (Ty.TensorTy[_]) = true
209 :     | chkTensorTy (Ty.TensorTy[_, _]) = Target.inlineMatrixExp
210 :     | chkTensorTy _ = false
211 :     in
212 :     case rator
213 :     of Op.LoadVoxels(_, 1) => true
214 :     | Op.LoadVoxels _ => false
215 :     | Op.Add ty => chkTensorTy ty
216 :     | Op.Sub ty => chkTensorTy ty
217 :     | Op.Neg ty => chkTensorTy ty
218 :     | Op.Scale ty => chkTensorTy ty
219 :     | Op.MulMatMat _ => Target.inlineMatrixExp
220 :     | Op.MulVecTen3 _ => false
221 :     | Op.MulTen3Vec _ => false
222 :     | Op.ColonMul(Ty.TensorTy dd1, Ty.TensorTy dd2) =>
223 :     (* if the result is a vector or scalar, then it is inline *)
224 :     (List.length dd1 + List.length dd2 > 5)
225 : jhr 1640 | Op.EigenVecs2x2 => false
226 :     | Op.EigenVecs3x3 => false
227 :     | Op.EigenVals2x2 => false
228 :     | Op.EigenVals3x3 => false
229 : jhr 2356 | Op.Identity _ => Target.inlineMatrixExp
230 :     | Op.Zero _ => Target.inlineMatrixExp
231 :     | Op.Transpose _ => false
232 :     | Op.TensorToWorldSpace(_, ty) => chkTensorTy ty
233 :     | _ => true
234 :     (* end case *)
235 :     end
236 : jhr 1115
237 :     (* translate a LowIL assignment to a list of zero or more target statements *)
238 :     fun doAssign (env, (lhs, rhs)) = let
239 : jhr 2356 fun doLHS () = (case peekGlobal(env, lhs)
240 :     of SOME lhs' => (env, lhs')
241 :     | NONE => let
242 :     val t = newLocal lhs
243 :     in
244 :     (rename (addLocal(env, t), lhs, t), t)
245 :     end
246 :     (* end case *))
247 :     (* for expressions that are going to be compiled to a call statement *)
248 :     fun assignExp (env, exp) = let
249 :     (* operations that return matrices may not be supported inline *)
250 :     val (env, t) = doLHS()
251 :     in
252 :     (env, [T.S_Assign([t], exp)])
253 :     end
254 :     in
255 :     case rhs
256 :     of IL.STATE x => bindSimple (env, lhs, T.E_State(getStateVar x))
257 : jhr 1640 | IL.VAR x => bindSimple (env, lhs, useVar env x)
258 : jhr 2356 | IL.LIT lit => bindSimple (env, lhs, T.E_Lit lit)
259 :     | IL.OP(Op.LoadImage info, [a]) => let
260 :     val (env, t) = doLHS()
261 :     in
262 :     (env, [T.S_LoadImage(t, ImageInfo.dim info, useVar env a)])
263 :     end
264 :     | IL.OP(Op.Input(ty, name, desc), []) => let
265 :     val (env, t) = doLHS()
266 :     in
267 :     (env, [T.S_Input(t, name, desc, NONE)])
268 :     end
269 :     | IL.OP(Op.InputWithDefault(ty, name, desc), [a]) => let
270 :     val (env, t) = doLHS()
271 :     in
272 :     (env, [T.S_Input(t, name, desc, SOME(useVar env a))])
273 :     end
274 :     | IL.OP(rator, args) => let
275 :     val exp = T.E_Op(rator, List.map (useVar env) args)
276 :     in
277 :     if isInlineOp rator
278 :     then bind (env, lhs, exp)
279 :     else assignExp (env, exp)
280 :     end
281 :     | IL.APPLY(f, args) =>
282 :     bind (env, lhs, T.E_Apply(f, List.map (useVar env) args))
283 :     | IL.CONS(ty, args) => let
284 :     val inline = (case ty
285 :     of Ty.SeqTy(Ty.IntTy, _) => true
286 :     | Ty.TensorTy dd => Target.inlineCons(List.length dd)
287 :     (* end case *))
288 :     val exp = T.E_Cons(ty, List.map (useVar env) args)
289 :     in
290 :     if inline
291 :     then bind (env, lhs, exp)
292 :     else assignExp (env, exp)
293 :     end
294 :     (* end case *)
295 :     end
296 : jhr 1115
297 :     (* In order to reconstruct the block-structure from the CFG, we keep a stack of open ifs.
298 :     * the items on this stack distinguish between when we are processing the then and else
299 :     * branches of the if.
300 :     *)
301 :     datatype open_if
302 :     (* working on the "then" branch. The fields are statments that preceed the if, the condition,
303 :     * and the else-branch node.
304 :     *)
305 :     = THEN_BR of T.stm list * T.exp * IL.node
306 :     (* working on the "else" branch. The fields are statments that preceed the if, the condition,
307 :     * the "then" branch statements, and the node that terminated the "then" branch (will be
308 :     * a JOIN, DIE, or STABILIZE).
309 :     *)
310 :     | ELSE_BR of T.stm list * T.exp * T.stm list * IL.node_kind
311 :    
312 :     fun trCFG (env, prefix, finish, cfg) = let
313 : jhr 2356 fun join (env, [], _, IL.JOIN _) = raise Fail "JOIN with no open if"
314 :     | join (env, [], stms, _) = endScope (env, prefix @ List.rev stms)
315 :     | join (env, THEN_BR(stms1, cond, elseBr)::stk, thenBlk, k) = let
316 :     val (env, thenBlk) = flushPending (env, thenBlk)
317 :     in
318 :     doNode (env, ELSE_BR(stms1, cond, thenBlk, k)::stk, [], elseBr)
319 :     end
320 :     | join (env, ELSE_BR(stms, cond, thenBlk, k1)::stk, elseBlk, k2) = let
321 :     val (env, elseBlk) = flushPending (env, elseBlk)
322 :     in
323 :     case (k1, k2)
324 :     of (IL.JOIN{phis, succ, ...}, IL.JOIN _) => let
325 :     val (env, [thenBlk, elseBlk]) =
326 :     List.foldl doPhi (env, [thenBlk, elseBlk]) (!phis)
327 :     val stm = mkIf(cond, List.rev thenBlk, List.rev elseBlk)
328 :     in
329 :     doNode (env, stk, stm::stms, !succ)
330 :     end
331 :     | (IL.JOIN{phis, succ, ...}, _) => let
332 :     val (env, [thenBlk]) = List.foldl doPhi (env, [thenBlk]) (!phis)
333 :     val stm = mkIf(cond, List.rev thenBlk, List.rev elseBlk)
334 :     in
335 :     doNode (env, stk, stm::stms, !succ)
336 :     end
337 :     | (_, IL.JOIN{phis, succ, ...}) => let
338 :     val (env, [elseBlk]) = List.foldl doPhi (env, [elseBlk]) (!phis)
339 :     val stm = mkIf(cond, List.rev thenBlk, List.rev elseBlk)
340 :     in
341 :     doNode (env, stk, stm::stms, !succ)
342 :     end
343 :     | (_, _) => raise Fail "no path to exit unimplemented" (* FIXME *)
344 :     (* end case *)
345 :     end
346 :     and doNode (env, ifStk : open_if list, stms, nd) = (
347 :     case Nd.kind nd
348 :     of IL.NULL => raise Fail "unexpected NULL"
349 :     | IL.ENTRY{succ} => doNode (env, ifStk, stms, !succ)
350 :     | k as IL.JOIN{phis, succ, ...} => join (env, ifStk, stms, k)
351 :     | IL.COND{cond, trueBranch, falseBranch, ...} => let
352 :     val cond = useVar env cond
353 :     val (env, stms) = flushPending (env, stms)
354 :     in
355 :     doNode (env, THEN_BR(stms, cond, !falseBranch)::ifStk, [], !trueBranch)
356 :     end
357 :     | IL.COM {text, succ, ...} =>
358 :     doNode (env, ifStk, T.S_Comment text :: stms, !succ)
359 :     | IL.ASSIGN{stm, succ, ...} => let
360 :     val (env, stms') = doAssign (env, stm)
361 :     in
362 :     doNode (env, ifStk, stms' @ stms, !succ)
363 :     end
364 : jhr 1640 | IL.MASSIGN{stm=(ys, rator, xs), succ, ...} => let
365 :     fun doit () = let
366 :     fun doLHSVar (y, (env, ys)) = (case peekGlobal(env, y)
367 :     of SOME y' => (env, y'::ys)
368 :     | NONE => let
369 :     val t = newLocal y
370 :     in
371 :     (rename (addLocal(env, t), y, t), t::ys)
372 :     end
373 :     (* end case *))
374 :     val (env, ys) = List.foldr doLHSVar (env, []) ys
375 :     val exp = T.E_Op(rator, List.map (useVar env) xs)
376 :     val stm = T.S_Assign(ys, exp)
377 :     in
378 :     doNode (env, ifStk, stm :: stms, !succ)
379 :     end
380 :     in
381 :     case rator
382 :     of Op.Print _ => if Target.supportsPrinting()
383 :     then doit ()
384 :     else doNode (env, ifStk, stms, !succ)
385 :     | _ => doit()
386 :     (* end case *)
387 :     end
388 : jhr 2356 | IL.NEW{strand, args, succ, ...} => raise Fail "NEW unimplemented"
389 : jhr 1640 | IL.SAVE{lhs, rhs, succ, ...} => let
390 :     val stm = T.S_Save([getStateVar lhs], useVar env rhs)
391 :     in
392 :     doNode (env, ifStk, stm::stms, !succ)
393 :     end
394 : jhr 2356 | k as IL.EXIT{kind, live, ...} => (case kind
395 :     of ExitKind.FRAGMENT =>
396 :     endScope (env, prefix @ List.revAppend(stms, finish env))
397 :     | ExitKind.SINIT => let
398 : jhr 1232 (* FIXME: we should probably call flushPending here! *)
399 : jhr 2356 val suffix = finish env @ [T.S_Exit[]]
400 :     in
401 :     endScope (env, prefix @ List.revAppend(stms, suffix))
402 :     end
403 :     | ExitKind.RETURN => let
404 : jhr 1115 (* FIXME: we should probably call flushPending here! *)
405 : jhr 2356 val suffix = finish env @ [T.S_Exit(List.map (useVar env) live)]
406 :     in
407 :     endScope (env, prefix @ List.revAppend(stms, suffix))
408 :     end
409 :     | ExitKind.ACTIVE => let
410 : jhr 1115 (* FIXME: we should probably call flushPending here! *)
411 : jhr 2356 val suffix = finish env @ [T.S_Active]
412 :     in
413 :     endScope (env, prefix @ List.revAppend(stms, suffix))
414 :     end
415 :     | ExitKind.STABILIZE => let
416 : jhr 1115 (* FIXME: we should probably call flushPending here! *)
417 : jhr 2356 val stms = T.S_Stabilize :: stms
418 :     in
419 : jhr 1115 (* FIXME: we should probably call flushPending here! *)
420 : jhr 2356 join (env, ifStk, stms, k)
421 :     end
422 :     | ExitKind.DIE => join (env, ifStk, T.S_Die :: stms, k)
423 :     (* end case *))
424 :     (* end case *))
425 :     in
426 :     doNode (env, [], [], CFG.entry cfg)
427 :     end
428 : jhr 1115
429 :     fun trInitially (env, IL.Initially{isArray, rangeInit, iters, create=(createInit, strand, args)}) =
430 : jhr 2356 let
431 :     val iterPrefix = trCFG (env, [], fn _ => [], rangeInit)
432 :     fun cvtIter ((param, lo, hi), (env, iters)) = let
433 :     val param' = newIter param
434 :     val env = rename (env, param, param')
435 :     in
436 :     (env, (param', useVar env lo, useVar env hi)::iters)
437 :     end
438 :     val (env, iters) = List.foldr cvtIter (env, []) iters
439 :     val createPrefix = trCFG (env, [], fn _ => [], createInit)
440 :     in {
441 :     isArray = isArray,
442 :     iterPrefix = iterPrefix,
443 :     iters = iters,
444 :     createPrefix = createPrefix,
445 :     strand = strand,
446 :     args = List.map (useVar env) args
447 :     } end
448 : jhr 1115
449 : jhr 1640 fun trMethod env (IL.Method{name, body}) = T.Method{
450 :     name = name,
451 :     body = trCFG (env, [], fn _ => [], body)
452 :     }
453 : jhr 1115
454 : jhr 1640 fun trStrand globalEnv (IL.Strand{name, params, state, stateInit, methods}) = let
455 : jhr 2356 val params' = List.map newParam params
456 :     val env = ListPair.foldlEq (fn (x, x', env) => rename(env, x, x')) globalEnv (params, params')
457 :     in
458 :     T.Strand{
459 :     name = name,
460 :     params = params',
461 :     state = List.map getStateVar state,
462 :     stateInit = trCFG (env, [], fn _ => [], stateInit),
463 :     methods = List.map (trMethod env) methods
464 :     }
465 :     end
466 : jhr 1115
467 : jhr 1301 (* split the globalInit into the part that specifies the inputs and the rest of
468 :     * the global initialization.
469 :     *)
470 :     fun splitGlobalInit globalInit = let
471 : jhr 2356 fun walk (nd, lastInput, live) = (case Nd.kind nd
472 :     of IL.ENTRY{succ} => walk (!succ, lastInput, live)
473 :     | IL.COM{succ, ...} => walk (!succ, lastInput, live)
474 :     | IL.ASSIGN{stm=(lhs, rhs), succ, ...} => (case rhs
475 :     of IL.OP(Op.Input _, _) => walk (!succ, nd, lhs::live)
476 :     | IL.OP(Op.InputWithDefault _, _) => walk (!succ, nd, lhs::live)
477 :     | _ => walk (!succ, lastInput, live)
478 :     (* end case *))
479 :     | _ => if Nd.isNULL lastInput
480 :     then let (* no inputs *)
481 :     val entry = Nd.mkENTRY()
482 :     val exit = Nd.mkEXIT(ExitKind.RETURN, [])
483 :     in
484 :     Nd.addEdge (entry, exit);
485 :     {inputInit = IL.CFG{entry=entry, exit=exit}, globalInit = globalInit}
486 :     end
487 :     else let (* split at lastInput *)
488 :     val inputExit = Nd.mkEXIT(ExitKind.RETURN, live)
489 :     val globalEntry = Nd.mkENTRY()
490 :     val [gFirst] = Nd.succs lastInput
491 :     in
492 :     Nd.replaceInEdge {src = lastInput, oldDst = gFirst, dst = inputExit};
493 :     Nd.replaceOutEdge {oldSrc = lastInput, src = globalEntry, dst = gFirst};
494 :     {
495 :     inputInit = IL.CFG{entry = IL.CFG.entry globalInit, exit = inputExit},
496 :     globalInit = IL.CFG{entry = globalEntry, exit = IL.CFG.exit globalInit}
497 :     }
498 :     end
499 :     (* end case *))
500 :     in
501 :     walk (IL.CFG.entry globalInit, Nd.dummy, [])
502 :     end
503 : jhr 1301
504 : jhr 1115 fun translate prog = let
505 : jhr 2356 (* first we do a variable analysis pass on the Low IL *)
506 :     val prog as IL.Program{props, globalInit, initially, strands} = VA.optimize prog
507 : jhr 1115 (* FIXME: here we should do a contraction pass to eliminate unused variables that VA may have created *)
508 : jhr 2356 val _ = (* DEBUG *)
509 :     LowPP.output (Log.logFile(), "LowIL after variable analysis", prog)
510 :     val env = newEnv()
511 :     val globals = List.map
512 :     (fn x => let val x' = newGlobal x in global(env, x, x'); x' end)
513 :     (IL.CFG.liveAtExit globalInit)
514 :     val {inputInit, globalInit} = splitGlobalInit globalInit
515 :     val strands = List.map (trStrand env) strands
516 :     in
517 :     T.Program{
518 :     props = props,
519 :     globals = globals,
520 :     inputInit = trCFG (env, [], fn _ => [], inputInit),
521 :     globalInit = trCFG (env, [], fn _ => [], globalInit),
522 :     strands = strands,
523 :     initially = trInitially (env, initially)
524 :     }
525 :     end
526 : jhr 1115
527 :     end

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