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/trunk/src/MLRISC/ppc/instructions/ppcProps.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/ppc/instructions/ppcProps.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1124 - (view) (download)

1 : jhr 1082 (* ppcProps.sml
2 :     *
3 :     * COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies
4 :     *)
5 :    
6 : george 984 functor PPCProps
7 :     ( structure PPCInstr : PPCINSTR
8 :     structure MLTreeEval : MLTREE_EVAL where T = PPCInstr.T
9 :     structure MLTreeHash : MLTREE_HASH where T = PPCInstr.T
10 :     ) : INSN_PROPERTIES =
11 : monnier 245 struct
12 :     structure I = PPCInstr
13 :     structure C = I.C
14 : leunga 775 structure T = I.T
15 : george 889 structure CB = CellsBasis
16 : monnier 245
17 :     exception NegateConditional
18 :    
19 : monnier 411 fun error msg = MLRiscErrorMsg.error("PPCProps",msg)
20 : monnier 245
21 : george 545 datatype kind = IK_JUMP | IK_NOP | IK_INSTR | IK_COPY | IK_CALL
22 : leunga 796 | IK_CALL_WITH_CUTS | IK_PHI | IK_SOURCE | IK_SINK
23 : monnier 245 datatype target = LABELLED of Label.label | FALLTHROUGH | ESCAPES
24 :    
25 : leunga 744 (* This stupid architecture doesn't really have a dedicated zero register *)
26 : george 889 fun zeroR() = C.Reg CB.GP 0
27 : leunga 744
28 : george 1003 fun instrKind(I.ANNOTATION{i, ...}) = instrKind i
29 : george 1009 | instrKind(I.COPY _) = IK_COPY
30 : george 1124 | instrKind(I.INSTR instr) = let
31 :     fun eqTest to = Word.andb(Word.fromInt to, 0w4) <> 0w0
32 :     fun trapAlways{to, ra, si} =
33 :     (case si
34 :     of I.RegOp rb =>
35 :     if CellsBasis.sameColor(ra,rb) andalso eqTest(to) then IK_JUMP
36 :     else IK_INSTR
37 :     | I.ImmedOp 0 =>
38 :     if CellsBasis.registerId ra = 0 andalso eqTest(to) then IK_JUMP
39 :     else IK_INSTR
40 :     (*esac*))
41 :     in
42 :     case instr
43 : george 1003 of (I.BC _) => IK_JUMP
44 :     | (I.BCLR _) => IK_JUMP
45 :     | (I.B _) => IK_JUMP
46 : george 1124 | (I.TW t) => trapAlways(t)
47 :     | (I.TD t) => trapAlways(t)
48 : george 1003 | (I.ARITHI{oper=I.ORI, rt, ra, im=I.ImmedOp 0}) =>
49 :     if CB.registerId rt = 0 andalso CB.registerId ra = 0 then IK_NOP
50 :     else IK_INSTR
51 :     | (I.CALL{cutsTo=_::_,...}) => IK_CALL_WITH_CUTS
52 :     | (I.CALL _) => IK_CALL
53 :     | (I.PHI _) => IK_PHI
54 :     | (I.SOURCE _) => IK_SOURCE
55 :     | (I.SINK _) => IK_SINK
56 : george 1124 | _ => IK_INSTR
57 :     (*esac*)
58 :     end
59 : george 1003 | instrKind _ = error "instrKind"
60 : monnier 245
61 : george 1009 fun moveInstr(I.COPY _) = true
62 : monnier 411 | moveInstr(I.ANNOTATION{i,...}) = moveInstr i
63 : monnier 245 | moveInstr _ = false
64 :    
65 : george 1003 fun nop () = I.arithi{oper=I.ORI, rt=zeroR(), ra=zeroR(), im=I.ImmedOp 0}
66 : monnier 245
67 : george 1009 fun moveTmpR(I.COPY{tmp, ...}) =
68 :     (case tmp
69 :     of SOME(I.Direct r) => SOME r
70 :     | SOME(I.FDirect f) => SOME f
71 :     | _ => NONE
72 :     (*esac*))
73 : monnier 411 | moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i
74 : monnier 245 | moveTmpR _ = NONE
75 :    
76 : george 1009 fun moveDstSrc(I.COPY{dst,src,...}) = (dst,src)
77 : monnier 411 | moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i
78 : monnier 245 | moveDstSrc _ = error "moveDstSrc"
79 :    
80 : george 1009
81 : george 1003 fun branchTargets(I.INSTR(I.BC{bo=I.ALWAYS, addr, ...})) =
82 : monnier 245 (case addr
83 : leunga 775 of I.LabelOp(T.LABEL lab) => [LABELLED lab]
84 : monnier 245 | _ => error "branchTargets:BC:ALWAYS"
85 :     (*esac*))
86 : george 1003 | branchTargets(I.INSTR(I.BC{addr, ...})) =
87 : monnier 245 (case addr
88 : leunga 775 of I.LabelOp(T.LABEL lab) => [LABELLED lab, FALLTHROUGH]
89 : monnier 245 | _ => error "branchTargets:BC"
90 :     (*esac*))
91 : george 1003 | branchTargets(I.INSTR(I.BCLR{labels, bo=I.ALWAYS, ...})) =
92 : monnier 245 (case labels of [] => [ESCAPES] | _ => map LABELLED labels)
93 : george 1003 | branchTargets(I.INSTR(I.BCLR{labels, ...})) =
94 : monnier 245 (case labels of [] => [ESCAPES, FALLTHROUGH] | _ => map LABELLED labels)
95 : george 1003 | branchTargets(I.INSTR(I.B{addr=I.LabelOp(T.LABEL lab), LK})) = [LABELLED lab]
96 :     | branchTargets(I.INSTR(I.CALL{cutsTo, ...})) = FALLTHROUGH::map LABELLED cutsTo
97 : george 1124 | branchTargets(I.INSTR(I.TD _)) = [ESCAPES]
98 :     | branchTargets(I.INSTR(I.TW _)) = [ESCAPES]
99 : monnier 411 | branchTargets(I.ANNOTATION{i,...}) = branchTargets i
100 : monnier 245 | branchTargets _ = error "branchTargets"
101 :    
102 : george 1124 fun labelOp l = I.LabelOp(T.LABEL l)
103 :    
104 :     fun setTargets(I.INSTR(I.BC{bo as I.ALWAYS, bf, bit, addr, fall, LK}), [l]) =
105 :     I.bc{bo=bo, bf=bf, bit=bit, fall=fall, LK=LK, addr=labelOp l}
106 :     | setTargets(I.INSTR(I.BC{bo, bf, bit, addr, fall, LK}), [f,t]) =
107 :     I.bc{bo=bo, bf=bf, bit=bit, LK=LK, addr=labelOp t, fall=labelOp f}
108 :     | setTargets(I.INSTR(I.BCLR _), _) = error "setTargets BCLR"
109 :     | setTargets(I.INSTR(I.B{addr, LK}), [l]) = I.b{addr=labelOp(l), LK=LK}
110 :     | setTargets(I.ANNOTATION{a,i}, l) = I.ANNOTATION{i=setTargets(i,l), a=a}
111 :     | setTargets _ = error "setTargets"
112 :    
113 : george 1003 fun jump lab = I.b{addr=I.LabelOp(T.LABEL lab), LK=false}
114 : monnier 245
115 : george 1124 fun negateConditional(I.ANNOTATION{a,i}, l) =
116 :     I.ANNOTATION{a=a, i=negateConditional(i, l)}
117 :     | negateConditional(I.INSTR(I.BC{bo, bf, bit, addr, fall, LK}), lab) = let
118 :     val bo' = (case bo
119 :     of I.TRUE => I.FALSE
120 :     | I.FALSE => I.TRUE
121 :     | I.ALWAYS => error "negateCondtional: ALWAYS"
122 :     | I.COUNTER{eqZero, cond=NONE} => I.COUNTER{eqZero=not eqZero, cond=NONE}
123 :     | I.COUNTER{eqZero, cond=SOME b} => error "negateConditional: COUNTER"
124 :     (*esac*))
125 :     in
126 :     I.bc{bo=bo', bf=bf, bit=bit, addr=labelOp lab, fall=fall, LK=LK}
127 :     end
128 :     | negateConditional _ = error "negateConditional"
129 :    
130 : monnier 411 val immedRange = {lo= ~32768, hi=32767}
131 :    
132 :     fun loadImmed{immed,t} =
133 : george 1003 I.arithi
134 : leunga 744 {oper=I.ADDI, rt=t, ra=zeroR(),
135 : leunga 657 im=if #lo immedRange <= immed andalso immed <= #hi immedRange
136 : leunga 775 then I.ImmedOp immed else I.LabelOp(I.T.LI(IntInf.fromInt immed))}
137 : leunga 657 fun loadOperand{opn,t} =
138 : george 1003 I.arithi{oper=I.ADDI, rt=t, ra=zeroR(), im=opn}
139 : monnier 411
140 : monnier 245
141 : george 889 fun hashOpn(I.RegOp r) = CB.hashCell r
142 : monnier 411 | hashOpn(I.ImmedOp i) = Word.fromInt i
143 : george 984 | hashOpn(I.LabelOp l) = MLTreeHash.hash l
144 : george 889 fun eqOpn(I.RegOp a,I.RegOp b) = CB.sameColor(a,b)
145 : monnier 411 | eqOpn(I.ImmedOp a,I.ImmedOp b) = a = b
146 : george 984 | eqOpn(I.LabelOp a,I.LabelOp b) = MLTreeEval.==(a,b)
147 : monnier 411 | eqOpn _ = false
148 :    
149 : monnier 245 fun defUseR instr = let
150 : george 1003 fun ppcDU instr = let
151 :     fun operand(I.RegOp r,use) = r::use
152 :     | operand(_,use) = use
153 :     in
154 :     case instr
155 :     of I.L{rt, ra, d, ...} => ([rt], operand(d,[ra]))
156 :     | I.LF{ra, d, ...} => ([], operand(d,[ra]))
157 :     | I.ST{rs, ra, d, ...} => ([], operand(d,[rs,ra]))
158 :     | I.STF{ra, d, ...} => ([], operand(d,[ra]))
159 :     | I.UNARY{rt, ra, ...} => ([rt], [ra])
160 :     | I.ARITH{rt, ra, rb, ...} => ([rt], [ra,rb])
161 :     | I.ARITHI{rt, ra, im, ...} => ([rt], operand(im,[ra]))
162 :     | I.ROTATE{ra, rs, sh, ...} => ([ra], [rs,sh])
163 :     | I.ROTATEI{ra, rs, sh, ...} => ([ra], operand(sh,[rs]))
164 :     | I.COMPARE{ra, rb, ...} => ([], operand(rb,[ra]))
165 :     | I.MTSPR{rs, ...} => ([], [rs])
166 :     | I.MFSPR{rt, ...} => ([rt], [])
167 :     | I.TW{to, ra, si} => ([], operand(si,[ra]))
168 :     | I.TD{to, ra, si} => ([], operand(si,[ra]))
169 :     | I.CALL{def, use, ...} => (C.getReg def, C.getReg use)
170 :     | _ => ([], [])
171 :     end
172 : monnier 245 in
173 :     case instr
174 : george 1003 of I.ANNOTATION{i, ...} => defUseR i
175 :     | I.LIVE{regs, ...} => ([], C.getReg regs)
176 :     | I.KILL{regs, ...} => (C.getReg regs, [])
177 :     | I.INSTR(i) => ppcDU(i)
178 : george 1009 | I.COPY{k, dst, src, tmp, ...} => let
179 :     val (d,u) = case k of CB.GP => (dst, src) | _ => ([], [])
180 :     in
181 :     case tmp
182 :     of SOME(I.Direct r) => (r::d, u)
183 :     | SOME(I.Displace{base, ...}) => (d, base::u)
184 :     | _ => (d,u)
185 :     end
186 : monnier 245 end
187 :    
188 : george 1003 fun defUseF instr = let
189 :     fun ppcDU instr =
190 :     (case instr
191 :     of I.LF{ft, ...} => ([ft],[])
192 :     | I.STF{fs, ...} => ([], [fs])
193 :     | I.FCOMPARE{fa, fb, ...} => ([], [fa, fb])
194 :     | I.FUNARY{ft, fb, ...} => ([ft], [fb])
195 :     | I.FARITH{ft, fa, fb, ...} => ([ft], [fa, fb])
196 :     | I.FARITH3{ft, fa, fb, fc, ...} => ([ft], [fa, fb, fc])
197 :     | I.CALL{def, use, ...} => (C.getFreg def,C.getFreg use)
198 :     | _ => ([], [])
199 :     (*esac*))
200 :     in
201 :     case instr
202 :     of I.ANNOTATION{i, ...} => defUseF i
203 :     | I.LIVE{regs, ...} => ([], C.getFreg regs)
204 :     | I.KILL{regs, ...} => (C.getFreg regs, [])
205 :     | I.INSTR(i) => ppcDU(i)
206 : george 1009 | I.COPY{k, dst, src, tmp, ...} => let
207 :     val (d, u) = case k of CB.FP => (dst, src) | _ => ([],[])
208 :     in
209 :     case tmp
210 :     of SOME(I.FDirect f) => (f::d, u)
211 :     | _ => (d, u)
212 :     end
213 : george 1003 end
214 : monnier 245 fun defUseCC instr = error "defUseCC: not implemented"
215 :    
216 : george 889 fun defUse CB.GP = defUseR
217 :     | defUse CB.FP = defUseF
218 :     | defUse CB.CC = defUseCC
219 : monnier 245 | defUse _ = error "defUse"
220 : monnier 411
221 :     (*========================================================================
222 :     * Annotations
223 :     *========================================================================*)
224 : monnier 469 fun getAnnotations(I.ANNOTATION{i,a}) =
225 :     let val (i,an) = getAnnotations i in (i,a::an) end
226 :     | getAnnotations i = (i,[])
227 : monnier 411 fun annotate(i,a) = I.ANNOTATION{i=i,a=a}
228 : leunga 657
229 :     (*========================================================================
230 :     * Replicate an instruction
231 :     *========================================================================*)
232 :     fun replicate(I.ANNOTATION{i,a}) = I.ANNOTATION{i=replicate i,a=a}
233 : george 1009 | replicate(I.COPY{k, sz, tmp=SOME _, dst, src}) =
234 :     I.COPY{k=k, sz=sz, tmp=SOME(I.Direct(C.newReg())), dst=dst, src=src}
235 : leunga 657 | replicate i = i
236 : monnier 245 end
237 :    
238 :    

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