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/branches/SMLNJ/src/MLRISC/x86/instructions/x86Props.sml
ViewVC logotype

Diff of /sml/branches/SMLNJ/src/MLRISC/x86/instructions/x86Props.sml

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

revision 410, Fri Sep 3 00:25:03 1999 UTC revision 411, Fri Sep 3 00:25:03 1999 UTC
# Line 3  Line 3 
3   * COPYRIGHT (c) 1997 Bell Laboratories.   * COPYRIGHT (c) 1997 Bell Laboratories.
4   *)   *)
5    
6  functor X86Props  functor X86Props(X86Instr : X86INSTR) : INSN_PROPERTIES =
   (structure X86Instr : X86INSTR  
    structure Shuffle : X86SHUFFLE  
      sharing Shuffle.I = X86Instr) : INSN_PROPERTIES =  
7  struct  struct
8    structure I = X86Instr    structure I = X86Instr
9    structure C = I.C    structure C = I.C
# Line 14  Line 11 
11    
12    exception NegateConditional    exception NegateConditional
13    
14    fun error msg = MLRiscErrorMsg.impossible ("X86Props." ^ msg)    fun error msg = MLRiscErrorMsg.error("X86Props",msg)
15    
16    datatype kind = IK_JUMP | IK_NOP | IK_INSTR    datatype kind = IK_JUMP | IK_NOP | IK_INSTR | IK_COPY | IK_CALL | IK_GROUP
17                    | IK_PHI | IK_SOURCE | IK_SINK
18    datatype target = LABELLED of Label.label | FALLTHROUGH | ESCAPES    datatype target = LABELLED of Label.label | FALLTHROUGH | ESCAPES
19   (*========================================================================   (*========================================================================
20    *  Instruction Kinds    *  Instruction Kinds
21    *========================================================================*)    *========================================================================*)
22    fun instrKind (I.JMP _) = IK_JUMP    fun instrKind (I.JMP _) = IK_JUMP
23      | instrKind (I.JCC _) = IK_JUMP      | instrKind (I.JCC _) = IK_JUMP
24        | instrKind (I.COPY _) = IK_COPY
25        | instrKind (I.FCOPY _) = IK_COPY
26        | instrKind (I.CALL _) = IK_CALL
27        | instrKind (I.ANNOTATION{i,...}) = instrKind i
28        | instrKind (I.GROUP _) = IK_GROUP
29      | instrKind _ = IK_INSTR      | instrKind _ = IK_INSTR
30    
31    
32    fun moveInstr(I.COPY _) = true    fun moveInstr(I.COPY _) = true
33      | moveInstr(I.FCOPY _) = true      | moveInstr(I.FCOPY _) = true
34        | moveInstr(I.ANNOTATION{i,...}) = moveInstr i
35      | moveInstr _ = false      | moveInstr _ = false
36    
37    val nop = fn () => I.NOP    val nop = fn () => I.NOP
# Line 38  Line 42 
42    *========================================================================*)    *========================================================================*)
43    fun moveTmpR(I.COPY{tmp=SOME(I.Direct r), ...}) = SOME r    fun moveTmpR(I.COPY{tmp=SOME(I.Direct r), ...}) = SOME r
44      | moveTmpR(I.FCOPY{tmp=SOME(I.FDirect f), ...}) = SOME f      | moveTmpR(I.FCOPY{tmp=SOME(I.FDirect f), ...}) = SOME f
45        | moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i
46      | moveTmpR _ = NONE      | moveTmpR _ = NONE
47    
48    fun moveDstSrc(I.COPY{src, dst, ...}) = (dst, src)    fun moveDstSrc(I.COPY{src, dst, ...}) = (dst, src)
49      | moveDstSrc(I.FCOPY{src, dst, ...}) = (dst, src)      | moveDstSrc(I.FCOPY{src, dst, ...}) = (dst, src)
50        | moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i
51      | moveDstSrc _ = error "moveDstSrc"      | moveDstSrc _ = error "moveDstSrc"
52    
   fun copy{src, dst} =  
        I.COPY{src=src, dst=dst, tmp=SOME(I.Direct(C.newReg()))}  
   
   fun fcopy{src, dst} = let  
     fun trans r = if r >= 8 andalso r < 16 then r-8 else r  
     val src = map trans src  
     val dst = map trans dst  
   in I.FCOPY{src=src, dst=dst, tmp=SOME(I.FDirect(C.newFreg()))}  
   end  
   
   fun splitCopies{regmap, insns} = let  
     val shuffle = Shuffle.shuffle  
     val shufflefp = Shuffle.shufflefp  
     fun scan([],is') = rev is'  
       | scan(I.COPY{dst,src,tmp,...}::is,is') =  
           scan(is,shuffle{regMap=regmap,src=src,dst=dst,temp=tmp}@is')  
       | scan(I.FCOPY{dst,src,tmp, ...}::is,is') =  
           scan(is,shufflefp{regMap=regmap,src=src,dst=dst,temp=tmp}@is')  
       | scan(i::is,is') = scan(is,i::is')  
   in scan(insns,[])  
   end  
   
53    
54   (*=====================================================================   (*=====================================================================
55    *  Branches and Calls/Returns    *  Branches and Calls/Returns
# Line 74  Line 58 
58      | branchTargets(I.JMP(_, labs)) = map LABELLED labs      | branchTargets(I.JMP(_, labs)) = map LABELLED labs
59      | branchTargets(I.JCC{opnd=I.ImmedLabel(LE.LABEL(lab)), ...}) =      | branchTargets(I.JCC{opnd=I.ImmedLabel(LE.LABEL(lab)), ...}) =
60          [FALLTHROUGH, LABELLED lab]          [FALLTHROUGH, LABELLED lab]
61        | branchTargets(I.ANNOTATION{i,...}) = branchTargets i
62      | branchTargets _ = error "branchTargets"      | branchTargets _ = error "branchTargets"
63    
64    fun jump label = I.JMP (I.ImmedLabel(LE.LABEL label), [label])    fun jump label = I.JMP (I.ImmedLabel(LE.LABEL label), [label])
# Line 82  Line 67 
67    fun setTargets _ = raise NotImplemented    fun setTargets _ = raise NotImplemented
68    fun negateConditional _ = raise NotImplemented    fun negateConditional _ = raise NotImplemented
69    
70      val immedRange={lo= ~1073741824, hi=1073741823}
71      val toInt32 = Int32.fromLarge o Int.toLarge
72      fun loadImmed{immed,t} =
73          I.MOVE{mvOp=I.MOVL,src=I.Immed(toInt32 immed),dst=I.Direct t}
74    
75     (*=====================================================================
76      *  Hashing and Equality on operands
77      *=====================================================================*)
78       fun hashOpn(I.Immed i) = Word.fromInt(Int32.toInt i)
79         | hashOpn(I.Const c) = I.Constant.hash c
80         | hashOpn(I.ImmedLabel le) = LabelExp.hash le + 0w123
81         | hashOpn(I.Relative i) = Word.fromInt i + 0w1232
82         | hashOpn(I.LabelEA le) = LabelExp.hash le + 0w44444
83         | hashOpn(I.Direct r)  = Word.fromInt r
84         | hashOpn(I.FDirect f) = Word.fromInt f + 0w8888
85         | hashOpn(I.Displace {base, disp, ...}) = hashOpn disp + Word.fromInt base
86         | hashOpn(I.Indexed {base, index, scale, disp, ...}) =
87             Word.fromInt index + Word.fromInt scale + hashOpn disp
88       fun eqOpn(I.Immed a,I.Immed b) = a = b
89         | eqOpn(I.Const a,I.Const b) = I.Constant.==(a,b)
90         | eqOpn(I.ImmedLabel a,I.ImmedLabel b) = LabelExp.==(a,b)
91         | eqOpn(I.Relative a,I.Relative b) = a = b
92         | eqOpn(I.LabelEA a,I.LabelEA b) = LabelExp.==(a,b)
93         | eqOpn(I.Direct a,I.Direct b) = a = b
94         | eqOpn(I.FDirect a,I.FDirect b) = a = b
95         | eqOpn(I.Displace{base=a,disp=b,...},I.Displace{base=c,disp=d,...}) =
96              a = c andalso eqOpn(b,d)
97         | eqOpn(I.Indexed{base=a,index=b,scale=c,disp=d,...},
98                 I.Indexed{base=e,index=f,scale=g,disp=h,...}) =
99              b = f andalso c = g andalso a = e andalso eqOpn(d,h)
100         | eqOpn _ = false
101    
102   (*========================================================================   (*========================================================================
103    *  Definition and use (for register allocation mainly)    *  Definition and use (for register allocation mainly)
104    *========================================================================*)    *========================================================================*)
# Line 112  Line 129 
129      case instr      case instr
130       of I.JMP(opnd, _)        => ([], operandUse opnd)       of I.JMP(opnd, _)        => ([], operandUse opnd)
131        | I.JCC{opnd, ...}      => ([], operandUse opnd)        | I.JCC{opnd, ...}      => ([], operandUse opnd)
132        | I.CALL(opnd,defs,uses)=> (#1 defs, operandAcc(opnd, #1 uses))        | I.CALL(opnd,defs,uses,_)=> (#1 defs, operandAcc(opnd, #1 uses))
133        | I.MOVE{src, dst as I.Direct _, ...} => (operandDef dst, operandUse src)        | I.MOVE{src, dst as I.Direct _, ...} => (operandDef dst, operandUse src)
134        | I.MOVE{src, dst, ...} => ([], operandAcc(dst, operandUse src))        | I.MOVE{src, dst, ...} => ([], operandAcc(dst, operandUse src))
135        | I.LEA{r32, addr}      => ([r32], operandUse addr)        | I.LEA{r32, addr}      => ([r32], operandUse addr)
# Line 135  Line 152 
152        | I.FBINARY{src, ...}   => ([], operandUse src)        | I.FBINARY{src, ...}   => ([], operandUse src)
153        | I.FNSTSW              => ([C.eax], [])        | I.FNSTSW              => ([C.eax], [])
154        | I.SAHF                => ([], [C.eax])        | I.SAHF                => ([], [C.eax])
155          | I.ANNOTATION{i,...}   => defUseR i
156        | _                     => ([], [])        | _                     => ([], [])
157    end (* defUseR *)    end (* defUseR *)
158    
# Line 145  Line 163 
163      case instr      case instr
164       of I.FSTP opnd             => (operand opnd, [])       of I.FSTP opnd             => (operand opnd, [])
165        | I.FLD opnd              => ([], operand opnd)        | I.FLD opnd              => ([], operand opnd)
166        | I.CALL(_, defs, uses)   => (#2 defs, #2 uses)        | I.CALL(_, defs, uses,_) => (#2 defs, #2 uses)
167        | I.FBINARY{dst, src, ...}=> (operand dst, operand dst @ operand src)        | I.FBINARY{dst, src, ...}=> (operand dst, operand dst @ operand src)
168        | I.FCOPY{dst, src, tmp=SOME(I.FDirect f), ...}  => (f::dst, src)        | I.FCOPY{dst, src, tmp=SOME(I.FDirect f), ...}  => (f::dst, src)
169        | I.FCOPY{dst, src, ...}  => (dst, src)        | I.FCOPY{dst, src, ...}  => (dst, src)
170          | I.ANNOTATION{i,...}   => defUseF i
171        | _  => ([], [])        | _  => ([], [])
172    end    end
173    
174    fun defUse C.GP = defUseR    fun defUse C.GP = defUseR
175      | defUse C.FP = defUseF      | defUse C.FP = defUseF
176      | defUse _ = error "defUse"      | defUse _ = error "defUse"
177    
178      (*========================================================================
179       *  Annotations
180       *========================================================================*)
181      fun getAnnotations(I.ANNOTATION{i,a}) = a::getAnnotations i
182        | getAnnotations _ = []
183      fun annotate(i,a) = I.ANNOTATION{i=i,a=a}
184    
185      (*========================================================================
186       *  Groups
187       *========================================================================*)
188      fun getGroup(I.ANNOTATION{i,...}) = getGroup i
189        | getGroup(I.GROUP r) = r
190        | getGroup _ = error "getGroup"
191    
192      val makeGroup = I.GROUP
193  end  end
194    
 (*  
  * $Log: X86Props.sml,v $  
  * Revision 1.2  1998/08/27 14:12:18  george  
  *   used sethi-ullman number for floating point stack  
  *  
  * Revision 1.1.1.1  1998/07/22 18:10:32  george  
  *   X86.1  
  *  
  *)  

Legend:
Removed from v.410  
changed lines
  Added in v.411

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