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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
// RUN: mlir-opt -allow-unregistered-dialect -split-input-file %s | FileCheck %s
// RUN: mlir-opt -allow-unregistered-dialect %s -mlir-print-op-generic | FileCheck -check-prefix=GENERIC %s
// Check that the attributes for the affine operations are round-tripped.
// Check that `affine.yield` is visible in the generic form.
// CHECK-LABEL: @empty
func.func @empty() {
// CHECK: affine.for
// CHECK-NEXT: } {some_attr = true}
//
// GENERIC: "affine.for"()
// GENERIC-NEXT: ^bb0(%{{.*}}: index):
// GENERIC-NEXT: "affine.yield"() : () -> ()
// GENERIC-NEXT: })
affine.for %i = 0 to 10 {
} {some_attr = true}
// CHECK: affine.if
// CHECK-NEXT: } {some_attr = true}
//
// GENERIC: "affine.if"()
// GENERIC-NEXT: "affine.yield"() : () -> ()
// GENERIC-NEXT: }, {
// GENERIC-NEXT: })
affine.if affine_set<() : ()> () {
} {some_attr = true}
// CHECK: } else {
// CHECK: } {some_attr = true}
//
// GENERIC: "affine.if"()
// GENERIC-NEXT: "affine.yield"() : () -> ()
// GENERIC-NEXT: }, {
// GENERIC-NEXT: "foo"() : () -> ()
// GENERIC-NEXT: "affine.yield"() : () -> ()
// GENERIC-NEXT: })
affine.if affine_set<() : ()> () {
} else {
"foo"() : () -> ()
} {some_attr = true}
return
}
// Check that an explicit affine.yield is not printed in custom format.
// Check that no extra terminator is introduced.
// CHECK-LABEL: @affine.yield
func.func @affine.yield() {
// CHECK: affine.for
// CHECK-NEXT: }
//
// GENERIC: "affine.for"() ({
// GENERIC-NEXT: ^bb0(%{{.*}}: index):
// GENERIC-NEXT: "affine.yield"() : () -> ()
// GENERIC-NEXT: }) {lower_bound = #map, step = 1 : index, upper_bound = #map1} : () -> ()
affine.for %i = 0 to 10 {
"affine.yield"() : () -> ()
}
return
}
// -----
// CHECK-DAG: #[[$MAP0:map[0-9]*]] = affine_map<(d0)[s0] -> (1000, d0 + 512, s0)>
// CHECK-DAG: #[[$MAP1:map[0-9]*]] = affine_map<(d0, d1)[s0] -> (d0 - d1, s0 + 512)>
// CHECK-DAG: #[[$MAP2:map[0-9]*]] = affine_map<()[s0, s1] -> (s0 - s1, 11)>
// CHECK-DAG: #[[$MAP3:map[0-9]*]] = affine_map<() -> (77, 78, 79)>
// CHECK-LABEL: @affine_min
func.func @affine_min(%arg0 : index, %arg1 : index, %arg2 : index) {
// CHECK: affine.min #[[$MAP0]](%arg0)[%arg1]
%0 = affine.min affine_map<(d0)[s0] -> (1000, d0 + 512, s0)> (%arg0)[%arg1]
// CHECK: affine.min #[[$MAP1]](%arg0, %arg1)[%arg2]
%1 = affine.min affine_map<(d0, d1)[s0] -> (d0 - d1, s0 + 512)> (%arg0, %arg1)[%arg2]
// CHECK: affine.min #[[$MAP2]]()[%arg1, %arg2]
%2 = affine.min affine_map<()[s0, s1] -> (s0 - s1, 11)> ()[%arg1, %arg2]
// CHECK: affine.min #[[$MAP3]]()
%3 = affine.min affine_map<()[] -> (77, 78, 79)> ()[]
return
}
// CHECK-LABEL: @affine_max
func.func @affine_max(%arg0 : index, %arg1 : index, %arg2 : index) {
// CHECK: affine.max #[[$MAP0]](%arg0)[%arg1]
%0 = affine.max affine_map<(d0)[s0] -> (1000, d0 + 512, s0)> (%arg0)[%arg1]
// CHECK: affine.max #[[$MAP1]](%arg0, %arg1)[%arg2]
%1 = affine.max affine_map<(d0, d1)[s0] -> (d0 - d1, s0 + 512)> (%arg0, %arg1)[%arg2]
// CHECK: affine.max #[[$MAP2]]()[%arg1, %arg2]
%2 = affine.max affine_map<()[s0, s1] -> (s0 - s1, 11)> ()[%arg1, %arg2]
// CHECK: affine.max #[[$MAP3]]()
%3 = affine.max affine_map<()[] -> (77, 78, 79)> ()[]
return
}
// -----
func.func @valid_symbols(%arg0: index, %arg1: index, %arg2: index) {
%c1 = arith.constant 1 : index
%c0 = arith.constant 0 : index
%0 = memref.alloc(%arg0, %arg1) : memref<?x?xf32>
affine.for %arg3 = 0 to %arg2 step 768 {
%13 = memref.dim %0, %c1 : memref<?x?xf32>
affine.for %arg4 = 0 to %13 step 264 {
%18 = memref.dim %0, %c0 : memref<?x?xf32>
%20 = memref.subview %0[%c0, %c0][%18,%arg4][%c1,%c1] : memref<?x?xf32>
to memref<?x?xf32, strided<[?, ?], offset: ?>>
%24 = memref.dim %20, %c0 : memref<?x?xf32, strided<[?, ?], offset: ?>>
affine.for %arg5 = 0 to %24 step 768 {
"foo"() : () -> ()
}
}
}
return
}
// -----
// Test symbol constraints for ops with AffineScope trait.
// CHECK-LABEL: func @valid_symbol_affine_scope
func.func @valid_symbol_affine_scope(%n : index, %A : memref<?xf32>) {
test.affine_scope {
%c1 = arith.constant 1 : index
%l = arith.subi %n, %c1 : index
// %l, %n are valid symbols since test.affine_scope defines a new affine
// scope.
affine.for %i = %l to %n {
%m = arith.subi %l, %i : index
test.affine_scope {
// %m and %n are valid symbols.
affine.for %j = %m to %n {
%v = affine.load %A[%n - 1] : memref<?xf32>
affine.store %v, %A[%n - 1] : memref<?xf32>
}
"terminate"() : () -> ()
}
}
"terminate"() : () -> ()
}
return
}
// -----
// Test the fact that module op always provides an affine scope.
%idx = "test.foo"() : () -> (index)
"test.func"() ({
^bb0(%A : memref<?xf32>):
affine.load %A[%idx] : memref<?xf32>
"terminate"() : () -> ()
}) : () -> ()
// -----
// CHECK-LABEL: func @parallel
// CHECK-SAME: (%[[A:.*]]: memref<100x100xf32>, %[[N:.*]]: index)
func.func @parallel(%A : memref<100x100xf32>, %N : index) {
// CHECK: affine.parallel (%[[I0:.*]], %[[J0:.*]]) = (0, 0) to (symbol(%[[N]]), 100) step (10, 10)
affine.parallel (%i0, %j0) = (0, 0) to (symbol(%N), 100) step (10, 10) {
// CHECK: affine.parallel (%{{.*}}, %{{.*}}) = (%[[I0]], %[[J0]]) to (%[[I0]] + 10, %[[J0]] + 10) reduce ("minf", "maxf") -> (f32, f32)
%0:2 = affine.parallel (%i1, %j1) = (%i0, %j0) to (%i0 + 10, %j0 + 10) reduce ("minf", "maxf") -> (f32, f32) {
%2 = affine.load %A[%i0 + %i0, %j0 + %j1] : memref<100x100xf32>
affine.yield %2, %2 : f32, f32
}
}
return
}
// -----
// CHECK-LABEL: @parallel_min_max
// CHECK: %[[A:.*]]: index, %[[B:.*]]: index, %[[C:.*]]: index, %[[D:.*]]: index
func.func @parallel_min_max(%a: index, %b: index, %c: index, %d: index) {
// CHECK: affine.parallel (%{{.*}}, %{{.*}}, %{{.*}}) =
// CHECK: (max(%[[A]], %[[B]])
// CHECK: to (%[[C]], min(%[[C]], %[[D]]), %[[B]])
affine.parallel (%i, %j, %k) = (max(%a, %b), %b, max(%a, %c))
to (%c, min(%c, %d), %b) {
affine.yield
}
return
}
// -----
// CHECK-LABEL: @parallel_no_ivs
func.func @parallel_no_ivs() {
// CHECK: affine.parallel () = () to ()
affine.parallel () = () to () {
affine.yield
}
return
}
// -----
// CHECK-LABEL: func @affine_if
func.func @affine_if() -> f32 {
// CHECK: %[[ZERO:.*]] = arith.constant {{.*}} : f32
%zero = arith.constant 0.0 : f32
// CHECK: %[[OUT:.*]] = affine.if {{.*}}() -> f32 {
%0 = affine.if affine_set<() : ()> () -> f32 {
// CHECK: affine.yield %[[ZERO]] : f32
affine.yield %zero : f32
} else {
// CHECK: affine.yield %[[ZERO]] : f32
affine.yield %zero : f32
}
// CHECK: return %[[OUT]] : f32
return %0 : f32
}
// -----
// Test affine.for with yield values.
#set = affine_set<(d0): (d0 - 10 >= 0)>
// CHECK-LABEL: func @yield_loop
func.func @yield_loop(%buffer: memref<1024xf32>) -> f32 {
%sum_init_0 = arith.constant 0.0 : f32
%res = affine.for %i = 0 to 10 step 2 iter_args(%sum_iter = %sum_init_0) -> f32 {
%t = affine.load %buffer[%i] : memref<1024xf32>
%sum_next = affine.if #set(%i) -> (f32) {
%new_sum = arith.addf %sum_iter, %t : f32
affine.yield %new_sum : f32
} else {
affine.yield %sum_iter : f32
}
affine.yield %sum_next : f32
}
return %res : f32
}
// CHECK: %[[const_0:.*]] = arith.constant 0.000000e+00 : f32
// CHECK-NEXT: %[[output:.*]] = affine.for %{{.*}} = 0 to 10 step 2 iter_args(%{{.*}} = %[[const_0]]) -> (f32) {
// CHECK: affine.if #set(%{{.*}}) -> f32 {
// CHECK: affine.yield %{{.*}} : f32
// CHECK-NEXT: } else {
// CHECK-NEXT: affine.yield %{{.*}} : f32
// CHECK-NEXT: }
// CHECK-NEXT: affine.yield %{{.*}} : f32
// CHECK-NEXT: }
// CHECK-NEXT: return %[[output]] : f32
// CHECK-LABEL: func @affine_for_multiple_yield
func.func @affine_for_multiple_yield(%buffer: memref<1024xf32>) -> (f32, f32) {
%init_0 = arith.constant 0.0 : f32
%res1, %res2 = affine.for %i = 0 to 10 step 2 iter_args(%iter_arg1 = %init_0, %iter_arg2 = %init_0) -> (f32, f32) {
%t = affine.load %buffer[%i] : memref<1024xf32>
%ret1 = arith.addf %t, %iter_arg1 : f32
%ret2 = arith.addf %t, %iter_arg2 : f32
affine.yield %ret1, %ret2 : f32, f32
}
return %res1, %res2 : f32, f32
}
// CHECK: %[[const_0:.*]] = arith.constant 0.000000e+00 : f32
// CHECK-NEXT: %[[output:[0-9]+]]:2 = affine.for %{{.*}} = 0 to 10 step 2 iter_args(%[[iter_arg1:.*]] = %[[const_0]], %[[iter_arg2:.*]] = %[[const_0]]) -> (f32, f32) {
// CHECK: %[[res1:.*]] = arith.addf %{{.*}}, %[[iter_arg1]] : f32
// CHECK-NEXT: %[[res2:.*]] = arith.addf %{{.*}}, %[[iter_arg2]] : f32
// CHECK-NEXT: affine.yield %[[res1]], %[[res2]] : f32, f32
// CHECK-NEXT: }
// -----
// CHECK-LABEL: func @delinearize
func.func @delinearize(%linear_idx: index, %basis0: index, %basis1 :index) -> (index, index) {
// CHECK: affine.delinearize_index %{{.+}} into (%{{.+}}, %{{.+}}) : index, index
%1:2 = affine.delinearize_index %linear_idx into (%basis0, %basis1) : index, index
return %1#0, %1#1 : index, index
}
|