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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2126 - (view) (download)

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 : george 545 fun getreg{pref,stamp:int,proh} =
24 : monnier 411 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 : allenleung 1436 in checkPreferred pref
49 :     end
50 : monnier 245
51 : allenleung 1436 val lastRegPair = ref first
52 :    
53 : allenleung 1433 fun getpair{pref, stamp:int, proh} = let
54 :     (* if not, use the round robin scheme to look for a register *)
55 :     fun find(start) = let
56 :     val limit = Array.length allRegs
57 :     fun search r =
58 :     if Array.sub(proh,r) <> stamp
59 :     andalso Array.sub(proh,r+1) <> stamp
60 :     andalso Array.sub(allRegs,r)
61 :     andalso Array.sub(allRegs,r+1) then r
62 : allenleung 1435 else let
63 :     val nxt = r+1
64 :     val nxtR = if nxt+1 >= limit then first else nxt
65 :     in
66 :     if nxtR = start then raise GetReg else search nxtR
67 : monnier 411 end
68 :     val found = search(start)
69 : allenleung 1433 val next = found + 1
70 : allenleung 1435 val next = if next+1 >= limit then first else next
71 : allenleung 1433 in
72 : allenleung 1436 lastRegPair := next;
73 : allenleung 1433 found
74 :     end
75 : allenleung 1436 in find(!lastRegPair)
76 : allenleung 1433 end
77 : monnier 245
78 :     end
79 :    
80 :    
81 :    
82 : monnier 498

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