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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 498 - (view) (download)
Original Path: sml/branches/SMLNJ/src/MLRISC/ra/getreg.sml

1 : monnier 245 (* getreg.sml
2 :     *
3 :     * COPYRIGHT (c) 1996 Bell Laboratories.
4 :     *
5 :     *)
6 :    
7 :     (** A simple round robin register allocator **)
8 : monnier 411 functor GetReg(val first : int (* start from ``first'' *)
9 :     val nRegs : int (* n registers *)
10 : monnier 245 val available : int list) : GETREG =
11 :     struct
12 :     exception GetReg
13 : monnier 411 val size = first+nRegs
14 :     val allRegs = Array.array(size,false)
15 :     val preferred = Array.array(size,~1)
16 : monnier 245
17 : monnier 411 val lastReg = ref first
18 : monnier 245
19 : monnier 411 fun reset () = (lastReg := first; Array.modify(fn _ => ~1) preferred)
20 : monnier 245
21 : monnier 411 val _ = app (fn r => Array.update(allRegs,r,true)) available
22 : monnier 245
23 : monnier 411 fun getreg{pref,stamp,proh} =
24 :     let (* use preferred registers whenever possible *)
25 :     fun checkPreferred [] = find(!lastReg)
26 :     | checkPreferred(r::rs) =
27 :     if Array.sub(proh,r) <> stamp andalso
28 :     Array.sub(allRegs,r) then r
29 :     else checkPreferred rs
30 : monnier 245
31 : monnier 411 (* if not, use the round robin scheme to look for a register *)
32 :     and find(start) =
33 :     let val limit = Array.length allRegs
34 :     fun search r =
35 :     if Array.sub(proh,r) <> stamp andalso
36 :     Array.sub(allRegs,r) then r
37 :     else let val r = r+1
38 :     val r = if r >= limit then first else r
39 :     in if r = start then raise GetReg
40 :     else search r
41 :     end
42 :     val found = search(start)
43 :     val next = found + 1
44 :     val next = if next >= limit then first else next
45 :     in lastReg := next;
46 :     found
47 :     end
48 :     in checkPreferred pref end
49 : monnier 245
50 : monnier 411 fun getpair{pref,stamp,proh} =
51 :     let (* if not, use the round robin scheme to look for a register *)
52 :     fun find(start) =
53 :     let val limit = Array.length allRegs
54 :     fun search r =
55 :     if Array.sub(proh,r) <> stamp andalso
56 :     Array.sub(proh,r+1) <> stamp andalso
57 :     Array.sub(allRegs,r) andalso
58 :     Array.sub(allRegs,r+1) then r
59 :     else let val r = r+2
60 :     val r = if r >= limit then first else r
61 :     in if r = start then raise GetReg
62 :     else search r
63 :     end
64 :     val found = search(start)
65 :     val next = found + 2
66 :     val next = if next >= limit then first else next
67 :     in lastReg := next;
68 :     found
69 :     end
70 :     in find(!lastReg) end
71 : monnier 245
72 :     end
73 :    
74 :    
75 :    
76 : monnier 498

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