15#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
21static mlir::omp::ClauseMapFlags
25 return mlir::omp::ClauseMapFlags::to;
27 return mlir::omp::ClauseMapFlags::from;
29 return mlir::omp::ClauseMapFlags::to | mlir::omp::ClauseMapFlags::from;
31 case OMPC_MAP_release:
32 return mlir::omp::ClauseMapFlags::storage;
34 return mlir::omp::ClauseMapFlags::del;
36 return mlir::omp::ClauseMapFlags::none;
41 mlir::OpBuilder &builder,
42 mlir::Location loc,
const VarDecl *vd,
43 mlir::omp::ClauseMapFlags mapFlags) {
46 auto varPtrType = mlir::cast<cir::PointerType>(varPtr.getType());
47 mlir::Type elementType = varPtrType.getPointee();
50 if (varPtrType.getAddrSpace()) {
52 cir::PointerType::get(builder.getContext(), elementType);
53 varPtr = cir::CastOp::create(builder, loc, genericPtrType,
54 cir::CastKind::address_space, varPtr);
55 varPtrType = genericPtrType;
58 return mlir::omp::MapInfoOp::create(
62 mlir::TypeAttr::get(elementType),
63 builder.getAttr<mlir::omp::ClauseMapFlagsAttr>(mapFlags),
65 builder.getAttr<mlir::omp::VariableCaptureKindAttr>(
66 mlir::omp::VariableCaptureKind::ByRef),
72 mlir::FlatSymbolRefAttr{},
73 builder.getStringAttr(vd->
getName()),
74 builder.getBoolAttr(
false));
78 mlir::omp::ProcBindClauseOps &result)
const {
80 const auto *pbc = dyn_cast<OMPProcBindClause>(clause);
84 llvm::omp::ProcBindKind
kind = pbc->getProcBindKind();
85 assert(
kind != llvm::omp::ProcBindKind::OMP_PROC_BIND_unknown &&
86 "unknown proc-bind kind");
88 if (
kind != llvm::omp::ProcBindKind::OMP_PROC_BIND_default)
89 result.procBindKind = mlir::omp::ClauseProcBindKindAttr::get(
90 builder.getContext(), mlir::omp::convertProcBindKind(
kind));
97 mlir::omp::NumThreadsClauseOps &result)
const {
99 const auto *ntc = dyn_cast<OMPNumThreadsClause>(clause);
103 for (
const Expr *
expr : ntc->getNumThreads()) {
104 mlir::Value numThreadsValue = cgf.emitScalarExpr(
expr);
105 auto intType = builder.getIntegerType(32);
106 numThreadsValue = builder.createBuiltinIntCast(numThreadsValue, intType);
107 result.numThreadsVars.push_back(numThreadsValue);
116 llvm::omp::Directive directiveName)
const {
117 for (
const OMPClause *clause : clauses) {
118 const auto *ic = dyn_cast<OMPIfClause>(clause);
122 if (!(ic->getNameModifier() == llvm::omp::Directive::OMPD_unknown) &&
123 ic->getNameModifier() != directiveName)
126 Expr *ifCondition = ic->getCondition();
127 mlir::Value ifBoolValue = cgf.evaluateExprAsBool(ifCondition);
129 mlir::Type uIntType = builder.getUIntNTy(1);
130 mlir::Value ifUIntValue =
131 builder.createBoolToInt(ifBoolValue, uIntType);
133 mlir::Type intType = builder.getI1Type();
135 builder.createBuiltinIntCast(ifUIntValue, intType);
137 result.ifExpr = ifExpr;
144 mlir::omp::MapClauseOps &result,
147 for (
const OMPClause *clause : clauses) {
148 const auto *mc = dyn_cast<OMPMapClause>(clause);
156 cgm.errorNYI(mc->getBeginLoc(),
157 std::string(
"OpenMP map modifier '") +
159 llvm::omp::Clause::OMPC_map, mod) +
163 if (mc->isImplicit()) {
164 cgm.errorNYI(mc->getBeginLoc(),
"OpenMP implicit map clause");
170 for (
const Expr *varExpr : mc->varlist()) {
171 const auto *refExpr = dyn_cast<DeclRefExpr>(varExpr->IgnoreImplicit());
173 cgm.errorNYI(varExpr->getExprLoc(),
174 "OpenMP map clause with non-DeclRefExpr variable");
178 const auto *vd = dyn_cast<VarDecl>(refExpr->getDecl());
180 cgm.errorNYI(varExpr->getExprLoc(),
181 "OpenMP map clause with non-VarDecl variable");
185 result.mapVars.push_back(
188 mapSyms->push_back(vd);
static mlir::Value emitMapInfoForVar(CIRGenFunction &cgf, mlir::OpBuilder &builder, mlir::Location loc, const VarDecl *vd, mlir::omp::ClauseMapFlags mapFlags)
static mlir::omp::ClauseMapFlags mapClauseKindToFlags(OpenMPMapClauseKind kind)
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
Defines some OpenMP-specific enums and functions.
mlir::Value getPointer() const
Address getAddrOfLocalVar(const clang::VarDecl *vd)
Return the address of a local variable.
bool emitMap(mlir::omp::MapClauseOps &result, llvm::SmallVectorImpl< const VarDecl * > *mapSyms=nullptr) const
Emit map clauses.
bool emitIf(mlir::omp::IfClauseOps &result, llvm::omp::Directive directiveName) const
bool emitProcBind(mlir::omp::ProcBindClauseOps &result) const
bool emitNumThreads(mlir::omp::NumThreadsClauseOps &result) const
This represents one expression.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
This is a basic class for representing single OpenMP clause.
Represents a variable declaration or definition.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
Top level wrappers for InstallAPI frontend operations.
const char * getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type)
OpenMPMapModifierKind
OpenMP modifier kind for 'map' clause.
@ OMPC_MAP_MODIFIER_unknown
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.