1 |
(* WARNING: this is generated by running 'nowhere sparcPeephole.peep'. |
(* WARNING: this is generated by running 'nowhere sparcPeephole.peep'. |
2 |
* Do not edit this file directly. |
* Do not edit this file directly. |
3 |
|
* Version 1.1 |
4 |
*) |
*) |
5 |
|
|
6 |
(*#line 7.1 "sparcPeephole.peep"*) |
(*#line 10.1 "sparcPeephole.peep"*) |
7 |
functor SparcPeephole(SparcInstr : SPARCINSTR): PEEPHOLE = |
functor SparcPeephole(SparcInstr : SPARCINSTR): PEEPHOLE = |
8 |
struct |
struct |
9 |
|
|
10 |
(*#line 9.4 "sparcPeephole.peep"*) |
(*#line 12.4 "sparcPeephole.peep"*) |
11 |
structure I = SparcInstr |
structure I = SparcInstr |
12 |
|
|
13 |
(*#line 10.4 "sparcPeephole.peep"*) |
(*#line 13.4 "sparcPeephole.peep"*) |
14 |
structure C = I.C |
structure C = I.C |
15 |
|
|
16 |
(*#line 13.4 "sparcPeephole.peep"*) |
(*#line 16.4 "sparcPeephole.peep"*) |
17 |
fun peephole instrs = |
fun peephole instrs = |
18 |
let |
let |
19 |
(*#line 14.8 "sparcPeephole.peep"*) |
(*#line 17.8 "sparcPeephole.peep"*) |
20 |
fun isZero (I.LAB le) = (I.LabelExp.valueOf le) = 0 |
fun isZero (I.LAB le) = (I.LabelExp.valueOf le) = 0 |
21 |
| isZero (I.REG r) = (C.registerNum r) = 0 |
| isZero (I.REG r) = (C.registerNum r) = 0 |
22 |
| isZero (I.IMMED i) = i = 0 |
| isZero (I.IMMED i) = i = 0 |
23 |
| isZero _ = false |
| isZero _ = false |
24 |
|
|
25 |
(*#line 19.8 "sparcPeephole.peep"*) |
(*#line 22.8 "sparcPeephole.peep"*) |
26 |
fun removable (I.ARITH{a=(I.ADD | I.SUB), r, i, d}) = (C.sameColor (r, d)) andalso (isZero i) |
fun removable p_0 = |
27 |
| removable (I.ANNOTATION{i, a}) = removable i |
let val v_6 = p_0 |
28 |
| removable _ = false |
fun state_5 () = false |
29 |
|
fun state_2 (v_0, v_1, v_2) = |
30 |
|
let val d = v_0 |
31 |
|
and i = v_1 |
32 |
|
and r = v_2 |
33 |
|
in (C.sameColor (r, d)) andalso (isZero i) |
34 |
|
end |
35 |
|
in |
36 |
|
let val v_5 = v_6 |
37 |
|
in |
38 |
|
(case v_5 of |
39 |
|
I.ANNOTATION v_4 => |
40 |
|
let val {a=v_3, i=v_1, ...} = v_4 |
41 |
|
in |
42 |
|
let val a = v_3 |
43 |
|
and i = v_1 |
44 |
|
in removable i |
45 |
|
end |
46 |
|
end |
47 |
|
| I.ARITH v_4 => |
48 |
|
let val {a=v_3, d=v_0, i=v_1, r=v_2, ...} = v_4 |
49 |
|
in |
50 |
|
(case v_3 of |
51 |
|
I.ADD => state_2 (v_0, v_1, v_2) |
52 |
|
| I.SUB => state_2 (v_0, v_1, v_2) |
53 |
|
| _ => state_5 () |
54 |
|
) |
55 |
|
end |
56 |
|
| _ => state_5 () |
57 |
|
) |
58 |
|
end |
59 |
|
end |
60 |
|
|
61 |
(*#line 24.8 "sparcPeephole.peep"*) |
(*#line 27.8 "sparcPeephole.peep"*) |
62 |
fun loop (current, instrs) = |
fun loop (current, instrs) = |
63 |
let val v_3 = current |
let val v_3 = current |
64 |
in |
in |
65 |
(case v_3 of |
(case v_3 of |
66 |
nil => instrs |
op :: v_2 => |
67 |
| op :: v_2 => |
let val (v_1, v_0) = v_2 |
|
let val (v_0, v_1) = v_2 |
|
68 |
in |
in |
69 |
let val i = v_0 |
let val i = v_1 |
70 |
and rest = v_1 |
and rest = v_0 |
71 |
in (if (removable i) |
in (if (removable i) |
72 |
then (loop (rest, instrs)) |
then (loop (rest, instrs)) |
73 |
else |
else |
74 |
let val i = v_0 |
let val i = v_1 |
75 |
and rest = v_1 |
and rest = v_0 |
76 |
in loop (rest, i :: instrs) |
in loop (rest, i :: instrs) |
77 |
end) |
end) |
78 |
end |
end |
79 |
end |
end |
80 |
|
| nil => instrs |
81 |
) |
) |
82 |
end |
end |
83 |
in loop (instrs, []) |
in loop (instrs, []) |