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
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1639, Wed Nov 16 01:48:07 2011 UTC revision 1640, Wed Nov 16 02:19:51 2011 UTC
# Line 14  Line 14 
14      structure Op = HighOps      structure Op = HighOps
15      structure V = IL.Var      structure V = IL.Var
16      structure ST = Stats      structure ST = Stats
     structure F = FieldDef  
17    
18    (********** Counters for statistics **********)    (********** Counters for statistics **********)
19      val cntProbeAdd             = ST.newCounter "high-opt:probe-add"      val cntProbeAdd             = ST.newCounter "high-opt:probe-add"
# Line 160  Line 159 
159              then () (* skip unused assignments *)              then () (* skip unused assignments *)
160              else (case doRHS(y, rhs)              else (case doRHS(y, rhs)
161                 of SOME[] => IL.CFG.deleteNode nd                 of SOME[] => IL.CFG.deleteNode nd
162                  | SOME assigns => (                  | SOME assigns => let
163                      List.app (fn (y, rhs) => V.setBinding(y, IL.VB_RHS rhs)) assigns;                      val assigns = List.map
164                      IL.CFG.replaceNodeWithCFG (nd, IL.CFG.mkBlock assigns))                            (fn (y, rhs) => (V.setBinding(y, IL.VB_RHS rhs); IL.ASSGN(y, rhs)))
165                  | NONE => ()                              assigns
               (* end case *))  
       | simplify _ = ()  
   
   (* reduce the code by removing variables with use counts of 0 *)  
     local  
       fun checkVar (y, _) = (useCount y > 0) orelse (ST.tick cntUnused; false)  
     in  
     fun reduce (nd as IL.ND{kind, ...}) = (case kind  
            of IL.JOIN{phis, ...} => let  
                 fun doVar (y, xs) = if (useCount y = 0)  
                       then (  
                         ST.tick cntUnused;  
                         List.app decUse xs;  
                         false)  
                       else true  
166                  in                  in
167                    phis := List.filter doVar (!phis)                        IL.CFG.replaceNodeWithCFG (nd, IL.CFG.mkBlock assigns)
168                  end                  end
169              | IL.ASSIGN{stm=(y, rhs), ...} =>                  | NONE => ()
                 if (useCount y = 0)  
                   then (  
                     ST.tick cntUnused;  
                     case rhs  
                      of IL.VAR x => decUse x  
                       | IL.LIT _ => ()  
                       | IL.OP(_, xs) => List.app decUse xs  
                       | IL.APPLY(_, xs) => List.app decUse xs  
                       | IL.CONS(_, xs) => List.app decUse xs  
                     (* end case *);  
                     IL.CFG.deleteNode nd)  
                   else ()  
             | _ => ()  
170            (* end case *))            (* end case *))
171      end (* local *)        | simplify _ = ()
172    
173      fun loopToFixPt f = let      fun loopToFixPt f = let
174            fun loop n = let            fun loop n = let
# Line 210  Line 181 
181              loop (Stats.sum{from=firstCounter, to=lastCounter})              loop (Stats.sum{from=firstCounter, to=lastCounter})
182            end            end
183    
184      fun transform (prog as IL.Program{globalInit, initially, strands}) = let      fun transform (prog as IL.Program{props, globalInit, initially, strands}) = let
185            fun doCFG cfg = (            fun doCFG cfg = (
186                  loopToFixPt (fn () => IL.CFG.apply simplify cfg);                  loopToFixPt (fn () => IL.CFG.apply simplify cfg);
187                  loopToFixPt (fn () => ignore(UnusedElim.reduce cfg)))                  loopToFixPt (fn () => ignore(UnusedElim.reduce cfg)))
# Line 225  Line 196 
196              loopToFixPt optPass;              loopToFixPt optPass;
197  (* FIXME: after optimization, we should filter out any globals that are now unused *)  (* FIXME: after optimization, we should filter out any globals that are now unused *)
198              IL.Program{              IL.Program{
199                    props = props,
200                  globalInit = globalInit,                  globalInit = globalInit,
201                  initially = initially,  (* FIXME: we should optimize this code *)                  initially = initially,  (* FIXME: we should optimize this code *)
202                  strands = strands                  strands = strands

Legend:
Removed from v.1639  
changed lines
  Added in v.1640

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