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

SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/x86/instructions/x86Props.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/x86/instructions/x86Props.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 796, Tue Mar 6 00:04:33 2001 UTC revision 1156, Thu Mar 21 22:01:11 2002 UTC
# Line 3  Line 3 
3   * COPYRIGHT (c) 1997 Bell Laboratories.   * COPYRIGHT (c) 1997 Bell Laboratories.
4   *)   *)
5    
6  functor X86Props(X86Instr : X86INSTR) : INSN_PROPERTIES =  functor X86Props
7      (structure Instr : X86INSTR
8       structure MLTreeHash : MLTREE_HASH where T = Instr.T
9       structure MLTreeEval : MLTREE_EVAL where T = Instr.T
10      ) : INSN_PROPERTIES =
11  struct  struct
12    structure I = X86Instr    structure I = Instr
13    structure C = I.C    structure C = I.C
   structure LE = I.LabelExp  
14    structure T = I.T    structure T = I.T
15      structure CB = CellsBasis
16    
17    exception NegateConditional    exception NegateConditional
18    
# Line 20  Line 24 
24   (*========================================================================   (*========================================================================
25    *  Instruction Kinds    *  Instruction Kinds
26    *========================================================================*)    *========================================================================*)
27    fun instrKind (I.JMP _) = IK_JUMP    fun instrKind (I.ANNOTATION{i, ...}) = instrKind i
     | instrKind (I.JCC _) = IK_JUMP  
28      | instrKind (I.COPY _) = IK_COPY      | instrKind (I.COPY _) = IK_COPY
29      | instrKind (I.FCOPY _) = IK_COPY      | instrKind (I.INSTR i)  =
30      | instrKind (I.CALL{cutsTo=_::_,...}) = IK_CALL_WITH_CUTS         (case i
31      | instrKind (I.CALL _) = IK_CALL           of I.JMP _ => IK_JUMP
32      | instrKind (I.PHI _)    = IK_PHI            | I.JCC _ => IK_JUMP
33      | instrKind (I.SOURCE _) = IK_SOURCE            | I.CALL{cutsTo=_::_,...} => IK_CALL_WITH_CUTS
34      | instrKind (I.SINK _)   = IK_SINK            | I.CALL _ => IK_CALL
35      | instrKind (I.RET _) = IK_JUMP            | I.PHI _    => IK_PHI
36      | instrKind (I.ANNOTATION{i,...}) = instrKind i            | I.SOURCE _ => IK_SOURCE
37              | I.SINK _   => IK_SINK
38              | I.RET _ => IK_JUMP
39              | I.INTO => IK_JUMP
40              | _ => IK_INSTR)
41      | instrKind _ = IK_INSTR      | instrKind _ = IK_INSTR
42    
43      fun moveInstr(I.ANNOTATION{i, ...}) = moveInstr i
44        | moveInstr(I.LIVE _) = false
45        | moveInstr(I.KILL _) = false
46        | moveInstr(I.COPY _) = true
47        | moveInstr(I.INSTR i)  =
48           (case i
49             of I.MOVE{mvOp=I.MOVL, src=I.Direct _, dst=I.MemReg _, ...} => true
50              | I.MOVE{mvOp=I.MOVL, src=I.MemReg _, dst=I.Direct _, ...} => true
51              | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FPR _, ...} => true
52              | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FDirect _, ...} => true
53              | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FPR _, ...} => true
54              | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FDirect _, ...} => true
55              | _ => false )
56    
57    
58      fun isMemMove(I.INSTR(i)) =
59          (case i
60            of I.MOVE{mvOp=I.MOVL, src=I.Direct _, dst=I.MemReg _, ...} => true
61             | I.MOVE{mvOp=I.MOVL, src=I.MemReg _, dst=I.Direct _, ...} => true
62             | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FPR _, ...} => true
63             | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FDirect _, ...} => true
64             | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FPR _, ...} => true
65             | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FDirect _, ...} => true
66             | _ => false
67          (*esac*))
68        | isMemMove _ = false
69    
70    
71      fun memMove(I.INSTR(i)) =
72          (case i
73            of I.MOVE{src=I.Direct rs, dst=I.MemReg rd, ...} => ([rd], [rs])
74             | I.MOVE{src=I.MemReg rs, dst=I.Direct rd, ...} => ([rd], [rs])
75             | I.FMOVE{src=I.FPR rs, dst=I.FPR rd, ...} => ([rd], [rs])
76             | I.FMOVE{src=I.FDirect rs, dst=I.FPR rd, ...} => ([rd], [rs])
77             | I.FMOVE{src=I.FPR rs, dst=I.FDirect rd, ...} => ([rd], [rs])
78             | I.FMOVE{src=I.FDirect rs, dst=I.FDirect rd, ...} => ([rd], [rs])
79             |  _ => error "memMove: INSTR"
80          (*esac*))
81        | memMove _ = error "memMove"
82    
83    fun moveInstr(I.COPY _) = true      val nop = fn () => I.nop
     | moveInstr(I.FCOPY _) = true  
     | moveInstr(I.MOVE{mvOp=I.MOVL, src=I.Direct _, dst=I.MemReg _, ...}) = true  
     | moveInstr(I.MOVE{mvOp=I.MOVL, src=I.MemReg _, dst=I.Direct _, ...}) = true  
     | moveInstr(I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FPR _, ...}) = true  
     | moveInstr(I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FDirect _, ...}) = true  
     | moveInstr(I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FPR _, ...}) = true  
     | moveInstr(I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FDirect _, ...}) = true  
     | moveInstr(I.ANNOTATION{i,...}) = moveInstr i  
     | moveInstr _ = false  
   
   val nop = fn () => I.NOP  
84    
85    
86   (*========================================================================   (*========================================================================
87    *  Parallel Move    *  Parallel Move
88    *========================================================================*)    *========================================================================*)
89    fun moveTmpR(I.COPY{tmp=SOME(I.Direct r), ...}) = SOME r    fun moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i
90      | moveTmpR(I.FCOPY{tmp=SOME(I.FDirect f), ...}) = SOME f      | moveTmpR(I.COPY{k=CB.GP, tmp=SOME(I.Direct r), ...}) = SOME r
91      | moveTmpR(I.FCOPY{tmp=SOME(I.FPR f), ...}) = SOME f      | moveTmpR(I.COPY{k=CB.FP, tmp=SOME(I.FDirect f), ...}) = SOME f
92      | moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i      | moveTmpR(I.COPY{k=CB.FP, tmp=SOME(I.FPR f), ...}) = SOME f
93      | moveTmpR _ = NONE      | moveTmpR _ = NONE
94    
95    fun moveDstSrc(I.COPY{src, dst, ...}) = (dst, src)    fun moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i
96      | moveDstSrc(I.FCOPY{src, dst, ...}) = (dst, src)      | moveDstSrc(I.COPY{src, dst, ...}) = (dst, src)
97      | moveDstSrc(I.MOVE{src=I.Direct rs, dst=I.MemReg rd, ...}) = ([rd], [rs])      | moveDstSrc(I.INSTR i) =
98      | moveDstSrc(I.MOVE{src=I.MemReg rs, dst=I.Direct rd, ...}) = ([rd], [rs])        (case i
99      | moveDstSrc(I.FMOVE{src=I.FPR rs, dst=I.FPR rd, ...}) = ([rd], [rs])          of I.MOVE{src=I.Direct rs, dst=I.MemReg rd, ...} => ([rd], [rs])
100      | moveDstSrc(I.FMOVE{src=I.FDirect rs, dst=I.FPR rd, ...}) = ([rd], [rs])           | I.MOVE{src=I.MemReg rs, dst=I.Direct rd, ...} => ([rd], [rs])
101      | moveDstSrc(I.FMOVE{src=I.FPR rs, dst=I.FDirect rd, ...}) = ([rd], [rs])           | I.FMOVE{src=I.FPR rs, dst=I.FPR rd, ...} => ([rd], [rs])
102      | moveDstSrc(I.FMOVE{src=I.FDirect rs, dst=I.FDirect rd, ...}) = ([rd], [rs])           | I.FMOVE{src=I.FDirect rs, dst=I.FPR rd, ...} => ([rd], [rs])
103      | moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i           | I.FMOVE{src=I.FPR rs, dst=I.FDirect rd, ...} => ([rd], [rs])
104      | moveDstSrc _ = error "moveDstSrc"           | I.FMOVE{src=I.FDirect rs, dst=I.FDirect rd, ...} => ([rd], [rs])
105             |  _ => error "moveDstSrc")
106        | moveDstSrc _ = error "moveDstSrc2"
107   (*=====================================================================   (*=====================================================================
108    *  Branches and Calls/Returns    *  Branches and Calls/Returns
109    *=====================================================================*)    *=====================================================================*)
110    fun branchTargets(I.JMP(_, [])) = [ESCAPES]    fun branchTargets(I.ANNOTATION{i,...}) = branchTargets i
111      | branchTargets(I.JMP(_, labs)) = map LABELLED labs      | branchTargets(I.INSTR i) =
112      | branchTargets(I.RET _) = [ESCAPES]        (case i
113      | branchTargets(I.JCC{opnd=I.ImmedLabel(T.LABEL(lab)), ...}) =          of I.JMP(_, []) => [ESCAPES]
114             | I.JMP(_, labs) => map LABELLED labs
115             | I.RET _ => [ESCAPES]
116             | I.JCC{opnd=I.ImmedLabel(T.LABEL(lab)), ...} =>
117          [FALLTHROUGH, LABELLED lab]          [FALLTHROUGH, LABELLED lab]
118      | branchTargets(I.CALL{cutsTo, ...}) = FALLTHROUGH :: map LABELLED cutsTo           | I.CALL{cutsTo, ...} => FALLTHROUGH :: map LABELLED cutsTo
119      | branchTargets(I.ANNOTATION{i,...}) = branchTargets i           | I.INTO => [ESCAPES]
120             |  _ => error "branchTargets")
121      | branchTargets _ = error "branchTargets"      | branchTargets _ = error "branchTargets"
122    
123    fun jump label = I.JMP (I.ImmedLabel(T.LABEL label), [label])    fun jump label = I.jmp (I.ImmedLabel(T.LABEL label), [label])
124    
125    exception NotImplemented    exception NotImplemented
126    fun setTargets(I.JMP(I.ImmedLabel _,_),[l]) = jump l  
127      | setTargets(I.JMP(opnd,_),_) = error "setTargets"    fun setJumpTarget(I.ANNOTATION{a,i}, l) = I.ANNOTATION{a=a, i=setJumpTarget(i,l)}
128      | setTargets(I.JCC{cond,opnd=I.ImmedLabel _},[f,t]) =      | setJumpTarget(I.INSTR(I.JMP(I.ImmedLabel _, _)), lab) = jump lab
129          I.JCC{cond=cond,opnd=I.ImmedLabel(T.LABEL t)}      | setJumpTarget _ = error "setJumpTarget"
130      | setTargets(I.JCC _,_) = error "setTargets"  
131      | setTargets(I.ANNOTATION{i,a},l) = I.ANNOTATION{i=setTargets(i,l),a=a}    fun setBranchTargets{i=I.ANNOTATION{a,i}, t, f} =
132      | setTargets(i,_) = i          I.ANNOTATION{a=a, i=setBranchTargets{i=i, t=t, f=f}}
133    fun negateConditional _ = raise NotImplemented      | setBranchTargets{i=I.INSTR(I.JCC{cond,opnd=I.ImmedLabel _}), t, ...} =
134            I.jcc{cond=cond,opnd=I.ImmedLabel(T.LABEL t)}
135        | setBranchTargets _ = error "setBranchTargets"
136    
137      fun negateConditional (I.ANNOTATION{i,a}, lab) =
138            I.ANNOTATION{i=negateConditional(i,lab), a=a}
139        | negateConditional (I.INSTR(I.JCC{cond,opnd=I.ImmedLabel(T.LABEL _)}), lab) =
140            let
141            val cond' = (case cond
142                   of I.EQ => I.NE
143                    | I.NE => I.EQ
144                    | I.LT => I.GE
145                    | I.LE => I.GT
146                    | I.GT => I.LE
147                    | I.GE => I.LT
148                    | I.B => I.AE
149                    | I.BE => I.A
150                    | I.A => I.BE
151                    | I.AE => I.B
152                    | I.C => I.NC
153                    | I.NC => I.C
154                    | I.P => I.NP
155                    | I.NP => I.P
156                    | I.O => I.NO
157                    | I.NO => I.O
158                  (* end case *))
159            in
160              I.INSTR(I.JCC{cond=cond', opnd=I.ImmedLabel(T.LABEL lab)})
161            end
162        | negateConditional _ = error "negateConditional"
163    
164    val immedRange={lo= ~1073741824, hi=1073741823}    val immedRange={lo= ~1073741824, hi=1073741823}
165    val toInt32 = Int32.fromLarge o Int.toLarge    val toInt32 = Int32.fromLarge o Int.toLarge
166    fun loadImmed{immed,t} =    fun loadImmed{immed,t} =
167        I.MOVE{mvOp=I.MOVL,src=I.Immed(toInt32 immed),dst=I.Direct t}        I.move{mvOp=I.MOVL,src=I.Immed(toInt32 immed),dst=I.Direct t}
168    fun loadOperand{opn,t} = I.MOVE{mvOp=I.MOVL,src=opn,dst=I.Direct t}    fun loadOperand{opn,t} = I.move{mvOp=I.MOVL,src=opn,dst=I.Direct t}
169    
170   (*=====================================================================   (*=====================================================================
171    *  Hashing and Equality on operands    *  Hashing and Equality on operands
172    *=====================================================================*)    *=====================================================================*)
173     fun hashOpn(I.Immed i) = Word.fromInt(Int32.toInt i)     fun hashOpn(I.Immed i) = Word.fromInt(Int32.toInt i)
174       | hashOpn(I.ImmedLabel le) = LE.hash le + 0w123       | hashOpn(I.ImmedLabel le) = MLTreeHash.hash le + 0w123
175       | hashOpn(I.Relative i) = Word.fromInt i + 0w1232       | hashOpn(I.Relative i) = Word.fromInt i + 0w1232
176       | hashOpn(I.LabelEA le) = LE.hash le + 0w44444       | hashOpn(I.LabelEA le) = MLTreeHash.hash le + 0w44444
177       | hashOpn(I.Direct r)  = C.hashCell r       | hashOpn(I.Direct r)  = CB.hashCell r
178       | hashOpn(I.MemReg r)  = C.hashCell r + 0w2123       | hashOpn(I.MemReg r)  = CB.hashCell r + 0w2123
179       | hashOpn(I.ST f) = C.hashCell f + 0w88       | hashOpn(I.ST f) = CB.hashCell f + 0w88
180       | hashOpn(I.FPR f) = C.hashCell f + 0w881       | hashOpn(I.FPR f) = CB.hashCell f + 0w881
181       | hashOpn(I.FDirect f) = C.hashCell f + 0w31245       | hashOpn(I.FDirect f) = CB.hashCell f + 0w31245
182       | hashOpn(I.Displace {base, disp, ...}) =       | hashOpn(I.Displace {base, disp, ...}) =
183           hashOpn disp + C.hashCell base           hashOpn disp + CB.hashCell base
184       | hashOpn(I.Indexed {base, index, scale, disp, ...}) =       | hashOpn(I.Indexed {base, index, scale, disp, ...}) =
185           C.hashCell index + Word.fromInt scale + hashOpn disp           CB.hashCell index + Word.fromInt scale + hashOpn disp
186     fun eqOpn(I.Immed a,I.Immed b) = a = b     fun eqOpn(I.Immed a,I.Immed b) = a = b
187       | eqOpn(I.ImmedLabel a,I.ImmedLabel b) = LE.==(a,b)       | eqOpn(I.ImmedLabel a,I.ImmedLabel b) = MLTreeEval.==(a,b)
188       | eqOpn(I.Relative a,I.Relative b) = a = b       | eqOpn(I.Relative a,I.Relative b) = a = b
189       | eqOpn(I.LabelEA a,I.LabelEA b) = LE.==(a,b)       | eqOpn(I.LabelEA a,I.LabelEA b) = MLTreeEval.==(a,b)
190       | eqOpn(I.Direct a,I.Direct b) = C.sameColor(a,b)       | eqOpn(I.Direct a,I.Direct b) = CB.sameColor(a,b)
191       | eqOpn(I.MemReg a,I.MemReg b) = C.sameColor(a,b)       | eqOpn(I.MemReg a,I.MemReg b) = CB.sameColor(a,b)
192       | eqOpn(I.FDirect a,I.FDirect b) = C.sameColor(a,b)       | eqOpn(I.FDirect a,I.FDirect b) = CB.sameColor(a,b)
193       | eqOpn(I.ST a,I.ST b) = C.sameColor(a,b)       | eqOpn(I.ST a,I.ST b) = CB.sameColor(a,b)
194       | eqOpn(I.FPR a,I.FPR b) = C.sameColor(a,b)       | eqOpn(I.FPR a,I.FPR b) = CB.sameColor(a,b)
195       | eqOpn(I.Displace{base=a,disp=b,...},I.Displace{base=c,disp=d,...}) =       | eqOpn(I.Displace{base=a,disp=b,...},I.Displace{base=c,disp=d,...}) =
196            C.sameColor(a,c) andalso eqOpn(b,d)            CB.sameColor(a,c) andalso eqOpn(b,d)
197       | eqOpn(I.Indexed{base=a,index=b,scale=c,disp=d,...},       | eqOpn(I.Indexed{base=a,index=b,scale=c,disp=d,...},
198               I.Indexed{base=e,index=f,scale=g,disp=h,...}) =               I.Indexed{base=e,index=f,scale=g,disp=h,...}) =
199            C.sameColor(b,f) andalso c = g            CB.sameColor(b,f) andalso c = g
200            andalso sameCellOption(a,e) andalso eqOpn(d,h)            andalso sameCellOption(a,e) andalso eqOpn(d,h)
201       | eqOpn _ = false       | eqOpn _ = false
202     and sameCellOption(NONE, NONE) = true     and sameCellOption(NONE, NONE) = true
203       | sameCellOption(SOME x, SOME y) = C.sameColor(x,y)       | sameCellOption(SOME x, SOME y) = CB.sameColor(x,y)
204       | sameCellOption _ = false       | sameCellOption _ = false
205    
206   (*========================================================================   (*========================================================================
# Line 147  Line 216 
216        | operandAcc(I.Indexed{base=NONE, index, ...}, acc) = index::acc        | operandAcc(I.Indexed{base=NONE, index, ...}, acc) = index::acc
217        | operandAcc(_, acc) = acc        | operandAcc(_, acc) = acc
218    
219        fun x86DefUseR instr = let
220      fun operandUse opnd = operandAcc(opnd, [])      fun operandUse opnd = operandAcc(opnd, [])
221    
222      fun operandUse2(src1, src2) = ([], operandAcc(src1, operandUse src2))      fun operandUse2(src1, src2) = ([], operandAcc(src1, operandUse src2))
# Line 160  Line 230 
230        val uses = operandUse src        val uses = operandUse src
231      in      in
232        case multDivOp        case multDivOp
233         of (I.IDIVL | I.DIVL) => (eaxPair, C.edx::C.eax::uses)           of (I.IDIVL1 | I.DIVL1) => (eaxPair, C.edx::C.eax::uses)
234          | I.MULL => (eaxPair, C.eax::uses)            | (I.IMULL1 | I.MULL1) => (eaxPair, C.eax::uses)
235      end      end
236    
237      fun unary opnd = (operandDef opnd, operandUse opnd)      fun unary opnd = (operandDef opnd, operandUse opnd)
238      fun cmptest{lsrc, rsrc} = ([], operandAcc(lsrc, operandUse rsrc))      fun cmptest{lsrc, rsrc} = ([], operandAcc(lsrc, operandUse rsrc))
239          fun espOnly()  = let val sp = [C.stackptrR] in (sp, sp) end
240      fun push arg = ([C.stackptrR], operandAcc(arg, [C.stackptrR]))      fun push arg = ([C.stackptrR], operandAcc(arg, [C.stackptrR]))
241      fun float opnd = ([], operandUse opnd)      fun float opnd = ([], operandUse opnd)
242    in    in
# Line 182  Line 253 
253          | I.TESTL arg | I.TESTW arg | I.TESTB arg ) => cmptest arg          | I.TESTL arg | I.TESTW arg | I.TESTB arg ) => cmptest arg
254        | I.BITOP{lsrc, rsrc, ...} => cmptest{lsrc=lsrc,rsrc=rsrc}        | I.BITOP{lsrc, rsrc, ...} => cmptest{lsrc=lsrc,rsrc=rsrc}
255        | I.BINARY{binOp=I.XORL,src=I.Direct rs,dst=I.Direct rd,...} =>        | I.BINARY{binOp=I.XORL,src=I.Direct rs,dst=I.Direct rd,...} =>
256             if C.sameColor(rs,rd) then ([rd],[]) else ([rd],[rs,rd])               if CB.sameColor(rs,rd) then ([rd],[]) else ([rd],[rs,rd])
257        | I.BINARY{src,dst,...} =>        | I.BINARY{src,dst,...} =>
258             (operandDef dst, operandAcc(src, operandUse dst))             (operandDef dst, operandAcc(src, operandUse dst))
259            | I.SHIFT{src,dst,count,...} =>
260                 (operandDef dst,
261                  operandAcc(count, operandAcc(src, operandUse dst)))
262            | I.CMPXCHG{src, dst, ...} =>
263                 (C.eax::operandDef dst, C.eax::operandAcc(src, operandUse dst))
264        | I.ENTER _             => ([C.esp, C.ebp], [C.esp, C.ebp])        | I.ENTER _             => ([C.esp, C.ebp], [C.esp, C.ebp])
265        | I.LEAVE               => ([C.esp, C.ebp], [C.esp, C.ebp])        | I.LEAVE               => ([C.esp, C.ebp], [C.esp, C.ebp])
266        | I.MULTDIV arg         => multdiv arg        | I.MULTDIV arg         => multdiv arg
267        | I.MUL3{src1, src2=SOME _, dst}=> ([dst], operandUse src1)          | I.MUL3{src1, dst, ...}=> ([dst], operandUse src1)
       | I.MUL3{src1, dst, ...}=> ([dst], dst::operandUse src1)  
268    
269        | I.UNARY{opnd, ...}    => unary opnd        | I.UNARY{opnd, ...}    => unary opnd
270        | I.SET{opnd, ...}      => unary opnd        | I.SET{opnd, ...}      => unary opnd
271        | ( I.PUSHL arg | I.PUSHW arg | I.PUSHB arg ) => push arg        | ( I.PUSHL arg | I.PUSHW arg | I.PUSHB arg ) => push arg
272        | I.POP arg             => (C.stackptrR::operandDef arg, [C.stackptrR])        | I.POP arg             => (C.stackptrR::operandDef arg, [C.stackptrR])
273            | I.PUSHFD            => espOnly()
274            | I.POPFD                     => espOnly()
275        | I.CDQ                 => ([C.edx], [C.eax])        | I.CDQ                 => ([C.edx], [C.eax])
   
       | I.COPY{dst, src, tmp=SOME(I.Direct r), ...}   => (r::dst, src)  
       | I.COPY{dst, src, ...} => (dst, src)  
276        | I.FSTPT opnd          => float opnd        | I.FSTPT opnd          => float opnd
277        | I.FSTPL opnd          => float opnd        | I.FSTPL opnd          => float opnd
278        | I.FSTPS opnd          => float opnd        | I.FSTPS opnd          => float opnd
# Line 215  Line 289 
289        | I.FNSTSW              => ([C.eax], [])        | I.FNSTSW              => ([C.eax], [])
290        | I.FUCOM opnd          => float opnd        | I.FUCOM opnd          => float opnd
291        | I.FUCOMP opnd         => float opnd        | I.FUCOMP opnd         => float opnd
292            | I.FCOMI opnd          => float opnd
293            | I.FCOMIP opnd         => float opnd
294            | I.FUCOMI opnd         => float opnd
295            | I.FUCOMIP opnd        => float opnd
296    
297        | I.FMOVE{src, dst, ...} => operandUse2(src, dst)        | I.FMOVE{src, dst, ...} => operandUse2(src, dst)
298        | I.FILOAD{ea, dst, ...} => operandUse2(ea, dst)        | I.FILOAD{ea, dst, ...} => operandUse2(ea, dst)
# Line 224  Line 302 
302        | I.FUNOP{src, dst, ...} => operandUse2(src, dst)        | I.FUNOP{src, dst, ...} => operandUse2(src, dst)
303    
304        | I.SAHF                => ([], [C.eax])        | I.SAHF                => ([], [C.eax])
305            | I.LAHF                      => ([C.eax], [])
306          (* This sets the low order byte,          (* This sets the low order byte,
307           * do potentially it may define *and* use           * do potentially it may define *and* use
308           *)           *)
309        | I.CMOV{src,dst,...} => ([dst], operandAcc(src, [dst]))        | I.CMOV{src,dst,...} => ([dst], operandAcc(src, [dst]))
       | I.ANNOTATION{a=C.DEF_USE{cellkind=C.GP,defs,uses}, i, ...} =>  
         let val (d,u) = defUseR i in (defs@d, u@uses) end  
       | I.ANNOTATION{a, i, ...} => defUseR i  
310        | _                     => ([], [])        | _                     => ([], [])
311    end (* defUseR *)      end
312      in
313          case instr
314           of I.ANNOTATION{i, ...} => defUseR i
315            | I.LIVE{regs, ...} => ([], C.getReg regs)
316            | I.KILL{regs, ...} => (C.getReg regs, [])
317            | I.COPY{k=CB.GP, dst, src, tmp, ...} =>
318              (case tmp
319                of NONE => (dst, src)
320                 | SOME(I.Direct r) => (r::dst, src)
321                 | SOME(I.MemReg r) => (r::dst, src)
322                 | SOME(ea) => (dst, operandAcc(ea, src))
323              (*esac*))
324            | I.COPY _ => ([], [])
325            | I.INSTR i  => x86DefUseR(i)
326      end
327    
328    fun defUseF instr = let    fun defUseF instr = let
329    
330        fun x86DefUseF instr = let
331      fun operand(I.FDirect f) = [f]      fun operand(I.FDirect f) = [f]
332        | operand(I.FPR f) = [f]        | operand(I.FPR f) = [f]
333        | operand _ = []        | operand _ = []
# Line 263  Line 356 
356        | I.FLDS opnd             => ([], operand opnd)        | I.FLDS opnd             => ([], operand opnd)
357        | I.FUCOM opnd            => ([], operand opnd)        | I.FUCOM opnd            => ([], operand opnd)
358        | I.FUCOMP opnd           => ([], operand opnd)        | I.FUCOMP opnd           => ([], operand opnd)
359            | I.FCOMI opnd          => ([], operand opnd)
360            | I.FCOMIP opnd         => ([], operand opnd)
361            | I.FUCOMI opnd         => ([], operand opnd)
362            | I.FUCOMIP opnd        => ([], operand opnd)
363        | I.CALL{defs, uses, ...} => (C.getFreg defs, C.getFreg uses)        | I.CALL{defs, uses, ...} => (C.getFreg defs, C.getFreg uses)
364        | I.FBINARY{dst, src, ...}=> (operand dst, operand dst @ operand src)        | I.FBINARY{dst, src, ...}=> (operand dst, operand dst @ operand src)
       | I.FCOPY{dst, src, tmp=SOME(I.FDirect f), ...}  => (f::dst, src)  
       | I.FCOPY{dst, src, tmp=SOME(I.FPR f), ...}  => (f::dst, src)  
       | I.FCOPY{dst, src, ...}  => (dst, src)  
365    
366        | I.FMOVE{src, dst, ...} => (operand dst, operand src)        | I.FMOVE{src, dst, ...} => (operand dst, operand src)
367        | I.FILOAD{ea, dst, ...} => (operand dst, [])        | I.FILOAD{ea, dst, ...} => (operand dst, [])
# Line 275  Line 369 
369        | I.FBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)        | I.FBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)
370        | I.FIBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)        | I.FIBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)
371        | I.FUNOP{src, dst, ...} => (operand dst, operand src)        | I.FUNOP{src, dst, ...} => (operand dst, operand src)
   
       | I.ANNOTATION{a=C.DEF_USE{cellkind=C.FP,defs,uses}, i, ...} =>  
         let val (d,u) = defUseF i in (defs@d, u@uses) end  
       | I.ANNOTATION{a, i, ...} => defUseF i  
372        | _  => ([], [])        | _  => ([], [])
373    end    end
374      in
375         case instr
376         of (I.ANNOTATION{i, ...}) => defUseF(i)
377          | I.LIVE{regs, ...} => ([], C.getFreg regs)
378          | I.KILL{regs, ...} => (C.getFreg regs, [])
379          | I.COPY{k=CB.FP, dst, src, tmp, ...} =>
380            (case tmp
381              of NONE => (dst, src)
382               | SOME(I.FDirect f) => (f::dst, src)
383               | SOME(I.FPR f) => (f::dst, src)
384               | _ => (dst, src)
385            (*esac*))
386          | I.COPY _  => ([], [])
387          | (I.INSTR i) => x86DefUseF(i)
388      end
389    
390    fun defUse C.GP = defUseR    fun defUse CB.GP = defUseR
391      | defUse C.FP = defUseF      | defUse CB.FP = defUseF
392      | defUse _ = error "defUse"      | defUse _ = error "defUse"
393    
394    (*========================================================================    (*========================================================================
# Line 292  Line 397 
397    fun getAnnotations(I.ANNOTATION{i,a}) =    fun getAnnotations(I.ANNOTATION{i,a}) =
398         let val (i,an) = getAnnotations i in (i,a::an) end         let val (i,an) = getAnnotations i in (i,a::an) end
399      | getAnnotations i = (i,[])      | getAnnotations i = (i,[])
400    
401    fun annotate(i,a) = I.ANNOTATION{i=i,a=a}    fun annotate(i,a) = I.ANNOTATION{i=i,a=a}
402    
403    (*========================================================================    (*========================================================================
404     *  Replicate an instruction     *  Replicate an instruction
405     *========================================================================*)     *========================================================================*)
406    fun replicate(I.ANNOTATION{i,a}) = I.ANNOTATION{i=replicate i,a=a}    fun replicate(I.ANNOTATION{i,a}) = I.ANNOTATION{i=replicate i,a=a}
407    (*
408      | replicate(I.COPY{tmp=SOME _, dst, src}) =      | replicate(I.COPY{tmp=SOME _, dst, src}) =
409          I.COPY{tmp=SOME(I.Direct(C.newReg())), dst=dst, src=src}          I.COPY{tmp=SOME(I.Direct(C.newReg())), dst=dst, src=src}
410      | replicate(I.FCOPY{tmp=SOME _, dst, src}) =      | replicate(I.FCOPY{tmp=SOME _, dst, src}) =
411          I.FCOPY{tmp=SOME(I.FDirect(C.newFreg())), dst=dst, src=src}          I.FCOPY{tmp=SOME(I.FDirect(C.newFreg())), dst=dst, src=src}
412    *)
413      | replicate i = i      | replicate i = i
414  end  end
415    

Legend:
Removed from v.796  
changed lines
  Added in v.1156

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