blob: 7ba7ada2b13f6dfd1ce983045d851996aa99d39c [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;
79 llvm::Value *GetOrCreateDefaultOpenMPLocation(OpenMPLocationFlags Flags);
80 /// \brief Describes ident structure that describes a source location.
81 /// All descriptions are taken from
82 /// http://llvm.org/svn/llvm-project/openmp/trunk/runtime/src/kmp.h
83 /// Original structure:
84 /// typedef struct ident {
85 /// kmp_int32 reserved_1; /**< might be used in Fortran;
86 /// see above */
87 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
88 /// KMP_IDENT_KMPC identifies this union
89 /// member */
90 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
91 /// see above */
92 ///#if USE_ITT_BUILD
93 /// /* but currently used for storing
94 /// region-specific ITT */
95 /// /* contextual information. */
96 ///#endif /* USE_ITT_BUILD */
97 /// kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for
98 /// C++ */
99 /// char const *psource; /**< String describing the source location.
100 /// The string is composed of semi-colon separated
101 // fields which describe the source file,
102 /// the function and a pair of line numbers that
103 /// delimit the construct.
104 /// */
105 /// } ident_t;
106 enum IdentFieldIndex {
107 /// \brief might be used in Fortran
108 IdentField_Reserved_1,
109 /// \brief OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
110 IdentField_Flags,
111 /// \brief Not really used in Fortran any more
112 IdentField_Reserved_2,
113 /// \brief Source[4] in Fortran, do not use for C++
114 IdentField_Reserved_3,
115 /// \brief String describing the source location. The string is composed of
116 /// semi-colon separated fields which describe the source file, the function
117 /// and a pair of line numbers that delimit the construct.
118 IdentField_PSource
119 };
120 llvm::StructType *IdentTy;
121 /// \brief The type for a microtask which gets passed to __kmpc_fork_call().
122 /// Original representation is:
123 /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...);
124 llvm::FunctionType *Kmpc_MicroTy;
125 /// \brief Map of local debug location and functions.
126 typedef llvm::DenseMap<llvm::Function *, llvm::Value *> OpenMPLocMapTy;
127 OpenMPLocMapTy OpenMPLocMap;
128 /// \brief Map of local gtid and functions.
129 typedef llvm::DenseMap<llvm::Function *, llvm::Value *> OpenMPGtidMapTy;
130 OpenMPGtidMapTy OpenMPGtidMap;
131
132public:
133 CGOpenMPRuntime(CodeGenModule &CGM);
134 ~CGOpenMPRuntime() {}
135
136 /// \brief Cleans up references to the objects in finished function.
137 /// \param CGF Reference to finished CodeGenFunction.
138 ///
139 void FunctionFinished(CodeGenFunction &CGF);
140
141 /// \brief Emits object of ident_t type with info for source location.
142 /// \param CGF Reference to current CodeGenFunction.
143 /// \param Loc Clang source location.
144 /// \param Flags Flags for OpenMP location.
145 ///
146 llvm::Value *
147 EmitOpenMPUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
148 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
149
150 /// \brief Generates global thread number value.
151 /// \param CGF Reference to current CodeGenFunction.
152 /// \param Loc Clang source location.
153 ///
154 llvm::Value *GetOpenMPGlobalThreadNum(CodeGenFunction &CGF,
155 SourceLocation Loc);
156
157 /// \brief Returns pointer to ident_t type;
158 llvm::Type *getIdentTyPointerTy();
159
160 /// \brief Returns pointer to kmpc_micro type;
161 llvm::Type *getKmpc_MicroPointerTy();
162
163 /// \brief Returns specified OpenMP runtime function.
164 /// \param Function OpenMP runtime function.
165 /// \return Specified function.
166 llvm::Constant *CreateRuntimeFunction(OpenMPRTLFunction Function);
167};
168}
169}
170
171#endif