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"
38 class OMPExecutableDirective;
43 class CodeGenFunction;
50 enum OpenMPRTLFunction {
53 OMPRTL__kmpc_fork_call,
56 OMPRTL__kmpc_threadprivate_cached,
59 OMPRTL__kmpc_threadprivate_register,
61 OMPRTL__kmpc_global_thread_num,
64 OMPRTL__kmpc_critical,
67 OMPRTL__kmpc_end_critical,
70 OMPRTL__kmpc_cancel_barrier,
74 OMPRTL__kmpc_for_static_fini,
77 OMPRTL__kmpc_serialized_parallel,
80 OMPRTL__kmpc_end_serialized_parallel,
83 OMPRTL__kmpc_push_num_threads,
89 OMPRTL__kmpc_end_master,
92 OMPRTL__kmpc_omp_taskyield,
96 OMPRTL__kmpc_end_single,
100 OMPRTL__kmpc_omp_task_alloc,
103 OMPRTL__kmpc_omp_task,
107 OMPRTL__kmpc_copyprivate,
116 OMPRTL__kmpc_reduce_nowait,
119 OMPRTL__kmpc_end_reduce,
122 OMPRTL__kmpc_end_reduce_nowait,
125 OMPRTL__kmpc_omp_task_begin_if0,
128 OMPRTL__kmpc_omp_task_complete_if0,
130 OMPRTL__kmpc_ordered,
132 OMPRTL__kmpc_end_ordered,
135 OMPRTL__kmpc_omp_taskwait,
137 OMPRTL__kmpc_taskgroup,
139 OMPRTL__kmpc_end_taskgroup,
142 OMPRTL__kmpc_push_proc_bind,
146 OMPRTL__kmpc_omp_task_with_deps,
150 OMPRTL__kmpc_omp_wait_deps,
153 OMPRTL__kmpc_cancellationpoint,
162 enum OpenMPLocationFlags {
164 OMP_IDENT_IMD = 0x01,
166 OMP_IDENT_KMPC = 0x02,
168 OMP_ATOMIC_REDUCE = 0x10,
170 OMP_IDENT_BARRIER_EXPL = 0x20,
172 OMP_IDENT_BARRIER_IMPL = 0x40,
174 OMP_IDENT_BARRIER_IMPL_FOR = 0x40,
176 OMP_IDENT_BARRIER_IMPL_SECTIONS = 0xC0,
178 OMP_IDENT_BARRIER_IMPL_SINGLE = 0x140
183 llvm::Constant *DefaultOpenMPPSource;
185 typedef llvm::DenseMap<unsigned, llvm::Value *> OpenMPDefaultLocMapTy;
186 OpenMPDefaultLocMapTy OpenMPDefaultLocMap;
187 llvm::Value *getOrCreateDefaultLocation(OpenMPLocationFlags Flags);
242 typedef llvm::DenseMap<llvm::Function *, DebugLocThreadIdTy>
253 llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
286 OpenMPLocationFlags Flags = OMP_IDENT_KMPC);
338 const llvm::Twine &Name);
363 virtual void clear();
374 const OMPExecutableDirective &D,
const VarDecl *ThreadIDVar,
387 const OMPExecutableDirective &D,
const VarDecl *ThreadIDVar,
440 ArrayRef<const Expr *> CopyprivateVars,
441 ArrayRef<const Expr *> DestExprs,
442 ArrayRef<const Expr *> SrcExprs,
443 ArrayRef<const Expr *> AssignmentOps);
460 bool CheckForCancel =
true);
500 virtual void emitForInit(CodeGenFunction &CGF, SourceLocation Loc,
515 SourceLocation Loc,
unsigned IVSize,
541 unsigned IVSize,
bool IVSigned,
578 virtual llvm::Function *
580 SourceLocation Loc,
bool PerformInit,
581 CodeGenFunction *CGF =
nullptr);
585 virtual void emitFlush(CodeGenFunction &CGF, ArrayRef<const Expr *> Vars,
634 bool Tied, llvm::PointerIntPair<llvm::Value *, 1, bool> Final,
641 ArrayRef<std::pair<OpenMPDependClauseKind, const Expr *>> Dependences);
692 bool WithNowait,
bool SimpleReduction);
void functionFinished(CodeGenFunction &CGF)
Cleans up references to the objects in finished function.
virtual llvm::Value * emitThreadIDAddress(CodeGenFunction &CGF, SourceLocation Loc)
Emits address of the word in a memory where current thread id is stored.
virtual void emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind Kind, bool CheckForCancel=true)
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. This outlined function has typ...
llvm::Value * getThreadID(CodeGenFunction &CGF, SourceLocation Loc)
Gets thread id value for the current thread.
Not really used in Fortran any more.
OpenMPLocThreadIDMapTy OpenMPLocThreadIDMap
QualType KmpDependInfoTy
Type typedef struct kmp_depend_info { kmp_intptr_t base_addr; size_t len; struct { bool in:1; bool ou...
llvm::StringMap< llvm::AssertingVH< llvm::Constant >, llvm::BumpPtrAllocator > InternalVars
An ordered map of auto-generated variables to their unique names. It stores variables with the follow...
virtual void emitTaskyieldCall(CodeGenFunction &CGF, SourceLocation Loc)
Emits code for a taskyield directive.
virtual void emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, llvm::Value *OutlinedFn, llvm::Value *CapturedStruct, const Expr *IfCond)
Emits code for parallel or serial call of the OutlinedFn with variables captured in a record which ad...
String describing the source location. The string is composed of semi-colon separated fields which de...
virtual void emitMasterRegion(CodeGenFunction &CGF, const RegionCodeGenTy &MasterOpGen, SourceLocation Loc)
Emits a master region.
Defines some OpenMP-specific enums and functions.
QualType KmpRoutineEntryPtrQTy
virtual void emitCancelCall(CodeGenFunction &CGF, SourceLocation Loc, OpenMPDirectiveKind CancelRegion)
Emit code for 'cancel' construct.
virtual void emitCriticalRegion(CodeGenFunction &CGF, StringRef CriticalName, const RegionCodeGenTy &CriticalOpGen, SourceLocation Loc)
Emits a critical region.
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];.
CGOpenMPRuntime(CodeGenModule &CGM)
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++.
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(). Original representation is: typedef...
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...
virtual void emitForInit(CodeGenFunction &CGF, SourceLocation Loc, OpenMPScheduleClauseKind SchedKind, unsigned IVSize, bool IVSigned, bool Ordered, llvm::Value *IL, llvm::Value *LB, llvm::Value *UB, llvm::Value *ST, llvm::Value *Chunk=nullptr)
Call the appropriate runtime routine to initialize it before start of loop.
llvm::Value * emitUpdateLocation(CodeGenFunction &CGF, SourceLocation Loc, OpenMPLocationFlags Flags=OMP_IDENT_KMPC)
Emits object of ident_t type with info for source location.
virtual void emitReduction(CodeGenFunction &CGF, SourceLocation Loc, ArrayRef< const Expr * > LHSExprs, ArrayRef< const Expr * > RHSExprs, ArrayRef< const Expr * > ReductionOps, bool WithNowait, bool SimpleReduction)
Emit a code for reduction clause. Next code should be emitted for reduction:
llvm::DenseMap< unsigned, llvm::Value * > OpenMPDebugLocMapTy
Map for SourceLocation and OpenMP runtime library debug locations.
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.
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. This kind of worksharing directive is emit...
virtual llvm::Value * getAddrOfThreadPrivate(CodeGenFunction &CGF, const VarDecl *VD, llvm::Value *VDAddr, SourceLocation Loc)
Returns address of the threadprivate variable for the current thread.
OpenMPProcBindClauseKind
OpenMP attributes for 'proc_bind' clause.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
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...
virtual llvm::Function * emitThreadPrivateVarDefinition(const VarDecl *VD, llvm::Value *VDAddr, SourceLocation Loc, bool PerformInit, CodeGenFunction *CGF=nullptr)
Emit a code for initialization of threadprivate variable. It emits a call to runtime library which ad...
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, llvm::Value *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)
llvm::Value * getCriticalRegionLock(StringRef CriticalName)
Returns corresponding lock object for the specified critical region name. If the lock object does not...
llvm::function_ref< void(CodeGenFunction &)> RegionCodeGenTy
llvm::Type * getKmpc_MicroPointerTy()
Returns pointer to kmpc_micro type.
OpenMPDebugLocMapTy OpenMPDebugLocMap
virtual llvm::Value * emitForNext(CodeGenFunction &CGF, SourceLocation Loc, unsigned IVSize, bool IVSigned, llvm::Value *IL, llvm::Value *LB, llvm::Value *UB, llvm::Value *ST)
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 emitInlinedDirective(CodeGenFunction &CGF, OpenMPDirectiveKind InnermostKind, const RegionCodeGenTy &CodeGen)
Emit code for the directive that does not require outlining.
virtual void emitOrderedRegion(CodeGenFunction &CGF, const RegionCodeGenTy &OrderedOpGen, SourceLocation Loc)
Emit an ordered region.
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...
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. This outlined function has type void(*)(kmp_...
llvm::DenseSet< const VarDecl * > ThreadPrivateWithDefinition
Set of threadprivate variables with the generated initializer.
Defines the clang::SourceLocation class and associated facilities.
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 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)...
void emitThreadPrivateVarInit(CodeGenFunction &CGF, llvm::Value *VDAddr, llvm::Value *Ctor, llvm::Value *CopyCtor, llvm::Value *Dtor, SourceLocation Loc)
Emits initialization code for the threadprivate variables.
virtual bool isDynamic(OpenMPScheduleClauseKind ScheduleKind) const
Check if the specified ScheduleKind is dynamic. This kind of worksharing directive is emitted without...
llvm::Constant * createForStaticInitFunction(unsigned IVSize, bool IVSigned)
Returns __kmpc_for_static_init_* runtime function for the specified size IVSize and sign IVSigned...
Stores debug location and ThreadID for the function.
virtual ~CGOpenMPRuntime()
llvm::StructType * IdentTy