Debian Codegraph @

lib/mlrisc-lib/MLRISC/amd64/instructions/amd64Peephole.sml

raw
1 (* WARNING: this is generated by running 'nowhere amd64Peephole.peep'.
2 * Do not edit this file directly.
3 * Version 1.2.2
4 *)
5
6 (*#line 20.1 "amd64Peephole.peep"*)
7 functor AMD64Peephole(
8 (*#line 21.5 "amd64Peephole.peep"*)
9 structure Instr : AMD64INSTR
10
11 (*#line 22.5 "amd64Peephole.peep"*)
12 structure Eval : MLTREE_EVAL
13
14 (*#line 23.7 "amd64Peephole.peep"*)
15 (* sharing Instr.T = Eval.T *)
16 where type T.Basis.cond = Instr.T.Basis.cond
17 and type T.Basis.div_rounding_mode = Instr.T.Basis.div_rounding_mode
18 and type T.Basis.ext = Instr.T.Basis.ext
19 and type T.Basis.fcond = Instr.T.Basis.fcond
20 and type T.Basis.rounding_mode = Instr.T.Basis.rounding_mode
21 and type T.Constant.const = Instr.T.Constant.const
22 and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) Instr.T.Extension.ccx
23 and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) Instr.T.Extension.fx
24 and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) Instr.T.Extension.rx
25 and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) Instr.T.Extension.sx
26 and type T.I.div_rounding_mode = Instr.T.I.div_rounding_mode
27 and type T.Region.region = Instr.T.Region.region
28 and type T.ccexp = Instr.T.ccexp
29 and type T.fexp = Instr.T.fexp
30 (* and type T.labexp = Instr.T.labexp *)
31 and type T.mlrisc = Instr.T.mlrisc
32 and type T.oper = Instr.T.oper
33 and type T.rep = Instr.T.rep
34 and type T.rexp = Instr.T.rexp
35 and type T.stm = Instr.T.stm
36 ): PEEPHOLE =
37 struct
38
39 (*#line 26.4 "amd64Peephole.peep"*)
40 structure I = Instr
41
42 (*#line 27.4 "amd64Peephole.peep"*)
43 structure C = I.C
44
45 (*#line 28.4 "amd64Peephole.peep"*)
46 structure CBase = CellsBasis
47
48 (*#line 31.4 "amd64Peephole.peep"*)
49 fun peephole instrs =
50 let
51 (*#line 32.8 "amd64Peephole.peep"*)
52 fun isStackPtr (I.Direct(_, r)) = CBase.sameColor (r, C.rsp)
53 | isStackPtr _ = false
54
55 (*#line 35.8 "amd64Peephole.peep"*)
56 fun isZeroLE le = (((Eval.valueOf le) = 0) handle _ => false
57 )
58
59 (*#line 37.8 "amd64Peephole.peep"*)
60 fun isZero (I.Immed n) = n = 0
61 | isZero (I.ImmedLabel le) = isZeroLE le
62 | isZero _ = false
63
64 (*#line 41.8 "amd64Peephole.peep"*)
65 fun isZeroOpt NONE = true
66 | isZeroOpt (SOME opn) = isZero opn
67
68 (*#line 44.8 "amd64Peephole.peep"*)
69 fun loop (code, instrs) =
70 let val v_39 = code
71 fun state_10 (v_0, v_3) =
72 let val i = v_0
73 and rest = v_3
74 in loop (rest, i :: instrs)
75 end
76 fun state_12 (v_0, v_19, v_3) =
77 let val le = v_19
78 and rest = v_3
79 in (if (isZeroLE le)
80 then (loop (rest, instrs))
81 else (state_10 (v_0, v_3)))
82 end
83 fun state_67 (v_0, v_1, v_2, v_3) =
84 (case v_1 of
85 I.Direct v_35 =>
86 let val dst = v_1
87 and rest = v_3
88 and src = v_2
89 in (if (isZero src)
90 then (loop (rest, (I.binary {binOp=I.XORQ, src=dst, dst=dst}) :: instrs))
91 else (state_10 (v_0, v_3)))
92 end
93 | _ => state_10 (v_0, v_3)
94 )
95 fun state_13 (v_0, v_2, v_3) =
96 (case v_2 of
97 I.ImmedLabel v_19 => state_12 (v_0, v_19, v_3)
98 | _ => state_10 (v_0, v_3)
99 )
100 in
101 (case v_39 of
102 op :: v_38 =>
103 let val (v_0, v_3) = v_38
104 in
105 (case v_0 of
106 I.INSTR v_37 =>
107 (case v_37 of
108 I.BINARY v_21 =>
109 let val {binOp=v_36, dst=v_1, src=v_2, ...} = v_21
110 in
111 (case v_36 of
112 I.ADDL => state_13 (v_0, v_2, v_3)
113 | I.ADDQ =>
114 (case v_2 of
115 I.Immed v_19 =>
116 (case v_1 of
117 I.Direct v_35 =>
118 let val (v_34, v_29) = v_35
119 in
120 (case v_3 of
121 op :: v_16 =>
122 let val (v_15, v_4) = v_16
123 in
124 (case v_15 of
125 I.INSTR v_14 =>
126 (case v_14 of
127 I.BINARY v_13 =>
128 let val {binOp=v_12, dst=v_11, src=v_8, ...} = v_13
129 in
130 (case v_12 of
131 I.SUBQ =>
132 (case v_11 of
133 I.Direct v_10 =>
134 let val (v_9, v_5) = v_10
135 in
136 (case v_8 of
137 I.Immed v_7 =>
138 let val d_i = v_29
139 and d_j = v_5
140 and m = v_7
141 and n = v_19
142 and rest = v_4
143 and ty = v_9
144 in (if ((CBase.sameColor (d_i, C.rsp)) andalso (CBase.sameColor (d_j, C.rsp)))
145 then (if (m = n)
146 then (loop (rest, instrs))
147 else (if (m < n)
148 then (loop (rest, (I.binary {binOp=I.ADDQ, src=I.Immed (n - m), dst=I.Direct (ty, C.rsp)}) :: instrs))
149 else (loop (rest, (I.binary {binOp=I.SUBQ, src=I.Immed (m - n), dst=I.Direct (ty, C.rsp)}) :: instrs))))
150 else (state_10 (v_0, v_3)))
151 end
152 | _ => state_10 (v_0, v_3)
153 )
154 end
155 | _ => state_10 (v_0, v_3)
156 )
157 | _ => state_10 (v_0, v_3)
158 )
159 end
160 | _ => state_10 (v_0, v_3)
161 )
162 | _ => state_10 (v_0, v_3)
163 )
164 end
165 | nil => state_10 (v_0, v_3)
166 )
167 end
168 | _ => state_10 (v_0, v_3)
169 )
170 | I.ImmedLabel v_19 => state_12 (v_0, v_19, v_3)
171 | _ => state_10 (v_0, v_3)
172 )
173 | I.SUBL => state_13 (v_0, v_2, v_3)
174 | I.SUBQ =>
175 (case v_2 of
176 I.Immed v_19 =>
177 (case v_1 of
178 I.Direct v_35 =>
179 let val (v_34, v_29) = v_35
180 in
181 (case v_19 of
182 4 =>
183 (case v_3 of
184 op :: v_16 =>
185 let val (v_15, v_4) = v_16
186 in
187 (case v_15 of
188 I.INSTR v_14 =>
189 (case v_14 of
190 I.MOVE v_13 =>
191 let val {dst=v_11, mvOp=v_31, src=v_8, ...} = v_13
192 in
193 (case v_11 of
194 I.Displace v_10 =>
195 let val {base=v_30, disp=v_33, ...} = v_10
196 in
197 (case v_33 of
198 I.Immed v_32 =>
199 (case v_32 of
200 0 =>
201 (case v_31 of
202 I.MOVQ =>
203 let val base = v_30
204 and dst_i = v_29
205 and rest = v_4
206 and src = v_8
207 in (if (((CBase.sameColor (base, C.rsp)) andalso (CBase.sameColor (dst_i, C.rsp))) andalso (not (isStackPtr src)))
208 then (loop (rest, (I.push src) :: instrs))
209 else (state_10 (v_0, v_3)))
210 end
211 | _ => state_10 (v_0, v_3)
212 )
213 | _ => state_10 (v_0, v_3)
214 )
215 | _ => state_10 (v_0, v_3)
216 )
217 end
218 | _ => state_10 (v_0, v_3)
219 )
220 end
221 | _ => state_10 (v_0, v_3)
222 )
223 | _ => state_10 (v_0, v_3)
224 )
225 end
226 | nil => state_10 (v_0, v_3)
227 )
228 | _ => state_10 (v_0, v_3)
229 )
230 end
231 | _ => state_10 (v_0, v_3)
232 )
233 | I.ImmedLabel v_19 => state_12 (v_0, v_19, v_3)
234 | _ => state_10 (v_0, v_3)
235 )
236 | _ => state_10 (v_0, v_3)
237 )
238 end
239 | I.LEAL v_21 =>
240 let val {addr=v_27, r32=v_28, ...} = v_21
241 in
242 (case v_27 of
243 I.Displace v_26 =>
244 let val {base=v_24, disp=v_25, ...} = v_26
245 in
246 (case v_25 of
247 I.ImmedLabel v_23 =>
248 let val base = v_24
249 and le = v_23
250 and r32 = v_28
251 and rest = v_3
252 in (if ((isZeroLE le) andalso (CBase.sameColor (r32, base)))
253 then (loop (rest, instrs))
254 else (state_10 (v_0, v_3)))
255 end
256 | _ => state_10 (v_0, v_3)
257 )
258 end
259 | _ => state_10 (v_0, v_3)
260 )
261 end
262 | I.LEAQ v_21 =>
263 let val {addr=v_27, r64=v_22, ...} = v_21
264 in
265 (case v_27 of
266 I.Displace v_26 =>
267 let val {base=v_24, disp=v_25, ...} = v_26
268 in
269 (case v_25 of
270 I.ImmedLabel v_23 =>
271 let val base = v_24
272 and le = v_23
273 and r64 = v_22
274 and rest = v_3
275 in (if ((isZeroLE le) andalso (CBase.sameColor (r64, base)))
276 then (loop (rest, instrs))
277 else (state_10 (v_0, v_3)))
278 end
279 | _ => state_10 (v_0, v_3)
280 )
281 end
282 | _ => state_10 (v_0, v_3)
283 )
284 end
285 | I.MOVE v_21 =>
286 let val {dst=v_1, mvOp=v_20, src=v_2, ...} = v_21
287 in
288 (case v_20 of
289 I.MOVQ =>
290 (case v_2 of
291 I.Displace v_19 =>
292 let val {base=v_6, disp=v_18, ...} = v_19
293 in
294 (case v_18 of
295 I.Immed v_17 =>
296 (case v_17 of
297 0 =>
298 (case v_3 of
299 op :: v_16 =>
300 let val (v_15, v_4) = v_16
301 in
302 (case v_15 of
303 I.INSTR v_14 =>
304 (case v_14 of
305 I.BINARY v_13 =>
306 let val {binOp=v_12, dst=v_11, src=v_8, ...} = v_13
307 in
308 (case v_12 of
309 I.ADDQ =>
310 (case v_11 of
311 I.Direct v_10 =>
312 let val (v_9, v_5) = v_10
313 in
314 (case v_8 of
315 I.Immed v_7 =>
316 (case v_7 of
317 4 =>
318 let val base = v_6
319 and dst = v_1
320 and dst_i = v_5
321 and rest = v_4
322 in (if (((CBase.sameColor (base, C.rsp)) andalso (CBase.sameColor (dst_i, C.rsp))) andalso (not (isStackPtr dst)))
323 then (loop (rest, (I.pop dst) :: instrs))
324 else (state_67 (v_0, v_1, v_2, v_3)))
325 end
326 | _ => state_67 (v_0, v_1, v_2, v_3)
327 )
328 | _ => state_67 (v_0, v_1, v_2, v_3)
329 )
330 end
331 | _ => state_67 (v_0, v_1, v_2, v_3)
332 )
333 | _ => state_67 (v_0, v_1, v_2, v_3)
334 )
335 end
336 | _ => state_67 (v_0, v_1, v_2, v_3)
337 )
338 | _ => state_67 (v_0, v_1, v_2, v_3)
339 )
340 end
341 | nil => state_67 (v_0, v_1, v_2, v_3)
342 )
343 | _ => state_67 (v_0, v_1, v_2, v_3)
344 )
345 | _ => state_67 (v_0, v_1, v_2, v_3)
346 )
347 end
348 | _ => state_67 (v_0, v_1, v_2, v_3)
349 )
350 | _ => state_10 (v_0, v_3)
351 )
352 end
353 | _ => state_10 (v_0, v_3)
354 )
355 | _ => state_10 (v_0, v_3)
356 )
357 end
358 | nil => instrs
359 )
360 end
361 in loop (instrs, [])
362 end
363 end
364