1 # RUN: %PYTHON %s | FileCheck %s
4 import mlir
.dialects
.std
as std
5 import mlir
.dialects
.memref
as memref
9 print("\nTEST:", f
.__name
__)
14 # CHECK-LABEL: TEST: testSubViewAccessors
16 def testSubViewAccessors():
18 module
= Module
.parse(
20 func @f1(%arg0: memref<?x?xf32>) {
21 %0 = arith.constant 0 : index
22 %1 = arith.constant 1 : index
23 %2 = arith.constant 2 : index
24 %3 = arith.constant 3 : index
25 %4 = arith.constant 4 : index
26 %5 = arith.constant 5 : index
27 memref.subview %arg0[%0, %1][%2, %3][%4, %5] : memref<?x?xf32> to memref<?x?xf32, offset: ?, strides: [?, ?]>
31 func_body
= module
.body
.operations
[0].regions
[0].blocks
[0]
32 subview
= func_body
.operations
[6]
34 assert subview
.source
== subview
.operands
[0]
35 assert len(subview
.offsets
) == 2
36 assert len(subview
.sizes
) == 2
37 assert len(subview
.strides
) == 2
38 assert subview
.result
== subview
.results
[0]
41 print(type(subview
).__name
__)
44 print(subview
.offsets
[0])
46 print(subview
.offsets
[1])
48 print(subview
.sizes
[0])
50 print(subview
.sizes
[1])
52 print(subview
.strides
[0])
54 print(subview
.strides
[1])
57 # CHECK-LABEL: TEST: testCustomBuidlers
59 def testCustomBuidlers():
60 with
Context() as ctx
, Location
.unknown(ctx
):
61 module
= Module
.parse(r
"""
62 func @f1(%arg0: memref<?x?xf32>, %arg1: index, %arg2: index) {
66 func
= module
.body
.operations
[0]
67 func_body
= func
.regions
[0].blocks
[0]
68 with InsertionPoint
.at_block_terminator(func_body
):
69 memref
.LoadOp(func
.arguments
[0], func
.arguments
[1:])
71 # CHECK: func @f1(%[[ARG0:.*]]: memref<?x?xf32>, %[[ARG1:.*]]: index, %[[ARG2:.*]]: index)
72 # CHECK: memref.load %[[ARG0]][%[[ARG1]], %[[ARG2]]]
74 assert module
.operation
.verify()