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

Annotation of /sml/trunk/src/compiler/CodeGen/x86/x86StackSpills.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 498 - (view) (download)
Original Path: sml/branches/SMLNJ/src/compiler/CodeGen/x86/x86StackSpills.sml

1 : monnier 247 signature X86STACKSPILLS = sig
2 :     structure I : X86INSTR
3 :     val init : unit -> unit
4 : monnier 498 val setAvailableOffsets : I.operand list -> unit
5 : monnier 247 val getRegLoc : int -> I.operand
6 :     val getFregLoc : int -> I.operand
7 :     end
8 :    
9 :     structure X86StackSpills : X86STACKSPILLS =
10 :     struct
11 :     exception RegSpills
12 :     structure I = X86Instr
13 :    
14 : monnier 498 fun error msg = ErrorMsg.impossible ("X86StackSpills." ^ msg)
15 : monnier 247
16 :     val initialSpillOffset = X86Runtime.spillStart
17 :     val spillOffset = ref initialSpillOffset
18 :     val spillAreaSz = X86Runtime.spillAreaSz
19 : monnier 498 val availableOffsets = ref [] : I.operand list ref
20 :    
21 :     (* Indicate that memory some memory registers are not used and
22 :     * can be used for spilling.
23 :     *)
24 :     fun setAvailableOffsets offsets = availableOffsets := offsets
25 :    
26 : monnier 247 fun newOffset n =
27 :     if (n > spillAreaSz) then error "newOffset - spill area is too small"
28 :     else spillOffset := n
29 :    
30 : monnier 498 val spillTbl : I.operand Intmap.intmap = Intmap.new(0, RegSpills)
31 :     val lookupTbl = Intmap.map spillTbl
32 :     val addTbl = Intmap.add spillTbl
33 : monnier 247
34 :     fun init () =
35 :     (spillOffset:=initialSpillOffset;
36 : monnier 498 availableOffsets := [];
37 :     Intmap.clear spillTbl
38 :     )
39 : monnier 247
40 :     val toInt32 = Int32.fromInt
41 :    
42 : monnier 498 fun getRegLoc (reg:int) =
43 :     lookupTbl reg
44 :     handle _ =>
45 :     let val operand =
46 :     case !availableOffsets of
47 :     [] => let val offset = !spillOffset
48 :     val i32 = toInt32 offset
49 :     in newOffset(offset+4); I.Immed i32 end
50 :     | off::offs => (availableOffsets := offs; off)
51 :     in addTbl (reg,operand);
52 :     operand
53 :     end
54 : monnier 247
55 : monnier 498 fun getFregLoc freg =
56 :     lookupTbl freg
57 :     handle _ =>
58 :     let val offset = !spillOffset
59 :     val fromInt = Word.fromInt
60 :     val aligned = Word.toIntX(Word.andb(fromInt offset+0w7, fromInt ~8))
61 :     val operand = I.Immed(toInt32 aligned)
62 :     in newOffset(aligned+8);
63 :     addTbl (freg, operand);
64 :     operand
65 :     end
66 : monnier 247 end

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