Debian Codegraph @

lib/mlrisc-lib/MLRISC/alpha/backpatch/alphaJumps.sml

raw
1 (* alphaJumps.sml --- information to resolve jumps.
2 *
3 * COPYRIGHT (c) 1996 Bell Laboratories.
4 *
5 *)
6 functor AlphaJumps
7 (structure Instr : ALPHAINSTR
8 structure Shuffle : ALPHASHUFFLE (* where I = Instr *)
9 where type I.Constant.const = Instr.Constant.const
10 and type I.Region.region = Instr.Region.region
11 and type I.T.Basis.cond = Instr.T.Basis.cond
12 and type I.T.Basis.div_rounding_mode = Instr.T.Basis.div_rounding_mode
13 and type I.T.Basis.ext = Instr.T.Basis.ext
14 and type I.T.Basis.fcond = Instr.T.Basis.fcond
15 and type I.T.Basis.rounding_mode = Instr.T.Basis.rounding_mode
16 and type ('s,'r,'f,'c) I.T.Extension.ccx = ('s,'r,'f,'c) Instr.T.Extension.ccx
17 and type ('s,'r,'f,'c) I.T.Extension.fx = ('s,'r,'f,'c) Instr.T.Extension.fx
18 and type ('s,'r,'f,'c) I.T.Extension.rx = ('s,'r,'f,'c) Instr.T.Extension.rx
19 and type ('s,'r,'f,'c) I.T.Extension.sx = ('s,'r,'f,'c) Instr.T.Extension.sx
20 and type I.T.I.div_rounding_mode = Instr.T.I.div_rounding_mode
21 and type I.T.ccexp = Instr.T.ccexp
22 and type I.T.fexp = Instr.T.fexp
23 (* and type I.T.labexp = Instr.T.labexp *)
24 and type I.T.mlrisc = Instr.T.mlrisc
25 and type I.T.oper = Instr.T.oper
26 and type I.T.rep = Instr.T.rep
27 and type I.T.rexp = Instr.T.rexp
28 and type I.T.stm = Instr.T.stm
29 and type I.branch = Instr.branch
30 and type I.cmove = Instr.cmove
31 and type I.ea = Instr.ea
32 and type I.fbranch = Instr.fbranch
33 and type I.fcmove = Instr.fcmove
34 and type I.fload = Instr.fload
35 and type I.foperate = Instr.foperate
36 and type I.foperateV = Instr.foperateV
37 and type I.fstore = Instr.fstore
38 and type I.funary = Instr.funary
39 and type I.instr = Instr.instr
40 and type I.instruction = Instr.instruction
41 and type I.load = Instr.load
42 and type I.operand = Instr.operand
43 and type I.operate = Instr.operate
44 and type I.operateV = Instr.operateV
45 and type I.osf_user_palcode = Instr.osf_user_palcode
46 and type I.pseudo_op = Instr.pseudo_op
47 and type I.store = Instr.store
48 structure MLTreeEval : MLTREE_EVAL (* where T = Instr.T *)
49 where type T.Basis.cond = Instr.T.Basis.cond
50 and type T.Basis.div_rounding_mode = Instr.T.Basis.div_rounding_mode
51 and type T.Basis.ext = Instr.T.Basis.ext
52 and type T.Basis.fcond = Instr.T.Basis.fcond
53 and type T.Basis.rounding_mode = Instr.T.Basis.rounding_mode
54 and type T.Constant.const = Instr.T.Constant.const
55 and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) Instr.T.Extension.ccx
56 and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) Instr.T.Extension.fx
57 and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) Instr.T.Extension.rx
58 and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) Instr.T.Extension.sx
59 and type T.I.div_rounding_mode = Instr.T.I.div_rounding_mode
60 and type T.Region.region = Instr.T.Region.region
61 and type T.ccexp = Instr.T.ccexp
62 and type T.fexp = Instr.T.fexp
63 (* and type T.labexp = Instr.T.labexp *)
64 and type T.mlrisc = Instr.T.mlrisc
65 and type T.oper = Instr.T.oper
66 and type T.rep = Instr.T.rep
67 and type T.rexp = Instr.T.rexp
68 and type T.stm = Instr.T.stm
69 ) : SDI_JUMPS =
70 struct
71 structure I = Instr
72 structure C = I.C
73 structure Const = I.Constant
74 structure Eval = MLTreeEval
75 structure CB = CellsBasis
76
77 fun error msg = MLRiscErrorMsg.error("AlphaJumps",msg)
78
79 val branchDelayedArch = false
80
81 fun isSdi(I.ANNOTATION{i,...}) = isSdi i
82 | isSdi(I.LIVE _) = true
83 | isSdi(I.KILL _) = true
84 | isSdi(I.COPY _) = true
85 | isSdi(I.INSTR i) =
86 (case i
87 of (I.LDA{d=I.LABop _, ...}) => true
88 | (I.LOAD{d=I.LABop _, ...}) => true
89 | (I.STORE{d=I.LABop _, ...}) => true
90 | (I.FSTORE{d=I.LABop _, ...}) => true
91 | (I.FLOAD{d=I.LABop _, ...}) => true
92 | (I.OPERATE{rb=I.LABop _, ...}) => true
93 | (I.OPERATEV{rb=I.LABop _, ...})=> true
94 | (I.CMOVE{rb=I.LABop _, ...}) => true
95 | _ => false
96 (*esac*))
97
98 fun minSize(I.LIVE _) = 0
99 | minSize(I.KILL _) = 0
100 | minSize(I.COPY _) = 0
101 | minSize(I.ANNOTATION{i,...}) = minSize i
102 | minSize _ = 4
103
104 (* max Size is not used for the alpha span dependency analysis. *)
105 fun maxSize _ = error "maxSize"
106
107 fun immed16 n = ~32768 <= n andalso n < 32768
108 fun im16load n = if immed16 n then 4 else 8
109 fun im16Oper le = if immed16 (Eval.valueOf le) then 4 else 12
110
111 fun immed8 n = n >= 0 andalso n < 256
112 fun im8Oper le = if immed8 (Eval.valueOf le) then 4 else 12
113 fun sdiSize(I.ANNOTATION{i,...},x,y) = sdiSize(i,x,y)
114 | sdiSize(I.LIVE _, _, _) = 0
115 | sdiSize(I.KILL _, _, _) = 0
116 | sdiSize(I.COPY{k=CB.GP, src, dst, tmp, ...}, _, _) =
117 4 * length(Shuffle.shuffle{tmp=tmp, dst=dst, src=src})
118 | sdiSize(I.COPY{k=CB.FP, src, dst, tmp, ...}, _, _) =
119 4 * length(Shuffle.shufflefp{src=src, dst=dst, tmp=tmp})
120 | sdiSize(I.INSTR instr, _, _) =
121 (case instr
122 of (I.LDA{d=I.LABop le, ...}) => im16load(Eval.valueOf le)
123 | (I.LOAD{d=I.LABop le, ...}) => im16Oper le
124 | (I.STORE{d=I.LABop le, ...}) => im16Oper le
125 | (I.FLOAD{d=I.LABop le, ...}) => im16Oper le
126 | (I.FSTORE{d=I.LABop le, ...}) => im16Oper le
127 | (I.OPERATE{rb=I.LABop le, ...}) => im8Oper le
128 | (I.OPERATEV{rb=I.LABop le, ...}) => im8Oper le
129 | (I.CMOVE{rb=I.LABop le, ...}) => im8Oper le
130 | _ => error "sdiSize"
131 (*easc*))
132 | sdiSize _ = error "sdiSize"
133
134 (* NOTE: All sdis must use a dedicated physical register as a
135 * temporaries, since sdi expansion is performed after register
136 * allocation.
137 *)
138 val zeroR = Option.valOf(C.zeroReg CellsBasis.GP)
139
140 fun caseSize 4 { four, twelf } = four ()
141 | caseSize 12 { four, twelf } = twelf ()
142 | caseSize sz _ = error ("caseSize " ^ Int.toString sz)
143
144 fun expand(I.ANNOTATION{i,...}, size, pos) = expand(i,size,pos)
145 | expand(I.LIVE _, _, _) = []
146 | expand(I.KILL _, _, _) = []
147 | expand(I.COPY{k=CB.GP, src, tmp, dst, ...}, _, _) =
148 Shuffle.shuffle{src=src, dst=dst, tmp=tmp}
149 | expand(I.COPY{k=CB.FP, src, tmp, dst, ...}, _, _) =
150 Shuffle.shufflefp{src=src, dst=dst, tmp=tmp}
151 | expand(I.INSTR instr, size, pos) = let
152 fun load(ldClass, ldOp, r, b, d as I.LABop le, mem) =
153 caseSize size
154 { four = fn () =>
155 [ldClass{ldOp=ldOp, r=r, b=b,
156 d=I.IMMop(Eval.valueOf le), mem=mem}],
157 twelf = fn () => let
158 val instrs = expand(I.lda{r=r, b=b, d=d}, 8, pos)
159 in instrs @ [ldClass{ldOp=ldOp, r=r, b=r,
160 d=I.IMMop 0, mem=mem}]
161 end }
162 | load _ = error "store"
163
164 fun store(stClass, stOp, r, b, d as I.LABop le, mem) =
165 caseSize size
166 { four = fn () =>
167 [stClass{stOp=stOp, r=r, b=b,
168 d=I.IMMop(Eval.valueOf le), mem=mem}],
169 twelf = fn () => let
170 val instrs = expand(I.lda{r=C.asmTmpR, b=b, d=d}, 8, pos)
171 in instrs @ [stClass{stOp=stOp, r=r, b=C.asmTmpR,
172 d=I.IMMop 0, mem=mem}]
173 end }
174 | store _ = error "store"
175
176 fun operate(opClass, oper, ra, rb as I.LABop le, rc) =
177 caseSize size
178 { four = fn () =>
179 [opClass{oper=oper, ra=ra,
180 rb=I.IMMop(Eval.valueOf le), rc=rc}],
181 twelf = fn () => let
182 val instrs = expand(I.lda{r=C.asmTmpR, b=zeroR, d=rb}, 8, pos)
183 in instrs @ [opClass{oper=oper, ra=ra,
184 rb=I.REGop C.asmTmpR, rc=rc}]
185 end }
186 | operate _ = error "operate"
187 in
188
189 case instr
190 of I.LDA{r=rd, b=rs, d=I.LABop le} =>
191 (case size of
192 4 => [I.lda{r=rd, b=rs, d=I.LOLABop le}]
193 | 8 => [I.lda{r=rd, b=rs, d=I.LOLABop le},
194 I.ldah{r=rd, b=rd, d=I.HILABop le}]
195 | _ => error "expand:LDA"
196 )
197 | I.LOAD{ldOp, r, b, d, mem} => load(I.load, ldOp, r, b, d, mem)
198 | I.FLOAD{ldOp, r, b, d, mem} => load(I.fload, ldOp, r, b, d, mem)
199 | I.STORE{stOp, r, b, d, mem} => store(I.store, stOp, r, b, d, mem)
200 | I.FSTORE{stOp, r, b, d, mem} => store(I.fstore, stOp, r, b, d, mem)
201 | I.OPERATE{oper, ra, rb, rc} => operate(I.operate, oper, ra, rb, rc)
202 | I.OPERATEV{oper, ra, rb, rc} => operate(I.operatev, oper, ra, rb, rc)
203 | I.CMOVE{oper, ra, rb, rc} =>
204 caseSize size
205 { four = fn () => [I.INSTR instr],
206 twelf = fn () => let
207 val instrs = expand(I.lda{r=C.asmTmpR, b=zeroR, d=rb},
208 8, pos)
209 in instrs @ [I.cmove{oper=oper, ra=ra,
210 rb=I.REGop C.asmTmpR, rc=rc}]
211 end }
212 | _ => error "expand"
213 end
214 | expand _ = error "expand"
215 end
216
217