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 /sml/branches/primop-branch/src/compiler/CodeGen/x86/x86StackSpills.sml
ViewVC logotype

View of /sml/branches/primop-branch/src/compiler/CodeGen/x86/x86StackSpills.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1372 - (download) (annotate)
Mon Sep 15 22:16:26 2003 UTC (17 years, 1 month ago)
File size: 2379 byte(s)
This commit was manufactured by cvs2svn to create branch
'primop-branch'.
signature X86STACKSPILLS = sig
  structure I : X86INSTR
  val init : unit -> unit
  val setAvailableOffsets : I.operand list -> unit
  val setAvailableFPOffsets : I.operand list -> unit
  val getRegLoc : int -> I.operand
  val getFregLoc : int -> I.operand
end

structure X86StackSpills : X86STACKSPILLS = 
struct
  exception RegSpills 
  structure I = X86Instr

  fun error msg = ErrorMsg.impossible ("X86StackSpills." ^ msg)

  val initialSpillOffset = X86Runtime.spillStart
  val spillOffset = ref initialSpillOffset
  val spillAreaSz = X86Runtime.spillAreaSz
  val availableOffsets = ref [] : I.operand list ref
  val availableFPOffsets = ref [] : I.operand list ref

  (* Indicate that memory some memory registers are not used and
   * can be used for spilling.
   *)
  fun setAvailableOffsets offsets = availableOffsets := offsets
  fun setAvailableFPOffsets offsets = availableFPOffsets := offsets

  fun newOffset n =
    if (n > spillAreaSz) then error "newOffset - spill area is too small"
    else spillOffset := n
  
  val spillTbl : I.operand IntHashTable.hash_table =
      IntHashTable.mkTable(0, RegSpills)
  val lookupTbl = IntHashTable.lookup spillTbl
  val addTbl    = IntHashTable.insert spillTbl

  fun init () = 
    (spillOffset:=initialSpillOffset; 
     availableOffsets := [];
     availableFPOffsets := [];
     IntHashTable.clear spillTbl
    )

  val toInt32 = Int32.fromInt

  fun getRegLoc reg = 
      lookupTbl reg
        handle _ => 
        let val operand = 
             case !availableOffsets of
               [] => let val offset = !spillOffset
                         val i32 = toInt32 offset
                     in  newOffset(offset+4); I.Immed i32 end
             | off::offs => (availableOffsets := offs; off) 
        in addTbl (reg,operand);
           operand
        end

  fun getFregLoc freg = 
      lookupTbl freg
        handle _ => 
        let val operand = 
             case !availableFPOffsets of
               [] =>
               let val offset = !spillOffset
                   val fromInt = Word.fromInt
                   val aligned = Word.toIntX(Word.andb(fromInt offset+0w7, fromInt ~8))
               in  newOffset(aligned+8); I.Immed(toInt32 aligned)
               end
             | off::offs => (availableFPOffsets := offs; off)
        in  addTbl (freg, operand);
            operand
        end
end

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