Skip to content

Commit 96ddba7

Browse files
committed
[MLIR][OpenMP] Create LoopRelatedClause
This patch introduces a new OpenMP clause definition not defined by the spec. Its main purpose is to define the `loop_inclusive` (previously "inclusive", renamed according to the parent of this PR in the stack) argument of `omp.loop_nest` in such a way that a followup implementation of a tablegen backend to automatically generate clause and operation operand structures directly from `OpenMP_Op` and `OpenMP_Clause` definitions can properly generate the `LoopNestOperands` structure.
1 parent 742bab2 commit 96ddba7

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,25 @@ class OpenMP_LinearClauseSkip<
564564

565565
def OpenMP_LinearClause : OpenMP_LinearClauseSkip<>;
566566

567+
//===----------------------------------------------------------------------===//
568+
// Not in the spec: Clause-like structure to hold loop related information.
569+
//===----------------------------------------------------------------------===//
570+
571+
class OpenMP_LoopRelatedClauseSkip<
572+
bit traits = false, bit arguments = false, bit assemblyFormat = false,
573+
bit description = false, bit extraClassDeclaration = false
574+
> : OpenMP_Clause</*isRequired=*/false, traits, arguments, assemblyFormat,
575+
description, extraClassDeclaration> {
576+
let arguments = (ins
577+
UnitAttr:$loop_inclusive
578+
);
579+
580+
// Description and formatting integrated in the `omp.loop_nest` operation,
581+
// which is the only one currently accepting this clause.
582+
}
583+
584+
def OpenMP_LoopRelatedClause : OpenMP_LoopRelatedClauseSkip<>;
585+
567586
//===----------------------------------------------------------------------===//
568587
// V5.2: [5.8.3] `map` clause
569588
//===----------------------------------------------------------------------===//

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def SingleOp : OpenMP_Op<"single", traits = [
297297
def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
298298
RecursiveMemoryEffects, SameVariadicOperandSize
299299
], clauses = [
300-
OpenMP_CollapseClause
300+
OpenMP_CollapseClause, OpenMP_LoopRelatedClause
301301
], singleRegion = true> {
302302
let summary = "rectangular loop nest";
303303
let description = [{
@@ -306,7 +306,7 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
306306
lower and upper bounds, as well as a step variable, must be defined.
307307

308308
The lower and upper bounds specify a half-open range: the range includes the
309-
lower bound but does not include the upper bound. If the `inclusive`
309+
lower bound but does not include the upper bound. If the `loop_inclusive`
310310
attribute is specified then the upper bound is also included.
311311

312312
The body region can contain any number of blocks. The region is terminated
@@ -335,8 +335,6 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
335335
non-perfectly nested loops.
336336
}];
337337

338-
let arguments = !con(clausesArgs, (ins UnitAttr:$inclusive));
339-
340338
let builders = [
341339
OpBuilder<(ins CArg<"const LoopNestOperands &">:$clauses)>
342340
];

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ ParseResult LoopNestOp::parse(OpAsmParser &parser, OperationState &result) {
20472047

20482048
// Parse "inclusive" flag.
20492049
if (succeeded(parser.parseOptionalKeyword("inclusive")))
2050-
result.addAttribute("inclusive",
2050+
result.addAttribute("loop_inclusive",
20512051
UnitAttr::get(parser.getBuilder().getContext()));
20522052

20532053
// Parse step values.
@@ -2076,7 +2076,7 @@ void LoopNestOp::print(OpAsmPrinter &p) {
20762076
auto args = region.getArguments();
20772077
p << " (" << args << ") : " << args[0].getType() << " = ("
20782078
<< getCollapseLowerBounds() << ") to (" << getCollapseUpperBounds() << ") ";
2079-
if (getInclusive())
2079+
if (getLoopInclusive())
20802080
p << "inclusive ";
20812081
p << "step (" << getCollapseSteps() << ") ";
20822082
p.printRegion(region, /*printEntryBlockArgs=*/false);

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
11961196
}
11971197
loopInfos.push_back(ompBuilder->createCanonicalLoop(
11981198
loc, bodyGen, lowerBound, upperBound, step,
1199-
/*IsSigned=*/true, loopOp.getInclusive(), computeIP));
1199+
/*IsSigned=*/true, loopOp.getLoopInclusive(), computeIP));
12001200

12011201
if (failed(bodyGenStatus))
12021202
return failure();

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func.func @omp_loop_nest(%lb : index, %ub : index, %step : index) -> () {
184184
"omp.loop_nest" (%lb, %ub, %step) ({
185185
^bb0(%iv: index):
186186
omp.yield
187-
}) {inclusive} : (index, index, index) -> ()
187+
}) {loop_inclusive} : (index, index, index) -> ()
188188
omp.terminator
189189
}
190190

0 commit comments

Comments
 (0)