summaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen/CIRGenDeclOpenACC.cpp
blob: 551027bb1c8eb142e885b7bfa10a34913cecccc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This contains code to emit Decl nodes as CIR code.
//
//===----------------------------------------------------------------------===//

#include "CIRGenFunction.h"
#include "mlir/Dialect/OpenACC/OpenACC.h"
#include "clang/AST/DeclOpenACC.h"

using namespace clang;
using namespace clang::CIRGen;

namespace {
struct OpenACCDeclareCleanup final : EHScopeStack::Cleanup {
  mlir::acc::DeclareEnterOp enterOp;

  OpenACCDeclareCleanup(mlir::acc::DeclareEnterOp enterOp) : enterOp(enterOp) {}

  void emit(CIRGenFunction &cgf) override {
    mlir::acc::DeclareExitOp::create(cgf.getBuilder(), enterOp.getLoc(),
                                     enterOp, {});

    // TODO(OpenACC): Some clauses require that we add info about them to the
    // DeclareExitOp.  However, we don't have any of those implemented yet, so
    // we should add infrastructure here to do that once we have one
    // implemented.
  }
};
} // namespace

void CIRGenFunction::emitOpenACCDeclare(const OpenACCDeclareDecl &d) {
  mlir::Location exprLoc = cgm.getLoc(d.getBeginLoc());
  auto enterOp = mlir::acc::DeclareEnterOp::create(
      builder, exprLoc, mlir::acc::DeclareTokenType::get(&cgm.getMLIRContext()),
      {});

  emitOpenACCClauses(enterOp, OpenACCDirectiveKind::Declare, d.getBeginLoc(),
                     d.clauses());

  ehStack.pushCleanup<OpenACCDeclareCleanup>(CleanupKind::NormalCleanup,
                                             enterOp);
}

void CIRGenFunction::emitOpenACCRoutine(const OpenACCRoutineDecl &d) {
  getCIRGenModule().errorNYI(d.getSourceRange(), "OpenACC Routine Construct");
}

void CIRGenModule::emitGlobalOpenACCDecl(const OpenACCConstructDecl *d) {
  if (isa<OpenACCRoutineDecl>(d))
    errorNYI(d->getSourceRange(), "OpenACC Routine Construct");
  else if (isa<OpenACCDeclareDecl>(d))
    errorNYI(d->getSourceRange(), "OpenACC Declare Construct");
  else
    llvm_unreachable("unknown OpenACC declaration kind?");
}