1//===--- CIRGenOpenMPRuntime.h - OpenMP code generation helpers -----------===//
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_CIRGENOPENMPRUNTIME_H
10#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENOPENMPRUNTIME_H
11
12#include "clang/AST/DeclOpenMP.h"
13#include "clang/AST/GlobalDecl.h"
14#include "clang/AST/StmtOpenMP.h"
15#include "clang/CIR/Dialect/IR/CIRDialect.h"
16#include "llvm/ADT/DenseSet.h"
17
18namespace clang::CIRGen {
19
20class CIRGenModule;
21
22class CIRGenOpenMPRuntime {
23 CIRGenModule &cgm;
24
25 /// Declarations that have been force-emitted for the target device because
26 /// they are transitively referenced from declare target functions.
27 llvm::DenseSet<CanonicalDeclPtr<const Decl>> alreadyEmittedTargetDecls;
28
29 /// Returns false if the given function or declare reduction should be
30 /// emitted. Returns true if it should eb skipped.
31 /// emission).
32 bool emitTargetFunctions(GlobalDecl gd);
33
34 /// Returns false if given global variable should be emitted. Returns
35 /// true if it should be skipped.
36 bool emitTargetGlobalVariable(GlobalDecl gd);
37
38public:
39 explicit CIRGenOpenMPRuntime(CIRGenModule &cgm) : cgm(cgm) {}
40
41 /// Check whether the given GlobalDecl needs special handling for device
42 /// compilation. Returns false if it should be emitted, true if it should be
43 /// skipped.
44 bool emitTargetGlobal(GlobalDecl gd);
45
46 /// Mark a function reference as one that should be emitted on the device.
47 /// Returns false if it should be emitted, true if the function is already
48 /// handled and should be skipped.
49 bool markAsGlobalTarget(GlobalDecl gd);
50
51 /// Register a global variable that may need an offload entry.
52 void registerTargetGlobalVariable(const VarDecl *vd);
53
54 /// Return whether unified shared memory is required.
55 bool hasRequiresUnifiedSharedMemory() const;
56
57 /// If the function has an OMPDeclareTargetDeclAttr, set the corresponding
58 /// omp.declare_target attribute on the emitted cir.func op.
59 void emitDeclareTargetFunction(const FunctionDecl *fd, cir::FuncOp funcOp);
60};
61
62} // namespace clang::CIRGen
63
64#endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENOPENMPRUNTIME_H
65