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 1082 - (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 1003 | instrKind(I.INSTR instr) =
31 :     (case instr
32 :     of (I.BC _) => IK_JUMP
33 :     | (I.BCLR _) => IK_JUMP
34 :     | (I.B _) => IK_JUMP
35 :     | (I.ARITHI{oper=I.ORI, rt, ra, im=I.ImmedOp 0}) =>
36 :     if CB.registerId rt = 0 andalso CB.registerId ra = 0 then IK_NOP
37 :     else IK_INSTR
38 :     | (I.CALL{cutsTo=_::_,...}) => IK_CALL_WITH_CUTS
39 :     | (I.CALL _) => IK_CALL
40 :     | (I.PHI _) => IK_PHI
41 :     | (I.SOURCE _) => IK_SOURCE
42 :     | (I.SINK _) => IK_SINK
43 :     | _ => IK_INSTR)
44 :     | instrKind _ = error "instrKind"
45 : monnier 245
46 : george 1009 fun moveInstr(I.COPY _) = true
47 : monnier 411 | moveInstr(I.ANNOTATION{i,...}) = moveInstr i
48 : monnier 245 | moveInstr _ = false
49 :    
50 : george 1003 fun nop () = I.arithi{oper=I.ORI, rt=zeroR(), ra=zeroR(), im=I.ImmedOp 0}
51 : monnier 245
52 : george 1009 fun moveTmpR(I.COPY{tmp, ...}) =
53 :     (case tmp
54 :     of SOME(I.Direct r) => SOME r
55 :     | SOME(I.FDirect f) => SOME f
56 :     | _ => NONE
57 :     (*esac*))
58 : monnier 411 | moveTmpR(I.ANNOTATION{i,...}) = moveTmpR i
59 : monnier 245 | moveTmpR _ = NONE
60 :    
61 : george 1009 fun moveDstSrc(I.COPY{dst,src,...}) = (dst,src)
62 : monnier 411 | moveDstSrc(I.ANNOTATION{i,...}) = moveDstSrc i
63 : monnier 245 | moveDstSrc _ = error "moveDstSrc"
64 :    
65 : george 1009
66 : george 1003 fun branchTargets(I.INSTR(I.BC{bo=I.ALWAYS, addr, ...})) =
67 : monnier 245 (case addr
68 : leunga 775 of I.LabelOp(T.LABEL lab) => [LABELLED lab]
69 : monnier 245 | _ => error "branchTargets:BC:ALWAYS"
70 :     (*esac*))
71 : george 1003 | branchTargets(I.INSTR(I.BC{addr, ...})) =
72 : monnier 245 (case addr
73 : leunga 775 of I.LabelOp(T.LABEL lab) => [LABELLED lab, FALLTHROUGH]
74 : monnier 245 | _ => error "branchTargets:BC"
75 :     (*esac*))
76 : george 1003 | branchTargets(I.INSTR(I.BCLR{labels, bo=I.ALWAYS, ...})) =
77 : monnier 245 (case labels of [] => [ESCAPES] | _ => map LABELLED labels)
78 : george 1003 | branchTargets(I.INSTR(I.BCLR{labels, ...})) =
79 : monnier 245 (case labels of [] => [ESCAPES, FALLTHROUGH] | _ => map LABELLED labels)
80 : george 1003 | branchTargets(I.INSTR(I.B{addr=I.LabelOp(T.LABEL lab), LK})) = [LABELLED lab]
81 :     | branchTargets(I.INSTR(I.CALL{cutsTo, ...})) = FALLTHROUGH::map LABELLED cutsTo
82 : monnier 411 | branchTargets(I.ANNOTATION{i,...}) = branchTargets i
83 : monnier 245 | branchTargets _ = error "branchTargets"
84 :    
85 : george 1003 fun jump lab = I.b{addr=I.LabelOp(T.LABEL lab), LK=false}
86 : monnier 245
87 : monnier 411 val immedRange = {lo= ~32768, hi=32767}
88 :    
89 :     fun loadImmed{immed,t} =
90 : george 1003 I.arithi
91 : leunga 744 {oper=I.ADDI, rt=t, ra=zeroR(),
92 : leunga 657 im=if #lo immedRange <= immed andalso immed <= #hi immedRange
93 : leunga 775 then I.ImmedOp immed else I.LabelOp(I.T.LI(IntInf.fromInt immed))}
94 : leunga 657 fun loadOperand{opn,t} =
95 : george 1003 I.arithi{oper=I.ADDI, rt=t, ra=zeroR(), im=opn}
96 : monnier 411
97 : monnier 245 fun setTargets _ = error " setTargets"
98 :    
99 :     fun negateConditional _ = error "negateConditional"
100 :    
101 : george 889 fun hashOpn(I.RegOp r) = CB.hashCell r
102 : monnier 411 | hashOpn(I.ImmedOp i) = Word.fromInt i
103 : george 984 | hashOpn(I.LabelOp l) = MLTreeHash.hash l
104 : george 889 fun eqOpn(I.RegOp a,I.RegOp b) = CB.sameColor(a,b)
105 : monnier 411 | eqOpn(I.ImmedOp a,I.ImmedOp b) = a = b
106 : george 984 | eqOpn(I.LabelOp a,I.LabelOp b) = MLTreeEval.==(a,b)
107 : monnier 411 | eqOpn _ = false
108 :    
109 : monnier 245 fun defUseR instr = let
110 : george 1003 fun ppcDU instr = let
111 :     fun operand(I.RegOp r,use) = r::use
112 :     | operand(_,use) = use
113 :     in
114 :     case instr
115 :     of I.L{rt, ra, d, ...} => ([rt], operand(d,[ra]))
116 :     | I.LF{ra, d, ...} => ([], operand(d,[ra]))
117 :     | I.ST{rs, ra, d, ...} => ([], operand(d,[rs,ra]))
118 :     | I.STF{ra, d, ...} => ([], operand(d,[ra]))
119 :     | I.UNARY{rt, ra, ...} => ([rt], [ra])
120 :     | I.ARITH{rt, ra, rb, ...} => ([rt], [ra,rb])
121 :     | I.ARITHI{rt, ra, im, ...} => ([rt], operand(im,[ra]))
122 :     | I.ROTATE{ra, rs, sh, ...} => ([ra], [rs,sh])
123 :     | I.ROTATEI{ra, rs, sh, ...} => ([ra], operand(sh,[rs]))
124 :     | I.COMPARE{ra, rb, ...} => ([], operand(rb,[ra]))
125 :     | I.MTSPR{rs, ...} => ([], [rs])
126 :     | I.MFSPR{rt, ...} => ([rt], [])
127 :     | I.TW{to, ra, si} => ([], operand(si,[ra]))
128 :     | I.TD{to, ra, si} => ([], operand(si,[ra]))
129 :     | I.CALL{def, use, ...} => (C.getReg def, C.getReg use)
130 :     | _ => ([], [])
131 :     end
132 : monnier 245 in
133 :     case instr
134 : george 1003 of I.ANNOTATION{i, ...} => defUseR i
135 :     | I.LIVE{regs, ...} => ([], C.getReg regs)
136 :     | I.KILL{regs, ...} => (C.getReg regs, [])
137 :     | I.INSTR(i) => ppcDU(i)
138 : george 1009 | I.COPY{k, dst, src, tmp, ...} => let
139 :     val (d,u) = case k of CB.GP => (dst, src) | _ => ([], [])
140 :     in
141 :     case tmp
142 :     of SOME(I.Direct r) => (r::d, u)
143 :     | SOME(I.Displace{base, ...}) => (d, base::u)
144 :     | _ => (d,u)
145 :     end
146 : monnier 245 end
147 :    
148 : george 1003 fun defUseF instr = let
149 :     fun ppcDU instr =
150 :     (case instr
151 :     of I.LF{ft, ...} => ([ft],[])
152 :     | I.STF{fs, ...} => ([], [fs])
153 :     | I.FCOMPARE{fa, fb, ...} => ([], [fa, fb])
154 :     | I.FUNARY{ft, fb, ...} => ([ft], [fb])
155 :     | I.FARITH{ft, fa, fb, ...} => ([ft], [fa, fb])
156 :     | I.FARITH3{ft, fa, fb, fc, ...} => ([ft], [fa, fb, fc])
157 :     | I.CALL{def, use, ...} => (C.getFreg def,C.getFreg use)
158 :     | _ => ([], [])
159 :     (*esac*))
160 :     in
161 :     case instr
162 :     of I.ANNOTATION{i, ...} => defUseF i
163 :     | I.LIVE{regs, ...} => ([], C.getFreg regs)
164 :     | I.KILL{regs, ...} => (C.getFreg regs, [])
165 :     | I.INSTR(i) => ppcDU(i)
166 : george 1009 | I.COPY{k, dst, src, tmp, ...} => let
167 :     val (d, u) = case k of CB.FP => (dst, src) | _ => ([],[])
168 :     in
169 :     case tmp
170 :     of SOME(I.FDirect f) => (f::d, u)
171 :     | _ => (d, u)
172 :     end
173 : george 1003 end
174 : monnier 245 fun defUseCC instr = error "defUseCC: not implemented"
175 :    
176 : george 889 fun defUse CB.GP = defUseR
177 :     | defUse CB.FP = defUseF
178 :     | defUse CB.CC = defUseCC
179 : monnier 245 | defUse _ = error "defUse"
180 : monnier 411
181 :     (*========================================================================
182 :     * Annotations
183 :     *========================================================================*)
184 : monnier 469 fun getAnnotations(I.ANNOTATION{i,a}) =
185 :     let val (i,an) = getAnnotations i in (i,a::an) end
186 :     | getAnnotations i = (i,[])
187 : monnier 411 fun annotate(i,a) = I.ANNOTATION{i=i,a=a}
188 : leunga 657
189 :     (*========================================================================
190 :     * Replicate an instruction
191 :     *========================================================================*)
192 :     fun replicate(I.ANNOTATION{i,a}) = I.ANNOTATION{i=replicate i,a=a}
193 : george 1009 | replicate(I.COPY{k, sz, tmp=SOME _, dst, src}) =
194 :     I.COPY{k=k, sz=sz, tmp=SOME(I.Direct(C.newReg())), dst=dst, src=src}
195 : leunga 657 | replicate i = i
196 : monnier 245 end
197 :    
198 :    

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