[Mlir-commits] [mlir] [mlir][OpenMP] inscan reduction modifier and scan op mlir support (PR #114737)
Sergio Afonso
llvmlistbot at llvm.org
Wed Jan 22 07:52:46 PST 2025
================
@@ -3125,6 +3153,34 @@ void MaskedOp::build(OpBuilder &builder, OperationState &state,
MaskedOp::build(builder, state, clauses.filteredThreadId);
}
+//===----------------------------------------------------------------------===//
+// Spec 5.2: Scan construct (5.6)
+//===----------------------------------------------------------------------===//
+
+void ScanOp::build(OpBuilder &builder, OperationState &state,
+ const ScanOperands &clauses) {
+ ScanOp::build(builder, state, clauses.inclusiveVars, clauses.exclusiveVars);
+}
+
+LogicalResult ScanOp::verify() {
+ if (hasExclusiveVars() == hasInclusiveVars())
+ return emitError(
+ "Exactly one of EXCLUSIVE or INCLUSIVE clause is expected");
+ if (WsloopOp parentWsLoopOp = (*this)->getParentOfType<WsloopOp>())
+ if (parentWsLoopOp.getReductionModAttr() &&
+ parentWsLoopOp.getReductionModAttr().getValue() ==
+ mlir::omp::ReductionModifier::inscan)
+ return success();
+ if (SimdOp parentSimdOp = (*this)->getParentOfType<SimdOp>())
+ if (parentSimdOp.getReductionModAttr() &&
+ parentSimdOp.getReductionModAttr().getValue() ==
+ mlir::omp::ReductionModifier::inscan)
+ return success();
----------------
skatrak wrote:
Nit: Some more `mlir::omp` left behind, and braces are preferred for the outer `if` statements to avoid future "dangling else" issues while removing them for the inner statements ([link](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements)).
```suggestion
if (WsloopOp parentWsLoopOp = (*this)->getParentOfType<WsloopOp>()) {
if (parentWsLoopOp.getReductionModAttr() &&
parentWsLoopOp.getReductionModAttr().getValue() ==
ReductionModifier::inscan)
return success();
}
if (SimdOp parentSimdOp = (*this)->getParentOfType<SimdOp>()) {
if (parentSimdOp.getReductionModAttr() &&
parentSimdOp.getReductionModAttr().getValue() ==
ReductionModifier::inscan)
return success();
}
```
https://github.com/llvm/llvm-project/pull/114737
More information about the Mlir-commits
mailing list