Skip to content

Commit 72e2387

Browse files
committed
[OpenMP][MLIR] Add "IsolatedFromAbove" trait to omp.target
This patch adds the MLIR translation changes required for add the IsolatedFromAbove and OutlineableOpenMPOpInterface traits to omp.target. It links the newly added block arguments to their corresponding llvm values. Depends on #67164.
1 parent fbaf2c6 commit 72e2387

13 files changed

+156
-61
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,23 +1733,28 @@ void collectMapDataFromMapOperands(MapInfoData &mapData,
17331733
"missing map info operation or incorrect map info operation type");
17341734
if (auto mapOp = mlir::dyn_cast_if_present<mlir::omp::MapInfoOp>(
17351735
mapValue.getDefiningOp())) {
1736-
mapData.OriginalValue.push_back(
1737-
moduleTranslation.lookupValue(mapOp.getVarPtr()));
1736+
mapData.OriginalValue.push_back(moduleTranslation.lookupValue(
1737+
mapOp.getVarPtr() ? mapOp.getVarPtr() : mapOp.getVal()));
17381738
mapData.Pointers.push_back(mapData.OriginalValue.back());
17391739

17401740
if (llvm::Value *refPtr = getRefPtrIfDeclareTarget(
1741-
mapOp.getVarPtr(), moduleTranslation)) { // declare target
1741+
mapOp.getVarPtr() ? mapOp.getVarPtr() : mapOp.getVal(),
1742+
moduleTranslation)) { // declare target
17421743
mapData.IsDeclareTarget.push_back(true);
17431744
mapData.BasePointers.push_back(refPtr);
17441745
} else { // regular mapped variable
17451746
mapData.IsDeclareTarget.push_back(false);
17461747
mapData.BasePointers.push_back(mapData.OriginalValue.back());
17471748
}
17481749

1749-
mapData.Sizes.push_back(getSizeInBytes(dl, mapOp.getVarType(), mapOp,
1750-
builder, moduleTranslation));
1751-
mapData.BaseType.push_back(
1752-
moduleTranslation.convertType(mapOp.getVarType()));
1750+
mapData.Sizes.push_back(
1751+
getSizeInBytes(dl,
1752+
mapOp.getVal() ? mapOp.getVal().getType()
1753+
: mapOp.getVarType().value(),
1754+
mapOp, builder, moduleTranslation));
1755+
mapData.BaseType.push_back(moduleTranslation.convertType(
1756+
mapOp.getVal() ? mapOp.getVal().getType()
1757+
: mapOp.getVarType().value()));
17531758
mapData.MapClause.push_back(mapOp.getOperation());
17541759
mapData.Types.push_back(
17551760
llvm::omp::OpenMPOffloadMappingFlags(mapOp.getMapType().value()));
@@ -1796,6 +1801,13 @@ static void genMapInfos(llvm::IRBuilderBase &builder,
17961801
else if (isTargetParams)
17971802
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TARGET_PARAM;
17981803

1804+
if (auto mapInfoOp = dyn_cast<mlir::omp::MapInfoOp>(mapData.MapClause[i]))
1805+
if (mapInfoOp.getMapCaptureType().value() ==
1806+
mlir::omp::VariableCaptureKind::ByCopy &&
1807+
!(mapInfoOp.getVarType().has_value() &&
1808+
mapInfoOp.getVarType()->isa<LLVM::LLVMPointerType>()))
1809+
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_LITERAL;
1810+
17991811
combinedInfo.BasePointers.emplace_back(mapData.BasePointers[i]);
18001812
combinedInfo.Pointers.emplace_back(mapData.Pointers[i]);
18011813
combinedInfo.DevicePointers.emplace_back(mapData.DevicePointers[i]);
@@ -2318,13 +2330,36 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
23182330

23192331
auto targetOp = cast<omp::TargetOp>(opInst);
23202332
auto &targetRegion = targetOp.getRegion();
2333+
DataLayout dl = DataLayout(opInst.getParentOfType<ModuleOp>());
2334+
SmallVector<Value> mapOperands = targetOp.getMapOperands();
2335+
2336+
// Remove mapOperands/blockArgs that have no use inside the region.
2337+
assert(mapOperands.size() == targetRegion.getNumArguments() &&
2338+
"Number of mapOperands must be same as block_arguments");
2339+
for (size_t i = 0; i < mapOperands.size(); i++) {
2340+
if (targetRegion.getArgument(i).use_empty()) {
2341+
targetRegion.eraseArgument(i);
2342+
mapOperands.erase(&mapOperands[i]);
2343+
i--;
2344+
}
2345+
}
23212346

23222347
LogicalResult bodyGenStatus = success();
23232348

23242349
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
23252350
auto bodyCB = [&](InsertPointTy allocaIP,
23262351
InsertPointTy codeGenIP) -> InsertPointTy {
23272352
builder.restoreIP(codeGenIP);
2353+
unsigned argIndex = 0;
2354+
for (auto &mapOp : mapOperands) {
2355+
auto mapInfoOp =
2356+
mlir::dyn_cast<mlir::omp::MapInfoOp>(mapOp.getDefiningOp());
2357+
llvm::Value *mapOpValue = moduleTranslation.lookupValue(
2358+
mapInfoOp.getVarPtr() ? mapInfoOp.getVarPtr() : mapInfoOp.getVal());
2359+
const auto &arg = targetRegion.front().getArgument(argIndex);
2360+
moduleTranslation.mapValue(arg, mapOpValue);
2361+
argIndex++;
2362+
}
23282363
llvm::BasicBlock *exitBlock = convertOmpOpRegions(
23292364
targetRegion, "omp.target", builder, moduleTranslation, bodyGenStatus);
23302365
builder.SetInsertPoint(exitBlock);
@@ -2352,8 +2387,6 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
23522387
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
23532388
findAllocaInsertPoint(builder, moduleTranslation);
23542389

2355-
DataLayout dl = DataLayout(opInst.getParentOfType<ModuleOp>());
2356-
llvm::SmallVector<Value> mapOperands = targetOp.getMapOperands();
23572390
MapInfoData mapData;
23582391
collectMapDataFromMapOperands(mapData, mapOperands, moduleTranslation, dl,
23592392
builder);

mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,12 @@ llvm.func @_QPomp_target_data_region(%a : !llvm.ptr, %i : !llvm.ptr) {
244244
// CHECK: %[[ARG_0:.*]]: !llvm.ptr,
245245
// CHECK: %[[ARG_1:.*]]: !llvm.ptr) {
246246
// CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(64 : i32) : i32
247-
// CHECK: %[[MAP:.*]] = omp.map_info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
248-
// CHECK: omp.target thread_limit(%[[VAL_0]] : i32) map_entries(%[[MAP]] : !llvm.ptr) {
247+
// CHECK: %[[MAP1:.*]] = omp.map_info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
248+
// CHECK: %[[MAP2:.*]] = omp.map_info var_ptr(%[[ARG_1]] : !llvm.ptr, i32) map_clauses(implicit, exit_release_or_enter_alloc) capture(ByCopy) -> !llvm.ptr {name = ""}
249+
// CHECK: omp.target thread_limit(%[[VAL_0]] : i32) map_entries(%[[MAP1]] -> %[[BB_ARG0:.*]], %[[MAP2]] -> %[[BB_ARG1:.*]] : !llvm.ptr, !llvm.ptr) {
250+
// CHECK: ^bb0(%[[BB_ARG0]]: !llvm.ptr, %[[BB_ARG1]]: !llvm.ptr):
249251
// CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(10 : i32) : i32
250-
// CHECK: llvm.store %[[VAL_1]], %[[ARG_1]] : i32, !llvm.ptr
252+
// CHECK: llvm.store %[[VAL_1]], %[[BB_ARG1]] : i32, !llvm.ptr
251253
// CHECK: omp.terminator
252254
// CHECK: }
253255
// CHECK: llvm.return
@@ -256,9 +258,11 @@ llvm.func @_QPomp_target_data_region(%a : !llvm.ptr, %i : !llvm.ptr) {
256258
llvm.func @_QPomp_target(%a : !llvm.ptr, %i : !llvm.ptr) {
257259
%0 = llvm.mlir.constant(64 : i32) : i32
258260
%1 = omp.map_info var_ptr(%a : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
259-
omp.target thread_limit(%0 : i32) map_entries(%1 : !llvm.ptr) {
261+
%3 = omp.map_info var_ptr(%i : !llvm.ptr, i32) map_clauses(implicit, exit_release_or_enter_alloc) capture(ByCopy) -> !llvm.ptr {name = ""}
262+
omp.target thread_limit(%0 : i32) map_entries(%1 -> %arg0, %3 -> %arg1 : !llvm.ptr, !llvm.ptr) {
263+
^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):
260264
%2 = llvm.mlir.constant(10 : i32) : i32
261-
llvm.store %2, %i : i32, !llvm.ptr
265+
llvm.store %2, %arg1 : i32, !llvm.ptr
262266
omp.terminator
263267
}
264268
llvm.return
@@ -449,7 +453,8 @@ llvm.func @sub_() {
449453
// CHECK: %[[C_14:.*]] = llvm.mlir.constant(1 : index) : i64
450454
// CHECK: %[[BOUNDS1:.*]] = omp.bounds lower_bound(%[[C_12]] : i64) upper_bound(%[[C_11]] : i64) stride(%[[C_14]] : i64) start_idx(%[[C_14]] : i64)
451455
// CHECK: %[[MAP1:.*]] = omp.map_info var_ptr(%[[ARG_2]] : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS1]]) -> !llvm.ptr {name = ""}
452-
// CHECK: omp.target map_entries(%[[MAP0]], %[[MAP1]] : !llvm.ptr, !llvm.ptr) {
456+
// CHECK: omp.target map_entries(%[[MAP0]] -> %[[BB_ARG0:.*]], %[[MAP1]] -> %[[BB_ARG1:.*]] : !llvm.ptr, !llvm.ptr) {
457+
// CHECK: ^bb0(%[[BB_ARG0]]: !llvm.ptr, %[[BB_ARG1]]: !llvm.ptr):
453458
// CHECK: omp.terminator
454459
// CHECK: }
455460
// CHECK: llvm.return
@@ -468,7 +473,8 @@ llvm.func @_QPtarget_map_with_bounds(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2:
468473
%9 = llvm.mlir.constant(1 : index) : i64
469474
%10 = omp.bounds lower_bound(%7 : i64) upper_bound(%6 : i64) stride(%9 : i64) start_idx(%9 : i64)
470475
%11 = omp.map_info var_ptr(%arg2 : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(tofrom) capture(ByRef) bounds(%10) -> !llvm.ptr {name = ""}
471-
omp.target map_entries(%5, %11 : !llvm.ptr, !llvm.ptr) {
476+
omp.target map_entries(%5 -> %arg3, %11 -> %arg4: !llvm.ptr, !llvm.ptr) {
477+
^bb0(%arg3: !llvm.ptr, %arg4: !llvm.ptr):
472478
omp.terminator
473479
}
474480
llvm.return

mlir/test/Dialect/OpenMP/canonicalize.mlir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ func.func private @foo() -> ()
131131

132132
func.func @constant_hoisting_target(%x : !llvm.ptr) {
133133
omp.target {
134+
^bb0(%arg0: !llvm.ptr):
134135
%c1 = arith.constant 10 : i32
135-
llvm.store %c1, %x : i32, !llvm.ptr
136+
llvm.store %c1, %arg0 : i32, !llvm.ptr
136137
omp.terminator
137138
}
138139
return
@@ -141,4 +142,4 @@ func.func @constant_hoisting_target(%x : !llvm.ptr) {
141142
// CHECK-LABEL: func.func @constant_hoisting_target
142143
// CHECK-NOT: arith.constant
143144
// CHECK: omp.target
144-
// CHECK-NEXT: arith.constant
145+
// CHECK: arith.constant

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,9 @@ func.func @omp_threadprivate() {
16171617
func.func @omp_target(%map1: memref<?xi32>) {
16181618
%mapv = omp.map_info var_ptr(%map1 : memref<?xi32>, tensor<?xi32>) map_clauses(delete) capture(ByRef) -> memref<?xi32> {name = ""}
16191619
// expected-error @below {{to, from, tofrom and alloc map types are permitted}}
1620-
omp.target map_entries(%mapv : memref<?xi32>){}
1620+
omp.target map_entries(%mapv -> %arg0: memref<?xi32>) {
1621+
^bb0(%arg0: memref<?xi32>):
1622+
}
16211623
return
16221624
}
16231625

@@ -1656,4 +1658,40 @@ func.func @omp_target_exit_data(%map1: memref<?xi32>) {
16561658
return
16571659
}
16581660

1661+
// -----
1662+
1663+
func.func @omp_map1(%map1: memref<?xi32>, %map2: i32) {
1664+
%mapv = omp.map_info var_ptr(%map1 : memref<?xi32>, tensor<?xi32>) val(%map2 : i32) map_clauses(tofrom) capture(ByRef) -> memref<?xi32> {name = ""}
1665+
// expected-error @below {{only one of val or var_ptr must be used}}
1666+
omp.target map_entries(%mapv -> %arg0: memref<?xi32>) {
1667+
^bb0(%arg0: memref<?xi32>):
1668+
omp.terminator
1669+
}
1670+
return
1671+
}
1672+
1673+
// -----
1674+
1675+
func.func @omp_map2(%map1: memref<?xi32>, %map2: i32) {
1676+
%mapv = omp.map_info var_ptr( : , tensor<?xi32>) val(%map2 : i32) map_clauses(tofrom) capture(ByRef) -> memref<?xi32> {name = ""}
1677+
// expected-error @below {{var_type supplied without var_ptr}}
1678+
omp.target map_entries(%mapv -> %arg0: memref<?xi32>) {
1679+
^bb0(%arg0: memref<?xi32>):
1680+
omp.terminator
1681+
}
1682+
return
1683+
}
1684+
1685+
// -----
1686+
1687+
func.func @omp_map3(%map1: memref<?xi32>, %map2: i32) {
1688+
%mapv = omp.map_info map_clauses(tofrom) capture(ByRef) -> memref<?xi32> {name = ""}
1689+
// expected-error @below {{missing val or var_ptr}}
1690+
omp.target map_entries(%mapv -> %arg0: memref<?xi32>) {
1691+
^bb0(%arg0: memref<?xi32>):
1692+
omp.terminator
1693+
}
1694+
return
1695+
}
1696+
16591697
llvm.mlir.global internal @_QFsubEx() : i32

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,22 @@ func.func @omp_target(%if_cond : i1, %device : si32, %num_threads : i32, %map1:
492492
// Test with optional map clause.
493493
// CHECK: %[[MAP_A:.*]] = omp.map_info var_ptr(%[[VAL_1:.*]] : memref<?xi32>, tensor<?xi32>) map_clauses(tofrom) capture(ByRef) -> memref<?xi32> {name = ""}
494494
// CHECK: %[[MAP_B:.*]] = omp.map_info var_ptr(%[[VAL_2:.*]] : memref<?xi32>, tensor<?xi32>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) -> memref<?xi32> {name = ""}
495-
// CHECK: omp.target map_entries(%[[MAP_A]], %[[MAP_B]] : memref<?xi32>, memref<?xi32>) {
495+
// CHECK: omp.target map_entries(%[[MAP_A]] -> {{.*}}, %[[MAP_B]] -> {{.*}} : memref<?xi32>, memref<?xi32>) {
496496
%mapv1 = omp.map_info var_ptr(%map1 : memref<?xi32>, tensor<?xi32>) map_clauses(tofrom) capture(ByRef) -> memref<?xi32> {name = ""}
497497
%mapv2 = omp.map_info var_ptr(%map2 : memref<?xi32>, tensor<?xi32>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) -> memref<?xi32> {name = ""}
498-
omp.target map_entries(%mapv1, %mapv2 : memref<?xi32>, memref<?xi32>){}
498+
omp.target map_entries(%mapv1 -> %arg0, %mapv2 -> %arg1 : memref<?xi32>, memref<?xi32>) {
499+
^bb0(%arg0: memref<?xi32>, %arg1: memref<?xi32>):
500+
omp.terminator
501+
}
499502
// CHECK: %[[MAP_C:.*]] = omp.map_info var_ptr(%[[VAL_1:.*]] : memref<?xi32>, tensor<?xi32>) map_clauses(to) capture(ByRef) -> memref<?xi32> {name = ""}
500503
// CHECK: %[[MAP_D:.*]] = omp.map_info var_ptr(%[[VAL_2:.*]] : memref<?xi32>, tensor<?xi32>) map_clauses(always, from) capture(ByRef) -> memref<?xi32> {name = ""}
501-
// CHECK: omp.target map_entries(%[[MAP_C]], %[[MAP_D]] : memref<?xi32>, memref<?xi32>) {
504+
// CHECK: omp.target map_entries(%[[MAP_C]] -> {{.*}}, %[[MAP_D]] -> {{.*}} : memref<?xi32>, memref<?xi32>) {
502505
%mapv3 = omp.map_info var_ptr(%map1 : memref<?xi32>, tensor<?xi32>) map_clauses(to) capture(ByRef) -> memref<?xi32> {name = ""}
503506
%mapv4 = omp.map_info var_ptr(%map2 : memref<?xi32>, tensor<?xi32>) map_clauses(always, from) capture(ByRef) -> memref<?xi32> {name = ""}
504-
omp.target map_entries(%mapv3, %mapv4 : memref<?xi32>, memref<?xi32>) {}
507+
omp.target map_entries(%mapv3 -> %arg0, %mapv4 -> %arg1 : memref<?xi32>, memref<?xi32>) {
508+
^bb0(%arg0: memref<?xi32>, %arg1: memref<?xi32>):
509+
omp.terminator
510+
}
505511
// CHECK: omp.barrier
506512
omp.barrier
507513

@@ -2055,8 +2061,11 @@ func.func @omp_targets_with_map_bounds(%arg0: !llvm.ptr, %arg1: !llvm.ptr) -> ()
20552061
%10 = omp.bounds lower_bound(%7 : i64) upper_bound(%6 : i64) stride(%8 : i64) start_idx(%9 : i64)
20562062
%mapv2 = omp.map_info var_ptr(%arg1 : !llvm.ptr, !llvm.array<10 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByCopy) bounds(%10) -> !llvm.ptr {name = ""}
20572063

2058-
// CHECK: omp.target map_entries(%[[MAP0]], %[[MAP1]] : !llvm.ptr, !llvm.ptr)
2059-
omp.target map_entries(%mapv1, %mapv2 : !llvm.ptr, !llvm.ptr){}
2064+
// CHECK: omp.target map_entries(%[[MAP0]] -> {{.*}}, %[[MAP1]] -> {{.*}} : !llvm.ptr, !llvm.ptr)
2065+
omp.target map_entries(%mapv1 -> %arg2, %mapv2 -> %arg3 : !llvm.ptr, !llvm.ptr) {
2066+
^bb0(%arg2: !llvm.ptr, %arg3: !llvm.ptr):
2067+
omp.terminator
2068+
}
20602069

20612070
// CHECK: omp.target_data map_entries(%[[MAP0]], %[[MAP1]] : !llvm.ptr, !llvm.ptr)
20622071
omp.target_data map_entries(%mapv1, %mapv2 : !llvm.ptr, !llvm.ptr){}

mlir/test/Target/LLVMIR/omptarget-array-sectioning-host.mlir

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
22

33
// This test checks the offload sizes provided to the OpenMP kernel argument
4-
// structure are correct when lowering to LLVM-IR from MLIR with 3-D bounds
5-
// provided for a 3-D array. One with full default size, and the other with
6-
// a user specified OpenMP array sectioning. We expect the default sized
7-
// array bounds to lower to the full size of the array and the sectioned
4+
// structure are correct when lowering to LLVM-IR from MLIR with 3-D bounds
5+
// provided for a 3-D array. One with full default size, and the other with
6+
// a user specified OpenMP array sectioning. We expect the default sized
7+
// array bounds to lower to the full size of the array and the sectioned
88
// array to be the size of 3*3*1*element-byte-size (36 bytes in this case).
99

1010
module attributes {omp.is_target_device = false} {
@@ -18,12 +18,13 @@ module attributes {omp.is_target_device = false} {
1818
%6 = omp.bounds lower_bound(%2 : i64) upper_bound(%2 : i64) stride(%2 : i64) start_idx(%2 : i64)
1919
%7 = omp.map_info var_ptr(%0 : !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>) map_clauses(tofrom) capture(ByRef) bounds(%5, %5, %6) -> !llvm.ptr {name = "inarray(1:3,1:3,2:2)"}
2020
%8 = omp.map_info var_ptr(%1 : !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>) map_clauses(tofrom) capture(ByRef) bounds(%5, %5, %5) -> !llvm.ptr {name = "outarray(1:3,1:3,1:3)"}
21-
omp.target map_entries(%7, %8 : !llvm.ptr, !llvm.ptr) {
21+
omp.target map_entries(%7 -> %arg0, %8 -> %arg1 : !llvm.ptr, !llvm.ptr) {
22+
^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):
2223
%9 = llvm.mlir.constant(0 : i64) : i64
2324
%10 = llvm.mlir.constant(1 : i64) : i64
24-
%11 = llvm.getelementptr %0[0, %10, %9, %9] : (!llvm.ptr, i64, i64, i64) -> !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>
25+
%11 = llvm.getelementptr %arg0[0, %10, %9, %9] : (!llvm.ptr, i64, i64, i64) -> !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>
2526
%12 = llvm.load %11 : !llvm.ptr -> i32
26-
%13 = llvm.getelementptr %1[0, %10, %9, %9] : (!llvm.ptr, i64, i64, i64) -> !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>
27+
%13 = llvm.getelementptr %arg1[0, %10, %9, %9] : (!llvm.ptr, i64, i64, i64) -> !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>
2728
llvm.store %12, %13 : i32, !llvm.ptr
2829
omp.terminator
2930
}

mlir/test/Target/LLVMIR/omptarget-byref-bycopy-generation-device.mlir

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ module attributes {omp.is_target_device = true} {
66
%1 = llvm.mlir.addressof @_QFEsp : !llvm.ptr
77
%2 = omp.map_info var_ptr(%1 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "sp"}
88
%3 = omp.map_info var_ptr(%0 : !llvm.ptr, i32) map_clauses(to) capture(ByCopy) -> !llvm.ptr {name = "i"}
9-
omp.target map_entries(%2, %3 : !llvm.ptr, !llvm.ptr) {
10-
%4 = llvm.load %0 : !llvm.ptr -> i32
11-
llvm.store %4, %1 : i32, !llvm.ptr
9+
omp.target map_entries(%2 -> %arg0, %3 -> %arg1 : !llvm.ptr, !llvm.ptr) {
10+
^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):
11+
%4 = llvm.load %arg1 : !llvm.ptr -> i32
12+
llvm.store %4, %arg0 : i32, !llvm.ptr
1213
omp.terminator
1314
}
1415
llvm.return
@@ -32,7 +33,7 @@ module attributes {omp.is_target_device = true} {
3233
// CHECK: store ptr %[[ARG_BYCOPY]], ptr %[[ALLOCA_BYCOPY]], align 8
3334

3435
// CHECK: user_code.entry: ; preds = %entry
35-
// CHECK: %[[LOAD_BYREF:.*]] = load ptr, ptr %[[ALLOCA_BYREF]], align 8
36+
// CHECK: %[[LOAD_BYREF:.*]] = load ptr, ptr %[[ALLOCA_BYREF]], align 8
3637
// CHECK: br label %omp.target
3738

3839
// CHECK: omp.target: ; preds = %user_code.entry

mlir/test/Target/LLVMIR/omptarget-byref-bycopy-generation-host.mlir

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ module attributes {omp.is_target_device = false} {
66
%1 = llvm.mlir.addressof @_QFEsp : !llvm.ptr
77
%2 = omp.map_info var_ptr(%1 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "sp"}
88
%3 = omp.map_info var_ptr(%0 : !llvm.ptr, i32) map_clauses(to) capture(ByCopy) -> !llvm.ptr {name = "i"}
9-
omp.target map_entries(%2, %3 : !llvm.ptr, !llvm.ptr) {
10-
%4 = llvm.load %0 : !llvm.ptr -> i32
11-
llvm.store %4, %1 : i32, !llvm.ptr
9+
omp.target map_entries(%2 -> %arg0, %3 -> %arg1 : !llvm.ptr, !llvm.ptr) {
10+
^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):
11+
%4 = llvm.load %arg1 : !llvm.ptr -> i32
12+
llvm.store %4, %arg0 : i32, !llvm.ptr
1213
omp.terminator
1314
}
1415
llvm.return

mlir/test/Target/LLVMIR/omptarget-declare-target-llvm-device.mlir

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
22

33
// This test the generation of additional load operations for declare target link variables
4-
// inside of target op regions when lowering to IR for device. Unfortunately as the host file is not
4+
// inside of target op regions when lowering to IR for device. Unfortunately as the host file is not
55
// passed as a module attribute, we miss out on the metadata and entryinfo.
66
//
7-
// Unfortunately, only so much can be tested as the device side is dependent on a *.bc
7+
// Unfortunately, only so much can be tested as the device side is dependent on a *.bc
88
// file created by the host and appended as an attribute to the module.
99

1010
module attributes {omp.is_target_device = true} {
@@ -13,18 +13,19 @@ module attributes {omp.is_target_device = true} {
1313
%0 = llvm.mlir.constant(0 : i32) : i32
1414
llvm.return %0 : i32
1515
}
16-
16+
1717
llvm.func @_QQmain() attributes {} {
1818
%0 = llvm.mlir.addressof @_QMtest_0Esp : !llvm.ptr
19-
19+
2020
// CHECK-DAG: omp.target: ; preds = %user_code.entry
2121
// CHECK-DAG: %[[V:.*]] = load ptr, ptr @_QMtest_0Esp_decl_tgt_ref_ptr, align 8
2222
// CHECK-DAG: store i32 1, ptr %[[V]], align 4
2323
// CHECK-DAG: br label %omp.region.cont
2424
%map = omp.map_info var_ptr(%0 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
25-
omp.target map_entries(%map : !llvm.ptr) {
25+
omp.target map_entries(%map -> %arg0 : !llvm.ptr) {
26+
^bb0(%arg0: !llvm.ptr):
2627
%1 = llvm.mlir.constant(1 : i32) : i32
27-
llvm.store %1, %0 : i32, !llvm.ptr
28+
llvm.store %1, %arg0 : i32, !llvm.ptr
2829
omp.terminator
2930
}
3031

0 commit comments

Comments
 (0)