221
|
1 // RUN: mlir-opt --split-input-file --tosa-to-scf %s -verify-diagnostics -o -| FileCheck %s
|
|
2
|
|
3 // CHECK-LABEL: func @while_test
|
|
4 // CHECK-SAME: ([[ARG0:%.+]]: tensor<i32>)
|
236
|
5 func.func @while_test(%arg0 : tensor<i32>) -> (tensor<i32>) {
|
221
|
6 // CHECK: [[WHILE:%.+]] = scf.while ([[ARG1:%.+]] = [[ARG0]])
|
236
|
7 %1 = "tosa.while_loop"(%arg0) ({
|
221
|
8 ^bb0(%arg2: tensor<i32>):
|
|
9 // CHECK: "tosa.const"
|
|
10 %2 = "tosa.const"() {value = dense<3> : tensor<i32>} : () -> tensor<i32>
|
|
11
|
|
12 // CHECK: [[COMPARE:%.+]] = "tosa.greater_equal"
|
|
13 %3 = "tosa.greater_equal"(%2, %arg2) : (tensor<i32>, tensor<i32>) -> tensor<i1>
|
|
14
|
|
15 // CHECK: [[EX:%.+]] = tensor.extract [[COMPARE]]
|
|
16 // CHECK: scf.condition([[EX]]) [[ARG1]]
|
|
17 "tosa.yield"(%3) : (tensor<i1>) -> ()
|
|
18 }, {
|
|
19 // CHECK: ^bb0([[ARG1:%.+]]: tensor<i32>)
|
|
20 ^bb0(%arg2: tensor<i32>):
|
|
21 // CHECK: tosa.const
|
|
22 %2 = "tosa.const"() {value = dense<1> : tensor<i32>} : () -> tensor<i32>
|
|
23
|
|
24 // CHECK: [[ADD:%.+]] = "tosa.add"
|
|
25 %3 = "tosa.add"(%arg2, %2) : (tensor<i32>, tensor<i32>) -> tensor<i32>
|
|
26
|
|
27 // CHECK: scf.yield [[ADD]]
|
|
28 "tosa.yield"(%3) : (tensor<i32>) -> ()
|
|
29 }) : (tensor<i32>) -> (tensor<i32>)
|
|
30 return %1 : tensor<i32>
|
|
31 }
|
|
32
|
236
|
33 // -----
|
221
|
34
|
|
35 // CHECK-LABEL: func @if_test
|
|
36 // CHECK-SAME: ([[ARG0:%.+]]: tensor<f32>, [[ARG1:%.+]]: tensor<f32>, [[ARG2:%.+]]: tensor<i1>)
|
236
|
37 func.func @if_test(%arg0 : tensor<f32>, %arg1 : tensor<f32>, %arg2 : tensor<i1>) -> (tensor<f32>) {
|
221
|
38 // CHECK: [[EX:%.+]] = tensor.extract [[ARG2]]
|
|
39 // CHECK: [[IF:%.+]] = scf.if [[EX]] -> (tensor<f32>) {
|
|
40 %0 = "tosa.cond_if"(%arg2, %arg0, %arg1) ({
|
|
41
|
|
42 // CHECK: scf.yield [[ARG0]]
|
|
43 ^bb1(%arg3 : tensor<f32>, %arg4 : tensor<f32>):
|
|
44 "tosa.yield"(%arg3) : (tensor<f32>) -> ()
|
|
45
|
|
46 // CHECK: } else {
|
|
47 }, {
|
|
48
|
|
49 // CHECK: scf.yield [[ARG1]]
|
|
50 ^bb1(%arg5 : tensor<f32>, %arg6 : tensor<f32>):
|
|
51 "tosa.yield"(%arg6) : (tensor<f32>) -> ()
|
|
52
|
|
53 // CHECK: }
|
|
54 // CHECK: return [[IF]]
|
|
55 }) : (tensor<i1>, tensor<f32>, tensor<f32>) -> (tensor<f32>)
|
|
56
|
|
57 return %0 : tensor<f32>
|
|
58 }
|