1 |
(* WARNING: this is generated by running 'nowhere alphaPeephole.peep'. |
(* WARNING: this is generated by running 'nowhere alphaPeephole.peep'. |
2 |
* Do not edit this file directly. |
* Do not edit this file directly. |
3 |
* Version 1.2 |
* Version 1.2.2 |
4 |
*) |
*) |
5 |
|
|
6 |
(*#line 8.1 "alphaPeephole.peep"*) |
(*#line 8.1 "alphaPeephole.peep"*) |
7 |
functor AlphaPeephole(AlphaInstr : ALPHAINSTR): PEEPHOLE = |
functor AlphaPeephole( |
8 |
|
(*#line 9.5 "alphaPeephole.peep"*) |
9 |
|
structure Instr : ALPHAINSTR |
10 |
|
|
11 |
|
(*#line 10.5 "alphaPeephole.peep"*) |
12 |
|
structure Eval : MLTREE_EVAL |
13 |
|
|
14 |
|
(*#line 11.7 "alphaPeephole.peep"*) |
15 |
|
sharing Instr.T = Eval.T |
16 |
|
): PEEPHOLE = |
17 |
struct |
struct |
18 |
|
|
19 |
(*#line 10.4 "alphaPeephole.peep"*) |
(*#line 14.4 "alphaPeephole.peep"*) |
20 |
structure I = AlphaInstr |
structure I = Instr |
21 |
|
|
22 |
(*#line 11.4 "alphaPeephole.peep"*) |
(*#line 15.4 "alphaPeephole.peep"*) |
23 |
structure CB = CellsBasis |
structure CB = CellsBasis |
24 |
|
|
25 |
(*#line 14.4 "alphaPeephole.peep"*) |
(*#line 18.4 "alphaPeephole.peep"*) |
26 |
fun peephole instrs = |
fun peephole instrs = |
27 |
let |
let |
28 |
(*#line 15.8 "alphaPeephole.peep"*) |
(*#line 19.8 "alphaPeephole.peep"*) |
29 |
fun isZero (I.LABop le) = (I.LabelExp.valueOf le) = 0 |
fun isZero (I.LABop le) = (((Eval.valueOf le) = 0) handle _ => false |
30 |
|
) |
31 |
| isZero (I.REGop r) = (CB.registerNum r) = 31 |
| isZero (I.REGop r) = (CB.registerNum r) = 31 |
32 |
| isZero (I.IMMop i) = i = 0 |
| isZero (I.IMMop i) = i = 0 |
33 |
| isZero _ = false |
| isZero _ = false |
34 |
|
|
35 |
(*#line 20.8 "alphaPeephole.peep"*) |
(*#line 24.8 "alphaPeephole.peep"*) |
36 |
fun removable p_0 = |
fun removable p_0 = |
37 |
let val v_11 = p_0 |
let val v_12 = p_0 |
38 |
fun state_7 () = false |
fun state_7 () = false |
39 |
fun state_4 (v_0, v_1, v_2) = |
fun state_4 (v_0, v_1, v_2) = |
40 |
let val ra = v_0 |
let val ra = v_0 |
43 |
in (CB.sameColor (ra, rc)) andalso (isZero rb) |
in (CB.sameColor (ra, rc)) andalso (isZero rb) |
44 |
end |
end |
45 |
in |
in |
46 |
let val v_10 = v_11 |
let val v_11 = v_12 |
47 |
in |
in |
48 |
(case v_10 of |
(case v_11 of |
49 |
I.ANNOTATION v_4 => |
I.ANNOTATION v_8 => |
50 |
let val {a=v_9, i=v_8, ...} = v_4 |
let val {a=v_10, i=v_9, ...} = v_8 |
51 |
in |
in |
52 |
let val a = v_9 |
let val a = v_10 |
53 |
and i = v_8 |
and i = v_9 |
54 |
in removable i |
in removable i |
55 |
end |
end |
56 |
end |
end |
57 |
| I.LDA v_4 => |
| I.INSTR v_8 => |
58 |
|
(case v_8 of |
59 |
|
I.LDA v_4 => |
60 |
let val {b=v_7, d=v_6, r=v_5, ...} = v_4 |
let val {b=v_7, d=v_6, r=v_5, ...} = v_4 |
61 |
in |
in |
62 |
let val b = v_7 |
let val b = v_7 |
76 |
end |
end |
77 |
| _ => state_7 () |
| _ => state_7 () |
78 |
) |
) |
79 |
|
| _ => state_7 () |
80 |
|
) |
81 |
end |
end |
82 |
end |
end |
83 |
|
|
84 |
(*#line 26.8 "alphaPeephole.peep"*) |
(*#line 31.8 "alphaPeephole.peep"*) |
85 |
fun symmetric (I.STQ, I.LDQ) = true |
fun symmetric (I.STQ, I.LDQ) = true |
86 |
| symmetric (I.STL, I.LDL) = true |
| symmetric (I.STL, I.LDL) = true |
87 |
| symmetric (I.STW, I.LDW) = true |
| symmetric (I.STW, I.LDW) = true |
88 |
| symmetric (I.STB, I.LDB) = true |
| symmetric (I.STB, I.LDB) = true |
89 |
| symmetric _ = false |
| symmetric _ = false |
90 |
|
|
91 |
(*#line 32.8 "alphaPeephole.peep"*) |
(*#line 37.8 "alphaPeephole.peep"*) |
92 |
fun sameOperand (I.REGop r1, I.REGop r2) = CB.sameColor (r1, r2) |
fun sameOperand (I.REGop r1, I.REGop r2) = CB.sameColor (r1, r2) |
93 |
| sameOperand (I.IMMop i1, I.IMMop i2) = i1 = i2 |
| sameOperand (I.IMMop i1, I.IMMop i2) = i1 = i2 |
94 |
| sameOperand (I.LABop l1, I.LABop l2) = (I.LabelExp.valueOf l1) = (I.LabelExp.valueOf l2) |
| sameOperand (I.LABop l1, I.LABop l2) = (((Eval.valueOf l1) = (Eval.valueOf l2)) handle _ => false |
95 |
|
) |
96 |
| sameOperand _ = false |
| sameOperand _ = false |
97 |
|
|
98 |
(*#line 38.8 "alphaPeephole.peep"*) |
(*#line 43.8 "alphaPeephole.peep"*) |
99 |
fun loop (current, instrs) = |
fun loop (current, instrs) = |
100 |
let val v_16 = current |
let val v_31 = current |
101 |
fun state_7 (v_0, v_1) = |
fun state_7 (v_13, v_14) = |
102 |
let val i = v_0 |
let val i = v_13 |
103 |
and rest = v_1 |
and rest = v_14 |
104 |
in (if (removable i) |
in (if (removable i) |
105 |
then (loop (rest, instrs)) |
then (loop (rest, instrs)) |
106 |
else |
else |
107 |
let val i = v_0 |
let val i = v_13 |
108 |
and rest = v_1 |
and rest = v_14 |
109 |
in loop (rest, i :: instrs) |
in loop (rest, i :: instrs) |
110 |
end) |
end) |
111 |
end |
end |
112 |
in |
in |
113 |
(case v_16 of |
(case v_31 of |
114 |
op :: v_15 => |
op :: v_30 => |
115 |
let val (v_0, v_1) = v_15 |
let val (v_13, v_14) = v_30 |
116 |
in |
in |
117 |
(case v_0 of |
(case v_13 of |
118 |
I.STORE v_14 => |
I.INSTR v_29 => |
119 |
let val {b=v_11, d=v_9, r=v_5, stOp=v_2, ...} = v_14 |
(case v_29 of |
120 |
in |
I.STORE v_28 => |
121 |
(case v_1 of |
let val {b=v_24, d=v_22, r=v_18, stOp=v_15, ...} = v_28 |
122 |
op :: v_13 => |
in |
123 |
let val (v_7, v_3) = v_13 |
(case v_14 of |
124 |
in |
op :: v_27 => |
125 |
(case v_7 of |
let val (v_20, v_16) = v_27 |
126 |
I.LOAD v_12 => |
in |
127 |
let val {b=v_10, d=v_8, ldOp=v_6, r=v_4, ...} = v_12 |
(case v_20 of |
128 |
in |
I.INSTR v_26 => |
129 |
let val b1 = v_11 |
(case v_26 of |
130 |
and b2 = v_10 |
I.LOAD v_25 => |
131 |
and d1 = v_9 |
let val {b=v_23, d=v_21, ldOp=v_19, r=v_17, ...} = v_25 |
132 |
and d2 = v_8 |
in |
133 |
and ld = v_7 |
let val b1 = v_24 |
134 |
and ldOp = v_6 |
and b2 = v_23 |
135 |
and r1 = v_5 |
and d1 = v_22 |
136 |
and r2 = v_4 |
and d2 = v_21 |
137 |
and rest = v_3 |
and ld = v_20 |
138 |
and st = v_0 |
and ldOp = v_19 |
139 |
and stOp = v_2 |
and r1 = v_18 |
140 |
|
and r2 = v_17 |
141 |
|
and rest = v_16 |
142 |
|
and st = v_13 |
143 |
|
and stOp = v_15 |
144 |
in (if ((((symmetric (stOp, ldOp)) andalso (CB.sameColor (r1, r2))) andalso (CB.sameColor (b1, b2))) andalso (sameOperand (d1, |
in (if ((((symmetric (stOp, ldOp)) andalso (CB.sameColor (r1, r2))) andalso (CB.sameColor (b1, b2))) andalso (sameOperand (d1, |
145 |
d2))) |
d2))) |
146 |
then (loop (rest, st :: instrs)) |
then (loop (rest, st :: instrs)) |
147 |
else (state_7 (v_0, v_1))) |
else (state_7 (v_13, v_14))) |
148 |
end |
end |
149 |
end |
end |
150 |
| _ => state_7 (v_0, v_1) |
| _ => state_7 (v_13, v_14) |
151 |
|
) |
152 |
|
| _ => state_7 (v_13, v_14) |
153 |
) |
) |
154 |
end |
end |
155 |
| nil => state_7 (v_0, v_1) |
| nil => state_7 (v_13, v_14) |
156 |
) |
) |
157 |
end |
end |
158 |
| _ => state_7 (v_0, v_1) |
| _ => state_7 (v_13, v_14) |
159 |
|
) |
160 |
|
| _ => state_7 (v_13, v_14) |
161 |
) |
) |
162 |
end |
end |
163 |
| nil => instrs |
| nil => instrs |