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 651 -
(view)
(download)
1 : |
leunga |
606 |
functor SparcPeephole(SparcInstr : SPARCINSTR) : PEEPHOLE =
|
2 : |
leunga |
601 |
struct
|
3 : |
|
|
structure I = SparcInstr
|
4 : |
|
|
|
5 : |
|
|
(* IMPORTANT: instructions are given in reversed order *)
|
6 : |
|
|
fun peephole regmap instrs =
|
7 : |
|
|
let fun isZero(I.LAB le) = I.LabelExp.valueOf le = 0
|
8 : |
|
|
| isZero(I.REG r) = regmap r = 0
|
9 : |
|
|
| isZero(I.IMMED i) = i = 0
|
10 : |
|
|
| isZero _ = false
|
11 : |
|
|
|
12 : |
|
|
fun removable(I.ARITH{a=(I.ADD | I.SUB), r, i, d}) =
|
13 : |
|
|
regmap r = regmap d andalso isZero i
|
14 : |
|
|
| removable(I.ANNOTATION{i,a}) = removable i
|
15 : |
|
|
| removable _ = false
|
16 : |
|
|
|
17 : |
|
|
fun loop([], instrs) = rev instrs
|
18 : |
|
|
| loop(i::rest, instrs) =
|
19 : |
|
|
if removable i then loop(rest, instrs)
|
20 : |
|
|
else loop(rest, i::instrs)
|
21 : |
|
|
in loop(instrs, [])
|
22 : |
|
|
end
|
23 : |
|
|
end
|