Skip to content

Commit d372361

Browse files
authored
[MLIR][OpenMP] Add a new ComposableOpInterface to check/set a composite unitAttr. (#102340)
Adds a new ComposableOpInterface for OpenMP operations that can represent a single leaf of a composite OpenMP construct. This is patch 1/2 in a series of patches. Patch 2 - #102341.
1 parent c7a44ec commit d372361

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def PrivateClauseOp : OpenMP_Op<"private", [IsolatedFromAbove, RecipeInterface]>
128128

129129
def ParallelOp : OpenMP_Op<"parallel", traits = [
130130
AttrSizedOperandSegments, AutomaticAllocationScope,
131+
DeclareOpInterfaceMethods<ComposableOpInterface>,
131132
DeclareOpInterfaceMethods<LoopWrapperInterface>,
132133
DeclareOpInterfaceMethods<OutlineableOpenMPOpInterface>,
133134
RecursiveMemoryEffects
@@ -356,7 +357,9 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
356357
//===----------------------------------------------------------------------===//
357358

358359
def WsloopOp : OpenMP_Op<"wsloop", traits = [
359-
AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>,
360+
AttrSizedOperandSegments,
361+
DeclareOpInterfaceMethods<ComposableOpInterface>,
362+
DeclareOpInterfaceMethods<LoopWrapperInterface>,
360363
RecursiveMemoryEffects, SingleBlock
361364
], clauses = [
362365
OpenMP_AllocateClauseSkip<assemblyFormat = true>,
@@ -432,7 +435,9 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
432435
//===----------------------------------------------------------------------===//
433436

434437
def SimdOp : OpenMP_Op<"simd", traits = [
435-
AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>,
438+
AttrSizedOperandSegments,
439+
DeclareOpInterfaceMethods<ComposableOpInterface>,
440+
DeclareOpInterfaceMethods<LoopWrapperInterface>,
436441
RecursiveMemoryEffects, SingleBlock
437442
], clauses = [
438443
OpenMP_AlignedClause, OpenMP_IfClause, OpenMP_LinearClause,
@@ -499,7 +504,9 @@ def YieldOp : OpenMP_Op<"yield",
499504
// Distribute construct [2.9.4.1]
500505
//===----------------------------------------------------------------------===//
501506
def DistributeOp : OpenMP_Op<"distribute", traits = [
502-
AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>,
507+
AttrSizedOperandSegments,
508+
DeclareOpInterfaceMethods<ComposableOpInterface>,
509+
DeclareOpInterfaceMethods<LoopWrapperInterface>,
503510
RecursiveMemoryEffects, SingleBlock
504511
], clauses = [
505512
OpenMP_AllocateClause, OpenMP_DistScheduleClause, OpenMP_OrderClause,
@@ -587,8 +594,9 @@ def TaskOp : OpenMP_Op<"task", traits = [
587594

588595
def TaskloopOp : OpenMP_Op<"taskloop", traits = [
589596
AttrSizedOperandSegments, AutomaticAllocationScope,
590-
DeclareOpInterfaceMethods<LoopWrapperInterface>, RecursiveMemoryEffects,
591-
SingleBlock
597+
DeclareOpInterfaceMethods<ComposableOpInterface>,
598+
DeclareOpInterfaceMethods<LoopWrapperInterface>,
599+
RecursiveMemoryEffects, SingleBlock
592600
], clauses = [
593601
OpenMP_AllocateClause, OpenMP_FinalClause, OpenMP_GrainsizeClause,
594602
OpenMP_IfClause, OpenMP_InReductionClauseSkip<extraClassDeclaration = true>,

mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,42 @@ def LoopWrapperInterface : OpInterface<"LoopWrapperInterface"> {
142142
];
143143
}
144144

145+
def ComposableOpInterface : OpInterface<"ComposableOpInterface"> {
146+
let description = [{
147+
OpenMP operations that can represent a single leaf of a composite OpenMP
148+
construct.
149+
}];
150+
151+
let cppNamespace = "::mlir::omp";
152+
153+
let methods = [
154+
InterfaceMethod<
155+
/*description=*/[{
156+
Check whether the operation is representing a leaf of a composite OpenMP
157+
construct.
158+
}],
159+
/*retTy=*/"bool",
160+
/*methodName=*/"isComposite",
161+
(ins ), [{}], [{
162+
return $_op->hasAttr("omp.composite");
163+
}]
164+
>,
165+
InterfaceMethod<
166+
/*description=*/[{
167+
Mark the operation as part of an OpenMP composite construct.
168+
}],
169+
/*retTy=*/"void",
170+
/*methodName=*/"setComposite",
171+
(ins "bool":$val), [{}], [{
172+
if (val)
173+
$_op->setDiscardableAttr("omp.composite", mlir::UnitAttr::get($_op->getContext()));
174+
else
175+
$_op->removeDiscardableAttr("omp.composite");
176+
}]
177+
>
178+
];
179+
}
180+
145181
def DeclareTargetInterface : OpInterface<"DeclareTargetInterface"> {
146182
let description = [{
147183
OpenMP operations that support declare target have this interface.

0 commit comments

Comments
 (0)