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

# SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/high-il/normalize.sml
 [diderot] / branches / vis12 / src / compiler / high-il / normalize.sml

# Diff of /branches/vis12/src/compiler/high-il/normalize.sml

revision 2196, Sun Feb 24 13:44:48 2013 UTC revision 2197, Sun Feb 24 14:15:22 2013 UTC
# Line 327  Line 327
327            (* end case *))            (* end case *))
328        | doRHS _ = NONE        | doRHS _ = NONE
329
330    (* simplify expressions *)      structure Rewrite = RewriteFn (
331      fun simplify (nd as IL.ND{kind=IL.ASSIGN{stm=(y, rhs), ...}, ...}) =        struct
332            if (useCount y = 0)          structure IL = IL
333              then () (* skip unused assignments *)          val doRHS = doRHS
334              else (case doRHS(y, rhs)          val elimUnusedVars = UnusedElim.reduce
335                 of SOME[] => IL.CFG.deleteNode nd        end)
| SOME assigns => let
val assigns = List.map
(fn (y, rhs) => (V.setBinding(y, IL.VB_RHS rhs); IL.ASSGN(y, rhs)))
assigns
in
IL.CFG.replaceNodeWithCFG (nd, IL.CFG.mkBlock assigns)
end
| NONE => ()
(* end case *))
| simplify _ = ()

fun loopToFixPt f = let
fun loop n = let
val () = f ()
val n' = Stats.sum{from=firstCounter, to=lastCounter}
in
if (n = n') then () else loop n'
end
in
loop (Stats.sum{from=firstCounter, to=lastCounter})
end
336
337      fun transform (prog as IL.Program{props, globalInit, initially, strands}) = let      val transform = Rewrite.transform
fun doCFG cfg = (
loopToFixPt (fn () => IL.CFG.apply simplify cfg);
loopToFixPt (fn () => ignore(UnusedElim.reduce cfg)))
fun doMethod (IL.Method{body, ...}) = doCFG body
fun doStrand (IL.Strand{stateInit, methods, ...}) = (
doCFG stateInit;
List.app doMethod methods)
fun optPass () = (
doCFG globalInit;
List.app doStrand strands)
in
loopToFixPt optPass;
(* FIXME: after optimization, we should filter out any globals that are now unused *)
IL.Program{
props = props,
globalInit = globalInit,
initially = initially,  (* FIXME: we should optimize this code *)
strands = strands
}
end
338
339    end    end

Legend:
 Removed from v.2196 changed lines Added in v.2197

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