source: Deliverables/D2.2/8051/src/LIN/simplePeephole.ml @ 1580

Last change on this file since 1580 was 1580, checked in by tranquil, 9 years ago

implemented constant propagation in LTL
cleaned up translations in optimizations, a new module for translations is available

File size: 1.1 KB
Line 
1(** This module implements some simple peephole optimizations on LIN *)
2
3open LIN
4
5
6(* [reduce prog] normalizing by measure:
7   |prog| + #[St_op2 (_, r) in prog | r != I8051.a] *)
8let rec reduce : internal_function -> internal_function = function
9
10  | [] -> []
11
12  | St_from_acc r ::
13    St_to_acc r' ::
14    tail
15    when I8051.eq_reg r r' ->
16    reduce (St_from_acc r :: tail)
17
18  | St_from_acc r ::
19    St_op2 (op, LTL.Reg r') ::
20    tail
21    when I8051.eq_reg r r' ->
22    reduce (St_from_acc r :: St_op2 (op, LTL.Reg I8051.a) :: tail)
23
24  | St_from_acc r ::
25    (St_op2 _ | St_op1 _ as s2) ::
26    (St_from_acc r' | St_int (r', _) as s3) ::
27    prog
28    when I8051.eq_reg r r' ->
29    reduce (s2 :: s3 :: prog)
30
31  | St_from_acc r ::
32    (St_from_acc r' | St_int (r', _) as s2) ::
33    prog
34    when I8051.eq_reg r r' ->
35    reduce (s2 :: prog)
36
37  | s1 :: prog -> s1 :: reduce prog
38
39let reduce_funct = function
40  | (id, F_int def) -> (id, F_int (reduce def))
41  | f_ext -> f_ext
42
43open Languages
44
45let trans =
46  (LIN, function
47    | AstLIN p ->
48      AstLIN { p with functs = List.map reduce_funct p.functs }
49    | _ -> assert false)
Note: See TracBrowser for help on using the repository browser.