Skip to content

Commit 2f0047a

Browse files
[MLIR][OpenMP] Allow map operands to be not specified
This patch permits map operands to be not specified for the target data operation. Also emit an error if none of the map, use_device_addr, or use_device_ptr operands are specified. Reviewed By: TIFitis Differential Revision: https://reviews.llvm.org/D156170
1 parent abb09a6 commit 2f0047a

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,19 @@ func.func @_QPopenmp_target_data_region() {
321321

322322
// -----
323323

324+
func.func @_QPomp_target_data_empty() {
325+
%0 = fir.alloca !fir.array<1024xi32> {bindc_name = "a", uniq_name = "_QFomp_target_data_emptyEa"}
326+
omp.target_data use_device_addr(%0 : !fir.ref<!fir.array<1024xi32>>) {
327+
}
328+
return
329+
}
330+
331+
// CHECK-LABEL: llvm.func @_QPomp_target_data_empty
332+
// CHECK: omp.target_data use_device_addr(%1 : !llvm.ptr<array<1024 x i32>>) {
333+
// CHECK: }
334+
335+
// -----
336+
324337
func.func @_QPomp_target() {
325338
%0 = fir.alloca !fir.array<512xi32> {bindc_name = "a", uniq_name = "_QFomp_targetEa"}
326339
%c64_i32 = arith.constant 64 : i32

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,15 +1041,16 @@ def Target_DataOp: OpenMP_Op<"target_data", [AttrSizedOperandSegments]>{
10411041
Variadic<OpenMP_PointerLikeType>:$use_device_ptr,
10421042
Variadic<OpenMP_PointerLikeType>:$use_device_addr,
10431043
Variadic<OpenMP_PointerLikeType>:$map_operands,
1044-
I64ArrayAttr:$map_types);
1044+
OptionalAttr<I64ArrayAttr>:$map_types);
10451045

10461046
let regions = (region AnyRegion:$region);
10471047

10481048
let assemblyFormat = [{
10491049
oilist(`if` `(` $if_expr `:` type($if_expr) `)`
1050-
| `device` `(` $device `:` type($device) `)`)
1051-
`map` `(` custom<MapClause>($map_operands, type($map_operands), $map_types) `)`
1052-
oilist(`use_device_ptr` `(` $use_device_ptr `:` type($use_device_ptr) `)`
1050+
| `device` `(` $device `:` type($device) `)`
1051+
| `map`
1052+
`(` custom<MapClause>($map_operands, type($map_operands), $map_types) `)`
1053+
| `use_device_ptr` `(` $use_device_ptr `:` type($use_device_ptr) `)`
10531054
| `use_device_addr` `(` $use_device_addr `:` type($use_device_addr) `)`)
10541055
$region attr-dict
10551056
}];

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,11 +800,22 @@ static LogicalResult verifyMapClause(Operation *op, OperandRange map_operands,
800800
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
801801
flag);
802802
};
803-
if (!map_types.has_value())
804-
return success();
803+
if (!map_types) {
804+
if (!map_operands.empty())
805+
return emitError(op->getLoc(), "missing mapTypes");
806+
else
807+
return success();
808+
}
809+
810+
if (map_operands.empty() && !map_types->empty())
811+
return emitError(op->getLoc(), "missing mapOperands");
812+
813+
if (map_types->empty() && !map_operands.empty())
814+
return emitError(op->getLoc(), "missing mapTypes");
805815

806816
if (map_operands.size() != map_types->size())
807-
return failure();
817+
return emitError(op->getLoc(),
818+
"mismatch in number of mapOperands and mapTypes");
808819

809820
for (const auto &mapTypeOp : *map_types) {
810821
int64_t mapTypeBits = 0x00;
@@ -835,6 +846,11 @@ static LogicalResult verifyMapClause(Operation *op, OperandRange map_operands,
835846
}
836847

837848
LogicalResult DataOp::verify() {
849+
if (getMapOperands().empty() && getUseDevicePtr().empty() &&
850+
getUseDeviceAddr().empty()) {
851+
return ::emitError(this->getLoc(), "At least one of map, useDevicePtr, or "
852+
"useDeviceAddr operand must be present");
853+
}
838854
return verifyMapClause(*this, getMapOperands(), getMapTypes());
839855
}
840856

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,8 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
14371437
deviceID = intAttr.getInt();
14381438

14391439
mapOperands = dataOp.getMapOperands();
1440-
mapTypes = dataOp.getMapTypes();
1440+
if (dataOp.getMapTypes())
1441+
mapTypes = dataOp.getMapTypes().value();
14411442
return success();
14421443
})
14431444
.Case([&](omp::EnterDataOp enterDataOp) {

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,14 @@ func.func @omp_target_data(%map1: memref<?xi32>) {
16301630

16311631
// -----
16321632

1633+
func.func @omp_target_data() {
1634+
// expected-error @below {{At least one of map, useDevicePtr, or useDeviceAddr operand must be present}}
1635+
omp.target_data {}
1636+
return
1637+
}
1638+
1639+
// -----
1640+
16331641
func.func @omp_target_enter_data(%map1: memref<?xi32>) {
16341642
// expected-error @below {{to and alloc map types are permitted}}
16351643
omp.target_enter_data map((from -> %map1 : memref<?xi32>)){}

0 commit comments

Comments
 (0)