1 //===----- CGOpenMPRuntime.h - Interface to OpenMP Runtimes -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This provides a class for OpenMP runtime code generation.
12 //===----------------------------------------------------------------------===//
14 #ifndef CLANG_CODEGEN_OPENMPRUNTIME_H
15 #define CLANG_CODEGEN_OPENMPRUNTIME_H
17 #include "clang/AST/Type.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/IR/Type.h"
20 #include "llvm/IR/Value.h"
40 class CodeGenFunction;
43 class CGOpenMPRuntime {
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.
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
66 enum OpenMPRTLFunction {
67 // Call to void __kmpc_fork_call(ident_t *loc, kmp_int32 argc, kmpc_micro
69 OMPRTL__kmpc_fork_call,
70 // Call to kmp_int32 kmpc_global_thread_num(ident_t *loc);
71 OMPRTL__kmpc_global_thread_num
76 /// \brief Default const ident_t object used for initialization of all other
78 llvm::Constant *DefaultOpenMPPSource;
79 /// \brief Map of flags and corrsponding default locations.
80 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
81 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
82 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;
90 /// kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags;
91 /// KMP_IDENT_KMPC identifies this union
93 /// kmp_int32 reserved_2; /**< not really used in Fortran any more;
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
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.
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.
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.
123 llvm::StructType *IdentTy;
124 /// \brief Map for Sourcelocation and OpenMP runtime library debug locations.
125 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy;
126 OpenMPDebugLocMapTy OpenMPDebugLocMap;
127 /// \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;
139 explicit CGOpenMPRuntime(CodeGenModule &CGM);
140 ~CGOpenMPRuntime() {}
142 /// \brief Cleans up references to the objects in finished function.
143 /// \param CGF Reference to finished CodeGenFunction.
145 void FunctionFinished(CodeGenFunction &CGF);
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.
153 EmitOpenMPUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc,
154 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
156 /// \brief Generates global thread number value.
157 /// \param CGF Reference to current CodeGenFunction.
158 /// \param Loc Clang source location.
160 llvm::Value *GetOpenMPGlobalThreadNum(CodeGenFunction &CGF,
163 /// \brief Returns pointer to ident_t type;
164 llvm::Type *getIdentTyPointerTy();
166 /// \brief Returns pointer to kmpc_micro type;
167 llvm::Type *getKmpc_MicroPointerTy();
169 /// \brief Returns specified OpenMP runtime function.
170 /// \param Function OpenMP runtime function.
171 /// \return Specified function.
172 llvm::Constant *CreateRuntimeFunction(OpenMPRTLFunction Function);
174 } // namespace CodeGen