File: value-bounds-op-interface-impl.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (106 lines) | stat: -rw-r--r-- 4,371 bytes parent folder | download | duplicates (3)
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
// RUN: mlir-opt %s -test-affine-reify-value-bounds -verify-diagnostics \
// RUN:     -split-input-file | FileCheck %s

// CHECK-LABEL: func @scf_for(
//  CHECK-SAME:     %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   "test.some_use"(%[[a]], %[[b]])
func.func @scf_for(%a: index, %b: index, %c: index) {
  scf.for %iv = %a to %b step %c {
    %0 = "test.reify_bound"(%iv) {type = "LB"} : (index) -> (index)
    %1 = "test.reify_bound"(%iv) {type = "UB"} : (index) -> (index)
    "test.some_use"(%0, %1) : (index, index) -> ()
  }
  return
}

// -----

// CHECK-LABEL: func @scf_for_index_result_small(
//  CHECK-SAME:     %[[i:.*]]: index, %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   "test.some_use"(%[[i]])
//       CHECK:   "test.some_use"(%[[i]])
func.func @scf_for_index_result_small(%i: index, %a: index, %b: index, %c: index) {
  %0 = scf.for %iv = %a to %b step %c iter_args(%arg = %i) -> index {
    %1 = "test.reify_bound"(%arg) {type = "EQ"} : (index) -> (index)
    "test.some_use"(%1) : (index) -> ()
    scf.yield %arg : index
  }
  %2 = "test.reify_bound"(%0) {type = "EQ"} : (index) -> (index)
  "test.some_use"(%2) : (index) -> ()
  return
}

// -----

// CHECK-LABEL: func @scf_for_index_result(
//  CHECK-SAME:     %[[i:.*]]: index, %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   "test.some_use"(%[[i]])
//       CHECK:   "test.some_use"(%[[i]])
func.func @scf_for_index_result(%i: index, %a: index, %b: index, %c: index) {
  %0 = scf.for %iv = %a to %b step %c iter_args(%arg = %i) -> index {
    %add = arith.addi %arg, %a : index
    %sub = arith.subi %add, %a : index

    %1 = "test.reify_bound"(%arg) {type = "EQ"} : (index) -> (index)
    "test.some_use"(%1) : (index) -> ()
    scf.yield %sub : index
  }
  %2 = "test.reify_bound"(%0) {type = "EQ"} : (index) -> (index)
  "test.some_use"(%2) : (index) -> ()
  return
}

// -----

// CHECK-LABEL: func @scf_for_tensor_result_small(
//  CHECK-SAME:     %[[t:.*]]: tensor<?xf32>, %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   %[[dim:.*]] = tensor.dim %[[t]]
//       CHECK:   "test.some_use"(%[[dim]])
//       CHECK:   %[[dim:.*]] = tensor.dim %[[t]]
//       CHECK:   "test.some_use"(%[[dim]])
func.func @scf_for_tensor_result_small(%t: tensor<?xf32>, %a: index, %b: index, %c: index) {
  %0 = scf.for %iv = %a to %b step %c iter_args(%arg = %t) -> tensor<?xf32> {
    %1 = "test.reify_bound"(%arg) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
    "test.some_use"(%1) : (index) -> ()
    scf.yield %arg : tensor<?xf32>
  }
  %2 = "test.reify_bound"(%0) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
  "test.some_use"(%2) : (index) -> ()
  return
}

// -----

// CHECK-LABEL: func @scf_for_tensor_result(
//  CHECK-SAME:     %[[t:.*]]: tensor<?xf32>, %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   %[[dim:.*]] = tensor.dim %[[t]]
//       CHECK:   "test.some_use"(%[[dim]])
//       CHECK:   %[[dim:.*]] = tensor.dim %[[t]]
//       CHECK:   "test.some_use"(%[[dim]])
func.func @scf_for_tensor_result(%t: tensor<?xf32>, %a: index, %b: index, %c: index) {
  %cst = arith.constant 5.0 : f32
  %0 = scf.for %iv = %a to %b step %c iter_args(%arg = %t) -> tensor<?xf32> {
    %filled = linalg.fill ins(%cst : f32) outs(%arg : tensor<?xf32>) -> tensor<?xf32>
    %1 = "test.reify_bound"(%arg) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
    "test.some_use"(%1) : (index) -> ()
    scf.yield %filled : tensor<?xf32>
  }
  %2 = "test.reify_bound"(%0) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
  "test.some_use"(%2) : (index) -> ()
  return
}

// -----

func.func @scf_for_swapping_yield(%t1: tensor<?xf32>, %t2: tensor<?xf32>, %a: index, %b: index, %c: index) {
  %cst = arith.constant 5.0 : f32
  %r1, %r2 = scf.for %iv = %a to %b step %c iter_args(%arg1 = %t1, %arg2 = %t2) -> (tensor<?xf32>, tensor<?xf32>) {
    %filled1 = linalg.fill ins(%cst : f32) outs(%arg1 : tensor<?xf32>) -> tensor<?xf32>
    %filled2 = linalg.fill ins(%cst : f32) outs(%arg2 : tensor<?xf32>) -> tensor<?xf32>
    scf.yield %filled2, %filled1 : tensor<?xf32>, tensor<?xf32>
  }
  // expected-error @below{{could not reify bound}}
  %reify1 = "test.reify_bound"(%r1) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
  "test.some_use"(%reify1) : (index) -> ()
  return
}