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/hppa/instructions/hppaProps.sml
ViewVC logotype

Diff of /sml/branches/SMLNJ/src/MLRISC/hppa/instructions/hppaProps.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 4  Line 4 
4   *   *
5   *)   *)
6    
7  functor HppaProps  functor HppaProps(HppaInstr : HPPAINSTR) : INSN_PROPERTIES =
   (structure HppaInstr : HPPAINSTR  
    structure Shuffle : HPPASHUFFLE  
      sharing Shuffle.I = HppaInstr) : INSN_PROPERTIES =  
8  struct  struct
9    structure I = HppaInstr    structure I = HppaInstr
10    structure C = HppaInstr.C    structure C = HppaInstr.C
# Line 15  Line 12 
12    
13    exception NegateConditional    exception NegateConditional
14    
15    fun error msg = MLRiscErrorMsg.impossible ("HppaProps." ^ msg)    fun error msg = MLRiscErrorMsg.error("HppaProps",msg)
16    
17    datatype kind = IK_JUMP | IK_NOP | IK_INSTR    datatype kind = IK_JUMP | IK_NOP | IK_INSTR | IK_COPY | IK_CALL | IK_GROUP
18                    | IK_PHI | IK_SOURCE | IK_SINK
19    datatype target = LABELLED of Label.label | FALLTHROUGH | ESCAPES    datatype target = LABELLED of Label.label | FALLTHROUGH | ESCAPES
20    
21     (*========================================================================     (*========================================================================
# Line 26  Line 24 
24    (* Note: BLE and BL used to implement calls are not view as branches *)    (* Note: BLE and BL used to implement calls are not view as branches *)
25    fun instrKind(I.BCOND _)  = IK_JUMP    fun instrKind(I.BCOND _)  = IK_JUMP
26      | instrKind(I.BCONDI _) = IK_JUMP      | instrKind(I.BCONDI _) = IK_JUMP
27        | instrKind(I.BB _)     = IK_JUMP
28      | instrKind(I.B _)      = IK_JUMP      | instrKind(I.B _)      = IK_JUMP
29      | instrKind(I.FBRANCH _)= IK_JUMP      | instrKind(I.FBRANCH _)= IK_JUMP
30      | instrKind(I.BV _)     = IK_JUMP      | instrKind(I.BV _)     = IK_JUMP
31      | instrKind(I.BLR _)    = IK_JUMP      | instrKind(I.BLR _)    = IK_JUMP
32      | instrKind(I.NOP)      = IK_NOP      | instrKind(I.NOP)      = IK_NOP
33        | instrKind(I.COPY _)   = IK_COPY
34        | instrKind(I.FCOPY _)  = IK_COPY
35        | instrKind(I.BL  _)    = IK_CALL
36        | instrKind(I.BLE _)    = IK_CALL
37        | instrKind(I.ANNOTATION{i,...}) = instrKind i
38        | instrKind(I.GROUP _)  = IK_GROUP
39      | instrKind _           = IK_INSTR      | instrKind _           = IK_INSTR
40    
41    fun moveInstr(I.COPY _)   = true    fun moveInstr(I.COPY _)   = true
42      | moveInstr(I.FCOPY _)  = true      | moveInstr(I.FCOPY _)  = true
43        | moveInstr(I.ANNOTATION{i,...}) = moveInstr i
44      | moveInstr _ = false      | moveInstr _ = false
45    
46    fun nop() = I.NOP    fun nop() = I.NOP
# Line 44  Line 50 
50      *========================================================================*)      *========================================================================*)
51    fun moveTmpR(I.COPY{tmp=SOME(I.Direct r), ...}) = SOME r    fun moveTmpR(I.COPY{tmp=SOME(I.Direct r), ...}) = SOME r
52      | moveTmpR(I.FCOPY{tmp=SOME(I.FDirect f), ...}) = SOME f      | moveTmpR(I.FCOPY{tmp=SOME(I.FDirect f), ...}) = SOME f
53        | moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i
54      | moveTmpR _ = NONE      | moveTmpR _ = NONE
55    
56    fun moveDstSrc(I.COPY{dst, src, ...}) = (dst, src)    fun moveDstSrc(I.COPY{dst, src, ...}) = (dst, src)
57      | moveDstSrc(I.FCOPY{dst, src, ...}) = (dst, src)      | moveDstSrc(I.FCOPY{dst, src, ...}) = (dst, src)
58        | moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i
59      | moveDstSrc _ = error "moveDstSrc"      | moveDstSrc _ = error "moveDstSrc"
60    
   fun copy{src, dst} =  
     I.COPY{src=src, dst=dst, impl=ref NONE,  
            tmp=case src of [_] => NONE | _ => SOME(I.Direct(C.newReg()))}  
   
   fun fcopy{dst,src} = let  
     fun trans r = if r >= 32 andalso r < 64 then r-32 else r  
     val src = map trans src  
     val dst = map trans dst  
   in  
     I.FCOPY{dst=dst,src=src,impl=ref NONE,  
             tmp=case src of [_] => NONE | _   => 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,temp=tmp,dst=dst,src=src}@is')  
       | scan(I.FCOPY{dst, src, tmp,...}::is,is') =  
           scan(is, shufflefp{regMap=regmap,temp=tmp,dst=dst,src=src}@is')  
       | scan(i::is, is') = scan(is, i::is')  
   in scan(insns,[])  
   end  
   
61     (*========================================================================     (*========================================================================
62      *  Branches and Calls/Returns      *  Branches and Calls/Returns
63      *========================================================================*)      *========================================================================*)
64    fun branchTargets(I.BCOND{t, ...})    = [LABELLED t, FALLTHROUGH]    fun branchTargets(I.BCOND{t, ...})    = [LABELLED t, FALLTHROUGH]
65      | branchTargets(I.BCONDI{t, ...})   = [LABELLED t, FALLTHROUGH]      | branchTargets(I.BCONDI{t, ...})   = [LABELLED t, FALLTHROUGH]
66        | branchTargets(I.BB{t, ...})       = [LABELLED t, FALLTHROUGH]
67      | branchTargets(I.B{lab, ...})      = [LABELLED lab]      | branchTargets(I.B{lab, ...})      = [LABELLED lab]
68      | branchTargets(I.FBRANCH{t,...})   = [LABELLED t, FALLTHROUGH]      | branchTargets(I.FBRANCH{t,...})   = [LABELLED t, FALLTHROUGH]
69      | branchTargets(I.BV{labs=[],...})  = [ESCAPES]      | branchTargets(I.BV{labs=[],...})  = [ESCAPES]
70      | branchTargets(I.BV{labs,...})     = map LABELLED labs      | branchTargets(I.BV{labs,...})     = map LABELLED labs
71      | branchTargets(I.BLR{labs,...})    = map LABELLED labs      | branchTargets(I.BLR{labs,...})    = map LABELLED labs
72        | branchTargets(I.ANNOTATION{i,...}) = branchTargets i
73      | branchTargets _ = error "branchTargets"      | branchTargets _ = error "branchTargets"
74    
75    fun jump label = I.B{lab=label,n=true}    fun jump label = I.B{lab=label,n=true}
76    
77    fun setTargets(I.BCOND{cmp,bc,r1,r2,t,f,n},[F,T]) =    val immedRange = {lo= ~8192, hi=8191}
78            I.BCOND{cmp=cmp,bc=bc,r1=r1,r2=r2,t=T,f=F,n=n}    fun loadImmed{immed,t} = I.LDO{i=I.IMMED immed,b=0,t=t}
79      | setTargets(I.BCONDI{cmpi,bc,i,r2,t,f,n},[F,T]) =  
80            I.BCONDI{cmpi=cmpi,bc=bc,i=i,r2=r2,t=T,f=F,n=n}    fun setTargets(I.BCOND{cmp,bc,r1,r2,t,f,n,nop},[F,T]) =
81              I.BCOND{cmp=cmp,bc=bc,r1=r1,r2=r2,t=T,f=F,n=n,nop=nop}
82        | setTargets(I.BCONDI{cmpi,bc,i,r2,t,f,n,nop=nop},[F,T]) =
83              I.BCONDI{cmpi=cmpi,bc=bc,i=i,r2=r2,t=T,f=F,n=n,nop=nop}
84        | setTargets(I.BB{bc,r,p,t,f,n,nop},[F,T]) =
85              I.BB{bc=bc,r=r,p=p,t=T,f=F,n=n,nop=nop}
86      | setTargets(I.B{n,...},[L]) = I.B{lab=L,n=n}      | setTargets(I.B{n,...},[L]) = I.B{lab=L,n=n}
87      | setTargets(I.FBRANCH{cc,n,long,f1,f2,...},[F,T]) =      | setTargets(I.FBRANCH{cc,fmt,n,long,f1,f2,...},[F,T]) =
88            I.FBRANCH{cc=cc,t=T,f=F,n=n,long=long,f1=f1,f2=f2}            I.FBRANCH{cc=cc,fmt=fmt,t=T,f=F,n=n,long=long,f1=f1,f2=f2}
89      | setTargets(I.BV{x,b,n,...},labels) = I.BV{x=x,b=b,labs=labels,n=n}      | setTargets(I.BV{x,b,n,...},labels) = I.BV{x=x,b=b,labs=labels,n=n}
90      | setTargets(I.BLR{x,t,n,...},labels) = I.BLR{x=x,t=t,labs=labels,n=n}      | setTargets(I.BLR{x,t,n,...},labels) = I.BLR{x=x,t=t,labs=labels,n=n}
91        | setTargets(I.ANNOTATION{i,a},labels) =
92              I.ANNOTATION{i=setTargets(i,labels),a=a}
93      | setTargets(i,_) = i      | setTargets(i,_) = i
94    
95    fun negateConditional br = let    fun negateConditional br = let
# Line 129  Line 121 
121        | revFcond I.<=>  = I.!<=>        | revFcond I.<=>  = I.!<=>
122    in    in
123      case br of      case br of
124        I.BCOND{cmp,bc,r1,r2,t,f,n} =>        I.BCOND{cmp,bc,r1,r2,t,f,n,nop} =>
125           I.BCOND{bc=bc, r1=r1, r2=r2, t=t, f=f, n=n,           I.BCOND{bc=bc, r1=r1, r2=r2, t=t, f=f, n=n, nop=nop,
126                   cmp=case cmp of I.COMBT => I.COMBF | I.COMBF => I.COMBT}                   cmp=case cmp of I.COMBT => I.COMBF | I.COMBF => I.COMBT}
127      | I.BCONDI{cmpi,bc,i,r2,t,f,n} =>      | I.BCONDI{cmpi,bc,i,r2,t,f,n,nop} =>
128          I.BCONDI{bc=bc, i=i, r2=r2, t=t, f=f, n=n,          I.BCONDI{bc=bc, i=i, r2=r2, t=t, f=f, n=n, nop=nop,
129                   cmpi=case cmpi of I.COMIBT => I.COMIBF | I.COMIBF => I.COMIBT}                   cmpi=case cmpi of I.COMIBT => I.COMIBF | I.COMIBF => I.COMIBT}
130      | I.FBRANCH{cc,f1,f2,t,f,n,long} =>      | I.BB{bc,r,p,t,f,n,nop} =>
131          I.FBRANCH{cc=revFcond cc,f1=f1,f2=f2,t=t,f=f,n=n,long=long}           I.BB{bc=case bc of I.BSET => I.BCLR | I.BCLR => I.BSET,
132                  r=r,p=p,t=t,f=f,n=n,nop=nop}
133        | I.FBRANCH{cc,fmt,f1,f2,t,f,n,long} =>
134            I.FBRANCH{cc=revFcond cc,fmt=fmt,f1=f1,f2=f2,t=t,f=f,n=n,long=long}
135        | I.ANNOTATION{i,a} => I.ANNOTATION{i=negateConditional i,a=a}
136      | _ => raise NegateConditional      | _ => raise NegateConditional
137    end    end
138    
139    (*========================================================================    (*========================================================================
140       *  Equality and hashing for operands
141       *========================================================================*)
142       fun hashFieldSel I.F = 0w0
143         | hashFieldSel I.S = 0w1
144         | hashFieldSel I.D = 0w2
145         | hashFieldSel I.R = 0w3
146         | hashFieldSel I.T = 0w4
147         | hashFieldSel I.P = 0w5
148       fun hashOpn(I.IMMED i) = Word.fromInt i
149         | hashOpn(I.LabExp(l,f)) = LabelExp.hash l + hashFieldSel f
150         | hashOpn(I.HILabExp(l,f)) = LabelExp.hash l + hashFieldSel f + 0w10000
151         | hashOpn(I.LOLabExp(l,f)) = LabelExp.hash l + hashFieldSel f + 0w20000
152         | hashOpn(I.ConstOp c) = I.Constant.hash c
153       fun eqOpn(I.IMMED i,I.IMMED j) = i = j
154         | eqOpn(I.LabExp(a,b),I.LabExp(c,d)) = b = d andalso LabelExp.==(a,c)
155         | eqOpn(I.HILabExp(a,b),I.HILabExp(c,d)) = b = d andalso LabelExp.==(a,c)
156         | eqOpn(I.LOLabExp(a,b),I.LOLabExp(c,d)) = b = d andalso LabelExp.==(a,c)
157         | eqOpn(I.ConstOp a,I.ConstOp b) = I.Constant.==(a,b)
158         | eqOpn _ = false
159    
160    
161      (*========================================================================
162     *  Definition and use (for register allocation mainly)     *  Definition and use (for register allocation mainly)
163     *========================================================================*)     *========================================================================*)
164    fun defUseR instr = let    fun defUseR instr = let
# Line 155  Line 173 
173        | I.LOADI {li, r, t, ...}     => ([t], [r])        | I.LOADI {li, r, t, ...}     => ([t], [r])
174        | I.ARITH {a, r1, r2, t, ...} => trap(a, [t], [r1,r2])        | I.ARITH {a, r1, r2, t, ...} => trap(a, [t], [r1,r2])
175        | I.ARITHI {ai, r, t, ...}    => trapi(ai, [t], [r])        | I.ARITHI {ai, r, t, ...}    => trapi(ai, [t], [r])
176        | I.COMCLR{r1, r2, t, ...}    => ([t], [r1, r2])        | I.COMCLR_LDO{r1, r2, b, t1, t2, ...}=> (if t1 = t2 then [t1]
177                                                    else [t1,t2], [b, r1, r2])
178        | I.SHIFTV {r, t, ...}        => ([t], [r])        | I.SHIFTV {r, t, ...}        => ([t], [r])
179        | I.SHIFT {r, t, ...}         => ([t], [r])        | I.SHIFT {r, t, ...}         => ([t], [r])
180        | I.BCOND {r1, r2, ...}       => ([],  [r1,r2])        | I.BCOND {r1, r2, ...}       => ([],  [r1,r2])
181        | I.BCONDI {r2, ...}          => ([],  [r2])        | I.BCONDI {r2, ...}          => ([],  [r2])
182          | I.BB {r, ...}               => ([],  [r])
183        | I.BV {x, b, ...}            => ([],  [x,b])        | I.BV {x, b, ...}            => ([],  [x,b])
184        | I.BLR{x, t, ...}            => ([t], [x])        | I.BLR{x, t, ...}            => ([t], [x])
185        | I.BL{defs, uses, ...}       => (#1 defs, #1 uses)        | I.BL{defs, uses, ...}       => (#1 defs, #1 uses)
# Line 173  Line 193 
193        | I.FSTOREX {b, x, ...}       => ([],  [b,x])        | I.FSTOREX {b, x, ...}       => ([],  [b,x])
194        | I.FLOAD {b, ...}            => ([],  [b])        | I.FLOAD {b, ...}            => ([],  [b])
195        | I.FLOADX{b, x, ...}         => ([],  [b,x])        | I.FLOADX{b, x, ...}         => ([],  [b,x])
196          | I.ANNOTATION{i,...}         => defUseR i
197        | _   => ([],[])        | _   => ([],[])
198    end    end
199    
# Line 184  Line 205 
205         | I.FLOADX{t, ...}          => ([t], [])         | I.FLOADX{t, ...}          => ([t], [])
206         | I.FARITH {r1, r2, t, ...} => ([t], [r1,r2])         | I.FARITH {r1, r2, t, ...} => ([t], [r1,r2])
207         | I.FUNARY {f, t, ...}      => ([t], [f])         | I.FUNARY {f, t, ...}      => ([t], [f])
208           | I.FCNV {f, t, ...}        => ([t], [f])
209         | I.FBRANCH{f1, f2,...}     => ([],  [f1, f2])         | I.FBRANCH{f1, f2,...}     => ([],  [f1, f2])
210         | I.BL{defs, uses, ...}     => (#2 defs, #2 uses)         | I.BL{defs, uses, ...}     => (#2 defs, #2 uses)
211         | I.BLE{defs, uses, ...}    => (#2 defs, #2 uses)         | I.BLE{defs, uses, ...}    => (#2 defs, #2 uses)
212         | I.FCOPY{dst, src, tmp=SOME(I.FDirect f), ...} => (f::dst, src)         | I.FCOPY{dst, src, tmp=SOME(I.FDirect f), ...} => (f::dst, src)
213         | I.FCOPY{dst, src, ...}    => (dst, src)         | I.FCOPY{dst, src, ...}    => (dst, src)
214           | I.ANNOTATION{i,...}       => defUseF i
215         | _ => ([],[])         | _ => ([],[])
216    
217    fun defUse C.GP = defUseR    fun defUse C.GP = defUseR
218      | defUse C.FP = defUseF      | defUse C.FP = defUseF
219      | defUse _ = error "defUse"      | defUse _ = error "defUse"
220    
221      (*========================================================================
222       *  Annotations
223       *========================================================================*)
224      fun getAnnotations(I.ANNOTATION{i,a}) = a::getAnnotations i
225        | getAnnotations _ = []
226      fun annotate(i,a) = I.ANNOTATION{i=i,a=a}
227    
228      (*========================================================================
229       *  Groups
230       *========================================================================*)
231      fun getGroup(I.ANNOTATION{i,...}) = getGroup i
232        | getGroup(I.GROUP r) = r
233        | getGroup _ = error "getGroup"
234    
235      val makeGroup = I.GROUP
236  end  end
237    
238    
239    
 (*  
  * $Log: hppaProps.sml,v $  
  * Revision 1.4  1998/10/06 14:04:35  george  
  *   The instruction sequence FCMP, FTEST, FBCC is being replaced  
  *   by the composite instruction FBRANCH.  This makes scheduling and  
  *   other tasks easier.  Also, added BLR and BL in the instruction set.  
  *                                                      [leunga]  
  *  
  * Revision 1.3  1998/05/25 15:10:58  george  
  *   Fixed RCS keywords  
  *  
  *)  

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