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/compiler/CodeGen/cpscompile/spill-new.sml
ViewVC logotype

Diff of /sml/trunk/compiler/CodeGen/cpscompile/spill-new.sml

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

sml/trunk/src/compiler/CodeGen/cpscompile/spill-new.sml revision 1126, Thu Mar 7 21:16:28 2002 UTC sml/trunk/compiler/CodeGen/cpscompile/spill-new.sml revision 4454, Thu Sep 21 18:25:19 2017 UTC
# Line 1  Line 1 
1  (* spill.sml  (* spill-new.sml
2     *
3     * COPYRIGHT (c) 2017 The Fellowship of SML/NJ (http://www.smlnj.org)
4     * All rights reserved.
5   *   *
  * Copyright 2002 by Bell Laboratories  
  *)  
   
 (*  
6   * This is a complete rewrite of the old Spill module.   * This is a complete rewrite of the old Spill module.
7   * The old module suffers from some serious performance problem but   * The old module suffers from some serious performance problem but
8   * I cannot decipher the old code fully, so instead of patching the problems up,   * I cannot decipher the old code fully, so instead of patching the problems up,
# Line 193  Line 192 
192       fun rmv(S, x) = Set.delete(S, x) handle _ => S       fun rmv(S, x) = Set.delete(S, x) handle _ => S
193    end    end
194    
195    fun rkToCty (CPS.RK_FCONT | CPS.RK_FBLOCK) = CPS.FLTt    fun rkToCty (CPS.RK_FCONT | CPS.RK_FBLOCK) = CPS.FLTt 64  (* REAL32: FIXME *)
196      | rkToCty _ = CPS.BOGt      | rkToCty _ = CPS.BOGt
197    
198    fun splittable CPS.RK_VECTOR = false (* not supported in backend (yet) *)    fun splittable CPS.RK_VECTOR = false (* not supported in backend (yet) *)
# Line 225  Line 224 
224        exception FloatSet        exception FloatSet
225        val floatSet = H.mkTable(32,FloatSet)        val floatSet = H.mkTable(32,FloatSet)
226        val addToFloatSet = H.insert floatSet        val addToFloatSet = H.insert floatSet
227        fun fp(r,CPS.FLTt) = addToFloatSet(r,true)        fun fp(r, CPS.FLTt _) = addToFloatSet(r,true)
228          | fp(r,_)        = ()          | fp(r,_)        = ()
229        exception RecordSet        exception RecordSet
230        val recordSet = H.mkTable(32,RecordSet)        val recordSet = H.mkTable(32,RecordSet)
# Line 261  Line 260 
260           | CPS.LOOKER(_,_,w,t,e)   => (fp(w,t); markfp e)           | CPS.LOOKER(_,_,w,t,e)   => (fp(w,t); markfp e)
261           | CPS.ARITH(_,_,w,t,e)    => (fp(w,t); markfp e)           | CPS.ARITH(_,_,w,t,e)    => (fp(w,t); markfp e)
262           | CPS.PURE(p,_,w,t,e)     => (markPure(p,w); fp(w,t); markfp e)           | CPS.PURE(p,_,w,t,e)     => (markPure(p,w); fp(w,t); markfp e)
263           | CPS.RCC(_,_,w,t,e)      => (fp(w,t); markfp e)           | CPS.RCC(_,_,_,_,wtl,e)  => (app fp wtl; markfp e)
264           | CPS.BRANCH(_,_,_,e1,e2) => (markfp e1; markfp e2)           | CPS.BRANCH(_,_,_,e1,e2) => (markfp e1; markfp e2)
265           | CPS.FIX _ => error "FIX in Spill.markfp"           | CPS.FIX _ => error "FIX in Spill.markfp"
266    
# Line 341  Line 340 
340          | CPS.LOOKER(_,vl,w,t,e)   => uses(vl,def(w,freevars e))          | CPS.LOOKER(_,vl,w,t,e)   => uses(vl,def(w,freevars e))
341          | CPS.ARITH(_,vl,w,t,e)    => uses(vl,def(w,freevars e))          | CPS.ARITH(_,vl,w,t,e)    => uses(vl,def(w,freevars e))
342          | CPS.PURE(_,vl,w,t,e)     => uses(vl,def(w,freevars e))          | CPS.PURE(_,vl,w,t,e)     => uses(vl,def(w,freevars e))
343          | CPS.RCC(_,vl,w,t,e)      => uses(vl,def(w,freevars e))          | CPS.RCC(_,_,_,vl,wtl,e)  => uses(vl, foldl (fn((w,_),s) => def(w,s))
344                                                         (freevars e) wtl)
345          | CPS.BRANCH(_,vl,c,e1,e2) => uses(vl,freevars e1 \/ freevars e2)          | CPS.BRANCH(_,vl,c,e1,e2) => uses(vl,freevars e1 \/ freevars e2)
346          | CPS.FIX _ => error "FIX in Spill.freevars"          | CPS.FIX _ => error "FIX in Spill.freevars"
347    
# Line 467  Line 467 
467                | CPS.LOOKER(_,vl,w,t,e) => fx(vl, w, t, e, b)                | CPS.LOOKER(_,vl,w,t,e) => fx(vl, w, t, e, b)
468                | CPS.ARITH(_,vl,w,t,e)  => fx(vl, w, t, e, b)                | CPS.ARITH(_,vl,w,t,e)  => fx(vl, w, t, e, b)
469                | CPS.PURE(_,vl,w,t,e)   => fx(vl, w, t, e, b)                | CPS.PURE(_,vl,w,t,e)   => fx(vl, w, t, e, b)
470                | CPS.RCC(_,vl,w,t,e)    => fx(vl, w, t, e, b+1)                | CPS.RCC(_,_,_,vl,wtl,e)=>
471                      let val b = b+1
472                      in uses (vl, n);
473                         app (fn (w, t) => def (w, t, b, n)) wtl;
474                         gather (e, b, n+1)
475                      end
476                | CPS.BRANCH(_,vl,c,x,y) => (uses(vl, n); gathers([x,y],b+1,n+1))                | CPS.BRANCH(_,vl,c,x,y) => (uses(vl, n); gathers([x,y],b+1,n+1))
477                | CPS.FIX _ => error "FIX in Spill.gather"                | CPS.FIX _ => error "FIX in Spill.gather"
478            end            end
# Line 622  Line 627 
627         *  spOff --- current available spill offset         *  spOff --- current available spill offset
628         *         *
629         * Return:         * Return:
        *  e      --- transformed cps expression  
630         *  L      --- the set of live lvars in e         *  L      --- the set of live lvars in e
631         *  spills --- the number of spills         *  spills --- the number of spills
632         *         *
# Line 708  Line 712 
712            | CPS.LOOKER(p,vl,w,t,e) => scanOp(vl, w, e, b)            | CPS.LOOKER(p,vl,w,t,e) => scanOp(vl, w, e, b)
713            | CPS.ARITH(p,vl,w,t,e)  => scanOp(vl, w, e, b)            | CPS.ARITH(p,vl,w,t,e)  => scanOp(vl, w, e, b)
714            | CPS.PURE(p,vl,w,t,e)   => scanOp(vl, w, e, b)            | CPS.PURE(p,vl,w,t,e)   => scanOp(vl, w, e, b)
715            | CPS.RCC(p,vl,w,t,e)    => scanOp(vl, w, e, b+1)            | CPS.RCC(k,l,p,vl,wtl,e)=>
716                let val b = b+1
717                    val (L,spOff) = scan(e,b,spOff)
718                    val L = foldl (fn ((w, _), L) => kill (w, L)) L wtl
719                    val L = addUses (vl, L)
720                    val (L, spOff) = genSpills (L, spOff)
721                in (L, spOff)
722                end
723            | CPS.BRANCH(p,vl,c,x,y) => scanStmt(vl,[x,y])            | CPS.BRANCH(p,vl,c,x,y) => scanStmt(vl,[x,y])
724            | CPS.FIX _ => error "FIX in Spill.scan"            | CPS.FIX _ => error "FIX in Spill.scan"
725    
# Line 793  Line 804 
804                val e  = e v'                val e  = e v'
805            in  CPS.SELECT(i, CPS.VAR v, v', CPS.BOGt, e)            in  CPS.SELECT(i, CPS.VAR v, v', CPS.BOGt, e)
806            end            end
807            | proj _ = error "SpillFn: proj"
808    
809        (*        (*
810         * generate         * generate
# Line 862  Line 874 
874            in  g(f(vs, w, e))            in  g(f(vs, w, e))
875            end            end
876    
877              fun rewrite'(vs,wl,e,f) =
878                  let val e = rebuild e
879                      val e = foldl emitSpill e wl
880                      val e = foldl assignToSplitRecord e wl
881                      val (vs, g) = emitReloads vs
882                  in g (f (vs, wl, e))
883                  end
884    
885            fun rewriteRec(vl, w, e, f) =            fun rewriteRec(vl, w, e, f) =
886            let val e = rebuild e            let val e = rebuild e
887                val e = emitSpill(w, e)                val e = emitSpill(w, e)
# Line 870  Line 890 
890                else f(emitPathReloads vl, w, e)                else f(emitPathReloads vl, w, e)
891            end            end
892    
893              (* wrappers -- make the match compiler shut up *)
894              fun s1 f (v :: vs, es) = f (v, vs, es)
895                | s1 _ _ = error "Spill: s1"
896    
897              fun e1 f ([v], w, e) = f (v, w, e)
898                | e1 _ _ = error "Spill: e1"
899    
900              fun s'1 f (vs, [e]) = f (vs, e)
901                | s'1 _ _ = error "Spill: s'1"
902    
903              fun s'2 f (vs, [x, y]) = f (vs, x, y)
904                | s'2 _ _ = error "Spill: s'2"
905    
906            (*            (*
907             * Rewrite the expression             * Rewrite the expression
908             *)             *)
909            val e =            val e =
910            case e of            case e of
911              CPS.APP(v,args) =>              CPS.APP(v,args) =>
912                 rewriteStmt(v::args, [], fn (v::args,_) => CPS.APP(v,args))                 rewriteStmt(v::args, [], s1 (fn (v, args,_) => CPS.APP(v,args)))
913            | CPS.SWITCH(v,c,es) =>            | CPS.SWITCH(v,c,es) =>
914                 rewriteStmt([v], es, fn ([v], es) => CPS.SWITCH(v, c, es))                 rewriteStmt([v], es, s1 (fn (v, _, es) => CPS.SWITCH(v, c, es)))
915            | CPS.SELECT(i,v,w,t,e) =>            | CPS.SELECT(i,v,w,t,e) =>
916                 rewrite([v], w, e, fn ([v],w,e) => CPS.SELECT(i,v,w,t,e))                 rewrite([v], w, e, e1 (fn (v,w,e) => CPS.SELECT(i,v,w,t,e)))
917            | CPS.OFFSET(i,v,w,e) =>            | CPS.OFFSET(i,v,w,e) =>
918                 rewrite([v], w, e, fn ([v],w,e) => CPS.OFFSET(i,v,w,e))                 rewrite([v], w, e, e1 (fn (v,w,e) => CPS.OFFSET(i,v,w,e)))
919            | CPS.RECORD(k,l,w,e) =>            | CPS.RECORD(k,l,w,e) =>
920                 rewriteRec(l,w,e,fn (l,w,e) => CPS.RECORD(k, l, w, e))                 rewriteRec(l,w,e,fn (l,w,e) => CPS.RECORD(k, l, w, e))
921            | CPS.SETTER(p,vl,e) =>            | CPS.SETTER(p,vl,e) =>
922                 rewriteStmt(vl,[e],fn (vl,[e]) => CPS.SETTER(p,vl,e))                 rewriteStmt(vl, [e], s'1 (fn (vl,e) => CPS.SETTER(p,vl,e)))
923            | CPS.LOOKER(p,vl,w,t,e) =>            | CPS.LOOKER(p,vl,w,t,e) =>
924                 rewrite(vl,w,e, fn (vl,w,e) => CPS.LOOKER(p,vl,w,t,e))                 rewrite(vl,w,e, fn (vl,w,e) => CPS.LOOKER(p,vl,w,t,e))
925            | CPS.ARITH(p,vl,w,t,e) =>            | CPS.ARITH(p,vl,w,t,e) =>
926                 rewrite(vl,w,e, fn (vl,w,e) => CPS.ARITH(p,vl,w,t,e))                 rewrite(vl,w,e, fn (vl,w,e) => CPS.ARITH(p,vl,w,t,e))
927            | CPS.PURE(p,vl,w,t,e) =>            | CPS.PURE(p,vl,w,t,e) =>
928                 rewrite(vl,w,e,fn (vl,w,e) => CPS.PURE(p,vl,w,t,e))                 rewrite(vl,w,e,fn (vl,w,e) => CPS.PURE(p,vl,w,t,e))
929            | CPS.RCC(p,vl,w,t,e) =>            | CPS.RCC(k,l,p,vl,wtl,e) =>
930                 rewrite(vl,w,e,fn (vl,w,e) => CPS.RCC(p,vl,w,t,e))                rewrite' (vl, map #1 wtl, e,
931                            fn (vl, wl, e) => CPS.RCC (k, l, p, vl,
932                                                       ListPair.map (fn (w, (_, t)) => (w, t)) (wl, wtl),
933                                                       e))
934            | CPS.BRANCH(p,vl,c,x,y) =>            | CPS.BRANCH(p,vl,c,x,y) =>
935                 rewriteStmt(vl,[x,y], fn (vl,[x,y]) => CPS.BRANCH(p,vl,c,x,y))                 rewriteStmt(vl,[x,y],
936                               s'2 (fn (vl,x,y) => CPS.BRANCH(p,vl,c,x,y)))
937            | CPS.FIX _ => error "FIX in Spill.rebuild"            | CPS.FIX _ => error "FIX in Spill.rebuild"
938    
939        in  e        in  e

Legend:
Removed from v.1126  
changed lines
  Added in v.4454

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