clang 24.0.0git
CIRGenOpenMPClause.h
Go to the documentation of this file.
1//===--- CIRGenOpenMPClause.h - OpenMP clause emitter -----------*- C++ -*-===//
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#ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENOPENMPCLAUSE_H
10#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENOPENMPCLAUSE_H
11
12#include "CIRGenBuilder.h"
13#include "CIRGenModule.h"
14#include "mlir/Dialect/OpenMP/OpenMPClauseOperands.h"
17#include "llvm/Frontend/OpenMP/OMPConstants.h"
18
19#include <type_traits>
20
21namespace clang::CIRGen {
22
23class CIRGenFunction;
24
25/// A type-only list of OpenMP clause AST node types.
26template <typename... Clauses> struct OpenMPNYIClauseList {};
27
28/// Emits OpenMP clauses for a directive, writing results into the
29/// auto-generated ClauseOps from the OMP dialect.
31 CIRGenFunction &cgf;
32 CIRGenModule &cgm;
33 CIRGenBuilderTy &builder;
34 mlir::Location loc;
36
37public:
39 CIRGenBuilderTy &builder, mlir::Location loc,
41 : cgf(cgf), cgm(cgm), builder(builder), loc(loc), clauses(clauses) {}
42
43 bool emitIf(mlir::omp::IfClauseOps &result,
44 llvm::omp::Directive directiveName) const;
45
46 /// Emit map clauses. The optional \p mapSyms parameter collects the
47 /// VarDecls corresponding to each map operand.
48 bool emitMap(mlir::omp::MapClauseOps &result,
49 llvm::SmallVectorImpl<const VarDecl *> *mapSyms = nullptr) const;
50
51 bool emitNumThreads(mlir::omp::NumThreadsClauseOps &result) const;
52
53 bool emitProcBind(mlir::omp::ProcBindClauseOps &result) const;
54
55 /// Verify the clauses of a directive to make sure all legal cases are either
56 /// implemented or give a NYI error. The \p SupportedClauses and \p
57 /// NYIClauses type lists must be disjoint and cover all clauses eligible for
58 /// the directive being processed. Returns failure if any not-yet-implemented
59 /// clause was present (and an error was emitted), success otherwise.
60 template <typename... SupportedClauses, typename... NYIClauses>
61 mlir::LogicalResult emitNYI(OpenMPNYIClauseList<NYIClauses...> nyi,
62 llvm::omp::Directive directive) const;
63
64private:
65 /// True if T is the same type as any of Ts.
66 template <typename T, typename... Ts>
67 static constexpr bool isAnyOf = (std::is_same_v<T, Ts> || ...);
68};
69
70template <typename... SupportedClauses, typename... NYIClauses>
71mlir::LogicalResult
73 llvm::omp::Directive directive) const {
74 static_assert(
75 (!isAnyOf<NYIClauses, SupportedClauses...> && ...),
76 "the supported and not-yet-implemented clause lists must be disjoint");
77
78 mlir::LogicalResult result = mlir::success();
79 for (const OMPClause *c : clauses) {
80 if (isa<NYIClauses...>(c)) {
81 std::string msg =
82 (llvm::Twine("OpenMP ") +
83 llvm::omp::getOpenMPDirectiveName(directive).upper() + " '" +
84 llvm::omp::getOpenMPClauseName(c->getClauseKind()) + "' clause")
85 .str();
86 cgm.errorNYI(c->getBeginLoc(), msg);
87 result = mlir::failure();
88 } else if (!isa<SupportedClauses...>(c)) {
89 // Unknown/illegal clause encountered.
90 llvm_unreachable("unexpected OpenMP clause");
91 }
92 }
93 return result;
94}
95
96} // namespace clang::CIRGen
97
98#endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENOPENMPCLAUSE_H
This file defines OpenMP AST classes for clauses.
This file defines OpenMP AST classes for executable directives and clauses.
This class organizes the cross-function state that is used while generating CIR code.
mlir::LogicalResult emitNYI(OpenMPNYIClauseList< NYIClauses... > nyi, llvm::omp::Directive directive) const
Verify the clauses of a directive to make sure all legal cases are either implemented or give a NYI e...
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
OpenMPClauseEmitter(CIRGenFunction &cgf, CIRGenModule &cgm, CIRGenBuilderTy &builder, mlir::Location loc, llvm::ArrayRef< const OMPClause * > clauses)
bool emitNumThreads(mlir::omp::NumThreadsClauseOps &result) const
This is a basic class for representing single OpenMP clause.
bool isa(CodeGen::Address addr)
Definition Address.h:330
const FunctionProtoType * T
A type-only list of OpenMP clause AST node types.