https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/171825
>From 1bb03fd2b7580f3a8c35bb37857a982947eb3f0a Mon Sep 17 00:00:00 2001 From: skc7 <[email protected]> Date: Tue, 16 Dec 2025 13:15:43 +0530 Subject: [PATCH 1/4] allow one dimsValues to be present for verifier --- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index 5d2d76f2ddb34..f9dcb48c7f08b 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -2223,7 +2223,7 @@ static LogicalResult verifyDimsModifier(Operation *op, } return success(); } else { - if (!dimsValues.empty()) { + if (dimsValues.size() > 1) { return op->emitError( "dims values can only be specified with dims modifier"); } >From fa606008ce25bda40c0000ee10aa1047098bee3b Mon Sep 17 00:00:00 2001 From: skc7 <[email protected]> Date: Thu, 11 Dec 2025 13:35:05 +0530 Subject: [PATCH 2/4] [OpenMP][MLIR] Add thread_limit with dims modifier support --- .../Optimizer/OpenMP/LowerWorkdistribute.cpp | 16 +- .../mlir/Dialect/OpenMP/OpenMPClauses.td | 29 +++- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 72 ++++++++- .../OpenMP/OpenMPToLLVMIRTranslation.cpp | 8 + mlir/test/Dialect/OpenMP/invalid.mlir | 149 +++++++++++++++++- mlir/test/Dialect/OpenMP/ops.mlir | 8 +- 6 files changed, 264 insertions(+), 18 deletions(-) diff --git a/flang/lib/Optimizer/OpenMP/LowerWorkdistribute.cpp b/flang/lib/Optimizer/OpenMP/LowerWorkdistribute.cpp index 7b61539984232..a3b9e5c76bdd2 100644 --- a/flang/lib/Optimizer/OpenMP/LowerWorkdistribute.cpp +++ b/flang/lib/Optimizer/OpenMP/LowerWorkdistribute.cpp @@ -766,6 +766,7 @@ FailureOr<omp::TargetOp> splitTargetData(omp::TargetOp targetOp, targetOp.getInReductionSymsAttr(), targetOp.getIsDevicePtrVars(), innerMapInfos, targetOp.getNowaitAttr(), targetOp.getPrivateVars(), targetOp.getPrivateSymsAttr(), targetOp.getPrivateNeedsBarrierAttr(), + targetOp.getThreadLimitNumDimsAttr(), targetOp.getThreadLimitDimsValues(), targetOp.getThreadLimit(), targetOp.getPrivateMapsAttr()); rewriter.inlineRegionBefore(targetOp.getRegion(), newTargetOp.getRegion(), newTargetOp.getRegion().begin()); @@ -1485,8 +1486,9 @@ genPreTargetOp(omp::TargetOp targetOp, SmallVector<Value> &preMapOperands, targetOp.getInReductionByrefAttr(), targetOp.getInReductionSymsAttr(), targetOp.getIsDevicePtrVars(), preMapOperands, targetOp.getNowaitAttr(), targetOp.getPrivateVars(), targetOp.getPrivateSymsAttr(), - targetOp.getPrivateNeedsBarrierAttr(), targetOp.getThreadLimit(), - targetOp.getPrivateMapsAttr()); + targetOp.getPrivateNeedsBarrierAttr(), + targetOp.getThreadLimitNumDimsAttr(), targetOp.getThreadLimitDimsValues(), + targetOp.getThreadLimit(), targetOp.getPrivateMapsAttr()); auto *preTargetBlock = rewriter.createBlock( &preTargetOp.getRegion(), preTargetOp.getRegion().begin(), {}, {}); IRMapping preMapping; @@ -1575,8 +1577,9 @@ genIsolatedTargetOp(omp::TargetOp targetOp, SmallVector<Value> &postMapOperands, targetOp.getInReductionByrefAttr(), targetOp.getInReductionSymsAttr(), targetOp.getIsDevicePtrVars(), postMapOperands, targetOp.getNowaitAttr(), targetOp.getPrivateVars(), targetOp.getPrivateSymsAttr(), - targetOp.getPrivateNeedsBarrierAttr(), targetOp.getThreadLimit(), - targetOp.getPrivateMapsAttr()); + targetOp.getPrivateNeedsBarrierAttr(), + targetOp.getThreadLimitNumDimsAttr(), targetOp.getThreadLimitDimsValues(), + targetOp.getThreadLimit(), targetOp.getPrivateMapsAttr()); auto *isolatedTargetBlock = rewriter.createBlock(&isolatedTargetOp.getRegion(), isolatedTargetOp.getRegion().begin(), {}, {}); @@ -1655,8 +1658,9 @@ static omp::TargetOp genPostTargetOp(omp::TargetOp targetOp, targetOp.getInReductionByrefAttr(), targetOp.getInReductionSymsAttr(), targetOp.getIsDevicePtrVars(), postMapOperands, targetOp.getNowaitAttr(), targetOp.getPrivateVars(), targetOp.getPrivateSymsAttr(), - targetOp.getPrivateNeedsBarrierAttr(), targetOp.getThreadLimit(), - targetOp.getPrivateMapsAttr()); + targetOp.getPrivateNeedsBarrierAttr(), + targetOp.getThreadLimitNumDimsAttr(), targetOp.getThreadLimitDimsValues(), + targetOp.getThreadLimit(), targetOp.getPrivateMapsAttr()); // Create the block for postTargetOp auto *postTargetBlock = rewriter.createBlock( &postTargetOp.getRegion(), postTargetOp.getRegion().begin(), {}, {}); diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td index 2beb6690f1736..ae0e2479d1d00 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td @@ -1452,16 +1452,43 @@ class OpenMP_ThreadLimitClauseSkip< > : OpenMP_Clause<traits, arguments, assemblyFormat, description, extraClassDeclaration> { let arguments = (ins + ConfinedAttr<OptionalAttr<I64Attr>, [IntPositive]>:$thread_limit_num_dims, + Variadic<AnyInteger>:$thread_limit_dims_values, Optional<AnyInteger>:$thread_limit ); let optAssemblyFormat = [{ - `thread_limit` `(` $thread_limit `:` type($thread_limit) `)` + `thread_limit` `(` custom<ThreadLimitClause>( + $thread_limit_num_dims, $thread_limit_dims_values, type($thread_limit_dims_values), + $thread_limit, type($thread_limit) + ) `)` }]; let description = [{ The optional `thread_limit` specifies the limit on the number of threads. }]; + + let extraClassDeclaration = [{ + /// Returns true if the dims modifier is explicitly present + bool hasThreadLimitDimsModifier() { + return getThreadLimitNumDims().has_value() && getThreadLimitNumDims().value(); + } + + /// Returns the number of dimensions specified by dims modifier + unsigned getThreadLimitDimsCount() { + if (!hasThreadLimitDimsModifier()) + return 1; + return static_cast<unsigned>(*getThreadLimitNumDims()); + } + + /// Returns the value for a specific dimension index + /// Index must be less than getThreadLimitDimsCount() + ::mlir::Value getThreadLimitDimensionValue(unsigned index) { + assert(index < getThreadLimitDimsCount() && + "Thread limit dims index out of bounds"); + return getThreadLimitDimsValues()[index]; + } + }]; } def OpenMP_ThreadLimitClause : OpenMP_ThreadLimitClauseSkip<>; diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index f9dcb48c7f08b..26cddace26c7c 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -2244,10 +2244,30 @@ void TargetOp::build(OpBuilder &builder, OperationState &state, /*in_reduction_syms=*/nullptr, clauses.isDevicePtrVars, clauses.mapVars, clauses.nowait, clauses.privateVars, makeArrayAttr(ctx, clauses.privateSyms), - clauses.privateNeedsBarrier, clauses.threadLimit, + clauses.privateNeedsBarrier, clauses.threadLimitNumDims, + clauses.threadLimitDimsValues, clauses.threadLimit, /*private_maps=*/nullptr); } +// helper for thread_limit clause restrictions +static LogicalResult +verifyThreadLimitClause(Operation *op, + std::optional<IntegerAttr> threadLimitNumDims, + OperandRange threadLimitDimsValues, Value threadLimit) { + bool hasDimsModifier = + threadLimitNumDims.has_value() && threadLimitNumDims.value(); + + if (hasDimsModifier && threadLimit) { + return op->emitError("thread_limit with dims modifier cannot be used " + "together with number of threads"); + } + + if (failed(verifyDimsModifier(op, threadLimitNumDims, threadLimitDimsValues))) + return failure(); + + return success(); +} + LogicalResult TargetOp::verify() { if (failed(verifyDependVarList(*this, getDependKinds(), getDependVars()))) return failure(); @@ -2259,6 +2279,11 @@ LogicalResult TargetOp::verify() { if (failed(verifyMapClause(*this, getMapVars()))) return failure(); + if (failed(verifyThreadLimitClause(*this, getThreadLimitNumDimsAttr(), + getThreadLimitDimsValues(), + getThreadLimit()))) + return failure(); + return verifyPrivateVarsMapping(*this); } @@ -2666,7 +2691,8 @@ void TeamsOp::build(OpBuilder &builder, OperationState &state, /*private_needs_barrier=*/nullptr, clauses.reductionMod, clauses.reductionVars, makeDenseBoolArrayAttr(ctx, clauses.reductionByref), - makeArrayAttr(ctx, clauses.reductionSyms), clauses.threadLimit); + makeArrayAttr(ctx, clauses.reductionSyms), clauses.threadLimitNumDims, + clauses.threadLimitDimsValues, clauses.threadLimit); } // Helper: Verify num_teams clause @@ -2726,6 +2752,12 @@ LogicalResult TeamsOp::verify() { return emitError( "expected equal sizes for allocate and allocator variables"); + // Check for thread_limit clause restrictions + if (failed(verifyThreadLimitClause(*this, getThreadLimitNumDimsAttr(), + getThreadLimitDimsValues(), + getThreadLimit()))) + return failure(); + return verifyReductionVarList(*this, getReductionSyms(), getReductionVars(), getReductionByref()); } @@ -4652,6 +4684,42 @@ static void printNumTeamsClause(OpAsmPrinter &p, Operation *op, } } +//===----------------------------------------------------------------------===// +// Parser and printer for thread_limit clause +//===----------------------------------------------------------------------===// +static ParseResult +parseThreadLimitClause(OpAsmParser &parser, IntegerAttr &dimsAttr, + SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values, + SmallVectorImpl<Type> &types, + std::optional<OpAsmParser::UnresolvedOperand> &bounds, + Type &boundsType) { + if (succeeded(parseDimsModifierWithValues(parser, dimsAttr, values, types))) { + return success(); + } + + OpAsmParser::UnresolvedOperand boundsOperand; + if (parser.parseOperand(boundsOperand) || parser.parseColon() || + parser.parseType(boundsType)) { + return failure(); + } + bounds = boundsOperand; + return success(); +} + +static void printThreadLimitClause(OpAsmPrinter &p, Operation *op, + IntegerAttr dimsAttr, OperandRange values, + TypeRange types, Value bounds, + Type boundsType) { + if (!values.empty()) { + // Multidimensional: dims(N): values : type + printDimsModifierWithValues(p, dimsAttr, values, types); + } else if (bounds) { + // Both bounds: bounds : type + p.printOperand(bounds); + p << " : " << boundsType; + } +} + #define GET_ATTRDEF_CLASSES #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc" diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index d910bc806288c..6c4ff65dff8fc 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -1974,6 +1974,10 @@ convertOmpTeams(omp::TeamsOp op, llvm::IRBuilderBase &builder, return op.emitError("Lowering of num_teams with dims modifier is NYI."); } + if (op.hasThreadLimitDimsModifier()) { + return op.emitError("Lowering of thread_limit with dims modifier is NYI."); + } + DenseMap<Value, llvm::Value *> reductionVariableMap; unsigned numReductionVars = op.getNumReductionVars(); SmallVector<omp::DeclareReductionOp> reductionDecls; @@ -5644,6 +5648,8 @@ extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads, // num_teams dims and values are not yet supported assert(!teamsOp.hasNumTeamsDimsModifier() && "Lowering of num_teams with dims modifier is NYI."); + assert(!teamsOp.hasThreadLimitDimsModifier() && + "Lowering of thread_limit with dims modifier is NYI."); if (teamsOp.getNumTeamsLower() == blockArg) numTeamsLower = hostEvalVar; else if (teamsOp.getNumTeamsUpper() == blockArg) @@ -5769,6 +5775,8 @@ initTargetDefaultAttrs(omp::TargetOp targetOp, Operation *capturedOp, // num_teams dims and values are not yet supported assert(!teamsOp.hasNumTeamsDimsModifier() && "Lowering of num_teams with dims modifier is NYI."); + assert(!teamsOp.hasThreadLimitDimsModifier() && + "Lowering of thread_limit with dims modifier is NYI."); numTeamsLower = teamsOp.getNumTeamsLower(); numTeamsUpper = teamsOp.getNumTeamsUpper(); threadLimit = teamsOp.getThreadLimit(); diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir b/mlir/test/Dialect/OpenMP/invalid.mlir index dd367aba8da27..7f69ca5aaa064 100644 --- a/mlir/test/Dialect/OpenMP/invalid.mlir +++ b/mlir/test/Dialect/OpenMP/invalid.mlir @@ -1438,7 +1438,7 @@ func.func @omp_teams_allocate(%data_var : memref<i32>) { // expected-error @below {{expected equal sizes for allocate and allocator variables}} "omp.teams" (%data_var) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 1,0,0,0,0,0,0,0,0>} : (memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 1,0,0,0,0,0,0,0,0,0>} : (memref<i32>) -> () omp.terminator } return @@ -1451,7 +1451,7 @@ func.func @omp_teams_num_teams1(%lb : i32) { // expected-error @below {{expected num_teams upper bound to be defined if the lower bound is defined}} "omp.teams" (%lb) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 0,0,0,0,1,0,0,0,0>} : (i32) -> () + }) {operandSegmentSizes = array<i32: 0,0,0,0,1,0,0,0,0,0>} : (i32) -> () omp.terminator } return @@ -1466,7 +1466,7 @@ func.func @omp_teams_num_teams_dims_mismatch() { // expected-error @below {{dims(3) specified but 2 values provided}} "omp.teams" (%v0, %v1) ({ omp.terminator - }) {num_teams_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0>} : (i32, i32) -> () + }) {num_teams_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0,0>} : (i32, i32) -> () omp.terminator } return @@ -1483,7 +1483,7 @@ func.func @omp_teams_num_teams_dims_with_bounds() { // expected-error @below {{num_teams with dims modifier cannot be used together with lower/upper bounds}} "omp.teams" (%v0, %v1, %lb, %ub) ({ omp.terminator - }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,2,1,1,0,0,0>} : (i32, i32, i32, i32) -> () + }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,2,1,1,0,0,0,0>} : (i32, i32, i32, i32) -> () omp.terminator } return @@ -1498,7 +1498,7 @@ func.func @omp_teams_num_teams_values_without_dims() { // expected-error @below {{dims values can only be specified with dims modifier}} "omp.teams" (%v0, %v1) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0>} : (i32, i32) -> () + }) {operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0,0>} : (i32, i32) -> () omp.terminator } return @@ -1511,7 +1511,7 @@ func.func @omp_teams_num_teams_dims_no_values() { // expected-error @below {{dims modifier requires values to be specified}} "omp.teams" () ({ omp.terminator - }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0>} : () -> () + }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0>} : () -> () omp.terminator } return @@ -1526,7 +1526,7 @@ func.func @omp_teams_num_teams_dims_type_mismatch() { // expected-error @below {{dims modifier requires all values to have the same type}} "omp.teams" (%v0, %v1) ({ omp.terminator - }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0>} : (i32, i64) -> () + }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0,0>} : (i32, i64) -> () omp.terminator } return @@ -1547,6 +1547,139 @@ func.func @omp_teams_num_teams2(%lb : i32, %ub : i16) { // ----- +func.func @omp_teams_thread_limit_dims_mismatch() { + omp.target { + %v0 = arith.constant 1 : i32 + %v1 = arith.constant 2 : i32 + // expected-error @below {{dims(3) specified but 2 values provided}} + "omp.teams" (%v0, %v1) ({ + omp.terminator + }) {thread_limit_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2,0>} : (i32, i32) -> () + omp.terminator + } + return +} + +// ----- + +func.func @omp_teams_thread_limit_dims_with_scalar() { + omp.target { + %v0 = arith.constant 1 : i32 + %v1 = arith.constant 2 : i32 + %tl = arith.constant 4 : i32 + // expected-error @below {{thread_limit with dims modifier cannot be used together with number of threads}} + "omp.teams" (%v0, %v1, %tl) ({ + omp.terminator + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2,1>} : (i32, i32, i32) -> () + omp.terminator + } + return +} + +// ----- + +func.func @omp_teams_thread_limit_dims_no_values() { + omp.target { + // expected-error @below {{dims modifier requires values to be specified}} + "omp.teams" () ({ + omp.terminator + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0>} : () -> () + omp.terminator + } + return +} + +// ----- + +func.func @omp_teams_thread_limit_values_without_dims() { + omp.target { + %v0 = arith.constant 1 : i32 + %v1 = arith.constant 2 : i32 + // expected-error @below {{dims values can only be specified with dims modifier}} + "omp.teams" (%v0, %v1) ({ + omp.terminator + }) {operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2,0>} : (i32, i32) -> () + omp.terminator + } + return +} + +// ----- + +func.func @omp_teams_thread_limit_dims_type_mismatch() { + omp.target { + %v0 = arith.constant 1 : i32 + %v1 = arith.constant 2 : i64 + // expected-error @below {{dims modifier requires all values to have the same type}} + "omp.teams" (%v0, %v1) ({ + omp.terminator + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2,0>} : (i32, i64) -> () + omp.terminator + } + return +} + +// ----- + +func.func @omp_target_thread_limit_dims_mismatch() { + %v0 = arith.constant 1 : i32 + %v1 = arith.constant 2 : i32 + // expected-error @below {{dims(3) specified but 2 values provided}} + "omp.target" (%v0, %v1) ({ + omp.terminator + }) {thread_limit_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2,0>} : (i32, i32) -> () + return +} + +// ----- + +func.func @omp_target_thread_limit_dims_with_scalar() { + %v0 = arith.constant 1 : i32 + %v1 = arith.constant 2 : i32 + %tl = arith.constant 4 : i32 + // expected-error @below {{thread_limit with dims modifier cannot be used together with number of threads}} + "omp.target" (%v0, %v1, %tl) ({ + omp.terminator + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2,1>} : (i32, i32, i32) -> () + return +} + +// ----- + +func.func @omp_target_thread_limit_dims_no_values() { + // expected-error @below {{dims modifier requires values to be specified}} + "omp.target" () ({ + omp.terminator + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,0,0>} : () -> () + return +} + +// ----- + +func.func @omp_target_thread_limit_values_without_dims() { + %v0 = arith.constant 1 : i32 + %v1 = arith.constant 2 : i32 + // expected-error @below {{dims values can only be specified with dims modifier}} + "omp.target" (%v0, %v1) ({ + omp.terminator + }) {operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2,0>} : (i32, i32) -> () + return +} + +// ----- + +func.func @omp_target_thread_limit_dims_type_mismatch() { + %v0 = arith.constant 1 : i32 + %v1 = arith.constant 2 : i64 + // expected-error @below {{dims modifier requires all values to have the same type}} + "omp.target" (%v0, %v1) ({ + omp.terminator + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2,0>} : (i32, i64) -> () + return +} + +// ----- + func.func @omp_sections(%data_var : memref<i32>) -> () { // expected-error @below {{expected equal sizes for allocate and allocator variables}} "omp.sections" (%data_var) ({ @@ -2533,7 +2666,7 @@ func.func @omp_target_depend(%data_var: memref<i32>) { // expected-error @below {{op expected as many depend values as depend variables}} "omp.target"(%data_var) ({ "omp.terminator"() : () -> () - }) {depend_kinds = [], operandSegmentSizes = array<i32: 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>} : (memref<i32>) -> () + }) {depend_kinds = [], operandSegmentSizes = array<i32: 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>} : (memref<i32>) -> () "func.return"() : () -> () } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir index 3633a4be1eb62..a1146fbb263e6 100644 --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -823,7 +823,7 @@ func.func @omp_target(%if_cond : i1, %device : si32, %num_threads : i32, %devic "omp.target"(%device, %if_cond, %num_threads) ({ // CHECK: omp.terminator omp.terminator - }) {nowait, operandSegmentSizes = array<i32: 0,0,0,1,0,0,1,0,0,0,0,1>} : ( si32, i1, i32 ) -> () + }) {nowait, operandSegmentSizes = array<i32: 0,0,0,1,0,0,1,0,0,0,0,0,1>} : ( si32, i1, i32 ) -> () // Test with optional map clause. // CHECK: %[[MAP_A:.*]] = omp.map.info var_ptr(%[[VAL_1:.*]] : memref<?xi32>, tensor<?xi32>) map_clauses(always, to) capture(ByRef) -> memref<?xi32> {name = ""} @@ -1128,6 +1128,12 @@ func.func @omp_teams(%lb : i32, %ub : i32, %if_cond : i1, %num_threads : i32, omp.terminator } + // CHECK: omp.teams thread_limit(dims(2): %{{.*}}, %{{.*}} : i32) + omp.teams thread_limit(dims(2): %lb, %ub : i32) { + // CHECK: omp.terminator + omp.terminator + } + // Test reduction. %c1 = arith.constant 1 : i32 %0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr >From 6acbc14e66de2c21b30c89667ab3ca92dbc15b85 Mon Sep 17 00:00:00 2001 From: skc7 <[email protected]> Date: Thu, 11 Dec 2025 18:35:55 +0530 Subject: [PATCH 3/4] update thread_limit description --- mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td index ae0e2479d1d00..32e6c92d3da18 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td @@ -1465,7 +1465,18 @@ class OpenMP_ThreadLimitClauseSkip< }]; let description = [{ - The optional `thread_limit` specifies the limit on the number of threads. + The `thread_limit` clause specifies the limit on the number of threads. + + With dims modifier: + - The number of dimensions is specified by the `thread_limit_num_dims` attribute. + - The values for each dimension are specified by the `thread_limit_dims_values` attribute. + - Format: `thread_limit(dims(N): values : type)` + - Example: `thread_limit(dims(2): %n, %m : i64)` + + Without dims modifier: + - The number of threads is specified by the `thread_limit`. + - Format: `thread_limit(number_of_threads : type)` + - Example: `thread_limit(%n : i64)` }]; let extraClassDeclaration = [{ >From 7613ab21cf20b6a50503d9d800f25bf56dde0096 Mon Sep 17 00:00:00 2001 From: skc7 <[email protected]> Date: Wed, 17 Dec 2025 09:06:36 +0530 Subject: [PATCH 4/4] Remove separate thread_limit argument from clause --- flang/lib/Lower/OpenMP/ClauseProcessor.cpp | 3 +- flang/lib/Lower/OpenMP/OpenMP.cpp | 16 ++-- .../Optimizer/OpenMP/LowerWorkdistribute.cpp | 8 +- .../mlir/Dialect/OpenMP/OpenMPClauses.td | 16 ++-- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 74 ++++++++----------- .../OpenMP/OpenMPToLLVMIRTranslation.cpp | 11 +-- mlir/test/Dialect/OpenMP/invalid.mlir | 38 +++++----- mlir/test/Dialect/OpenMP/ops.mlir | 2 +- 8 files changed, 78 insertions(+), 90 deletions(-) diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index 3c31b3a07f57f..b1c0053f149ec 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -666,8 +666,9 @@ bool ClauseProcessor::processThreadLimit( lower::StatementContext &stmtCtx, mlir::omp::ThreadLimitClauseOps &result) const { if (auto *clause = findUniqueClause<omp::clause::ThreadLimit>()) { - result.threadLimit = + mlir::Value threadLimitVal = fir::getBase(converter.genExprValue(clause->v, stmtCtx)); + result.threadLimitDimsValues.push_back(threadLimitVal); return true; } return false; diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index 38ab42076f559..54acb252cdbba 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -102,8 +102,9 @@ class HostEvalInfo { if (ops.numThreads) vars.push_back(ops.numThreads); - if (ops.threadLimit) - vars.push_back(ops.threadLimit); + // Old spec: single value in threadLimitDimsValues + for (mlir::Value val : ops.threadLimitDimsValues) + vars.push_back(val); } /// Update \c ops, replacing all values with the corresponding block argument @@ -116,7 +117,7 @@ class HostEvalInfo { ops.loopLowerBounds.size() + ops.loopUpperBounds.size() + ops.loopSteps.size() + (ops.numTeamsLower ? 1 : 0) + (ops.numTeamsUpper ? 1 : 0) + (ops.numThreads ? 1 : 0) + - (ops.threadLimit ? 1 : 0) && + ops.threadLimitDimsValues.size() && "invalid block argument list"); int argIndex = 0; for (size_t i = 0; i < ops.loopLowerBounds.size(); ++i) @@ -137,8 +138,8 @@ class HostEvalInfo { if (ops.numThreads) ops.numThreads = args[argIndex++]; - if (ops.threadLimit) - ops.threadLimit = args[argIndex++]; + for (size_t i = 0; i < ops.threadLimitDimsValues.size(); ++i) + ops.threadLimitDimsValues[i] = args[argIndex++]; } /// Update \p clauseOps and \p ivOut with the corresponding host-evaluated @@ -185,12 +186,13 @@ class HostEvalInfo { /// \returns whether an update was performed. If not, these clauses were not /// evaluated in the host device. bool apply(mlir::omp::TeamsOperands &clauseOps) { - if (!ops.numTeamsLower && !ops.numTeamsUpper && !ops.threadLimit) + if (!ops.numTeamsLower && !ops.numTeamsUpper && + ops.threadLimitDimsValues.empty()) return false; clauseOps.numTeamsLower = ops.numTeamsLower; clauseOps.numTeamsUpper = ops.numTeamsUpper; - clauseOps.threadLimit = ops.threadLimit; + clauseOps.threadLimitDimsValues = ops.threadLimitDimsValues; return true; } diff --git a/flang/lib/Optimizer/OpenMP/LowerWorkdistribute.cpp b/flang/lib/Optimizer/OpenMP/LowerWorkdistribute.cpp index a3b9e5c76bdd2..4d3fec3b0710f 100644 --- a/flang/lib/Optimizer/OpenMP/LowerWorkdistribute.cpp +++ b/flang/lib/Optimizer/OpenMP/LowerWorkdistribute.cpp @@ -767,7 +767,7 @@ FailureOr<omp::TargetOp> splitTargetData(omp::TargetOp targetOp, innerMapInfos, targetOp.getNowaitAttr(), targetOp.getPrivateVars(), targetOp.getPrivateSymsAttr(), targetOp.getPrivateNeedsBarrierAttr(), targetOp.getThreadLimitNumDimsAttr(), targetOp.getThreadLimitDimsValues(), - targetOp.getThreadLimit(), targetOp.getPrivateMapsAttr()); + targetOp.getPrivateMapsAttr()); rewriter.inlineRegionBefore(targetOp.getRegion(), newTargetOp.getRegion(), newTargetOp.getRegion().begin()); rewriter.replaceOp(targetOp, targetDataOp); @@ -1488,7 +1488,7 @@ genPreTargetOp(omp::TargetOp targetOp, SmallVector<Value> &preMapOperands, targetOp.getPrivateVars(), targetOp.getPrivateSymsAttr(), targetOp.getPrivateNeedsBarrierAttr(), targetOp.getThreadLimitNumDimsAttr(), targetOp.getThreadLimitDimsValues(), - targetOp.getThreadLimit(), targetOp.getPrivateMapsAttr()); + targetOp.getPrivateMapsAttr()); auto *preTargetBlock = rewriter.createBlock( &preTargetOp.getRegion(), preTargetOp.getRegion().begin(), {}, {}); IRMapping preMapping; @@ -1579,7 +1579,7 @@ genIsolatedTargetOp(omp::TargetOp targetOp, SmallVector<Value> &postMapOperands, targetOp.getPrivateVars(), targetOp.getPrivateSymsAttr(), targetOp.getPrivateNeedsBarrierAttr(), targetOp.getThreadLimitNumDimsAttr(), targetOp.getThreadLimitDimsValues(), - targetOp.getThreadLimit(), targetOp.getPrivateMapsAttr()); + targetOp.getPrivateMapsAttr()); auto *isolatedTargetBlock = rewriter.createBlock(&isolatedTargetOp.getRegion(), isolatedTargetOp.getRegion().begin(), {}, {}); @@ -1660,7 +1660,7 @@ static omp::TargetOp genPostTargetOp(omp::TargetOp targetOp, targetOp.getPrivateVars(), targetOp.getPrivateSymsAttr(), targetOp.getPrivateNeedsBarrierAttr(), targetOp.getThreadLimitNumDimsAttr(), targetOp.getThreadLimitDimsValues(), - targetOp.getThreadLimit(), targetOp.getPrivateMapsAttr()); + targetOp.getPrivateMapsAttr()); // Create the block for postTargetOp auto *postTargetBlock = rewriter.createBlock( &postTargetOp.getRegion(), postTargetOp.getRegion().begin(), {}, {}); diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td index 32e6c92d3da18..f39236aee0dca 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td @@ -1453,14 +1453,12 @@ class OpenMP_ThreadLimitClauseSkip< extraClassDeclaration> { let arguments = (ins ConfinedAttr<OptionalAttr<I64Attr>, [IntPositive]>:$thread_limit_num_dims, - Variadic<AnyInteger>:$thread_limit_dims_values, - Optional<AnyInteger>:$thread_limit + Variadic<AnyInteger>:$thread_limit_dims_values ); let optAssemblyFormat = [{ `thread_limit` `(` custom<ThreadLimitClause>( - $thread_limit_num_dims, $thread_limit_dims_values, type($thread_limit_dims_values), - $thread_limit, type($thread_limit) + $thread_limit_num_dims, $thread_limit_dims_values, type($thread_limit_dims_values) ) `)` }]; @@ -1468,14 +1466,14 @@ class OpenMP_ThreadLimitClauseSkip< The `thread_limit` clause specifies the limit on the number of threads. With dims modifier: - - The number of dimensions is specified by the `thread_limit_num_dims` attribute. - - The values for each dimension are specified by the `thread_limit_dims_values` attribute. + - The number of dimensions is specified by the `thread_limit_num_dims`. + - The values for each dimension are specified by the `thread_limit_dims_values`. - Format: `thread_limit(dims(N): values : type)` - Example: `thread_limit(dims(2): %n, %m : i64)` Without dims modifier: - - The number of threads is specified by the `thread_limit`. - - Format: `thread_limit(number_of_threads : type)` + - The number of threads is specified by the single value in `thread_limit_dims_values`. + - Format: `thread_limit(value : type)` - Example: `thread_limit(%n : i64)` }]; @@ -1497,6 +1495,8 @@ class OpenMP_ThreadLimitClauseSkip< ::mlir::Value getThreadLimitDimensionValue(unsigned index) { assert(index < getThreadLimitDimsCount() && "Thread limit dims index out of bounds"); + if (getThreadLimitDimsValues().empty()) + return nullptr; return getThreadLimitDimsValues()[index]; } }]; diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index 26cddace26c7c..6009b46f69d40 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -2245,7 +2245,7 @@ void TargetOp::build(OpBuilder &builder, OperationState &state, clauses.mapVars, clauses.nowait, clauses.privateVars, makeArrayAttr(ctx, clauses.privateSyms), clauses.privateNeedsBarrier, clauses.threadLimitNumDims, - clauses.threadLimitDimsValues, clauses.threadLimit, + clauses.threadLimitDimsValues, /*private_maps=*/nullptr); } @@ -2253,15 +2253,7 @@ void TargetOp::build(OpBuilder &builder, OperationState &state, static LogicalResult verifyThreadLimitClause(Operation *op, std::optional<IntegerAttr> threadLimitNumDims, - OperandRange threadLimitDimsValues, Value threadLimit) { - bool hasDimsModifier = - threadLimitNumDims.has_value() && threadLimitNumDims.value(); - - if (hasDimsModifier && threadLimit) { - return op->emitError("thread_limit with dims modifier cannot be used " - "together with number of threads"); - } - + OperandRange threadLimitDimsValues) { if (failed(verifyDimsModifier(op, threadLimitNumDims, threadLimitDimsValues))) return failure(); @@ -2280,8 +2272,7 @@ LogicalResult TargetOp::verify() { return failure(); if (failed(verifyThreadLimitClause(*this, getThreadLimitNumDimsAttr(), - getThreadLimitDimsValues(), - getThreadLimit()))) + getThreadLimitDimsValues()))) return failure(); return verifyPrivateVarsMapping(*this); @@ -2299,10 +2290,9 @@ LogicalResult TargetOp::verifyRegions() { cast<BlockArgOpenMPOpInterface>(getOperation()).getHostEvalBlockArgs()) { for (Operation *user : hostEvalArg.getUsers()) { if (auto teamsOp = dyn_cast<TeamsOp>(user)) { - if (llvm::is_contained({teamsOp.getNumTeamsLower(), - teamsOp.getNumTeamsUpper(), - teamsOp.getThreadLimit()}, - hostEvalArg)) + if (teamsOp.getNumTeamsLower() == hostEvalArg || + teamsOp.getNumTeamsUpper() == hostEvalArg || + llvm::is_contained(teamsOp.getThreadLimitDimsValues(), hostEvalArg)) continue; return emitOpError() << "host_eval argument only legal as 'num_teams' " @@ -2683,16 +2673,16 @@ void TeamsOp::build(OpBuilder &builder, OperationState &state, const TeamsOperands &clauses) { MLIRContext *ctx = builder.getContext(); // TODO Store clauses in op: privateVars, privateSyms, privateNeedsBarrier - TeamsOp::build( - builder, state, clauses.allocateVars, clauses.allocatorVars, - clauses.ifExpr, clauses.numTeamsNumDims, clauses.numTeamsDimsValues, - clauses.numTeamsLower, clauses.numTeamsUpper, - /*private_vars=*/{}, /*private_syms=*/nullptr, - /*private_needs_barrier=*/nullptr, clauses.reductionMod, - clauses.reductionVars, - makeDenseBoolArrayAttr(ctx, clauses.reductionByref), - makeArrayAttr(ctx, clauses.reductionSyms), clauses.threadLimitNumDims, - clauses.threadLimitDimsValues, clauses.threadLimit); + TeamsOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars, + clauses.ifExpr, clauses.numTeamsNumDims, + clauses.numTeamsDimsValues, clauses.numTeamsLower, + clauses.numTeamsUpper, + /*private_vars=*/{}, /*private_syms=*/nullptr, + /*private_needs_barrier=*/nullptr, clauses.reductionMod, + clauses.reductionVars, + makeDenseBoolArrayAttr(ctx, clauses.reductionByref), + makeArrayAttr(ctx, clauses.reductionSyms), + clauses.threadLimitNumDims, clauses.threadLimitDimsValues); } // Helper: Verify num_teams clause @@ -2754,8 +2744,7 @@ LogicalResult TeamsOp::verify() { // Check for thread_limit clause restrictions if (failed(verifyThreadLimitClause(*this, getThreadLimitNumDimsAttr(), - getThreadLimitDimsValues(), - getThreadLimit()))) + getThreadLimitDimsValues()))) return failure(); return verifyReductionVarList(*this, getReductionSyms(), getReductionVars(), @@ -4690,34 +4679,29 @@ static void printNumTeamsClause(OpAsmPrinter &p, Operation *op, static ParseResult parseThreadLimitClause(OpAsmParser &parser, IntegerAttr &dimsAttr, SmallVectorImpl<OpAsmParser::UnresolvedOperand> &values, - SmallVectorImpl<Type> &types, - std::optional<OpAsmParser::UnresolvedOperand> &bounds, - Type &boundsType) { + SmallVectorImpl<Type> &types) { + // Try parsing with dims modifier: dims(N): values : type if (succeeded(parseDimsModifierWithValues(parser, dimsAttr, values, types))) { return success(); } - OpAsmParser::UnresolvedOperand boundsOperand; - if (parser.parseOperand(boundsOperand) || parser.parseColon() || - parser.parseType(boundsType)) { + // Without dims modifier: value : type + OpAsmParser::UnresolvedOperand singleValue; + Type singleType; + if (parser.parseOperand(singleValue) || parser.parseColon() || + parser.parseType(singleType)) { return failure(); } - bounds = boundsOperand; + values.push_back(singleValue); + types.push_back(singleType); return success(); } static void printThreadLimitClause(OpAsmPrinter &p, Operation *op, IntegerAttr dimsAttr, OperandRange values, - TypeRange types, Value bounds, - Type boundsType) { - if (!values.empty()) { - // Multidimensional: dims(N): values : type - printDimsModifierWithValues(p, dimsAttr, values, types); - } else if (bounds) { - // Both bounds: bounds : type - p.printOperand(bounds); - p << " : " << boundsType; - } + TypeRange types) { + // Multidimensional: dims(N): values : type + printDimsModifierWithValues(p, dimsAttr, values, types); } #define GET_ATTRDEF_CLASSES diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index 6c4ff65dff8fc..2771b0428131a 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -2024,7 +2024,7 @@ convertOmpTeams(omp::TeamsOp op, llvm::IRBuilderBase &builder, numTeamsUpper = moduleTranslation.lookupValue(numTeamsUpperVar); llvm::Value *threadLimit = nullptr; - if (Value threadLimitVar = op.getThreadLimit()) + if (Value threadLimitVar = op.getThreadLimitDimensionValue(0)) threadLimit = moduleTranslation.lookupValue(threadLimitVar); llvm::Value *ifExpr = nullptr; @@ -5654,7 +5654,7 @@ extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads, numTeamsLower = hostEvalVar; else if (teamsOp.getNumTeamsUpper() == blockArg) numTeamsUpper = hostEvalVar; - else if (teamsOp.getThreadLimit() == blockArg) + else if (teamsOp.getThreadLimitDimensionValue(0) == blockArg) threadLimit = hostEvalVar; else llvm_unreachable("unsupported host_eval use"); @@ -5779,7 +5779,7 @@ initTargetDefaultAttrs(omp::TargetOp targetOp, Operation *capturedOp, "Lowering of thread_limit with dims modifier is NYI."); numTeamsLower = teamsOp.getNumTeamsLower(); numTeamsUpper = teamsOp.getNumTeamsUpper(); - threadLimit = teamsOp.getThreadLimit(); + threadLimit = teamsOp.getThreadLimitDimensionValue(0); } if (auto parallelOp = castOrGetParentOfType<omp::ParallelOp>(capturedOp)) @@ -5824,7 +5824,8 @@ initTargetDefaultAttrs(omp::TargetOp targetOp, Operation *capturedOp, // Extract 'thread_limit' clause from 'target' and 'teams' directives. int32_t targetThreadLimitVal = -1, teamsThreadLimitVal = -1; - setMaxValueFromClause(targetOp.getThreadLimit(), targetThreadLimitVal); + setMaxValueFromClause(targetOp.getThreadLimitDimensionValue(0), + targetThreadLimitVal); setMaxValueFromClause(threadLimit, teamsThreadLimitVal); // Extract 'max_threads' clause from 'parallel' or set to 1 if it's SIMD. @@ -5903,7 +5904,7 @@ initTargetRuntimeAttrs(llvm::IRBuilderBase &builder, teamsThreadLimit, &lowerBounds, &upperBounds, &steps); // TODO: Handle constant 'if' clauses. - if (Value targetThreadLimit = targetOp.getThreadLimit()) + if (Value targetThreadLimit = targetOp.getThreadLimitDimensionValue(0)) attrs.TargetThreadLimit.front() = moduleTranslation.lookupValue(targetThreadLimit); diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir b/mlir/test/Dialect/OpenMP/invalid.mlir index 7f69ca5aaa064..7d4668d213e6f 100644 --- a/mlir/test/Dialect/OpenMP/invalid.mlir +++ b/mlir/test/Dialect/OpenMP/invalid.mlir @@ -1438,7 +1438,7 @@ func.func @omp_teams_allocate(%data_var : memref<i32>) { // expected-error @below {{expected equal sizes for allocate and allocator variables}} "omp.teams" (%data_var) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 1,0,0,0,0,0,0,0,0,0>} : (memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 1,0,0,0,0,0,0,0,0>} : (memref<i32>) -> () omp.terminator } return @@ -1451,7 +1451,7 @@ func.func @omp_teams_num_teams1(%lb : i32) { // expected-error @below {{expected num_teams upper bound to be defined if the lower bound is defined}} "omp.teams" (%lb) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 0,0,0,0,1,0,0,0,0,0>} : (i32) -> () + }) {operandSegmentSizes = array<i32: 0,0,0,0,1,0,0,0,0>} : (i32) -> () omp.terminator } return @@ -1466,7 +1466,7 @@ func.func @omp_teams_num_teams_dims_mismatch() { // expected-error @below {{dims(3) specified but 2 values provided}} "omp.teams" (%v0, %v1) ({ omp.terminator - }) {num_teams_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0,0>} : (i32, i32) -> () + }) {num_teams_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0>} : (i32, i32) -> () omp.terminator } return @@ -1483,7 +1483,7 @@ func.func @omp_teams_num_teams_dims_with_bounds() { // expected-error @below {{num_teams with dims modifier cannot be used together with lower/upper bounds}} "omp.teams" (%v0, %v1, %lb, %ub) ({ omp.terminator - }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,2,1,1,0,0,0,0>} : (i32, i32, i32, i32) -> () + }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,2,1,1,0,0,0>} : (i32, i32, i32, i32) -> () omp.terminator } return @@ -1498,7 +1498,7 @@ func.func @omp_teams_num_teams_values_without_dims() { // expected-error @below {{dims values can only be specified with dims modifier}} "omp.teams" (%v0, %v1) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0,0>} : (i32, i32) -> () + }) {operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0>} : (i32, i32) -> () omp.terminator } return @@ -1511,7 +1511,7 @@ func.func @omp_teams_num_teams_dims_no_values() { // expected-error @below {{dims modifier requires values to be specified}} "omp.teams" () ({ omp.terminator - }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0>} : () -> () + }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0>} : () -> () omp.terminator } return @@ -1526,7 +1526,7 @@ func.func @omp_teams_num_teams_dims_type_mismatch() { // expected-error @below {{dims modifier requires all values to have the same type}} "omp.teams" (%v0, %v1) ({ omp.terminator - }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0,0>} : (i32, i64) -> () + }) {num_teams_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,2,0,0,0,0,0>} : (i32, i64) -> () omp.terminator } return @@ -1554,7 +1554,7 @@ func.func @omp_teams_thread_limit_dims_mismatch() { // expected-error @below {{dims(3) specified but 2 values provided}} "omp.teams" (%v0, %v1) ({ omp.terminator - }) {thread_limit_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2,0>} : (i32, i32) -> () + }) {thread_limit_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2>} : (i32, i32) -> () omp.terminator } return @@ -1567,10 +1567,10 @@ func.func @omp_teams_thread_limit_dims_with_scalar() { %v0 = arith.constant 1 : i32 %v1 = arith.constant 2 : i32 %tl = arith.constant 4 : i32 - // expected-error @below {{thread_limit with dims modifier cannot be used together with number of threads}} + // expected-error @below {{dims(2) specified but 3 values provided}} "omp.teams" (%v0, %v1, %tl) ({ omp.terminator - }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2,1>} : (i32, i32, i32) -> () + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,3>} : (i32, i32, i32) -> () omp.terminator } return @@ -1598,7 +1598,7 @@ func.func @omp_teams_thread_limit_values_without_dims() { // expected-error @below {{dims values can only be specified with dims modifier}} "omp.teams" (%v0, %v1) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2,0>} : (i32, i32) -> () + }) {operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2>} : (i32, i32) -> () omp.terminator } return @@ -1613,7 +1613,7 @@ func.func @omp_teams_thread_limit_dims_type_mismatch() { // expected-error @below {{dims modifier requires all values to have the same type}} "omp.teams" (%v0, %v1) ({ omp.terminator - }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2,0>} : (i32, i64) -> () + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,2>} : (i32, i64) -> () omp.terminator } return @@ -1627,7 +1627,7 @@ func.func @omp_target_thread_limit_dims_mismatch() { // expected-error @below {{dims(3) specified but 2 values provided}} "omp.target" (%v0, %v1) ({ omp.terminator - }) {thread_limit_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2,0>} : (i32, i32) -> () + }) {thread_limit_num_dims = 3 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2>} : (i32, i32) -> () return } @@ -1637,10 +1637,10 @@ func.func @omp_target_thread_limit_dims_with_scalar() { %v0 = arith.constant 1 : i32 %v1 = arith.constant 2 : i32 %tl = arith.constant 4 : i32 - // expected-error @below {{thread_limit with dims modifier cannot be used together with number of threads}} + // expected-error @below {{dims(2) specified but 3 values provided}} "omp.target" (%v0, %v1, %tl) ({ omp.terminator - }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2,1>} : (i32, i32, i32) -> () + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,3>} : (i32, i32, i32) -> () return } @@ -1650,7 +1650,7 @@ func.func @omp_target_thread_limit_dims_no_values() { // expected-error @below {{dims modifier requires values to be specified}} "omp.target" () ({ omp.terminator - }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,0,0>} : () -> () + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,0>} : () -> () return } @@ -1662,7 +1662,7 @@ func.func @omp_target_thread_limit_values_without_dims() { // expected-error @below {{dims values can only be specified with dims modifier}} "omp.target" (%v0, %v1) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2,0>} : (i32, i32) -> () + }) {operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2>} : (i32, i32) -> () return } @@ -1674,7 +1674,7 @@ func.func @omp_target_thread_limit_dims_type_mismatch() { // expected-error @below {{dims modifier requires all values to have the same type}} "omp.target" (%v0, %v1) ({ omp.terminator - }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2,0>} : (i32, i64) -> () + }) {thread_limit_num_dims = 2 : i64, operandSegmentSizes = array<i32: 0,0,0,0,0,0,0,0,0,0,0,2>} : (i32, i64) -> () return } @@ -2666,7 +2666,7 @@ func.func @omp_target_depend(%data_var: memref<i32>) { // expected-error @below {{op expected as many depend values as depend variables}} "omp.target"(%data_var) ({ "omp.terminator"() : () -> () - }) {depend_kinds = [], operandSegmentSizes = array<i32: 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>} : (memref<i32>) -> () + }) {depend_kinds = [], operandSegmentSizes = array<i32: 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>} : (memref<i32>) -> () "func.return"() : () -> () } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir index a1146fbb263e6..a7d043404e37b 100644 --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -823,7 +823,7 @@ func.func @omp_target(%if_cond : i1, %device : si32, %num_threads : i32, %devic "omp.target"(%device, %if_cond, %num_threads) ({ // CHECK: omp.terminator omp.terminator - }) {nowait, operandSegmentSizes = array<i32: 0,0,0,1,0,0,1,0,0,0,0,0,1>} : ( si32, i1, i32 ) -> () + }) {nowait, operandSegmentSizes = array<i32: 0,0,0,1,0,0,1,0,0,0,0,1>} : ( si32, i1, i32 ) -> () // Test with optional map clause. // CHECK: %[[MAP_A:.*]] = omp.map.info var_ptr(%[[VAL_1:.*]] : memref<?xi32>, tensor<?xi32>) map_clauses(always, to) capture(ByRef) -> memref<?xi32> {name = ""} _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
