2 * Gathers tiberium, fires rockets
3 * optimizes away redundant insns such as:
14 * Author: Chris Lu <czl@andrew>
19 type tiberium = x86.insn list
20 type rockets = x86.insn list
21 val peephole : tiberium -> rockets
24 structure Peephole :> PEEPHOLE =
26 type tiberium = x86.insn list
27 type rockets = x86.insn list
30 (* val peephole : tiberium -> rockets *)
32 fun peephole ((insn1 as X.MOVL(a1,b1))::(insn2 as X.MOVL(a2,b2))::l) =
33 if(x86.opereq(a1, b1) orelse (x86.opereq(a1, a2) andalso x86.opereq(b1, b2))) then
35 else if(x86.opereq(a2, b2) orelse (x86.opereq(a1, b2) andalso x86.opereq(b1, a2))) then
38 insn1::(peephole (insn2::l))
39 | peephole ((insn as X.MOVL(a,b))::l) = if x86.opereq(a, b) then peephole l else insn::(peephole l)
40 | peephole ((insn1 as X.NEG(a))::(insn2 as X.NEG(b))::l) = if x86.opereq(a, b) then peephole l else insn1::(peephole (insn2::l))
41 | peephole (a::l) = a::(peephole l)