|
12 | 12 |
|
13 | 13 | #include "CIRGenBuilder.h"
|
14 | 14 | #include "CIRGenFunction.h"
|
| 15 | +#include "clang/AST/OpenACCClause.h" |
15 | 16 | #include "clang/AST/StmtOpenACC.h"
|
16 | 17 |
|
| 18 | +#include "mlir/Dialect/OpenACC/OpenACC.h" |
| 19 | + |
17 | 20 | using namespace clang;
|
18 | 21 | using namespace clang::CIRGen;
|
19 | 22 | using namespace cir;
|
| 23 | +using namespace mlir::acc; |
| 24 | + |
| 25 | +namespace { |
| 26 | +class OpenACCClauseCIREmitter final |
| 27 | + : public OpenACCClauseVisitor<OpenACCClauseCIREmitter> { |
| 28 | + CIRGenModule &cgm; |
| 29 | + |
| 30 | + void clauseNotImplemented(const OpenACCClause &c) { |
| 31 | + cgm.errorNYI(c.getSourceRange(), "OpenACC Clause", c.getClauseKind()); |
| 32 | + } |
| 33 | + |
| 34 | +public: |
| 35 | + OpenACCClauseCIREmitter(CIRGenModule &cgm) : cgm(cgm) {} |
| 36 | + |
| 37 | +#define VISIT_CLAUSE(CN) \ |
| 38 | + void Visit##CN##Clause(const OpenACC##CN##Clause &clause) { \ |
| 39 | + clauseNotImplemented(clause); \ |
| 40 | + } |
| 41 | +#include "clang/Basic/OpenACCClauses.def" |
| 42 | +}; |
| 43 | +} // namespace |
| 44 | + |
| 45 | +template <typename Op, typename TermOp> |
| 46 | +mlir::LogicalResult CIRGenFunction::emitOpenACCComputeOp( |
| 47 | + mlir::Location start, mlir::Location end, |
| 48 | + llvm::ArrayRef<const OpenACCClause *> clauses, |
| 49 | + const Stmt *structuredBlock) { |
| 50 | + mlir::LogicalResult res = mlir::success(); |
| 51 | + |
| 52 | + OpenACCClauseCIREmitter clauseEmitter(getCIRGenModule()); |
| 53 | + clauseEmitter.VisitClauseList(clauses); |
| 54 | + |
| 55 | + llvm::SmallVector<mlir::Type> retTy; |
| 56 | + llvm::SmallVector<mlir::Value> operands; |
| 57 | + auto op = builder.create<Op>(start, retTy, operands); |
| 58 | + |
| 59 | + mlir::Block &block = op.getRegion().emplaceBlock(); |
| 60 | + mlir::OpBuilder::InsertionGuard guardCase(builder); |
| 61 | + builder.setInsertionPointToEnd(&block); |
| 62 | + |
| 63 | + LexicalScope ls{*this, start, builder.getInsertionBlock()}; |
| 64 | + res = emitStmt(structuredBlock, /*useCurrentScope=*/true); |
| 65 | + |
| 66 | + builder.create<TermOp>(end); |
| 67 | + return res; |
| 68 | +} |
20 | 69 |
|
21 | 70 | mlir::LogicalResult
|
22 | 71 | CIRGenFunction::emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s) {
|
23 |
| - getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Compute Construct"); |
24 |
| - return mlir::failure(); |
| 72 | + mlir::Location start = getLoc(s.getSourceRange().getEnd()); |
| 73 | + mlir::Location end = getLoc(s.getSourceRange().getEnd()); |
| 74 | + |
| 75 | + switch (s.getDirectiveKind()) { |
| 76 | + case OpenACCDirectiveKind::Parallel: |
| 77 | + return emitOpenACCComputeOp<ParallelOp, mlir::acc::YieldOp>( |
| 78 | + start, end, s.clauses(), s.getStructuredBlock()); |
| 79 | + case OpenACCDirectiveKind::Serial: |
| 80 | + return emitOpenACCComputeOp<SerialOp, mlir::acc::YieldOp>( |
| 81 | + start, end, s.clauses(), s.getStructuredBlock()); |
| 82 | + case OpenACCDirectiveKind::Kernels: |
| 83 | + return emitOpenACCComputeOp<KernelsOp, mlir::acc::TerminatorOp>( |
| 84 | + start, end, s.clauses(), s.getStructuredBlock()); |
| 85 | + default: |
| 86 | + llvm_unreachable("invalid compute construct kind"); |
| 87 | + } |
25 | 88 | }
|
26 | 89 |
|
27 | 90 | mlir::LogicalResult
|
|
0 commit comments