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 984, Wed Nov 21 19:00:08 2001 UTC revision 1009, Wed Jan 9 19:44:22 2002 UTC
# Line 24  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              | _ => IK_INSTR)
40      | instrKind _ = IK_INSTR      | instrKind _ = IK_INSTR
41    
42      fun moveInstr(I.ANNOTATION{i, ...}) = moveInstr i
43        | moveInstr(I.LIVE _) = false
44        | moveInstr(I.KILL _) = false
45        | moveInstr(I.COPY _) = true
46        | moveInstr(I.INSTR i)  =
47           (case i
48             of I.MOVE{mvOp=I.MOVL, src=I.Direct _, dst=I.MemReg _, ...} => true
49              | I.MOVE{mvOp=I.MOVL, src=I.MemReg _, dst=I.Direct _, ...} => true
50              | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FPR _, ...} => true
51              | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FDirect _, ...} => true
52              | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FPR _, ...} => true
53              | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FDirect _, ...} => true
54              | _ => false )
55    
56    
57      fun isMemMove(I.INSTR(i)) =
58          (case i
59            of I.MOVE{mvOp=I.MOVL, src=I.Direct _, dst=I.MemReg _, ...} => true
60             | I.MOVE{mvOp=I.MOVL, src=I.MemReg _, dst=I.Direct _, ...} => true
61             | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FPR _, ...} => true
62             | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FDirect _, ...} => true
63             | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FPR _, ...} => true
64             | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FDirect _, ...} => true
65             | _ => false
66          (*esac*))
67        | isMemMove _ = false
68    
69    
70      fun memMove(I.INSTR(i)) =
71          (case i
72            of I.MOVE{src=I.Direct rs, dst=I.MemReg rd, ...} => ([rd], [rs])
73             | I.MOVE{src=I.MemReg rs, dst=I.Direct rd, ...} => ([rd], [rs])
74             | I.FMOVE{src=I.FPR rs, dst=I.FPR rd, ...} => ([rd], [rs])
75             | I.FMOVE{src=I.FDirect rs, dst=I.FPR rd, ...} => ([rd], [rs])
76             | I.FMOVE{src=I.FPR rs, dst=I.FDirect rd, ...} => ([rd], [rs])
77             | I.FMOVE{src=I.FDirect rs, dst=I.FDirect rd, ...} => ([rd], [rs])
78             |  _ => error "memMove: INSTR"
79          (*esac*))
80        | memMove _ = error "memMove"
81    
82    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  
83    
84    
85   (*========================================================================   (*========================================================================
86    *  Parallel Move    *  Parallel Move
87    *========================================================================*)    *========================================================================*)
88    fun moveTmpR(I.COPY{tmp=SOME(I.Direct r), ...}) = SOME r    fun moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i
89      | moveTmpR(I.FCOPY{tmp=SOME(I.FDirect f), ...}) = SOME f      | moveTmpR(I.COPY{k=CB.GP, tmp=SOME(I.Direct r), ...}) = SOME r
90      | moveTmpR(I.FCOPY{tmp=SOME(I.FPR f), ...}) = SOME f      | moveTmpR(I.COPY{k=CB.FP, tmp=SOME(I.FDirect f), ...}) = SOME f
91      | moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i      | moveTmpR(I.COPY{k=CB.FP, tmp=SOME(I.FPR f), ...}) = SOME f
92      | moveTmpR _ = NONE      | moveTmpR _ = NONE
93    
94    fun moveDstSrc(I.COPY{src, dst, ...}) = (dst, src)    fun moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i
95      | moveDstSrc(I.FCOPY{src, dst, ...}) = (dst, src)      | moveDstSrc(I.COPY{src, dst, ...}) = (dst, src)
96      | moveDstSrc(I.MOVE{src=I.Direct rs, dst=I.MemReg rd, ...}) = ([rd], [rs])      | moveDstSrc(I.INSTR i) =
97      | moveDstSrc(I.MOVE{src=I.MemReg rs, dst=I.Direct rd, ...}) = ([rd], [rs])        (case i
98      | 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])
99      | 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])
100      | 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])
101      | 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])
102      | moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i           | I.FMOVE{src=I.FPR rs, dst=I.FDirect rd, ...} => ([rd], [rs])
103      | moveDstSrc _ = error "moveDstSrc"           | I.FMOVE{src=I.FDirect rs, dst=I.FDirect rd, ...} => ([rd], [rs])
104             |  _ => error "moveDstSrc")
105        | moveDstSrc _ = error "moveDstSrc2"
106   (*=====================================================================   (*=====================================================================
107    *  Branches and Calls/Returns    *  Branches and Calls/Returns
108    *=====================================================================*)    *=====================================================================*)
109    fun branchTargets(I.JMP(_, [])) = [ESCAPES]    fun branchTargets(I.ANNOTATION{i,...}) = branchTargets i
110      | branchTargets(I.JMP(_, labs)) = map LABELLED labs      | branchTargets(I.INSTR i) =
111      | branchTargets(I.RET _) = [ESCAPES]        (case i
112      | branchTargets(I.JCC{opnd=I.ImmedLabel(T.LABEL(lab)), ...}) =          of I.JMP(_, []) => [ESCAPES]
113             | I.JMP(_, labs) => map LABELLED labs
114             | I.RET _ => [ESCAPES]
115             | I.JCC{opnd=I.ImmedLabel(T.LABEL(lab)), ...} =>
116          [FALLTHROUGH, LABELLED lab]          [FALLTHROUGH, LABELLED lab]
117      | branchTargets(I.CALL{cutsTo, ...}) = FALLTHROUGH :: map LABELLED cutsTo           | I.CALL{cutsTo, ...} => FALLTHROUGH :: map LABELLED cutsTo
118      | branchTargets(I.ANNOTATION{i,...}) = branchTargets i           |  _ => error "branchTargets")
119      | branchTargets _ = error "branchTargets"      | branchTargets _ = error "branchTargets"
120    
121    fun jump label = I.JMP (I.ImmedLabel(T.LABEL label), [label])    fun jump label = I.jmp (I.ImmedLabel(T.LABEL label), [label])
122    
123    exception NotImplemented    exception NotImplemented
124    fun setTargets(I.JMP(I.ImmedLabel _,_),[l]) = jump l  
125      | setTargets(I.JMP(opnd,_),_) = error "setTargets"    fun setTargets(I.ANNOTATION{i,a},l) = I.ANNOTATION{i=setTargets(i,l),a=a}
126      | setTargets(I.JCC{cond,opnd=I.ImmedLabel _},[f,t]) =      | setTargets(I.INSTR(I.JMP(I.ImmedLabel _,_)), [l]) = jump l
127          I.JCC{cond=cond,opnd=I.ImmedLabel(T.LABEL t)}      | setTargets(I.INSTR(I.JMP _), _) = error "setTargets"
128      | setTargets(I.JCC _,_) = error "setTargets"      | setTargets(I.INSTR(I.JCC{cond,opnd=I.ImmedLabel _}),[f,t]) =
129      | setTargets(I.ANNOTATION{i,a},l) = I.ANNOTATION{i=setTargets(i,l),a=a}          I.jcc{cond=cond,opnd=I.ImmedLabel(T.LABEL t)}
130        | setTargets(I.INSTR(I.JCC _),_) = error "setTargets"
131      | setTargets(i,_) = i      | setTargets(i,_) = i
132    
133    fun negateConditional _ = raise NotImplemented    fun negateConditional _ = raise NotImplemented
134    
135    val immedRange={lo= ~1073741824, hi=1073741823}    val immedRange={lo= ~1073741824, hi=1073741823}
136    val toInt32 = Int32.fromLarge o Int.toLarge    val toInt32 = Int32.fromLarge o Int.toLarge
137    fun loadImmed{immed,t} =    fun loadImmed{immed,t} =
138        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}
139    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}
140    
141   (*=====================================================================   (*=====================================================================
142    *  Hashing and Equality on operands    *  Hashing and Equality on operands
# Line 151  Line 187 
187        | operandAcc(I.Indexed{base=NONE, index, ...}, acc) = index::acc        | operandAcc(I.Indexed{base=NONE, index, ...}, acc) = index::acc
188        | operandAcc(_, acc) = acc        | operandAcc(_, acc) = acc
189    
190        fun x86DefUseR instr = let
191      fun operandUse opnd = operandAcc(opnd, [])      fun operandUse opnd = operandAcc(opnd, [])
192    
193      fun operandUse2(src1, src2) = ([], operandAcc(src1, operandUse src2))      fun operandUse2(src1, src2) = ([], operandAcc(src1, operandUse src2))
# Line 204  Line 241 
241        | I.PUSHFD              => espOnly()        | I.PUSHFD              => espOnly()
242        | I.POPFD               => espOnly()        | I.POPFD               => espOnly()
243        | 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)  
244        | I.FSTPT opnd          => float opnd        | I.FSTPT opnd          => float opnd
245        | I.FSTPL opnd          => float opnd        | I.FSTPL opnd          => float opnd
246        | I.FSTPS opnd          => float opnd        | I.FSTPS opnd          => float opnd
# Line 237  Line 271 
271           * do potentially it may define *and* use           * do potentially it may define *and* use
272           *)           *)
273        | I.CMOV{src,dst,...} => ([dst], operandAcc(src, [dst]))        | I.CMOV{src,dst,...} => ([dst], operandAcc(src, [dst]))
       | I.ANNOTATION{a=CB.DEF_USE{cellkind=CB.GP,defs,uses}, i, ...} =>  
         let val (d,u) = defUseR i in (defs@d, u@uses) end  
       | I.ANNOTATION{a, i, ...} => defUseR i  
274        | _                     => ([], [])        | _                     => ([], [])
275    end (* defUseR *)      end
276      in
277          case instr
278           of I.ANNOTATION{i, ...} => defUseR i
279            | I.LIVE{regs, ...} => ([], C.getReg regs)
280            | I.KILL{regs, ...} => (C.getReg regs, [])
281            | I.COPY{k=CB.GP, dst, src, tmp, ...} =>
282              (case tmp
283                of NONE => (dst, src)
284                 | SOME(I.Direct r) => (r::dst, src)
285                 | SOME(I.MemReg r) => (r::dst, src)
286                 | SOME(ea) => (dst, operandAcc(ea, src))
287              (*esac*))
288            | I.COPY _ => ([], [])
289            | I.INSTR i  => x86DefUseR(i)
290      end
291    
292    fun defUseF instr = let    fun defUseF instr = let
293    
294        fun x86DefUseF instr = let
295      fun operand(I.FDirect f) = [f]      fun operand(I.FDirect f) = [f]
296        | operand(I.FPR f) = [f]        | operand(I.FPR f) = [f]
297        | operand _ = []        | operand _ = []
# Line 274  Line 322 
322        | I.FUCOMP opnd           => ([], operand opnd)        | I.FUCOMP opnd           => ([], operand opnd)
323        | I.CALL{defs, uses, ...} => (C.getFreg defs, C.getFreg uses)        | I.CALL{defs, uses, ...} => (C.getFreg defs, C.getFreg uses)
324        | 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)  
325    
326        | I.FMOVE{src, dst, ...} => (operand dst, operand src)        | I.FMOVE{src, dst, ...} => (operand dst, operand src)
327        | I.FILOAD{ea, dst, ...} => (operand dst, [])        | I.FILOAD{ea, dst, ...} => (operand dst, [])
# Line 284  Line 329 
329        | I.FBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)        | I.FBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)
330        | I.FIBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)        | I.FIBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)
331        | I.FUNOP{src, dst, ...} => (operand dst, operand src)        | I.FUNOP{src, dst, ...} => (operand dst, operand src)
   
       | I.ANNOTATION{a=CB.DEF_USE{cellkind=CB.FP,defs,uses}, i, ...} =>  
         let val (d,u) = defUseF i in (defs@d, u@uses) end  
       | I.ANNOTATION{a, i, ...} => defUseF i  
332        | _  => ([], [])        | _  => ([], [])
333    end    end
334      in
335         case instr
336         of (I.ANNOTATION{i, ...}) => defUseF(i)
337          | I.LIVE{regs, ...} => ([], C.getFreg regs)
338          | I.KILL{regs, ...} => (C.getFreg regs, [])
339          | I.COPY{k=CB.FP, dst, src, tmp, ...} =>
340            (case tmp
341              of NONE => (dst, src)
342               | SOME(I.FDirect f) => (f::dst, src)
343               | SOME(I.FPR f) => (f::dst, src)
344               | _ => (dst, src)
345            (*esac*))
346          | I.COPY _  => ([], [])
347          | (I.INSTR i) => x86DefUseF(i)
348      end
349    
350    fun defUse CB.GP = defUseR    fun defUse CB.GP = defUseR
351      | defUse CB.FP = defUseF      | defUse CB.FP = defUseF
# Line 301  Line 357 
357    fun getAnnotations(I.ANNOTATION{i,a}) =    fun getAnnotations(I.ANNOTATION{i,a}) =
358         let val (i,an) = getAnnotations i in (i,a::an) end         let val (i,an) = getAnnotations i in (i,a::an) end
359      | getAnnotations i = (i,[])      | getAnnotations i = (i,[])
360    
361    fun annotate(i,a) = I.ANNOTATION{i=i,a=a}    fun annotate(i,a) = I.ANNOTATION{i=i,a=a}
362    
363    (*========================================================================    (*========================================================================
364     *  Replicate an instruction     *  Replicate an instruction
365     *========================================================================*)     *========================================================================*)
366    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}
367    (*
368      | replicate(I.COPY{tmp=SOME _, dst, src}) =      | replicate(I.COPY{tmp=SOME _, dst, src}) =
369          I.COPY{tmp=SOME(I.Direct(C.newReg())), dst=dst, src=src}          I.COPY{tmp=SOME(I.Direct(C.newReg())), dst=dst, src=src}
370      | replicate(I.FCOPY{tmp=SOME _, dst, src}) =      | replicate(I.FCOPY{tmp=SOME _, dst, src}) =
371          I.FCOPY{tmp=SOME(I.FDirect(C.newFreg())), dst=dst, src=src}          I.FCOPY{tmp=SOME(I.FDirect(C.newFreg())), dst=dst, src=src}
372    *)
373      | replicate i = i      | replicate i = i
374  end  end
375    

Legend:
Removed from v.984  
changed lines
  Added in v.1009

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