Skip to content

Commit 8bccd4c

Browse files
committed
Add missing linear clause and emit errors for unsupported clauses
1 parent 20213d5 commit 8bccd4c

File tree

6 files changed

+66
-28
lines changed

6 files changed

+66
-28
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,10 @@ using ParallelOperands =
271271
using SectionsOperands = detail::Clauses<AllocateClauseOps, NowaitClauseOps,
272272
PrivateClauseOps, ReductionClauseOps>;
273273

274-
// TODO `linear` clause.
275274
using SimdOperands =
276-
detail::Clauses<AlignedClauseOps, IfClauseOps, NontemporalClauseOps,
277-
OrderClauseOps, PrivateClauseOps, ReductionClauseOps,
278-
SafelenClauseOps, SimdlenClauseOps>;
275+
detail::Clauses<AlignedClauseOps, IfClauseOps, LinearClauseOps,
276+
NontemporalClauseOps, OrderClauseOps, PrivateClauseOps,
277+
ReductionClauseOps, SafelenClauseOps, SimdlenClauseOps>;
279278

280279
using SingleOperands = detail::Clauses<AllocateClauseOps, CopyprivateClauseOps,
281280
NowaitClauseOps, PrivateClauseOps>;

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,9 @@ def SimdOp : OpenMP_Op<"simd", traits = [
439439
AttrSizedOperandSegments, DeclareOpInterfaceMethods<LoopWrapperInterface>,
440440
RecursiveMemoryEffects, SingleBlock
441441
], clauses = [
442-
// TODO: Complete clause list (linear).
443-
OpenMP_AlignedClause, OpenMP_IfClause, OpenMP_NontemporalClause,
444-
OpenMP_OrderClause, OpenMP_PrivateClause, OpenMP_ReductionClause,
445-
OpenMP_SafelenClause, OpenMP_SimdlenClause
442+
OpenMP_AlignedClause, OpenMP_IfClause, OpenMP_LinearClause,
443+
OpenMP_NontemporalClause, OpenMP_OrderClause, OpenMP_PrivateClause,
444+
OpenMP_ReductionClause, OpenMP_SafelenClause, OpenMP_SimdlenClause
446445
], singleRegion = true> {
447446
let summary = "simd construct";
448447
let description = [{

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,10 +1764,11 @@ LogicalResult WsloopOp::verify() {
17641764
void SimdOp::build(OpBuilder &builder, OperationState &state,
17651765
const SimdOperands &clauses) {
17661766
MLIRContext *ctx = builder.getContext();
1767-
// TODO Store clauses in op: privateVars, privateSyms, reductionVars,
1768-
// reductionByref, reductionSyms.
1767+
// TODO Store clauses in op: linearVars, linearStepVars, privateVars,
1768+
// privateSyms, reductionVars, reductionByref, reductionSyms.
17691769
SimdOp::build(builder, state, clauses.alignedVars,
17701770
makeArrayAttr(ctx, clauses.alignments), clauses.ifVar,
1771+
/*linear_vars=*/{}, /*linear_step_vars=*/{},
17711772
clauses.nontemporalVars, clauses.order, clauses.orderMod,
17721773
/*private_vars=*/{}, /*private_syms=*/nullptr,
17731774
/*reduction_vars=*/{}, /*reduction_byref=*/nullptr,

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,9 @@ convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder,
837837
// TODO: Support the following clauses: private, firstprivate, lastprivate,
838838
// allocate
839839
if (!sectionsOp.getAllocateVars().empty() ||
840-
!sectionsOp.getAllocatorVars().empty())
841-
return emitError(sectionsOp.getLoc())
842-
<< "allocate clause is not supported for sections construct";
840+
!sectionsOp.getAllocatorVars().empty() ||
841+
!sectionsOp.getPrivateVars().empty() || sectionsOp.getPrivateSyms())
842+
return opInst.emitError("unhandled clauses for translation to LLVM IR");
843843

844844
llvm::ArrayRef<bool> isByRef = getIsByRef(sectionsOp.getReductionByref());
845845
assert(isByRef.size() == sectionsOp.getNumReductionVars());
@@ -945,6 +945,9 @@ convertOmpSingle(omp::SingleOp &singleOp, llvm::IRBuilderBase &builder,
945945
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
946946
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
947947
LogicalResult bodyGenStatus = success();
948+
if (!singleOp.getPrivateVars().empty() || singleOp.getPrivateSyms())
949+
return singleOp.emitError("unhandled clauses for translation to LLVM IR");
950+
948951
auto bodyCB = [&](InsertPointTy allocaIP, InsertPointTy codegenIP) {
949952
builder.restoreIP(codegenIP);
950953
convertOmpOpRegions(singleOp.getRegion(), "omp.single.region", builder,
@@ -976,7 +979,8 @@ convertOmpTeams(omp::TeamsOp op, llvm::IRBuilderBase &builder,
976979
LLVM::ModuleTranslation &moduleTranslation) {
977980
using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
978981
LogicalResult bodyGenStatus = success();
979-
if (!op.getAllocatorVars().empty() || op.getReductionSyms())
982+
if (!op.getAllocatorVars().empty() || op.getReductionSyms() ||
983+
!op.getPrivateVars().empty() || op.getPrivateSyms())
980984
return op.emitError("unhandled clauses for translation to LLVM IR");
981985

982986
auto bodyCB = [&](InsertPointTy allocaIP, InsertPointTy codegenIP) {
@@ -1017,7 +1021,8 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder,
10171021
LogicalResult bodyGenStatus = success();
10181022
if (taskOp.getUntiedAttr() || taskOp.getMergeableAttr() ||
10191023
taskOp.getInReductionSyms() || taskOp.getPriority() ||
1020-
!taskOp.getAllocateVars().empty()) {
1024+
!taskOp.getAllocateVars().empty() || !taskOp.getPrivateVars().empty() ||
1025+
taskOp.getPrivateSyms()) {
10211026
return taskOp.emitError("unhandled clauses for translation to LLVM IR");
10221027
}
10231028
auto bodyCB = [&](InsertPointTy allocaIP, InsertPointTy codegenIP) {
@@ -1085,11 +1090,28 @@ convertOmpTaskgroupOp(omp::TaskgroupOp tgOp, llvm::IRBuilderBase &builder,
10851090
ompLoc, allocaIP, bodyCB));
10861091
return bodyGenStatus;
10871092
}
1093+
1094+
static LogicalResult
1095+
convertOmpTaskwaitOp(omp::TaskwaitOp twOp, llvm::IRBuilderBase &builder,
1096+
LLVM::ModuleTranslation &moduleTranslation) {
1097+
if (!twOp.getDependVars().empty() || twOp.getDependKinds() ||
1098+
twOp.getNowait())
1099+
return twOp.emitError("unhandled clauses for translation to LLVM IR");
1100+
1101+
moduleTranslation.getOpenMPBuilder()->createTaskwait(builder.saveIP());
1102+
return success();
1103+
}
1104+
10881105
/// Converts an OpenMP workshare loop into LLVM IR using OpenMPIRBuilder.
10891106
static LogicalResult
10901107
convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
10911108
LLVM::ModuleTranslation &moduleTranslation) {
10921109
auto wsloopOp = cast<omp::WsloopOp>(opInst);
1110+
if (!wsloopOp.getAllocateVars().empty() ||
1111+
!wsloopOp.getAllocatorVars().empty() ||
1112+
!wsloopOp.getPrivateVars().empty() || wsloopOp.getPrivateSyms())
1113+
return opInst.emitError("unhandled clauses for translation to LLVM IR");
1114+
10931115
// FIXME: Here any other nested wrappers (e.g. omp.simd) are skipped, so
10941116
// codegen for composite constructs like 'DO/FOR SIMD' will be the same as for
10951117
// 'DO/FOR'.
@@ -1603,6 +1625,12 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
16031625
auto simdOp = cast<omp::SimdOp>(opInst);
16041626
auto loopOp = cast<omp::LoopNestOp>(simdOp.getWrappedLoop());
16051627

1628+
if (!simdOp.getLinearVars().empty() || !simdOp.getLinearStepVars().empty() ||
1629+
!simdOp.getPrivateVars().empty() || simdOp.getPrivateSyms() ||
1630+
!simdOp.getReductionVars().empty() || simdOp.getReductionByref() ||
1631+
simdOp.getReductionSyms())
1632+
return opInst.emitError("unhandled clauses for translation to LLVM IR");
1633+
16061634
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
16071635

16081636
// Generator of the canonical loop body.
@@ -3032,6 +3060,18 @@ static bool targetOpSupported(Operation &opInst) {
30323060
return false;
30333061
}
30343062

3063+
if (!targetOp.getAllocateVars().empty() ||
3064+
!targetOp.getAllocatorVars().empty()) {
3065+
opInst.emitError("Allocate clause not yet supported");
3066+
return false;
3067+
}
3068+
3069+
if (!targetOp.getInReductionVars().empty() ||
3070+
targetOp.getInReductionByref() || targetOp.getInReductionSyms()) {
3071+
opInst.emitError("In reduction clause not yet supported");
3072+
return false;
3073+
}
3074+
30353075
return true;
30363076
}
30373077

@@ -3427,10 +3467,6 @@ convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder,
34273467
ompBuilder->createBarrier(builder.saveIP(), llvm::omp::OMPD_barrier);
34283468
return success();
34293469
})
3430-
.Case([&](omp::TaskwaitOp) {
3431-
ompBuilder->createTaskwait(builder.saveIP());
3432-
return success();
3433-
})
34343470
.Case([&](omp::TaskyieldOp) {
34353471
ompBuilder->createTaskyield(builder.saveIP());
34363472
return success();
@@ -3498,6 +3534,9 @@ convertHostOrTargetOperation(Operation *op, llvm::IRBuilderBase &builder,
34983534
.Case([&](omp::TaskgroupOp op) {
34993535
return convertOmpTaskgroupOp(op, builder, moduleTranslation);
35003536
})
3537+
.Case([&](omp::TaskwaitOp op) {
3538+
return convertOmpTaskwaitOp(op, builder, moduleTranslation);
3539+
})
35013540
.Case<omp::YieldOp, omp::TerminatorOp, omp::DeclareReductionOp,
35023541
omp::CriticalDeclareOp>([](auto op) {
35033542
// `yield` and `terminator` can be just omitted. The block structure

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ func.func @omp_simd_aligned_mismatch(%arg0 : index, %arg1 : index,
421421
omp.yield
422422
}
423423
}) {alignments = [128],
424-
operandSegmentSizes = array<i32: 2, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
424+
operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
425425
return
426426
}
427427

@@ -435,7 +435,7 @@ func.func @omp_simd_aligned_negative(%arg0 : index, %arg1 : index,
435435
omp.loop_nest (%iv) : index = (%arg0) to (%arg1) step (%arg2) {
436436
omp.yield
437437
}
438-
}) {alignments = [-1, 128], operandSegmentSizes = array<i32: 2, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
438+
}) {alignments = [-1, 128], operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
439439
return
440440
}
441441

@@ -463,7 +463,7 @@ func.func @omp_simd_aligned_float(%arg0 : index, %arg1 : index,
463463
omp.loop_nest (%iv) : index = (%arg0) to (%arg1) step (%arg2) {
464464
omp.yield
465465
}
466-
}) {alignments = [1.5, 128], operandSegmentSizes = array<i32: 2, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
466+
}) {alignments = [1.5, 128], operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
467467
return
468468
}
469469

@@ -477,7 +477,7 @@ func.func @omp_simd_aligned_the_same_var(%arg0 : index, %arg1 : index,
477477
omp.loop_nest (%iv) : index = (%arg0) to (%arg1) step (%arg2) {
478478
omp.yield
479479
}
480-
}) {alignments = [1, 128], operandSegmentSizes = array<i32: 2, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
480+
}) {alignments = [1, 128], operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
481481
return
482482
}
483483

@@ -491,7 +491,7 @@ func.func @omp_simd_nontemporal_the_same_var(%arg0 : index, %arg1 : index,
491491
omp.loop_nest (%iv) : index = (%arg0) to (%arg1) step (%arg2) {
492492
omp.yield
493493
}
494-
}) {operandSegmentSizes = array<i32: 0, 0, 2, 0, 0>} : (memref<i32>, memref<i32>) -> ()
494+
}) {operandSegmentSizes = array<i32: 0, 0, 0, 0, 2, 0, 0>} : (memref<i32>, memref<i32>) -> ()
495495
return
496496
}
497497

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func.func @omp_simd_aligned_list(%arg0 : index, %arg1 : index, %arg2 : index,
575575
}) : (index, index, index) -> ()
576576
"omp.terminator"() : () -> ()
577577
}) {alignments = [32, 128],
578-
operandSegmentSizes = array<i32: 2, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
578+
operandSegmentSizes = array<i32: 2, 0, 0, 0, 0, 0, 0>} : (memref<i32>, memref<i32>) -> ()
579579
return
580580
}
581581

@@ -590,7 +590,7 @@ func.func @omp_simd_aligned_single(%arg0 : index, %arg1 : index, %arg2 : index,
590590
}) : (index, index, index) -> ()
591591
"omp.terminator"() : () -> ()
592592
}) {alignments = [32],
593-
operandSegmentSizes = array<i32: 1, 0, 0, 0, 0>} : (memref<i32>) -> ()
593+
operandSegmentSizes = array<i32: 1, 0, 0, 0, 0, 0, 0>} : (memref<i32>) -> ()
594594
return
595595
}
596596

@@ -605,7 +605,7 @@ func.func @omp_simd_nontemporal_list(%arg0 : index, %arg1 : index,
605605
"omp.yield"() : () -> ()
606606
}) : (index, index, index) -> ()
607607
"omp.terminator"() : () -> ()
608-
}) {operandSegmentSizes = array<i32: 0, 0, 2, 0, 0>} : (memref<i32>, memref<i64>) -> ()
608+
}) {operandSegmentSizes = array<i32: 0, 0, 0, 0, 2, 0, 0>} : (memref<i32>, memref<i64>) -> ()
609609
return
610610
}
611611

@@ -620,7 +620,7 @@ func.func @omp_simd_nontemporal_single(%arg0 : index, %arg1 : index,
620620
"omp.yield"() : () -> ()
621621
}) : (index, index, index) -> ()
622622
"omp.terminator"() : () -> ()
623-
}) {operandSegmentSizes = array<i32: 0, 0, 1, 0, 0>} : (memref<i32>) -> ()
623+
}) {operandSegmentSizes = array<i32: 0, 0, 0, 0, 1, 0, 0>} : (memref<i32>) -> ()
624624
return
625625
}
626626

0 commit comments

Comments
 (0)