diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -785,6 +785,154 @@ let assemblyFormat = "attr-dict"; } +//===---------------------------------------------------------------------===// +// 2.12.2 target data Construct +//===---------------------------------------------------------------------===// + +def Target_Data: OpenMP_Op<"target_data", [AttrSizedOperandSegments]>{ + let summary = "target data construct"; + let description = [{ + Map variables to a device data environment for the extent of the region. + + The omp target data directive maps variables to a device data + environment, and defines the lexical scope of the data environment + that is created. The omp target data directive can reduce data copies + to and from the offloading device when multiple target regions are using + the same data. + + The optional $if_expr parameter specifies a boolean result of a + conditional check. If this value is 1 or is not provided then the target + region runs on a device, if it is 0 then the target region is executed + on the host device. + + The optional $device parameter specifies the device number for the target + region. + + The optional $use_device_ptr specifies the device pointers to the + corresponding list items in the device data environment. + + The optional $use_device_addr specifies the address of the objects in the + device data enviornment. + + The $map_operands specifies operands in map clause along with it's type and modifiers. + + The $map_operand_segments specifies the segment sizes for $map_operands. + + TODO: depend clause and map_type_modifier values iterator and mapper. + }]; + + let arguments = (ins Optional:$if_expr, + Optional:$device, + Variadic:$use_device_ptr, + Variadic:$use_device_addr, + VariadicOfVariadic:$map_operands, + DenseI32ArrayAttr:$map_operand_segments); + + let regions = (region AnyRegion:$region); + + let assemblyFormat = [{ + (`if` `(` $if_expr^ `)` )? + (`device` `(` $device^ `:` type($device) `)` )? + (`use_device_ptr` `(` $use_device_ptr^ `:` type($use_device_ptr) `)` )? + (`use_device_addr` `(` $use_device_addr^ `:` type($use_device_addr) `)` )? + (`map` `(` $map_operands^ `:` type($map_operands) `)` )? + $region attr-dict + }]; + +} + +//===---------------------------------------------------------------------===// +// 2.12.3 target enter data Construct +//===---------------------------------------------------------------------===// + +def Target_EnterDataOp: OpenMP_Op<"target_enter_data", + [AttrSizedOperandSegments]>{ + let summary = "target enter data construct"; + let description = [{ + The target enter data directive specifies that variables are mapped to + a device data environment. The target enter data directive is a + stand-alone directive. + + The optional $if_expr parameter specifies a boolean result of a + conditional check. If this value is 1 or is not provided then the target + region runs on a device, if it is 0 then the target region is executed on + the host device. + + The optional $device parameter specifies the device number for the + target region. + + The optional $nowait eliminates the implicit barrier so the parent task + can make progress even if the target task is not yet completed. + + The $map_operands specifies operands in map clause along with it's type and modifiers. + + The $map_operand_segments specifies the segment sizes for $map_operands. + + TODO: depend clause and map_type_modifier values iterator and mapper. + }]; + + let arguments = (ins Optional:$if_expr, + Optional:$device, + UnitAttr:$nowait, + VariadicOfVariadic:$map_operands, + DenseI32ArrayAttr:$map_operand_segments); + + let assemblyFormat = [{ + (`if` `(` $if_expr^ `)` )? + (`device` `(` $device^ `:` type($device) `)` )? + (`nowait` $nowait^ )? + (`map` `(` $map_operands^ `:` type($map_operands) `)` )? + attr-dict + }]; + +} + +//===---------------------------------------------------------------------===// +// 2.12.4 target exit data Construct +//===---------------------------------------------------------------------===// + +def Target_ExitDataOp: OpenMP_Op<"target_exit_data", + [AttrSizedOperandSegments]>{ + let summary = "target exit data construct"; + let description = [{ + The target exit data directive specifies that variables are mapped to a + device data environment. The target exit data directive is + a stand-alone directive. + + The optional $if_expr parameter specifies a boolean result of a + conditional check. If this value is 1 or is not provided then the target + region runs on a device, if it is 0 then the target region is executed + on the host device. + + The optional $device parameter specifies the device number for the + target region. + + The optional $nowait eliminates the implicit barrier so the parent + task can make progress even if the target task is not yet completed. + + The $map_operands specifies operands in map clause along with it's type and modifiers. + + The $map_operand_segments specifies the segment sizes for $map_operands. + + TODO: depend clause and map_type_modifier values iterator and mapper. + }]; + + let arguments = (ins Optional:$if_expr, + Optional:$device, + UnitAttr:$nowait, + VariadicOfVariadic:$map_operands, + DenseI32ArrayAttr:$map_operand_segments); + + let assemblyFormat = [{ + (`if` `(` $if_expr^ `)` )? + (`device` `(` $device^ `:` type($device) `)` )? + (`nowait` $nowait^ )? + (`map` `(` $map_operands^ `:` type($map_operands) `)` )? + attr-dict + }]; + +} + //===----------------------------------------------------------------------===// // 2.13.7 flush Construct //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -23,6 +23,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/TypeSwitch.h" #include +#include #include "mlir/Dialect/OpenMP/OpenMPOpsDialect.cpp.inc" #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc" diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -451,6 +451,27 @@ return } +// CHECK-LABEL: omp_target_data +func.func @omp_target_data (%if_cond : i1, %device : si32, %map: memref) -> () { + + //CHECK: omp.target_data + "omp.target_data"(%if_cond, %device, %map) ({ + }) {operand_segment_sizes = array, map_operand_segments = array } : ( i1, si32, memref ) -> () + + // CHECK: omp.target_enter_data + "omp.target_enter_data"(%if_cond, %device) {nowait, operand_segment_sizes = array, map_operand_segments = array } : ( i1, si32) -> () + + // CHECK: omp.target_exit_data + "omp.target_exit_data"(%if_cond, %device) {nowait, operand_segment_sizes = array, map_operand_segments = array } : ( i1, si32) -> () + + // CHECK: omp.barrier + omp.barrier + + return +} + + + // CHECK-LABEL: omp_target_pretty func.func @omp_target_pretty(%if_cond : i1, %device : si32, %num_threads : i32) -> () { // CHECK: omp.target if({{.*}}) device({{.*}})