clang 23.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 emitProcBind(mlir::omp::ProcBindClauseOps &result) const;
44
45 /// Emit map clauses. The optional \p mapSyms parameter collects the
46 /// VarDecls corresponding to each map operand.
47 bool emitMap(mlir::omp::MapClauseOps &result,
48 llvm::SmallVectorImpl<const VarDecl *> *mapSyms = nullptr) const;
49
50 /// Verify the clauses of a directive to make sure all legal cases are either
51 /// implemented or give a NYI error. The \p SupportedClauses and \p
52 /// NYIClauses type lists must be disjoint and cover all clauses eligible for
53 /// the directive being processed.
54 template <typename... SupportedClauses, typename... NYIClauses>
56 llvm::omp::Directive directive) const;
57
58private:
59 /// True if T is the same type as any of Ts.
60 template <typename T, typename... Ts>
61 static constexpr bool isAnyOf = (std::is_same_v<T, Ts> || ...);
62};
63
64template <typename... SupportedClauses, typename... NYIClauses>
66 llvm::omp::Directive directive) const {
67 static_assert(
68 (!isAnyOf<NYIClauses, SupportedClauses...> && ...),
69 "the supported and not-yet-implemented clause lists must be disjoint");
70
71 for (const OMPClause *c : clauses) {
72 if (isa<NYIClauses...>(c)) {
73 std::string msg =
74 (llvm::Twine("OpenMP ") +
75 llvm::omp::getOpenMPDirectiveName(directive).upper() + " '" +
76 llvm::omp::getOpenMPClauseName(c->getClauseKind()) + "' clause")
77 .str();
78 cgm.errorNYI(c->getBeginLoc(), msg);
79 } else if (!isa<SupportedClauses...>(c)) {
80 // Unknown/illegal clause encountered.
81 llvm_unreachable("unexpected OpenMP clause");
82 }
83 }
84}
85
86} // namespace clang::CIRGen
87
88#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.
bool emitMap(mlir::omp::MapClauseOps &result, llvm::SmallVectorImpl< const VarDecl * > *mapSyms=nullptr) const
Emit map clauses.
void 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 emitProcBind(mlir::omp::ProcBindClauseOps &result) const
OpenMPClauseEmitter(CIRGenFunction &cgf, CIRGenModule &cgm, CIRGenBuilderTy &builder, mlir::Location loc, llvm::ArrayRef< const OMPClause * > clauses)
This is a basic class for representing single OpenMP clause.
bool isa(CodeGen::Address addr)
Definition Address.h:330
A type-only list of OpenMP clause AST node types.