blob: 862e8a148c563872f514f9ca3afa6361cf182509 [file] [log] [blame]
Alexey Bataev9959db52014-05-06 10:08:46 +00001//===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This provides a class for OpenMP runtime code generation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CLANG_CODEGEN_OPENMPRUNTIME_H
15#define CLANG_CODEGEN_OPENMPRUNTIME_H
16
17#include "clang/AST/Type.h"
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/IR/Type.h"
20#include "llvm/IR/Value.h"
21
22namespace llvm {
23class AllocaInst;
24class CallInst;
25class GlobalVariable;
26class Constant;
27class Function;
28class Module;
29class StructLayout;
30class FunctionType;
31class StructType;
32class Type;
33class Value;
Alexey Bataev23b69422014-06-18 07:08:49 +000034} // namespace llvm
Alexey Bataev9959db52014-05-06 10:08:46 +000035
36namespace clang {
37
38namespace CodeGen {
39
40class CodeGenFunction;
41class CodeGenModule;
42
43class CGOpenMPRuntime {
44public:
45 /// \brief Values for bit flags used in the ident_t to describe the fields.
46 /// All enumeric elements are named and described in accordance with the code
47 /// from http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
48 enum OpenMPLocationFlags {
49 /// \brief Use trampoline for internal microtask.
50 OMP_IDENT_IMD = 0x01,
51 /// \brief Use c-style ident structure.
52 OMP_IDENT_KMPC = 0x02,
53 /// \brief Atomic reduction option for kmpc_reduce.
54 OMP_ATOMIC_REDUCE = 0x10,
55 /// \brief Explicit 'barrier' directive.
56 OMP_IDENT_BARRIER_EXPL = 0x20,
57 /// \brief Implicit barrier in code.
58 OMP_IDENT_BARRIER_IMPL = 0x40,
59 /// \brief Implicit barrier in 'for' directive.
60 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
61 /// \brief Implicit barrier in 'sections' directive.
62 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
63 /// \brief Implicit barrier in 'single' directive.
64 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
65 };
66 enum OpenMPRTLFunction {
67 // Call to void __kmpc_fork_call(ident_t *loc, kmp_int32 argc, kmpc_micro
68 // microtask, ...);
69 OMPRTL__kmpc_fork_call,
70 // Call to kmp_int32 kmpc_global_thread_num(ident_t *loc);
71 OMPRTL__kmpc_global_thread_num
72 };
73
74private:
75 CodeGenModule &CGM;
76 /// \brief Default const ident_t object used for initialization of all other
77 /// ident_t objects.
78 llvm::Constant *DefaultOpenMPPSource;
Alexey Bataev15007ba2014-05-07 06:18:01 +000079 /// \brief Map of flags and corrsponding default locations.
80 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
81 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +000082 llvm::Value *GetOrCreateDefaultOpenMPLocation(OpenMPLocationFlags Flags);
83 /// \brief Describes ident structure that describes a source location.
84 /// All descriptions are taken from
85 /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
86 /// Original structure:
87 /// typedef struct ident {
88 /// kmp_int32 reserved_1; /**< might be used in Fortran;
89 /// see above */
90 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
91 /// KMP_IDENT_KMPC identifies this union
92 /// member */
93 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
94 /// see above */
95 ///#if USE_ITT_BUILD
96 /// /* but currently used for storing
97 /// region-specific ITT */
98 /// /* contextual information. */
99 ///#endif /* USE_ITT_BUILD */
100 /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for
101 /// C++ */
102 /// char const *psource; /**< String describing the source location.
103 /// The string is composed of semi-colon separated
104 // fields which describe the source file,
105 /// the function and a pair of line numbers that
106 /// delimit the construct.
107 /// */
108 /// } ident_t;
109 enum IdentFieldIndex {
110 /// \brief might be used in Fortran
111 IdentField_Reserved_1,
112 /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
113 IdentField_Flags,
114 /// \brief Not really used in Fortran any more
115 IdentField_Reserved_2,
116 /// \brief Source[4] in Fortran, do not use for C++
117 IdentField_Reserved_3,
118 /// \brief String describing the source location. The string is composed of
119 /// semi-colon separated fields which describe the source file, the function
120 /// and a pair of line numbers that delimit the construct.
121 IdentField_PSource
122 };
123 llvm::StructType *IdentTy;
Alexey Bataevf002aca2014-05-30 05:48:40 +0000124 /// \brief Map for Sourcelocation and OpenMP runtime library debug locations.
125 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
126 OpenMPDebugLocMapTy OpenMPDebugLocMap;
Alexey Bataev9959db52014-05-06 10:08:46 +0000127 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
128 /// Original representation is:
129 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
130 llvm::FunctionType *Kmpc_MicroTy;
131 /// \brief Map of local debug location and functions.
132 typedef llvm::DenseMap<llvm::Function *, llvm::Value *> OpenMPLocMapTy;
133 OpenMPLocMapTy OpenMPLocMap;
134 /// \brief Map of local gtid and functions.
135 typedef llvm::DenseMap<llvm::Function *, llvm::Value *> OpenMPGtidMapTy;
136 OpenMPGtidMapTy OpenMPGtidMap;
137
138public:
Alexey Bataev23b69422014-06-18 07:08:49 +0000139 explicit CGOpenMPRuntime(CodeGenModule &CGM);
Alexey Bataev9959db52014-05-06 10:08:46 +0000140 ~CGOpenMPRuntime() {}
141
142 /// \brief Cleans up references to the objects in finished function.
143 /// \param CGF Reference to finished CodeGenFunction.
144 ///
145 void FunctionFinished(CodeGenFunction &CGF);
146
147 /// \brief Emits object of ident_t type with info for source location.
148 /// \param CGF Reference to current CodeGenFunction.
149 /// \param Loc Clang source location.
150 /// \param Flags Flags for OpenMP location.
151 ///
152 llvm::Value *
153 EmitOpenMPUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
154 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
155
156 /// \brief Generates global thread number value.
157 /// \param CGF Reference to current CodeGenFunction.
158 /// \param Loc Clang source location.
159 ///
160 llvm::Value *GetOpenMPGlobalThreadNum(CodeGenFunction &CGF,
161 SourceLocation Loc);
162
163 /// \brief Returns pointer to ident_t type;
164 llvm::Type *getIdentTyPointerTy();
165
166 /// \brief Returns pointer to kmpc_micro type;
167 llvm::Type *getKmpc_MicroPointerTy();
168
169 /// \brief Returns specified OpenMP runtime function.
170 /// \param Function OpenMP runtime function.
171 /// \return Specified function.
172 llvm::Constant *CreateRuntimeFunction(OpenMPRTLFunction Function);
173};
Alexey Bataev23b69422014-06-18 07:08:49 +0000174} // namespace CodeGen
175} // namespace clang
Alexey Bataev9959db52014-05-06 10:08:46 +0000176
177#endif