-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathverif-to-smt-errors.mlir
More file actions
266 lines (233 loc) · 8.15 KB
/
Copy pathverif-to-smt-errors.mlir
File metadata and controls
266 lines (233 loc) · 8.15 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// RUN: circt-opt %s --convert-verif-to-smt --split-input-file --verify-diagnostics
func.func @assert_with_unsupported_property_type(%arg0: !smt.bv<1>) {
%0 = builtin.unrealized_conversion_cast %arg0 : !smt.bv<1> to !ltl.sequence
// expected-error @below {{failed to legalize operation 'verif.assert' that was explicitly marked illegal}}
verif.assert %0 : !ltl.sequence
return
}
// -----
func.func @assert_with_unsupported_property_type(%arg0: !smt.bv<1>) {
%0 = builtin.unrealized_conversion_cast %arg0 : !smt.bv<1> to !ltl.property
// expected-error @below {{failed to legalize operation 'verif.assert' that was explicitly marked illegal}}
verif.assert %0 : !ltl.property
return
}
// -----
func.func @multiple_assertions_bmc() -> (i1) {
// expected-error @below {{bounded model checking problems with multiple assertions are not yet correctly handled - instead, you can assert the conjunction of your assertions}}
%bmc = verif.bmc bound 10 num_regs 0 initial_values []
init {}
loop {}
circuit {
^bb0(%arg0: i32, %arg1: i32):
%c1_i32 = hw.constant 1 : i32
%cond1 = comb.icmp ugt %arg0, %c1_i32 : i32
verif.assert %cond1 : i1
%cond2 = comb.icmp ugt %arg1, %c1_i32 : i32
verif.assert %cond2 : i1
%sum = comb.add %arg0, %arg1 : i32
verif.yield %sum : i32
}
func.return %bmc : i1
}
// -----
// Asserts inside instantiated modules are rejected: they would convert
// inside the callee, outside the per-step property scope, and their negated
// conditions would be asserted permanently, masking later violations.
func.func @nested_asserts_via_instances() -> (i1) {
// expected-error @below {{assertions inside instantiated modules or called functions are not supported - inline them into the top module first (e.g. with --flatten-modules)}}
%bmc = verif.bmc bound 10 num_regs 0 initial_values []
init {}
loop {}
circuit {
^bb0(%arg0: i32, %arg1: i1, %arg2: i1):
hw.instance "" @OneAssertion(x: %arg1: i1) -> ()
hw.instance "" @OneAssertion(x: %arg2: i1) -> ()
%sum = comb.add %arg0, %arg0 : i32
verif.yield %sum : i32
}
func.return %bmc : i1
}
hw.module @OneAssertion(in %x: i1) {
verif.assert %x : i1
}
// -----
// Asserts reachable through func.call are rejected as well.
func.func @nested_asserts_via_calls() -> (i1) {
// expected-error @below {{assertions inside instantiated modules or called functions are not supported - inline them into the top module first (e.g. with --flatten-modules)}}
%bmc = verif.bmc bound 10 num_regs 0 initial_values []
init {}
loop {}
circuit {
^bb0(%arg0: i32, %arg1: i1, %arg2: i1):
func.call @OneAssertion(%arg1) : (i1) -> ()
func.call @OneAssertion(%arg2) : (i1) -> ()
%sum = comb.add %arg0, %arg0 : i32
verif.yield %sum : i32
}
func.return %bmc : i1
}
func.func @OneAssertion(%x: i1) {
verif.assert %x : i1
func.return
}
// -----
func.func @no_assertions() -> (i1) {
// expected-warning @below {{no property provided to check in module - will trivially find no violations.}}
%bmc = verif.bmc bound 10 num_regs 0 initial_values []
init {}
loop {}
circuit {
^bb0(%arg0: i32):
hw.instance "" @empty() -> ()
%sum = comb.add %arg0, %arg0 : i32
verif.yield %sum : i32
}
func.return %bmc : i1
}
hw.module @empty() {
}
// -----
// Even a single nested assert is rejected; assumptions in callees are fine
// (they persist, which is the lifetime assumptions need), but a permanently
// asserted negated property would mask later violations.
func.func @one_nested_assertion() -> (i1) {
// expected-error @below {{assertions inside instantiated modules or called functions are not supported - inline them into the top module first (e.g. with --flatten-modules)}}
%bmc = verif.bmc bound 10 num_regs 0 initial_values []
init {}
loop {}
circuit {
^bb0(%arg0: i32, %arg1: i1):
hw.instance "" @OneAssertion(x: %arg1: i1) -> ()
%sum = comb.add %arg0, %arg0 : i32
verif.yield %sum : i32
}
func.return %bmc : i1
}
hw.module @OneAssertion(in %x: i1) {
verif.assert %x : i1
}
// -----
// A nested assert is rejected even when accompanied by a top-level assert
// (which on its own would be fine). The multiple-assertion diagnostic only
// counts asserts in the top module, so it does not apply here.
func.func @nested_and_toplevel_assertions() -> (i1) {
// expected-error @below {{assertions inside instantiated modules or called functions are not supported - inline them into the top module first (e.g. with --flatten-modules)}}
%bmc = verif.bmc bound 10 num_regs 0 initial_values []
init {}
loop {}
circuit {
^bb0(%arg0: i32, %arg1: i1, %arg2: i1):
hw.instance "" @OneAssertion(x: %arg1: i1) -> ()
verif.assert %arg2 : i1
%sum = comb.add %arg0, %arg0 : i32
verif.yield %sum : i32
}
func.return %bmc : i1
}
hw.module @OneAssertion(in %x: i1) {
verif.assert %x : i1
}
// -----
// Two asserts inside one instantiated module hit the nested-assert
// rejection; the multiple-assertion diagnostic only counts top-module
// asserts.
func.func @nested_asserts_in_one_module() -> (i1) {
// expected-error @below {{assertions inside instantiated modules or called functions are not supported - inline them into the top module first (e.g. with --flatten-modules)}}
%bmc = verif.bmc bound 10 num_regs 0 initial_values []
init {}
loop {}
circuit {
^bb0(%arg0: i32, %arg1: i1, %arg2: i1):
hw.instance "" @TwoAssertions(x: %arg1: i1, y: %arg2: i1) -> ()
%sum = comb.add %arg0, %arg0 : i32
verif.yield %sum : i32
}
func.return %bmc : i1
}
hw.module @TwoAssertions(in %x: i1, in %y: i1) {
verif.assert %x : i1
verif.assert %y : i1
}
// -----
func.func @multiple_clocks() -> (i1) {
// expected-error @below {{only modules with one or zero clocks are currently supported}}
%bmc = verif.bmc bound 10 num_regs 1 initial_values [unit]
init {
%c0_i1 = hw.constant 0 : i1
%clk = seq.to_clock %c0_i1
verif.yield %clk, %clk : !seq.clock, !seq.clock
}
loop {
^bb0(%clock0: !seq.clock, %clock1: !seq.clock):
verif.yield %clock0, %clock1 : !seq.clock, !seq.clock
}
circuit {
^bb0(%clock0: !seq.clock, %clock1: !seq.clock, %arg0: i32):
%c1_i32 = hw.constant 1 : i32
%cond1 = comb.icmp ugt %arg0, %c1_i32 : i32
verif.assert %cond1 : i1
verif.yield %arg0 : i32
}
func.return %bmc : i1
}
// -----
func.func @multiple_clocks() -> (i1) {
// expected-error @below {{initial values are currently only supported for registers with integer types}}
%bmc = verif.bmc bound 10 num_regs 1 initial_values [0]
init {
%c0_i1 = hw.constant 0 : i1
%clk = seq.to_clock %c0_i1
verif.yield %clk : !seq.clock
}
loop {
^bb0(%clk: !seq.clock):
verif.yield %clk: !seq.clock
}
circuit {
^bb0(%clk: !seq.clock, %arg0: !hw.array<2xi32>):
%true = hw.constant true
verif.assert %true : i1
verif.yield %arg0 : !hw.array<2xi32>
}
func.return %bmc : i1
}
// -----
func.func @wrong_initial_type() -> (i1) {
// expected-error @below {{type of initial value does not match type of initialized register}}
%bmc = verif.bmc bound 10 num_regs 1 initial_values [-1 : i7]
init {
%c0_i1 = hw.constant 0 : i1
%clk = seq.to_clock %c0_i1
verif.yield %clk : !seq.clock
}
loop {
^bb0(%clk: !seq.clock):
verif.yield %clk: !seq.clock
}
circuit {
^bb0(%clk: !seq.clock, %arg0: i8):
%true = hw.constant true
verif.assert %true : i1
verif.yield %arg0 : i8
}
func.return %bmc : i1
}
// -----
func.func @refines_non_primitive_free_var() -> () {
// expected-error @below {{failed to legalize operation 'verif.refines' that was explicitly marked illegal}}
verif.refines first {
^bb0(%arg0: !smt.bv<4>):
// expected-error @below {{Uninterpreted function of non-primitive type cannot be converted.}}
%nondetar = smt.declare_fun : !smt.array<[!smt.bv<4> -> !smt.bv<32>]>
%sel = smt.array.select %nondetar[%arg0] : !smt.array<[!smt.bv<4> -> !smt.bv<32>]>
%cc = builtin.unrealized_conversion_cast %sel : !smt.bv<32> to i32
verif.yield %cc : i32
} second {
^bb0(%arg0: !smt.bv<4>):
%const = smt.bv.constant #smt.bv<0> : !smt.bv<32>
%cc = builtin.unrealized_conversion_cast %const : !smt.bv<32> to i32
verif.yield %cc : i32
}
return
}