14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGOPENMPRUNTIME_H
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/DenseSet.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/IR/ValueHandle.h"
39 class OMPExecutableDirective;
44 class CodeGenFunction;
51 enum OpenMPRTLFunction {
54 OMPRTL__kmpc_fork_call,
57 OMPRTL__kmpc_threadprivate_cached,
60 OMPRTL__kmpc_threadprivate_register,
62 OMPRTL__kmpc_global_thread_num,
65 OMPRTL__kmpc_critical,
68 OMPRTL__kmpc_critical_with_hint,
71 OMPRTL__kmpc_end_critical,
74 OMPRTL__kmpc_cancel_barrier,
78 OMPRTL__kmpc_for_static_fini,
81 OMPRTL__kmpc_serialized_parallel,
84 OMPRTL__kmpc_end_serialized_parallel,
87 OMPRTL__kmpc_push_num_threads,
93 OMPRTL__kmpc_end_master,
96 OMPRTL__kmpc_omp_taskyield,
100 OMPRTL__kmpc_end_single,
104 OMPRTL__kmpc_omp_task_alloc,
107 OMPRTL__kmpc_omp_task,
111 OMPRTL__kmpc_copyprivate,
120 OMPRTL__kmpc_reduce_nowait,
123 OMPRTL__kmpc_end_reduce,
126 OMPRTL__kmpc_end_reduce_nowait,
129 OMPRTL__kmpc_omp_task_begin_if0,
132 OMPRTL__kmpc_omp_task_complete_if0,
134 OMPRTL__kmpc_ordered,
136 OMPRTL__kmpc_end_ordered,
139 OMPRTL__kmpc_omp_taskwait,
141 OMPRTL__kmpc_taskgroup,
143 OMPRTL__kmpc_end_taskgroup,
146 OMPRTL__kmpc_push_proc_bind,
150 OMPRTL__kmpc_omp_task_with_deps,
154 OMPRTL__kmpc_omp_wait_deps,
157 OMPRTL__kmpc_cancellationpoint,
170 OMPRTL__tgt_register_lib,
172 OMPRTL__tgt_unregister_lib,
178 enum OpenMPLocationFlags {
180 OMP_IDENT_IMD = 0x01,
182 OMP_IDENT_KMPC = 0x02,
184 OMP_ATOMIC_REDUCE = 0x10,
186 OMP_IDENT_BARRIER_EXPL = 0x20,
188 OMP_IDENT_BARRIER_IMPL = 0x40,
190 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
192 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
194 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
199 llvm::Constant *DefaultOpenMPPSource;
201 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
202 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
203 Address getOrCreateDefaultLocation(OpenMPLocationFlags Flags);
256 struct DebugLocThreadIdTy {
261 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
272 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
330 unsigned OffloadingEntriesNum;
340 OFFLOAD_ENTRY_INFO_TARGET_REGION = 0,
342 OFFLOAD_ENTRY_INFO_INVALID = ~0u
347 : Order(Order), Kind(Kind) {}
364 unsigned size()
const {
return OffloadingEntriesNum; }
366 : CGM(CGM), OffloadingEntriesNum(0) {}
374 llvm::Constant *Addr;
381 Addr(nullptr),
ID(nullptr) {}
383 llvm::Constant *Addr,
386 Addr(Addr), ID(ID) {}
391 assert(!Addr &&
"Address as been set before!");
395 assert(!
ID &&
"ID as been set before!");
399 return Info->
getKind() == OFFLOAD_ENTRY_INFO_TARGET_REGION;
403 void initializeTargetRegionEntryInfo(
unsigned DeviceID,
unsigned FileID,
404 StringRef ParentName,
unsigned LineNum,
405 unsigned ColNum,
unsigned Order);
407 void registerTargetRegionEntryInfo(
unsigned DeviceID,
unsigned FileID,
408 StringRef ParentName,
unsigned LineNum,
409 unsigned ColNum, llvm::Constant *Addr,
413 bool hasTargetRegionEntryInfo(
unsigned DeviceID,
unsigned FileID,
414 StringRef ParentName,
unsigned LineNum,
415 unsigned ColNum)
const;
417 typedef llvm::function_ref<void(
unsigned,
unsigned, StringRef,
unsigned,
418 unsigned, OffloadEntryInfoTargetRegion &)>
420 void actOnTargetRegionEntriesInfo(
426 typedef llvm::DenseMap<unsigned, OffloadEntryInfoTargetRegion>
427 OffloadEntriesTargetRegionPerColumn;
428 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerColumn>
429 OffloadEntriesTargetRegionPerLine;
430 typedef llvm::StringMap<OffloadEntriesTargetRegionPerLine>
431 OffloadEntriesTargetRegionPerParentName;
432 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
433 OffloadEntriesTargetRegionPerFile;
434 typedef llvm::DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
435 OffloadEntriesTargetRegionPerDevice;
436 typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
437 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
479 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
530 const llvm::Twine &
Name);
555 virtual void clear();
566 const OMPExecutableDirective &D,
const VarDecl *ThreadIDVar,
579 const OMPExecutableDirective &D,
const VarDecl *ThreadIDVar,
598 ArrayRef<llvm::Value *> CapturedVars,
609 const Expr *Hint =
nullptr);
634 ArrayRef<const Expr *> CopyprivateVars,
635 ArrayRef<const Expr *> DestExprs,
636 ArrayRef<const Expr *> SrcExprs,
637 ArrayRef<const Expr *> AssignmentOps);
644 SourceLocation Loc,
bool IsThreads);
656 bool EmitChecks =
true,
657 bool ForceSimpleCall =
false);
675 unsigned IVSize,
bool IVSigned,
705 unsigned IVSize,
bool IVSigned,
bool Ordered,
706 Address IL, Address LB,
707 Address UB, Address ST,
719 SourceLocation Loc,
unsigned IVSize,
745 unsigned IVSize,
bool IVSigned,
746 Address IL, Address LB,
747 Address UB, Address ST);
782 virtual llvm::Function *
784 SourceLocation Loc,
bool PerformInit,
785 CodeGenFunction *CGF =
nullptr);
789 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
838 bool Tied, llvm::PointerIntPair<llvm::Value *, 1, bool> Final,
845 ArrayRef<std::pair<OpenMPDependClauseKind, const Expr *>> Dependences);
857 bool HasCancel =
false);
901 bool WithNowait,
bool SimpleReduction);
932 StringRef ParentName,
933 llvm::Function *&OutlinedFn,
934 llvm::Constant *&OutlinedFnID,
935 bool IsOffloadEntry);
void functionFinished(CodeGenFunction &CGF)
Cleans up references to the objects in finished function.
Base class of the entries info.
virtual void emitTargetCall(CodeGenFunction &CGF, const OMPExecutableDirective &D, llvm::Value *OutlinedFn, llvm::Value *OutlinedFnID, const Expr *IfCond, const Expr *Device, ArrayRef< llvm::Value * > CapturedVars)
Emit the target offloading code associated with D.
A (possibly-)qualified type.
virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, Address VDAddr, SourceLocation Loc)
Returns address of the threadprivate variable for the current thread.
virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind Kind, bool EmitChecks=true, bool ForceSimpleCall=false)
Emit an implicit/explicit barrier for OpenMP threads.
virtual void emitForOrderedIterationEnd(CodeGenFunction &CGF, SourceLocation Loc, unsigned IVSize, bool IVSigned)
Call the appropriate runtime routine to notify that we finished iteration of the ordered loop with th...
virtual llvm::Value * emitParallelOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the specified OpenMP parallel directive D.
llvm::Value * getThreadID(CodeGenFunction &CGF, SourceLocation Loc)
Gets thread id value for the current thread.
Not really used in Fortran any more.
OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap
C Language Family Type Representation.
QualType getTgtDeviceImageQTy()
Returns __tgt_device_image type.
virtual llvm::Function * emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, SourceLocation Loc, bool PerformInit, CodeGenFunction *CGF=nullptr)
Emit a code for initialization of threadprivate variable.
QualType KmpDependInfoTy
Type typedef struct kmp_depend_info { kmp_intptr_t base_addr; size_t len; struct { bool in:1; bool ou...
QualType TgtOffloadEntryQTy
Type struct __tgt_offload_entry{ void *addr; // Pointer to the offload entry info.
Target region entries related.
llvm::function_ref< void(unsigned, unsigned, StringRef, unsigned, unsigned, OffloadEntryInfoTargetRegion &)> OffloadTargetRegionEntryInfoActTy
brief Applies action Action on all registered entries.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
virtual llvm::Value * emitForNext(CodeGenFunction &CGF, SourceLocation Loc, unsigned IVSize, bool IVSigned, Address IL, Address LB, Address UB, Address ST)
Call __kmpc_dispatch_next( ident_t *loc, kmp_int32 tid, kmp_int32 *p_lastiter, kmp_int[32|64] *p_lowe...
OffloadEntryInfo(OffloadingEntryInfoKinds Kind, unsigned Order)
llvm::StringMap< llvm::AssertingVH< llvm::Constant >, llvm::BumpPtrAllocator > InternalVars
An ordered map of auto-generated variables to their unique names.
virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc)
Emits code for a taskyield directive.
void setID(llvm::Constant *V)
String describing the source location.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
unsigned getOrder() const
OffloadingEntryInfoKinds Kind
virtual void emitMasterRegion(CodeGenFunction &CGF, const RegionCodeGenTy &MasterOpGen, SourceLocation Loc)
Emits a master region.
virtual void emitOrderedRegion(CodeGenFunction &CGF, const RegionCodeGenTy &OrderedOpGen, SourceLocation Loc, bool IsThreads)
Emit an ordered region.
virtual void emitForStaticInit(CodeGenFunction &CGF, SourceLocation Loc, OpenMPScheduleClauseKind SchedKind, unsigned IVSize, bool IVSigned, bool Ordered, Address IL, Address LB, Address UB, Address ST, llvm::Value *Chunk=nullptr)
Call the appropriate runtime routine to initialize it before start of loop.
OffloadEntryInfoTargetRegion()
virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, const RegionCodeGenTy &CriticalOpGen, SourceLocation Loc, const Expr *Hint=nullptr)
Emits a critical region.
llvm::Constant * getAddress() const
Defines some OpenMP-specific enums and functions.
llvm::Constant * getID() const
QualType KmpRoutineEntryPtrQTy
void createOffloadEntriesAndInfoMetadata()
Creates all the offload entries in the current compilation unit along with the associated metadata...
void scanForTargetRegionsFunctions(const Stmt *S, StringRef ParentName)
Start scanning from statement S and and emit all target regions found along the way.
llvm::DenseMap< llvm::Function *, DebugLocThreadIdTy > OpenMPLocThreadIDMapTy
Map of local debug location, ThreadId and functions.
llvm::ArrayType * KmpCriticalNameTy
Type kmp_critical_name, originally defined as typedef kmp_int32 kmp_critical_name[8];.
llvm::Function * createOffloadingBinaryDescriptorRegistration()
Creates and registers offloading binary descriptor for the current compilation unit.
CGOpenMPRuntime(CodeGenModule &CGM)
OffloadEntriesInfoManagerTy OffloadEntriesInfoManager
virtual bool emitTargetGlobalVariable(GlobalDecl GD)
Emit the global variable if it is a valid device global variable.
llvm::Constant * getOrCreateThreadPrivateCache(const VarDecl *VD)
If the specified mangled name is not in the module, create and return threadprivate cache object...
Source[4] in Fortran, do not use for C++.
QualType TgtDeviceImageQTy
struct __tgt_device_image{ void *ImageStart; // Pointer to the target code start. ...
virtual void emitForStaticFinish(CodeGenFunction &CGF, SourceLocation Loc)
Call the appropriate runtime routine to notify that we finished all the work with current loop...
OMP_IDENT_xxx flags; OMP_IDENT_KMPC identifies this union member.
llvm::FunctionType * Kmpc_MicroTy
The type for a microtask which gets passed to __kmpc_fork_call().
virtual void emitTaskgroupRegion(CodeGenFunction &CGF, const RegionCodeGenTy &TaskgroupOpGen, SourceLocation Loc)
Emit a taskgroup region.
virtual void emitProcBindClause(CodeGenFunction &CGF, OpenMPProcBindClauseKind ProcBind, SourceLocation Loc)
Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32 global_tid, int proc_bind) to generat...
llvm::Constant * createDispatchInitFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_dispatch_init_* runtime function for the specified size IVSize and sign IVSigned...
static bool classof(const OffloadEntryInfo *Info)
virtual void emitForDispatchInit(CodeGenFunction &CGF, SourceLocation Loc, OpenMPScheduleClauseKind SchedKind, unsigned IVSize, bool IVSigned, bool Ordered, llvm::Value *UB, llvm::Value *Chunk=nullptr)
void emitThreadPrivateVarInit(CodeGenFunction &CGF, Address VDAddr, llvm::Value *Ctor, llvm::Value *CopyCtor, llvm::Value *Dtor, SourceLocation Loc)
Emits initialization code for the threadprivate variables.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param IfCond Not a nullptr if if clause was nullptr *otherwise *param PrivateVars List of references to private variables for the task *directive *param PrivateCopies List of private copies for each private variable in *p PrivateVars *param FirstprivateVars List of references to private variables for the *task directive *param FirstprivateCopies List of private copies for each private variable *in p FirstprivateVars *param FirstprivateInits List of references to auto generated variables *used for initialization of a single array element Used if firstprivate *variable is of array type *param Dependences List of dependences for the task including *original expression and dependency type *virtual void emitTaskCall(CodeGenFunction &CGF, SourceLocation Loc, const OMPExecutableDirective &D, bool Tied, llvm::PointerIntPair< llvm::Value *, 1, bool > Final, llvm::Value *TaskFunction, QualType SharedsTy, Address Shareds, const Expr *IfCond, ArrayRef< const Expr * > PrivateVars, ArrayRef< const Expr * > PrivateCopies, ArrayRef< const Expr * > FirstprivateVars, ArrayRef< const Expr * > FirstprivateCopies, ArrayRef< const Expr * > FirstprivateInits, ArrayRef< std::pair< OpenMPDependClauseKind, const Expr * >> Dependences)
virtual Address emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc)
Emits address of the word in a memory where current thread id is stored.
ID
Defines the set of possible language-specific address spaces.
llvm::Value * emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, OpenMPLocationFlags Flags=OMP_IDENT_KMPC)
Emits object of ident_t type with info for source location.
llvm::DenseMap< unsigned, llvm::Value * > OpenMPDebugLocMapTy
Map for SourceLocation and OpenMP runtime library debug locations.
Expr - This represents one expression.
virtual void emitSingleRegion(CodeGenFunction &CGF, const RegionCodeGenTy &SingleOpGen, SourceLocation Loc, ArrayRef< const Expr * > CopyprivateVars, ArrayRef< const Expr * > DestExprs, ArrayRef< const Expr * > SrcExprs, ArrayRef< const Expr * > AssignmentOps)
Emits a single region.
QualType getTgtBinaryDescriptorQTy()
Returns __tgt_bin_desc type.
llvm::Constant * createRuntimeFunction(OpenMPRTLFunction Function)
Returns specified OpenMP runtime function.
virtual bool isStaticNonchunked(OpenMPScheduleClauseKind ScheduleKind, bool Chunked) const
Check if the specified ScheduleKind is static non-chunked.
Entity that registers the offloading constants that were emitted so far.
virtual bool emitTargetGlobal(GlobalDecl GD)
Emit the global GD if it is meaningful for the target.
QualType getTgtOffloadEntryQTy()
Returns __tgt_offload_entry type.
OffloadingEntryInfoKinds getKind() const
OpenMPProcBindClauseKind
OpenMP attributes for 'proc_bind' clause.
GlobalDecl - represents a global declaration.
The l-value was considered opaque, so the alignment was determined from a type.
virtual void emitInlinedDirective(CodeGenFunction &CGF, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen, bool HasCancel=false)
Emit code for the directive that does not require outlining.
Encodes a location in the source.
This is a basic class for representing single OpenMP executable directive.
OpenMPDirectiveKind
OpenMP directives.
llvm::Constant * createDispatchFiniFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_dispatch_fini_* runtime function for the specified size IVSize and sign IVSigned...
virtual void emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc)
Emit code for 'taskwait' directive.
llvm::Constant * createDispatchNextFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_dispatch_next_* runtime function for the specified size IVSize and sign IVSigned...
llvm::Value * getCriticalRegionLock(StringRef CriticalName)
Returns corresponding lock object for the specified critical region name.
llvm::function_ref< void(CodeGenFunction &)> RegionCodeGenTy
llvm::Type * getKmpc_MicroPointerTy()
Returns pointer to kmpc_micro type.
OpenMPDebugLocMapTy OpenMPDebugLocMap
static bool classof(const OffloadEntryInfo *Info)
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
This class organizes the cross-function state that is used while generating LLVM code.
void emitKmpRoutineEntryT(QualType KmpInt32Ty)
Build type kmp_routine_entry_t (if not built yet).
virtual void emitCancellationPointCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind CancelRegion)
Emit code for 'cancellation point' construct.
llvm::Type * KmpRoutineEntryPtrTy
Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);.
virtual void emitTargetOutlinedFunction(const OMPExecutableDirective &D, StringRef ParentName, llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID, bool IsOffloadEntry)
Emit outilined function for 'target' directive.
virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, const Expr *IfCond, OpenMPDirectiveKind CancelRegion)
Emit code for 'cancel' construct.
OffloadingEntryInfoKinds
Kind of a given entry.
llvm::Constant * getOrCreateInternalVariable(llvm::Type *Ty, const llvm::Twine &Name)
Gets (if variable with the given name already exist) or creates internal global variable with the spe...
unsigned size() const
Return number of entries defined so far.
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
virtual llvm::Value * emitTaskOutlinedFunction(const OMPExecutableDirective &D, const VarDecl *ThreadIDVar, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emits outlined function for the OpenMP task directive D.
llvm::DenseSet< const VarDecl * > ThreadPrivateWithDefinition
Set of threadprivate variables with the generated initializer.
void createOffloadEntry(llvm::Constant *Addr, StringRef Name, uint64_t Size)
Creates offloading entry for the provided address Addr, name Name and size Size.
Defines the clang::SourceLocation class and associated facilities.
virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef< const Expr * > Privates, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, ArrayRef< const Expr * > ReductionOps, bool WithNowait, bool SimpleReduction)
Emit a code for reduction clause.
virtual bool emitTargetFunctions(GlobalDecl GD)
Emit the target regions enclosed in GD function definition or the function itself in case it is a val...
void loadOffloadInfoMetadata()
Loads all the offload entries information from the host IR metadata.
Privates[]
Gets the list of initial values for linear variables.
virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *OutlinedFn, ArrayRef< llvm::Value * > CapturedVars, const Expr *IfCond)
Emits code for parallel or serial call of the OutlinedFn with variables captured in a record which ad...
OffloadEntryInfoTargetRegion(unsigned Order, llvm::Constant *Addr, llvm::Constant *ID)
llvm::Type * getIdentTyPointerTy()
Returns pointer to ident_t type.
virtual void emitFlush(CodeGenFunction &CGF, ArrayRef< const Expr * > Vars, SourceLocation Loc)
Emit flush of the variables specified in 'omp flush' directive.
virtual llvm::Function * emitRegistrationFunction()
Creates the offloading descriptor in the event any target region was emitted in the current module an...
virtual void emitNumThreadsClause(CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc)
Emits call to void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_threads)...
OffloadEntriesInfoManagerTy(CodeGenModule &CGM)
virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const
Check if the specified ScheduleKind is dynamic.
llvm::Constant * createForStaticInitFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_for_static_init_* runtime function for the specified size IVSize and sign IVSigned...
void setAddress(llvm::Constant *V)
virtual ~CGOpenMPRuntime()
llvm::StructType * IdentTy
QualType TgtBinaryDescriptorQTy
struct __tgt_bin_desc{ int32_t NumDevices; // Number of devices supported.