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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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