@@ -3096,6 +3096,41 @@ void Fortran::lower::finalizeOpenACCRoutineAttachment(
3096
3096
accRoutineInfos.clear ();
3097
3097
}
3098
3098
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
+
3099
3134
void Fortran::lower::genOpenACCConstruct (
3100
3135
Fortran::lower::AbstractConverter &converter,
3101
3136
Fortran::semantics::SemanticsContext &semanticsContext,
@@ -3119,8 +3154,7 @@ void Fortran::lower::genOpenACCConstruct(
3119
3154
genACC (converter, semanticsContext, standaloneConstruct);
3120
3155
},
3121
3156
[&](const Fortran::parser::OpenACCCacheConstruct &cacheConstruct) {
3122
- TODO (converter.genLocation (cacheConstruct.source ),
3123
- " OpenACC Cache construct not lowered yet!" );
3157
+ genACC (converter, semanticsContext, cacheConstruct);
3124
3158
},
3125
3159
[&](const Fortran::parser::OpenACCWaitConstruct &waitConstruct) {
3126
3160
genACC (converter, waitConstruct);
0 commit comments