@@ -3096,6 +3096,41 @@ void Fortran::lower::finalizeOpenACCRoutineAttachment(
30963096 accRoutineInfos.clear ();
30973097}
30983098
3099+ static void
3100+ genACC (Fortran::lower::AbstractConverter &converter,
3101+ Fortran::semantics::SemanticsContext &semanticsContext,
3102+ const Fortran::parser::OpenACCCacheConstruct &cacheConstruct) {
3103+ fir::FirOpBuilder &builder = converter.getFirOpBuilder ();
3104+ auto loopOp = builder.getRegion ().getParentOfType <mlir::acc::LoopOp>();
3105+ auto crtPos = builder.saveInsertionPoint ();
3106+ if (loopOp) {
3107+ builder.setInsertionPoint (loopOp);
3108+ Fortran::lower::StatementContext stmtCtx;
3109+ llvm::SmallVector<mlir::Value> cacheOperands;
3110+ const Fortran::parser::AccObjectListWithModifier &listWithModifier =
3111+ std::get<Fortran::parser::AccObjectListWithModifier>(cacheConstruct.t );
3112+ const auto &accObjectList =
3113+ std::get<Fortran::parser::AccObjectList>(listWithModifier.t );
3114+ const auto &modifier =
3115+ std::get<std::optional<Fortran::parser::AccDataModifier>>(
3116+ listWithModifier.t );
3117+
3118+ mlir::acc::DataClause dataClause = mlir::acc::DataClause::acc_cache;
3119+ if (modifier &&
3120+ (*modifier).v == Fortran::parser::AccDataModifier::Modifier::ReadOnly)
3121+ dataClause = mlir::acc::DataClause::acc_cache_readonly;
3122+ genDataOperandOperations<mlir::acc::CacheOp>(
3123+ accObjectList, converter, semanticsContext, stmtCtx, cacheOperands,
3124+ dataClause,
3125+ /* structured=*/ true , /* implicit=*/ false , /* setDeclareAttr*/ false );
3126+ loopOp.getCacheOperandsMutable ().append (cacheOperands);
3127+ } else {
3128+ llvm::report_fatal_error (
3129+ " could not find loop to attach OpenACC cache information." );
3130+ }
3131+ builder.restoreInsertionPoint (crtPos);
3132+ }
3133+
30993134void Fortran::lower::genOpenACCConstruct (
31003135 Fortran::lower::AbstractConverter &converter,
31013136 Fortran::semantics::SemanticsContext &semanticsContext,
@@ -3119,8 +3154,7 @@ void Fortran::lower::genOpenACCConstruct(
31193154 genACC (converter, semanticsContext, standaloneConstruct);
31203155 },
31213156 [&](const Fortran::parser::OpenACCCacheConstruct &cacheConstruct) {
3122- TODO (converter.genLocation (cacheConstruct.source ),
3123- " OpenACC Cache construct not lowered yet!" );
3157+ genACC (converter, semanticsContext, cacheConstruct);
31243158 },
31253159 [&](const Fortran::parser::OpenACCWaitConstruct &waitConstruct) {
31263160 genACC (converter, waitConstruct);
0 commit comments