// RUN: mlir-opt %s -func-bufferize -split-input-file -verify-diagnostics | FileCheck %s // CHECK-LABEL: func @identity( // CHECK-SAME: %[[ARG:.*]]: memref) -> memref { // CHECK: return %[[ARG]] : memref func.func @identity(%arg0: tensor) -> tensor { return %arg0 : tensor } // CHECK-LABEL: func @block_arguments( // CHECK-SAME: %[[ARG:.*]]: memref) -> memref { // CHECK: cf.br ^bb1(%[[ARG]] : memref) // CHECK: ^bb1(%[[BBARG:.*]]: memref): // CHECK: return %[[BBARG]] : memref func.func @block_arguments(%arg0: tensor) -> tensor { cf.br ^bb1(%arg0: tensor) ^bb1(%bbarg: tensor): return %bbarg : tensor } // CHECK-LABEL: func private @source() -> memref // CHECK-LABEL: func @call_source() -> memref { // CHECK: %[[RET:.*]] = call @source() : () -> memref // CHECK: return %[[RET]] : memref func.func private @source() -> tensor func.func @call_source() -> tensor { %0 = call @source() : () -> tensor return %0 : tensor } // CHECK-LABEL: func @call_sink( // CHECK-SAME: %[[ARG:.*]]: memref) { // CHECK: call @sink(%[[ARG]]) : (memref) -> () // CHECK: return func.func private @sink(tensor) func.func @call_sink(%arg0: tensor) { call @sink(%arg0) : (tensor) -> () return } // CHECK-LABEL: func @unconverted_op_in_body() -> memref { // CHECK: %[[TENSOR:.*]] = "test.source"() : () -> tensor // CHECK: %[[MEMREF:.*]] = bufferization.to_memref %[[TENSOR]] : memref // CHECK: return %[[MEMREF]] : memref func.func @unconverted_op_in_body() -> tensor { %0 = "test.source"() : () -> tensor return %0 : tensor } // ----- // Because this pass updates block arguments, it needs to also atomically // update all terminators and issue an error if that is not possible. func.func @unable_to_update_terminator(%arg0: tensor) -> tensor { %0 = arith.constant true cf.cond_br %0, ^bb1(%arg0: tensor), ^bb2(%arg0: tensor) ^bb1(%bbarg0: tensor): // expected-error @+1 {{failed to legalize operation 'test.terminator'}} "test.terminator"() : () -> () ^bb2(%bbarg1: tensor): return %bbarg1 : tensor } // ----- // There was a bug in func-bufferize pass which caused terminators without // ReturnLike and BranchOpInterface traits (e.g. scf.condition) to always // fail to legalize even if bufferization doesn't needed. // Check the pass succedeed. // CHECK: bufferize_while // CHECK: scf.while // CHECK: scf.condition func.func @bufferize_while(%arg0: i64, %arg1: i64) -> i64 { %c2_i64 = arith.constant 2 : i64 %0:2 = scf.while (%arg2 = %arg0) : (i64) -> (i64, i64) { %1 = arith.cmpi slt, %arg2, %arg1 : i64 scf.condition(%1) %arg2, %arg2 : i64, i64 } do { ^bb0(%arg2: i64, %arg3: i64): %1 = arith.muli %arg3, %c2_i64 : i64 scf.yield %1 : i64 } return %0#1 : i64 }