[Mlir-commits] [mlir] [mlir][OpenMP] inscan reduction modifier and scan op mlir support (PR #114737)
Michael Klemm
llvmlistbot at llvm.org
Mon Nov 18 14:19:21 PST 2024
================
@@ -2840,6 +2886,54 @@ 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");
+ }
+ const OperandRange &scanVars =
+ hasExclusiveVars() ? getExclusiveVars() : getInclusiveVars();
+ auto verifyScanVarsInReduction = [&scanVars](OperandRange reductionVars) {
+ for (const auto &it : scanVars)
+ if (!llvm::is_contained(reductionVars, it))
+ return false;
+ return true;
+ };
+ if (mlir::omp::WsloopOp parentOp =
+ (*this)->getParentOfType<mlir::omp::WsloopOp>()) {
+ if (parentOp.getReductionModAttr() &&
+ parentOp.getReductionModAttr().getValue() ==
+ mlir::omp::ReductionModifier::InScan) {
+ if (!verifyScanVarsInReduction(parentOp.getReductionVars())) {
+ return emitError(
+ "List item should appear in REDUCTION clause of the parent");
+ }
+ return success();
+ }
+ } else if (mlir::omp::SimdOp parentOp =
+ (*this)->getParentOfType<mlir::omp::SimdOp>()) {
+ if (parentOp.getReductionModAttr().getValue() ==
+ mlir::omp::ReductionModifier::InScan) {
+ if (!verifyScanVarsInReduction(parentOp.getReductionVars())) {
+ return emitError(
+ "List item should appear in REDUCTION clause of the parent");
+ }
+ return success();
+ }
+ }
+ return emitError("Scan Operation should be enclosed within a parent "
+ "WORSKSHARING LOOP or SIMD with INSCAN reduction modifier");
----------------
mjklemm wrote:
```suggestion
return emitError("SCAN directive needs to be enclosed within a parent "
"worksharing loop construct or SIMD construct with INSCAN reduction modifier");
```
https://github.com/llvm/llvm-project/pull/114737
More information about the Mlir-commits
mailing list