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/memAliasing.sml
ViewVC logotype

Diff of /sml/trunk/compiler/CodeGen/cpscompile/memAliasing.sml

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

sml/trunk/src/compiler/CodeGen/cpscompile/memAliasing.sml revision 585, Wed Mar 29 23:55:35 2000 UTC sml/trunk/compiler/CodeGen/cpscompile/memAliasing.sml revision 4419, Mon Sep 18 21:53:44 2017 UTC
# Line 51  Line 51 
51    
52     fun error msg = MLRiscErrorMsg.error("MemAliasing",msg)     fun error msg = MLRiscErrorMsg.error("MemAliasing",msg)
53    
54       val cellSz = Cells.cellSize
55       val cellShift = (case cellSz of 4 => 0w2 | 8 => 0w3)
56    
57     (*     (*
58      * The following functions advances the heap pointer.      * The following functions advances the heap pointer.
59      * These functions are highly dependent on the runtime system and      * These functions are highly dependent on the runtime system and
60      * how data structures are represented.      * how data structures are represented.
61      * IMPORTANT: we are assuming that the new array representation is used.      * IMPORTANT: we are assuming that the new array representation is used.
62      *)      *)
63     fun recordSize(n,hp)  =  n * 4 + 4 + hp     fun recordSize (n,hp) = (n + 1) * cellSz + hp
64     fun frecordSize(n,hp) =   (* a record to hold n 64-bit floats; it needs to be 8-byte aligned on
65         let val hp = if Word.andb(Word.fromInt hp,0w4) <> 0w0 then hp+8 else hp+4    * 32-bit systems.
66         in  8*n + hp end    *)
67       fun frecordSize (n,hp) = let
68              val hp = if (cellSz = 8) orelse Word.andb(Word.fromInt hp,0w4) <> 0w0
69                    then hp + 8
70                    else hp + 4
71              in
72                8*n + hp
73              end
74     fun vectorSize(n,hp) = n * 4 + 16 + hp     fun vectorSize(n,hp) = n * 4 + 16 + hp
75    
76     fun allocRecord(C.RK_FBLOCK,vs,hp) = frecordSize(length vs,hp)     fun allocRecord(C.RK_FBLOCK,vs,hp) = frecordSize(length vs,hp)
# Line 68  Line 78 
78       | allocRecord(C.RK_VECTOR,vs,hp) = vectorSize(length vs,hp)       | allocRecord(C.RK_VECTOR,vs,hp) = vectorSize(length vs,hp)
79       | allocRecord(_,vs,hp) = recordSize(length vs,hp)       | allocRecord(_,vs,hp) = recordSize(length vs,hp)
80    
81     val storeListSize = 8     val storeListSize = 2 * cellSz       (* store-list elements *)
82     val array0Size    = 20     val array0Size    = 5 * cellSz       (* zero-length array *)
83    
84     exception NotFound     exception NotFound
85    
86       val top = CPSRegions.memory
87    
88     (*     (*
89      * Analyze a set of CPS functions      * Analyze a set of CPS functions
90      *)      *)
# Line 87  Line 99 
99               Int.max(sizeOf(k1,hp),sizeOf(k2,hp))               Int.max(sizeOf(k1,hp),sizeOf(k2,hp))
100           | sizeOf(C.SETTER(P.assign,vs,k),hp) = sizeOf(k,hp+storeListSize)           | sizeOf(C.SETTER(P.assign,vs,k),hp) = sizeOf(k,hp+storeListSize)
101           | sizeOf(C.SETTER(P.update,vs,k),hp) = sizeOf(k,hp+storeListSize)           | sizeOf(C.SETTER(P.update,vs,k),hp) = sizeOf(k,hp+storeListSize)
          | sizeOf(C.SETTER(P.boxedupdate,vs,k),hp) = sizeOf(k,hp+storeListSize)  
102           | sizeOf(C.SETTER(_,vs,k),hp) = sizeOf(k,hp)           | sizeOf(C.SETTER(_,vs,k),hp) = sizeOf(k,hp)
103           | sizeOf(C.PURE(P.fwrap,vs,x,cty,k),hp) = sizeOf(k,frecordSize(1,hp))           | sizeOf(C.PURE(P.fwrap,vs,x,cty,k),hp) = sizeOf(k,frecordSize(1,hp))
104           | sizeOf(C.PURE(P.mkspecial,vs,x,cty,k),hp) = sizeOf(k,hp+8)           | sizeOf(C.PURE(P.mkspecial,vs,x,cty,k),hp) = sizeOf(k, hp + 2*cellSz)
105           | sizeOf(C.PURE(P.makeref,vs,x,cty,k),hp) = sizeOf(k,hp+8)           | sizeOf(C.PURE(P.makeref,vs,x,cty,k),hp) = sizeOf(k, hp + 2*cellSz)
106           | sizeOf(C.PURE(P.i32wrap,vs,x,cty,k),hp) = sizeOf(k,hp+8)           | sizeOf(C.PURE(P.i32wrap,vs,x,cty,k),hp) = sizeOf(k, hp + 2*cellSz)
107           | sizeOf(C.PURE(P.newarray0,vs,x,cty,k),hp) = sizeOf(k,hp+array0Size)           | sizeOf(C.PURE(P.newarray0,vs,x,cty,k),hp) = sizeOf(k,hp+array0Size)
108           | sizeOf(C.PURE(p,vs,x,cty,k),hp) = sizeOf(k,hp)           | sizeOf(C.PURE(p,vs,x,cty,k),hp) = sizeOf(k,hp)
109           | sizeOf(C.ARITH(a,vs,x,cty,k),hp) = sizeOf(k,hp)           | sizeOf(C.ARITH(a,vs,x,cty,k),hp) = sizeOf(k,hp)
110           | sizeOf(C.LOOKER(lk,vs,x,cty,k),hp) = sizeOf(k,hp)           | sizeOf(C.LOOKER(lk,vs,x,cty,k),hp) = sizeOf(k,hp)
111             | sizeOf(C.RCC(_,_,_,_,_,k),hp) = sizeOf(k,hp)
112    
113         and sizeOfs([],hp)    = hp         and sizeOfs([],hp)    = hp
114           | sizeOfs(k::ks,hp) = Int.max(sizeOf(k,hp),sizeOfs(ks,hp))           | sizeOfs(k::ks,hp) = Int.max(sizeOf(k,hp),sizeOfs(ks,hp))
115    
116         val locMap = Intmap.new(37,NotFound) (* lvar -> loc *)         val locMap = IntHashTable.mkTable(37,NotFound) (* lvar -> loc *)
117         val look   = Intmap.map locMap         val look   = IntHashTable.lookup locMap
118         val bind   = Intmap.add locMap         val bind   = IntHashTable.insert locMap
119    
120         val newMem = Cells.newCell Cells.MEM         val newMem = Cells.newCell CellsBasis.MEM
121    
122         val _      = PT.reset newMem         val _      = PT.reset newMem
123    
# Line 163  Line 175 
175    
176             (* How to make a record *)             (* How to make a record *)
177             fun mkRec(f,getPaths,x,vs,hp) =             fun mkRec(f,getPaths,x,vs,hp) =
178                 let val i = Word.toInt(Word.>>(Word.fromInt hp,0w2))                 let val i = Word.toInt(Word.>>(Word.fromInt hp,cellShift))
179                     val r = f(SOME(Array.sub(table,i)),getPaths(vs,i+1))                     val r = f(SOME(Array.sub(table,i)),getPaths(vs,i+1))
180                 in  bind(x,r) end                 in  bind(x,r) end
181             fun mkFRecord(x,vs,hp) = mkRec(PT.mkRecord,getF64Paths,x,vs,hp)             fun mkFRecord(x,vs,hp) = mkRec(PT.mkRecord,getF64Paths,x,vs,hp)
# Line 175  Line 187 
187               | mkRecord(C.RK_VECTOR,x,vs,hp) = mkVector(x,vs,hp)               | mkRecord(C.RK_VECTOR,x,vs,hp) = mkVector(x,vs,hp)
188               | mkRecord(_,x,vs,hp) = mkNormalRecord(x,vs,hp)               | mkRecord(_,x,vs,hp) = mkNormalRecord(x,vs,hp)
189    
190               fun makeTop(m) = (PT.unify(m, top); top)
191    
192             (* CPS Pure Primitives *)             (* CPS Pure Primitives *)
193             fun arrayptr v = PT.strongSubscript(value v, 0)             fun arrayptr v = PT.pi(value v, 0)
194    
195             fun mkspecial(x,v,hp) = mkNormalRecord(x,[(v,off0)],hp)             fun mkspecial(x,v,hp) = mkNormalRecord(x,[(v,off0)],hp)
196             fun fwrap(x,v,hp) = mkFRecord(x,[(v,off0)],hp)             fun fwrap(x,v,hp) = mkFRecord(x,[(v,off0)],hp)
# Line 185  Line 199 
199             fun newarray0(x,hp) =             fun newarray0(x,hp) =
200                 bind(x,PT.mkRecord(NONE,[PT.mkRecord(NONE,[])]))                 bind(x,PT.mkRecord(NONE,[PT.mkRecord(NONE,[])]))
201    
202             fun objlength(x,v) = bind(x, PT.strongSubscript(value v, ~1))             fun objlength(x,v) = bind(x, PT.pi(value v, ~1))
203             fun length(x,v) = bind(x, PT.strongSubscript(value v, 1))             fun length(x,v) = bind(x, PT.pi(value v, 1))
204             fun arraysub(x,a,i) = bind(x,PT.weakSubscript(arrayptr a))             fun arraysub(x,a,i) = makeTop(PT.weakSubscript(arrayptr a))
205             fun subscriptv(x,a,i) = arraysub(x,a,i)             fun subscriptv(x,a,i) = arraysub(x,a,i)
206             fun subscript(x,a,i) = arraysub(x,a,i)             fun subscript(x,a,i) = arraysub(x,a,i)
207             fun pure_numsubscript(x,a,i) = arraysub(x,a,i)             fun pure_numsubscript(x,a,i) = arraysub(x,a,i)
208             fun gettag(x,v) = bind(x,PT.strongSubscript(value v, ~1))             fun gettag(x,v) = bind(x,PT.pi(value v, ~1))
209             fun numsubscript8(x,a,i) = arraysub(x,a,i)             fun numsubscript8(x,a,i) = arraysub(x,a,i)
210             fun numsubscriptf64(x,a,i) = arraysub(x,a,i)             fun numsubscriptf64(x,a,i) = arraysub(x,a,i)
211             fun getcon(x,v) = bind(x, PT.strongSubscript(value v,0))             fun getcon(x,v) = bind(x, PT.pi(value v,0))
212             fun getexn(x,v) = bind(x, PT.strongSubscript(value v,0))             fun getexn(x,v) = bind(x, PT.pi(value v,0))
213             fun recsubscript(x,a,i) = arraysub(x,a,i)             fun recsubscript(x,a,i) = arraysub(x,a,i)
214             fun raw64subscript(x,a,i) = arraysub(x,a,i)             fun raw64subscript(x,a,i) = arraysub(x,a,i)
215    
216             (* CPS Looker Primitives *)             (* CPS Looker Primitives *)
217             fun deref(x,v) = bind(x, PT.strongSubscript(value v, 0))             fun deref(x,v) = makeTop(PT.strongSubscript(value v, 0))
218             fun gethdlr x = bind(x, PT.strongSubscript(exnptr, 0))             fun gethdlr x = bind(x, PT.strongSubscript(exnptr, 0))
219             fun getvar x = bind(x, PT.strongSubscript(varptr, 0))             fun getvar x = bind(x, PT.strongSubscript(varptr, 0))
220    
221             (* CPS Setter Primitives *)             (* CPS Setter Primitives *)
222             fun supdate(a,x) = PT.strongUpdate(value a, 0, value x)             fun supdate(a,x) = PT.strongUpdate(value a, 0, makeTop(value x))
223             fun wupdate(a,x) = PT.weakUpdate(value a, value x)             fun wupdate(a,x) = PT.weakUpdate(value a, makeTop(value x))
224    
225               fun arrayupdate(a,i,x) = PT.weakUpdate(arrayptr a,value x)
226    
227             fun assign(a,x) = supdate(a,x)             fun assign(a,x) = supdate(a,x)
228             fun unboxedassign(a,x) = supdate(a,x)             fun unboxedassign(a,x) = supdate(a,x)
229             fun update(a,i,x) = wupdate(a,x)             fun update(a,i,x) = arrayupdate(a,i,x)
230             fun boxedupdate(a,i,x) = wupdate(a,x)             fun unboxedupdate(a,i,x) = arrayupdate(a,i,x)
231             fun numupdate(a,i,x) = wupdate(a,x)             fun numupdate(a,i,x) = arrayupdate(a,i,x)
232             fun numupdateF64(a,i,x) = wupdate(a,x)             fun numupdateF64(a,i,x) = arrayupdate(a,i,x)
233             fun sethdlr x = PT.strongUpdate(exnptr, 0, value x)             fun sethdlr x = PT.strongUpdate(exnptr, 0, value x)
234             fun setvar  x = PT.strongUpdate(varptr, 0, value x)             fun setvar  x = PT.strongUpdate(varptr, 0, value x)
235    
236               (* I don't know whether the following makes any sense...
237                * Basically, I want to ignore this aliasing analysis
238                * as far as raw access is concerned.  (The invariant is
239                * that raw access NEVER occurs to any memory location
240                * that ML "knows" about.  -- Blume (2000/1/1) *)
241               fun rawstore (a, x) = ()
242               fun rawload (a, x) = top
243    
244             fun infer(C.RECORD(rk,vs,x,k),hp) =             fun infer(C.RECORD(rk,vs,x,k),hp) =
245                   (mkRecord(rk,x,vs,hp); infer(k,allocRecord(rk,vs,hp)))                   (mkRecord(rk,x,vs,hp); infer(k,allocRecord(rk,vs,hp)))
246               | infer(C.SELECT(i,v,x,cty,k),hp) = (select(i,v,x); infer(k,hp))               | infer(C.SELECT(i,v,x,cty,k),hp) = (select(i,v,x); infer(k,hp))
# Line 273  Line 297 
297    
298               | infer(C.LOOKER(P.getvar,[],x,_,k),hp) = (getvar x; infer(k,hp))               | infer(C.LOOKER(P.getvar,[],x,_,k),hp) = (getvar x; infer(k,hp))
299    
300               | infer(C.LOOKER(P.deflvar,[],x,cty,k),hp) = infer(k,hp) (* nop! *)               | infer (C.LOOKER (P.rawload _, [a], x, _, k), hp) =
301                     (rawload (x, a); infer(k,hp))
302    
303                 (* Setters *)                 (* Setters *)
304               | infer(C.SETTER(P.assign, [a,v], k),hp) =               | infer(C.SETTER(P.assign, [a,v], k),hp) =
# Line 282  Line 307 
307                   (unboxedassign(a,v); infer(k,hp))                   (unboxedassign(a,v); infer(k,hp))
308               | infer(C.SETTER(P.update, [a,i,v], k),hp) =               | infer(C.SETTER(P.update, [a,i,v], k),hp) =
309                   (update(a,i,v); infer(k,hp+storeListSize))                   (update(a,i,v); infer(k,hp+storeListSize))
310               | infer(C.SETTER(P.boxedupdate, [a,i,v], k),hp) =               | infer(C.SETTER(P.unboxedupdate, [a,i,v], k), hp) =
311                   (boxedupdate(a,i,v); infer(k,hp+storeListSize))                   (unboxedupdate(a,i,v); infer(k,hp))
312               | infer(C.SETTER(P.numupdate{kind=P.INT _}, [a,i,v], k),hp) =               | infer(C.SETTER(P.numupdate{kind=P.INT _}, [a,i,v], k),hp) =
313                   (numupdate(a,i,v); infer(k,hp))                   (numupdate(a,i,v); infer(k,hp))
314               | infer(C.SETTER(P.numupdate{kind=P.FLOAT 64}, [a,i,v], k),hp) =               | infer(C.SETTER(P.numupdate{kind=P.FLOAT 64}, [a,i,v], k),hp) =
# Line 291  Line 316 
316    
317               | infer(C.SETTER(P.sethdlr, [x], k), hp) = (sethdlr x; infer(k,hp))               | infer(C.SETTER(P.sethdlr, [x], k), hp) = (sethdlr x; infer(k,hp))
318               | infer(C.SETTER(P.setvar, [x], k), hp) = (setvar x; infer(k,hp))               | infer(C.SETTER(P.setvar, [x], k), hp) = (setvar x; infer(k,hp))
319                 | infer (C.SETTER (P.rawstore _, [a, x], k), hp) =
320                     (rawstore (a, x); infer (k, hp))
321    
322                  (* Apparently these are nops (see MLRiscGen.sml) *)                  (* Apparently these are nops (see MLRiscGen.sml) *)
              | infer(C.SETTER(P.uselvar, [x], k), hp) = infer(k, hp)  
323               | infer(C.SETTER(P.acclink, _, k), hp) = infer(k, hp)               | infer(C.SETTER(P.acclink, _, k), hp) = infer(k, hp)
324               | infer(C.SETTER(P.setmark, _, k), hp) = infer(k, hp)               | infer(C.SETTER(P.setmark, _, k), hp) = infer(k, hp)
325               | infer(C.SETTER(P.free, [x], k), hp) = infer(k, hp)               | infer(C.SETTER(P.free, [x], k), hp) = infer(k, hp)
# Line 308  Line 334 
334         in infer(cexp, 0)         in infer(cexp, 0)
335         end         end
336    
        val top = CPSRegions.memory  
337     in  if !Control.CG.memDisambiguate then     in  if !Control.CG.memDisambiguate then
338         (CPSRegions.reset();         (CPSRegions.reset();
339          app defineFunction cpsFunctions;          app defineFunction cpsFunctions;

Legend:
Removed from v.585  
changed lines
  Added in v.4419

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