SCM Repository
[smlnj] Annotation of /sml/trunk/src/MLRISC/sparc/instructions/sparcPeephole.sml
Annotation of /sml/trunk/src/MLRISC/sparc/instructions/sparcPeephole.sml
Parent Directory
|
Revision Log
Revision 744 -
(view)
(download)
1 : |
leunga |
744 |
(* WARNING: this is generated by running 'wheregen sparcPeephole.peep'.
|
2 : |
|
|
* Do not edit this file directly.
|
3 : |
|
|
*)
|
4 : |
|
|
|
5 : |
|
|
(*#line 7.1 "sparcPeephole.peep"*)
|
6 : |
|
|
functor SparcPeephole(SparcInstr : SPARCINSTR): PEEPHOLE =
|
7 : |
leunga |
601 |
struct
|
8 : |
leunga |
744 |
|
9 : |
|
|
(*#line 9.4 "sparcPeephole.peep"*)
|
10 : |
leunga |
601 |
structure I = SparcInstr
|
11 : |
|
|
|
12 : |
leunga |
744 |
(*#line 10.4 "sparcPeephole.peep"*)
|
13 : |
|
|
structure C = I.C
|
14 : |
leunga |
601 |
|
15 : |
leunga |
744 |
(*#line 13.4 "sparcPeephole.peep"*)
|
16 : |
|
|
fun peephole instrs =
|
17 : |
|
|
let
|
18 : |
|
|
(*#line 14.8 "sparcPeephole.peep"*)
|
19 : |
|
|
fun isZero (I.LAB le) = (I.LabelExp.valueOf le) = 0
|
20 : |
|
|
| isZero (I.REG r) = (C.registerNum r) = 0
|
21 : |
|
|
| isZero (I.IMMED i) = i = 0
|
22 : |
|
|
| isZero _ = false
|
23 : |
leunga |
601 |
|
24 : |
leunga |
744 |
(*#line 19.8 "sparcPeephole.peep"*)
|
25 : |
|
|
fun removable (I.ARITH{a=(I.ADD | I.SUB), r, i, d}) = (C.sameColor (r,
|
26 : |
|
|
d)) andalso (isZero i)
|
27 : |
|
|
| removable (I.ANNOTATION{i, a}) = removable i
|
28 : |
|
|
| removable _ = false
|
29 : |
|
|
|
30 : |
|
|
(*#line 24.8 "sparcPeephole.peep"*)
|
31 : |
|
|
fun loop (current, instrs) =
|
32 : |
|
|
let val v_3 = current
|
33 : |
|
|
in
|
34 : |
|
|
(case v_3 of
|
35 : |
|
|
nil => instrs
|
36 : |
|
|
| op :: v_2 =>
|
37 : |
|
|
let val (v_0, v_1) = v_2
|
38 : |
|
|
in
|
39 : |
|
|
let val i = v_0
|
40 : |
|
|
and rest = v_1
|
41 : |
|
|
in (if (removable i)
|
42 : |
|
|
then (loop (rest, instrs))
|
43 : |
|
|
else
|
44 : |
|
|
let val i = v_0
|
45 : |
|
|
and rest = v_1
|
46 : |
|
|
in loop (rest, i :: instrs)
|
47 : |
|
|
end)
|
48 : |
|
|
end
|
49 : |
|
|
end
|
50 : |
|
|
)
|
51 : |
|
|
end
|
52 : |
|
|
in loop (instrs, [])
|
53 : |
|
|
end
|
54 : |
|
|
end
|
55 : |
|
|
|