| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
// Emit OpenMP clause nodes as CIR code. |
| 10 |
// |
| 11 |
//===----------------------------------------------------------------------===// |
| 12 |
|
| 13 |
#include "CIRGenFunction.h" |
| 14 |
#include "mlir/Dialect/OpenMP/OpenMPDialect.h" |
| 15 |
|
| 16 |
using namespace clang; |
| 17 |
using namespace clang::CIRGen; |
| 18 |
|
| 19 |
namespace { |
| 20 |
template <typename OpTy> |
| 21 |
class OpenMPClauseCIREmitter final |
| 22 |
: public ConstOMPClauseVisitor<OpenMPClauseCIREmitter<OpTy>> { |
| 23 |
OpTy &operation; |
| 24 |
CIRGen::CIRGenFunction &cgf; |
| 25 |
CIRGen::CIRGenBuilderTy &builder; |
| 26 |
|
| 27 |
public: |
| 28 |
OpenMPClauseCIREmitter(OpTy &operation, CIRGen::CIRGenFunction &cgf, |
| 29 |
CIRGen::CIRGenBuilderTy &builder) |
| 30 |
: operation(operation), cgf(cgf), builder(builder) {} |
| 31 |
|
| 32 |
void VisitOMPClause(const OMPClause *clause) { |
| 33 |
cgf.cgm.errorNYI(clause->getBeginLoc(), "OpenMPClause ", |
| 34 |
llvm::omp::getOpenMPClauseName(clause->getClauseKind())); |
| 35 |
} |
| 36 |
|
| 37 |
void VisitOMPProcBindClause(const OMPProcBindClause *clause) { |
| 38 |
if constexpr (std::is_same_v<OpTy, mlir::omp::ParallelOp>) { |
| 39 |
mlir::omp::ClauseProcBindKind kind; |
| 40 |
switch (clause->getProcBindKind()) { |
| 41 |
case llvm::omp::ProcBindKind::OMP_PROC_BIND_master: |
| 42 |
kind = mlir::omp::ClauseProcBindKind::Master; |
| 43 |
break; |
| 44 |
case llvm::omp::ProcBindKind::OMP_PROC_BIND_close: |
| 45 |
kind = mlir::omp::ClauseProcBindKind::Close; |
| 46 |
break; |
| 47 |
case llvm::omp::ProcBindKind::OMP_PROC_BIND_spread: |
| 48 |
kind = mlir::omp::ClauseProcBindKind::Spread; |
| 49 |
break; |
| 50 |
case llvm::omp::ProcBindKind::OMP_PROC_BIND_primary: |
| 51 |
kind = mlir::omp::ClauseProcBindKind::Primary; |
| 52 |
break; |
| 53 |
case llvm::omp::ProcBindKind::OMP_PROC_BIND_default: |
| 54 |
// 'default' in the classic-codegen does no runtime call/doesn't |
| 55 |
// really do anything. So this is a no-op, and thus shouldn't change |
| 56 |
// the IR. |
| 57 |
return; |
| 58 |
case llvm::omp::ProcBindKind::OMP_PROC_BIND_unknown: |
| 59 |
llvm_unreachable("unknown proc-bind kind"); |
| 60 |
} |
| 61 |
operation.setProcBindKind(kind); |
| 62 |
} else { |
| 63 |
cgf.cgm.errorNYI( |
| 64 |
clause->getBeginLoc(), |
| 65 |
"OMPProcBindClause unimplemented on this directive kind"); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
void emitClauses(ArrayRef<const OMPClause *> clauses) { |
| 70 |
for (const auto *c : clauses) |
| 71 |
this->Visit(c); |
| 72 |
} |
| 73 |
}; |
| 74 |
template <typename OpTy> |
| 75 |
auto makeClauseEmitter(OpTy &op, CIRGen::CIRGenFunction &cgf, |
| 76 |
CIRGen::CIRGenBuilderTy &builder) { |
| 77 |
return OpenMPClauseCIREmitter<OpTy>(op, cgf, builder); |
| 78 |
} |
| 79 |
} // namespace |
| 80 |
|
| 81 |
template <typename Op> |
| 82 |
void CIRGenFunction::emitOpenMPClauses(Op &op, |
| 83 |
ArrayRef<const OMPClause *> clauses) { |
| 84 |
mlir::OpBuilder::InsertionGuard guardCase(builder); |
| 85 |
builder.setInsertionPoint(op); |
| 86 |
makeClauseEmitter(op, *this, builder).emitClauses(clauses); |
| 87 |
} |
| 88 |
|
| 89 |
// We're defining the template for this in a .cpp file, so we have to explicitly |
| 90 |
// specialize the templates. |
| 91 |
#define EXPL_SPEC(N) \ |
| 92 |
template void CIRGenFunction::emitOpenMPClauses<N>( \ |
| 93 |
N &, ArrayRef<const OMPClause *>); |
| 94 |
EXPL_SPEC(mlir::omp::ParallelOp) |
| 95 |
#undef EXPL_SPEC |