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

SCM Repository

[smlnj] View of /MLRISC/releases/release-110.64/ra/getreg2.sml
ViewVC logotype

View of /MLRISC/releases/release-110.64/ra/getreg2.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2656 - (download) (annotate)
Thu May 31 22:17:39 2007 UTC (12 years, 2 months ago) by blume
File size: 1308 byte(s)
Release 110.64
(* getreg2.sml
 *
 * COPYRIGHT (c) 1996 Bell Laboratories.
 *
 *)

(** A simple first come/first serve register allocator **)
functor GetReg2(val first : int  (* start from ``first'' *)
                val nRegs : int  (* n registers *)
	        val available : int list) : GETREG =
struct
  exception GetReg
  val size = first+nRegs
  val allRegs = Array.array(size,false)
  val preferred = Array.array(size,~1)

  fun reset () = Array.modify(fn _ => ~1) preferred

  val _ = app (fn r => Array.update(allRegs,r,true)) available

  fun getreg{pref,stamp:int,proh} = 
  let (* use preferred registers whenever possible *)
      fun checkPreferred [] = find(first)
        | checkPreferred(r::rs) = 
           if Array.sub(proh,r) <> stamp andalso 
              Array.sub(allRegs,r) then r 
           else checkPreferred rs

      and find(start) =
          let val limit = Array.length allRegs
              fun search r = 
              if Array.sub(proh,r) <> stamp andalso
                 Array.sub(allRegs,r) then r 
              else let val r = r+1
                   in  if r >= limit then raise GetReg else search r
                   end
          in  search start
          end
  in  checkPreferred pref end

  fun getpair{pref,stamp:int,proh} = raise GetReg (* unimplemented *)

end


    


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