88 lines · python
1# RUN: %PYTHON %s | FileCheck %s2 3from mlir.dialects import smt, arith4from mlir.ir import Context, Location, Module, InsertionPoint, F32Type5 6 7def run(f):8 print("\nTEST:", f.__name__)9 with Context(), Location.unknown():10 module = Module.create()11 with InsertionPoint(module.body):12 f(module)13 print(module)14 assert module.operation.verify()15 16 17# CHECK-LABEL: TEST: test_smoke18@run19def test_smoke(_module):20 true = smt.constant(True)21 false = smt.constant(False)22 # CHECK: smt.constant true23 # CHECK: smt.constant false24 25 26# CHECK-LABEL: TEST: test_types27@run28def test_types(_module):29 bool_t = smt.bool_t()30 bitvector_t = smt.bv_t(5)31 # CHECK: !smt.bool32 print(bool_t)33 # CHECK: !smt.bv<5>34 print(bitvector_t)35 36 37# CHECK-LABEL: TEST: test_solver_op38@run39def test_solver_op(_module):40 @smt.solver41 def foo1():42 true = smt.constant(True)43 false = smt.constant(False)44 45 # CHECK: smt.solver() : () -> () {46 # CHECK: %true = smt.constant true47 # CHECK: %false = smt.constant false48 # CHECK: }49 50 f32 = F32Type.get()51 52 @smt.solver(results=[f32])53 def foo2():54 return arith.ConstantOp(f32, 1.0)55 56 # CHECK: %{{.*}} = smt.solver() : () -> f32 {57 # CHECK: %[[CST1:.*]] = arith.constant 1.000000e+00 : f3258 # CHECK: smt.yield %[[CST1]] : f3259 # CHECK: }60 61 two = arith.ConstantOp(f32, 2.0)62 # CHECK: %[[CST2:.*]] = arith.constant 2.000000e+00 : f3263 print(two)64 65 @smt.solver(inputs=[two], results=[f32])66 def foo3(z: f32):67 return z68 69 # CHECK: %{{.*}} = smt.solver(%[[CST2]]) : (f32) -> f32 {70 # CHECK: ^bb0(%[[ARG0:.*]]: f32):71 # CHECK: smt.yield %[[ARG0]] : f3272 # CHECK: }73 74 75# CHECK-LABEL: TEST: test_export_smtlib76@run77def test_export_smtlib(module):78 @smt.solver79 def foo1():80 true = smt.constant(True)81 smt.assert_(true)82 83 query = smt.export_smtlib(module.operation)84 # CHECK: ; solver scope 085 # CHECK: (assert true)86 # CHECK: (reset)87 print(query)88