Skip to content

Commit 3163f7a

Browse files
committed
[flang][openacc] Add kernels construct lowering
Lower the parse tree to acc dialects operations. Make use of the compute construct lowering. Depends on D148277 Reviewed By: PeteSteinfeld Differential Revision: https://reviews.llvm.org/D148278
1 parent 33468a5 commit 3163f7a

File tree

3 files changed

+943
-8
lines changed

3 files changed

+943
-8
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,15 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
551551
llvm::SmallVector<int32_t, 8> operandSegments;
552552
addOperand(operands, operandSegments, async);
553553
addOperands(operands, operandSegments, waitOperands);
554-
if constexpr (std::is_same_v<Op, mlir::acc::ParallelOp>) {
554+
if constexpr (!std::is_same_v<Op, mlir::acc::SerialOp>) {
555555
addOperand(operands, operandSegments, numGangs);
556556
addOperand(operands, operandSegments, numWorkers);
557557
addOperand(operands, operandSegments, vectorLength);
558558
}
559559
addOperand(operands, operandSegments, ifCond);
560560
addOperand(operands, operandSegments, selfCond);
561-
addOperands(operands, operandSegments, reductionOperands);
561+
if constexpr (!std::is_same_v<Op, mlir::acc::KernelsOp>)
562+
addOperands(operands, operandSegments, reductionOperands);
562563
addOperands(operands, operandSegments, copyOperands);
563564
addOperands(operands, operandSegments, copyinOperands);
564565
addOperands(operands, operandSegments, copyinReadonlyOperands);
@@ -570,11 +571,18 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
570571
addOperands(operands, operandSegments, presentOperands);
571572
addOperands(operands, operandSegments, devicePtrOperands);
572573
addOperands(operands, operandSegments, attachOperands);
573-
addOperands(operands, operandSegments, privateOperands);
574-
addOperands(operands, operandSegments, firstprivateOperands);
574+
if constexpr (!std::is_same_v<Op, mlir::acc::KernelsOp>) {
575+
addOperands(operands, operandSegments, privateOperands);
576+
addOperands(operands, operandSegments, firstprivateOperands);
577+
}
575578

576-
Op computeOp = createRegionOp<Op, mlir::acc::YieldOp>(
577-
firOpBuilder, currentLocation, operands, operandSegments);
579+
Op computeOp;
580+
if constexpr (std::is_same_v<Op, mlir::acc::KernelsOp>)
581+
computeOp = createRegionOp<Op, mlir::acc::TerminatorOp>(
582+
firOpBuilder, currentLocation, operands, operandSegments);
583+
else
584+
computeOp = createRegionOp<Op, mlir::acc::YieldOp>(
585+
firOpBuilder, currentLocation, operands, operandSegments);
578586

579587
if (addAsyncAttr)
580588
computeOp.setAsyncAttrAttr(firOpBuilder.getUnitAttr());
@@ -697,7 +705,8 @@ genACC(Fortran::lower::AbstractConverter &converter,
697705
createComputeOp<mlir::acc::SerialOp>(
698706
converter, currentLocation, semanticsContext, stmtCtx, accClauseList);
699707
} else if (blockDirective.v == llvm::acc::ACCD_kernels) {
700-
TODO(currentLocation, "kernels construct lowering");
708+
createComputeOp<mlir::acc::KernelsOp>(
709+
converter, currentLocation, semanticsContext, stmtCtx, accClauseList);
701710
} else if (blockDirective.v == llvm::acc::ACCD_host_data) {
702711
TODO(currentLocation, "host_data construct lowering");
703712
}
@@ -720,7 +729,10 @@ genACC(Fortran::lower::AbstractConverter &converter,
720729
Fortran::lower::StatementContext stmtCtx;
721730

722731
if (combinedDirective.v == llvm::acc::ACCD_kernels_loop) {
723-
TODO(currentLocation, "OpenACC Kernels Loop construct not lowered yet!");
732+
createComputeOp<mlir::acc::KernelsOp>(
733+
converter, currentLocation, semanticsContext, stmtCtx, accClauseList);
734+
createLoopOp(converter, currentLocation, semanticsContext, stmtCtx,
735+
accClauseList);
724736
} else if (combinedDirective.v == llvm::acc::ACCD_parallel_loop) {
725737
createComputeOp<mlir::acc::ParallelOp>(
726738
converter, currentLocation, semanticsContext, stmtCtx, accClauseList);

0 commit comments

Comments
 (0)