Skip to content

Commit b439a72

Browse files
committed
[MLIR][OpenMP] Add a new ComposableLoopWrapperInterface to check and set a composite unitAttr.
1 parent 704f303 commit b439a72

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def PrivateClauseOp : OpenMP_Op<"private", [IsolatedFromAbove, RecipeInterface]>
129129
def ParallelOp : OpenMP_Op<"parallel", traits = [
130130
AttrSizedOperandSegments, AutomaticAllocationScope,
131131
DeclareOpInterfaceMethods<LoopWrapperInterface>,
132+
DeclareOpInterfaceMethods<ComposableLoopWrapperInterface>,
132133
DeclareOpInterfaceMethods<OutlineableOpenMPOpInterface>,
133134
RecursiveMemoryEffects
134135
], clauses = [
@@ -357,6 +358,7 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
357358

358359
def WsloopOp : OpenMP_Op<"wsloop", traits = [
359360
AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>,
361+
DeclareOpInterfaceMethods<ComposableLoopWrapperInterface>,
360362
RecursiveMemoryEffects, SingleBlock
361363
], clauses = [
362364
OpenMP_AllocateClauseSkip<assemblyFormat = true>,
@@ -433,6 +435,7 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
433435

434436
def SimdOp : OpenMP_Op<"simd", traits = [
435437
AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>,
438+
DeclareOpInterfaceMethods<ComposableLoopWrapperInterface>,
436439
RecursiveMemoryEffects, SingleBlock
437440
], clauses = [
438441
OpenMP_AlignedClause, OpenMP_IfClause, OpenMP_LinearClause,
@@ -500,6 +503,7 @@ def YieldOp : OpenMP_Op<"yield",
500503
//===----------------------------------------------------------------------===//
501504
def DistributeOp : OpenMP_Op<"distribute", traits = [
502505
AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>,
506+
DeclareOpInterfaceMethods<ComposableLoopWrapperInterface>,
503507
RecursiveMemoryEffects, SingleBlock
504508
], clauses = [
505509
OpenMP_AllocateClause, OpenMP_DistScheduleClause, OpenMP_OrderClause,
@@ -587,8 +591,9 @@ def TaskOp : OpenMP_Op<"task", traits = [
587591

588592
def TaskloopOp : OpenMP_Op<"taskloop", traits = [
589593
AttrSizedOperandSegments, AutomaticAllocationScope,
590-
DeclareOpInterfaceMethods<LoopWrapperInterface>, RecursiveMemoryEffects,
591-
SingleBlock
594+
DeclareOpInterfaceMethods<LoopWrapperInterface>,
595+
DeclareOpInterfaceMethods<ComposableLoopWrapperInterface>,
596+
RecursiveMemoryEffects, SingleBlock
592597
], clauses = [
593598
OpenMP_AllocateClause, OpenMP_FinalClause, OpenMP_GrainsizeClause,
594599
OpenMP_IfClause, OpenMP_InReductionClauseSkip<extraClassDeclaration = true>,

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

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

145+
def ComposableLoopWrapperInterface : OpInterface<"ComposableLoopWrapperInterface"> {
146+
let description = [{
147+
OpenMP operations that can wrap a single loop nest. When taking a wrapper
148+
role, these operations must only contain a single region with a single block
149+
in which there's a single operation and a terminator. That nested operation
150+
must be another loop wrapper or an `omp.loop_nest`.
151+
}];
152+
153+
let cppNamespace = "::mlir::omp";
154+
155+
let methods = [
156+
InterfaceMethod<
157+
/*description=*/[{
158+
Check whether the operation is composable.
159+
}],
160+
/*retTy=*/"bool",
161+
/*methodName=*/"isComposite",
162+
(ins ), [{}], [{
163+
return $_op->hasAttr("omp.composite");
164+
}]
165+
>,
166+
InterfaceMethod<
167+
/*description=*/[{
168+
Set the CompositeAttr for the op.
169+
}],
170+
/*retTy=*/"void",
171+
/*methodName=*/"setComposite",
172+
(ins), [{}], [{
173+
$_op->setDiscardableAttr("omp.composite", mlir::UnitAttr::get($_op->getContext()));
174+
}]
175+
>
176+
];
177+
}
178+
145179
def DeclareTargetInterface : OpInterface<"DeclareTargetInterface"> {
146180
let description = [{
147181
OpenMP operations that support declare target have this interface.

0 commit comments

Comments
 (0)