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

Annotation of /sml/trunk/src/MLRISC/ra/getreg2.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 744 - (view) (download)

1 : leunga 744 (* getreg2.sml
2 :     *
3 :     * COPYRIGHT (c) 1996 Bell Laboratories.
4 :     *
5 :     *)
6 :    
7 :     (** A simple first come/first serve register allocator **)
8 :     functor GetReg2(val first : int (* start from ``first'' *)
9 :     val nRegs : int (* n registers *)
10 :     val available : int list) : GETREG =
11 :     struct
12 :     exception GetReg
13 :     val size = first+nRegs
14 :     val allRegs = Array.array(size,false)
15 :     val preferred = Array.array(size,~1)
16 :    
17 :     fun reset () = Array.modify(fn _ => ~1) preferred
18 :    
19 :     val _ = app (fn r => Array.update(allRegs,r,true)) available
20 :    
21 :     fun getreg{pref,stamp:int,proh} =
22 :     let (* use preferred registers whenever possible *)
23 :     fun checkPreferred [] = find(first)
24 :     | checkPreferred(r::rs) =
25 :     if Array.sub(proh,r) <> stamp andalso
26 :     Array.sub(allRegs,r) then r
27 :     else checkPreferred rs
28 :    
29 :     and find(start) =
30 :     let val limit = Array.length allRegs
31 :     fun search r =
32 :     if Array.sub(proh,r) <> stamp andalso
33 :     Array.sub(allRegs,r) then r
34 :     else let val r = r+1
35 :     in if r >= limit then raise GetReg else search r
36 :     end
37 :     in search start
38 :     end
39 :     in checkPreferred pref end
40 :    
41 :     fun getpair{pref,stamp:int,proh} = raise GetReg (* unimplemented *)
42 :    
43 :     end
44 :    
45 :    
46 :    
47 :    

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