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 @@ -1644,4 +1644,33 @@ let hasVerifier = 1; } +//===----------------------------------------------------------------------===// +// 8.2 requires directive +//===----------------------------------------------------------------------===// + +def ClauseRequiresNone : I32BitEnumAttrCaseNone<"none">; +def ClauseRequiresReverseOffload : I32BitEnumAttrCaseBit<"reverse_offload", 0>; +def ClauseRequiresUnifiedAddress : I32BitEnumAttrCaseBit<"unified_address", 1>; +def ClauseRequiresUnifiedSharedMemory + : I32BitEnumAttrCaseBit<"unified_shared_memory", 2>; +def ClauseRequiresDynamicAllocators + : I32BitEnumAttrCaseBit<"dynamic_allocators", 3>; + +def ClauseRequires : I32BitEnumAttr< + "ClauseRequires", + "requires clause", + [ + ClauseRequiresNone, + ClauseRequiresReverseOffload, + ClauseRequiresUnifiedAddress, + ClauseRequiresUnifiedSharedMemory, + ClauseRequiresDynamicAllocators + ]> { + let genSpecializedAttr = 0; + let cppNamespace = "::mlir::omp"; +} +def ClauseRequiresAttr : + EnumAttr { +} + #endif // OPENMP_OPS diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td @@ -49,7 +49,7 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> { let description = [{ - Operations that represent a module for offloading (host or device) + Operations that represent a module for offloading (host or device) should have this interface. }]; @@ -68,7 +68,7 @@ mlir::StringAttr::get($_op->getContext(), llvm::Twine{"omp.is_device"}), mlir::omp::IsDeviceAttr::get($_op->getContext(), isDevice)); }]>, - InterfaceMethod< + InterfaceMethod< /*description=*/[{ Get the IsDeviceAttr attribute on the current module if it exists and return its value, if it doesn't exist it returns false by default. @@ -81,7 +81,7 @@ return isDevice.dyn_cast().getIsDevice(); return false; }]>, - InterfaceMethod< + InterfaceMethod< /*description=*/[{ Get the FlagsAttr attribute on the current module if it exists and return the attribute, if it doesn't exit it returns a nullptr @@ -93,7 +93,7 @@ return flags.dyn_cast_or_null(); return nullptr; }]>, - InterfaceMethod< + InterfaceMethod< /*description=*/[{ Apply an omp.FlagsAttr to a module with the specified values for the flags @@ -138,7 +138,7 @@ targetCPU.str(), targetFeatures.str())); }]>, - InterfaceMethod< + InterfaceMethod< /*description=*/[{ Set a StringAttr on the current module containing the host IR file path. This file path is used in two-phase compilation during the device phase to generate @@ -151,7 +151,7 @@ mlir::StringAttr::get($_op->getContext(), llvm::Twine{"omp.host_ir_filepath"}), mlir::StringAttr::get($_op->getContext(), hostIRFilePath)); }]>, - InterfaceMethod< + InterfaceMethod< /*description=*/[{ Find the host-ir file path StringAttr from the current module if it exists and return its contained value, if it doesn't exist it returns an empty string. This @@ -165,6 +165,30 @@ if (filepath.isa()) return filepath.dyn_cast().getValue(); return {}; + }]>, + InterfaceMethod< + /*description=*/[{ + Get the omp.requires attribute on the operator if it's present and + return its value. If it doesn't exist, return `ClauseRequires::none` by + default. + }], + /*retTy=*/"::mlir::omp::ClauseRequires", + /*methodName=*/"getRequires", + (ins), [{}], [{ + if (Attribute requiresAttr = $_op->getAttr("omp.requires")) + if (auto requiresVal = requiresAttr.dyn_cast()) + return requiresVal.getValue(); + return mlir::omp::ClauseRequires::none; + }]>, + InterfaceMethod< + /*description=*/[{ + Set the omp.requires attribute on the operator to the specified clauses. + }], + /*retTy=*/"void", + /*methodName=*/"setRequires", + (ins "::mlir::omp::ClauseRequires":$clauses), [{}], [{ + $_op->setAttr(mlir::StringAttr::get($_op->getContext(), "omp.requires"), + mlir::omp::ClauseRequiresAttr::get($_op->getContext(), clauses)); }]> ]; }