[llvm-branch-commits] [mlir] [MLIR][OpenMP] Create `LoopRelatedClause` (PR #99506)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jul 18 07:57:22 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-llvm
Author: Sergio Afonso (skatrak)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/99506.diff
5 Files Affected:
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td (+19)
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+2-4)
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+2-2)
- (modified) mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+1-1)
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+1-1)
``````````diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
index 0846bc9d2189c..859801ca28da0 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
@@ -559,6 +559,25 @@ class OpenMP_LinearClauseSkip<
def OpenMP_LinearClause : OpenMP_LinearClauseSkip<>;
+//===----------------------------------------------------------------------===//
+// Not in the spec: Clause-like structure to hold loop related information.
+//===----------------------------------------------------------------------===//
+
+class OpenMP_LoopRelatedClauseSkip<
+ bit traits = false, bit arguments = false, bit assemblyFormat = false,
+ bit description = false, bit extraClassDeclaration = false
+ > : OpenMP_Clause</*isRequired=*/false, traits, arguments, assemblyFormat,
+ description, extraClassDeclaration> {
+ let arguments = (ins
+ UnitAttr:$loop_inclusive
+ );
+
+ // Description and formatting integrated in the `omp.loop_nest` operation,
+ // which is the only one currently accepting this clause.
+}
+
+def OpenMP_LoopRelatedClause : OpenMP_LoopRelatedClauseSkip<>;
+
//===----------------------------------------------------------------------===//
// V5.2: [5.8.3] `map` clause
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 4b3120dddfa54..a4aeeacfea672 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -297,7 +297,7 @@ def SingleOp : OpenMP_Op<"single", traits = [
def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
RecursiveMemoryEffects, SameVariadicOperandSize
], clauses = [
- OpenMP_CollapseClause
+ OpenMP_CollapseClause, OpenMP_LoopRelatedClause
], singleRegion = true> {
let summary = "rectangular loop nest";
let description = [{
@@ -306,7 +306,7 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
lower and upper bounds, as well as a step variable, must be defined.
The lower and upper bounds specify a half-open range: the range includes the
- lower bound but does not include the upper bound. If the `inclusive`
+ lower bound but does not include the upper bound. If the `loop_inclusive`
attribute is specified then the upper bound is also included.
The body region can contain any number of blocks. The region is terminated
@@ -335,8 +335,6 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
non-perfectly nested loops.
}];
- let arguments = !con(clausesArgs, (ins UnitAttr:$inclusive));
-
let builders = [
OpBuilder<(ins CArg<"const LoopNestOperands &">:$clauses)>
];
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 575133a4dfe2e..761eaa810038c 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -2047,7 +2047,7 @@ ParseResult LoopNestOp::parse(OpAsmParser &parser, OperationState &result) {
// Parse "inclusive" flag.
if (succeeded(parser.parseOptionalKeyword("inclusive")))
- result.addAttribute("inclusive",
+ result.addAttribute("loop_inclusive",
UnitAttr::get(parser.getBuilder().getContext()));
// Parse step values.
@@ -2076,7 +2076,7 @@ void LoopNestOp::print(OpAsmPrinter &p) {
auto args = region.getArguments();
p << " (" << args << ") : " << args[0].getType() << " = ("
<< getCollapseLowerBound() << ") to (" << getCollapseUpperBound() << ") ";
- if (getInclusive())
+ if (getLoopInclusive())
p << "inclusive ";
p << "step (" << getCollapseStep() << ") ";
p.printRegion(region, /*printEntryBlockArgs=*/false);
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index b353468711047..fb6da86474b84 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -1190,7 +1190,7 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
}
loopInfos.push_back(ompBuilder->createCanonicalLoop(
loc, bodyGen, lowerBound, upperBound, step,
- /*IsSigned=*/true, loopOp.getInclusive(), computeIP));
+ /*IsSigned=*/true, loopOp.getLoopInclusive(), computeIP));
if (failed(bodyGenStatus))
return failure();
diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir
index 4a14714355c2a..f93074895bfab 100644
--- a/mlir/test/Dialect/OpenMP/ops.mlir
+++ b/mlir/test/Dialect/OpenMP/ops.mlir
@@ -184,7 +184,7 @@ func.func @omp_loop_nest(%lb : index, %ub : index, %step : index) -> () {
"omp.loop_nest" (%lb, %ub, %step) ({
^bb0(%iv: index):
omp.yield
- }) {inclusive} : (index, index, index) -> ()
+ }) {loop_inclusive} : (index, index, index) -> ()
omp.terminator
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/99506
More information about the llvm-branch-commits
mailing list