SCM Repository
Annotation of /sml/trunk/src/compiler/FLINT/clos/staticprof.sml
Parent Directory
|
Revision Log
Revision 93 -
(view)
(download)
Original Path: sml/branches/SMLNJ/src/compiler/FLINT/clos/staticprof.sml
1 : | monnier | 16 | (* staticprof.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 1996 Bell Laboratories. | ||
4 : | * | ||
5 : | *) | ||
6 : | |||
7 : | signature STATICPROF = sig | ||
8 : | val initfk : unit -> unit | ||
9 : | val incfk : CPS.fun_kind * int -> unit | ||
10 : | val incln : int -> unit | ||
11 : | val reportfk : unit -> unit | ||
12 : | end | ||
13 : | |||
14 : | functor StaticProf (MachSpec : MACH_SPEC) : STATICPROF = struct | ||
15 : | |||
16 : | local open CPS | ||
17 : | structure CGoptions = Control.CG | ||
18 : | in | ||
19 : | |||
20 : | val pr = Control.Print.say | ||
21 : | val lenlimit = 40 | ||
22 : | val esize = Array.array(lenlimit+1,0) | ||
23 : | val ksize = Array.array(lenlimit+1,0) | ||
24 : | val csize = Array.array(lenlimit+1,0) | ||
25 : | val links = Array.array(11,0) | ||
26 : | val numvars = ref 0 | ||
27 : | val printf = app pr | ||
28 : | |||
29 : | fun zeroArray(a) = | ||
30 : | let val len = Array.length a | ||
31 : | fun h(n) = if n >= len then () | ||
32 : | else (Array.update(a,n,0); h(n+1)) | ||
33 : | in h(0) | ||
34 : | end | ||
35 : | |||
36 : | fun initfk() = (numvars := 0; | ||
37 : | app zeroArray [esize,ksize,csize,links]) | ||
38 : | |||
39 : | fun incfk(fk,sz) = | ||
40 : | let val a = case fk of ESCAPE => esize | ||
41 : | | CONT => csize | ||
42 : | | _ => ksize | ||
43 : | val i = if (sz >= lenlimit) then lenlimit-1 else sz | ||
44 : | val c = Array.sub(a,i) | ||
45 : | val s = Array.sub(a,lenlimit) | ||
46 : | in Array.update(a,i,c+1); | ||
47 : | Array.update(a,lenlimit,s+(sz+1)) | ||
48 : | end | ||
49 : | |||
50 : | fun incln(sz) = | ||
51 : | let val i = if (sz >= 10) then 10 else sz | ||
52 : | val n = !numvars | ||
53 : | val c = Array.sub(links,i) | ||
54 : | in numvars := n+sz; | ||
55 : | Array.update(links,i,c+1) | ||
56 : | end | ||
57 : | |||
58 : | val im = Int.toString | ||
59 : | fun field (st,w) = | ||
60 : | if w <= String.size st then st | ||
61 : | else let val s = " " ^ st | ||
62 : | in substring(s,String.size s - w, w) | ||
63 : | end | ||
64 : | |||
65 : | fun ifield(i,w) = if i=0 then field(" ",w) | ||
66 : | else (field(im i,w)) | ||
67 : | |||
68 : | fun fromto(m,n) = if m>n then [] else m::(fromto(m+1,n)) | ||
69 : | |||
70 : | fun reportsz(fk) = | ||
71 : | let val (a,s) = case fk of ESCAPE => (esize,"ESCAPE") | ||
72 : | | CONT => (csize, "CALLEE") | ||
73 : | | _ => (ksize,"KNOWN") | ||
74 : | fun loop(n,k,j) = | ||
75 : | if (k >= j) then (printf ["\n"]) | ||
76 : | else (printf [" | ",ifield(Array.sub(a,n+k),4)]; | ||
77 : | loop(n,k+1,j)) | ||
78 : | fun loop2(n) = | ||
79 : | if n >= lenlimit then () | ||
80 : | else (let val k = Int.min(10,lenlimit-n) | ||
81 : | in printf [ifield(n div 10,2)]; | ||
82 : | loop(n,0,k); | ||
83 : | loop2(n+k) | ||
84 : | end) | ||
85 : | val totalsize = Array.sub(a,lenlimit) | ||
86 : | in printf ["CSregs = ",im(MachSpec.numCalleeSaves), | ||
87 : | " Total Size = ",im(totalsize), | ||
88 : | " for ",s," functions: \n"]; | ||
89 : | printf [" "]; | ||
90 : | app (fn n => printf [" | ",ifield(n,4)]) [0,1,2,3,4,5,6,7,8,9]; | ||
91 : | pr "\n"; | ||
92 : | printf ["--"]; | ||
93 : | app (fn n => printf ["---","----"]) [0,1,2,3,4,5,6,7,8,9]; | ||
94 : | pr "\n"; | ||
95 : | loop2(0) | ||
96 : | end | ||
97 : | |||
98 : | fun reportfk() = | ||
99 : | let val s = Array.sub(esize,lenlimit) + | ||
100 : | Array.sub(csize,lenlimit) + | ||
101 : | Array.sub(ksize,lenlimit) | ||
102 : | in if s <> 0 then | ||
103 : | (printf ["**"]; | ||
104 : | app (fn n => printf ["*******"]) [0,1,2,3,4,5,6,7,8,9]; | ||
105 : | pr "\n"; | ||
106 : | printf ["CSregs = ",im(MachSpec.numCalleeSaves), | ||
107 : | " Total Links = ",im(!numvars), | ||
108 : | " for all variables: \n"]; | ||
109 : | printf [" "]; | ||
110 : | app (fn n => printf [" | ",ifield(Array.sub(links,n),4)]) | ||
111 : | (fromto(1,10)); | ||
112 : | pr "\n\n"; | ||
113 : | reportsz(ESCAPE); pr "\n\n"; | ||
114 : | reportsz(KNOWN); pr "\n\n"; | ||
115 : | reportsz(CONT); pr "\n\n"; | ||
116 : | printf ["**"]; | ||
117 : | app (fn n => printf ["*******"]) [0,1,2,3,4,5,6,7,8,9]; | ||
118 : | printf ["\n\n"]) | ||
119 : | else () | ||
120 : | end | ||
121 : | |||
122 : | end (* local *) | ||
123 : | end (* structure ReportSZ *) | ||
124 : | |||
125 : | (* | ||
126 : | * $Log: staticprof.sml,v $ | ||
127 : | monnier | 93 | * Revision 1.1.1.1 1998/04/08 18:39:46 george |
128 : | * Version 110.5 | ||
129 : | monnier | 16 | * |
130 : | *) |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |