Debian Codegraph @

lib/mlrisc-lib/MLRISC/alpha/instructions/alphaPeephole.sml

raw
1 (* WARNING: this is generated by running 'nowhere alphaPeephole.peep'.
2 * Do not edit this file directly.
3 * Version 1.2.2
4 *)
5
6 (*#line 8.1 "alphaPeephole.peep"*)
7 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
18
19 (*#line 14.4 "alphaPeephole.peep"*)
20 structure I = Instr
21
22 (*#line 15.4 "alphaPeephole.peep"*)
23 structure CB = CellsBasis
24
25 (*#line 18.4 "alphaPeephole.peep"*)
26 fun peephole instrs =
27 let
28 (*#line 19.8 "alphaPeephole.peep"*)
29 fun isZero (I.LABop le) = (((Eval.valueOf le) = 0) handle _ => false
30 )
31 | isZero (I.REGop r) = (CB.registerNum r) = 31
32 | isZero (I.IMMop i) = i = 0
33 | isZero _ = false
34
35 (*#line 24.8 "alphaPeephole.peep"*)
36 fun removable p_0 =
37 let val v_12 = p_0
38 fun state_7 () = false
39 fun state_4 (v_0, v_1, v_2) =
40 let val ra = v_0
41 and rb = v_1
42 and rc = v_2
43 in (CB.sameColor (ra, rc)) andalso (isZero rb)
44 end
45 in
46 let val v_11 = v_12
47 in
48 (case v_11 of
49 I.ANNOTATION v_8 =>
50 let val {a=v_10, i=v_9, ...} = v_8
51 in
52 let val a = v_10
53 and i = v_9
54 in removable i
55 end
56 end
57 | 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
61 in
62 let val b = v_7
63 and d = v_6
64 and r = v_5
65 in (isZero d) andalso (CB.sameColor (r, b))
66 end
67 end
68 | I.OPERATE v_4 =>
69 let val {oper=v_3, ra=v_0, rb=v_1, rc=v_2, ...} = v_4
70 in
71 (case v_3 of
72 I.ADDQ => state_4 (v_0, v_1, v_2)
73 | I.SUBQ => state_4 (v_0, v_1, v_2)
74 | _ => state_7 ()
75 )
76 end
77 | _ => state_7 ()
78 )
79 | _ => state_7 ()
80 )
81 end
82 end
83
84 (*#line 31.8 "alphaPeephole.peep"*)
85 fun symmetric (I.STQ, I.LDQ) = true
86 | symmetric (I.STL, I.LDL) = true
87 | symmetric (I.STW, I.LDW) = true
88 | symmetric (I.STB, I.LDB) = true
89 | symmetric _ = false
90
91 (*#line 37.8 "alphaPeephole.peep"*)
92 fun sameOperand (I.REGop r1, I.REGop r2) = CB.sameColor (r1, r2)
93 | sameOperand (I.IMMop i1, I.IMMop i2) = i1 = i2
94 | sameOperand (I.LABop l1, I.LABop l2) = (((Eval.valueOf l1) = (Eval.valueOf l2)) handle _ => false
95 )
96 | sameOperand _ = false
97
98 (*#line 43.8 "alphaPeephole.peep"*)
99 fun loop (current, instrs) =
100 let val v_31 = current
101 fun state_7 (v_13, v_14) =
102 let val i = v_13
103 and rest = v_14
104 in (if (removable i)
105 then (loop (rest, instrs))
106 else
107 let val i = v_13
108 and rest = v_14
109 in loop (rest, i :: instrs)
110 end)
111 end
112 in
113 (case v_31 of
114 op :: v_30 =>
115 let val (v_13, v_14) = v_30
116 in
117 (case v_13 of
118 I.INSTR v_29 =>
119 (case v_29 of
120 I.STORE v_28 =>
121 let val {b=v_24, d=v_22, r=v_18, stOp=v_15, ...} = v_28
122 in
123 (case v_14 of
124 op :: v_27 =>
125 let val (v_20, v_16) = v_27
126 in
127 (case v_20 of
128 I.INSTR v_26 =>
129 (case v_26 of
130 I.LOAD v_25 =>
131 let val {b=v_23, d=v_21, ldOp=v_19, r=v_17, ...} = v_25
132 in
133 let val b1 = v_24
134 and b2 = v_23
135 and d1 = v_22
136 and d2 = v_21
137 and ld = v_20
138 and ldOp = v_19
139 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,
145 d2)))
146 then (loop (rest, st :: instrs))
147 else (state_7 (v_13, v_14)))
148 end
149 end
150 | _ => state_7 (v_13, v_14)
151 )
152 | _ => state_7 (v_13, v_14)
153 )
154 end
155 | nil => state_7 (v_13, v_14)
156 )
157 end
158 | _ => state_7 (v_13, v_14)
159 )
160 | _ => state_7 (v_13, v_14)
161 )
162 end
163 | nil => instrs
164 )
165 end
166 in loop (instrs, [])
167 end
168 end
169