File: sparcPeephole.sml

package info (click to toggle)
mlton 20210117%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,464 kB
  • sloc: ansic: 27,682; sh: 4,455; asm: 3,569; lisp: 2,879; makefile: 2,347; perl: 1,169; python: 191; pascal: 68; javascript: 7
file content (100 lines) | stat: -rw-r--r-- 3,267 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
(* WARNING: this is generated by running 'nowhere sparcPeephole.peep'.
 * Do not edit this file directly.
 * Version 1.2.2
 *)

(*#line 10.1 "sparcPeephole.peep"*)
functor SparcPeephole(
(*#line 11.5 "sparcPeephole.peep"*)
                      structure Instr : SPARCINSTR

(*#line 12.5 "sparcPeephole.peep"*)
                      structure Eval : MLTREE_EVAL

(*#line 13.7 "sparcPeephole.peep"*)
                      sharing Eval.T = Instr.T
                     ): PEEPHOLE =
struct

(*#line 16.4 "sparcPeephole.peep"*)
   structure I = Instr

(*#line 17.4 "sparcPeephole.peep"*)
   structure CB = CellsBasis

(*#line 20.4 "sparcPeephole.peep"*)
   fun peephole instrs = 
       let 
(*#line 21.8 "sparcPeephole.peep"*)
           fun isZero (I.LAB le) = (((Eval.valueOf le) = 0) handle _ => false
)
             | isZero (I.REG r) = (CB.registerNum r) = 0
             | isZero (I.IMMED i) = i = 0
             | isZero _ = false

(*#line 26.8 "sparcPeephole.peep"*)
           fun removable p_0 = 
               let val v_9 = p_0
                   fun state_5 () = false
                   fun state_2 (v_0, v_1, v_2) = 
                       let val d = v_0
                           and i = v_1
                           and r = v_2
                       in (CB.sameColor (r, d)) andalso (isZero i)
                       end
               in 
                  let val v_8 = v_9
                  in 
                     (case v_8 of
                       I.ANNOTATION v_5 => 
                       let val {a=v_7, i=v_6, ...} = v_5
                       in 
                          let val a = v_7
                              and i = v_6
                          in removable i
                          end
                       end
                     | I.INSTR v_5 => 
                       (case v_5 of
                         I.ARITH v_4 => 
                         let val {a=v_3, d=v_0, i=v_1, r=v_2, ...} = v_4
                         in 
                            (case v_3 of
                              I.ADD => state_2 (v_0, v_1, v_2)
                            | I.SUB => state_2 (v_0, v_1, v_2)
                            | _ => state_5 ()
                            )
                         end
                       | _ => state_5 ()
                       )
                     | _ => state_5 ()
                     )
                  end
               end

(*#line 31.8 "sparcPeephole.peep"*)
           fun loop (current, instrs) = 
               let val v_13 = current
               in 
                  (case v_13 of
                    op :: v_12 => 
                    let val (v_11, v_10) = v_12
                    in 
                       let val i = v_11
                           and rest = v_10
                       in (if (removable i)
                             then (loop (rest, instrs))
                             else 
                             let val i = v_11
                                 and rest = v_10
                             in loop (rest, i :: instrs)
                             end)
                       end
                    end
                  | nil => instrs
                  )
               end
       in loop (instrs, [])
       end
end