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 4842, Sun Sep 23 23:37:18 2018 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) *)
199      | splittable _             = true      | splittable _             = true
200    
201      (* tagged integers *)
202      fun tagInt n = CPS.NUM{
203              ival = IntInf.fromInt n,
204              ty = {tag = true, sz = Target.defaultIntSz}
205            }
206    
207    (*-------------------------------------------------------------------------    (*-------------------------------------------------------------------------
208     *     *
209     * All CPS functions can be independently processed.     * All CPS functions can be independently processed.
# Line 225  Line 230 
230        exception FloatSet        exception FloatSet
231        val floatSet = H.mkTable(32,FloatSet)        val floatSet = H.mkTable(32,FloatSet)
232        val addToFloatSet = H.insert floatSet        val addToFloatSet = H.insert floatSet
233        fun fp(r,CPS.FLTt) = addToFloatSet(r,true)        fun fp(r, CPS.FLTt _) = addToFloatSet(r,true)
234          | fp(r,_)        = ()          | fp(r,_)        = ()
235        exception RecordSet        exception RecordSet
236        val recordSet = H.mkTable(32,RecordSet)        val recordSet = H.mkTable(32,RecordSet)
# Line 242  Line 247 
247                  | _ => ()                  | _ => ()
248                )                )
249    
250        fun markPure(p,w) =        fun markPure (p, w) = (case p
251            case p of              (* these pure operators actually allocate storage! *)
252              (* these pure operators actually allocates storage! *)               of P.wrap(P.INT sz) => if (sz <= Target.defaultIntSz) then () else markrec(w, 0)
253              (P.fwrap | P.iwrap | P.i32wrap | P.newarray0 |                | (P.wrap(P.FLOAT _) | P.newarray0 | P.makeref | P.mkspecial | P.rawrecord _) =>
254               P.makeref | P.mkspecial | P.rawrecord _                    markrec(w, 0)
             ) => markrec(w, 0)  
255            | _ => ()            | _ => ()
256                (* end case *))
257    
258        fun markfp e =        fun markfp e =
259           case e of           case e of
# Line 261  Line 266 
266           | CPS.LOOKER(_,_,w,t,e)   => (fp(w,t); markfp e)           | CPS.LOOKER(_,_,w,t,e)   => (fp(w,t); markfp e)
267           | CPS.ARITH(_,_,w,t,e)    => (fp(w,t); markfp e)           | CPS.ARITH(_,_,w,t,e)    => (fp(w,t); markfp e)
268           | 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)
269           | CPS.RCC(_,_,w,t,e)      => (fp(w,t); markfp e)           | CPS.RCC(_,_,_,_,wtl,e)  => (app fp wtl; markfp e)
270           | CPS.BRANCH(_,_,_,e1,e2) => (markfp e1; markfp e2)           | CPS.BRANCH(_,_,_,e1,e2) => (markfp e1; markfp e2)
271           | CPS.FIX _ => error "FIX in Spill.markfp"           | CPS.FIX _ => error "FIX in Spill.markfp"
272    
# Line 341  Line 346 
346          | CPS.LOOKER(_,vl,w,t,e)   => uses(vl,def(w,freevars e))          | CPS.LOOKER(_,vl,w,t,e)   => uses(vl,def(w,freevars e))
347          | CPS.ARITH(_,vl,w,t,e)    => uses(vl,def(w,freevars e))          | CPS.ARITH(_,vl,w,t,e)    => uses(vl,def(w,freevars e))
348          | CPS.PURE(_,vl,w,t,e)     => uses(vl,def(w,freevars e))          | CPS.PURE(_,vl,w,t,e)     => uses(vl,def(w,freevars e))
349          | 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))
350                                                         (freevars e) wtl)
351          | CPS.BRANCH(_,vl,c,e1,e2) => uses(vl,freevars e1 \/ freevars e2)          | CPS.BRANCH(_,vl,c,e1,e2) => uses(vl,freevars e1 \/ freevars e2)
352          | CPS.FIX _ => error "FIX in Spill.freevars"          | CPS.FIX _ => error "FIX in Spill.freevars"
353    
# Line 467  Line 473 
473                | CPS.LOOKER(_,vl,w,t,e) => fx(vl, w, t, e, b)                | CPS.LOOKER(_,vl,w,t,e) => fx(vl, w, t, e, b)
474                | CPS.ARITH(_,vl,w,t,e)  => fx(vl, w, t, e, b)                | CPS.ARITH(_,vl,w,t,e)  => fx(vl, w, t, e, b)
475                | CPS.PURE(_,vl,w,t,e)   => fx(vl, w, t, e, b)                | CPS.PURE(_,vl,w,t,e)   => fx(vl, w, t, e, b)
476                | CPS.RCC(_,vl,w,t,e)    => fx(vl, w, t, e, b+1)                | CPS.RCC(_,_,_,vl,wtl,e)=>
477                      let val b = b+1
478                      in uses (vl, n);
479                         app (fn (w, t) => def (w, t, b, n)) wtl;
480                         gather (e, b, n+1)
481                      end
482                | 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))
483                | CPS.FIX _ => error "FIX in Spill.gather"                | CPS.FIX _ => error "FIX in Spill.gather"
484            end            end
# Line 622  Line 633 
633         *  spOff --- current available spill offset         *  spOff --- current available spill offset
634         *         *
635         * Return:         * Return:
        *  e      --- transformed cps expression  
636         *  L      --- the set of live lvars in e         *  L      --- the set of live lvars in e
637         *  spills --- the number of spills         *  spills --- the number of spills
638         *         *
# Line 708  Line 718 
718            | CPS.LOOKER(p,vl,w,t,e) => scanOp(vl, w, e, b)            | CPS.LOOKER(p,vl,w,t,e) => scanOp(vl, w, e, b)
719            | CPS.ARITH(p,vl,w,t,e)  => scanOp(vl, w, e, b)            | CPS.ARITH(p,vl,w,t,e)  => scanOp(vl, w, e, b)
720            | CPS.PURE(p,vl,w,t,e)   => scanOp(vl, w, e, b)            | CPS.PURE(p,vl,w,t,e)   => scanOp(vl, w, e, b)
721            | CPS.RCC(p,vl,w,t,e)    => scanOp(vl, w, e, b+1)            | CPS.RCC(k,l,p,vl,wtl,e)=>
722                let val b = b+1
723                    val (L,spOff) = scan(e,b,spOff)
724                    val L = foldl (fn ((w, _), L) => kill (w, L)) L wtl
725                    val L = addUses (vl, L)
726                    val (L, spOff) = genSpills (L, spOff)
727                in (L, spOff)
728                end
729            | CPS.BRANCH(p,vl,c,x,y) => scanStmt(vl,[x,y])            | CPS.BRANCH(p,vl,c,x,y) => scanStmt(vl,[x,y])
730            | CPS.FIX _ => error "FIX in Spill.scan"            | CPS.FIX _ => error "FIX in Spill.scan"
731    
# Line 766  Line 783 
783             NONE => e             NONE => e
784           | SOME(spillRecord, off, cty) =>           | SOME(spillRecord, off, cty) =>
785              CPS.SETTER(P.rawupdate cty,              CPS.SETTER(P.rawupdate cty,
786                 [spillRecord, CPS.INT off,CPS.VAR w], e)                 [spillRecord, tagInt off,CPS.VAR w], e)
787    
788        (*        (*
789         * Emit spill record code         * Emit spill record code
# Line 775  Line 792 
792          | createSpillRecord(numSpills, e) =          | createSpillRecord(numSpills, e) =
793        let val (spillRecLvar,_) = genSpillRec()        let val (spillRecLvar,_) = genSpillRec()
794            val m = numSpills * itemSize            val m = numSpills * itemSize
795            val e = CPS.PURE(P.rawrecord NONE,[CPS.INT m],            val e = CPS.PURE(P.rawrecord NONE,[tagInt m],
796                             spillRecLvar,CPS.BOGt,e)                             spillRecLvar,CPS.BOGt,e)
797        in  currentSpillRecord := NONE; (* clear *)        in  currentSpillRecord := NONE; (* clear *)
798            e            e
# Line 793  Line 810 
810                val e  = e v'                val e  = e v'
811            in  CPS.SELECT(i, CPS.VAR v, v', CPS.BOGt, e)            in  CPS.SELECT(i, CPS.VAR v, v', CPS.BOGt, e)
812            end            end
813            | proj _ = error "SpillFn: proj"
814    
815        (*        (*
816         * generate         * generate
# Line 801  Line 819 
819        fun initRecordItem(record, rk, offset, v, path, e) =        fun initRecordItem(record, rk, offset, v, path, e) =
820            proj(v, path,            proj(v, path,
821                 fn x => CPS.SETTER(P.rawupdate(rkToCty rk),                 fn x => CPS.SETTER(P.rawupdate(rkToCty rk),
822                           [CPS.VAR record, CPS.INT offset, CPS.VAR x], e))                           [CPS.VAR record, tagInt offset, CPS.VAR x], e))
823    
824        (*        (*
825         * Generate code to create a record.         * Generate code to create a record.
# Line 809  Line 827 
827        fun createRecord(record, rk, len, consts, e) =        fun createRecord(record, rk, len, consts, e) =
828        let val e = emitSpill(record, e)        let val e = emitSpill(record, e)
829            val p = P.rawupdate(rkToCty rk)            val p = P.rawupdate(rkToCty rk)
830            fun init((i, c),e) = CPS.SETTER(p,[CPS.VAR record, CPS.INT i, c], e)            fun init((i, c),e) = CPS.SETTER(p,[CPS.VAR record, tagInt i, c], e)
831            val e = foldr init e consts            val e = foldr init e consts
832            val e = CPS.PURE(P.rawrecord(SOME rk),[CPS.INT len],record,CPS.BOGt,e)            val e = CPS.PURE(P.rawrecord(SOME rk),[tagInt len],record,CPS.BOGt,e)
833        in  e        in  e
834        end        end
835    
# Line 862  Line 880 
880            in  g(f(vs, w, e))            in  g(f(vs, w, e))
881            end            end
882    
883              fun rewrite'(vs,wl,e,f) =
884                  let val e = rebuild e
885                      val e = foldl emitSpill e wl
886                      val e = foldl assignToSplitRecord e wl
887                      val (vs, g) = emitReloads vs
888                  in g (f (vs, wl, e))
889                  end
890    
891            fun rewriteRec(vl, w, e, f) =            fun rewriteRec(vl, w, e, f) =
892            let val e = rebuild e            let val e = rebuild e
893                val e = emitSpill(w, e)                val e = emitSpill(w, e)
# Line 870  Line 896 
896                else f(emitPathReloads vl, w, e)                else f(emitPathReloads vl, w, e)
897            end            end
898    
899              (* wrappers -- make the match compiler shut up *)
900              fun s1 f (v :: vs, es) = f (v, vs, es)
901                | s1 _ _ = error "Spill: s1"
902    
903              fun e1 f ([v], w, e) = f (v, w, e)
904                | e1 _ _ = error "Spill: e1"
905    
906              fun s'1 f (vs, [e]) = f (vs, e)
907                | s'1 _ _ = error "Spill: s'1"
908    
909              fun s'2 f (vs, [x, y]) = f (vs, x, y)
910                | s'2 _ _ = error "Spill: s'2"
911    
912            (*            (*
913             * Rewrite the expression             * Rewrite the expression
914             *)             *)
915            val e =            val e =
916            case e of            case e of
917              CPS.APP(v,args) =>              CPS.APP(v,args) =>
918                 rewriteStmt(v::args, [], fn (v::args,_) => CPS.APP(v,args))                 rewriteStmt(v::args, [], s1 (fn (v, args,_) => CPS.APP(v,args)))
919            | CPS.SWITCH(v,c,es) =>            | CPS.SWITCH(v,c,es) =>
920                 rewriteStmt([v], es, fn ([v], es) => CPS.SWITCH(v, c, es))                 rewriteStmt([v], es, s1 (fn (v, _, es) => CPS.SWITCH(v, c, es)))
921            | CPS.SELECT(i,v,w,t,e) =>            | CPS.SELECT(i,v,w,t,e) =>
922                 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)))
923            | CPS.OFFSET(i,v,w,e) =>            | CPS.OFFSET(i,v,w,e) =>
924                 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)))
925            | CPS.RECORD(k,l,w,e) =>            | CPS.RECORD(k,l,w,e) =>
926                 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))
927            | CPS.SETTER(p,vl,e) =>            | CPS.SETTER(p,vl,e) =>
928                 rewriteStmt(vl,[e],fn (vl,[e]) => CPS.SETTER(p,vl,e))                 rewriteStmt(vl, [e], s'1 (fn (vl,e) => CPS.SETTER(p,vl,e)))
929            | CPS.LOOKER(p,vl,w,t,e) =>            | CPS.LOOKER(p,vl,w,t,e) =>
930                 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))
931            | CPS.ARITH(p,vl,w,t,e) =>            | CPS.ARITH(p,vl,w,t,e) =>
932                 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))
933            | CPS.PURE(p,vl,w,t,e) =>            | CPS.PURE(p,vl,w,t,e) =>
934                 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))
935            | CPS.RCC(p,vl,w,t,e) =>            | CPS.RCC(k,l,p,vl,wtl,e) =>
936                 rewrite(vl,w,e,fn (vl,w,e) => CPS.RCC(p,vl,w,t,e))                rewrite' (vl, map #1 wtl, e,
937                            fn (vl, wl, e) => CPS.RCC (k, l, p, vl,
938                                                       ListPair.map (fn (w, (_, t)) => (w, t)) (wl, wtl),
939                                                       e))
940            | CPS.BRANCH(p,vl,c,x,y) =>            | CPS.BRANCH(p,vl,c,x,y) =>
941                 rewriteStmt(vl,[x,y], fn (vl,[x,y]) => CPS.BRANCH(p,vl,c,x,y))                 rewriteStmt(vl,[x,y],
942                               s'2 (fn (vl,x,y) => CPS.BRANCH(p,vl,c,x,y)))
943            | CPS.FIX _ => error "FIX in Spill.rebuild"            | CPS.FIX _ => error "FIX in Spill.rebuild"
944    
945        in  e        in  e

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

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