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/branches/primop-branch-3/compiler/CodeGen/amd64/amd64StackSpills.sml
ViewVC logotype

Annotation of /sml/branches/primop-branch-3/compiler/CodeGen/amd64/amd64StackSpills.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2221 - (view) (download)

1 : mblume 2066 signature AMD64STACKSPILLS = sig
2 :     structure I : AMD64INSTR
3 :     val init : unit -> unit
4 :     (* FIXME: this should be removed *)
5 :     val setAvailableOffsets : I.operand list -> unit
6 :     val setAvailableFPOffsets : I.operand list -> unit
7 :     val getRegLoc : int -> I.operand
8 :     val getFregLoc : int -> I.operand
9 :     end
10 :    
11 :     structure AMD64StackSpills : AMD64STACKSPILLS =
12 :     struct
13 :     exception RegSpills
14 :     structure I = AMD64Instr
15 :    
16 :     fun error msg = ErrorMsg.impossible ("AMD64StackSpills." ^ msg)
17 :    
18 :     val initialSpillOffset = AMD64Runtime.spillStart
19 :     val spillOffset = ref initialSpillOffset
20 :     val spillAreaSz = AMD64Runtime.spillAreaSz
21 :     val availableOffsets = ref [] : I.operand list ref
22 :     val availableFPOffsets = ref [] : I.operand list ref
23 :    
24 :     (* Indicate that some memory registers are not used and
25 :     * can be used for spilling.
26 :     *)
27 :     fun setAvailableOffsets offsets = availableOffsets := offsets
28 :     fun setAvailableFPOffsets offsets = availableFPOffsets := offsets
29 :    
30 :     fun newOffset n =
31 :     if (n > spillAreaSz) then error "newOffset - spill area is too small"
32 :     else spillOffset := n
33 :    
34 :     val spillTbl : I.operand IntHashTable.hash_table =
35 :     IntHashTable.mkTable(0, RegSpills)
36 :     val lookupTbl = IntHashTable.lookup spillTbl
37 :     val addTbl = IntHashTable.insert spillTbl
38 :    
39 :     fun init () =
40 :     (spillOffset:=initialSpillOffset;
41 :     availableOffsets := [];
42 :     availableFPOffsets := [];
43 :     IntHashTable.clear spillTbl
44 :     )
45 :    
46 :     val toInt32 = Int32.fromInt
47 :    
48 :     fun getRegLoc reg =
49 :     lookupTbl reg
50 :     handle _ =>
51 :     let val operand =
52 :     case !availableOffsets of
53 :     [] => let val offset = !spillOffset
54 :     val i32 = toInt32 offset
55 :     in newOffset(offset+4); I.Immed i32 end
56 :     | off::offs => (availableOffsets := offs; off)
57 :     in addTbl (reg,operand);
58 :     operand
59 :     end
60 :    
61 :     fun getFregLoc freg =
62 :     lookupTbl freg
63 :     handle _ =>
64 :     let val operand =
65 :     case !availableFPOffsets of
66 :     [] =>
67 :     let val offset = !spillOffset
68 :     val fromInt = Word.fromInt
69 :     val aligned = Word.toIntX(Word.andb(fromInt offset+0w7, fromInt ~8))
70 :     in newOffset(aligned+8); I.Immed(toInt32 aligned)
71 :     end
72 :     | off::offs => (availableFPOffsets := offs; off)
73 :     in addTbl (freg, operand);
74 :     operand
75 :     end
76 :     end

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