Skip to content

Commit e18050f

Browse files
clementvalrazmser
authored andcommittedOct 11, 2023
[flang][openacc] Lower the bind clause on acc routine
Lower the bind clause to the corresponding attribute Depends on D158120 Reviewed By: razvanlupusoru Differential Revision: https://reviews.llvm.org/D158121
1 parent 3653c9d commit e18050f

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
 

‎flang/lib/Lower/OpenACC.cpp

+33-1
Original file line numberDiff line numberDiff line change
@@ -2905,8 +2905,25 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
29052905
llvm_unreachable("unsupported declarative directive");
29062906
}
29072907

2908+
template <typename R, typename T>
2909+
std::optional<R>
2910+
GetConstExpr(Fortran::semantics::SemanticsContext &semanticsContext,
2911+
const T &x) {
2912+
using DefaultCharConstantType = Fortran::evaluate::Ascii;
2913+
if (const auto *expr{Fortran::semantics::GetExpr(semanticsContext, x)}) {
2914+
const auto foldExpr{Fortran::evaluate::Fold(
2915+
semanticsContext.foldingContext(), Fortran::common::Clone(*expr))};
2916+
if constexpr (std::is_same_v<R, std::string>) {
2917+
return Fortran::evaluate::GetScalarConstantValue<DefaultCharConstantType>(
2918+
foldExpr);
2919+
}
2920+
}
2921+
return std::nullopt;
2922+
}
2923+
29082924
static void
29092925
genACC(Fortran::lower::AbstractConverter &converter,
2926+
Fortran::semantics::SemanticsContext &semanticsContext,
29102927
Fortran::lower::pft::Evaluation &eval,
29112928
const Fortran::parser::OpenACCRoutineConstruct &routineConstruct) {
29122929
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
@@ -2955,6 +2972,21 @@ genACC(Fortran::lower::AbstractConverter &converter,
29552972
routineOp.setWorkerAttr(builder.getUnitAttr());
29562973
} else if (std::get_if<Fortran::parser::AccClause::Nohost>(&clause.u)) {
29572974
routineOp.setNohostAttr(builder.getUnitAttr());
2975+
} else if (const auto *bindClause =
2976+
std::get_if<Fortran::parser::AccClause::Bind>(&clause.u)) {
2977+
if (const auto *name =
2978+
std::get_if<Fortran::parser::Name>(&bindClause->v.u)) {
2979+
routineOp.setBindName(
2980+
builder.getStringAttr(converter.mangleName(*name->symbol)));
2981+
} else if (const auto charExpr =
2982+
std::get_if<Fortran::parser::ScalarDefaultCharExpr>(
2983+
&bindClause->v.u)) {
2984+
const std::optional<std::string> bindName =
2985+
GetConstExpr<std::string>(semanticsContext, *charExpr);
2986+
if (!bindName)
2987+
routineOp.emitError("Could not retrieve the bind name");
2988+
routineOp.setBindName(builder.getStringAttr(*bindName));
2989+
}
29582990
}
29592991
}
29602992

@@ -3025,7 +3057,7 @@ void Fortran::lower::genOpenACCDeclarativeConstruct(
30253057
},
30263058
[&](const Fortran::parser::OpenACCRoutineConstruct
30273059
&routineConstruct) {
3028-
genACC(converter, eval, routineConstruct);
3060+
genACC(converter, semanticsContext, eval, routineConstruct);
30293061
},
30303062
},
30313063
accDeclConstruct.u);

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

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
44

5+
! CHECK: acc.routine @acc_routine_8 func(@_QPacc_routine9) bind("_QPacc_routine9a")
6+
! CHECK: acc.routine @acc_routine_7 func(@_QPacc_routine8) bind("routine8_")
57
! CHECK: acc.routine @acc_routine_6 func(@_QPacc_routine7) gang(dim = 1 : i32)
68
! CHECK: acc.routine @acc_routine_5 func(@_QPacc_routine6) nohost
79
! CHECK: acc.routine @acc_routine_4 func(@_QPacc_routine5) worker
@@ -51,3 +53,18 @@ subroutine acc_routine7()
5153
end subroutine
5254

5355
! CHECK-LABEL: func.func @_QPacc_routine7() attributes {acc.routine_info = #acc.routine_info<[@acc_routine_6]>}
56+
57+
subroutine acc_routine8()
58+
!$acc routine bind("routine8_")
59+
end subroutine
60+
61+
! CHECK-LABEL: func.func @_QPacc_routine8() attributes {acc.routine_info = #acc.routine_info<[@acc_routine_7]>}
62+
63+
subroutine acc_routine9a()
64+
end subroutine
65+
66+
subroutine acc_routine9()
67+
!$acc routine bind(acc_routine9a)
68+
end subroutine
69+
70+
! CHECK-LABEL: func.func @_QPacc_routine9() attributes {acc.routine_info = #acc.routine_info<[@acc_routine_8]>}

0 commit comments

Comments
 (0)
Please sign in to comment.