blob: 06103cf4d6f50fddb3c800bc54c96ab6932f372e [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;
34}
35
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;
124 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
125 /// Original representation is:
126 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
127 llvm::FunctionType *Kmpc_MicroTy;
128 /// \brief Map of local debug location and functions.
129 typedef llvm::DenseMap<llvm::Function *, llvm::Value *> OpenMPLocMapTy;
130 OpenMPLocMapTy OpenMPLocMap;
131 /// \brief Map of local gtid and functions.
132 typedef llvm::DenseMap<llvm::Function *, llvm::Value *> OpenMPGtidMapTy;
133 OpenMPGtidMapTy OpenMPGtidMap;
134
135public:
136 CGOpenMPRuntime(CodeGenModule &CGM);
137 ~CGOpenMPRuntime() {}
138
139 /// \brief Cleans up references to the objects in finished function.
140 /// \param CGF Reference to finished CodeGenFunction.
141 ///
142 void FunctionFinished(CodeGenFunction &CGF);
143
144 /// \brief Emits object of ident_t type with info for source location.
145 /// \param CGF Reference to current CodeGenFunction.
146 /// \param Loc Clang source location.
147 /// \param Flags Flags for OpenMP location.
148 ///
149 llvm::Value *
150 EmitOpenMPUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
151 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
152
153 /// \brief Generates global thread number value.
154 /// \param CGF Reference to current CodeGenFunction.
155 /// \param Loc Clang source location.
156 ///
157 llvm::Value *GetOpenMPGlobalThreadNum(CodeGenFunction &CGF,
158 SourceLocation Loc);
159
160 /// \brief Returns pointer to ident_t type;
161 llvm::Type *getIdentTyPointerTy();
162
163 /// \brief Returns pointer to kmpc_micro type;
164 llvm::Type *getKmpc_MicroPointerTy();
165
166 /// \brief Returns specified OpenMP runtime function.
167 /// \param Function OpenMP runtime function.
168 /// \return Specified function.
169 llvm::Constant *CreateRuntimeFunction(OpenMPRTLFunction Function);
170};
171}
172}
173
174#endif