File: reinterpret-cast-runtime-verification.mlir

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,388 kB
  • sloc: cpp: 7,438,767; ansic: 1,393,871; asm: 1,012,926; python: 241,728; f90: 86,635; objc: 75,411; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (76 lines) | stat: -rw-r--r-- 3,139 bytes parent folder | download | duplicates (2)
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
// RUN: mlir-opt %s -generate-runtime-verification \
// RUN:     -lower-affine \
// RUN:     -finalize-memref-to-llvm \
// RUN:     -test-cf-assert \
// RUN:     -convert-func-to-llvm \
// RUN:     -convert-arith-to-llvm \
// RUN:     -reconcile-unrealized-casts | \
// RUN: mlir-runner -e main -entry-point-result=void \
// RUN:     -shared-libs=%mlir_runner_utils 2>&1 | \
// RUN: FileCheck %s

func.func @reinterpret_cast(%memref: memref<1xf32>, %offset: index) {
    memref.reinterpret_cast %memref to
                    offset: [%offset],
                    sizes: [1],
                    strides: [1]
                  : memref<1xf32> to  memref<1xf32, strided<[1], offset: ?>>
    return
}

func.func @reinterpret_cast_fully_dynamic(%memref: memref<?xf32>, %offset: index, %size: index, %stride: index)  {
    memref.reinterpret_cast %memref to
                    offset: [%offset],
                    sizes: [%size],
                    strides: [%stride]
                  : memref<?xf32> to  memref<?xf32, strided<[?], offset: ?>>
    return
}

func.func @main() {
  %0 = arith.constant 0 : index
  %1 = arith.constant 1 : index
  %n1 = arith.constant -1 : index
  %4 = arith.constant 4 : index
  %5 = arith.constant 5 : index

  %alloca_1 = memref.alloca() : memref<1xf32>
  %alloca_4 = memref.alloca() : memref<4xf32>
  %alloca_4_dyn = memref.cast %alloca_4 : memref<4xf32> to memref<?xf32>

  // Offset is out-of-bounds
  //      CHECK: ERROR: Runtime op verification failed
  // CHECK-NEXT: "memref.reinterpret_cast"(%{{.*}})
  // CHECK-NEXT: ^ result of reinterpret_cast is out-of-bounds of the base memref
  // CHECK-NEXT: Location: loc({{.*}})
  func.call @reinterpret_cast(%alloca_1, %1) : (memref<1xf32>, index) -> ()

  // Offset is out-of-bounds
  //      CHECK: ERROR: Runtime op verification failed
  // CHECK-NEXT: "memref.reinterpret_cast"(%{{.*}})
  // CHECK-NEXT: ^ result of reinterpret_cast is out-of-bounds of the base memref
  // CHECK-NEXT: Location: loc({{.*}})
  func.call @reinterpret_cast(%alloca_1, %n1) : (memref<1xf32>, index) -> ()

  // Size is out-of-bounds
  //      CHECK: ERROR: Runtime op verification failed
  // CHECK-NEXT: "memref.reinterpret_cast"(%{{.*}})
  // CHECK-NEXT: ^ result of reinterpret_cast is out-of-bounds of the base memref
  // CHECK-NEXT: Location: loc({{.*}})
  func.call @reinterpret_cast_fully_dynamic(%alloca_4_dyn, %0, %5, %1) : (memref<?xf32>, index, index, index) -> ()

  // Stride is out-of-bounds
  //      CHECK: ERROR: Runtime op verification failed
  // CHECK-NEXT: "memref.reinterpret_cast"(%{{.*}})
  // CHECK-NEXT: ^ result of reinterpret_cast is out-of-bounds of the base memref
  // CHECK-NEXT: Location: loc({{.*}})
  func.call @reinterpret_cast_fully_dynamic(%alloca_4_dyn, %0, %4, %4) : (memref<?xf32>, index, index, index) -> ()

  //  CHECK-NOT: ERROR: Runtime op verification failed
  func.call @reinterpret_cast(%alloca_1, %0) : (memref<1xf32>, index) -> ()

  //  CHECK-NOT: ERROR: Runtime op verification failed
  func.call @reinterpret_cast_fully_dynamic(%alloca_4_dyn, %0, %4, %1) : (memref<?xf32>, index, index, index) -> ()

  return
}