14#include "mlir/Dialect/OpenACC/OpenACC.h"
21struct OpenACCDeclareCleanup final : EHScopeStack::Cleanup {
22 SourceRange declareRange;
23 mlir::acc::DeclareEnterOp enterOp;
25 OpenACCDeclareCleanup(SourceRange declareRange,
26 mlir::acc::DeclareEnterOp enterOp)
27 : declareRange(declareRange), enterOp(enterOp) {}
29 template <
typename OutTy,
typename InTy>
30 void createOutOp(CIRGenFunction &cgf, InTy inOp) {
31 if constexpr (std::is_same_v<OutTy, mlir::acc::DeleteOp>) {
33 OutTy::create(cgf.
getBuilder(), inOp.getLoc(), inOp,
34 inOp.getStructured(), inOp.getImplicit(),
35 llvm::Twine(inOp.getNameAttr()), inOp.getBounds());
36 outOp.setDataClause(inOp.getDataClause());
37 outOp.setModifiers(inOp.getModifiers());
40 OutTy::create(cgf.
getBuilder(), inOp.getLoc(), inOp, inOp.getVarPtr(),
41 inOp.getStructured(), inOp.getImplicit(),
42 llvm::Twine(inOp.getNameAttr()), inOp.getBounds());
43 outOp.setDataClause(inOp.getDataClause());
44 outOp.setModifiers(inOp.getModifiers());
48 void emit(CIRGenFunction &cgf)
override {
49 auto exitOp = mlir::acc::DeclareExitOp::create(
50 cgf.
getBuilder(), enterOp.getLoc(), enterOp, {});
54 for (mlir::Value val : enterOp.getDataClauseOperands()) {
55 if (
auto copyin = val.getDefiningOp<mlir::acc::CopyinOp>()) {
56 switch (copyin.getDataClause()) {
59 "OpenACC local declare clause copyin cleanup");
61 case mlir::acc::DataClause::acc_copy:
62 createOutOp<mlir::acc::CopyoutOp>(cgf, copyin);
64 case mlir::acc::DataClause::acc_copyin:
65 createOutOp<mlir::acc::DeleteOp>(cgf, copyin);
68 }
else if (
auto create = val.getDefiningOp<mlir::acc::CreateOp>()) {
69 switch (
create.getDataClause()) {
72 "OpenACC local declare clause create cleanup");
74 case mlir::acc::DataClause::acc_copyout:
75 createOutOp<mlir::acc::CopyoutOp>(cgf, create);
78 }
else if (val.getDefiningOp<mlir::acc::DeclareLinkOp>()) {
81 }
else if (val.getDefiningOp<mlir::acc::DevicePtrOp>()) {
85 cgf.
cgm.
errorNYI(declareRange,
"OpenACC local declare clause cleanup");
88 exitOp.getDataClauseOperandsMutable().append(val);
96 auto enterOp = mlir::acc::DeclareEnterOp::create(
97 builder, exprLoc, mlir::acc::DeclareTokenType::get(&
cgm.getMLIRContext()),
117 llvm_unreachable(
"unknown OpenACC declaration kind?");
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
This file defines OpenACC nodes for declarative directives.
void emitOpenACCRoutine(const OpenACCRoutineDecl &d)
void emitOpenACCDeclare(const OpenACCDeclareDecl &d)
EHScopeStack ehStack
Tracks function scope overall cleanup handling.
CIRGenBuilderTy & getBuilder()
CIRGenModule & getCIRGenModule()
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
void emitGlobalOpenACCDecl(const clang::OpenACCConstructDecl *cd)
SourceLocation getBeginLoc() const LLVM_READONLY
ArrayRef< const OpenACCClause * > clauses() const
virtual SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions &DiagOpts, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)