6
6
! CHECK-SAME: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
7
7
subroutine test_assumed_shape_to_array (x )
8
8
real :: x(:)
9
+
10
+ ! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
11
+ ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) : (!fir.box<none>) -> i1
12
+ ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]] -> (!fir.heap<!fir.array<?xf32>>) {
13
+ ! CHECK: %[[box_addr:.*]] = fir.box_addr %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.heap<!fir.array<?xf32>>
14
+ ! CHECK: fir.result %[[box_addr]] : !fir.heap<!fir.array<?xf32>>
15
+ ! CHECK: } else {
9
16
! Creating temp
10
17
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x:.*]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
11
18
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1 {uniq_name = ".copyinout"}
@@ -20,23 +27,26 @@ subroutine test_assumed_shape_to_array(x)
20
27
! CHECK: fir.result %[[update]] : !fir.array<?xf32>
21
28
! CHECK: }
22
29
! CHECK: fir.array_merge_store %[[temp_load]], %[[copyin:.*]] to %[[temp]] : !fir.array<?xf32>, !fir.array<?xf32>, !fir.heap<!fir.array<?xf32>>
30
+ ! CHECK: fir.result %[[temp]] : !fir.heap<!fir.array<?xf32>>
23
31
24
- ! CHECK: %[[cast:.*]] = fir.convert %[[temp]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
32
+ ! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
33
+ ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
25
34
! CHECK: fir.call @_QPbar(%[[cast]]) : (!fir.ref<!fir.array<?xf32>>) -> ()
26
35
27
36
! Copy-out
28
-
29
37
! CHECK-DAG: %[[x_load:.*]] = fir.array_load %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.array<?xf32>
38
+ ! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : index
39
+
30
40
! CHECK-DAG: %[[shape:.*]] = fir.shape %[[dim]]#1 : (index) -> !fir.shape<1>
31
- ! CHECK-DAG: %[[temp_load:.*]] = fir.array_load %[[temp ]](%[[shape]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.array<?xf32>
41
+ ! CHECK-DAG: %[[temp_load:.*]] = fir.array_load %[[addr ]](%[[shape]]) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.array<?xf32>
32
42
! CHECK: %[[copyout:.*]] = fir.do_loop %[[i:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[res:.*]] = %[[x_load]]) -> (!fir.array<?xf32>) {
33
43
! CHECK: %[[fetch:.*]] = fir.array_fetch %[[temp_load]], %[[i]] : (!fir.array<?xf32>, index) -> f32
34
44
! CHECK: %[[update:.*]] = fir.array_update %[[res]], %[[fetch]], %[[i]] : (!fir.array<?xf32>, f32, index) -> !fir.array<?xf32>
35
45
! CHECK: fir.result %[[update]] : !fir.array<?xf32>
36
46
! CHECK: }
37
47
! CHECK: fir.array_merge_store %[[x_load]], %[[copyout:.*]] to %[[x]] : !fir.array<?xf32>, !fir.array<?xf32>, !fir.box<!fir.array<?xf32>>
38
48
39
- ! CHECK: fir.freemem %[[temp ]] : !fir.heap<!fir.array<?xf32>>
49
+ ! CHECK: fir.freemem %[[addr ]] : !fir.heap<!fir.array<?xf32>>
40
50
41
51
call bar(x)
42
52
end subroutine
@@ -50,19 +60,24 @@ subroutine eval_expr_only_once(x)
50
60
real :: x(200 )
51
61
! CHECK: fir.call @_QPonly_once()
52
62
! CHECK: %[[x_section:.*]] = fir.embox %[[x]](%{{.*}}) [%{{.*}}] : (!fir.ref<!fir.array<200xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
63
+ ! CHECK: %[[box_none:.*]] = fir.convert %[[x_section]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
64
+ ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) : (!fir.box<none>) -> i1
65
+ ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]] -> (!fir.heap<!fir.array<?xf32>>) {
66
+
53
67
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>
54
68
! CHECK-NOT: fir.call @_QPonly_once()
55
69
! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %[[temp]]
56
70
! CHECK-NOT: fir.call @_QPonly_once()
57
71
58
- ! CHECK: %[[cast:.*]] = fir.convert %[[temp ]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
72
+ ! CHECK: %[[cast:.*]] = fir.convert %[[addr ]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
59
73
! CHECK: fir.call @_QPbar(%[[cast]]) : (!fir.ref<!fir.array<?xf32>>) -> ()
60
74
call bar(x(1 :200 :only_once()))
61
75
62
76
! CHECK-NOT: fir.call @_QPonly_once()
63
77
! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %[[x_section]]
64
78
! CHECK-NOT: fir.call @_QPonly_once()
65
- ! CHECK: fir.freemem %[[temp]] : !fir.heap<!fir.array<?xf32>>
79
+
80
+ ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
66
81
end subroutine
67
82
68
83
! Test no copy-in/copy-out is generated for contiguous assumed shapes.
@@ -104,19 +119,26 @@ subroutine bar_intent_out(x)
104
119
real , intent (out ) :: x(100 )
105
120
end subroutine
106
121
end interface
122
+ ! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
123
+ ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) : (!fir.box<none>) -> i1
124
+ ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]]
125
+ ! CHECK: } else {
107
126
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
108
127
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1
109
128
! CHECK-NOT: fir.array_merge_store
110
- ! CHECK: %[[cast:.*]] = fir.convert %[[temp]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>>
129
+ ! CHECK: %[[not_contiguous:.*]] = arith.cmpi eq, %[[is_contiguous]], %false{{.*}} : i1
130
+ ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>>
111
131
! CHECK: fir.call @_QPbar_intent_out(%[[cast]]) : (!fir.ref<!fir.array<100xf32>>) -> ()
112
132
call bar_intent_out(x)
113
- ! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %[[x]]
114
- ! CHECK: fir.freemem %[[temp]] : !fir.heap<!fir.array<?xf32>>
133
+
134
+ ! CHECK: fir.if %[[not_contiguous]]
135
+ ! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %[[x]]
136
+ ! CHECK: fir.freemem %[[addr]] : !fir.heap<!fir.array<?xf32>>
115
137
! CHECK: return
116
138
end subroutine
117
139
118
140
! Test copy-out is skipped for intent(out) arguments.
119
- ! CHECK: func @_QPtest_intent_in(
141
+ ! CHECK-LABEL: func. func @_QPtest_intent_in(
120
142
! CHECK: %[[x:.*]]: !fir.box<!fir.array<?xf32>>{{.*}}) {
121
143
subroutine test_intent_in (x )
122
144
real :: x(:)
@@ -125,14 +147,20 @@ subroutine bar_intent_in(x)
125
147
real , intent (in ) :: x(100 )
126
148
end subroutine
127
149
end interface
150
+ ! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
151
+ ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) : (!fir.box<none>) -> i1
152
+ ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]]
153
+ ! CHECK: } else {
128
154
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
129
155
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1
130
156
! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %[[temp]]
131
- ! CHECK: %[[cast:.*]] = fir.convert %[[temp]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>>
157
+ ! CHECK: %[[not_contiguous:.*]] = arith.cmpi eq, %[[is_contiguous]], %false{{.*}} : i1
158
+ ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>>
132
159
! CHECK: fir.call @_QPbar_intent_in(%[[cast]]) : (!fir.ref<!fir.array<100xf32>>) -> ()
133
160
call bar_intent_in(x)
161
+ ! CHECK: fir.if %[[not_contiguous]]
134
162
! CHECK-NOT: fir.array_merge_store
135
- ! CHECK: fir.freemem %[[temp ]] : !fir.heap<!fir.array<?xf32>>
163
+ ! CHECK: fir.freemem %[[addr ]] : !fir.heap<!fir.array<?xf32>>
136
164
! CHECK: return
137
165
end subroutine
138
166
@@ -146,14 +174,20 @@ subroutine bar_intent_inout(x)
146
174
real , intent (inout ) :: x(100 )
147
175
end subroutine
148
176
end interface
177
+ ! CHECK: %[[box_none:.*]] = fir.convert %[[x]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none>
178
+ ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) : (!fir.box<none>) -> i1
179
+ ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]]
180
+ ! CHECK: } else {
149
181
! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[x]], %c0{{.*}} : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
150
182
! CHECK: %[[temp:.*]] = fir.allocmem !fir.array<?xf32>, %[[dim]]#1
151
183
! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %[[temp]]
152
- ! CHECK: %[[cast:.*]] = fir.convert %[[temp]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>>
184
+ ! CHECK: %[[not_contiguous:.*]] = arith.cmpi eq, %[[is_contiguous]], %false{{.*}} : i1
185
+ ! CHECK: %[[cast:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?xf32>>) -> !fir.ref<!fir.array<100xf32>>
153
186
! CHECK: fir.call @_QPbar_intent_inout(%[[cast]]) : (!fir.ref<!fir.array<100xf32>>) -> ()
154
187
call bar_intent_inout(x)
188
+ ! CHECK: fir.if %[[not_contiguous]]
155
189
! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %[[x]]
156
- ! CHECK: fir.freemem %[[temp ]] : !fir.heap<!fir.array<?xf32>>
190
+ ! CHECK: fir.freemem %[[addr ]] : !fir.heap<!fir.array<?xf32>>
157
191
! CHECK: return
158
192
end subroutine
159
193
@@ -162,6 +196,10 @@ subroutine bar_intent_inout(x)
162
196
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.char<1,10>>>{{.*}}) {
163
197
subroutine test_char (x )
164
198
! CHECK: %[[VAL_1:.*]] = arith.constant 10 : index
199
+ ! CHECK: %[[box_none:.*]] = fir.convert %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.box<none>
200
+ ! CHECK: %[[is_contiguous:.*]] = fir.call @_FortranAIsContiguous(%[[box_none]]) : (!fir.box<none>) -> i1
201
+ ! CHECK: %[[addr:.*]] = fir.if %[[is_contiguous]]
202
+ ! CHECK: } else {
165
203
! CHECK: %[[VAL_2:.*]] = arith.constant 0 : index
166
204
! CHECK: %[[VAL_3:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_2]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>, index) -> (index, index, index)
167
205
! CHECK: %[[VAL_4:.*]] = fir.allocmem !fir.array<?x!fir.char<1,10>>, %[[VAL_3]]#1 {uniq_name = ".copyinout"}
@@ -186,14 +224,15 @@ subroutine test_char(x)
186
224
! CHECK: fir.result %[[VAL_23]] : !fir.array<?x!fir.char<1,10>>
187
225
! CHECK: }
188
226
! CHECK: fir.array_merge_store %[[VAL_6]], %[[VAL_24:.*]] to %[[VAL_4]] : !fir.array<?x!fir.char<1,10>>, !fir.array<?x!fir.char<1,10>>, !fir.heap<!fir.array<?x!fir.char<1,10>>>
189
- ! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_4]] : (!fir.heap<!fir.array<?x!fir.char<1,10>>>) -> !fir.ref<!fir.char<1,?>>
227
+ ! CHECK: %[[dim:.*]]:3 = fir.box_dims %[[VAL_0]], %c0{{.*}} : (!fir.box<!fir.array<?x!fir.char<1,10>>>, index) -> (index, index, index)
228
+ ! CHECK: %[[VAL_25:.*]] = fir.convert %[[addr]] : (!fir.heap<!fir.array<?x!fir.char<1,10>>>) -> !fir.ref<!fir.char<1,?>>
190
229
! CHECK: %[[VAL_26:.*]] = fir.emboxchar %[[VAL_25]], %[[VAL_1]] : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
191
230
! CHECK: fir.call @_QPbar_char(%[[VAL_26]]) : (!fir.boxchar<1>) -> ()
192
231
! CHECK: %[[VAL_27:.*]] = fir.array_load %[[VAL_0]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>) -> !fir.array<?x!fir.char<1,10>>
193
232
! CHECK: %[[VAL_28:.*]] = arith.constant 0 : index
194
233
! CHECK: %[[VAL_29:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_28]] : (!fir.box<!fir.array<?x!fir.char<1,10>>>, index) -> (index, index, index)
195
- ! CHECK: %[[VAL_30:.*]] = fir.shape %[[VAL_3 ]]#1 : (index) -> !fir.shape<1>
196
- ! CHECK: %[[VAL_31:.*]] = fir.array_load %[[VAL_4 ]](%[[VAL_30]]) : (!fir.heap<!fir.array<?x!fir.char<1,10>>>, !fir.shape<1>) -> !fir.array<?x!fir.char<1,10>>
234
+ ! CHECK: %[[VAL_30:.*]] = fir.shape %[[dim ]]#1 : (index) -> !fir.shape<1>
235
+ ! CHECK: %[[VAL_31:.*]] = fir.array_load %[[addr ]](%[[VAL_30]]) : (!fir.heap<!fir.array<?x!fir.char<1,10>>>, !fir.shape<1>) -> !fir.array<?x!fir.char<1,10>>
197
236
! CHECK: %[[VAL_32:.*]] = arith.constant 1 : index
198
237
! CHECK: %[[VAL_33:.*]] = arith.constant 0 : index
199
238
! CHECK: %[[VAL_34:.*]] = arith.subi %[[VAL_29]]#1, %[[VAL_32]] : index
@@ -212,7 +251,7 @@ subroutine test_char(x)
212
251
! CHECK: fir.result %[[VAL_47]] : !fir.array<?x!fir.char<1,10>>
213
252
! CHECK: }
214
253
! CHECK: fir.array_merge_store %[[VAL_27]], %[[VAL_48:.*]] to %[[VAL_0]] : !fir.array<?x!fir.char<1,10>>, !fir.array<?x!fir.char<1,10>>, !fir.box<!fir.array<?x!fir.char<1,10>>>
215
- ! CHECK: fir.freemem %[[VAL_4 ]] : !fir.heap<!fir.array<?x!fir.char<1,10>>>
254
+ ! CHECK: fir.freemem %[[addr ]] : !fir.heap<!fir.array<?x!fir.char<1,10>>>
216
255
217
256
character (10 ) :: x(:)
218
257
call bar_char(x)
0 commit comments