https://github.com/skatrak updated https://github.com/llvm/llvm-project/pull/99507
>From c80e6f18eabfc05804c1ac5320bf12af756f5b79 Mon Sep 17 00:00:00 2001 From: Sergio Afonso <safon...@amd.com> Date: Tue, 16 Jul 2024 17:18:13 +0100 Subject: [PATCH] [MLIR][OpenMP] Add missing clauses to OpenMP op definitions This patch adds the missing `OpenMP_Clause` definitions to all existing `OpenMP_Op`s and updates their operand structure based builders to initialize the new arguments. The result of this change is that operation operand structures are now based in the same list of clauses as their tablegen counterparts. This means that all of the information needed is now in place to automatically generate OpenMP operand structures from tablegen defitions. Since this change doesn't involve the introduction of actual support for these clauses, new arguments are not initialized from values stored in the corresponding operand structure fields but rather set to empty or null. Those should be updated when support for these clauses on the corresponding operation is added. --- .../Dialect/OpenMP/OpenMPClauseOperands.h | 7 +-- mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 52 +++++++++-------- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 49 ++++++++++------ .../OpenMP/OpenMPToLLVMIRTranslation.cpp | 57 ++++++++++++++++--- mlir/test/Dialect/OpenMP/invalid.mlir | 40 ++++++------- mlir/test/Dialect/OpenMP/ops.mlir | 26 ++++----- 6 files changed, 144 insertions(+), 87 deletions(-) diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h index a680a85db0f25..38e4d8f245e4f 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h @@ -272,11 +272,10 @@ using ParallelOperands = using SectionsOperands = detail::Clauses<AllocateClauseOps, NowaitClauseOps, PrivateClauseOps, ReductionClauseOps>; -// TODO `linear` clause. using SimdOperands = - detail::Clauses<AlignedClauseOps, IfClauseOps, NontemporalClauseOps, - OrderClauseOps, PrivateClauseOps, ReductionClauseOps, - SafelenClauseOps, SimdlenClauseOps>; + detail::Clauses<AlignedClauseOps, IfClauseOps, LinearClauseOps, + NontemporalClauseOps, OrderClauseOps, PrivateClauseOps, + ReductionClauseOps, SafelenClauseOps, SimdlenClauseOps>; using SingleOperands = detail::Clauses<AllocateClauseOps, CopyprivateClauseOps, NowaitClauseOps, PrivateClauseOps>; diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 00dadc6e6538d..16b6f624ce042 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -195,10 +195,9 @@ def TerminatorOp : OpenMP_Op<"terminator", [Terminator, Pure]> { def TeamsOp : OpenMP_Op<"teams", traits = [ AttrSizedOperandSegments, RecursiveMemoryEffects ], clauses = [ - // TODO: Complete clause list (private). // TODO: Sort clauses alphabetically. OpenMP_NumTeamsClause, OpenMP_IfClause, OpenMP_ThreadLimitClause, - OpenMP_AllocateClause, OpenMP_ReductionClause + OpenMP_AllocateClause, OpenMP_ReductionClause, OpenMP_PrivateClause ], singleRegion = true> { let summary = "teams construct"; let description = [{ @@ -238,9 +237,9 @@ def SectionOp : OpenMP_Op<"section", [HasParent<"SectionsOp">], def SectionsOp : OpenMP_Op<"sections", traits = [ AttrSizedOperandSegments ], clauses = [ - // TODO: Complete clause list (private). // TODO: Sort clauses alphabetically. - OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause + OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause, + OpenMP_PrivateClause ], singleRegion = true> { let summary = "sections construct"; let description = [{ @@ -271,8 +270,8 @@ def SectionsOp : OpenMP_Op<"sections", traits = [ def SingleOp : OpenMP_Op<"single", traits = [ AttrSizedOperandSegments ], clauses = [ - // TODO: Complete clause list (private). - OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause + OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause, + OpenMP_PrivateClause ], singleRegion = true> { let summary = "single directive"; let description = [{ @@ -363,14 +362,15 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [ AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>, RecursiveMemoryEffects, SingleBlock ], clauses = [ - // TODO: Complete clause list (allocate, private). // TODO: Sort clauses alphabetically. OpenMP_LinearClauseSkip<assemblyFormat = true>, OpenMP_ReductionClauseSkip<assemblyFormat = true>, OpenMP_ScheduleClauseSkip<assemblyFormat = true>, OpenMP_NowaitClauseSkip<assemblyFormat = true>, OpenMP_OrderedClauseSkip<assemblyFormat = true>, - OpenMP_OrderClauseSkip<assemblyFormat = true> + OpenMP_OrderClauseSkip<assemblyFormat = true>, + OpenMP_AllocateClauseSkip<assemblyFormat = true>, + OpenMP_PrivateClauseSkip<assemblyFormat = true> ], singleRegion = true> { let summary = "worksharing-loop construct"; let description = [{ @@ -417,6 +417,13 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [ |`nowait` $nowait |`ordered` `(` $ordered `)` |`order` `(` custom<OrderClause>($order, $order_mod) `)` + |`allocate` `(` + custom<AllocateAndAllocator>( + $allocate_vars, type($allocate_vars), $allocator_vars, + type($allocator_vars)) `)` + |`private` `(` + custom<PrivateList>( + $private_vars, type($private_vars), $private_syms) `)` ) custom<Wsloop>($region, $reduction_vars, type($reduction_vars), $reduction_byref, $reduction_syms) attr-dict }]; @@ -432,9 +439,9 @@ def SimdOp : OpenMP_Op<"simd", traits = [ AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>, RecursiveMemoryEffects, SingleBlock ], clauses = [ - // TODO: Complete clause list (linear, private, reduction). - OpenMP_AlignedClause, OpenMP_IfClause, OpenMP_NontemporalClause, - OpenMP_OrderClause, OpenMP_SafelenClause, OpenMP_SimdlenClause + OpenMP_AlignedClause, OpenMP_IfClause, OpenMP_LinearClause, + OpenMP_NontemporalClause, OpenMP_OrderClause, OpenMP_PrivateClause, + OpenMP_ReductionClause, OpenMP_SafelenClause, OpenMP_SimdlenClause ], singleRegion = true> { let summary = "simd construct"; let description = [{ @@ -499,9 +506,9 @@ def DistributeOp : OpenMP_Op<"distribute", traits = [ AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>, RecursiveMemoryEffects, SingleBlock ], clauses = [ - // TODO: Complete clause list (private). // TODO: Sort clauses alphabetically. - OpenMP_DistScheduleClause, OpenMP_AllocateClause, OpenMP_OrderClause + OpenMP_DistScheduleClause, OpenMP_AllocateClause, OpenMP_OrderClause, + OpenMP_PrivateClause ], singleRegion = true> { let summary = "distribute construct"; let description = [{ @@ -552,11 +559,12 @@ def TaskOp : OpenMP_Op<"task", traits = [ AttrSizedOperandSegments, AutomaticAllocationScope, OutlineableOpenMPOpInterface ], clauses = [ - // TODO: Complete clause list (affinity, detach, private). + // TODO: Complete clause list (affinity, detach). // TODO: Sort clauses alphabetically. OpenMP_IfClause, OpenMP_FinalClause, OpenMP_UntiedClause, OpenMP_MergeableClause, OpenMP_InReductionClause, - OpenMP_PriorityClause, OpenMP_DependClause, OpenMP_AllocateClause + OpenMP_PriorityClause, OpenMP_DependClause, OpenMP_AllocateClause, + OpenMP_PrivateClause ], singleRegion = true> { let summary = "task construct"; let description = [{ @@ -589,14 +597,13 @@ def TaskloopOp : OpenMP_Op<"taskloop", traits = [ DeclareOpInterfaceMethods<LoopWrapperInterface>, RecursiveMemoryEffects, SingleBlock ], clauses = [ - // TODO: Complete clause list (private). // TODO: Sort clauses alphabetically. OpenMP_IfClause, OpenMP_FinalClause, OpenMP_UntiedClause, OpenMP_MergeableClause, OpenMP_InReductionClauseSkip<extraClassDeclaration = true>, OpenMP_ReductionClauseSkip<extraClassDeclaration = true>, OpenMP_PriorityClause, OpenMP_AllocateClause, OpenMP_GrainsizeClause, - OpenMP_NumTasksClause, OpenMP_NogroupClause + OpenMP_NumTasksClause, OpenMP_NogroupClause, OpenMP_PrivateClause ], singleRegion = true> { let summary = "taskloop construct"; let description = [{ @@ -1076,12 +1083,12 @@ def TargetUpdateOp: OpenMP_Op<"target_update", traits = [ def TargetOp : OpenMP_Op<"target", traits = [ AttrSizedOperandSegments, IsolatedFromAbove, OutlineableOpenMPOpInterface ], clauses = [ - // TODO: Complete clause list (allocate, defaultmap, in_reduction, - // uses_allocators). + // TODO: Complete clause list (defaultmap, uses_allocators). // TODO: Sort clauses alphabetically. OpenMP_IfClause, OpenMP_DeviceClause, OpenMP_ThreadLimitClause, OpenMP_DependClause, OpenMP_NowaitClause, OpenMP_IsDevicePtrClause, - OpenMP_HasDeviceAddrClause, OpenMP_MapClause, OpenMP_PrivateClause + OpenMP_HasDeviceAddrClause, OpenMP_MapClause, OpenMP_PrivateClause, + OpenMP_AllocateClause, OpenMP_InReductionClause ], singleRegion = true> { let summary = "target construct"; let description = [{ @@ -1207,7 +1214,7 @@ def OrderedRegionOp : OpenMP_Op<"ordered.region", clauses = [ //===----------------------------------------------------------------------===// def TaskwaitOp : OpenMP_Op<"taskwait", clauses = [ - // TODO: Complete clause list (depend, nowait). + OpenMP_DependClause, OpenMP_NowaitClause ]> { let summary = "taskwait construct"; let description = [{ @@ -1218,9 +1225,6 @@ def TaskwaitOp : OpenMP_Op<"taskwait", clauses = [ let builders = [ OpBuilder<(ins CArg<"const TaskwaitOperands &">:$clauses)> ]; - - // TODO: Remove overriden `assemblyFormat` once a clause is added. - let assemblyFormat = "attr-dict"; } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index 84de63b7806dc..51e9dbe8c801d 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -1451,13 +1451,15 @@ void TargetOp::build(OpBuilder &builder, OperationState &state, const TargetOperands &clauses) { MLIRContext *ctx = builder.getContext(); // TODO Store clauses in op: allocateVars, allocatorVars, inReductionVars, - // inReduceVarByRef, inReductionDeclSymbols, reductionVars, reduceVarByRef, - // reductionDeclSymbols. + // inReductionByref, inReductionSyms. TargetOp::build(builder, state, clauses.ifVar, clauses.device, clauses.threadLimit, makeArrayAttr(ctx, clauses.dependKinds), clauses.dependVars, clauses.nowait, clauses.isDevicePtrVars, clauses.hasDeviceAddrVars, clauses.mapVars, - clauses.privateVars, makeArrayAttr(ctx, clauses.privateSyms)); + clauses.privateVars, makeArrayAttr(ctx, clauses.privateSyms), + /*allocate_vars=*/{}, /*allocator_vars=*/{}, + /*in_reduction_vars=*/{}, /*in_reduction_byref=*/nullptr, + /*in_reduction_syms=*/nullptr); } LogicalResult TargetOp::verify() { @@ -1584,7 +1586,8 @@ void TeamsOp::build(OpBuilder &builder, OperationState &state, clauses.ifVar, clauses.threadLimit, clauses.allocateVars, clauses.allocatorVars, clauses.reductionVars, makeDenseBoolArrayAttr(ctx, clauses.reductionByref), - makeArrayAttr(ctx, clauses.reductionSyms)); + makeArrayAttr(ctx, clauses.reductionSyms), /*private_vars=*/{}, + /*private_syms=*/nullptr); } LogicalResult TeamsOp::verify() { @@ -1630,8 +1633,8 @@ void SectionsOp::build(OpBuilder &builder, OperationState &state, SectionsOp::build(builder, state, clauses.reductionVars, makeDenseBoolArrayAttr(ctx, clauses.reductionByref), makeArrayAttr(ctx, clauses.reductionSyms), - clauses.allocateVars, clauses.allocatorVars, - clauses.nowait); + clauses.allocateVars, clauses.allocatorVars, clauses.nowait, + /*private_vars=*/{}, /*private_syms=*/nullptr); } LogicalResult SectionsOp::verify() { @@ -1664,7 +1667,8 @@ void SingleOp::build(OpBuilder &builder, OperationState &state, // TODO Store clauses in op: privateVars, privateSyms. SingleOp::build(builder, state, clauses.allocateVars, clauses.allocatorVars, clauses.copyprivateVars, - makeArrayAttr(ctx, clauses.copyprivateSyms), clauses.nowait); + makeArrayAttr(ctx, clauses.copyprivateSyms), clauses.nowait, + /*private_vars=*/{}, /*private_syms=*/nullptr); } LogicalResult SingleOp::verify() { @@ -1716,7 +1720,9 @@ void WsloopOp::build(OpBuilder &builder, OperationState &state, /*reduction_byref=*/nullptr, /*reduction_syms=*/nullptr, /*schedule_kind=*/nullptr, /*schedule_chunk=*/nullptr, /*schedule_mod=*/nullptr, /*schedule_simd=*/false, /*nowait=*/false, - /*ordered=*/nullptr, /*order=*/nullptr, /*order_mod=*/nullptr); + /*ordered=*/nullptr, /*order=*/nullptr, /*order_mod=*/nullptr, + /*allocate_vars=*/{}, /*allocator_vars=*/{}, /*private_vars=*/{}, + /*private_syms=*/nullptr); state.addAttributes(attributes); } @@ -1731,7 +1737,9 @@ void WsloopOp::build(OpBuilder &builder, OperationState &state, makeArrayAttr(ctx, clauses.reductionSyms), clauses.scheduleKind, clauses.scheduleChunk, clauses.scheduleMod, clauses.scheduleSimd, clauses.nowait, - clauses.ordered, clauses.order, clauses.orderMod); + clauses.ordered, clauses.order, clauses.orderMod, + /*allocate_vars=*/{}, /*allocator_vars=*/{}, + /*private_vars=*/{}, /*private_syms=*/nullptr); } LogicalResult WsloopOp::verify() { @@ -1756,12 +1764,15 @@ LogicalResult WsloopOp::verify() { void SimdOp::build(OpBuilder &builder, OperationState &state, const SimdOperands &clauses) { MLIRContext *ctx = builder.getContext(); - // TODO Store clauses in op: privateVars, privateSyms, reductionVars, - // reduceVarByRef, reductionDeclSymbols. + // TODO Store clauses in op: linearVars, linearStepVars, privateVars, + // privateSyms, reductionVars, reductionByref, reductionSyms. SimdOp::build(builder, state, clauses.alignedVars, makeArrayAttr(ctx, clauses.alignments), clauses.ifVar, + /*linear_vars=*/{}, /*linear_step_vars=*/{}, clauses.nontemporalVars, clauses.order, clauses.orderMod, - clauses.safelen, clauses.simdlen); + /*private_vars=*/{}, /*private_syms=*/nullptr, + /*reduction_vars=*/{}, /*reduction_byref=*/nullptr, + /*reduction_syms=*/nullptr, clauses.safelen, clauses.simdlen); } LogicalResult SimdOp::verify() { @@ -1795,7 +1806,8 @@ void DistributeOp::build(OpBuilder &builder, OperationState &state, // TODO Store clauses in op: privateVars, privateSyms. DistributeOp::build(builder, state, clauses.distScheduleStatic, clauses.distScheduleChunkSize, clauses.allocateVars, - clauses.allocatorVars, clauses.order, clauses.orderMod); + clauses.allocatorVars, clauses.order, clauses.orderMod, + /*private_vars=*/{}, /*private_syms=*/nullptr); } LogicalResult DistributeOp::verify() { @@ -1927,7 +1939,8 @@ void TaskOp::build(OpBuilder &builder, OperationState &state, makeDenseBoolArrayAttr(ctx, clauses.inReductionByref), makeArrayAttr(ctx, clauses.inReductionSyms), clauses.priority, makeArrayAttr(ctx, clauses.dependKinds), clauses.dependVars, - clauses.allocateVars, clauses.allocatorVars); + clauses.allocateVars, clauses.allocatorVars, + /*private_vars=*/{}, /*private_syms=*/nullptr); } LogicalResult TaskOp::verify() { @@ -1975,7 +1988,8 @@ void TaskloopOp::build(OpBuilder &builder, OperationState &state, makeDenseBoolArrayAttr(ctx, clauses.reductionByref), makeArrayAttr(ctx, clauses.reductionSyms), clauses.priority, clauses.allocateVars, clauses.allocatorVars, - clauses.grainsize, clauses.numTasks, clauses.nogroup); + clauses.grainsize, clauses.numTasks, clauses.nogroup, + /*private_vars=*/{}, /*private_syms=*/nullptr); } SmallVector<Value> TaskloopOp::getAllReductionVars() { @@ -2225,8 +2239,9 @@ LogicalResult OrderedRegionOp::verify() { void TaskwaitOp::build(OpBuilder &builder, OperationState &state, const TaskwaitOperands &clauses) { - // TODO Store clauses in op: dependTypeAttrs, dependVars, nowaitAttr. - TaskwaitOp::build(builder, state); + // TODO Store clauses in op: dependKinds, dependVars, nowait. + TaskwaitOp::build(builder, state, /*depend_kinds=*/nullptr, + /*depend_vars=*/{}, /*nowait=*/nullptr); } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index fe3f258156690..ddee117838697 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -837,9 +837,9 @@ convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder, // TODO: Support the following clauses: private, firstprivate, lastprivate, // allocate if (!sectionsOp.getAllocateVars().empty() || - !sectionsOp.getAllocatorVars().empty()) - return emitError(sectionsOp.getLoc()) - << "allocate clause is not supported for sections construct"; + !sectionsOp.getAllocatorVars().empty() || + !sectionsOp.getPrivateVars().empty() || sectionsOp.getPrivateSyms()) + return opInst.emitError("unhandled clauses for translation to LLVM IR"); llvm::ArrayRef<bool> isByRef = getIsByRef(sectionsOp.getReductionByref()); assert(isByRef.size() == sectionsOp.getNumReductionVars()); @@ -945,6 +945,9 @@ convertOmpSingle(omp::SingleOp &singleOp, llvm::IRBuilderBase &builder, using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy; llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder); LogicalResult bodyGenStatus = success(); + if (!singleOp.getPrivateVars().empty() || singleOp.getPrivateSyms()) + return singleOp.emitError("unhandled clauses for translation to LLVM IR"); + auto bodyCB = [&](InsertPointTy allocaIP, InsertPointTy codegenIP) { builder.restoreIP(codegenIP); convertOmpOpRegions(singleOp.getRegion(), "omp.single.region", builder, @@ -976,7 +979,8 @@ convertOmpTeams(omp::TeamsOp op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation) { using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy; LogicalResult bodyGenStatus = success(); - if (!op.getAllocatorVars().empty() || op.getReductionSyms()) + if (!op.getAllocatorVars().empty() || op.getReductionSyms() || + !op.getPrivateVars().empty() || op.getPrivateSyms()) return op.emitError("unhandled clauses for translation to LLVM IR"); auto bodyCB = [&](InsertPointTy allocaIP, InsertPointTy codegenIP) { @@ -1043,7 +1047,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder, LogicalResult bodyGenStatus = success(); if (taskOp.getUntiedAttr() || taskOp.getMergeableAttr() || taskOp.getInReductionSyms() || taskOp.getPriority() || - !taskOp.getAllocateVars().empty()) { + !taskOp.getAllocateVars().empty() || !taskOp.getPrivateVars().empty() || + taskOp.getPrivateSyms()) { return taskOp.emitError("unhandled clauses for translation to LLVM IR"); } auto bodyCB = [&](InsertPointTy allocaIP, InsertPointTy codegenIP) { @@ -1091,11 +1096,28 @@ convertOmpTaskgroupOp(omp::TaskgroupOp tgOp, llvm::IRBuilderBase &builder, ompLoc, allocaIP, bodyCB)); return bodyGenStatus; } + +static LogicalResult +convertOmpTaskwaitOp(omp::TaskwaitOp twOp, llvm::IRBuilderBase &builder, + LLVM::ModuleTranslation &moduleTranslation) { + if (!twOp.getDependVars().empty() || twOp.getDependKinds() || + twOp.getNowait()) + return twOp.emitError("unhandled clauses for translation to LLVM IR"); + + moduleTranslation.getOpenMPBuilder()->createTaskwait(builder.saveIP()); + return success(); +} + /// Converts an OpenMP workshare loop into LLVM IR using OpenMPIRBuilder. static LogicalResult convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation) { auto wsloopOp = cast<omp::WsloopOp>(opInst); + if (!wsloopOp.getAllocateVars().empty() || + !wsloopOp.getAllocatorVars().empty() || + !wsloopOp.getPrivateVars().empty() || wsloopOp.getPrivateSyms()) + return opInst.emitError("unhandled clauses for translation to LLVM IR"); + // FIXME: Here any other nested wrappers (e.g. omp.simd) are skipped, so // codegen for composite constructs like 'DO/FOR SIMD' will be the same as for // 'DO/FOR'. @@ -1607,6 +1629,12 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder, auto simdOp = cast<omp::SimdOp>(opInst); auto loopOp = cast<omp::LoopNestOp>(simdOp.getWrappedLoop()); + if (!simdOp.getLinearVars().empty() || !simdOp.getLinearStepVars().empty() || + !simdOp.getPrivateVars().empty() || simdOp.getPrivateSyms() || + !simdOp.getReductionVars().empty() || simdOp.getReductionByref() || + simdOp.getReductionSyms()) + return opInst.emitError("unhandled clauses for translation to LLVM IR"); + llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder); // Generator of the canonical loop body. @@ -3035,6 +3063,18 @@ static bool targetOpSupported(Operation &opInst) { return false; } + if (!targetOp.getAllocateVars().empty() || + !targetOp.getAllocatorVars().empty()) { + opInst.emitError("Allocate clause not yet supported"); + return false; + } + + if (!targetOp.getInReductionVars().empty() || + targetOp.getInReductionByref() || targetOp.getInReductionSyms()) { + opInst.emitError("In reduction clause not yet supported"); + return false; + } + return true; } @@ -3434,10 +3474,6 @@ convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder, ompBuilder->createBarrier(builder.saveIP(), llvm::omp::OMPD_barrier); return success(); }) - .Case([&](omp::TaskwaitOp) { - ompBuilder->createTaskwait(builder.saveIP()); - return success(); - }) .Case([&](omp::TaskyieldOp) { ompBuilder->createTaskyield(builder.saveIP()); return success(); @@ -3505,6 +3541,9 @@ convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder, .Case([&](omp::TaskgroupOp op) { return convertOmpTaskgroupOp(op, builder, moduleTranslation); }) + .Case([&](omp::TaskwaitOp op) { + return convertOmpTaskwaitOp(op, builder, moduleTranslation); + }) .Case<omp::YieldOp, omp::TerminatorOp, omp::DeclareReductionOp, omp::CriticalDeclareOp>([](auto op) { // `yield` and `terminator` can be just omitted. The block structure diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir b/mlir/test/Dialect/OpenMP/invalid.mlir index a29e34a9d5518..28542587fb9bb 100644 --- a/mlir/test/Dialect/OpenMP/invalid.mlir +++ b/mlir/test/Dialect/OpenMP/invalid.mlir @@ -421,7 +421,7 @@ func.func @omp_simd_aligned_mismatch(%arg0 : index, %arg1 : index, omp.yield } }) {alignments = [128], - operandSegmentSizes = array<i32: 2, 0, 0>} : (memref<i32>, memref<i32>) -> () + operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> () return } @@ -435,7 +435,7 @@ func.func @omp_simd_aligned_negative(%arg0 : index, %arg1 : index, omp.loop_nest (%iv) : index = (%arg0) to (%arg1) step (%arg2) { omp.yield } - }) {alignments = [-1, 128], operandSegmentSizes = array<i32: 2, 0, 0>} : (memref<i32>, memref<i32>) -> () + }) {alignments = [-1, 128], operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> () return } @@ -463,7 +463,7 @@ func.func @omp_simd_aligned_float(%arg0 : index, %arg1 : index, omp.loop_nest (%iv) : index = (%arg0) to (%arg1) step (%arg2) { omp.yield } - }) {alignments = [1.5, 128], operandSegmentSizes = array<i32: 2, 0, 0>} : (memref<i32>, memref<i32>) -> () + }) {alignments = [1.5, 128], operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> () return } @@ -477,7 +477,7 @@ func.func @omp_simd_aligned_the_same_var(%arg0 : index, %arg1 : index, omp.loop_nest (%iv) : index = (%arg0) to (%arg1) step (%arg2) { omp.yield } - }) {alignments = [1, 128], operandSegmentSizes = array<i32: 2, 0, 0>} : (memref<i32>, memref<i32>) -> () + }) {alignments = [1, 128], operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> () return } @@ -491,7 +491,7 @@ func.func @omp_simd_nontemporal_the_same_var(%arg0 : index, %arg1 : index, omp.loop_nest (%iv) : index = (%arg0) to (%arg1) step (%arg2) { omp.yield } - }) {operandSegmentSizes = array<i32: 0, 0, 2>} : (memref<i32>, memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 0, 0, 0, 0, 2, 0, 0>} : (memref<i32>, memref<i32>) -> () return } @@ -1394,7 +1394,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: 0,0,0,0,1,0,0>} : (memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 0,0,0,0,1,0,0,0>} : (memref<i32>) -> () omp.terminator } return @@ -1407,7 +1407,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: 1,0,0,0,0,0,0>} : (i32) -> () + }) {operandSegmentSizes = array<i32: 1,0,0,0,0,0,0,0>} : (i32) -> () omp.terminator } return @@ -1432,7 +1432,7 @@ func.func @omp_sections(%data_var : memref<i32>) -> () { // expected-error @below {{expected equal sizes for allocate and allocator variables}} "omp.sections" (%data_var) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 0,1,0>} : (memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 0,1,0,0>} : (memref<i32>) -> () return } @@ -1442,7 +1442,7 @@ func.func @omp_sections(%data_var : memref<i32>) -> () { // expected-error @below {{expected as many reduction symbol references as reduction variables}} "omp.sections" (%data_var) ({ omp.terminator - }) {operandSegmentSizes = array<i32: 1,0,0>} : (memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 1,0,0,0>} : (memref<i32>) -> () return } @@ -1557,7 +1557,7 @@ func.func @omp_single(%data_var : memref<i32>) -> () { // expected-error @below {{expected equal sizes for allocate and allocator variables}} "omp.single" (%data_var) ({ omp.barrier - }) {operandSegmentSizes = array<i32: 1,0,0>} : (memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 1,0,0,0>} : (memref<i32>) -> () return } @@ -1567,7 +1567,7 @@ func.func @omp_single_copyprivate(%data_var : memref<i32>) -> () { // expected-error @below {{inconsistent number of copyprivate vars (= 1) and functions (= 0), both must be equal}} "omp.single" (%data_var) ({ omp.barrier - }) {operandSegmentSizes = array<i32: 0,0,1>} : (memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 0,0,1,0>} : (memref<i32>) -> () return } @@ -1623,7 +1623,7 @@ func.func @omp_task_depend(%data_var: memref<i32>) { // expected-error @below {{op expected as many depend values as depend variables}} "omp.task"(%data_var) ({ "omp.terminator"() : () -> () - }) {depend_kinds = [], operandSegmentSizes = array<i32: 0, 0, 0, 0, 1, 0, 0>} : (memref<i32>) -> () + }) {depend_kinds = [], operandSegmentSizes = array<i32: 0, 0, 0, 0, 1, 0, 0, 0>} : (memref<i32>) -> () "func.return"() : () -> () } @@ -1820,7 +1820,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) { omp.loop_nest (%i, %j) : i32 = (%lb, %ub) to (%ub, %lb) step (%step, %step) { omp.yield } - }) {operandSegmentSizes = array<i32: 0, 0, 0, 0, 0, 1, 0, 0, 0>} : (memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 0, 0, 0, 0, 0, 1, 0, 0, 0, 0>} : (memref<i32>) -> () return } @@ -1834,7 +1834,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) { omp.loop_nest (%i, %j) : i32 = (%lb, %ub) to (%ub, %lb) step (%step, %step) { omp.yield } - }) {operandSegmentSizes = array<i32: 0, 0, 0, 2, 0, 0, 0, 0, 0>, reduction_syms = [@add_f32]} : (!llvm.ptr, !llvm.ptr) -> () + }) {operandSegmentSizes = array<i32: 0, 0, 0, 2, 0, 0, 0, 0, 0, 0>, reduction_syms = [@add_f32]} : (!llvm.ptr, !llvm.ptr) -> () return } @@ -1847,7 +1847,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) { omp.loop_nest (%i, %j) : i32 = (%lb, %ub) to (%ub, %lb) step (%step, %step) { omp.yield } - }) {operandSegmentSizes = array<i32: 0, 0, 0, 1, 0, 0, 0, 0, 0>, reduction_syms = [@add_f32, @add_f32]} : (!llvm.ptr) -> () + }) {operandSegmentSizes = array<i32: 0, 0, 0, 1, 0, 0, 0, 0, 0, 0>, reduction_syms = [@add_f32, @add_f32]} : (!llvm.ptr) -> () return } @@ -1861,7 +1861,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) { omp.loop_nest (%i, %j) : i32 = (%lb, %ub) to (%ub, %lb) step (%step, %step) { omp.yield } - }) {in_reduction_syms = [@add_f32], operandSegmentSizes = array<i32: 0, 0, 2, 0, 0, 0, 0, 0, 0>} : (!llvm.ptr, !llvm.ptr) -> () + }) {in_reduction_syms = [@add_f32], operandSegmentSizes = array<i32: 0, 0, 2, 0, 0, 0, 0, 0, 0, 0>} : (!llvm.ptr, !llvm.ptr) -> () return } @@ -1874,7 +1874,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) { omp.loop_nest (%i, %j) : i32 = (%lb, %ub) to (%ub, %lb) step (%step, %step) { omp.yield } - }) {in_reduction_syms = [@add_f32, @add_f32], operandSegmentSizes = array<i32: 0, 0, 1, 0, 0, 0, 0, 0, 0>} : (!llvm.ptr) -> () + }) {in_reduction_syms = [@add_f32, @add_f32], operandSegmentSizes = array<i32: 0, 0, 1, 0, 0, 0, 0, 0, 0, 0>} : (!llvm.ptr) -> () return } @@ -2129,7 +2129,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, 0, 1, 0, 0, 0, 0>} : (memref<i32>) -> () + }) {depend_kinds = [], operandSegmentSizes = array<i32: 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0>} : (memref<i32>) -> () "func.return"() : () -> () } @@ -2137,7 +2137,7 @@ func.func @omp_target_depend(%data_var: memref<i32>) { func.func @omp_distribute_schedule(%chunk_size : i32) -> () { // expected-error @below {{op chunk size set without dist_schedule_static being present}} - "omp.distribute"(%chunk_size) <{operandSegmentSizes = array<i32: 1, 0, 0>}> ({ + "omp.distribute"(%chunk_size) <{operandSegmentSizes = array<i32: 1, 0, 0, 0>}> ({ "omp.terminator"() : () -> () }) : (i32) -> () } @@ -2146,7 +2146,7 @@ func.func @omp_distribute_schedule(%chunk_size : i32) -> () { func.func @omp_distribute_allocate(%data_var : memref<i32>) -> () { // expected-error @below {{expected equal sizes for allocate and allocator variables}} - "omp.distribute"(%data_var) <{operandSegmentSizes = array<i32: 0, 1, 0>}> ({ + "omp.distribute"(%data_var) <{operandSegmentSizes = array<i32: 0, 1, 0, 0>}> ({ "omp.terminator"() : () -> () }) : (memref<i32>) -> () } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir index f639af9b86722..057d54c0c2f7c 100644 --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -382,7 +382,7 @@ func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memre omp.yield } omp.terminator - }) {operandSegmentSizes = array<i32: 0,0,0,0>, ordered = 1} : + }) {operandSegmentSizes = array<i32: 0,0,0,0,0,0,0>, ordered = 1} : () -> () // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref<i32>) schedule(static) { @@ -392,7 +392,7 @@ func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memre omp.yield } omp.terminator - }) {operandSegmentSizes = array<i32: 1,1,0,0>, schedule_kind = #omp<schedulekind static>} : + }) {operandSegmentSizes = array<i32: 1,1,0,0,0,0,0>, schedule_kind = #omp<schedulekind static>} : (memref<i32>, i32) -> () // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref<i32>, %{{.*}} = %{{.*}} : memref<i32>) schedule(static) { @@ -402,7 +402,7 @@ func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memre omp.yield } omp.terminator - }) {operandSegmentSizes = array<i32: 2,2,0,0>, schedule_kind = #omp<schedulekind static>} : + }) {operandSegmentSizes = array<i32: 2,2,0,0,0,0,0>, schedule_kind = #omp<schedulekind static>} : (memref<i32>, memref<i32>, i32, i32) -> () // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref<i32>) schedule(dynamic = %{{.*}}) ordered(2) { @@ -412,7 +412,7 @@ func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memre omp.yield } omp.terminator - }) {operandSegmentSizes = array<i32: 1,1,0,1>, schedule_kind = #omp<schedulekind dynamic>, ordered = 2} : + }) {operandSegmentSizes = array<i32: 1,1,0,1,0,0,0>, schedule_kind = #omp<schedulekind dynamic>, ordered = 2} : (memref<i32>, i32, i32) -> () // CHECK: omp.wsloop schedule(auto) nowait { @@ -422,7 +422,7 @@ func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memre omp.yield } omp.terminator - }) {operandSegmentSizes = array<i32: 0,0,0,0>, nowait, schedule_kind = #omp<schedulekind auto>} : + }) {operandSegmentSizes = array<i32: 0,0,0,0,0,0,0>, nowait, schedule_kind = #omp<schedulekind auto>} : () -> () // CHECK: omp.wsloop { @@ -575,7 +575,7 @@ func.func @omp_simd_aligned_list(%arg0 : index, %arg1 : index, %arg2 : index, }) : (index, index, index) -> () "omp.terminator"() : () -> () }) {alignments = [32, 128], - operandSegmentSizes = array<i32: 2, 0, 0>} : (memref<i32>, memref<i32>) -> () + operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> () return } @@ -590,7 +590,7 @@ func.func @omp_simd_aligned_single(%arg0 : index, %arg1 : index, %arg2 : index, }) : (index, index, index) -> () "omp.terminator"() : () -> () }) {alignments = [32], - operandSegmentSizes = array<i32: 1, 0, 0>} : (memref<i32>) -> () + operandSegmentSizes = array<i32: 1, 0, 0, 0, 0, 0, 0>} : (memref<i32>) -> () return } @@ -605,7 +605,7 @@ func.func @omp_simd_nontemporal_list(%arg0 : index, %arg1 : index, "omp.yield"() : () -> () }) : (index, index, index) -> () "omp.terminator"() : () -> () - }) {operandSegmentSizes = array<i32: 0, 0, 2>} : (memref<i32>, memref<i64>) -> () + }) {operandSegmentSizes = array<i32: 0, 0, 0, 0, 2, 0, 0>} : (memref<i32>, memref<i64>) -> () return } @@ -620,7 +620,7 @@ func.func @omp_simd_nontemporal_single(%arg0 : index, %arg1 : index, "omp.yield"() : () -> () }) : (index, index, index) -> () "omp.terminator"() : () -> () - }) {operandSegmentSizes = array<i32: 0, 0, 1>} : (memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 0, 0, 0, 0, 1, 0, 0>} : (memref<i32>) -> () return } @@ -809,7 +809,7 @@ func.func @omp_target(%if_cond : i1, %device : si32, %num_threads : i32, %devic "omp.target"(%if_cond, %device, %num_threads) ({ // CHECK: omp.terminator omp.terminator - }) {nowait, operandSegmentSizes = array<i32: 1,1,1,0,0,0,0,0>} : ( i1, si32, i32 ) -> () + }) {nowait, operandSegmentSizes = array<i32: 1,1,1,0,0,0,0,0,0,0,0>} : ( i1, si32, i32 ) -> () // Test with optional map clause. // CHECK: %[[MAP_A:.*]] = omp.map.info var_ptr(%[[VAL_1:.*]] : memref<?xi32>, tensor<?xi32>) map_clauses(tofrom) capture(ByRef) -> memref<?xi32> {name = ""} @@ -1874,13 +1874,13 @@ func.func @omp_sectionsop(%data_var1 : memref<i32>, %data_var2 : memref<i32>, "omp.sections" (%data_var1, %data_var1) ({ // CHECK: omp.terminator omp.terminator - }) {operandSegmentSizes = array<i32: 0,1,1>} : (memref<i32>, memref<i32>) -> () + }) {operandSegmentSizes = array<i32: 0,1,1,0>} : (memref<i32>, memref<i32>) -> () // CHECK: omp.sections reduction(@add_f32 -> %{{.*}} : !llvm.ptr) "omp.sections" (%redn_var) ({ // CHECK: omp.terminator omp.terminator - }) {operandSegmentSizes = array<i32: 1,0,0>, reduction_byref = array<i1: false>, reduction_syms=[@add_f32]} : (!llvm.ptr) -> () + }) {operandSegmentSizes = array<i32: 1,0,0,0>, reduction_byref = array<i1: false>, reduction_syms=[@add_f32]} : (!llvm.ptr) -> () // CHECK: omp.sections nowait { omp.sections nowait { @@ -2136,7 +2136,7 @@ func.func @omp_target_depend(%arg0: memref<i32>, %arg1: memref<i32>) { omp.target depend(taskdependin -> %arg0 : memref<i32>, taskdependin -> %arg1 : memref<i32>, taskdependinout -> %arg0 : memref<i32>) { // CHECK: omp.terminator omp.terminator - } {operandSegmentSizes = array<i32: 0,0,0,3,0>} + } {operandSegmentSizes = array<i32: 0,0,0,3,0,0,0,0>} return } _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits