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 @@ -52,6 +52,22 @@ let assemblyFormat = "`<` struct(params) `>`"; } +//===----------------------------------------------------------------------===// +// Runtime library flag's attribute that holds information for lowering to LLVM +//===----------------------------------------------------------------------===// + +def FlagsAttr : OpenMP_Attr<"Flags", "flags"> { + let parameters = (ins + DefaultValuedParameter<"uint32_t", "0">:$debug_kind, + DefaultValuedParameter<"bool", "false">:$assume_teams_oversubscription, + DefaultValuedParameter<"bool", "false">:$assume_threads_oversubscription, + DefaultValuedParameter<"bool", "false">:$assume_no_thread_state, + DefaultValuedParameter<"bool", "false">:$assume_no_nested_parallelism + ); + + let assemblyFormat = "`<` struct(params) `>`"; +} + class OpenMP_Op traits = []> : Op; 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 @@ -81,6 +81,35 @@ return isDevice.dyn_cast().getIsDevice(); return false; }]>, + 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 + }], + /*retTy=*/"mlir::omp::FlagsAttr", + /*methodName=*/"getFlags", + (ins), [{}], [{ + if (Attribute flags = $_op->getAttr("omp.flags")) + return flags.dyn_cast_or_null(); + return nullptr; + }]>, + InterfaceMethod< + /*description=*/[{ + Apply an omp.FlagsAttr to a module with the specified values + for the flags + }], + /*retTy=*/"void", + /*methodName=*/"setFlags", + (ins "uint32_t":$debugKind, + "bool":$assumeTeamsOversubscription, + "bool":$assumeThreadsOversubscription, + "bool":$assumeNoThreadState, + "bool":$assumeNoNestedParallelism), [{}], [{ + $_op->setAttr(("omp." + mlir::omp::FlagsAttr::getMnemonic()).str(), + mlir::omp::FlagsAttr::get($_op->getContext(), debugKind, + assumeTeamsOversubscription, assumeThreadsOversubscription, + assumeNoThreadState, assumeNoNestedParallelism)); + }]>, ]; } diff --git a/mlir/test/Dialect/OpenMP/attr.mlir b/mlir/test/Dialect/OpenMP/attr.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Dialect/OpenMP/attr.mlir @@ -0,0 +1,31 @@ +// RUN: mlir-opt %s | mlir-opt | FileCheck %s + +// CHECK: module attributes {omp.flags = #omp.flags<>} { +module attributes {omp.flags = #omp.flags} {} + +// CHECK: module attributes {omp.flags = #omp.flags} { +module attributes {omp.flags = #omp.flags} {} + +// CHECK: module attributes {omp.flags = #omp.flags} { +module attributes {omp.flags = #omp.flags} {} + +// CHECK: module attributes {omp.flags = #omp.flags} { +module attributes {omp.flags = #omp.flags} {} + +// CHECK: module attributes {omp.flags = #omp.flags} { +module attributes {omp.flags = #omp.flags} {} + +// CHECK: module attributes {omp.flags = #omp.flags} { +module attributes {omp.flags = #omp.flags} {} + +// CHECK: module attributes {omp.flags = #omp.flags<>} { +module attributes {omp.flags = #omp.flags<>} {} + +// CHECK: module attributes {omp.flags = #omp.flags} { +module attributes {omp.flags = #omp.flags} {} + +// CHECK: module attributes {omp.flags = #omp.flags} { +module attributes {omp.flags = #omp.flags} {} + +// CHECK: module attributes {omp.flags = #omp.flags} { +module attributes {omp.flags = #omp.flags} {}