Skip to content

Commit e070ea4

Browse files
[flang][openacc] Enable lowering support for OpenACC atomic operations (#65776)
Since the OpenACC atomics specification is a subset of OpenMP atomics, the same lowering implementation can be used. This change extracts out the necessary pieces from the OpenMP lowering and puts them in a shared spot. The shared spot is a header file so that each implementation can template specialize directly. After putting the OpenMP implementation in a common spot, the following changes were needed to make it work for OpenACC: * Ensure parsing works correctly by avoiding hardcoded offsets. * Templatize based on atomic type. * The checking whether it is OpenMP or OpenACC is done by checking for OmpAtomicClauseList (OpenACC does not implement this so we just templatize with void). It was preferable to check this instead of atomic type because in some cases, like atomic capture, the read/write/update implementations are called - and we want compile time evaluation of these conditional parts. * The memory order and hint are used only for OpenMP. * Generate acc dialect operations instead of omp dialect operations.
1 parent d1b418f commit e070ea4

9 files changed

+956
-491
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,9 +2287,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
22872287

22882288
void genFIR(const Fortran::parser::OpenACCConstruct &acc) {
22892289
mlir::OpBuilder::InsertPoint insertPt = builder->saveInsertionPoint();
2290+
localSymbols.pushScope();
22902291
genOpenACCConstruct(*this, bridge.getSemanticsContext(), getEval(), acc);
22912292
for (Fortran::lower::pft::Evaluation &e : getEval().getNestedEvaluations())
22922293
genFIR(e);
2294+
localSymbols.popScope();
22932295
builder->restoreInsertionPoint(insertPt);
22942296
}
22952297

flang/lib/Lower/DirectivesCommon.h

Lines changed: 593 additions & 0 deletions
Large diffs are not rendered by default.

flang/lib/Lower/OpenACC.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "flang/Lower/OpenACC.h"
14+
#include "DirectivesCommon.h"
1415
#include "flang/Common/idioms.h"
1516
#include "flang/Lower/Bridge.h"
1617
#include "flang/Lower/ConvertType.h"
@@ -3096,6 +3097,34 @@ void Fortran::lower::finalizeOpenACCRoutineAttachment(
30963097
accRoutineInfos.clear();
30973098
}
30983099

3100+
static void
3101+
genACC(Fortran::lower::AbstractConverter &converter,
3102+
Fortran::lower::pft::Evaluation &eval,
3103+
const Fortran::parser::OpenACCAtomicConstruct &atomicConstruct) {
3104+
std::visit(
3105+
Fortran::common::visitors{
3106+
[&](const Fortran::parser::AccAtomicRead &atomicRead) {
3107+
Fortran::lower::genOmpAccAtomicRead<Fortran::parser::AccAtomicRead,
3108+
void>(converter, atomicRead);
3109+
},
3110+
[&](const Fortran::parser::AccAtomicWrite &atomicWrite) {
3111+
Fortran::lower::genOmpAccAtomicWrite<
3112+
Fortran::parser::AccAtomicWrite, void>(converter, atomicWrite);
3113+
},
3114+
[&](const Fortran::parser::AccAtomicUpdate &atomicUpdate) {
3115+
Fortran::lower::genOmpAccAtomicUpdate<
3116+
Fortran::parser::AccAtomicUpdate, void>(converter,
3117+
atomicUpdate);
3118+
},
3119+
[&](const Fortran::parser::AccAtomicCapture &atomicCapture) {
3120+
Fortran::lower::genOmpAccAtomicCapture<
3121+
Fortran::parser::AccAtomicCapture, void>(converter,
3122+
atomicCapture);
3123+
},
3124+
},
3125+
atomicConstruct.u);
3126+
}
3127+
30993128
static void
31003129
genACC(Fortran::lower::AbstractConverter &converter,
31013130
Fortran::semantics::SemanticsContext &semanticsContext,
@@ -3160,8 +3189,7 @@ void Fortran::lower::genOpenACCConstruct(
31603189
genACC(converter, waitConstruct);
31613190
},
31623191
[&](const Fortran::parser::OpenACCAtomicConstruct &atomicConstruct) {
3163-
TODO(converter.genLocation(atomicConstruct.source),
3164-
"OpenACC Atomic construct not lowered yet!");
3192+
genACC(converter, eval, atomicConstruct);
31653193
},
31663194
},
31673195
accConstruct.u);

0 commit comments

Comments
 (0)