@@ -2905,8 +2905,25 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
2905
2905
llvm_unreachable (" unsupported declarative directive" );
2906
2906
}
2907
2907
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
+
2908
2924
static void
2909
2925
genACC (Fortran::lower::AbstractConverter &converter,
2926
+ Fortran::semantics::SemanticsContext &semanticsContext,
2910
2927
Fortran::lower::pft::Evaluation &eval,
2911
2928
const Fortran::parser::OpenACCRoutineConstruct &routineConstruct) {
2912
2929
fir::FirOpBuilder &builder = converter.getFirOpBuilder ();
@@ -2955,6 +2972,21 @@ genACC(Fortran::lower::AbstractConverter &converter,
2955
2972
routineOp.setWorkerAttr (builder.getUnitAttr ());
2956
2973
} else if (std::get_if<Fortran::parser::AccClause::Nohost>(&clause.u )) {
2957
2974
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
+ }
2958
2990
}
2959
2991
}
2960
2992
@@ -3025,7 +3057,7 @@ void Fortran::lower::genOpenACCDeclarativeConstruct(
3025
3057
},
3026
3058
[&](const Fortran::parser::OpenACCRoutineConstruct
3027
3059
&routineConstruct) {
3028
- genACC (converter, eval, routineConstruct);
3060
+ genACC (converter, semanticsContext, eval, routineConstruct);
3029
3061
},
3030
3062
},
3031
3063
accDeclConstruct.u );
0 commit comments