Debian Codegraph @

lib/mlrisc-lib/MLRISC/x86/instructions/x86Peephole.sml

raw
1 (* WARNING: this is generated by running 'nowhere x86Peephole.peep'.
2 * Do not edit this file directly.
3 * Version 1.2.2
4 *)
5
6 (*#line 20.1 "x86Peephole.peep"*)
7 functor X86Peephole(
8 (*#line 21.5 "x86Peephole.peep"*)
9 structure Instr : X86INSTR
10
11 (*#line 22.5 "x86Peephole.peep"*)
12 structure Eval : MLTREE_EVAL
13
14 (*#line 23.7 "x86Peephole.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 "x86Peephole.peep"*)
40 structure I = Instr
41
42 (*#line 27.4 "x86Peephole.peep"*)
43 structure C = I.C
44
45 (*#line 28.4 "x86Peephole.peep"*)
46 structure CBase = CellsBasis
47
48 (*#line 31.4 "x86Peephole.peep"*)
49 fun peephole instrs =
50 let
51 (*#line 32.8 "x86Peephole.peep"*)
52 fun isStackPtr (I.Direct r) = CBase.sameColor (r, C.esp)
53 | isStackPtr _ = false
54
55 (*#line 35.8 "x86Peephole.peep"*)
56 fun isZeroLE le = (((Eval.valueOf le) = 0) handle _ => false
57 )
58
59 (*#line 37.8 "x86Peephole.peep"*)
60 fun isZero (I.Immed n) = n = 0
61 | isZero (I.ImmedLabel le) = isZeroLE le
62 | isZero _ = false
63
64 (*#line 41.8 "x86Peephole.peep"*)
65 fun isZeroOpt NONE = true
66 | isZeroOpt (SOME opn) = isZero opn
67
68 (*#line 44.8 "x86Peephole.peep"*)
69 fun loop (code, instrs) =
70 let val v_34 = code
71 fun state_9 (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_22 (v_0, v_17, v_3) =
77 let val le = v_17
78 and rest = v_3
79 in (if (isZeroLE le)
80 then (loop (rest, instrs))
81 else (state_9 (v_0, v_3)))
82 end
83 fun state_51 (v_0, v_1, v_2, v_3) =
84 (case v_1 of
85 I.Direct v_26 =>
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.XORL, src=dst, dst=dst}) :: instrs))
91 else (state_9 (v_0, v_3)))
92 end
93 | _ => state_9 (v_0, v_3)
94 )
95 in
96 (case v_34 of
97 op :: v_33 =>
98 let val (v_0, v_3) = v_33
99 in
100 (case v_0 of
101 I.INSTR v_32 =>
102 (case v_32 of
103 I.BINARY v_19 =>
104 let val {binOp=v_31, dst=v_1, src=v_2, ...} = v_19
105 in
106 (case v_31 of
107 I.ADDL =>
108 (case v_2 of
109 I.Immed v_17 =>
110 (case v_1 of
111 I.Direct v_26 =>
112 (case v_3 of
113 op :: v_14 =>
114 let val (v_13, v_4) = v_14
115 in
116 (case v_13 of
117 I.INSTR v_12 =>
118 (case v_12 of
119 I.BINARY v_11 =>
120 let val {binOp=v_10, dst=v_9, src=v_8, ...} = v_11
121 in
122 (case v_10 of
123 I.SUBL =>
124 (case v_9 of
125 I.Direct v_5 =>
126 (case v_8 of
127 I.Immed v_7 =>
128 let val d_i = v_26
129 and d_j = v_5
130 and m = v_7
131 and n = v_17
132 and rest = v_4
133 in (if ((CBase.sameColor (d_i, C.esp)) andalso (CBase.sameColor (d_j, C.esp)))
134 then (if (m = n)
135 then (loop (rest, instrs))
136 else (if (m < n)
137 then (loop (rest, (I.binary {binOp=I.ADDL, src=I.Immed (n - m), dst=I.Direct C.esp}) :: instrs))
138 else (loop (rest, (I.binary {binOp=I.SUBL, src=I.Immed (m - n), dst=I.Direct C.esp}) :: instrs))))
139 else (state_9 (v_0, v_3)))
140 end
141 | _ => state_9 (v_0, v_3)
142 )
143 | _ => state_9 (v_0, v_3)
144 )
145 | _ => state_9 (v_0, v_3)
146 )
147 end
148 | _ => state_9 (v_0, v_3)
149 )
150 | _ => state_9 (v_0, v_3)
151 )
152 end
153 | nil => state_9 (v_0, v_3)
154 )
155 | _ => state_9 (v_0, v_3)
156 )
157 | I.ImmedLabel v_17 => state_22 (v_0, v_17, v_3)
158 | _ => state_9 (v_0, v_3)
159 )
160 | I.SUBL =>
161 (case v_2 of
162 I.Immed v_17 =>
163 (case v_1 of
164 I.Direct v_26 =>
165 (case v_17 of
166 4 =>
167 (case v_3 of
168 op :: v_14 =>
169 let val (v_13, v_4) = v_14
170 in
171 (case v_13 of
172 I.INSTR v_12 =>
173 (case v_12 of
174 I.MOVE v_11 =>
175 let val {dst=v_9, mvOp=v_28, src=v_8, ...} = v_11
176 in
177 (case v_9 of
178 I.Displace v_5 =>
179 let val {base=v_27, disp=v_30, ...} = v_5
180 in
181 (case v_30 of
182 I.Immed v_29 =>
183 (case v_29 of
184 0 =>
185 (case v_28 of
186 I.MOVL =>
187 let val base = v_27
188 and dst_i = v_26
189 and rest = v_4
190 and src = v_8
191 in (if (((CBase.sameColor (base, C.esp)) andalso (CBase.sameColor (dst_i, C.esp))) andalso (not (isStackPtr src)))
192 then (loop (rest, (I.pushl src) :: instrs))
193 else (state_9 (v_0, v_3)))
194 end
195 | _ => state_9 (v_0, v_3)
196 )
197 | _ => state_9 (v_0, v_3)
198 )
199 | _ => state_9 (v_0, v_3)
200 )
201 end
202 | _ => state_9 (v_0, v_3)
203 )
204 end
205 | _ => state_9 (v_0, v_3)
206 )
207 | _ => state_9 (v_0, v_3)
208 )
209 end
210 | nil => state_9 (v_0, v_3)
211 )
212 | _ => state_9 (v_0, v_3)
213 )
214 | _ => state_9 (v_0, v_3)
215 )
216 | I.ImmedLabel v_17 => state_22 (v_0, v_17, v_3)
217 | _ => state_9 (v_0, v_3)
218 )
219 | _ => state_9 (v_0, v_3)
220 )
221 end
222 | I.LEA v_19 =>
223 let val {addr=v_25, r32=v_20, ...} = v_19
224 in
225 (case v_25 of
226 I.Displace v_24 =>
227 let val {base=v_22, disp=v_23, ...} = v_24
228 in
229 (case v_23 of
230 I.ImmedLabel v_21 =>
231 let val base = v_22
232 and le = v_21
233 and r32 = v_20
234 and rest = v_3
235 in (if ((isZeroLE le) andalso (CBase.sameColor (r32, base)))
236 then (loop (rest, instrs))
237 else (state_9 (v_0, v_3)))
238 end
239 | _ => state_9 (v_0, v_3)
240 )
241 end
242 | _ => state_9 (v_0, v_3)
243 )
244 end
245 | I.MOVE v_19 =>
246 let val {dst=v_1, mvOp=v_18, src=v_2, ...} = v_19
247 in
248 (case v_18 of
249 I.MOVL =>
250 (case v_2 of
251 I.Displace v_17 =>
252 let val {base=v_6, disp=v_16, ...} = v_17
253 in
254 (case v_16 of
255 I.Immed v_15 =>
256 (case v_15 of
257 0 =>
258 (case v_3 of
259 op :: v_14 =>
260 let val (v_13, v_4) = v_14
261 in
262 (case v_13 of
263 I.INSTR v_12 =>
264 (case v_12 of
265 I.BINARY v_11 =>
266 let val {binOp=v_10, dst=v_9, src=v_8, ...} = v_11
267 in
268 (case v_10 of
269 I.ADDL =>
270 (case v_9 of
271 I.Direct v_5 =>
272 (case v_8 of
273 I.Immed v_7 =>
274 (case v_7 of
275 4 =>
276 let val base = v_6
277 and dst = v_1
278 and dst_i = v_5
279 and rest = v_4
280 in (if (((CBase.sameColor (base, C.esp)) andalso (CBase.sameColor (dst_i, C.esp))) andalso (not (isStackPtr dst)))
281 then (loop (rest, (I.pop dst) :: instrs))
282 else (state_51 (v_0, v_1, v_2, v_3)))
283 end
284 | _ => state_51 (v_0, v_1, v_2, v_3)
285 )
286 | _ => state_51 (v_0, v_1, v_2, v_3)
287 )
288 | _ => state_51 (v_0, v_1, v_2, v_3)
289 )
290 | _ => state_51 (v_0, v_1, v_2, v_3)
291 )
292 end
293 | _ => state_51 (v_0, v_1, v_2, v_3)
294 )
295 | _ => state_51 (v_0, v_1, v_2, v_3)
296 )
297 end
298 | nil => state_51 (v_0, v_1, v_2, v_3)
299 )
300 | _ => state_51 (v_0, v_1, v_2, v_3)
301 )
302 | _ => state_51 (v_0, v_1, v_2, v_3)
303 )
304 end
305 | _ => state_51 (v_0, v_1, v_2, v_3)
306 )
307 | _ => state_9 (v_0, v_3)
308 )
309 end
310 | _ => state_9 (v_0, v_3)
311 )
312 | _ => state_9 (v_0, v_3)
313 )
314 end
315 | nil => instrs
316 )
317 end
318 in loop (instrs, [])
319 end
320 end
321