Skip to content

Commit 9334671

Browse files
committed
[flang][openacc] Lower simple acc routine directive
This patch lower simple acc routine directive with no clauses and no name inside function/subroutine. Patch to handle name and clauses will follow up. Patch to add attribute to the original routine will follow as well. Reviewed By: razvanlupusoru Differential Revision: https://reviews.llvm.org/D157919
1 parent 2e1982f commit 9334671

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
// Special value for * passed in device_type or gang clauses.
3232
static constexpr std::int64_t starCst = -1;
3333

34+
static unsigned routineCounter = 0;
35+
static constexpr llvm::StringRef accRoutinePrefix = "acc_routine_";
36+
3437
/// Generate the acc.bounds operation from the descriptor information.
3538
static llvm::SmallVector<mlir::Value>
3639
genBoundsOpsFromBox(fir::FirOpBuilder &builder, mlir::Location loc,
@@ -2721,6 +2724,32 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
27212724
llvm_unreachable("unsupported declarative directive");
27222725
}
27232726

2727+
static void
2728+
genACC(Fortran::lower::AbstractConverter &converter,
2729+
Fortran::lower::pft::Evaluation &eval,
2730+
const Fortran::parser::OpenACCRoutineConstruct &routineConstruct) {
2731+
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
2732+
mlir::Location loc = converter.genLocation(routineConstruct.source);
2733+
std::optional<Fortran::parser::Name> name =
2734+
std::get<std::optional<Fortran::parser::Name>>(routineConstruct.t);
2735+
const auto &clauses =
2736+
std::get<Fortran::parser::AccClauseList>(routineConstruct.t);
2737+
if (name)
2738+
TODO(loc, "acc routine with name");
2739+
if (!clauses.v.empty())
2740+
TODO(loc, "acc routine with clauses");
2741+
2742+
mlir::func::FuncOp func = builder.getFunction();
2743+
mlir::ModuleOp mod = builder.getModule();
2744+
mlir::OpBuilder modBuilder(mod.getBodyRegion());
2745+
std::stringstream routineOpName;
2746+
routineOpName << accRoutinePrefix.str() << routineCounter++;
2747+
modBuilder.create<mlir::acc::RoutineOp>(
2748+
loc, routineOpName.str(), func.getName(), mlir::StringAttr{},
2749+
mlir::UnitAttr{}, mlir::UnitAttr{}, mlir::UnitAttr{}, mlir::UnitAttr{},
2750+
mlir::UnitAttr{}, mlir::UnitAttr{}, mlir::IntegerAttr{});
2751+
}
2752+
27242753
void Fortran::lower::genOpenACCConstruct(
27252754
Fortran::lower::AbstractConverter &converter,
27262755
Fortran::semantics::SemanticsContext &semanticsContext,
@@ -2774,8 +2803,7 @@ void Fortran::lower::genOpenACCDeclarativeConstruct(
27742803
},
27752804
[&](const Fortran::parser::OpenACCRoutineConstruct
27762805
&routineConstruct) {
2777-
TODO(converter.genLocation(routineConstruct.source),
2778-
"OpenACC Routine construct not lowered yet!");
2806+
genACC(converter, eval, routineConstruct);
27792807
},
27802808
},
27812809
accDeclConstruct.u);

flang/test/Lower/OpenACC/Todo/acc-routine.f90

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! This test checks lowering of OpenACC routine directive.
2+
3+
! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
4+
5+
subroutine acc_routine1()
6+
!$acc routine
7+
end subroutine
8+
9+
! CHECK: acc.routine @acc_routine_0 func(@_QPacc_routine1)
10+
! CHECK-LABEL: func.func @_QPacc_routine1()

0 commit comments

Comments
 (0)