• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: mlir-opt %s -func-bufferize -split-input-file -verify-diagnostics | FileCheck %s
2
3// CHECK-LABEL:   func @identity(
4// CHECK-SAME:                   %[[ARG:.*]]: memref<f32>) -> memref<f32> {
5// CHECK:           %[[TENSOR:.*]] = tensor_load %[[ARG]] : memref<f32>
6// CHECK:           %[[MEMREF:.*]] = tensor_to_memref %[[TENSOR]] : memref<f32>
7// CHECK:           return %[[MEMREF]] : memref<f32>
8func @identity(%arg0: tensor<f32>) -> tensor<f32> {
9  return %arg0 : tensor<f32>
10}
11
12// CHECK-LABEL:   func @block_arguments(
13// CHECK-SAME:        %[[ARG:.*]]: memref<f32>) -> memref<f32> {
14// CHECK:           %[[T1:.*]] = tensor_load %[[ARG]] : memref<f32>
15// CHECK:           %[[M1:.*]] = tensor_to_memref %[[T1]] : memref<f32>
16// CHECK:           br ^bb1(%[[M1]] : memref<f32>)
17// CHECK:         ^bb1(%[[BBARG:.*]]: memref<f32>):
18// CHECK:           %[[T2:.*]] = tensor_load %[[BBARG]] : memref<f32>
19// CHECK:           %[[M2:.*]] = tensor_to_memref %[[T2]] : memref<f32>
20// CHECK:           return %[[M2]] : memref<f32>
21func @block_arguments(%arg0: tensor<f32>) -> tensor<f32> {
22  br ^bb1(%arg0: tensor<f32>)
23^bb1(%bbarg: tensor<f32>):
24  return %bbarg : tensor<f32>
25}
26
27// CHECK-LABEL:   func private @source() -> memref<f32>
28// CHECK-LABEL:   func @call_source() -> memref<f32> {
29// CHECK:           %[[RET:.*]] = call @source() : () -> memref<f32>
30// CHECK:           return %[[RET]] : memref<f32>
31func private @source() -> tensor<f32>
32func @call_source() -> tensor<f32> {
33  %0 = call @source() : () -> tensor<f32>
34  return %0 : tensor<f32>
35}
36// CHECK-LABEL:   func @call_sink(
37// CHECK-SAME:                    %[[ARG:.*]]: memref<f32>) {
38// CHECK:           %[[TENSOR:.*]] = tensor_load %[[ARG]] : memref<f32>
39// CHECK:           %[[MEMREF:.*]] = tensor_to_memref %[[TENSOR]] : memref<f32>
40// CHECK:           call @sink(%[[MEMREF]]) : (memref<f32>) -> ()
41// CHECK:           return
42func private @sink(tensor<f32>)
43func @call_sink(%arg0: tensor<f32>) {
44  call @sink(%arg0) : (tensor<f32>) -> ()
45  return
46}
47
48// CHECK-LABEL:   func @unconverted_op_in_body() -> memref<f32> {
49// CHECK:           %[[TENSOR:.*]] = "test.source"() : () -> tensor<f32>
50// CHECK:           %[[MEMREF:.*]] = tensor_to_memref %[[TENSOR]] : memref<f32>
51// CHECK:           return %[[MEMREF]] : memref<f32>
52func @unconverted_op_in_body() -> tensor<f32> {
53  %0 = "test.source"() : () -> tensor<f32>
54  return %0 : tensor<f32>
55}
56
57// -----
58
59// Because this pass updates block arguments, it needs to also atomically
60// update all terminators and issue an error if that is not possible.
61func @unable_to_update_terminator(%arg0: tensor<f32>) -> tensor<f32> {
62    %0 = constant true
63    cond_br %0, ^bb1(%arg0: tensor<f32>), ^bb2(%arg0: tensor<f32>)
64  ^bb1(%bbarg0: tensor<f32>):
65    // expected-error @+1 {{failed to legalize operation 'test.terminator'}}
66    "test.terminator"() : () -> ()
67  ^bb2(%bbarg1: tensor<f32>):
68    return %bbarg1 : tensor<f32>
69}
70