Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===----- 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 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H |
| 15 | #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 17 | #include "CGValue.h" |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/Type.h" |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 19 | #include "clang/Basic/OpenMPKinds.h" |
Chandler Carruth | 0d9593d | 2015-01-14 11:29:14 +0000 | [diff] [blame] | 20 | #include "clang/Basic/SourceLocation.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseMap.h" |
Benjamin Kramer | 8fdba91 | 2016-02-02 14:24:21 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallPtrSet.h" |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringMap.h" |
Benjamin Kramer | 8fdba91 | 2016-02-02 14:24:21 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Function.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 25 | #include "llvm/IR/ValueHandle.h" |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 26 | |
| 27 | namespace llvm { |
| 28 | class ArrayType; |
| 29 | class Constant; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 30 | class FunctionType; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 31 | class GlobalVariable; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 32 | class StructType; |
| 33 | class Type; |
| 34 | class Value; |
| 35 | } // namespace llvm |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 36 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 37 | namespace clang { |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 38 | class Expr; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 39 | class GlobalDecl; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 40 | class OMPExecutableDirective; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 41 | class OMPLoopDirective; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 42 | class VarDecl; |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 43 | class OMPDeclareReductionDecl; |
| 44 | class IdentifierInfo; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 45 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 46 | namespace CodeGen { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 47 | class Address; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 48 | class CodeGenFunction; |
| 49 | class CodeGenModule; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 50 | |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 51 | /// A basic class for pre|post-action for advanced codegen sequence for OpenMP |
| 52 | /// region. |
| 53 | class PrePostActionTy { |
| 54 | public: |
| 55 | explicit PrePostActionTy() {} |
| 56 | virtual void Enter(CodeGenFunction &CGF) {} |
| 57 | virtual void Exit(CodeGenFunction &CGF) {} |
| 58 | virtual ~PrePostActionTy() {} |
| 59 | }; |
| 60 | |
| 61 | /// Class provides a way to call simple version of codegen for OpenMP region, or |
| 62 | /// an advanced with possible pre|post-actions in codegen. |
| 63 | class RegionCodeGenTy final { |
| 64 | intptr_t CodeGen; |
| 65 | typedef void (*CodeGenTy)(intptr_t, CodeGenFunction &, PrePostActionTy &); |
| 66 | CodeGenTy Callback; |
| 67 | mutable PrePostActionTy *PrePostAction; |
| 68 | RegionCodeGenTy() = delete; |
| 69 | RegionCodeGenTy &operator=(const RegionCodeGenTy &) = delete; |
| 70 | template <typename Callable> |
| 71 | static void CallbackFn(intptr_t CodeGen, CodeGenFunction &CGF, |
| 72 | PrePostActionTy &Action) { |
| 73 | return (*reinterpret_cast<Callable *>(CodeGen))(CGF, Action); |
| 74 | } |
| 75 | |
| 76 | public: |
| 77 | template <typename Callable> |
| 78 | RegionCodeGenTy( |
| 79 | Callable &&CodeGen, |
| 80 | typename std::enable_if< |
| 81 | !std::is_same<typename std::remove_reference<Callable>::type, |
| 82 | RegionCodeGenTy>::value>::type * = nullptr) |
| 83 | : CodeGen(reinterpret_cast<intptr_t>(&CodeGen)), |
| 84 | Callback(CallbackFn<typename std::remove_reference<Callable>::type>), |
| 85 | PrePostAction(nullptr) {} |
| 86 | void setAction(PrePostActionTy &Action) const { PrePostAction = &Action; } |
| 87 | void operator()(CodeGenFunction &CGF) const; |
| 88 | }; |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 89 | |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 90 | struct OMPTaskDataTy final { |
| 91 | SmallVector<const Expr *, 4> PrivateVars; |
| 92 | SmallVector<const Expr *, 4> PrivateCopies; |
| 93 | SmallVector<const Expr *, 4> FirstprivateVars; |
| 94 | SmallVector<const Expr *, 4> FirstprivateCopies; |
| 95 | SmallVector<const Expr *, 4> FirstprivateInits; |
Alexey Bataev | f93095a | 2016-05-05 08:46:22 +0000 | [diff] [blame] | 96 | SmallVector<const Expr *, 4> LastprivateVars; |
| 97 | SmallVector<const Expr *, 4> LastprivateCopies; |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 98 | SmallVector<std::pair<OpenMPDependClauseKind, const Expr *>, 4> Dependences; |
| 99 | llvm::PointerIntPair<llvm::Value *, 1, bool> Final; |
| 100 | llvm::PointerIntPair<llvm::Value *, 1, bool> Schedule; |
| 101 | unsigned NumberOfParts = 0; |
| 102 | bool Tied = true; |
| 103 | bool Nogroup = false; |
| 104 | }; |
| 105 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 106 | class CGOpenMPRuntime { |
Arpith Chacko Jacob | 5c309e4 | 2016-03-22 01:48:56 +0000 | [diff] [blame] | 107 | protected: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 108 | CodeGenModule &CGM; |
Arpith Chacko Jacob | 5c309e4 | 2016-03-22 01:48:56 +0000 | [diff] [blame] | 109 | |
| 110 | /// \brief Creates offloading entry for the provided entry ID \a ID, |
| 111 | /// address \a Addr and size \a Size. |
| 112 | virtual void createOffloadEntry(llvm::Constant *ID, llvm::Constant *Addr, |
| 113 | uint64_t Size); |
| 114 | |
| 115 | /// \brief Helper to emit outlined function for 'target' directive. |
| 116 | /// \param D Directive to emit. |
| 117 | /// \param ParentName Name of the function that encloses the target region. |
| 118 | /// \param OutlinedFn Outlined function value to be defined by this call. |
| 119 | /// \param OutlinedFnID Outlined function ID value to be defined by this call. |
| 120 | /// \param IsOffloadEntry True if the outlined function is an offload entry. |
| 121 | /// \param CodeGen Lambda codegen specific to an accelerator device. |
| 122 | /// An oulined function may not be an entry if, e.g. the if clause always |
| 123 | /// evaluates to false. |
| 124 | virtual void emitTargetOutlinedFunctionHelper(const OMPExecutableDirective &D, |
| 125 | StringRef ParentName, |
| 126 | llvm::Function *&OutlinedFn, |
| 127 | llvm::Constant *&OutlinedFnID, |
| 128 | bool IsOffloadEntry, |
| 129 | const RegionCodeGenTy &CodeGen); |
| 130 | |
| 131 | private: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 132 | /// \brief Default const ident_t object used for initialization of all other |
| 133 | /// ident_t objects. |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 134 | llvm::Constant *DefaultOpenMPPSource = nullptr; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 135 | /// \brief Map of flags and corresponding default locations. |
Alexey Bataev | 15007ba | 2014-05-07 06:18:01 +0000 | [diff] [blame] | 136 | typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy; |
| 137 | OpenMPDefaultLocMapTy OpenMPDefaultLocMap; |
Alexey Bataev | 50b3c95 | 2016-02-19 10:38:26 +0000 | [diff] [blame] | 138 | Address getOrCreateDefaultLocation(unsigned Flags); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 139 | |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 140 | llvm::StructType *IdentTy = nullptr; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 141 | /// \brief Map for SourceLocation and OpenMP runtime library debug locations. |
Alexey Bataev | f002aca | 2014-05-30 05:48:40 +0000 | [diff] [blame] | 142 | typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDebugLocMapTy; |
| 143 | OpenMPDebugLocMapTy OpenMPDebugLocMap; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 144 | /// \brief The type for a microtask which gets passed to __kmpc_fork_call(). |
| 145 | /// Original representation is: |
| 146 | /// typedef void (kmpc_micro)(kmp_int32 global_tid, kmp_int32 bound_tid,...); |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 147 | llvm::FunctionType *Kmpc_MicroTy = nullptr; |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 148 | /// \brief Stores debug location and ThreadID for the function. |
| 149 | struct DebugLocThreadIdTy { |
| 150 | llvm::Value *DebugLoc; |
| 151 | llvm::Value *ThreadID; |
| 152 | }; |
| 153 | /// \brief Map of local debug location, ThreadId and functions. |
| 154 | typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy> |
| 155 | OpenMPLocThreadIDMapTy; |
| 156 | OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap; |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 157 | /// Map of UDRs and corresponding combiner/initializer. |
| 158 | typedef llvm::DenseMap<const OMPDeclareReductionDecl *, |
| 159 | std::pair<llvm::Function *, llvm::Function *>> |
| 160 | UDRMapTy; |
| 161 | UDRMapTy UDRMap; |
| 162 | /// Map of functions and locally defined UDRs. |
| 163 | typedef llvm::DenseMap<llvm::Function *, |
| 164 | SmallVector<const OMPDeclareReductionDecl *, 4>> |
| 165 | FunctionUDRMapTy; |
| 166 | FunctionUDRMapTy FunctionUDRMap; |
| 167 | IdentifierInfo *In = nullptr; |
| 168 | IdentifierInfo *Out = nullptr; |
| 169 | IdentifierInfo *Priv = nullptr; |
| 170 | IdentifierInfo *Orig = nullptr; |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 171 | /// \brief Type kmp_critical_name, originally defined as typedef kmp_int32 |
| 172 | /// kmp_critical_name[8]; |
| 173 | llvm::ArrayType *KmpCriticalNameTy; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 174 | /// \brief An ordered map of auto-generated variables to their unique names. |
| 175 | /// It stores variables with the following names: 1) ".gomp_critical_user_" + |
| 176 | /// <critical_section_name> + ".var" for "omp critical" directives; 2) |
| 177 | /// <mangled_name_for_global_var> + ".cache." for cache for threadprivate |
| 178 | /// variables. |
| 179 | llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator> |
| 180 | InternalVars; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 181 | /// \brief Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *); |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 182 | llvm::Type *KmpRoutineEntryPtrTy = nullptr; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 183 | QualType KmpRoutineEntryPtrQTy; |
Alexey Bataev | 8fc69dc | 2015-05-18 07:54:53 +0000 | [diff] [blame] | 184 | /// \brief Type typedef struct kmp_task { |
| 185 | /// void * shareds; /**< pointer to block of pointers to |
| 186 | /// shared vars */ |
| 187 | /// kmp_routine_entry_t routine; /**< pointer to routine to call for |
| 188 | /// executing task */ |
| 189 | /// kmp_int32 part_id; /**< part id for the task */ |
| 190 | /// kmp_routine_entry_t destructors; /* pointer to function to invoke |
| 191 | /// deconstructors of firstprivate C++ objects */ |
| 192 | /// } kmp_task_t; |
| 193 | QualType KmpTaskTQTy; |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 194 | /// \brief Type typedef struct kmp_depend_info { |
| 195 | /// kmp_intptr_t base_addr; |
| 196 | /// size_t len; |
| 197 | /// struct { |
| 198 | /// bool in:1; |
| 199 | /// bool out:1; |
| 200 | /// } flags; |
| 201 | /// } kmp_depend_info_t; |
| 202 | QualType KmpDependInfoTy; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 203 | /// \brief Type struct __tgt_offload_entry{ |
| 204 | /// void *addr; // Pointer to the offload entry info. |
| 205 | /// // (function or global) |
| 206 | /// char *name; // Name of the function or global. |
| 207 | /// size_t size; // Size of the entry info (0 if it a function). |
| 208 | /// }; |
| 209 | QualType TgtOffloadEntryQTy; |
| 210 | /// struct __tgt_device_image{ |
| 211 | /// void *ImageStart; // Pointer to the target code start. |
| 212 | /// void *ImageEnd; // Pointer to the target code end. |
| 213 | /// // We also add the host entries to the device image, as it may be useful |
| 214 | /// // for the target runtime to have access to that information. |
| 215 | /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all |
| 216 | /// // the entries. |
| 217 | /// __tgt_offload_entry *EntriesEnd; // End of the table with all the |
| 218 | /// // entries (non inclusive). |
| 219 | /// }; |
| 220 | QualType TgtDeviceImageQTy; |
| 221 | /// struct __tgt_bin_desc{ |
| 222 | /// int32_t NumDevices; // Number of devices supported. |
| 223 | /// __tgt_device_image *DeviceImages; // Arrays of device images |
| 224 | /// // (one per device). |
| 225 | /// __tgt_offload_entry *EntriesBegin; // Begin of the table with all the |
| 226 | /// // entries. |
| 227 | /// __tgt_offload_entry *EntriesEnd; // End of the table with all the |
| 228 | /// // entries (non inclusive). |
| 229 | /// }; |
| 230 | QualType TgtBinaryDescriptorQTy; |
| 231 | /// \brief Entity that registers the offloading constants that were emitted so |
| 232 | /// far. |
| 233 | class OffloadEntriesInfoManagerTy { |
| 234 | CodeGenModule &CGM; |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 235 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 236 | /// \brief Number of entries registered so far. |
| 237 | unsigned OffloadingEntriesNum; |
| 238 | |
| 239 | public: |
| 240 | /// \brief Base class of the entries info. |
| 241 | class OffloadEntryInfo { |
| 242 | public: |
| 243 | /// \brief Kind of a given entry. Currently, only target regions are |
| 244 | /// supported. |
Reid Kleckner | dc78f95 | 2016-01-11 20:55:16 +0000 | [diff] [blame] | 245 | enum OffloadingEntryInfoKinds : unsigned { |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 246 | // Entry is a target region. |
| 247 | OFFLOAD_ENTRY_INFO_TARGET_REGION = 0, |
| 248 | // Invalid entry info. |
| 249 | OFFLOAD_ENTRY_INFO_INVALID = ~0u |
| 250 | }; |
| 251 | |
| 252 | OffloadEntryInfo() : Order(~0u), Kind(OFFLOAD_ENTRY_INFO_INVALID) {} |
| 253 | explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order) |
| 254 | : Order(Order), Kind(Kind) {} |
| 255 | |
| 256 | bool isValid() const { return Order != ~0u; } |
| 257 | unsigned getOrder() const { return Order; } |
| 258 | OffloadingEntryInfoKinds getKind() const { return Kind; } |
| 259 | static bool classof(const OffloadEntryInfo *Info) { return true; } |
| 260 | |
| 261 | protected: |
| 262 | // \brief Order this entry was emitted. |
| 263 | unsigned Order; |
| 264 | |
| 265 | OffloadingEntryInfoKinds Kind; |
| 266 | }; |
| 267 | |
| 268 | /// \brief Return true if a there are no entries defined. |
| 269 | bool empty() const; |
| 270 | /// \brief Return number of entries defined so far. |
| 271 | unsigned size() const { return OffloadingEntriesNum; } |
| 272 | OffloadEntriesInfoManagerTy(CodeGenModule &CGM) |
| 273 | : CGM(CGM), OffloadingEntriesNum(0) {} |
| 274 | |
| 275 | /// |
| 276 | /// Target region entries related. |
| 277 | /// |
| 278 | /// \brief Target region entries info. |
| 279 | class OffloadEntryInfoTargetRegion : public OffloadEntryInfo { |
| 280 | // \brief Address of the entity that has to be mapped for offloading. |
| 281 | llvm::Constant *Addr; |
| 282 | // \brief Address that can be used as the ID of the entry. |
| 283 | llvm::Constant *ID; |
| 284 | |
| 285 | public: |
| 286 | OffloadEntryInfoTargetRegion() |
| 287 | : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, ~0u), |
| 288 | Addr(nullptr), ID(nullptr) {} |
| 289 | explicit OffloadEntryInfoTargetRegion(unsigned Order, |
| 290 | llvm::Constant *Addr, |
| 291 | llvm::Constant *ID) |
| 292 | : OffloadEntryInfo(OFFLOAD_ENTRY_INFO_TARGET_REGION, Order), |
| 293 | Addr(Addr), ID(ID) {} |
| 294 | |
| 295 | llvm::Constant *getAddress() const { return Addr; } |
| 296 | llvm::Constant *getID() const { return ID; } |
| 297 | void setAddress(llvm::Constant *V) { |
| 298 | assert(!Addr && "Address as been set before!"); |
| 299 | Addr = V; |
| 300 | } |
| 301 | void setID(llvm::Constant *V) { |
| 302 | assert(!ID && "ID as been set before!"); |
| 303 | ID = V; |
| 304 | } |
| 305 | static bool classof(const OffloadEntryInfo *Info) { |
| 306 | return Info->getKind() == OFFLOAD_ENTRY_INFO_TARGET_REGION; |
| 307 | } |
| 308 | }; |
| 309 | /// \brief Initialize target region entry. |
| 310 | void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, |
| 311 | StringRef ParentName, unsigned LineNum, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 312 | unsigned Order); |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 313 | /// \brief Register target region entry. |
| 314 | void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, |
| 315 | StringRef ParentName, unsigned LineNum, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 316 | llvm::Constant *Addr, |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 317 | llvm::Constant *ID); |
| 318 | /// \brief Return true if a target region entry with the provided |
| 319 | /// information exists. |
| 320 | bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 321 | StringRef ParentName, unsigned LineNum) const; |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 322 | /// brief Applies action \a Action on all registered entries. |
| 323 | typedef llvm::function_ref<void(unsigned, unsigned, StringRef, unsigned, |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 324 | OffloadEntryInfoTargetRegion &)> |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 325 | OffloadTargetRegionEntryInfoActTy; |
| 326 | void actOnTargetRegionEntriesInfo( |
| 327 | const OffloadTargetRegionEntryInfoActTy &Action); |
| 328 | |
| 329 | private: |
| 330 | // Storage for target region entries kind. The storage is to be indexed by |
Samuel Antao | 2de62b0 | 2016-02-13 23:35:10 +0000 | [diff] [blame] | 331 | // file ID, device ID, parent function name and line number. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 332 | typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion> |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 333 | OffloadEntriesTargetRegionPerLine; |
| 334 | typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine> |
| 335 | OffloadEntriesTargetRegionPerParentName; |
| 336 | typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName> |
| 337 | OffloadEntriesTargetRegionPerFile; |
| 338 | typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile> |
| 339 | OffloadEntriesTargetRegionPerDevice; |
| 340 | typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy; |
| 341 | OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion; |
| 342 | }; |
| 343 | OffloadEntriesInfoManagerTy OffloadEntriesInfoManager; |
| 344 | |
| 345 | /// \brief Creates and registers offloading binary descriptor for the current |
| 346 | /// compilation unit. The function that does the registration is returned. |
| 347 | llvm::Function *createOffloadingBinaryDescriptorRegistration(); |
| 348 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 349 | /// \brief Creates all the offload entries in the current compilation unit |
| 350 | /// along with the associated metadata. |
| 351 | void createOffloadEntriesAndInfoMetadata(); |
| 352 | |
| 353 | /// \brief Loads all the offload entries information from the host IR |
| 354 | /// metadata. |
| 355 | void loadOffloadInfoMetadata(); |
| 356 | |
| 357 | /// \brief Returns __tgt_offload_entry type. |
| 358 | QualType getTgtOffloadEntryQTy(); |
| 359 | |
| 360 | /// \brief Returns __tgt_device_image type. |
| 361 | QualType getTgtDeviceImageQTy(); |
| 362 | |
| 363 | /// \brief Returns __tgt_bin_desc type. |
| 364 | QualType getTgtBinaryDescriptorQTy(); |
| 365 | |
| 366 | /// \brief Start scanning from statement \a S and and emit all target regions |
| 367 | /// found along the way. |
| 368 | /// \param S Starting statement. |
| 369 | /// \param ParentName Name of the function declaration that is being scanned. |
| 370 | void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 371 | |
| 372 | /// \brief Build type kmp_routine_entry_t (if not built yet). |
| 373 | void emitKmpRoutineEntryT(QualType KmpInt32Ty); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 374 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 375 | /// \brief Emits object of ident_t type with info for source location. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 376 | /// \param Flags Flags for OpenMP location. |
| 377 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 378 | llvm::Value *emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 50b3c95 | 2016-02-19 10:38:26 +0000 | [diff] [blame] | 379 | unsigned Flags = 0); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 380 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 381 | /// \brief Returns pointer to ident_t type. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 382 | llvm::Type *getIdentTyPointerTy(); |
| 383 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 384 | /// \brief Returns pointer to kmpc_micro type. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 385 | llvm::Type *getKmpc_MicroPointerTy(); |
| 386 | |
| 387 | /// \brief Returns specified OpenMP runtime function. |
| 388 | /// \param Function OpenMP runtime function. |
| 389 | /// \return Specified function. |
Alexey Bataev | 50b3c95 | 2016-02-19 10:38:26 +0000 | [diff] [blame] | 390 | llvm::Constant *createRuntimeFunction(unsigned Function); |
Alexey Bataev | 3a3bf0b | 2014-09-22 10:01:53 +0000 | [diff] [blame] | 391 | |
Alexander Musman | 21212e4 | 2015-03-13 10:38:23 +0000 | [diff] [blame] | 392 | /// \brief Returns __kmpc_for_static_init_* runtime function for the specified |
| 393 | /// size \a IVSize and sign \a IVSigned. |
| 394 | llvm::Constant *createForStaticInitFunction(unsigned IVSize, bool IVSigned); |
| 395 | |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 396 | /// \brief Returns __kmpc_dispatch_init_* runtime function for the specified |
| 397 | /// size \a IVSize and sign \a IVSigned. |
| 398 | llvm::Constant *createDispatchInitFunction(unsigned IVSize, bool IVSigned); |
| 399 | |
| 400 | /// \brief Returns __kmpc_dispatch_next_* runtime function for the specified |
| 401 | /// size \a IVSize and sign \a IVSigned. |
| 402 | llvm::Constant *createDispatchNextFunction(unsigned IVSize, bool IVSigned); |
| 403 | |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 404 | /// \brief Returns __kmpc_dispatch_fini_* runtime function for the specified |
| 405 | /// size \a IVSize and sign \a IVSigned. |
| 406 | llvm::Constant *createDispatchFiniFunction(unsigned IVSize, bool IVSigned); |
| 407 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 408 | /// \brief If the specified mangled name is not in the module, create and |
| 409 | /// return threadprivate cache object. This object is a pointer's worth of |
| 410 | /// storage that's reserved for use by the OpenMP runtime. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 411 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 412 | /// \return Cache variable for the specified threadprivate. |
| 413 | llvm::Constant *getOrCreateThreadPrivateCache(const VarDecl *VD); |
| 414 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 415 | /// \brief Emits address of the word in a memory where current thread id is |
| 416 | /// stored. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 417 | virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 418 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 419 | /// \brief Gets thread id value for the current thread. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 420 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 421 | llvm::Value *getThreadID(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 422 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 423 | /// \brief Gets (if variable with the given name already exist) or creates |
| 424 | /// internal global variable with the specified Name. The created variable has |
| 425 | /// linkage CommonLinkage by default and is initialized by null value. |
| 426 | /// \param Ty Type of the global variable. If it is exist already the type |
| 427 | /// must be the same. |
| 428 | /// \param Name Name of the variable. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 429 | llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty, |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 430 | const llvm::Twine &Name); |
| 431 | |
| 432 | /// \brief Set of threadprivate variables with the generated initializer. |
Benjamin Kramer | 8fdba91 | 2016-02-02 14:24:21 +0000 | [diff] [blame] | 433 | llvm::SmallPtrSet<const VarDecl *, 4> ThreadPrivateWithDefinition; |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 434 | |
| 435 | /// \brief Emits initialization code for the threadprivate variables. |
| 436 | /// \param VDAddr Address of the global variable \a VD. |
| 437 | /// \param Ctor Pointer to a global init function for \a VD. |
| 438 | /// \param CopyCtor Pointer to a global copy function for \a VD. |
| 439 | /// \param Dtor Pointer to a global destructor function for \a VD. |
| 440 | /// \param Loc Location of threadprivate declaration. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 441 | void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 442 | llvm::Value *Ctor, llvm::Value *CopyCtor, |
| 443 | llvm::Value *Dtor, SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 444 | |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 445 | /// \brief Returns corresponding lock object for the specified critical region |
| 446 | /// name. If the lock object does not exist it is created, otherwise the |
| 447 | /// reference to the existing copy is returned. |
| 448 | /// \param CriticalName Name of the critical region. |
| 449 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 450 | llvm::Value *getCriticalRegionLock(StringRef CriticalName); |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 451 | |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 452 | struct TaskResultTy { |
| 453 | llvm::Value *NewTask = nullptr; |
| 454 | llvm::Value *TaskEntry = nullptr; |
| 455 | llvm::Value *NewTaskNewTaskTTy = nullptr; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 456 | LValue TDBase; |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 457 | RecordDecl *KmpTaskTQTyRD = nullptr; |
Alexey Bataev | f93095a | 2016-05-05 08:46:22 +0000 | [diff] [blame] | 458 | llvm::Value *TaskDupFn = nullptr; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 459 | }; |
| 460 | /// Emit task region for the task directive. The task region is emitted in |
| 461 | /// several steps: |
| 462 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 463 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 464 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 465 | /// function: |
| 466 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 467 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 468 | /// return 0; |
| 469 | /// } |
| 470 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 471 | /// structure kmp_task_t returned by the previous call (if any). |
| 472 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 473 | /// resulting structure kmp_task_t. |
| 474 | /// \param D Current task directive. |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 475 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 476 | /// /*part_id*/, captured_struct */*__context*/); |
| 477 | /// \param SharedsTy A type which contains references the shared variables. |
| 478 | /// \param Shareds Context with the list of shared variables from the \p |
| 479 | /// TaskFunction. |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 480 | /// \param Data Additional data for task generation like tiednsee, final |
| 481 | /// state, list of privates etc. |
| 482 | TaskResultTy emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 483 | const OMPExecutableDirective &D, |
| 484 | llvm::Value *TaskFunction, QualType SharedsTy, |
| 485 | Address Shareds, const OMPTaskDataTy &Data); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 486 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 487 | public: |
| 488 | explicit CGOpenMPRuntime(CodeGenModule &CGM); |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 489 | virtual ~CGOpenMPRuntime() {} |
Alexey Bataev | 9179755 | 2015-03-18 04:13:55 +0000 | [diff] [blame] | 490 | virtual void clear(); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 491 | |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 492 | /// Emit code for the specified user defined reduction construct. |
| 493 | virtual void emitUserDefinedReduction(CodeGenFunction *CGF, |
| 494 | const OMPDeclareReductionDecl *D); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 495 | /// Get combiner/initializer for the specified user-defined reduction, if any. |
| 496 | virtual std::pair<llvm::Function *, llvm::Function *> |
| 497 | getUserDefinedReduction(const OMPDeclareReductionDecl *D); |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 498 | /// \brief Emits outlined function for the specified OpenMP parallel directive |
| 499 | /// \a D. This outlined function has type void(*)(kmp_int32 *ThreadID, |
| 500 | /// kmp_int32 BoundID, struct context_vars*). |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 501 | /// \param D OpenMP directive. |
| 502 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 503 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 504 | /// is a directive itself, for combined - its innermost directive). |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 505 | /// \param CodeGen Code generation sequence for the \a D directive. |
Carlo Bertolli | 430d8ec | 2016-03-03 20:34:23 +0000 | [diff] [blame] | 506 | virtual llvm::Value *emitParallelOrTeamsOutlinedFunction( |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 507 | const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, |
| 508 | OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen); |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 509 | |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 510 | /// \brief Emits outlined function for the OpenMP task directive \a D. This |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 511 | /// outlined function has type void(*)(kmp_int32 ThreadID, struct task_t* |
| 512 | /// TaskT). |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 513 | /// \param D OpenMP directive. |
| 514 | /// \param ThreadIDVar Variable for thread id in the current OpenMP region. |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 515 | /// \param PartIDVar Variable for partition id in the current OpenMP untied |
| 516 | /// task region. |
| 517 | /// \param TaskTVar Variable for task_t argument. |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 518 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 519 | /// is a directive itself, for combined - its innermost directive). |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 520 | /// \param CodeGen Code generation sequence for the \a D directive. |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 521 | /// \param Tied true if task is generated for tied task, false otherwise. |
| 522 | /// \param NumberOfParts Number of parts in untied task. Ignored for tied |
| 523 | /// tasks. |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 524 | /// |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 525 | virtual llvm::Value *emitTaskOutlinedFunction( |
| 526 | const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 527 | const VarDecl *PartIDVar, const VarDecl *TaskTVar, |
| 528 | OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, |
| 529 | bool Tied, unsigned &NumberOfParts); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 530 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 531 | /// \brief Cleans up references to the objects in finished function. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 532 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 533 | void functionFinished(CodeGenFunction &CGF); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 534 | |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 535 | /// \brief Emits code for parallel or serial call of the \a OutlinedFn with |
| 536 | /// variables captured in a record which address is stored in \a |
| 537 | /// CapturedStruct. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 538 | /// \param OutlinedFn Outlined function to be run in parallel threads. Type of |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 539 | /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). |
NAKAMURA Takumi | 62f0eb5 | 2015-09-11 08:13:32 +0000 | [diff] [blame] | 540 | /// \param CapturedVars A pointer to the record with the references to |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 541 | /// variables used in \a OutlinedFn function. |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 542 | /// \param IfCond Condition in the associated 'if' clause, if it was |
| 543 | /// specified, nullptr otherwise. |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 544 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 545 | virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 546 | llvm::Value *OutlinedFn, |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 547 | ArrayRef<llvm::Value *> CapturedVars, |
| 548 | const Expr *IfCond); |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 549 | |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 550 | /// \brief Emits a critical region. |
Alexey Bataev | 1809571 | 2014-10-10 12:19:54 +0000 | [diff] [blame] | 551 | /// \param CriticalName Name of the critical region. |
Alexey Bataev | 75ddfab | 2014-12-01 11:32:38 +0000 | [diff] [blame] | 552 | /// \param CriticalOpGen Generator for the statement associated with the given |
| 553 | /// critical region. |
Alexey Bataev | fc57d16 | 2015-12-15 10:55:09 +0000 | [diff] [blame] | 554 | /// \param Hint Value of the 'hint' clause (optional). |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 555 | virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 556 | const RegionCodeGenTy &CriticalOpGen, |
Alexey Bataev | fc57d16 | 2015-12-15 10:55:09 +0000 | [diff] [blame] | 557 | SourceLocation Loc, |
| 558 | const Expr *Hint = nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 559 | |
Alexey Bataev | 8d69065 | 2014-12-04 07:23:53 +0000 | [diff] [blame] | 560 | /// \brief Emits a master region. |
| 561 | /// \param MasterOpGen Generator for the statement associated with the given |
| 562 | /// master region. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 563 | virtual void emitMasterRegion(CodeGenFunction &CGF, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 564 | const RegionCodeGenTy &MasterOpGen, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 565 | SourceLocation Loc); |
Alexey Bataev | 8d69065 | 2014-12-04 07:23:53 +0000 | [diff] [blame] | 566 | |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 567 | /// \brief Emits code for a taskyield directive. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 568 | virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 9f797f3 | 2015-02-05 05:57:51 +0000 | [diff] [blame] | 569 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 570 | /// \brief Emit a taskgroup region. |
| 571 | /// \param TaskgroupOpGen Generator for the statement associated with the |
| 572 | /// given taskgroup region. |
| 573 | virtual void emitTaskgroupRegion(CodeGenFunction &CGF, |
| 574 | const RegionCodeGenTy &TaskgroupOpGen, |
| 575 | SourceLocation Loc); |
| 576 | |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 577 | /// \brief Emits a single region. |
| 578 | /// \param SingleOpGen Generator for the statement associated with the given |
| 579 | /// single region. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 580 | virtual void emitSingleRegion(CodeGenFunction &CGF, |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 581 | const RegionCodeGenTy &SingleOpGen, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 582 | SourceLocation Loc, |
| 583 | ArrayRef<const Expr *> CopyprivateVars, |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 584 | ArrayRef<const Expr *> DestExprs, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 585 | ArrayRef<const Expr *> SrcExprs, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 586 | ArrayRef<const Expr *> AssignmentOps); |
Alexey Bataev | 6956e2e | 2015-02-05 06:35:41 +0000 | [diff] [blame] | 587 | |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 588 | /// \brief Emit an ordered region. |
| 589 | /// \param OrderedOpGen Generator for the statement associated with the given |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 590 | /// ordered region. |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 591 | virtual void emitOrderedRegion(CodeGenFunction &CGF, |
| 592 | const RegionCodeGenTy &OrderedOpGen, |
Alexey Bataev | 5f600d6 | 2015-09-29 03:48:57 +0000 | [diff] [blame] | 593 | SourceLocation Loc, bool IsThreads); |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 594 | |
Alexey Bataev | f268568 | 2015-03-30 04:30:22 +0000 | [diff] [blame] | 595 | /// \brief Emit an implicit/explicit barrier for OpenMP threads. |
| 596 | /// \param Kind Directive for which this implicit barrier call must be |
| 597 | /// generated. Must be OMPD_barrier for explicit barrier generation. |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 598 | /// \param EmitChecks true if need to emit checks for cancellation barriers. |
| 599 | /// \param ForceSimpleCall true simple barrier call must be emitted, false if |
| 600 | /// runtime class decides which one to emit (simple or with cancellation |
| 601 | /// checks). |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 602 | /// |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 603 | virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 604 | OpenMPDirectiveKind Kind, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 605 | bool EmitChecks = true, |
| 606 | bool ForceSimpleCall = false); |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 607 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 608 | /// \brief Check if the specified \a ScheduleKind is static non-chunked. |
| 609 | /// This kind of worksharing directive is emitted without outer loop. |
| 610 | /// \param ScheduleKind Schedule kind specified in the 'schedule' clause. |
| 611 | /// \param Chunked True if chunk is specified in the clause. |
| 612 | /// |
| 613 | virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind, |
| 614 | bool Chunked) const; |
| 615 | |
Carlo Bertolli | fc35ad2 | 2016-03-07 16:04:49 +0000 | [diff] [blame] | 616 | /// \brief Check if the specified \a ScheduleKind is static non-chunked. |
| 617 | /// This kind of distribute directive is emitted without outer loop. |
| 618 | /// \param ScheduleKind Schedule kind specified in the 'dist_schedule' clause. |
| 619 | /// \param Chunked True if chunk is specified in the clause. |
| 620 | /// |
| 621 | virtual bool isStaticNonchunked(OpenMPDistScheduleClauseKind ScheduleKind, |
| 622 | bool Chunked) const; |
| 623 | |
Alexander Musman | df7a8e2 | 2015-01-22 08:49:35 +0000 | [diff] [blame] | 624 | /// \brief Check if the specified \a ScheduleKind is dynamic. |
| 625 | /// This kind of worksharing directive is emitted without outer loop. |
| 626 | /// \param ScheduleKind Schedule Kind specified in the 'schedule' clause. |
| 627 | /// |
| 628 | virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const; |
| 629 | |
NAKAMURA Takumi | ff7a925 | 2015-09-08 09:42:41 +0000 | [diff] [blame] | 630 | virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 631 | OpenMPScheduleClauseKind SchedKind, |
| 632 | unsigned IVSize, bool IVSigned, |
| 633 | bool Ordered, llvm::Value *UB, |
| 634 | llvm::Value *Chunk = nullptr); |
| 635 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 636 | /// \brief Call the appropriate runtime routine to initialize it before start |
| 637 | /// of loop. |
| 638 | /// |
| 639 | /// Depending on the loop schedule, it is nesessary to call some runtime |
| 640 | /// routine before start of the OpenMP loop to get the loop upper / lower |
| 641 | /// bounds \a LB and \a UB and stride \a ST. |
| 642 | /// |
| 643 | /// \param CGF Reference to current CodeGenFunction. |
| 644 | /// \param Loc Clang source location. |
NAKAMURA Takumi | eca0838 | 2014-12-17 14:47:06 +0000 | [diff] [blame] | 645 | /// \param SchedKind Schedule kind, specified by the 'schedule' clause. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 646 | /// \param IVSize Size of the iteration variable in bits. |
| 647 | /// \param IVSigned Sign of the interation variable. |
Alexey Bataev | d7589ffe | 2015-05-20 13:12:48 +0000 | [diff] [blame] | 648 | /// \param Ordered true if loop is ordered, false otherwise. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 649 | /// \param IL Address of the output variable in which the flag of the |
| 650 | /// last iteration is returned. |
| 651 | /// \param LB Address of the output variable in which the lower iteration |
| 652 | /// number is returned. |
| 653 | /// \param UB Address of the output variable in which the upper iteration |
| 654 | /// number is returned. |
| 655 | /// \param ST Address of the output variable in which the stride value is |
| 656 | /// returned nesessary to generated the static_chunked scheduled loop. |
| 657 | /// \param Chunk Value of the chunk for the static_chunked scheduled loop. |
| 658 | /// For the default (nullptr) value, the chunk 1 will be used. |
| 659 | /// |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 660 | virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 661 | OpenMPScheduleClauseKind SchedKind, |
| 662 | unsigned IVSize, bool IVSigned, bool Ordered, |
| 663 | Address IL, Address LB, |
| 664 | Address UB, Address ST, |
| 665 | llvm::Value *Chunk = nullptr); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 666 | |
Carlo Bertolli | fc35ad2 | 2016-03-07 16:04:49 +0000 | [diff] [blame] | 667 | /// |
| 668 | /// \param CGF Reference to current CodeGenFunction. |
| 669 | /// \param Loc Clang source location. |
| 670 | /// \param SchedKind Schedule kind, specified by the 'dist_schedule' clause. |
| 671 | /// \param IVSize Size of the iteration variable in bits. |
| 672 | /// \param IVSigned Sign of the interation variable. |
| 673 | /// \param Ordered true if loop is ordered, false otherwise. |
| 674 | /// \param IL Address of the output variable in which the flag of the |
| 675 | /// last iteration is returned. |
| 676 | /// \param LB Address of the output variable in which the lower iteration |
| 677 | /// number is returned. |
| 678 | /// \param UB Address of the output variable in which the upper iteration |
| 679 | /// number is returned. |
| 680 | /// \param ST Address of the output variable in which the stride value is |
| 681 | /// returned nesessary to generated the static_chunked scheduled loop. |
| 682 | /// \param Chunk Value of the chunk for the static_chunked scheduled loop. |
| 683 | /// For the default (nullptr) value, the chunk 1 will be used. |
| 684 | /// |
| 685 | virtual void emitDistributeStaticInit(CodeGenFunction &CGF, SourceLocation Loc, |
| 686 | OpenMPDistScheduleClauseKind SchedKind, |
| 687 | unsigned IVSize, bool IVSigned, |
| 688 | bool Ordered, Address IL, Address LB, |
| 689 | Address UB, Address ST, |
| 690 | llvm::Value *Chunk = nullptr); |
| 691 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 692 | /// \brief Call the appropriate runtime routine to notify that we finished |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 693 | /// iteration of the ordered loop with the dynamic scheduling. |
| 694 | /// |
| 695 | /// \param CGF Reference to current CodeGenFunction. |
| 696 | /// \param Loc Clang source location. |
| 697 | /// \param IVSize Size of the iteration variable in bits. |
| 698 | /// \param IVSigned Sign of the interation variable. |
| 699 | /// |
Alexey Bataev | d7589ffe | 2015-05-20 13:12:48 +0000 | [diff] [blame] | 700 | virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF, |
| 701 | SourceLocation Loc, unsigned IVSize, |
| 702 | bool IVSigned); |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 703 | |
| 704 | /// \brief Call the appropriate runtime routine to notify that we finished |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 705 | /// all the work with current loop. |
| 706 | /// |
| 707 | /// \param CGF Reference to current CodeGenFunction. |
| 708 | /// \param Loc Clang source location. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 709 | /// |
Alexey Bataev | 98eb6e3 | 2015-04-22 11:15:40 +0000 | [diff] [blame] | 710 | virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 711 | |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 712 | /// Call __kmpc_dispatch_next( |
| 713 | /// ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, |
| 714 | /// kmp_int[32|64] *p_lower, kmp_int[32|64] *p_upper, |
| 715 | /// kmp_int[32|64] *p_stride); |
| 716 | /// \param IVSize Size of the iteration variable in bits. |
| 717 | /// \param IVSigned Sign of the interation variable. |
| 718 | /// \param IL Address of the output variable in which the flag of the |
| 719 | /// last iteration is returned. |
| 720 | /// \param LB Address of the output variable in which the lower iteration |
| 721 | /// number is returned. |
| 722 | /// \param UB Address of the output variable in which the upper iteration |
| 723 | /// number is returned. |
| 724 | /// \param ST Address of the output variable in which the stride value is |
| 725 | /// returned. |
| 726 | virtual llvm::Value *emitForNext(CodeGenFunction &CGF, SourceLocation Loc, |
| 727 | unsigned IVSize, bool IVSigned, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 728 | Address IL, Address LB, |
| 729 | Address UB, Address ST); |
Alexander Musman | 92bdaab | 2015-03-12 13:37:50 +0000 | [diff] [blame] | 730 | |
Alexey Bataev | b205978 | 2014-10-13 08:23:51 +0000 | [diff] [blame] | 731 | /// \brief Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 |
| 732 | /// global_tid, kmp_int32 num_threads) to generate code for 'num_threads' |
| 733 | /// clause. |
| 734 | /// \param NumThreads An integer value of threads. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 735 | virtual void emitNumThreadsClause(CodeGenFunction &CGF, |
| 736 | llvm::Value *NumThreads, |
| 737 | SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 738 | |
Alexey Bataev | 7f210c6 | 2015-06-18 13:40:03 +0000 | [diff] [blame] | 739 | /// \brief Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 |
| 740 | /// global_tid, int proc_bind) to generate code for 'proc_bind' clause. |
| 741 | virtual void emitProcBindClause(CodeGenFunction &CGF, |
| 742 | OpenMPProcBindClauseKind ProcBind, |
| 743 | SourceLocation Loc); |
| 744 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 745 | /// \brief Returns address of the threadprivate variable for the current |
| 746 | /// thread. |
NAKAMURA Takumi | cdcbfba | 2014-11-11 07:58:06 +0000 | [diff] [blame] | 747 | /// \param VD Threadprivate variable. |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 748 | /// \param VDAddr Address of the global variable \a VD. |
| 749 | /// \param Loc Location of the reference to threadprivate var. |
| 750 | /// \return Address of the threadprivate variable for the current thread. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 751 | virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF, |
| 752 | const VarDecl *VD, |
| 753 | Address VDAddr, |
| 754 | SourceLocation Loc); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 755 | |
| 756 | /// \brief Emit a code for initialization of threadprivate variable. It emits |
| 757 | /// a call to runtime library which adds initial value to the newly created |
| 758 | /// threadprivate variable (if it is not constant) and registers destructor |
| 759 | /// for the variable (if any). |
| 760 | /// \param VD Threadprivate variable. |
| 761 | /// \param VDAddr Address of the global variable \a VD. |
| 762 | /// \param Loc Location of threadprivate declaration. |
| 763 | /// \param PerformInit true if initialization expression is not constant. |
| 764 | virtual llvm::Function * |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 765 | emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 766 | SourceLocation Loc, bool PerformInit, |
| 767 | CodeGenFunction *CGF = nullptr); |
Alexey Bataev | cc37cc1 | 2014-11-20 04:34:54 +0000 | [diff] [blame] | 768 | |
| 769 | /// \brief Emit flush of the variables specified in 'omp flush' directive. |
| 770 | /// \param Vars List of variables to flush. |
Alexey Bataev | 3eff5f4 | 2015-02-25 08:32:46 +0000 | [diff] [blame] | 771 | virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars, |
| 772 | SourceLocation Loc); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 773 | |
| 774 | /// \brief Emit task region for the task directive. The task region is |
Nico Weber | 20b0ce3 | 2015-04-28 18:19:18 +0000 | [diff] [blame] | 775 | /// emitted in several steps: |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 776 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 777 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 778 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 779 | /// function: |
| 780 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 781 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 782 | /// return 0; |
| 783 | /// } |
| 784 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 785 | /// structure kmp_task_t returned by the previous call (if any). |
| 786 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 787 | /// resulting structure kmp_task_t. |
| 788 | /// 4. Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, |
| 789 | /// kmp_task_t *new_task), where new_task is a resulting structure from |
| 790 | /// previous items. |
Alexey Bataev | 36c1eb9 | 2015-04-30 06:51:57 +0000 | [diff] [blame] | 791 | /// \param D Current task directive. |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 792 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 793 | /// /*part_id*/, captured_struct */*__context*/); |
| 794 | /// \param SharedsTy A type which contains references the shared variables. |
Alexey Bataev | 1d2353d | 2015-06-24 11:01:36 +0000 | [diff] [blame] | 795 | /// \param Shareds Context with the list of shared variables from the \p |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 796 | /// TaskFunction. |
Alexey Bataev | 1d67713 | 2015-04-22 13:57:31 +0000 | [diff] [blame] | 797 | /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr |
| 798 | /// otherwise. |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 799 | /// \param Data Additional data for task generation like tiednsee, final |
| 800 | /// state, list of privates etc. |
| 801 | virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, |
| 802 | const OMPExecutableDirective &D, |
| 803 | llvm::Value *TaskFunction, QualType SharedsTy, |
| 804 | Address Shareds, const Expr *IfCond, |
| 805 | const OMPTaskDataTy &Data); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 806 | |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 807 | /// Emit task region for the taskloop directive. The taskloop region is |
| 808 | /// emitted in several steps: |
| 809 | /// 1. Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 |
| 810 | /// gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, |
| 811 | /// kmp_routine_entry_t *task_entry). Here task_entry is a pointer to the |
| 812 | /// function: |
| 813 | /// kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) { |
| 814 | /// TaskFunction(gtid, tt->part_id, tt->shareds); |
| 815 | /// return 0; |
| 816 | /// } |
| 817 | /// 2. Copy a list of shared variables to field shareds of the resulting |
| 818 | /// structure kmp_task_t returned by the previous call (if any). |
| 819 | /// 3. Copy a pointer to destructions function to field destructions of the |
| 820 | /// resulting structure kmp_task_t. |
| 821 | /// 4. Emit a call to void __kmpc_taskloop(ident_t *loc, int gtid, kmp_task_t |
| 822 | /// *task, int if_val, kmp_uint64 *lb, kmp_uint64 *ub, kmp_int64 st, int |
| 823 | /// nogroup, int sched, kmp_uint64 grainsize, void *task_dup ), where new_task |
| 824 | /// is a resulting structure from |
| 825 | /// previous items. |
| 826 | /// \param D Current task directive. |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 827 | /// \param TaskFunction An LLVM function with type void (*)(i32 /*gtid*/, i32 |
| 828 | /// /*part_id*/, captured_struct */*__context*/); |
| 829 | /// \param SharedsTy A type which contains references the shared variables. |
| 830 | /// \param Shareds Context with the list of shared variables from the \p |
| 831 | /// TaskFunction. |
| 832 | /// \param IfCond Not a nullptr if 'if' clause was specified, nullptr |
| 833 | /// otherwise. |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 834 | /// \param Data Additional data for task generation like tiednsee, final |
| 835 | /// state, list of privates etc. |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 836 | virtual void emitTaskLoopCall( |
| 837 | CodeGenFunction &CGF, SourceLocation Loc, const OMPLoopDirective &D, |
Alexey Bataev | 24b5bae | 2016-04-28 09:23:51 +0000 | [diff] [blame] | 838 | llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds, |
| 839 | const Expr *IfCond, const OMPTaskDataTy &Data); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 840 | |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 841 | /// \brief Emit code for the directive that does not require outlining. |
| 842 | /// |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 843 | /// \param InnermostKind Kind of innermost directive (for simple directives it |
| 844 | /// is a directive itself, for combined - its innermost directive). |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 845 | /// \param CodeGen Code generation sequence for the \a D directive. |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 846 | /// \param HasCancel true if region has inner cancel directive, false |
| 847 | /// otherwise. |
Alexey Bataev | 6f1ffc0 | 2015-04-10 04:50:10 +0000 | [diff] [blame] | 848 | virtual void emitInlinedDirective(CodeGenFunction &CGF, |
Alexey Bataev | 81c7ea0 | 2015-07-03 09:56:58 +0000 | [diff] [blame] | 849 | OpenMPDirectiveKind InnermostKind, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 850 | const RegionCodeGenTy &CodeGen, |
| 851 | bool HasCancel = false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 852 | /// \brief Emit a code for reduction clause. Next code should be emitted for |
| 853 | /// reduction: |
| 854 | /// \code |
| 855 | /// |
| 856 | /// static kmp_critical_name lock = { 0 }; |
| 857 | /// |
| 858 | /// void reduce_func(void *lhs[<n>], void *rhs[<n>]) { |
| 859 | /// ... |
| 860 | /// *(Type<i>*)lhs[i] = RedOp<i>(*(Type<i>*)lhs[i], *(Type<i>*)rhs[i]); |
| 861 | /// ... |
| 862 | /// } |
| 863 | /// |
| 864 | /// ... |
| 865 | /// void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]}; |
| 866 | /// switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), |
| 867 | /// RedList, reduce_func, &<lock>)) { |
| 868 | /// case 1: |
| 869 | /// ... |
| 870 | /// <LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]); |
| 871 | /// ... |
| 872 | /// __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>); |
| 873 | /// break; |
| 874 | /// case 2: |
| 875 | /// ... |
| 876 | /// Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i])); |
| 877 | /// ... |
| 878 | /// break; |
| 879 | /// default:; |
| 880 | /// } |
| 881 | /// \endcode |
| 882 | /// |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 883 | /// \param Privates List of private copies for original reduction arguments. |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 884 | /// \param LHSExprs List of LHS in \a ReductionOps reduction operations. |
| 885 | /// \param RHSExprs List of RHS in \a ReductionOps reduction operations. |
| 886 | /// \param ReductionOps List of reduction operations in form 'LHS binop RHS' |
| 887 | /// or 'operator binop(LHS, RHS)'. |
| 888 | /// \param WithNowait true if parent directive has also nowait clause, false |
| 889 | /// otherwise. |
| 890 | virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 891 | ArrayRef<const Expr *> Privates, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 892 | ArrayRef<const Expr *> LHSExprs, |
| 893 | ArrayRef<const Expr *> RHSExprs, |
| 894 | ArrayRef<const Expr *> ReductionOps, |
Alexey Bataev | 89e7e8e | 2015-06-17 06:21:39 +0000 | [diff] [blame] | 895 | bool WithNowait, bool SimpleReduction); |
Alexey Bataev | 8b8e202 | 2015-04-27 05:22:09 +0000 | [diff] [blame] | 896 | |
| 897 | /// \brief Emit code for 'taskwait' directive. |
| 898 | virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc); |
Alexey Bataev | 0f34da1 | 2015-07-02 04:17:07 +0000 | [diff] [blame] | 899 | |
| 900 | /// \brief Emit code for 'cancellation point' construct. |
| 901 | /// \param CancelRegion Region kind for which the cancellation point must be |
| 902 | /// emitted. |
| 903 | /// |
| 904 | virtual void emitCancellationPointCall(CodeGenFunction &CGF, |
| 905 | SourceLocation Loc, |
| 906 | OpenMPDirectiveKind CancelRegion); |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 907 | |
| 908 | /// \brief Emit code for 'cancel' construct. |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 909 | /// \param IfCond Condition in the associated 'if' clause, if it was |
| 910 | /// specified, nullptr otherwise. |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 911 | /// \param CancelRegion Region kind for which the cancel must be emitted. |
| 912 | /// |
| 913 | virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 914 | const Expr *IfCond, |
Alexey Bataev | 7d5d33e | 2015-07-06 05:50:32 +0000 | [diff] [blame] | 915 | OpenMPDirectiveKind CancelRegion); |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 916 | |
| 917 | /// \brief Emit outilined function for 'target' directive. |
| 918 | /// \param D Directive to emit. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 919 | /// \param ParentName Name of the function that encloses the target region. |
| 920 | /// \param OutlinedFn Outlined function value to be defined by this call. |
| 921 | /// \param OutlinedFnID Outlined function ID value to be defined by this call. |
| 922 | /// \param IsOffloadEntry True if the outlined function is an offload entry. |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 923 | /// \param CodeGen Code generation sequence for the \a D directive. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 924 | /// An oulined function may not be an entry if, e.g. the if clause always |
| 925 | /// evaluates to false. |
| 926 | virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D, |
| 927 | StringRef ParentName, |
| 928 | llvm::Function *&OutlinedFn, |
| 929 | llvm::Constant *&OutlinedFnID, |
Alexey Bataev | 14fa1c6 | 2016-03-29 05:34:15 +0000 | [diff] [blame] | 930 | bool IsOffloadEntry, |
| 931 | const RegionCodeGenTy &CodeGen); |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 932 | |
| 933 | /// \brief Emit the target offloading code associated with \a D. The emitted |
| 934 | /// code attempts offloading the execution to the device, an the event of |
| 935 | /// a failure it executes the host version outlined in \a OutlinedFn. |
| 936 | /// \param D Directive to emit. |
| 937 | /// \param OutlinedFn Host version of the code to be offloaded. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 938 | /// \param OutlinedFnID ID of host version of the code to be offloaded. |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 939 | /// \param IfCond Expression evaluated in if clause associated with the target |
| 940 | /// directive, or null if no if clause is used. |
| 941 | /// \param Device Expression evaluated in device clause associated with the |
| 942 | /// target directive, or null if no device clause is used. |
| 943 | /// \param CapturedVars Values captured in the current region. |
| 944 | virtual void emitTargetCall(CodeGenFunction &CGF, |
| 945 | const OMPExecutableDirective &D, |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 946 | llvm::Value *OutlinedFn, |
| 947 | llvm::Value *OutlinedFnID, const Expr *IfCond, |
Samuel Antao | bed3c46 | 2015-10-02 16:14:20 +0000 | [diff] [blame] | 948 | const Expr *Device, |
| 949 | ArrayRef<llvm::Value *> CapturedVars); |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 950 | |
| 951 | /// \brief Emit the target regions enclosed in \a GD function definition or |
| 952 | /// the function itself in case it is a valid device function. Returns true if |
| 953 | /// \a GD was dealt with successfully. |
Nico Weber | a2abe8c | 2016-01-06 19:13:49 +0000 | [diff] [blame] | 954 | /// \param GD Function to scan. |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 955 | virtual bool emitTargetFunctions(GlobalDecl GD); |
| 956 | |
| 957 | /// \brief Emit the global variable if it is a valid device global variable. |
| 958 | /// Returns true if \a GD was dealt with successfully. |
| 959 | /// \param GD Variable declaration to emit. |
| 960 | virtual bool emitTargetGlobalVariable(GlobalDecl GD); |
| 961 | |
| 962 | /// \brief Emit the global \a GD if it is meaningful for the target. Returns |
| 963 | /// if it was emitted succesfully. |
| 964 | /// \param GD Global to scan. |
| 965 | virtual bool emitTargetGlobal(GlobalDecl GD); |
| 966 | |
| 967 | /// \brief Creates the offloading descriptor in the event any target region |
| 968 | /// was emitted in the current module and return the function that registers |
| 969 | /// it. |
| 970 | virtual llvm::Function *emitRegistrationFunction(); |
Carlo Bertolli | 430d8ec | 2016-03-03 20:34:23 +0000 | [diff] [blame] | 971 | |
| 972 | /// \brief Emits code for teams call of the \a OutlinedFn with |
| 973 | /// variables captured in a record which address is stored in \a |
| 974 | /// CapturedStruct. |
| 975 | /// \param OutlinedFn Outlined function to be run by team masters. Type of |
| 976 | /// this function is void(*)(kmp_int32 *, kmp_int32, struct context_vars*). |
| 977 | /// \param CapturedVars A pointer to the record with the references to |
| 978 | /// variables used in \a OutlinedFn function. |
| 979 | /// |
| 980 | virtual void emitTeamsCall(CodeGenFunction &CGF, |
| 981 | const OMPExecutableDirective &D, |
| 982 | SourceLocation Loc, llvm::Value *OutlinedFn, |
| 983 | ArrayRef<llvm::Value *> CapturedVars); |
| 984 | |
| 985 | /// \brief Emits call to void __kmpc_push_num_teams(ident_t *loc, kmp_int32 |
| 986 | /// global_tid, kmp_int32 num_teams, kmp_int32 thread_limit) to generate code |
| 987 | /// for num_teams clause. |
Carlo Bertolli | c687225 | 2016-04-04 15:55:02 +0000 | [diff] [blame] | 988 | /// \param NumTeams An integer expression of teams. |
| 989 | /// \param ThreadLimit An integer expression of threads. |
| 990 | virtual void emitNumTeamsClause(CodeGenFunction &CGF, const Expr *NumTeams, |
| 991 | const Expr *ThreadLimit, SourceLocation Loc); |
Samuel Antao | df158d5 | 2016-04-27 22:58:19 +0000 | [diff] [blame] | 992 | |
| 993 | /// \brief Emit the target data mapping code associated with \a D. |
| 994 | /// \param D Directive to emit. |
| 995 | /// \param IfCond Expression evaluated in if clause associated with the target |
| 996 | /// directive, or null if no if clause is used. |
| 997 | /// \param Device Expression evaluated in device clause associated with the |
| 998 | /// target directive, or null if no device clause is used. |
NAKAMURA Takumi | 01d07db | 2016-04-28 02:45:21 +0000 | [diff] [blame] | 999 | /// \param CodeGen Function that emits the enclosed region. |
Samuel Antao | df158d5 | 2016-04-27 22:58:19 +0000 | [diff] [blame] | 1000 | virtual void emitTargetDataCalls(CodeGenFunction &CGF, |
| 1001 | const OMPExecutableDirective &D, |
| 1002 | const Expr *IfCond, const Expr *Device, |
| 1003 | const RegionCodeGenTy &CodeGen); |
Samuel Antao | bd0ae2e | 2016-04-27 23:07:29 +0000 | [diff] [blame] | 1004 | |
Samuel Antao | 8dd6628 | 2016-04-27 23:14:30 +0000 | [diff] [blame] | 1005 | /// \brief Emit the target enter or exit data mapping code associated with |
| 1006 | /// directive \a D. |
Samuel Antao | bd0ae2e | 2016-04-27 23:07:29 +0000 | [diff] [blame] | 1007 | /// \param D Directive to emit. |
| 1008 | /// \param IfCond Expression evaluated in if clause associated with the target |
| 1009 | /// directive, or null if no if clause is used. |
| 1010 | /// \param Device Expression evaluated in device clause associated with the |
| 1011 | /// target directive, or null if no device clause is used. |
Samuel Antao | 8dd6628 | 2016-04-27 23:14:30 +0000 | [diff] [blame] | 1012 | virtual void emitTargetEnterOrExitDataCall(CodeGenFunction &CGF, |
| 1013 | const OMPExecutableDirective &D, |
| 1014 | const Expr *IfCond, |
| 1015 | const Expr *Device); |
Alexey Bataev | c7a82b4 | 2016-05-06 09:40:08 +0000 | [diff] [blame^] | 1016 | |
| 1017 | /// Marks function \a Fn with properly mangled versions of vector functions. |
| 1018 | /// \param FD Function marked as 'declare simd'. |
| 1019 | /// \param Fn LLVM function that must be marked with 'declare simd' |
| 1020 | /// attributes. |
| 1021 | virtual void emitDeclareSimdFunction(const FunctionDecl *FD, |
| 1022 | llvm::Function *Fn); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1023 | }; |
Alexey Bataev | 8cbe0a6 | 2015-02-26 10:27:34 +0000 | [diff] [blame] | 1024 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1025 | } // namespace CodeGen |
| 1026 | } // namespace clang |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1027 | |
| 1028 | #endif |