Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/compiler/FLINT/opt/collect.sml
ViewVC logotype

Diff of /sml/trunk/src/compiler/FLINT/opt/collect.sml

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

revision 199, Wed Nov 25 18:30:38 1998 UTC revision 202, Sun Dec 13 02:29:45 1998 UTC
# Line 88  Line 88 
88      structure FU = FlintUtil      structure FU = FlintUtil
89      structure LV = LambdaVar      structure LV = LambdaVar
90      structure PP = PPFlint      structure PP = PPFlint
91        structure PO = PrimOp
92  in  in
93    
94  val say = Control.Print.say  val say = Control.Print.say
# Line 110  Line 111 
111    
112  (* map related helper functions *)  (* map related helper functions *)
113  fun get lv = (M.map m lv)  fun get lv = (M.map m lv)
114                    (* handle x as NotFound =>                    handle x as NotFound =>
115                    (say ("Collect: ERROR: get unknown var "^                    (say ("Collect: ERROR: get unknown var "^
116                          (LV.lvarName lv)^                          (LV.lvarName lv)^
117                          ". Pretending dead...\n");                          ". Pretending dead...\n");
118                     (*  raise x; *)                     (*  raise x; *)
119                     new NONE lv) *)                     new NONE lv)
120    
121  fun LVarString lv =  fun LVarString lv =
122      let val Info{uses=ref uses,calls=ref calls,...} = get lv      let val Info{uses=ref uses,calls=ref calls,...} = get lv
# Line 201  Line 202 
202           | [] => None           | [] => None
203      end      end
204    
205  fun impurePO po = true          (* if a PrimOP is pure or not *)  fun impurePO (po:F.primop) = not(PO.purePrimop (#2 po))
206    
207  val census = let  val census = let
208      (* val use = if inc then use else unuse *)      (* val use = if inc then use else unuse *)
# Line 211  Line 212 
212      fun newf args lv = new args lv      fun newf args lv = new args lv
213      fun id x = x      fun id x = x
214    
     fun impurePO po = true              (* if a PrimOP is pure or not *)  
   
215      (* here, the use resembles a call, but it's safer to consider it as a use *)      (* here, the use resembles a call, but it's safer to consider it as a use *)
216      fun cpo (NONE:F.dict option,po,lty,tycs) = ()      fun cpo (NONE:F.dict option,po,lty,tycs) = ()
217        | cpo (SOME{default,table},po,lty,tycs) =        | cpo (SOME{default,table},po,lty,tycs) =
# Line 258  Line 257 
257              (call (SOME vs) f; app use vs)              (call (SOME vs) f; app use vs)
258    
259            | F.TFN ((tf,args,body),le) =>            | F.TFN ((tf,args,body),le) =>
260              let val tfi = newf NONE tf              let val tfi = newf (SOME[]) tf
261              in cexp le; if used tfi then cexp body else ()              in cexp le; if used tfi then cexp body else ()
262              end              end
263    
264            | F.TAPP (F.VAR tf,tycs) => call NONE tf            | F.TAPP (F.VAR tf,tycs) => call (SOME[]) tf
265    
266            | F.SWITCH (v,cs,arms,def) =>            | F.SWITCH (v,cs,arms,def) =>
267              (use v; Option.map cexp def;              (use v; Option.map cexp def;
# Line 294  Line 293 
293            | F.PRIMOP (po,vs,lv,le) =>            | F.PRIMOP (po,vs,lv,le) =>
294              let val lvi = newv lv              let val lvi = newv lv
295              in cexp le;              in cexp le;
296                  if impurePO po orelse used lvi then (cpo po; app use vs) else ()                  if used lvi orelse impurePO po then (cpo po; app use vs) else ()
297              end              end
298    
299            | le => buglexp("unexpected lexp", le)            | le => buglexp("unexpected lexp", le)
# Line 389  Line 388 
388    
389            | F.PRIMOP (po,vs,lv,le) =>            | F.PRIMOP (po,vs,lv,le) =>
390              let val lvi = get lv              let val lvi = get lv
391              in if impurePO po orelse used lvi              in if used lvi orelse impurePO po
392                 then (cpo po; app unuse vs)                 then (cpo po; app unuse vs)
393                 else ();                 else ();
394                 def lvi; cexp le; kill lv                 def lvi; cexp le; kill lv
# Line 409  Line 408 
408  fun collect (fdec as (_,f,_,_)) =  fun collect (fdec as (_,f,_,_)) =
409      ((*  say "Entering Collect...\n"; *)      ((*  say "Entering Collect...\n"; *)
410       M.clear m;                         (* start from a fresh state *)       M.clear m;                         (* start from a fresh state *)
411       (* PP.LVarString := LVarString; *)       PP.LVarString := LVarString;
412       uselexp (F.FIX([fdec], F.RET[F.VAR f]));       uselexp (F.FIX([fdec], F.RET[F.VAR f]));
413       (*  say "...Collect Done.\n"; *)       (*  say "...Collect Done.\n"; *)
414       fdec)       fdec)

Legend:
Removed from v.199  
changed lines
  Added in v.202

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