// Test conversions of fir.alloca // RUN: fir-opt %s --fir-to-memref --allow-unregistered-dialect | FileCheck %s // Test that compiler generated fir.allocas are converted, slightly edited from // subroutine alloca(a) // call f(1) // end // CHECK-LABEL: func.func @alloca // CHECK: [[ALLOCA:%.+]] = memref.alloca() : memref // CHECK-NEXT: [[CONVERT0:%[0-9]]] = fir.convert [[ALLOCA]] : (memref) -> !fir.ref // CHECK: [[CONSTANT:%.+]] = arith.constant 1 : i32 // CHECK: memref.store [[CONSTANT]], [[ALLOCA]][] : memref // CHECK: fir.call @f([[CONVERT0]]) func.func @alloca(%arg0: !fir.ref {fir.bindc_name = "a"}) { %0 = fir.alloca i32 {adapt.valuebyref} %c1_i32 = arith.constant 1 : i32 %1 = fir.dummy_scope : !fir.dscope %2 = fir.declare %arg0 dummy_scope %1 {uniq_name = "alloca"} : (!fir.ref, !fir.dscope) -> !fir.ref fir.store %c1_i32 to %0 : !fir.ref %false = arith.constant false fir.call @f(%0) fastmath : (!fir.ref) -> () return } func.func private @f(!fir.ref) // Test that compiler generated fir.allocas are converted, slightly edited from // subroutine passbyvalue(x) // integer, value :: x // end subroutine // CHECK-LABEL: func.func @passbyvalue // CHECK: [[ALLOCA:%.+]] = memref.alloca() : memref // CHECK-NEXT: [[CONVERT0:%[0-9]]] = fir.convert [[ALLOCA]] : (memref) -> !fir.ref // CHECK-NEXT: memref.store %arg0, [[ALLOCA]][] : memref func.func @passbyvalue(%arg0: i32 {fir.bindc_name = "x"}) { %0 = fir.dummy_scope : !fir.dscope %1 = fir.alloca i32 fir.store %arg0 to %1 : !fir.ref %2 = fir.declare %1 dummy_scope %0 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFpEx"} : (!fir.ref, !fir.dscope) -> !fir.ref return } // Multi-dim dynamic alloca, reduced from // subroutine alloca_2d(n,m) // real :: a(n,m) // end // CHECK-LABEL: func.func @_QPalloca_2d // CHECK: [[CON5:%.+]] = arith.constant 5 // CHECK-NEXT: [[CON3:%.+]] = arith.constant 3 // CHECK-NEXT: [[ALLOCA:%.+]] = memref.alloca([[CON3]], [[CON5]]) {bindc_name = "a"} : memref // CHECK-NEXT: [[CONVERT0:%[0-9]]] = fir.convert [[ALLOCA]] : (memref) -> !fir.ref> func.func @_QPalloca_2d() { %0 = arith.constant 5 : index %1 = arith.constant 3 : index %2 = fir.alloca !fir.array, %0, %1 {bindc_name = "a"} return } // CHECK-LABEL: func.func @alloca_nonconvertible // CHECK-NEXT: [[ALLOCA1:%.+]] = fir.alloca // CHECK-NEXT: [[ALLOCA2:%.+]] = memref.alloca // CHECK-NEXT: [[CONVERT0:%[0-9]]] = fir.convert [[ALLOCA2]] : (memref) -> !fir.ref func.func @alloca_nonconvertible() { %0 = fir.alloca !fir.box> %1 = fir.alloca i32 return } // compiler generated alloca will not preserve declare // CHECK-LABEL: func.func @peep_declare // CHECK: [[ALLOCA:%.+]] = memref.alloca() : memref // CHECK-NOT: fir.declare // CHECK: memref.store %c1_i32, [[ALLOCA]][] : memref func.func @peep_declare() { %c1_i32 = arith.constant 1 : i32 %0 = fir.alloca i32 %1 = fir.declare %0 {uniq_name = "some_name"} : (!fir.ref) -> !fir.ref fir.store %c1_i32 to %1 : !fir.ref return } // check that attributes are copied when they exist // CHECK-LABEL: func.func @preserve_declare // CHECK: [[ALLOCA:%.*]] = memref.alloca() {bindc_name = "x", uniq_name = "y"} : memref // CHECK-NOT: memref.store %c1_i32, [[ALLOCA]][] : memref func.func @preserve_declare() { %c1_i32 = arith.constant 1 : i32 %0 = fir.alloca i32 {bindc_name = "x", uniq_name = "y"} %1 = fir.declare %0 {uniq_name = "some_name"} : (!fir.ref) -> !fir.ref fir.store %c1_i32 to %1 : !fir.ref return } // CHECK-LABEL: func.func @copy_cuf_data_attr // CHECK: memref.alloca() {cuf.data_attr = #cuf.cuda} : memref func.func @copy_cuf_data_attr() { %c1_i32 = arith.constant 1 : i32 %0 = fir.alloca i32 {cuf.data_attr = #cuf.cuda} %1 = fir.declare %0 {uniq_name = "some_name"} : (!fir.ref) -> !fir.ref fir.store %c1_i32 to %1 : !fir.ref return } // CHECK-LABEL: func.func @copy_acc_var_name_attr // CHECK: memref.alloca() {acc.var_name = #acc.var_name<"x">} : memref func.func @copy_acc_var_name_attr() { %c1_i32 = arith.constant 1 : i32 %0 = fir.alloca i32 {acc.var_name = #acc.var_name<"x">} %1 = fir.declare %0 {uniq_name = "some_name"} : (!fir.ref) -> !fir.ref fir.store %c1_i32 to %1 : !fir.ref return }