forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 1
/
old_cprop.isle
113 lines (98 loc) · 3.73 KB
/
old_cprop.isle
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
101
102
103
104
105
106
107
108
109
110
111
112
113
;; VERI: relevant parts of prelude/definitions
(type Type (primitive Type))
(type Value (primitive Value))
(type u64 (primitive u64))
(type Imm64 (primitive Imm64))
(type bool (primitive bool))
(extern const $true bool)
;;@ (spec (sig (args x) (ret))
;;@ (assertions (= (x) (ret))))
(decl simplify (Value) Value)
;;@ (spec (sig (args x) (ret))
;;@ (assertions (= (x) (ret))))
(decl subsume (Value) Value)
(extern constructor subsume subsume)
;; An extractor that only matches types that can fit in 64 bits.
;;@ (spec (sig (args arg) (ret))
;;@ (assertions (= (arg) (ret)), (<= (arg) (64i128: isleType))))
(decl fits_in_64 (Type) Type)
(extern extractor fits_in_64 fits_in_64)
;;@ (spec (sig (args ty, x, y) (ret))
;;@ (assertions (= (+ (x) (y)) (ret)),
;;@ (= (ty) (widthof (x))),
;;@ (= (ty) (widthof (y))),
;;@))
(decl iadd (Type Value Value) Value)
(extern constructor iadd iadd)
(extern extractor iadd iadd)
;;@ (spec (sig (args ty, x, y) (ret))
;;@ (assertions (= (- (x) (y)) (ret)),
;;@ (= (ty) (widthof (x))),
;;@ (= (ty) (widthof (y))),
;;@))
(decl isub (Type Value Value) Value)
(extern constructor isub isub)
(extern extractor isub isub)
;;@ (spec (sig (args ty, x) (ret))
;;@ (assertions (= (- (x)) (ret)),
;;@ (= (ty) (widthof (x))),
;;@))
(decl ineg (Type Value) Value)
(extern constructor ineg ineg)
(extern extractor ineg ineg)
;; Specify to this rule with constants
;;@ (spec (sig (args ty, arg) (ret))
;;@ (assertions (= (arg) (zero_ext (64) (ret))),
;;@ (= (ty) (widthof (ret)))
;;@ ))
(decl iconst (Type Imm64) Value)
(extern constructor iconst iconst)
(extern extractor iconst iconst)
;; Extract a `u64` from an `Imm64`.
;;@ (spec (sig (args arg) (ret))
;;@ (assertions (= (arg) (ret))))
(decl u64_from_imm64 (u64) Imm64)
(extern extractor u64_from_imm64 u64_from_imm64)
;;@ (spec (sig (args x, y) (ret))
;;@ (assertions (= (+ (x) (y)) (ret))))
(decl pure u64_add (u64 u64) u64)
(extern constructor u64_add u64_add)
;;@ (spec (sig (args x, y) (ret))
;;@ (assertions (= (- (x) (y)) (ret))))
(decl pure u64_sub (u64 u64) u64)
(extern constructor u64_sub u64_sub)
;;@ (spec (sig (args x) (ret))
;;@ (assertions (= (x) (ret))))
(decl pure imm64 (u64) Imm64)
(extern constructor imm64 imm64)
;; OLD isle starts
(rule (simplify
(iadd (fits_in_64 ty)
x @ (iconst ty (u64_from_imm64 k1))
(iconst ty (u64_from_imm64 k2))))
(subsume (iconst ty (imm64 (u64_add k1 k2)))))
(rule (simplify
(isub (fits_in_64 ty)
x @ (iconst ty (u64_from_imm64 k1))
(iconst ty (u64_from_imm64 k2))))
(subsume (iconst ty (imm64 (u64_sub k1 k2)))))
(rule (simplify (isub ty
(isub ty x (iconst ty (u64_from_imm64 k1)))
(iconst ty (u64_from_imm64 k2))))
(isub ty x (iconst ty (imm64 (u64_add k1 k2)))))
(rule (simplify (isub ty
(isub ty (iconst ty (u64_from_imm64 k1)) x)
(iconst ty (u64_from_imm64 k2))))
(isub ty (iconst ty (imm64 (u64_sub k1 k2))) x))
(rule (simplify (isub ty
(iadd ty x (iconst ty (u64_from_imm64 k1)))
(iconst ty (u64_from_imm64 k2))))
(isub ty x (iconst ty (imm64 (u64_sub k2 k1)))))
(rule (simplify (iadd ty
(isub ty x (iconst ty (u64_from_imm64 k1)))
(iconst ty (u64_from_imm64 k2))))
(iadd ty x (iconst ty (imm64 (u64_sub k2 k1)))))
(rule (simplify (iadd ty
(isub ty (iconst ty (u64_from_imm64 k1)) x)
(iconst ty (u64_from_imm64 k2))))
(isub ty (iconst ty (imm64 (u64_add k1 k2))) x))