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 1003, Fri Dec 7 02:45:32 2001 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
28      | instrKind (I.JCC _) = IK_JUMP      | instrKind (I.INSTR i)  =
29      | instrKind (I.COPY _) = IK_COPY         (case i
30      | instrKind (I.FCOPY _) = IK_COPY           of I.JMP _ => IK_JUMP
31      | instrKind (I.CALL{cutsTo=_::_,...}) = IK_CALL_WITH_CUTS            | I.JCC _ => IK_JUMP
32      | instrKind (I.CALL _) = IK_CALL            | I.COPY _ => IK_COPY
33      | instrKind (I.PHI _)    = IK_PHI            | I.FCOPY _ => IK_COPY
34      | instrKind (I.SOURCE _) = IK_SOURCE            | I.CALL{cutsTo=_::_,...} => IK_CALL_WITH_CUTS
35      | instrKind (I.SINK _)   = IK_SINK            | I.CALL _ => IK_CALL
36      | instrKind (I.RET _) = IK_JUMP            | I.PHI _    => IK_PHI
37      | instrKind (I.ANNOTATION{i,...}) = instrKind i            | I.SOURCE _ => IK_SOURCE
38              | I.SINK _   => IK_SINK
39              | I.RET _ => IK_JUMP
40              | _ => IK_INSTR)
41      | instrKind _ = IK_INSTR      | instrKind _ = IK_INSTR
42    
43      fun moveInstr(I.ANNOTATION{i, ...}) = moveInstr i
44    fun moveInstr(I.COPY _) = true      | moveInstr(I.LIVE _) = false
45      | moveInstr(I.FCOPY _) = true      | moveInstr(I.KILL _) = false
46      | moveInstr(I.MOVE{mvOp=I.MOVL, src=I.Direct _, dst=I.MemReg _, ...}) = true      | moveInstr(I.INSTR i)  =
47      | moveInstr(I.MOVE{mvOp=I.MOVL, src=I.MemReg _, dst=I.Direct _, ...}) = true         (case i
48      | moveInstr(I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FPR _, ...}) = true           of I.COPY _ => true
49      | moveInstr(I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FDirect _, ...}) = true            | I.FCOPY _ =>true
50      | moveInstr(I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FPR _, ...}) = true            | I.MOVE{mvOp=I.MOVL, src=I.Direct _, dst=I.MemReg _, ...} => true
51      | moveInstr(I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FDirect _, ...}) = true            | I.MOVE{mvOp=I.MOVL, src=I.MemReg _, dst=I.Direct _, ...} => true
52      | moveInstr(I.ANNOTATION{i,...}) = moveInstr i            | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FPR _, ...} => true
53              | I.FMOVE{fsize=I.FP64,src=I.FPR _,dst=I.FDirect _, ...} => true
54              | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FPR _, ...} => true
55              | I.FMOVE{fsize=I.FP64,src=I.FDirect _,dst=I.FDirect _, ...} => true
56              | _ => false )
57      | moveInstr _ = false      | moveInstr _ = false
58    
59    val nop = fn () => I.NOP  
60      val nop = fn () => I.nop
61    
62    
63   (*========================================================================   (*========================================================================
64    *  Parallel Move    *  Parallel Move
65    *========================================================================*)    *========================================================================*)
66    fun moveTmpR(I.COPY{tmp=SOME(I.Direct r), ...}) = SOME r    fun moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i
67      | moveTmpR(I.FCOPY{tmp=SOME(I.FDirect f), ...}) = SOME f      | moveTmpR(I.INSTR i) =
68      | moveTmpR(I.FCOPY{tmp=SOME(I.FPR f), ...}) = SOME f        (case i
69      | moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i          of I.COPY{tmp=SOME(I.Direct r), ...} => SOME r
70             | I.FCOPY{tmp=SOME(I.FDirect f), ...} => SOME f
71             | I.FCOPY{tmp=SOME(I.FPR f), ...} => SOME f
72             |  _ => NONE)
73      | moveTmpR _ = NONE      | moveTmpR _ = NONE
74    
75    fun moveDstSrc(I.COPY{src, dst, ...}) = (dst, src)    fun moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i
76      | moveDstSrc(I.FCOPY{src, dst, ...}) = (dst, src)      | moveDstSrc(I.INSTR i) =
77      | moveDstSrc(I.MOVE{src=I.Direct rs, dst=I.MemReg rd, ...}) = ([rd], [rs])        (case i
78      | moveDstSrc(I.MOVE{src=I.MemReg rs, dst=I.Direct rd, ...}) = ([rd], [rs])          of I.COPY{src, dst, ...} => (dst, src)
79      | moveDstSrc(I.FMOVE{src=I.FPR rs, dst=I.FPR rd, ...}) = ([rd], [rs])           | I.FCOPY{src, dst, ...} => (dst, src)
80      | moveDstSrc(I.FMOVE{src=I.FDirect rs, dst=I.FPR rd, ...}) = ([rd], [rs])           | I.MOVE{src=I.Direct rs, dst=I.MemReg rd, ...} => ([rd], [rs])
81      | moveDstSrc(I.FMOVE{src=I.FPR rs, dst=I.FDirect rd, ...}) = ([rd], [rs])           | I.MOVE{src=I.MemReg rs, dst=I.Direct rd, ...} => ([rd], [rs])
82      | moveDstSrc(I.FMOVE{src=I.FDirect rs, dst=I.FDirect rd, ...}) = ([rd], [rs])           | I.FMOVE{src=I.FPR rs, dst=I.FPR rd, ...} => ([rd], [rs])
83      | moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i           | I.FMOVE{src=I.FDirect rs, dst=I.FPR rd, ...} => ([rd], [rs])
84      | moveDstSrc _ = error "moveDstSrc"           | I.FMOVE{src=I.FPR rs, dst=I.FDirect rd, ...} => ([rd], [rs])
85             | I.FMOVE{src=I.FDirect rs, dst=I.FDirect rd, ...} => ([rd], [rs])
86             |  _ => error "moveDstSrc")
87        | moveDstSrc _ = error "moveDstSrc2"
88   (*=====================================================================   (*=====================================================================
89    *  Branches and Calls/Returns    *  Branches and Calls/Returns
90    *=====================================================================*)    *=====================================================================*)
91    fun branchTargets(I.JMP(_, [])) = [ESCAPES]    fun branchTargets(I.ANNOTATION{i,...}) = branchTargets i
92      | branchTargets(I.JMP(_, labs)) = map LABELLED labs      | branchTargets(I.INSTR i) =
93      | branchTargets(I.RET _) = [ESCAPES]        (case i
94      | branchTargets(I.JCC{opnd=I.ImmedLabel(T.LABEL(lab)), ...}) =          of I.JMP(_, []) => [ESCAPES]
95             | I.JMP(_, labs) => map LABELLED labs
96             | I.RET _ => [ESCAPES]
97             | I.JCC{opnd=I.ImmedLabel(T.LABEL(lab)), ...} =>
98          [FALLTHROUGH, LABELLED lab]          [FALLTHROUGH, LABELLED lab]
99      | branchTargets(I.CALL{cutsTo, ...}) = FALLTHROUGH :: map LABELLED cutsTo           | I.CALL{cutsTo, ...} => FALLTHROUGH :: map LABELLED cutsTo
100      | branchTargets(I.ANNOTATION{i,...}) = branchTargets i           |  _ => error "branchTargets")
101      | branchTargets _ = error "branchTargets"      | branchTargets _ = error "branchTargets"
102    
103    fun jump label = I.JMP (I.ImmedLabel(T.LABEL label), [label])    fun jump label = I.jmp (I.ImmedLabel(T.LABEL label), [label])
104    
105    exception NotImplemented    exception NotImplemented
106    fun setTargets(I.JMP(I.ImmedLabel _,_),[l]) = jump l  
107      | setTargets(I.JMP(opnd,_),_) = error "setTargets"    fun setTargets(I.ANNOTATION{i,a},l) = I.ANNOTATION{i=setTargets(i,l),a=a}
108      | setTargets(I.JCC{cond,opnd=I.ImmedLabel _},[f,t]) =      | setTargets(I.INSTR(I.JMP(I.ImmedLabel _,_)), [l]) = jump l
109          I.JCC{cond=cond,opnd=I.ImmedLabel(T.LABEL t)}      | setTargets(I.INSTR(I.JMP _), _) = error "setTargets"
110      | setTargets(I.JCC _,_) = error "setTargets"      | setTargets(I.INSTR(I.JCC{cond,opnd=I.ImmedLabel _}),[f,t]) =
111      | setTargets(I.ANNOTATION{i,a},l) = I.ANNOTATION{i=setTargets(i,l),a=a}          I.jcc{cond=cond,opnd=I.ImmedLabel(T.LABEL t)}
112        | setTargets(I.INSTR(I.JCC _),_) = error "setTargets"
113      | setTargets(i,_) = i      | setTargets(i,_) = i
114    
115    fun negateConditional _ = raise NotImplemented    fun negateConditional _ = raise NotImplemented
116    
117    val immedRange={lo= ~1073741824, hi=1073741823}    val immedRange={lo= ~1073741824, hi=1073741823}
118    val toInt32 = Int32.fromLarge o Int.toLarge    val toInt32 = Int32.fromLarge o Int.toLarge
119    fun loadImmed{immed,t} =    fun loadImmed{immed,t} =
120        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}
121    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}
122    
123   (*=====================================================================   (*=====================================================================
124    *  Hashing and Equality on operands    *  Hashing and Equality on operands
# Line 144  Line 162 
162    val eaxPair = [C.edx, C.eax]    val eaxPair = [C.edx, C.eax]
163    
164    fun defUseR instr = let    fun defUseR instr = let
165        fun x86DefUseR instr = let
166      fun operandAcc(I.Direct r, acc) = r::acc      fun operandAcc(I.Direct r, acc) = r::acc
167        | operandAcc(I.MemReg r, acc) = r::acc        | operandAcc(I.MemReg r, acc) = r::acc
168        | operandAcc(I.Displace{base, ...}, acc) = base::acc        | operandAcc(I.Displace{base, ...}, acc) = base::acc
# Line 237  Line 256 
256           * do potentially it may define *and* use           * do potentially it may define *and* use
257           *)           *)
258        | 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  
259        | _                     => ([], [])        | _                     => ([], [])
260    end (* defUseR *)      end
261      in
262          case instr
263           of I.ANNOTATION{i, ...} => defUseR i
264            | I.LIVE{regs, ...} => ([], C.getReg regs)
265            | I.KILL{regs, ...} => (C.getReg regs, [])
266            | I.INSTR i  => x86DefUseR(i)
267            | _ => error "defUseR"
268      end
269    
270    fun defUseF instr = let    fun defUseF instr = let
271    
272        fun x86DefUseF instr = let
273      fun operand(I.FDirect f) = [f]      fun operand(I.FDirect f) = [f]
274        | operand(I.FPR f) = [f]        | operand(I.FPR f) = [f]
275        | operand _ = []        | operand _ = []
# Line 284  Line 310 
310        | I.FBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)        | I.FBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)
311        | I.FIBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)        | I.FIBINOP{lsrc, rsrc, dst, ...} => fbinop(lsrc, rsrc, dst)
312        | 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  
313        | _  => ([], [])        | _  => ([], [])
314    end    end
315      in
316         case instr
317         of (I.ANNOTATION{i, ...}) => defUseF(i)
318            | I.LIVE{regs, ...} => ([], C.getFreg regs)
319            | I.KILL{regs, ...} => (C.getFreg regs, [])
320          | (I.INSTR i) => x86DefUseF(i)
321          | _ =>  error "defUseF not implemented"
322      end
323    
324    fun defUse CB.GP = defUseR    fun defUse CB.GP = defUseR
325      | defUse CB.FP = defUseF      | defUse CB.FP = defUseF
# Line 301  Line 331 
331    fun getAnnotations(I.ANNOTATION{i,a}) =    fun getAnnotations(I.ANNOTATION{i,a}) =
332         let val (i,an) = getAnnotations i in (i,a::an) end         let val (i,an) = getAnnotations i in (i,a::an) end
333      | getAnnotations i = (i,[])      | getAnnotations i = (i,[])
334    
335    fun annotate(i,a) = I.ANNOTATION{i=i,a=a}    fun annotate(i,a) = I.ANNOTATION{i=i,a=a}
336    
337    (*========================================================================    (*========================================================================
338     *  Replicate an instruction     *  Replicate an instruction
339     *========================================================================*)     *========================================================================*)
340    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}
341    (*
342      | replicate(I.COPY{tmp=SOME _, dst, src}) =      | replicate(I.COPY{tmp=SOME _, dst, src}) =
343          I.COPY{tmp=SOME(I.Direct(C.newReg())), dst=dst, src=src}          I.COPY{tmp=SOME(I.Direct(C.newReg())), dst=dst, src=src}
344      | replicate(I.FCOPY{tmp=SOME _, dst, src}) =      | replicate(I.FCOPY{tmp=SOME _, dst, src}) =
345          I.FCOPY{tmp=SOME(I.FDirect(C.newFreg())), dst=dst, src=src}          I.FCOPY{tmp=SOME(I.FDirect(C.newFreg())), dst=dst, src=src}
346    *)
347      | replicate i = i      | replicate i = i
348  end  end
349    

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

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