Skip to content

Commit 0235cd7

Browse files
[MLIR,Flang,OpenMP] Remove usage of getElementType in OpenMPTranslation (#69772)
Remove usage of getElementType in OpenMPTranslation to pave way for switching to opaque pointers in MLIR and Flang. The approach chosen stores the elementType in a new field in MapInfo called varType. A similar approach was chosen for AtomicReadOp in 81767f5
1 parent dc9ed44 commit 0235cd7

18 files changed

+154
-122
lines changed

flang/lib/Lower/OpenMP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,8 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
16751675

16761676
mlir::omp::MapInfoOp op =
16771677
builder.create<mlir::omp::MapInfoOp>(loc, retTy, baseAddr);
1678+
op.setVarTypeAttr(mlir::TypeAttr::get(
1679+
llvm::dyn_cast<mlir::omp::PointerLikeType>(retTy).getElementType()));
16781680
op.setNameAttr(builder.getStringAttr(name.str()));
16791681
op.setImplicit(implicit);
16801682
op.setMapType(mapType);

flang/test/Fir/convert-to-llvm-openmp-and-fir.fir

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -232,38 +232,38 @@ func.func @_QPomp_target_data() {
232232
%c0 = arith.constant 0 : index
233233
%4 = arith.subi %c1024, %c1 : index
234234
%5 = omp.bounds lower_bound(%c0 : index) upper_bound(%4 : index) extent(%c1024 : index) stride(%c1 : index) start_idx(%c1 : index)
235-
%6 = omp.map_info var_ptr(%0 : !fir.ref<!fir.array<1024xi32>>) map_clauses(to) capture(ByRef) bounds(%5) -> !fir.ref<!fir.array<1024xi32>> {name = "a"}
235+
%6 = omp.map_info var_ptr(%0 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(to) capture(ByRef) bounds(%5) -> !fir.ref<!fir.array<1024xi32>> {name = "a"}
236236
%c1_3 = arith.constant 1 : index
237237
%c0_4 = arith.constant 0 : index
238238
%7 = arith.subi %c1024_0, %c1_3 : index
239239
%8 = omp.bounds lower_bound(%c0_4 : index) upper_bound(%7 : index) extent(%c1024_0 : index) stride(%c1_3 : index) start_idx(%c1_3 : index)
240-
%9 = omp.map_info var_ptr(%1 : !fir.ref<!fir.array<1024xi32>>) map_clauses(to) capture(ByRef) bounds(%8) -> !fir.ref<!fir.array<1024xi32>> {name = "b"}
240+
%9 = omp.map_info var_ptr(%1 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(to) capture(ByRef) bounds(%8) -> !fir.ref<!fir.array<1024xi32>> {name = "b"}
241241
%c1_5 = arith.constant 1 : index
242242
%c0_6 = arith.constant 0 : index
243243
%10 = arith.subi %c1024_1, %c1_5 : index
244244
%11 = omp.bounds lower_bound(%c0_6 : index) upper_bound(%10 : index) extent(%c1024_1 : index) stride(%c1_5 : index) start_idx(%c1_5 : index)
245-
%12 = omp.map_info var_ptr(%2 : !fir.ref<!fir.array<1024xi32>>) map_clauses(always, exit_release_or_enter_alloc) capture(ByRef) bounds(%11) -> !fir.ref<!fir.array<1024xi32>> {name = "c"}
245+
%12 = omp.map_info var_ptr(%2 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(always, exit_release_or_enter_alloc) capture(ByRef) bounds(%11) -> !fir.ref<!fir.array<1024xi32>> {name = "c"}
246246
omp.target_enter_data map_entries(%6, %9, %12 : !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>)
247247
%c1_7 = arith.constant 1 : index
248248
%c0_8 = arith.constant 0 : index
249249
%13 = arith.subi %c1024, %c1_7 : index
250250
%14 = omp.bounds lower_bound(%c0_8 : index) upper_bound(%13 : index) extent(%c1024 : index) stride(%c1_7 : index) start_idx(%c1_7 : index)
251-
%15 = omp.map_info var_ptr(%0 : !fir.ref<!fir.array<1024xi32>>) map_clauses(from) capture(ByRef) bounds(%14) -> !fir.ref<!fir.array<1024xi32>> {name = "a"}
251+
%15 = omp.map_info var_ptr(%0 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(from) capture(ByRef) bounds(%14) -> !fir.ref<!fir.array<1024xi32>> {name = "a"}
252252
%c1_9 = arith.constant 1 : index
253253
%c0_10 = arith.constant 0 : index
254254
%16 = arith.subi %c1024_0, %c1_9 : index
255255
%17 = omp.bounds lower_bound(%c0_10 : index) upper_bound(%16 : index) extent(%c1024_0 : index) stride(%c1_9 : index) start_idx(%c1_9 : index)
256-
%18 = omp.map_info var_ptr(%1 : !fir.ref<!fir.array<1024xi32>>) map_clauses(from) capture(ByRef) bounds(%17) -> !fir.ref<!fir.array<1024xi32>> {name = "b"}
256+
%18 = omp.map_info var_ptr(%1 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(from) capture(ByRef) bounds(%17) -> !fir.ref<!fir.array<1024xi32>> {name = "b"}
257257
%c1_11 = arith.constant 1 : index
258258
%c0_12 = arith.constant 0 : index
259259
%19 = arith.subi %c1024_1, %c1_11 : index
260260
%20 = omp.bounds lower_bound(%c0_12 : index) upper_bound(%19 : index) extent(%c1024_1 : index) stride(%c1_11 : index) start_idx(%c1_11 : index)
261-
%21 = omp.map_info var_ptr(%2 : !fir.ref<!fir.array<1024xi32>>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%20) -> !fir.ref<!fir.array<1024xi32>> {name = "c"}
261+
%21 = omp.map_info var_ptr(%2 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%20) -> !fir.ref<!fir.array<1024xi32>> {name = "c"}
262262
%c1_13 = arith.constant 1 : index
263263
%c0_14 = arith.constant 0 : index
264264
%22 = arith.subi %c1024_2, %c1_13 : index
265265
%23 = omp.bounds lower_bound(%c0_14 : index) upper_bound(%22 : index) extent(%c1024_2 : index) stride(%c1_13 : index) start_idx(%c1_13 : index)
266-
%24 = omp.map_info var_ptr(%3 : !fir.ref<!fir.array<1024xi32>>) map_clauses(always, delete) capture(ByRef) bounds(%23) -> !fir.ref<!fir.array<1024xi32>> {name = "d"}
266+
%24 = omp.map_info var_ptr(%3 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(always, delete) capture(ByRef) bounds(%23) -> !fir.ref<!fir.array<1024xi32>> {name = "d"}
267267
omp.target_exit_data map_entries(%15, %18, %21, %24 : !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>)
268268
return
269269
}
@@ -285,38 +285,38 @@ func.func @_QPomp_target_data() {
285285
// CHECK: %13 = llvm.mlir.constant(0 : index) : i64
286286
// CHECK: %14 = llvm.mlir.constant(1023 : index) : i64
287287
// CHECK: %15 = omp.bounds lower_bound(%13 : i64) upper_bound(%14 : i64) extent(%0 : i64) stride(%12 : i64) start_idx(%12 : i64)
288-
// CHECK: %16 = omp.map_info var_ptr(%[[VAL_1]] : !llvm.ptr<array<1024 x i32>>) map_clauses(to) capture(ByRef) bounds(%15) -> !llvm.ptr<array<1024 x i32>> {name = "a"}
288+
// CHECK: %16 = omp.map_info var_ptr(%[[VAL_1]] : !llvm.ptr<array<1024 x i32>>, !llvm.array<1024 x i32>) map_clauses(to) capture(ByRef) bounds(%15) -> !llvm.ptr<array<1024 x i32>> {name = "a"}
289289
// CHECK: %17 = llvm.mlir.constant(1 : index) : i64
290290
// CHECK: %18 = llvm.mlir.constant(0 : index) : i64
291291
// CHECK: %19 = llvm.mlir.constant(1023 : index) : i64
292292
// CHECK: %20 = omp.bounds lower_bound(%18 : i64) upper_bound(%19 : i64) extent(%3 : i64) stride(%17 : i64) start_idx(%17 : i64)
293-
// CHECK: %21 = omp.map_info var_ptr(%[[VAL_3]] : !llvm.ptr<array<1024 x i32>>) map_clauses(to) capture(ByRef) bounds(%20) -> !llvm.ptr<array<1024 x i32>> {name = "b"}
293+
// CHECK: %21 = omp.map_info var_ptr(%[[VAL_3]] : !llvm.ptr<array<1024 x i32>>, !llvm.array<1024 x i32>) map_clauses(to) capture(ByRef) bounds(%20) -> !llvm.ptr<array<1024 x i32>> {name = "b"}
294294
// CHECK: %22 = llvm.mlir.constant(1 : index) : i64
295295
// CHECK: %23 = llvm.mlir.constant(0 : index) : i64
296296
// CHECK: %24 = llvm.mlir.constant(1023 : index) : i64
297297
// CHECK: %25 = omp.bounds lower_bound(%23 : i64) upper_bound(%24 : i64) extent(%6 : i64) stride(%22 : i64) start_idx(%22 : i64)
298-
// CHECK: %26 = omp.map_info var_ptr(%[[VAL_5]] : !llvm.ptr<array<1024 x i32>>) map_clauses(always, exit_release_or_enter_alloc) capture(ByRef) bounds(%25) -> !llvm.ptr<array<1024 x i32>> {name = "c"}
298+
// CHECK: %26 = omp.map_info var_ptr(%[[VAL_5]] : !llvm.ptr<array<1024 x i32>>, !llvm.array<1024 x i32>) map_clauses(always, exit_release_or_enter_alloc) capture(ByRef) bounds(%25) -> !llvm.ptr<array<1024 x i32>> {name = "c"}
299299
// CHECK: omp.target_enter_data map_entries(%16, %21, %26 : !llvm.ptr<array<1024 x i32>>, !llvm.ptr<array<1024 x i32>>, !llvm.ptr<array<1024 x i32>>)
300300
// CHECK: %27 = llvm.mlir.constant(1 : index) : i64
301301
// CHECK: %28 = llvm.mlir.constant(0 : index) : i64
302302
// CHECK: %29 = llvm.mlir.constant(1023 : index) : i64
303303
// CHECK: %30 = omp.bounds lower_bound(%28 : i64) upper_bound(%29 : i64) extent(%0 : i64) stride(%27 : i64) start_idx(%27 : i64)
304-
// CHECK: %31 = omp.map_info var_ptr(%[[VAL_1]] : !llvm.ptr<array<1024 x i32>>) map_clauses(from) capture(ByRef) bounds(%30) -> !llvm.ptr<array<1024 x i32>> {name = "a"}
304+
// CHECK: %31 = omp.map_info var_ptr(%[[VAL_1]] : !llvm.ptr<array<1024 x i32>>, !llvm.array<1024 x i32>) map_clauses(from) capture(ByRef) bounds(%30) -> !llvm.ptr<array<1024 x i32>> {name = "a"}
305305
// CHECK: %32 = llvm.mlir.constant(1 : index) : i64
306306
// CHECK: %33 = llvm.mlir.constant(0 : index) : i64
307307
// CHECK: %34 = llvm.mlir.constant(1023 : index) : i64
308308
// CHECK: %35 = omp.bounds lower_bound(%33 : i64) upper_bound(%34 : i64) extent(%3 : i64) stride(%32 : i64) start_idx(%32 : i64)
309-
// CHECK: %36 = omp.map_info var_ptr(%[[VAL_3]] : !llvm.ptr<array<1024 x i32>>) map_clauses(from) capture(ByRef) bounds(%35) -> !llvm.ptr<array<1024 x i32>> {name = "b"}
309+
// CHECK: %36 = omp.map_info var_ptr(%[[VAL_3]] : !llvm.ptr<array<1024 x i32>>, !llvm.array<1024 x i32>) map_clauses(from) capture(ByRef) bounds(%35) -> !llvm.ptr<array<1024 x i32>> {name = "b"}
310310
// CHECK: %37 = llvm.mlir.constant(1 : index) : i64
311311
// CHECK: %38 = llvm.mlir.constant(0 : index) : i64
312312
// CHECK: %39 = llvm.mlir.constant(1023 : index) : i64
313313
// CHECK: %40 = omp.bounds lower_bound(%38 : i64) upper_bound(%39 : i64) extent(%6 : i64) stride(%37 : i64) start_idx(%37 : i64)
314-
// CHECK: %41 = omp.map_info var_ptr(%[[VAL_5]] : !llvm.ptr<array<1024 x i32>>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%40) -> !llvm.ptr<array<1024 x i32>> {name = "c"}
314+
// CHECK: %41 = omp.map_info var_ptr(%[[VAL_5]] : !llvm.ptr<array<1024 x i32>>, !llvm.array<1024 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%40) -> !llvm.ptr<array<1024 x i32>> {name = "c"}
315315
// CHECK: %42 = llvm.mlir.constant(1 : index) : i64
316316
// CHECK: %43 = llvm.mlir.constant(0 : index) : i64
317317
// CHECK: %44 = llvm.mlir.constant(1023 : index) : i64
318318
// CHECK: %45 = omp.bounds lower_bound(%43 : i64) upper_bound(%44 : i64) extent(%9 : i64) stride(%42 : i64) start_idx(%42 : i64)
319-
// CHECK: %46 = omp.map_info var_ptr(%[[VAL_7]] : !llvm.ptr<array<1024 x i32>>) map_clauses(always, delete) capture(ByRef) bounds(%45) -> !llvm.ptr<array<1024 x i32>> {name = "d"}
319+
// CHECK: %46 = omp.map_info var_ptr(%[[VAL_7]] : !llvm.ptr<array<1024 x i32>>, !llvm.array<1024 x i32>) map_clauses(always, delete) capture(ByRef) bounds(%45) -> !llvm.ptr<array<1024 x i32>> {name = "d"}
320320
// CHECK: omp.target_exit_data map_entries(%31, %36, %41, %46 : !llvm.ptr<array<1024 x i32>>, !llvm.ptr<array<1024 x i32>>, !llvm.ptr<array<1024 x i32>>, !llvm.ptr<array<1024 x i32>>)
321321
// CHECK: llvm.return
322322
// CHECK: }
@@ -331,7 +331,7 @@ func.func @_QPopenmp_target_data_region() {
331331
%c0 = arith.constant 0 : index
332332
%c2 = arith.subi %c1024, %c3 : index
333333
%bound = omp.bounds lower_bound(%c0 : index) upper_bound(%c2 : index) extent(%c1024 : index) stride(%c3 : index) start_idx(%c3 : index)
334-
%entry = omp.map_info var_ptr(%0 : !fir.ref<!fir.array<1024xi32>>) map_clauses(tofrom) capture(ByRef) bounds(%bound) -> !fir.ref<!fir.array<1024xi32>> {name = "a"}
334+
%entry = omp.map_info var_ptr(%0 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(tofrom) capture(ByRef) bounds(%bound) -> !fir.ref<!fir.array<1024xi32>> {name = "a"}
335335
omp.target_data map_entries(%entry : !fir.ref<!fir.array<1024xi32>>) {
336336
%c1_i32 = arith.constant 1 : i32
337337
%2 = fir.convert %c1_i32 : (i32) -> index
@@ -370,7 +370,7 @@ func.func @_QPopenmp_target_data_region() {
370370
// CHECK: %[[VAL_ZERO:.*]] = llvm.mlir.constant(0 : index) : i64
371371
// CHECK: %[[VAL_UPPER:.*]] = llvm.mlir.constant(1023 : index) : i64
372372
// CHECK: %[[VAL_BOUNDS:.*]] = omp.bounds lower_bound(%[[VAL_ZERO]] : i64) upper_bound(%[[VAL_UPPER]] : i64) extent(%[[VAL_MAX]] : i64) stride(%[[VAL_ONE]] : i64) start_idx(%[[VAL_ONE]] : i64)
373-
// CHECK: %[[VAL_MAP:.*]] = omp.map_info var_ptr(%[[VAL_1]] : !llvm.ptr<array<1024 x i32>>) map_clauses(tofrom) capture(ByRef) bounds(%[[VAL_BOUNDS]]) -> !llvm.ptr<array<1024 x i32>> {name = "a"}
373+
// CHECK: %[[VAL_MAP:.*]] = omp.map_info var_ptr(%[[VAL_1]] : !llvm.ptr<array<1024 x i32>>, !llvm.array<1024 x i32>) map_clauses(tofrom) capture(ByRef) bounds(%[[VAL_BOUNDS]]) -> !llvm.ptr<array<1024 x i32>> {name = "a"}
374374
// CHECK: omp.target_data map_entries(%[[VAL_MAP]] : !llvm.ptr<array<1024 x i32>>) {
375375
// CHECK: %[[VAL_4:.*]] = llvm.mlir.constant(1 : i32) : i32
376376
// CHECK: %[[VAL_5:.*]] = llvm.sext %[[VAL_4]] : i32 to i64
@@ -432,7 +432,7 @@ func.func @_QPomp_target() {
432432
%c0 = arith.constant 0 : index
433433
%1 = arith.subi %c512, %c1 : index
434434
%2 = omp.bounds lower_bound(%c0 : index) upper_bound(%1 : index) extent(%c512 : index) stride(%c1 : index) start_idx(%c1 : index)
435-
%3 = omp.map_info var_ptr(%0 : !fir.ref<!fir.array<512xi32>>) map_clauses(tofrom) capture(ByRef) bounds(%2) -> !fir.ref<!fir.array<512xi32>> {name = "a"}
435+
%3 = omp.map_info var_ptr(%0 : !fir.ref<!fir.array<512xi32>>, !fir.array<512xi32>) map_clauses(tofrom) capture(ByRef) bounds(%2) -> !fir.ref<!fir.array<512xi32>> {name = "a"}
436436
omp.target thread_limit(%c64_i32 : i32) map_entries(%3 : !fir.ref<!fir.array<512xi32>>) {
437437
%c10_i32 = arith.constant 10 : i32
438438
%c1_i64 = arith.constant 1 : i64
@@ -454,7 +454,7 @@ func.func @_QPomp_target() {
454454
// CHECK: %[[LOWER:.*]] = llvm.mlir.constant(0 : index) : i64
455455
// CHECK: %[[UPPER:.*]] = llvm.mlir.constant(511 : index) : i64
456456
// CHECK: %[[BOUNDS:.*]] = omp.bounds lower_bound(%[[LOWER]] : i64) upper_bound(%[[UPPER]] : i64) extent(%[[EXTENT]] : i64) stride(%[[STRIDE]] : i64) start_idx(%[[STRIDE]] : i64)
457-
// CHECK: %[[MAP:.*]] = omp.map_info var_ptr(%2 : !llvm.ptr<array<512 x i32>>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !llvm.ptr<array<512 x i32>> {name = "a"}
457+
// CHECK: %[[MAP:.*]] = omp.map_info var_ptr(%2 : !llvm.ptr<array<512 x i32>>, !llvm.array<512 x i32>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !llvm.ptr<array<512 x i32>> {name = "a"}
458458
// CHECK: omp.target thread_limit(%[[VAL_2]] : i32) map_entries(%[[MAP]] : !llvm.ptr<array<512 x i32>>) {
459459
// CHECK: %[[VAL_3:.*]] = llvm.mlir.constant(10 : i32) : i32
460460
// CHECK: %[[VAL_4:.*]] = llvm.mlir.constant(1 : i64) : i64

0 commit comments

Comments
 (0)