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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/instructions/cells.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/instructions/cells.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 889 - (view) (download)

1 : monnier 409 (*
2 : monnier 429 * Description of cell and other updatable cells.
3 : monnier 409 *
4 :     * -- Allen.
5 :     *)
6 : leunga 744
7 :     (*
8 :     * This functor is applied to create the cells structure for an architecture
9 :     *)
10 : george 889 functor Cells
11 : leunga 744 (exception Cells
12 :     val firstPseudo : int
13 :     val cellKindDescs : (CellsBasis.cellkind * CellsBasis.cellkindDesc) list
14 : george 889 ) : CELLS =
15 : monnier 409 struct
16 : leunga 744
17 : george 889 open CellsBasis
18 : leunga 744
19 : monnier 409 exception Cells = Cells
20 :    
21 : leunga 775 val i2s = Int.toString
22 :    
23 : leunga 744 fun error msg = MLRiscErrorMsg.error(exnName Cells, msg)
24 : monnier 409
25 : george 823 val cellkinds = map (fn (kind,_) => kind) cellKindDescs
26 :     val firstPseudo = firstPseudo
27 :     val maxDedicatedCells = 256
28 :     val firstName = firstPseudo + maxDedicatedCells
29 :     val name = ref firstName
30 :     (* val cellCounter = name *)
31 : monnier 409
32 : leunga 744 val _ = app (fn (_, desc as DESC{physicalRegs, high, low, ...}) =>
33 :     let val n = high - low + 1
34 :     in if n <= 0 then ()
35 :     else let val a = Array.tabulate(n, fn nth =>
36 :     let val reg = nth + low
37 :     in CELL{id=reg, col=ref(MACHINE reg),
38 :     an=ref [], desc=desc}
39 :     end)
40 :     in physicalRegs := a
41 :     end
42 :     end) cellKindDescs
43 : monnier 409
44 : leunga 744 fun nextName() = let val id = !name in name := !name + 1; id end
45 : monnier 409
46 : leunga 744 fun desc(k:cellkind) =
47 :     let fun loop [] = error("missing info for "^cellkindToString k)
48 :     | loop((kind,info)::defs) =
49 :     if kind = k then info else loop defs
50 :     in loop cellKindDescs end
51 : monnier 409
52 : leunga 775 val cellkindDesc = desc
53 :    
54 : leunga 744 fun cellRange k =
55 :     let val DESC{low,high,...} = desc k
56 :     in {low=low,high=high} end
57 :    
58 : monnier 409 fun Reg k =
59 : leunga 744 let val desc as DESC{low,kind,physicalRegs,...} = desc k
60 :     in fn nth => Array.sub(!physicalRegs,nth) handle _ => raise Cells
61 : monnier 409 end
62 :    
63 : leunga 744 fun Regs k =
64 :     let val Reg = Reg k
65 :     fun loop{from, to, step} =
66 :     if from > to then []
67 :     else Reg from :: loop{from=from+step, to=to, step=step}
68 :     in loop end
69 : monnier 409
70 : leunga 744 fun Cell k =
71 :     let val desc as DESC{low,kind,physicalRegs,...} = desc k
72 :     in fn reg =>
73 :     Array.sub(!physicalRegs,reg - low) handle _ => raise Cells
74 :     end
75 :    
76 :     val GPReg = Reg GP
77 :     val FPReg = Reg FP
78 :    
79 :     (* Counters *)
80 :     fun newCell k =
81 :     let val desc as DESC{counter,...} = desc k
82 : monnier 429 in fn _ =>
83 : monnier 409 let val r = !name
84 :     in name := r + 1;
85 : leunga 744 counter := !counter + 1;
86 :     CELL{id=r, col=ref PSEUDO, an=ref [], desc=desc}
87 : monnier 409 end
88 :     end
89 :    
90 : leunga 744 local val desc as DESC{counter, ...} = desc GP
91 : monnier 429 in fun newReg _ =
92 :     let val r = !name
93 :     in name := r + 1;
94 : leunga 744 counter := !counter + 1;
95 :     CELL{id=r, col=ref PSEUDO, an=ref [], desc=desc}
96 : monnier 429 end
97 :     end
98 : monnier 409
99 : leunga 744 local val desc as DESC{counter, ...} = desc FP
100 : monnier 429 in fun newFreg _ =
101 :     let val r = !name
102 :     in name := r + 1;
103 : leunga 744 counter := !counter + 1;
104 :     CELL{id=r, col=ref PSEUDO, an=ref [], desc=desc}
105 : monnier 429 end
106 :     end
107 :    
108 : george 823 fun newDedicatedCell k =
109 :     let val desc as DESC{dedicated,...} = desc k
110 :     in fn _ =>
111 :     let val d = !dedicated
112 :     in dedicated := d + 1;
113 :     if d >= maxDedicatedCells then
114 :     error "too many dedicated cells"
115 :     else
116 :     CELL{id=firstPseudo+d, col=ref PSEUDO, an=ref [], desc=desc}
117 :     end
118 :     end
119 :    
120 : leunga 744 fun newVar (CELL{desc, an, ...}) =
121 : monnier 409 let val r = !name
122 : leunga 744 in name := r + 1;
123 :     CELL{id=r, col=ref PSEUDO, an=ref(!an), desc=desc}
124 : monnier 409 end
125 :    
126 : leunga 744 fun cloneCell c =
127 :     let val CELL{desc, an, col, ...} = chase c
128 :     val r = !name
129 :     in name := r + 1;
130 :     CELL{id=r, col=ref(!col), an=ref(!an), desc=desc}
131 :     end
132 :    
133 :     fun numCell k = let val DESC{counter, ...} = desc k
134 :     in fn () => !counter end
135 : monnier 409
136 :     fun maxCell() = !name
137 :    
138 : leunga 744 fun reset() =
139 :     (app (fn (_,DESC{counter, ...}) => counter := 0) cellKindDescs;
140 : george 823 name := firstName
141 : leunga 744 )
142 : monnier 409
143 : george 889
144 : leunga 744 structure CellSet =
145 :     struct
146 :     type cellset = (cellkindDesc * cell list) list
147 :     val empty = []
148 : monnier 409
149 : leunga 744 fun same(DESC{counter=c1,...}, DESC{counter=c2,...}) = c1=c2
150 : monnier 409
151 : leunga 744 fun descOf (CELL{desc, ...}) = desc
152 : monnier 409
153 : leunga 744 fun add (r, cellset:cellset) =
154 :     let val k = descOf r
155 :     fun loop [] = [(k,[r])]
156 :     | loop((x as (k',s))::cellset) =
157 :     if same(k,k') then (k',r::s)::cellset
158 :     else x::loop cellset
159 :     in loop cellset end
160 : leunga 657
161 : leunga 744 fun rmv (r, cellset:cellset) =
162 :     let val k = descOf r
163 :     val c = registerId r
164 :     fun filter [] = []
165 :     | filter(r::rs) = if registerId r = c then filter rs
166 :     else r::filter rs
167 :     fun loop [] = []
168 :     | loop((x as (k',s))::cellset) =
169 :     if same(k,k') then (k',filter s)::cellset else x::loop cellset
170 :     in loop cellset end
171 :    
172 :     fun get' k (cellset:cellset) =
173 :     let fun loop [] = []
174 :     | loop((x as (k',s))::cellset) =
175 :     if same(k,k') then s else loop cellset
176 :     in loop cellset end
177 :    
178 : george 889 fun get (k: cellkind) = get'(desc k)
179 : leunga 744
180 :     fun update' k (cellset:cellset,s) =
181 :     let fun loop [] = [(k,s)]
182 :     | loop((x as (k',_))::cellset) =
183 :     if same(k,k') then (k',s)::cellset else x::loop cellset
184 :     in loop cellset end
185 :    
186 :     fun update k = update'(desc k)
187 :    
188 :     fun map {from,to} (cellset:cellset) =
189 :     let val CELL{desc=k,...} = from
190 :     val cf = registerId from
191 :     fun trans r = if registerId r = cf then to else r
192 :     fun loop [] = []
193 :     | loop((x as (k',s))::cellset) =
194 :     if same(k,k') then (k',List.map trans s)::cellset
195 :     else x::loop cellset
196 :     in loop cellset end
197 :    
198 :     val toCellList : cellset -> cell list =
199 :     List.foldr (fn ((_,S),S') => S @ S') []
200 :    
201 :     (* Pretty print cellset *)
202 :     fun printSet(f,set,S) =
203 :     let fun loop([], S) = "}"::S
204 :     | loop([x], S) = f(chase x)::"}"::S
205 :     | loop(x::xs, S) = f(chase x)::" "::loop(xs, S)
206 :     in "{"::loop(set, S) end
207 :    
208 :     fun toString' cellset =
209 :     let fun pr cellset =
210 :     let fun loop((DESC{kind, toString, ...},s)::rest, S)=
211 :     (case s of
212 :     [] => loop(rest, S)
213 :     | _ => cellkindToString kind::"="::
214 :     printSet(toString o registerId,s," "::loop(rest,S))
215 :     )
216 :     | loop([],S) = S
217 :     in String.concat(loop(cellset, []))
218 :     end
219 :     in pr cellset end
220 :    
221 :     val toString = toString'
222 : george 889 end (* CellSet *)
223 : leunga 744
224 :     type cellset = CellSet.cellset
225 :     val empty = CellSet.empty
226 :     val getReg = CellSet.get GP
227 :     val getFreg = CellSet.get FP
228 :     val addReg = CellSet.add
229 :     val addFreg = CellSet.add
230 :     val rmvReg = CellSet.rmv
231 :     val rmvFreg = CellSet.rmv
232 :    
233 :     (* Misc *)
234 :     fun zeroReg k =
235 :     let val desc as DESC{zeroReg, physicalRegs, low, ...} = desc k
236 :     in case zeroReg of
237 :     NONE => NONE
238 :     | SOME r => SOME(Array.sub(!physicalRegs, r))
239 :     end
240 :    
241 :     fun defaultValues k =
242 :     let val DESC{defaultValues, ...} = desc k
243 :     in defaultValues end
244 : george 889
245 :     (* dummy values for now; these get redefined for each architecture *)
246 :     val stackptrR = GPReg 0
247 :     val asmTmpR = GPReg 0
248 :     val fasmTmp = FPReg 0
249 : monnier 409 end

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