Debian Codegraph @

lib/mlrisc-lib/MLRISC/sparc/instructions/sparcPeephole.sml

raw
1 (* WARNING: this is generated by running 'nowhere sparcPeephole.peep'.
2 * Do not edit this file directly.
3 * Version 1.2.2
4 *)
5
6 (*#line 10.1 "sparcPeephole.peep"*)
7 functor SparcPeephole(
8 (*#line 11.5 "sparcPeephole.peep"*)
9 structure Instr : SPARCINSTR
10
11 (*#line 12.5 "sparcPeephole.peep"*)
12 structure Eval : MLTREE_EVAL
13
14 (*#line 13.7 "sparcPeephole.peep"*)
15 sharing Eval.T = Instr.T
16 ): PEEPHOLE =
17 struct
18
19 (*#line 16.4 "sparcPeephole.peep"*)
20 structure I = Instr
21
22 (*#line 17.4 "sparcPeephole.peep"*)
23 structure CB = CellsBasis
24
25 (*#line 20.4 "sparcPeephole.peep"*)
26 fun peephole instrs =
27 let
28 (*#line 21.8 "sparcPeephole.peep"*)
29 fun isZero (I.LAB le) = (((Eval.valueOf le) = 0) handle _ => false
30 )
31 | isZero (I.REG r) = (CB.registerNum r) = 0
32 | isZero (I.IMMED i) = i = 0
33 | isZero _ = false
34
35 (*#line 26.8 "sparcPeephole.peep"*)
36 fun removable p_0 =
37 let val v_9 = p_0
38 fun state_5 () = false
39 fun state_2 (v_0, v_1, v_2) =
40 let val d = v_0
41 and i = v_1
42 and r = v_2
43 in (CB.sameColor (r, d)) andalso (isZero i)
44 end
45 in
46 let val v_8 = v_9
47 in
48 (case v_8 of
49 I.ANNOTATION v_5 =>
50 let val {a=v_7, i=v_6, ...} = v_5
51 in
52 let val a = v_7
53 and i = v_6
54 in removable i
55 end
56 end
57 | I.INSTR v_5 =>
58 (case v_5 of
59 I.ARITH v_4 =>
60 let val {a=v_3, d=v_0, i=v_1, r=v_2, ...} = v_4
61 in
62 (case v_3 of
63 I.ADD => state_2 (v_0, v_1, v_2)
64 | I.SUB => state_2 (v_0, v_1, v_2)
65 | _ => state_5 ()
66 )
67 end
68 | _ => state_5 ()
69 )
70 | _ => state_5 ()
71 )
72 end
73 end
74
75 (*#line 31.8 "sparcPeephole.peep"*)
76 fun loop (current, instrs) =
77 let val v_13 = current
78 in
79 (case v_13 of
80 op :: v_12 =>
81 let val (v_11, v_10) = v_12
82 in
83 let val i = v_11
84 and rest = v_10
85 in (if (removable i)
86 then (loop (rest, instrs))
87 else
88 let val i = v_11
89 and rest = v_10
90 in loop (rest, i :: instrs)
91 end)
92 end
93 end
94 | nil => instrs
95 )
96 end
97 in loop (instrs, [])
98 end
99 end
100