| 1 |
// Test fir.rebox_assumed_rank lowering to runtime calls in fir-assumed-rank-op pass. |
| 2 |
// RUN: fir-opt -o - --fir-assumed-rank-op %s | FileCheck %s |
| 3 |
|
| 4 |
func.func @test_simple(%arg0: !fir.box<!fir.array<*:f32>> ) { |
| 5 |
%1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>> |
| 6 |
fir.call @somefunc(%1) : (!fir.box<!fir.array<*:f32>>) -> () |
| 7 |
return |
| 8 |
} |
| 9 |
func.func @test_simple_zeroes(%arg0: !fir.box<!fir.array<*:f32>> ) { |
| 10 |
%1 = fir.rebox_assumed_rank %arg0 lbs zeroes : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>> |
| 11 |
fir.call @somefunc(%1) : (!fir.box<!fir.array<*:f32>>) -> () |
| 12 |
return |
| 13 |
} |
| 14 |
func.func @test_simple_preserve(%arg0: !fir.box<!fir.array<*:f32>> ) { |
| 15 |
%1 = fir.rebox_assumed_rank %arg0 lbs preserve : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>> |
| 16 |
fir.call @somefunc(%1) : (!fir.box<!fir.array<*:f32>>) -> () |
| 17 |
return |
| 18 |
} |
| 19 |
func.func @test_allocatable(%arg0: !fir.box<!fir.array<*:f32>> ) { |
| 20 |
%1 = fir.rebox_assumed_rank %arg0 lbs preserve : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.heap<!fir.array<*:f32>>> |
| 21 |
fir.call @somefuncalloc(%1) : (!fir.box<!fir.heap<!fir.array<*:f32>>>) -> () |
| 22 |
return |
| 23 |
} |
| 24 |
func.func @test_pointer(%arg0: !fir.box<!fir.array<*:f32>> ) { |
| 25 |
%1 = fir.rebox_assumed_rank %arg0 lbs preserve : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.ptr<!fir.array<*:f32>>> |
| 26 |
fir.call @somefuncpointer(%1) : (!fir.box<!fir.ptr<!fir.array<*:f32>>>) -> () |
| 27 |
return |
| 28 |
} |
| 29 |
!t1= !fir.type<t1{i:i32}> |
| 30 |
!t2= !fir.type<t2{t1:!t1, x:f32}> |
| 31 |
func.func @test_new_dtype(%arg0: !fir.box<!fir.array<*:!t2>> ) { |
| 32 |
%1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.box<!fir.array<*:!t2>>) -> !fir.box<!fir.array<*:!t1>> |
| 33 |
fir.call @somefunct1(%1) : (!fir.box<!fir.array<*:!t1>>) -> () |
| 34 |
return |
| 35 |
} |
| 36 |
|
| 37 |
!sometype = !fir.type<sometype{i:i32}> |
| 38 |
func.func @test_poly_to_nonepoly(%arg0: !fir.class<!fir.array<*:!sometype>>) { |
| 39 |
%1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.class<!fir.array<*:!sometype>>) -> !fir.box<!fir.array<*:!sometype>> |
| 40 |
fir.call @takes_assumed_rank_t(%1) : (!fir.box<!fir.array<*:!sometype>>) -> () |
| 41 |
return |
| 42 |
} |
| 43 |
|
| 44 |
func.func private @somefunc(!fir.box<!fir.array<*:f32>>) |
| 45 |
func.func private @somefuncalloc(!fir.box<!fir.heap<!fir.array<*:f32>>>) |
| 46 |
func.func private @somefuncpointer(!fir.box<!fir.ptr<!fir.array<*:f32>>>) |
| 47 |
func.func private @somefunct1(!fir.box<!fir.array<*:!t1>>) |
| 48 |
func.func private @takes_assumed_rank_t(!fir.box<!fir.array<*:!sometype>>) |
| 49 |
|
| 50 |
// CHECK-LABEL: func.func @test_simple( |
| 51 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>>) { |
| 52 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : i32 |
| 53 |
// CHECK: %[[VAL_2:.*]] = arith.constant 0 : i8 |
| 54 |
// CHECK: %[[VAL_3:.*]] = fir.alloca !fir.box<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>> |
| 55 |
// CHECK: %[[VAL_4:.*]] = fir.zero_bits !fir.ref<none> |
| 56 |
// CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<!fir.box<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>>) -> !fir.ref<!fir.box<none>> |
| 57 |
// CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<*:f32>>) -> !fir.box<none> |
| 58 |
// CHECK: fir.call @_FortranACopyAndUpdateDescriptor(%[[VAL_5]], %[[VAL_6]], %[[VAL_4]], %[[VAL_2]], %[[VAL_1]]) : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<none>, i8, i32) -> () |
| 59 |
// CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_3]] : !fir.ref<!fir.box<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>> |
| 60 |
// CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (!fir.box<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>) -> !fir.box<!fir.array<*:f32>> |
| 61 |
// CHECK: fir.call @somefunc(%[[VAL_9]]) : (!fir.box<!fir.array<*:f32>>) -> () |
| 62 |
// CHECK: return |
| 63 |
// CHECK: } |
| 64 |
|
| 65 |
// CHECK-LABEL: func.func @test_simple_zeroes( |
| 66 |
// CHECK: %[[VAL_1:.*]] = arith.constant 2 : i32 |
| 67 |
// CHECK: fir.call @_FortranACopyAndUpdateDescriptor(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_1]]) |
| 68 |
|
| 69 |
// CHECK-LABEL: func.func @test_simple_preserve( |
| 70 |
// CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32 |
| 71 |
// CHECK: fir.call @_FortranACopyAndUpdateDescriptor(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %[[VAL_1]]) |
| 72 |
|
| 73 |
// CHECK-LABEL: func.func @test_allocatable( |
| 74 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>>) { |
| 75 |
// CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32 |
| 76 |
// CHECK: %[[VAL_2:.*]] = arith.constant 2 : i8 |
| 77 |
// CHECK: %[[VAL_3:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>> |
| 78 |
// CHECK: %[[VAL_4:.*]] = fir.zero_bits !fir.ref<none> |
| 79 |
// CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>>>) -> !fir.ref<!fir.box<none>> |
| 80 |
// CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<*:f32>>) -> !fir.box<none> |
| 81 |
// CHECK: fir.call @_FortranACopyAndUpdateDescriptor(%[[VAL_5]], %[[VAL_6]], %[[VAL_4]], %[[VAL_2]], %[[VAL_1]]) : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<none>, i8, i32) -> () |
| 82 |
// CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_3]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>>> |
| 83 |
// CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (!fir.box<!fir.heap<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>>) -> !fir.box<!fir.heap<!fir.array<*:f32>>> |
| 84 |
// CHECK: fir.call @somefuncalloc(%[[VAL_9]]) : (!fir.box<!fir.heap<!fir.array<*:f32>>>) -> () |
| 85 |
// CHECK: return |
| 86 |
// CHECK: } |
| 87 |
|
| 88 |
// CHECK-LABEL: func.func @test_pointer( |
| 89 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>>) { |
| 90 |
// CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32 |
| 91 |
// CHECK: %[[VAL_2:.*]] = arith.constant 1 : i8 |
| 92 |
// CHECK: %[[VAL_3:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>> |
| 93 |
// CHECK: %[[VAL_4:.*]] = fir.zero_bits !fir.ref<none> |
| 94 |
// CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>>>) -> !fir.ref<!fir.box<none>> |
| 95 |
// CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<*:f32>>) -> !fir.box<none> |
| 96 |
// CHECK: fir.call @_FortranACopyAndUpdateDescriptor(%[[VAL_5]], %[[VAL_6]], %[[VAL_4]], %[[VAL_2]], %[[VAL_1]]) : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<none>, i8, i32) -> () |
| 97 |
// CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_3]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>>> |
| 98 |
// CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (!fir.box<!fir.ptr<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?xf32>>>) -> !fir.box<!fir.ptr<!fir.array<*:f32>>> |
| 99 |
// CHECK: fir.call @somefuncpointer(%[[VAL_9]]) : (!fir.box<!fir.ptr<!fir.array<*:f32>>>) -> () |
| 100 |
// CHECK: return |
| 101 |
// CHECK: } |
| 102 |
|
| 103 |
// CHECK-LABEL: func.func @test_new_dtype( |
| 104 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:!fir.type<t2{t1:!fir.type<t1{i:i32}>,x:f32}>>>) { |
| 105 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : i32 |
| 106 |
// CHECK: %[[VAL_2:.*]] = arith.constant 0 : i8 |
| 107 |
// CHECK: %[[VAL_3:.*]] = fir.alloca !fir.box<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?x!fir.type<t1{i:i32}>>> |
| 108 |
// CHECK: %[[VAL_4:.*]] = fir.type_desc !fir.type<t1{i:i32}> |
| 109 |
// CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<!fir.box<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?x!fir.type<t1{i:i32}>>>>) -> !fir.ref<!fir.box<none>> |
| 110 |
// CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<*:!fir.type<t2{t1:!fir.type<t1{i:i32}>,x:f32}>>>) -> !fir.box<none> |
| 111 |
// CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]] : (!fir.tdesc<!fir.type<t1{i:i32}>>) -> !fir.ref<none> |
| 112 |
// CHECK: fir.call @_FortranACopyAndUpdateDescriptor(%[[VAL_5]], %[[VAL_6]], %[[VAL_7]], %[[VAL_2]], %[[VAL_1]]) : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<none>, i8, i32) -> () |
| 113 |
// CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_3]] : !fir.ref<!fir.box<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?x!fir.type<t1{i:i32}>>>> |
| 114 |
// CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (!fir.box<!fir.array<?x?x?x?x?x?x?x?x?x?x?x?x?x?x?x!fir.type<t1{i:i32}>>>) -> !fir.box<!fir.array<*:!fir.type<t1{i:i32}>>> |
| 115 |
// CHECK: fir.call @somefunct1(%[[VAL_10]]) : (!fir.box<!fir.array<*:!fir.type<t1{i:i32}>>>) -> () |
| 116 |
// CHECK: return |
| 117 |
// CHECK: } |
| 118 |
|
| 119 |
// CHECK-LABEL: func.func @test_poly_to_nonepoly( |
| 120 |
// CHECK: %[[VAL_4:.*]] = fir.type_desc !fir.type<sometype{i:i32}> |
| 121 |
// CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]] : (!fir.tdesc<!fir.type<sometype{i:i32}>>) -> !fir.ref<none> |
| 122 |
// CHECK: fir.call @_FortranACopyAndUpdateDescriptor(%{{.*}}, %{{.*}}, %[[VAL_7]], |
| 123 |
|
| 124 |
// CHECK: func.func private @_FortranACopyAndUpdateDescriptor(!fir.ref<!fir.box<none>> {llvm.nocapture}, !fir.box<none> {llvm.nocapture}, !fir.ref<none>, i8, i32) attributes {fir.runtime} |