1# RUN: %PYTHON %s | FileCheck %s
2
3from mlir.ir import *
4import mlir.dialects.builtin as builtin
5import mlir.dialects.std as std
6import mlir.dialects.vector as vector
7
8def run(f):
9  print("\nTEST:", f.__name__)
10  with Context(), Location.unknown():
11    f()
12  return f
13
14# CHECK-LABEL: TEST: testPrintOp
15@run
16def testPrintOp():
17  module = Module.create()
18  with InsertionPoint(module.body):
19
20    @builtin.FuncOp.from_py_func(VectorType.get((12, 5), F32Type.get()))
21    def print_vector(arg):
22      return vector.PrintOp(arg)
23
24  # CHECK-LABEL: func @print_vector(
25  # CHECK-SAME:                     %[[ARG:.*]]: vector<12x5xf32>) {
26  #       CHECK:   vector.print %[[ARG]] : vector<12x5xf32>
27  #       CHECK:   return
28  #       CHECK: }
29  print(module)
30
31
32# CHECK-LABEL: TEST: testTransferReadOp
33@run
34def testTransferReadOp():
35  module = Module.create()
36  with InsertionPoint(module.body):
37    vector_type = VectorType.get([2, 3], F32Type.get())
38    memref_type = MemRefType.get([-1, -1], F32Type.get())
39    index_type = IndexType.get()
40    mask_type = VectorType.get(vector_type.shape, IntegerType.get_signless(1))
41    identity_map = AffineMap.get_identity(vector_type.rank)
42    identity_map_attr = AffineMapAttr.get(identity_map)
43    func = builtin.FuncOp("transfer_read",
44                          ([memref_type, index_type,
45                            F32Type.get(), mask_type], []))
46    with InsertionPoint(func.add_entry_block()):
47      A, zero, padding, mask = func.arguments
48      vector.TransferReadOp(vector_type, A, [zero, zero], identity_map_attr,
49                            padding, mask, None)
50      vector.TransferReadOp(vector_type, A, [zero, zero], identity_map_attr,
51                            padding, None, None)
52      std.ReturnOp([])
53
54  # CHECK: @transfer_read(%[[MEM:.*]]: memref<?x?xf32>, %[[IDX:.*]]: index,
55  # CHECK: %[[PAD:.*]]: f32, %[[MASK:.*]]: vector<2x3xi1>)
56  # CHECK: vector.transfer_read %[[MEM]][%[[IDX]], %[[IDX]]], %[[PAD]], %[[MASK]]
57  # CHECK: vector.transfer_read %[[MEM]][%[[IDX]], %[[IDX]]], %[[PAD]]
58  # CHECK-NOT: %[[MASK]]
59  print(module)
60