]> Joshua Wise's Git repositories - snipe.git/blame_incremental - codegen/peephole.sml
Initial import of l2c
[snipe.git] / codegen / peephole.sml
... / ...
CommitLineData
1(* L2 compiler
2 * peephole optimizer
3 * optimizes away redundant insns such as:
4 mov a, b
5 mov a, b
6
7 mov a, b
8 mov b, a
9
10 mov a, a
11
12 neg a
13 neg a
14 * Author: Chris Lu <czl@andrew.cmu.edu>
15 *)
16
17signature PEEPHOLE =
18sig
19 val peephole : x86.insn list -> x86.insn list
20end
21
22structure Peephole :> PEEPHOLE =
23struct
24 structure X = x86
25
26 (* val peephole : x86.insn list -> x86.insn list *)
27
28 fun peephole ((insn1 as X.MOVL(a1,b1))::(insn2 as X.MOVL(a2,b2))::l) =
29 if(x86.opereq(a1, b1) orelse (x86.opereq(a1, a2) andalso x86.opereq(b1, b2))) then
30 peephole (insn2::l)
31 else if(x86.opereq(a2, b2) orelse (x86.opereq(a1, b2) andalso x86.opereq(b1, a2))) then
32 peephole (insn1::l)
33 else
34 insn1::(peephole (insn2::l))
35 | peephole ((insn as X.MOVL(a,b))::l) = if x86.opereq(a, b) then peephole l else insn::(peephole l)
36 | 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))
37 | peephole (a::l) = a::(peephole l)
38 | peephole nil = nil
39
40end
This page took 0.018471 seconds and 4 git commands to generate.