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

SCM Repository

[smlnj] Annotation of /sml/branches/SMLNJ/src/MLRISC/hppa/instructions/hppaProps.sml
ViewVC logotype

Annotation of /sml/branches/SMLNJ/src/MLRISC/hppa/instructions/hppaProps.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 245 - (view) (download)

1 : monnier 245 (* hppaProps.sml
2 :     *
3 :     * COPYRIGHT (c) 1996 Bell Laboratories.
4 :     *
5 :     *)
6 :    
7 :     functor HppaProps
8 :     (structure HppaInstr : HPPAINSTR
9 :     structure Shuffle : HPPASHUFFLE
10 :     sharing Shuffle.I = HppaInstr) : INSN_PROPERTIES =
11 :     struct
12 :     structure I = HppaInstr
13 :     structure C = HppaInstr.C
14 :     structure LE = LabelExp
15 :    
16 :     exception NegateConditional
17 :    
18 :     fun error msg = MLRiscErrorMsg.impossible ("HppaProps." ^ msg)
19 :    
20 :     datatype kind = IK_JUMP | IK_NOP | IK_INSTR
21 :     datatype target = LABELLED of Label.label | FALLTHROUGH | ESCAPES
22 :    
23 :     (*========================================================================
24 :     * Instruction Kinds
25 :     *========================================================================*)
26 :     (* Note: BLE and BL used to implement calls are not view as branches *)
27 :     fun instrKind(I.BCOND _) = IK_JUMP
28 :     | instrKind(I.BCONDI _) = IK_JUMP
29 :     | instrKind(I.B _) = IK_JUMP
30 :     | instrKind(I.FBRANCH _)= IK_JUMP
31 :     | instrKind(I.BV _) = IK_JUMP
32 :     | instrKind(I.BLR _) = IK_JUMP
33 :     | instrKind(I.NOP) = IK_NOP
34 :     | instrKind _ = IK_INSTR
35 :    
36 :     fun moveInstr(I.COPY _) = true
37 :     | moveInstr(I.FCOPY _) = true
38 :     | moveInstr _ = false
39 :    
40 :     fun nop() = I.NOP
41 :    
42 :     (*========================================================================
43 :     * Parallel Move
44 :     *========================================================================*)
45 :     fun moveTmpR(I.COPY{tmp=SOME(I.Direct r), ...}) = SOME r
46 :     | moveTmpR(I.FCOPY{tmp=SOME(I.FDirect f), ...}) = SOME f
47 :     | moveTmpR _ = NONE
48 :    
49 :     fun moveDstSrc(I.COPY{dst, src, ...}) = (dst, src)
50 :     | moveDstSrc(I.FCOPY{dst, src, ...}) = (dst, src)
51 :     | moveDstSrc _ = error "moveDstSrc"
52 :    
53 :     fun copy{src, dst} =
54 :     I.COPY{src=src, dst=dst, impl=ref NONE,
55 :     tmp=case src of [_] => NONE | _ => SOME(I.Direct(C.newReg()))}
56 :    
57 :     fun fcopy{dst,src} = let
58 :     fun trans r = if r >= 32 andalso r < 64 then r-32 else r
59 :     val src = map trans src
60 :     val dst = map trans dst
61 :     in
62 :     I.FCOPY{dst=dst,src=src,impl=ref NONE,
63 :     tmp=case src of [_] => NONE | _ => SOME(I.FDirect(C.newFreg()))}
64 :     end
65 :    
66 :     fun splitCopies{regmap, insns} = let
67 :     val shuffle = Shuffle.shuffle
68 :     val shufflefp = Shuffle.shufflefp
69 :     fun scan([],is') = rev is'
70 :     | scan(I.COPY{dst, src, tmp,...}::is,is') =
71 :     scan(is, shuffle{regMap=regmap,temp=tmp,dst=dst,src=src}@is')
72 :     | scan(I.FCOPY{dst, src, tmp,...}::is,is') =
73 :     scan(is, shufflefp{regMap=regmap,temp=tmp,dst=dst,src=src}@is')
74 :     | scan(i::is, is') = scan(is, i::is')
75 :     in scan(insns,[])
76 :     end
77 :    
78 :     (*========================================================================
79 :     * Branches and Calls/Returns
80 :     *========================================================================*)
81 :     fun branchTargets(I.BCOND{t, ...}) = [LABELLED t, FALLTHROUGH]
82 :     | branchTargets(I.BCONDI{t, ...}) = [LABELLED t, FALLTHROUGH]
83 :     | branchTargets(I.B{lab, ...}) = [LABELLED lab]
84 :     | branchTargets(I.FBRANCH{t,...}) = [LABELLED t, FALLTHROUGH]
85 :     | branchTargets(I.BV{labs=[],...}) = [ESCAPES]
86 :     | branchTargets(I.BV{labs,...}) = map LABELLED labs
87 :     | branchTargets(I.BLR{labs,...}) = map LABELLED labs
88 :     | branchTargets _ = error "branchTargets"
89 :    
90 :     fun jump label = I.B{lab=label,n=true}
91 :    
92 :     fun setTargets(I.BCOND{cmp,bc,r1,r2,t,f,n},[F,T]) =
93 :     I.BCOND{cmp=cmp,bc=bc,r1=r1,r2=r2,t=T,f=F,n=n}
94 :     | setTargets(I.BCONDI{cmpi,bc,i,r2,t,f,n},[F,T]) =
95 :     I.BCONDI{cmpi=cmpi,bc=bc,i=i,r2=r2,t=T,f=F,n=n}
96 :     | setTargets(I.B{n,...},[L]) = I.B{lab=L,n=n}
97 :     | setTargets(I.FBRANCH{cc,n,long,f1,f2,...},[F,T]) =
98 :     I.FBRANCH{cc=cc,t=T,f=F,n=n,long=long,f1=f1,f2=f2}
99 :     | setTargets(I.BV{x,b,n,...},labels) = I.BV{x=x,b=b,labs=labels,n=n}
100 :     | setTargets(I.BLR{x,t,n,...},labels) = I.BLR{x=x,t=t,labs=labels,n=n}
101 :     | setTargets(i,_) = i
102 :    
103 :     fun negateConditional br = let
104 :     fun revFcond I.? = I.!?
105 :     | revFcond I.!<=> = I.<=>
106 :     | revFcond I.== = I.!=
107 :     | revFcond I.?= = I.!?=
108 :     | revFcond I.!<> = I.<>
109 :     | revFcond I.!?>= = I.?>=
110 :     | revFcond I.< = I.!<
111 :     | revFcond I.?< = I.!?<
112 :     | revFcond I.!>= = I.>=
113 :     | revFcond I.!?> = I.?>
114 :     | revFcond I.<= = I.!<=
115 :     | revFcond I.?<= = I.!?<=
116 :     | revFcond I.!> = I.>
117 :     | revFcond I.!?<= = I.?<=
118 :     | revFcond I.> = I.!>
119 :     | revFcond I.?> = I.!?>
120 :     | revFcond I.!<= = I.<=
121 :     | revFcond I.!?< = I.?<
122 :     | revFcond I.>= = I.!>=
123 :     | revFcond I.?>= = I.!?>=
124 :     | revFcond I.!< = I.<
125 :     | revFcond I.!?= = I.?=
126 :     | revFcond I.<> = I.!<>
127 :     | revFcond I.!= = I.==
128 :     | revFcond I.!? = I.?
129 :     | revFcond I.<=> = I.!<=>
130 :     in
131 :     case br of
132 :     I.BCOND{cmp,bc,r1,r2,t,f,n} =>
133 :     I.BCOND{bc=bc, r1=r1, r2=r2, t=t, f=f, n=n,
134 :     cmp=case cmp of I.COMBT => I.COMBF | I.COMBF => I.COMBT}
135 :     | I.BCONDI{cmpi,bc,i,r2,t,f,n} =>
136 :     I.BCONDI{bc=bc, i=i, r2=r2, t=t, f=f, n=n,
137 :     cmpi=case cmpi of I.COMIBT => I.COMIBF | I.COMIBF => I.COMIBT}
138 :     | I.FBRANCH{cc,f1,f2,t,f,n,long} =>
139 :     I.FBRANCH{cc=revFcond cc,f1=f1,f2=f2,t=t,f=f,n=n,long=long}
140 :     | _ => raise NegateConditional
141 :     end
142 :    
143 :     (*========================================================================
144 :     * Definition and use (for register allocation mainly)
145 :     *========================================================================*)
146 :     fun defUseR instr = let
147 :     fun trap((I.ADDO | I.SUBO | I.SH1ADDO), d, u) = (d, u)
148 :     | trap(_, d, u) = (d, u)
149 :     fun trapi((I.ADDIO | I.SUBIO), d, u) = (d, u)
150 :     | trapi(_, d, u) = (d, u)
151 :     in
152 :     case instr
153 :     of I.STORE {b, r,...} => ([], [b,r])
154 :     | I.LOAD {l, r1, r2, t, ...} => ([t], [r1,r2])
155 :     | I.LOADI {li, r, t, ...} => ([t], [r])
156 :     | I.ARITH {a, r1, r2, t, ...} => trap(a, [t], [r1,r2])
157 :     | I.ARITHI {ai, r, t, ...} => trapi(ai, [t], [r])
158 :     | I.COMCLR{r1, r2, t, ...} => ([t], [r1, r2])
159 :     | I.SHIFTV {r, t, ...} => ([t], [r])
160 :     | I.SHIFT {r, t, ...} => ([t], [r])
161 :     | I.BCOND {r1, r2, ...} => ([], [r1,r2])
162 :     | I.BCONDI {r2, ...} => ([], [r2])
163 :     | I.BV {x, b, ...} => ([], [x,b])
164 :     | I.BLR{x, t, ...} => ([t], [x])
165 :     | I.BL{defs, uses, ...} => (#1 defs, #1 uses)
166 :     | I.BLE{t, b, defs, uses, ...}=> (31 :: t :: #1 defs, b :: #1 uses)
167 :     | I.LDIL{i, t} => ([t], [])
168 :     | I.LDO{b, t, ...} => ([t], [b])
169 :     | I.COPY{dst, src, tmp=SOME(I.Direct r), ...} => (r::dst, src)
170 :     | I.COPY{dst, src, ...} => (dst, src)
171 :     | I.MTCTL{r, t} => ([], [r])
172 :     | I.FSTORE {b, ...} => ([], [b])
173 :     | I.FSTOREX {b, x, ...} => ([], [b,x])
174 :     | I.FLOAD {b, ...} => ([], [b])
175 :     | I.FLOADX{b, x, ...} => ([], [b,x])
176 :     | _ => ([],[])
177 :     end
178 :    
179 :     fun defUseF instr =
180 :     case instr
181 :     of I.FSTORE {r, ...} => ([], [r])
182 :     | I.FSTOREX{r, ...} => ([], [r])
183 :     | I.FLOAD{t, ...} => ([t], [])
184 :     | I.FLOADX{t, ...} => ([t], [])
185 :     | I.FARITH {r1, r2, t, ...} => ([t], [r1,r2])
186 :     | I.FUNARY {f, t, ...} => ([t], [f])
187 :     | I.FBRANCH{f1, f2,...} => ([], [f1, f2])
188 :     | I.BL{defs, uses, ...} => (#2 defs, #2 uses)
189 :     | I.BLE{defs, uses, ...} => (#2 defs, #2 uses)
190 :     | I.FCOPY{dst, src, tmp=SOME(I.FDirect f), ...} => (f::dst, src)
191 :     | I.FCOPY{dst, src, ...} => (dst, src)
192 :     | _ => ([],[])
193 :    
194 :     fun defUse C.GP = defUseR
195 :     | defUse C.FP = defUseF
196 :     | defUse _ = error "defUse"
197 :     end
198 :    
199 :    
200 :    
201 :     (*
202 :     * $Log: hppaProps.sml,v $
203 :     * Revision 1.4 1998/10/06 14:04:35 george
204 :     * The instruction sequence FCMP, FTEST, FBCC is being replaced
205 :     * by the composite instruction FBRANCH. This makes scheduling and
206 :     * other tasks easier. Also, added BLR and BL in the instruction set.
207 :     * [leunga]
208 :     *
209 :     * Revision 1.3 1998/05/25 15:10:58 george
210 :     * Fixed RCS keywords
211 :     *
212 :     *)

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