LLVM 17.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
llvm::OpenMPIRBuilder Class Reference

An interface to create LLVM-IR for OpenMP directives. More...

#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"

Classes

struct  AtomicOpValue
 a struct to pack relevant information while generating atomic Ops More...
 
struct  DependData
 A struct to pack the relevant information for an OpenMP depend clause. More...
 
struct  FinalizationInfo
 
struct  LocationDescription
 Description of a LLVM-IR insertion point (IP) and a debug/source location (filename, line, column, ...). More...
 
struct  MapInfosTy
 This structure contains combined information generated for mappable clauses, including base pointers, pointers, sizes, map types, user-defined mappers, and non-contiguous information. More...
 
struct  MapperAllocas
 
struct  OutlineInfo
 Helper that contains information about regions we need to outline during finalization. More...
 
struct  ReductionInfo
 Information about an OpenMP reduction. More...
 
class  TargetDataInfo
 Struct that keeps the information that should be kept throughout a 'target data' region. More...
 
struct  TargetDataRTArgs
 Container for the arguments used to pass data to the runtime library. More...
 

Public Types

enum  EmitMetadataErrorKind { EMIT_MD_TARGET_REGION_ERROR , EMIT_MD_DECLARE_TARGET_ERROR , EMIT_MD_GLOBAL_VAR_LINK_ERROR }
 The kind of errors that can occur when emitting the offload entries and metadata. More...
 
using InsertPointTy = IRBuilder<>::InsertPoint
 Type used throughout for insertion points.
 
using FinalizeCallbackTy = std::function< void(InsertPointTy CodeGenIP)>
 Callback type for variable finalization (think destructors).
 
using BodyGenCallbackTy = function_ref< void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>
 Callback type for body (=inner region) code generation.
 
using StorableBodyGenCallbackTy = std::function< void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>
 
using LoopBodyGenCallbackTy = function_ref< void(InsertPointTy CodeGenIP, Value *IndVar)>
 Callback type for loop body code generation.
 
using PrivatizeCallbackTy = function_ref< InsertPointTy(InsertPointTy AllocaIP, InsertPointTy CodeGenIP, Value &Original, Value &Inner, Value *&ReplVal)>
 Callback type for variable privatization (think copy & default constructor).
 
using ReductionGenTy = function_ref< InsertPointTy(InsertPointTy, Value *, Value *, Value *&)>
 Functions used to generate reductions.
 
using AtomicReductionGenTy = function_ref< InsertPointTy(InsertPointTy, Type *, Value *, Value *)>
 Functions used to generate atomic reductions.
 
using MapValuesArrayTy = SmallVector< Value *, 4 >
 
using MapFlagsArrayTy = SmallVector< omp::OpenMPOffloadMappingFlags, 4 >
 
using MapNamesArrayTy = SmallVector< Constant *, 4 >
 
using MapDimArrayTy = SmallVector< uint64_t, 4 >
 
using MapNonContiguousArrayTy = SmallVector< MapValuesArrayTy, 4 >
 
using EmitMetadataErrorReportFunctionTy = std::function< void(EmitMetadataErrorKind, TargetRegionEntryInfo)>
 Callback function type.
 
using FunctionGenCallback = std::function< Function *(StringRef FunctionName)>
 Functions used to generate a function with the given name.
 
using TargetBodyGenCallbackTy = function_ref< InsertPointTy(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>
 

Public Member Functions

 OpenMPIRBuilder (Module &M)
 Create a new OpenMPIRBuilder operating on the given module M.
 
 ~OpenMPIRBuilder ()
 
void initialize (StringRef HostFilePath={})
 Initialize the internal state, this will put structures types and potentially other helpers into the underlying module.
 
void setConfig (OpenMPIRBuilderConfig C)
 
void finalize (Function *Fn=nullptr)
 Finalize the underlying module, e.g., by outlining regions.
 
void addAttributes (omp::RuntimeFunction FnID, Function &Fn)
 Add attributes known for FnID to Fn.
 
std::string createPlatformSpecificName (ArrayRef< StringRef > Parts) const
 Get the create a name using the platform specific separators.
 
void pushFinalizationCB (const FinalizationInfo &FI)
 Push a finalization callback on the finalization stack.
 
void popFinalizationCB ()
 Pop the last finalization callback from the finalization stack.
 
InsertPointTy createBarrier (const LocationDescription &Loc, omp::Directive DK, bool ForceSimpleCall=false, bool CheckCancelFlag=true)
 Emitter methods for OpenMP directives.
 
InsertPointTy createCancel (const LocationDescription &Loc, Value *IfCondition, omp::Directive CanceledDirective)
 Generator for '#omp cancel'.
 
IRBuilder ::InsertPoint createParallel (const LocationDescription &Loc, InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB, Value *IfCondition, Value *NumThreads, omp::ProcBindKind ProcBind, bool IsCancellable)
 Generator for '#omp parallel'.
 
CanonicalLoopInfocreateCanonicalLoop (const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB, Value *TripCount, const Twine &Name="loop")
 Generator for the control flow structure of an OpenMP canonical loop.
 
CanonicalLoopInfocreateCanonicalLoop (const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB, Value *Start, Value *Stop, Value *Step, bool IsSigned, bool InclusiveStop, InsertPointTy ComputeIP={}, const Twine &Name="loop")
 Generator for the control flow structure of an OpenMP canonical loop.
 
CanonicalLoopInfocollapseLoops (DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, InsertPointTy ComputeIP)
 Collapse a loop nest into a single loop.
 
InsertPointTy applyWorkshareLoop (DebugLoc DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP, bool NeedsBarrier, llvm::omp::ScheduleKind SchedKind=llvm::omp::OMP_SCHEDULE_Default, Value *ChunkSize=nullptr, bool HasSimdModifier=false, bool HasMonotonicModifier=false, bool HasNonmonotonicModifier=false, bool HasOrderedClause=false)
 Modifies the canonical loop to be a workshare loop.
 
std::vector< CanonicalLoopInfo * > tileLoops (DebugLoc DL, ArrayRef< CanonicalLoopInfo * > Loops, ArrayRef< Value * > TileSizes)
 Tile a loop nest.
 
void unrollLoopFull (DebugLoc DL, CanonicalLoopInfo *Loop)
 Fully unroll a loop.
 
void unrollLoopHeuristic (DebugLoc DL, CanonicalLoopInfo *Loop)
 Fully or partially unroll a loop.
 
void unrollLoopPartial (DebugLoc DL, CanonicalLoopInfo *Loop, int32_t Factor, CanonicalLoopInfo **UnrolledCLI)
 Partially unroll a loop.
 
void applySimd (CanonicalLoopInfo *Loop, MapVector< Value *, Value * > AlignedVars, Value *IfCond, omp::OrderKind Order, ConstantInt *Simdlen, ConstantInt *Safelen)
 Add metadata to simd-ize a loop.
 
void createFlush (const LocationDescription &Loc)
 Generator for '#omp flush'.
 
void createTaskwait (const LocationDescription &Loc)
 Generator for '#omp taskwait'.
 
void createTaskyield (const LocationDescription &Loc)
 Generator for '#omp taskyield'.
 
InsertPointTy createTask (const LocationDescription &Loc, InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB, bool Tied=true, Value *Final=nullptr, Value *IfCondition=nullptr, SmallVector< DependData > Dependencies={})
 Generator for #omp task
 
InsertPointTy createTaskgroup (const LocationDescription &Loc, InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB)
 Generator for the taskgroup construct.
 
InsertPointTy createReductions (const LocationDescription &Loc, InsertPointTy AllocaIP, ArrayRef< ReductionInfo > ReductionInfos, bool IsNoWait=false)
 Generator for '#omp reduction'.
 
InsertPointTy getInsertionPoint ()
 }
 
bool updateToLocation (const LocationDescription &Loc)
 Update the internal location to Loc.
 
FunctionCallee getOrCreateRuntimeFunction (Module &M, omp::RuntimeFunction FnID)
 Return the function declaration for the runtime function with FnID.
 
FunctiongetOrCreateRuntimeFunctionPtr (omp::RuntimeFunction FnID)
 
ConstantgetOrCreateSrcLocStr (StringRef LocStr, uint32_t &SrcLocStrSize)
 Return the (LLVM-IR) string describing the source location LocStr.
 
ConstantgetOrCreateDefaultSrcLocStr (uint32_t &SrcLocStrSize)
 Return the (LLVM-IR) string describing the default source location.
 
ConstantgetOrCreateSrcLocStr (StringRef FunctionName, StringRef FileName, unsigned Line, unsigned Column, uint32_t &SrcLocStrSize)
 Return the (LLVM-IR) string describing the source location identified by the arguments.
 
ConstantgetOrCreateSrcLocStr (DebugLoc DL, uint32_t &SrcLocStrSize, Function *F=nullptr)
 Return the (LLVM-IR) string describing the DebugLoc DL.
 
ConstantgetOrCreateSrcLocStr (const LocationDescription &Loc, uint32_t &SrcLocStrSize)
 Return the (LLVM-IR) string describing the source location Loc.
 
ConstantgetOrCreateIdent (Constant *SrcLocStr, uint32_t SrcLocStrSize, omp::IdentFlag Flags=omp::IdentFlag(0), unsigned Reserve2Flags=0)
 Return an ident_t* encoding the source location SrcLocStr and Flags.
 
GlobalValuecreateGlobalFlag (unsigned Value, StringRef Name)
 Create a hidden global flag Name in the module with initial value Value.
 
void emitOffloadingEntry (Constant *Addr, StringRef Name, uint64_t Size, int32_t Flags, StringRef SectionName="omp_offloading_entries")
 Create an offloading section struct used to register this global at runtime.
 
void emitCancelationCheckImpl (Value *CancelFlag, omp::Directive CanceledDirective, FinalizeCallbackTy ExitCB={})
 Generate control flow and cleanup for cancellation.
 
InsertPointTy emitTargetKernel (const LocationDescription &Loc, InsertPointTy AllocaIP, Value *&Return, Value *Ident, Value *DeviceID, Value *NumTeams, Value *NumThreads, Value *HostPtr, ArrayRef< Value * > KernelArgs)
 Generate a target region entry call.
 
InsertPointTy emitBarrierImpl (const LocationDescription &Loc, omp::Directive DK, bool ForceSimpleCall, bool CheckCancelFlag)
 Generate a barrier runtime call.
 
void emitFlush (const LocationDescription &Loc)
 Generate a flush runtime call.
 
bool isLastFinalizationInfoCancellable (omp::Directive DK)
 Return true if the last entry in the finalization stack is of kind DK and cancellable.
 
void emitTaskwaitImpl (const LocationDescription &Loc)
 Generate a taskwait runtime call.
 
void emitTaskyieldImpl (const LocationDescription &Loc)
 Generate a taskyield runtime call.
 
ValuegetOrCreateThreadID (Value *Ident)
 Return the current thread ID.
 
void addOutlineInfo (OutlineInfo &&OI)
 Add a new region that will be outlined later.
 
ValuegetSizeInBytes (Value *BasePtr)
 Computes the size of type in bytes.
 
GlobalVariablecreateOffloadMaptypes (SmallVectorImpl< uint64_t > &Mappings, std::string VarName)
 Create the global variable holding the offload mappings information.
 
GlobalVariablecreateOffloadMapnames (SmallVectorImpl< llvm::Constant * > &Names, std::string VarName)
 Create the global variable holding the offload names information.
 
void createMapperAllocas (const LocationDescription &Loc, InsertPointTy AllocaIP, unsigned NumOperands, struct MapperAllocas &MapperAllocas)
 Create the allocas instruction used in call to mapper functions.
 
void emitMapperCall (const LocationDescription &Loc, Function *MapperFunc, Value *SrcLocInfo, Value *MaptypesArg, Value *MapnamesArg, struct MapperAllocas &MapperAllocas, int64_t DeviceID, unsigned NumOperands)
 Create the call for the target mapper function.
 
void emitOffloadingArraysArgument (IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs, OpenMPIRBuilder::TargetDataInfo &Info, bool EmitDebug=false, bool ForEndCall=false)
 Emit the arguments to be passed to the runtime library based on the arrays of base pointers, pointers, sizes, map types, and mappers.
 
void createOffloadEntry (Constant *ID, Constant *Addr, uint64_t Size, int32_t Flags, GlobalValue::LinkageTypes)
 Creates offloading entry for the provided entry ID ID, address Addr, size Size, and flags Flags.
 
void createOffloadEntriesAndInfoMetadata (EmitMetadataErrorReportFunctionTy &ErrorReportFunction)
 
InsertPointTy createCopyPrivate (const LocationDescription &Loc, llvm::Value *BufSize, llvm::Value *CpyBuf, llvm::Value *CpyFn, llvm::Value *DidIt)
 Generator for __kmpc_copyprivate.
 
InsertPointTy createSingle (const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, bool IsNowait, llvm::Value *DidIt)
 Generator for '#omp single'.
 
InsertPointTy createMaster (const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB)
 Generator for '#omp master'.
 
InsertPointTy createMasked (const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, Value *Filter)
 Generator for '#omp masked'.
 
InsertPointTy createCritical (const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, StringRef CriticalName, Value *HintInst)
 Generator for '#omp critical'.
 
InsertPointTy createOrderedDepend (const LocationDescription &Loc, InsertPointTy AllocaIP, unsigned NumLoops, ArrayRef< llvm::Value * > StoreValues, const Twine &Name, bool IsDependSource)
 Generator for '#omp ordered depend (source | sink)'.
 
InsertPointTy createOrderedThreadsSimd (const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB, bool IsThreads)
 Generator for '#omp ordered [threads | simd]'.
 
InsertPointTy createSections (const LocationDescription &Loc, InsertPointTy AllocaIP, ArrayRef< StorableBodyGenCallbackTy > SectionCBs, PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB, bool IsCancellable, bool IsNowait)
 Generator for '#omp sections'.
 
InsertPointTy createSection (const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB, FinalizeCallbackTy FiniCB)
 Generator for '#omp section'.
 
InsertPointTy createCopyinClauseBlocks (InsertPointTy IP, Value *MasterAddr, Value *PrivateAddr, llvm::IntegerType *IntPtrTy, bool BranchtoEnd=true)
 Generate conditional branch and relevant BasicBlocks through which private threads copy the 'copyin' variables from Master copy to threadprivate copies.
 
CallInstcreateOMPAlloc (const LocationDescription &Loc, Value *Size, Value *Allocator, std::string Name="")
 Create a runtime call for kmpc_Alloc.
 
CallInstcreateOMPFree (const LocationDescription &Loc, Value *Addr, Value *Allocator, std::string Name="")
 Create a runtime call for kmpc_free.
 
CallInstcreateCachedThreadPrivate (const LocationDescription &Loc, llvm::Value *Pointer, llvm::ConstantInt *Size, const llvm::Twine &Name=Twine(""))
 Create a runtime call for kmpc_threadprivate_cached.
 
CallInstcreateOMPInteropInit (const LocationDescription &Loc, Value *InteropVar, omp::OMPInteropType InteropType, Value *Device, Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause)
 Create a runtime call for __tgt_interop_init.
 
CallInstcreateOMPInteropDestroy (const LocationDescription &Loc, Value *InteropVar, Value *Device, Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause)
 Create a runtime call for __tgt_interop_destroy.
 
CallInstcreateOMPInteropUse (const LocationDescription &Loc, Value *InteropVar, Value *Device, Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause)
 Create a runtime call for __tgt_interop_use.
 
InsertPointTy createTargetInit (const LocationDescription &Loc, bool IsSPMD)
 The omp target interface.
 
void createTargetDeinit (const LocationDescription &Loc, bool IsSPMD)
 Create a runtime call for kmpc_target_deinit.
 
void emitTargetRegionFunction (TargetRegionEntryInfo &EntryInfo, FunctionGenCallback &GenerateFunctionCallback, int32_t NumTeams, int32_t NumThreads, bool IsOffloadEntry, Function *&OutlinedFn, Constant *&OutlinedFnID)
 Create a unique name for the entry function using the source location information of the current target region.
 
ConstantregisterTargetRegionFunction (TargetRegionEntryInfo &EntryInfo, Function *OutlinedFunction, StringRef EntryFnName, StringRef EntryFnIDName, int32_t NumTeams, int32_t NumThreads)
 Registers the given function and sets up the attribtues of the function Returns the FunctionID.
 
OpenMPIRBuilder::InsertPointTy createTargetData (const LocationDescription &Loc, OpenMPIRBuilder::InsertPointTy CodeGenIP, SmallVectorImpl< uint64_t > &MapTypeFlags, SmallVectorImpl< Constant * > &MapNames, struct MapperAllocas &MapperAllocas, bool IsBegin, int64_t DeviceID, Value *IfCond, BodyGenCallbackTy ProcessMapOpCB, BodyGenCallbackTy BodyGenCB={})
 Generator for '#omp target data'.
 
InsertPointTy createTarget (const LocationDescription &Loc, OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetRegionEntryInfo &EntryInfo, int32_t NumTeams, int32_t NumThreads, SmallVectorImpl< Value * > &Inputs, TargetBodyGenCallbackTy BodyGenCB)
 Generator for '#omp target'.
 
InsertPointTy createAtomicRead (const LocationDescription &Loc, AtomicOpValue &X, AtomicOpValue &V, AtomicOrdering AO)
 Emit atomic Read for : V = X — Only Scalar data types.
 
InsertPointTy createAtomicWrite (const LocationDescription &Loc, AtomicOpValue &X, Value *Expr, AtomicOrdering AO)
 Emit atomic write for : X = Expr — Only Scalar data types.
 
InsertPointTy createAtomicUpdate (const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &X, Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp, bool IsXBinopExpr)
 Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X) Only Scalar data types.
 
InsertPointTy createAtomicCapture (const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &X, AtomicOpValue &V, Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp, bool UpdateExpr, bool IsPostfixUpdate, bool IsXBinopExpr)
 Emit atomic update for constructs: — Only Scalar data types V = X; X = X BinOp Expr , X = X BinOp Expr; V = X, V = X; X = Expr BinOp X, X = Expr BinOp X; V = X, V = X; X = UpdateOp(X), X = UpdateOp(X); V = X,.
 
InsertPointTy createAtomicCompare (const LocationDescription &Loc, AtomicOpValue &X, AtomicOpValue &V, AtomicOpValue &R, Value *E, Value *D, AtomicOrdering AO, omp::OMPAtomicCompareOp Op, bool IsXBinopExpr, bool IsPostfixUpdate, bool IsFailOnly)
 Emit atomic compare for constructs: — Only scalar data types cond-expr-stmt: x = x ordop expr ? expr : x; x = expr ordop x ? expr : x; x = x == e ? d : x; x = e == x ? d : x; (this one is not in the spec) cond-update-stmt: if (x ordop expr) { x = expr; } if (expr ordop x) { x = expr; } if (x == e) { x = d; } if (e == x) { x = d; } (this one is not in the spec) conditional-update-capture-atomic: v = x; cond-update-stmt; (IsPostfixUpdate=true, IsFailOnly=false) cond-update-stmt; v = x; (IsPostfixUpdate=false, IsFailOnly=false) if (x == e) { x = d; } else { v = x; } (IsPostfixUpdate=false, IsFailOnly=true) r = x == e; if (r) { x = d; } (IsPostfixUpdate=false, IsFailOnly=false) r = x == e; if (r) { x = d; } else { v = x; } (IsPostfixUpdate=false, IsFailOnly=true)
 
CanonicalLoopInfocreateLoopSkeleton (DebugLoc DL, Value *TripCount, Function *F, BasicBlock *PreInsertBefore, BasicBlock *PostInsertBefore, const Twine &Name={})
 Create the control flow structure of a canonical OpenMP loop.
 
void loadOffloadInfoMetadata (Module &M)
 Loads all the offload entries information from the host IR metadata.
 
GlobalVariablegetOrCreateInternalVariable (Type *Ty, const StringRef &Name, unsigned AddressSpace=0)
 Gets (if variable with the given name already exist) or creates internal global variable with the specified Name.
 

Static Public Member Functions

static unsigned getOpenMPDefaultSimdAlign (const Triple &TargetTriple, const StringMap< bool > &Features)
 Get the default alignment value for given target.
 

Public Attributes

SmallVector< FinalizationInfo, 8 > FinalizationStack
 The finalization stack made up of finalize callbacks currently in-flight, wrapped into FinalizationInfo objects that reference also the finalization target block and the kind of cancellable directive.
 
OpenMPIRBuilderConfig Config
 The OpenMPIRBuilder Configuration.
 
ModuleM
 The underlying LLVM-IR module.
 
IRBuilder Builder
 The LLVM-IR Builder used to create IR.
 
StringMap< Constant * > SrcLocStrMap
 Map to remember source location strings.
 
DenseMap< std::pair< Constant *, uint64_t >, Constant * > IdentMap
 Map to remember existing ident_t*.
 
OffloadEntriesInfoManager OffloadInfoManager
 Info manager to keep track of target regions.
 
SmallVector< OutlineInfo, 16 > OutlineInfos
 Collection of regions that need to be outlined during finalization.
 
std::forward_list< CanonicalLoopInfoLoopInfos
 Collection of owned canonical loop objects that eventually need to be free'd.
 
StringMap< Constant *, BumpPtrAllocatorInternalVars
 An ordered map of auto-generated variables to their unique names.
 
const std::string ompOffloadInfoName = "omp_offload.info"
 OMP Offload Info Metadata name string.
 

Detailed Description

An interface to create LLVM-IR for OpenMP directives.

Each OpenMP directive has a corresponding public generator method.

Definition at line 411 of file OMPIRBuilder.h.

Member Typedef Documentation

◆ AtomicReductionGenTy

Functions used to generate atomic reductions.

Such functions take two Values representing pointers to LHS and RHS of the reduction, as well as the element type of these pointers. They are expected to atomically update the LHS to the reduced value.

Definition at line 1059 of file OMPIRBuilder.h.

◆ BodyGenCallbackTy

Callback type for body (=inner region) code generation.

The callback takes code locations as arguments, each describing a location where additional instructions can be inserted.

The CodeGenIP may be in the middle of a basic block or point to the end of it. The basic block may have a terminator or be degenerate. The callback function may just insert instructions at that position, but also split the block (without the Before argument of BasicBlock::splitBasicBlock such that the identify of the split predecessor block is preserved) and insert additional control flow, including branches that do not lead back to what follows the CodeGenIP. Note that since the callback is allowed to split the block, callers must assume that InsertPoints to positions in the BasicBlock after CodeGenIP including CodeGenIP itself are invalidated. If such InsertPoints need to be preserved, it can split the block itself before calling the callback.

AllocaIP and CodeGenIP must not point to the same position.

Parameters
AllocaIPis the insertion point at which new alloca instructions should be placed. The BasicBlock it is pointing to must not be split.
CodeGenIPis the insertion point at which the body code should be placed.

Definition at line 512 of file OMPIRBuilder.h.

◆ EmitMetadataErrorReportFunctionTy

Callback function type.

Definition at line 1521 of file OMPIRBuilder.h.

◆ FinalizeCallbackTy

using llvm::OpenMPIRBuilder::FinalizeCallbackTy = std::function<void(InsertPointTy CodeGenIP)>

Callback type for variable finalization (think destructors).

Parameters
CodeGenIPis the insertion point at which the finalization code should be placed.

A finalize callback knows about all objects that need finalization, e.g. destruction, when the scope of the currently generated construct is left at the time, and location, the callback is invoked.

Definition at line 461 of file OMPIRBuilder.h.

◆ FunctionGenCallback

using llvm::OpenMPIRBuilder::FunctionGenCallback = std::function<Function *(StringRef FunctionName)>

Functions used to generate a function with the given name.

Definition at line 1796 of file OMPIRBuilder.h.

◆ InsertPointTy

Type used throughout for insertion points.

Definition at line 441 of file OMPIRBuilder.h.

◆ LoopBodyGenCallbackTy

Callback type for loop body code generation.

Parameters
CodeGenIPis the insertion point where the loop's body code must be placed. This will be a dedicated BasicBlock with a conditional branch from the loop condition check and terminated with an unconditional branch to the loop latch.
IndVaris the induction variable usable at the insertion point.

Definition at line 530 of file OMPIRBuilder.h.

◆ MapDimArrayTy

Definition at line 1457 of file OMPIRBuilder.h.

◆ MapFlagsArrayTy

Definition at line 1455 of file OMPIRBuilder.h.

◆ MapNamesArrayTy

Definition at line 1456 of file OMPIRBuilder.h.

◆ MapNonContiguousArrayTy

Definition at line 1458 of file OMPIRBuilder.h.

◆ MapValuesArrayTy

Definition at line 1454 of file OMPIRBuilder.h.

◆ PrivatizeCallbackTy

Callback type for variable privatization (think copy & default constructor).

Parameters
AllocaIPis the insertion point at which new alloca instructions should be placed.
CodeGenIPis the insertion point at which the privatization code should be placed.
OriginalThe value being copied/created, should not be used in the generated IR.
InnerThe equivalent of Original that should be used in the generated IR; this is equal to Original if the value is a pointer and can thus be passed directly, otherwise it is an equivalent but different value.
ReplValThe replacement value, thus a copy or new created version of Inner.
Returns
The new insertion point where code generation continues and ReplVal the replacement value.

Definition at line 551 of file OMPIRBuilder.h.

◆ ReductionGenTy

Functions used to generate reductions.

Such functions take two Values representing LHS and RHS of the reduction, respectively, and a reference to the value that is updated to refer to the reduction result.

Definition at line 1052 of file OMPIRBuilder.h.

◆ StorableBodyGenCallbackTy

using llvm::OpenMPIRBuilder::StorableBodyGenCallbackTy = std::function<void(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>

Definition at line 519 of file OMPIRBuilder.h.

◆ TargetBodyGenCallbackTy

Definition at line 1876 of file OMPIRBuilder.h.

Member Enumeration Documentation

◆ EmitMetadataErrorKind

The kind of errors that can occur when emitting the offload entries and metadata.

Enumerator
EMIT_MD_TARGET_REGION_ERROR 
EMIT_MD_DECLARE_TARGET_ERROR 
EMIT_MD_GLOBAL_VAR_LINK_ERROR 

Definition at line 1514 of file OMPIRBuilder.h.

Constructor & Destructor Documentation

◆ OpenMPIRBuilder()

llvm::OpenMPIRBuilder::OpenMPIRBuilder ( Module M)
inline

Create a new OpenMPIRBuilder operating on the given module M.

This will not have an effect on M (see initialize)

Definition at line 415 of file OMPIRBuilder.h.

◆ ~OpenMPIRBuilder()

OpenMPIRBuilder::~OpenMPIRBuilder ( )

Definition at line 575 of file OMPIRBuilder.cpp.

References assert(), and OutlineInfos.

Member Function Documentation

◆ addAttributes()

void OpenMPIRBuilder::addAttributes ( omp::RuntimeFunction  FnID,
Function Fn 
)

◆ addOutlineInfo()

void llvm::OpenMPIRBuilder::addOutlineInfo ( OutlineInfo &&  OI)
inline

Add a new region that will be outlined later.

Definition at line 1346 of file OMPIRBuilder.h.

References OutlineInfos.

Referenced by createParallel(), and createTask().

◆ applySimd()

void OpenMPIRBuilder::applySimd ( CanonicalLoopInfo Loop,
MapVector< Value *, Value * >  AlignedVars,
Value IfCond,
omp::OrderKind  Order,
ConstantInt Simdlen,
ConstantInt Safelen 
)

Add metadata to simd-ize a loop.

If IfCond is not nullptr, the loop is cloned. The metadata which prevents vectorization is added to to the cloned loop. The cloned loop is executed when ifCond is evaluated to false.

Parameters
LoopThe loop to simd-ize.
AlignedVarsThe map which containts pairs of the pointer and its corresponding alignment.
IfCondThe value which corresponds to the if clause condition.
OrderThe enum to map order clause.
SimdlenThe Simdlen length to apply to the simd loop.
SafelenThe Safelen length to apply to the simd loop.

Definition at line 3112 of file OMPIRBuilder.cpp.

References addBasicBlockMetadata(), addLoopMetadata(), addSimdMetadata(), assert(), llvm::Block, Builder, llvm::IRBuilderBase::CreateAlignmentAssumption(), F, FAM, llvm::ConstantAsMetadata::get(), llvm::MDNode::get(), llvm::MDString::get(), llvm::CanonicalLoopInfo::getCond(), llvm::IRBuilderBase::getContext(), llvm::MDNode::getDistinct(), llvm::ConstantInt::getFalse(), llvm::CanonicalLoopInfo::getFunction(), llvm::CanonicalLoopInfo::getHeader(), llvm::Type::getInt1Ty(), llvm::CanonicalLoopInfo::getLatch(), llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor(), llvm::CanonicalLoopInfo::getPreheader(), llvm::BasicBlock::getTerminator(), llvm::ConstantInt::getTrue(), llvm::SmallSet< T, N, C >::insert(), llvm::ValueMap< KeyT, ValueT, Config >::lookup(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::AnalysisManager< IRUnitT, ExtraArgTs >::registerPass(), llvm::IRBuilderBase::restoreIP(), llvm::LoopAnalysis::run(), llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), and llvm::MapVector< KeyT, ValueT, MapType, VectorType >::size().

◆ applyWorkshareLoop()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::applyWorkshareLoop ( DebugLoc  DL,
CanonicalLoopInfo CLI,
InsertPointTy  AllocaIP,
bool  NeedsBarrier,
llvm::omp::ScheduleKind  SchedKind = llvm::omp::OMP_SCHEDULE_Default,
llvm::Value ChunkSize = nullptr,
bool  HasSimdModifier = false,
bool  HasMonotonicModifier = false,
bool  HasNonmonotonicModifier = false,
bool  HasOrderedClause = false 
)

Modifies the canonical loop to be a workshare loop.

This takes a LoopInfo representing a canonical loop, such as the one created by createCanonicalLoop and emits additional instructions to turn it into a workshare loop. In particular, it calls to an OpenMP runtime function in the preheader to obtain the loop bounds to be used in the current thread, updates the relevant instructions in the canonical loop and calls to an OpenMP runtime finalization function after the loop.

The concrete transformation is done by applyStaticWorkshareLoop, applyStaticChunkedWorkshareLoop, or applyDynamicWorkshareLoop, depending on the value of SchedKind and ChunkSize.

Parameters
DLDebug location for instructions added for the workshare-loop construct itself.
CLIA descriptor of the canonical loop to workshare.
AllocaIPAn insertion point for Alloca instructions usable in the preheader of the loop.
NeedsBarrierIndicates whether a barrier must be insterted after the loop.
SchedKindScheduling algorithm to use.
ChunkSizeThe chunk size for the inner loop.
HasSimdModifierWhether the simd modifier is present in the schedule clause.
HasMonotonicModifierWhether the monotonic modifier is present in the schedule clause.
HasNonmonotonicModifierWhether the nonmonotonic modifier is present in the schedule clause.
HasOrderedClauseWhether the (parameterless) ordered clause is present.
Returns
Point where to insert code after the workshare construct.

Definition at line 2386 of file OMPIRBuilder.cpp.

References assert(), computeOpenMPScheduleType(), DL, and llvm_unreachable.

◆ collapseLoops()

CanonicalLoopInfo * OpenMPIRBuilder::collapseLoops ( DebugLoc  DL,
ArrayRef< CanonicalLoopInfo * >  Loops,
InsertPointTy  ComputeIP 
)

Collapse a loop nest into a single loop.

Merges loops of a loop nest into a single CanonicalLoopNest representation that has the same number of innermost loop iterations as the origin loop nest. The induction variables of the input loops are derived from the collapsed loop's induction variable. This is intended to be used to implement OpenMP's collapse clause. Before applying a directive, collapseLoops normalizes a loop nest to contain only a single loop and the directive's implementation does not need to handle multiple loops itself. This does not remove the need to handle all loop nest handling by directives, such as the ordered(<n>) clause or the simd schedule-clause modifier of the worksharing-loop directive.

Example:

for (int i = 0; i < 7; ++i) // Canonical loop "i"
for (int j = 0; j < 9; ++j) // Canonical loop "j"
body(i, j);

After collapsing with Loops={i,j}, the loop is changed to

for (int ij = 0; ij < 63; ++ij) {
int i = ij / 9;
int j = ij % 9;
body(i, j);
}

In the current implementation, the following limitations apply:

  • All input loops have an induction variable of the same type.
  • The collapsed loop will have the same trip count integer type as the input loops. Therefore it is possible that the collapsed loop cannot represent all iterations of the input loops. For instance, assuming a 32 bit integer type, and two input loops both iterating 2^16 times, the theoretical trip count of the collapsed loop would be 2^32 iteration, which cannot be represented in an 32-bit integer. Behavior is undefined in this case.
  • The trip counts of every input loop must be available at ComputeIP. Non-rectangular loops are not yet supported.
  • At each nest level, code between a surrounding loop and its nested loop is hoisted into the loop body, and such code will be executed more often than before collapsing (or not at all if any inner loop iteration has a trip count of 0). This is permitted by the OpenMP specification.
Parameters
DLDebug location for instructions added for collapsing, such as instructions to compute/derive the input loop's induction variables.
LoopsLoops in the loop nest to collapse. Loops are specified from outermost-to-innermost and every control flow of a loop's body must pass through its directly nested loop.
ComputeIPWhere additional instruction that compute the collapsed trip count. If not set, defaults to before the generated loop.
Returns
The CanonicalLoopInfo object representing the collapsed loop.

Definition at line 2652 of file OMPIRBuilder.cpp.

References assert(), Builder, createLoopSkeleton(), llvm::IRBuilderBase::CreateMul(), llvm::IRBuilderBase::CreateUDiv(), llvm::IRBuilderBase::CreateURem(), DL, F, llvm::CanonicalLoopInfo::getAfter(), llvm::CanonicalLoopInfo::getBody(), llvm::CanonicalLoopInfo::getLatch(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::BasicBlock::getParent(), llvm::CanonicalLoopInfo::getPreheader(), llvm::CanonicalLoopInfo::getPreheaderIP(), llvm::IRBuilderBase::InsertPoint::isSet(), Loops, redirectAllPredecessorsTo(), redirectTo(), removeUnusedBlocksFromParent(), llvm::SmallVectorImpl< T >::reserve(), llvm::SmallVectorImpl< T >::resize(), llvm::IRBuilderBase::restoreIP(), and llvm::IRBuilderBase::SetCurrentDebugLocation().

◆ createAtomicCapture()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createAtomicCapture ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
AtomicOpValue X,
AtomicOpValue V,
Value Expr,
AtomicOrdering  AO,
AtomicRMWInst::BinOp  RMWOp,
AtomicUpdateCallbackTy UpdateOp,
bool  UpdateExpr,
bool  IsPostfixUpdate,
bool  IsXBinopExpr 
)

Emit atomic update for constructs: — Only Scalar data types V = X; X = X BinOp Expr , X = X BinOp Expr; V = X, V = X; X = Expr BinOp X, X = Expr BinOp X; V = X, V = X; X = UpdateOp(X), X = UpdateOp(X); V = X,.

Parameters
LocThe insert and source location description.
AllocaIPThe insertion point to be used for alloca instructions.
XThe target atomic pointer to be updated
VMemory address where to store captured value
ExprThe value to update X with.
AOAtomic ordering of the generated atomic instructions
RMWOpThe binary operation used for update. If operation is not supported by atomicRMW, or belong to {FADD, FSUB, BAD_BINOP}. Then a cmpExch based atomic will be generated.
UpdateOpCode generator for complex expressions that cannot be expressed through atomicrmw instruction.
UpdateExprtrue if X is an in place update of the form X = X BinOp Expr or X = Expr BinOp X
IsXBinopExprtrue if X is Left H.S. in Right H.S. part of the update expression, false otherwise. (e.g. true for X = X BinOp Expr)
IsPostfixUpdatetrue if original value of 'x' must be stored in 'v', not an updated one.
Returns
Insertion point after generated atomic capture IR.

Definition at line 4731 of file OMPIRBuilder.cpp.

References assert(), Builder, llvm::IRBuilderBase::CreateStore(), llvm::OpenMPIRBuilder::LocationDescription::IP, llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), LLVM_DEBUG, llvm::AtomicRMWInst::Max, llvm::AtomicRMWInst::Min, llvm::IRBuilderBase::saveIP(), updateToLocation(), X, and llvm::AtomicRMWInst::Xchg.

◆ createAtomicCompare()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createAtomicCompare ( const LocationDescription Loc,
AtomicOpValue X,
AtomicOpValue V,
AtomicOpValue R,
Value E,
Value D,
AtomicOrdering  AO,
omp::OMPAtomicCompareOp  Op,
bool  IsXBinopExpr,
bool  IsPostfixUpdate,
bool  IsFailOnly 
)

Emit atomic compare for constructs: — Only scalar data types cond-expr-stmt: x = x ordop expr ? expr : x; x = expr ordop x ? expr : x; x = x == e ? d : x; x = e == x ? d : x; (this one is not in the spec) cond-update-stmt: if (x ordop expr) { x = expr; } if (expr ordop x) { x = expr; } if (x == e) { x = d; } if (e == x) { x = d; } (this one is not in the spec) conditional-update-capture-atomic: v = x; cond-update-stmt; (IsPostfixUpdate=true, IsFailOnly=false) cond-update-stmt; v = x; (IsPostfixUpdate=false, IsFailOnly=false) if (x == e) { x = d; } else { v = x; } (IsPostfixUpdate=false, IsFailOnly=true) r = x == e; if (r) { x = d; } (IsPostfixUpdate=false, IsFailOnly=false) r = x == e; if (r) { x = d; } else { v = x; } (IsPostfixUpdate=false, IsFailOnly=true)

Parameters
LocThe insert and source location description.
XThe target atomic pointer to be updated.
VMemory address where to store captured value (for compare capture only).
RMemory address where to store comparison result (for compare capture with '==' only).
EThe expected value ('e') for forms that use an equality comparison or an expression ('expr') for forms that use 'ordop' (logically an atomic maximum or minimum).
DThe desired value for forms that use an equality comparison. If forms that use 'ordop', it should be nullptr.
AOAtomic ordering of the generated atomic instructions.
OpAtomic compare operation. It can only be ==, <, or >.
IsXBinopExprTrue if the conditional statement is in the form where x is on LHS. It only matters for < or >.
IsPostfixUpdateTrue if original value of 'x' must be stored in 'v', not an updated one (for compare capture only).
IsFailOnlyTrue if the original value of 'x' is stored to 'v' only when the comparison fails. This is only valid for the case the comparison is '=='.
Returns
Insertion point after generated atomic capture IR.

Definition at line 4765 of file OMPIRBuilder.cpp.

References assert(), Builder, llvm::IRBuilderBase::CreateAtomicCmpXchg(), llvm::IRBuilderBase::CreateAtomicRMW(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateBr(), llvm::IRBuilderBase::CreateCmp(), llvm::IRBuilderBase::CreateCondBr(), llvm::IRBuilderBase::CreateExtractValue(), llvm::IRBuilderBase::CreateSelect(), llvm::IRBuilderBase::CreateSExt(), llvm::IRBuilderBase::CreateStore(), llvm::IRBuilderBase::CreateUnreachable(), llvm::IRBuilderBase::CreateZExt(), D, E, llvm::Instruction::eraseFromParent(), llvm::CmpInst::FCMP_OGT, llvm::CmpInst::FCMP_OLT, llvm::AtomicRMWInst::FMax, llvm::AtomicRMWInst::FMin, llvm::IntegerType::get(), llvm::Module::getContext(), llvm::IRBuilderBase::GetInsertBlock(), llvm::Type::getPointerTo(), llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::OpenMPIRBuilder::LocationDescription::IP, llvm_unreachable, M, llvm::AtomicRMWInst::Max, llvm::AtomicRMWInst::Min, llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), llvm::BasicBlock::splitBasicBlock(), llvm::AtomicRMWInst::UMax, llvm::AtomicRMWInst::UMin, updateToLocation(), and X.

◆ createAtomicRead()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createAtomicRead ( const LocationDescription Loc,
AtomicOpValue X,
AtomicOpValue V,
AtomicOrdering  AO 
)

Emit atomic Read for : V = X — Only Scalar data types.

Parameters
LocThe insert and source location description.
XThe target pointer to be atomically read
VMemory address where to store atomically read value
AOAtomic ordering of the generated atomic instructions.
Returns
Insertion point after generated atomic read IR.

Definition at line 4482 of file OMPIRBuilder.cpp.

References assert(), Builder, llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateIntToPtr(), llvm::IRBuilderBase::CreateLoad(), llvm::IRBuilderBase::CreateStore(), llvm::IntegerType::get(), llvm::Module::getContext(), llvm::Type::getPointerTo(), llvm::Type::getScalarSizeInBits(), llvm::OpenMPIRBuilder::LocationDescription::IP, llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), M, llvm::IRBuilderBase::saveIP(), llvm::LoadInst::setAtomic(), updateToLocation(), and X.

◆ createAtomicUpdate()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createAtomicUpdate ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
AtomicOpValue X,
Value Expr,
AtomicOrdering  AO,
AtomicRMWInst::BinOp  RMWOp,
AtomicUpdateCallbackTy UpdateOp,
bool  IsXBinopExpr 
)

Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X) Only Scalar data types.

Parameters
LocThe insert and source location description.
AllocaIPThe insertion point to be used for alloca instructions.
XThe target atomic pointer to be updated
ExprThe value to update X with.
AOAtomic ordering of the generated atomic instructions.
RMWOpThe binary operation used for update. If operation is not supported by atomicRMW, or belong to {FADD, FSUB, BAD_BINOP}. Then a cmpExch based atomic will be generated.
UpdateOpCode generator for complex expressions that cannot be expressed through atomicrmw instruction.
IsXBinopExprtrue if X is Left H.S. in Right H.S. part of the update expression, false otherwise. (e.g. true for X = X BinOp Expr)
Returns
Insertion point after generated atomic update IR.

Definition at line 4557 of file OMPIRBuilder.cpp.

References assert(), Builder, llvm::OpenMPIRBuilder::LocationDescription::IP, isConflictIP(), llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), LLVM_DEBUG, llvm::AtomicRMWInst::Max, llvm::AtomicRMWInst::Min, llvm::IRBuilderBase::saveIP(), llvm::AtomicRMWInst::UMax, llvm::AtomicRMWInst::UMin, updateToLocation(), and X.

◆ createAtomicWrite()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createAtomicWrite ( const LocationDescription Loc,
AtomicOpValue X,
Value Expr,
AtomicOrdering  AO 
)

Emit atomic write for : X = Expr — Only Scalar data types.

Parameters
LocThe insert and source location description.
XThe target pointer to be atomically written to
ExprThe value to store.
AOAtomic ordering of the generated atomic instructions.
Returns
Insertion point after generated atomic Write IR.

Definition at line 4524 of file OMPIRBuilder.cpp.

References assert(), Builder, llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateStore(), llvm::IntegerType::get(), llvm::Module::getContext(), llvm::Type::getPointerTo(), llvm::Type::getScalarSizeInBits(), llvm::OpenMPIRBuilder::LocationDescription::IP, llvm::Type::isFloatingPointTy(), llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), M, llvm::IRBuilderBase::saveIP(), llvm::StoreInst::setAtomic(), updateToLocation(), and X.

◆ createBarrier()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createBarrier ( const LocationDescription Loc,
omp::Directive  DK,
bool  ForceSimpleCall = false,
bool  CheckCancelFlag = true 
)

Emitter methods for OpenMP directives.

{ Generator for '#omp barrier'

Parameters
LocThe location where the barrier directive was encountered.
DKThe kind of directive that caused the barrier.
ForceSimpleCallFlag to force a simple (=non-cancellation) barrier.
CheckCancelFlagFlag to indicate a cancel barrier return value should be checked and acted upon.
Returns
The insertion point after the barrier.

Definition at line 705 of file OMPIRBuilder.cpp.

References emitBarrierImpl(), llvm::OpenMPIRBuilder::LocationDescription::IP, and updateToLocation().

Referenced by createCancel(), and createSingle().

◆ createCachedThreadPrivate()

CallInst * OpenMPIRBuilder::createCachedThreadPrivate ( const LocationDescription Loc,
llvm::Value Pointer,
llvm::ConstantInt Size,
const llvm::Twine Name = Twine("") 
)

Create a runtime call for kmpc_threadprivate_cached.

Parameters
LocThe insert and source location description.
Pointerpointer to data to be cached
Sizesize of data to be cached
NameName of call Instruction for callinst
Returns
CallInst to the thread private cache call.

Definition at line 3906 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), getOrCreateIdent(), getOrCreateInternalVariable(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, Name, llvm::IRBuilderBase::restoreIP(), and Size.

◆ createCancel()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createCancel ( const LocationDescription Loc,
Value IfCondition,
omp::Directive  CanceledDirective 
)

Generator for '#omp cancel'.

Parameters
LocThe location where the directive was encountered.
IfConditionThe evaluated 'if' clause expression, if any.
CanceledDirectiveThe kind of directive that is cancled.
Returns
The insertion point after the barrier.

Definition at line 762 of file OMPIRBuilder.cpp.

References Builder, createBarrier(), llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateUnreachable(), llvm::OpenMPIRBuilder::LocationDescription::DL, emitCancelationCheckImpl(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, llvm_unreachable, llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), llvm::SplitBlockAndInsertIfThenElse(), and updateToLocation().

◆ createCanonicalLoop() [1/2]

CanonicalLoopInfo * OpenMPIRBuilder::createCanonicalLoop ( const LocationDescription Loc,
LoopBodyGenCallbackTy  BodyGenCB,
Value Start,
Value Stop,
Value Step,
bool  IsSigned,
bool  InclusiveStop,
InsertPointTy  ComputeIP = {},
const Twine Name = "loop" 
)

Generator for the control flow structure of an OpenMP canonical loop.

Instead of a logical iteration space, this allows specifying user-defined loop counter values using increment, upper- and lower bounds. To disambiguate the terminology when counting downwards, instead of lower bounds we use Start for the loop counter value in the first body iteration.

Consider the following limitations:

  • A loop counter space over all integer values of its bit-width cannot be represented. E.g using uint8_t, its loop trip count of 256 cannot be stored into an 8 bit integer):

    DO I = 0, 255, 1

  • Unsigned wrapping is only supported when wrapping only "once"; E.g. effectively counting downwards:

    for (uint8_t i = 100u; i > 0; i += 127u)

TODO: May need to add additional parameters to represent:

  • Allow representing downcounting with unsigned integers.
  • Sign of the step and the comparison operator might disagree:

    for (int i = 0; i < 42; i -= 1u)

    Parameters
    LocThe insert and source location description.
    BodyGenCBCallback that will generate the loop body code.
    StartValue of the loop counter for the first iterations.
    StopLoop counter values past this will stop the loop.
    StepLoop counter increment after each iteration; negative means counting down.
    IsSignedWhether Start, Stop and Step are signed integers.
    InclusiveStopWhether Stop itself is a valid value for the loop counter.
    ComputeIPInsertion point for instructions computing the trip count. Can be used to ensure the trip count is available at the outermost loop of a loop nest. If not set, defaults to the preheader of the generated loop.
    NameBase name used to derive BB and instruction names.
    Returns
    An object representing the created control flow structure which can be used for loop-associated directives.
  • A Step of INT_MIN cannot not be normalized to a positive direction:

Definition at line 2068 of file OMPIRBuilder.cpp.

References assert(), Builder, llvm::IRBuilderBase::CreateAdd(), createCanonicalLoop(), llvm::IRBuilderBase::CreateICmp(), llvm::IRBuilderBase::CreateICmpSLT(), llvm::IRBuilderBase::CreateMul(), llvm::IRBuilderBase::CreateNeg(), llvm::IRBuilderBase::CreateSelect(), llvm::IRBuilderBase::CreateSub(), llvm::IRBuilderBase::CreateUDiv(), llvm::OpenMPIRBuilder::LocationDescription::DL, llvm::ConstantInt::get(), llvm::Value::getType(), llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::OpenMPIRBuilder::LocationDescription::IP, llvm::IRBuilderBase::InsertPoint::isSet(), IV, Name, llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::saveIP(), and updateToLocation().

◆ createCanonicalLoop() [2/2]

CanonicalLoopInfo * OpenMPIRBuilder::createCanonicalLoop ( const LocationDescription Loc,
LoopBodyGenCallbackTy  BodyGenCB,
Value TripCount,
const Twine Name = "loop" 
)

Generator for the control flow structure of an OpenMP canonical loop.

This generator operates on the logical iteration space of the loop, i.e. the caller only has to provide a loop trip count of the loop as defined by base language semantics. The trip count is interpreted as an unsigned integer. The induction variable passed to BodyGenCB will be of the same type and run from 0 to TripCount - 1. It is up to the callback to convert the logical iteration variable to the loop counter variable in the loop body.

Parameters
LocThe insert and source location description. The insert location can be between two instructions or the end of a degenerate block (e.g. a BB under construction).
BodyGenCBCallback that will generate the loop body code.
TripCountNumber of iterations the loop body is executed.
NameBase name used to derive BB and instruction names.
Returns
An object representing the created control flow structure which can be used for loop-associated directives.

Definition at line 2039 of file OMPIRBuilder.cpp.

References llvm::CanonicalLoopInfo::assertOK(), Builder, llvm::IRBuilderBase::CreateBr(), createLoopSkeleton(), llvm::OpenMPIRBuilder::LocationDescription::DL, llvm::CanonicalLoopInfo::getAfter(), llvm::IRBuilderBase::InsertPoint::getBlock(), llvm::CanonicalLoopInfo::getBodyIP(), llvm::CanonicalLoopInfo::getIndVar(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::BasicBlock::getParent(), llvm::CanonicalLoopInfo::getPreheader(), llvm::OpenMPIRBuilder::LocationDescription::IP, Name, llvm::spliceBB(), and updateToLocation().

Referenced by createCanonicalLoop(), and createSections().

◆ createCopyinClauseBlocks()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createCopyinClauseBlocks ( InsertPointTy  IP,
Value MasterAddr,
Value PrivateAddr,
llvm::IntegerType IntPtrTy,
bool  BranchtoEnd = true 
)

Generate conditional branch and relevant BasicBlocks through which private threads copy the 'copyin' variables from Master copy to threadprivate copies.

Parameters
IPinsertion block for copyin conditional
MasterVarPtra pointer to the master variable
PrivateVarPtra pointer to the threadprivate variable
IntPtrTyPointer size type
BranchtoEndCreate a branch between the copyin.not.master blocks
Returns
The insertion point where copying operation to be emitted.

Definition at line 3740 of file OMPIRBuilder.cpp.

References Builder, llvm::BasicBlock::Create(), llvm::IRBuilderBase::CreateBr(), llvm::IRBuilderBase::CreateCondBr(), llvm::IRBuilderBase::CreateICmpNE(), llvm::IRBuilderBase::CreatePtrToInt(), llvm::Instruction::eraseFromParent(), llvm::IRBuilderBase::InsertPoint::getBlock(), llvm::Module::getContext(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getTerminator(), llvm::IRBuilderBase::InsertPoint::isSet(), M, llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), and llvm::BasicBlock::splitBasicBlock().

◆ createCopyPrivate()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createCopyPrivate ( const LocationDescription Loc,
llvm::Value BufSize,
llvm::Value CpyBuf,
llvm::Value CpyFn,
llvm::Value DidIt 
)

Generator for __kmpc_copyprivate.

Parameters
LocThe source location description.
BufSizeNumber of elements in the buffer.
CpyBufList of pointers to data to be copied.
CpyFnfunction to call for copying data.
DidItflag variable; 1 for 'single' thread, 0 otherwise.
Returns
The insertion position after the CopyPrivate call.

Definition at line 3454 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateLoad(), llvm::IRBuilderBase::getInt32Ty(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, llvm::IRBuilderBase::saveIP(), and updateToLocation().

◆ createCritical()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createCritical ( const LocationDescription Loc,
BodyGenCallbackTy  BodyGenCB,
FinalizeCallbackTy  FiniCB,
StringRef  CriticalName,
Value HintInst 
)

Generator for '#omp critical'.

Parameters
LocThe insert and source location description.
BodyGenCBCallback that will generate the region body code.
FiniCBCallback to finalize variable copies.
CriticalNamename of the lock used by the critical directive
HintInstHint Instruction for hint clause associated with critical
Returns
The insertion position after the critical.

Definition at line 3517 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, llvm::SmallVectorTemplateBase< T, bool >::push_back(), and updateToLocation().

◆ createFlush()

void OpenMPIRBuilder::createFlush ( const LocationDescription Loc)

Generator for '#omp flush'.

Parameters
LocThe location where the flush directive was encountered

Definition at line 1278 of file OMPIRBuilder.cpp.

References emitFlush(), and updateToLocation().

◆ createGlobalFlag()

GlobalValue * OpenMPIRBuilder::createGlobalFlag ( unsigned  Value,
StringRef  Name 
)

Create a hidden global flag Name in the module with initial value Value.

Definition at line 579 of file OMPIRBuilder.cpp.

References llvm::ConstantInt::get(), llvm::Module::getContext(), llvm::Type::getInt32Ty(), llvm::GlobalValue::HiddenVisibility, M, Name, and llvm::GlobalValue::WeakODRLinkage.

◆ createLoopSkeleton()

CanonicalLoopInfo * OpenMPIRBuilder::createLoopSkeleton ( DebugLoc  DL,
Value TripCount,
Function F,
BasicBlock PreInsertBefore,
BasicBlock PostInsertBefore,
const Twine Name = {} 
)

Create the control flow structure of a canonical OpenMP loop.

The emitted loop will be disconnected, i.e. no edge to the loop's preheader and no terminator in the AfterBB. The OpenMPIRBuilder's IRBuilder location is not preserved.

Parameters
DLDebugLoc used for the instructions in the skeleton.
TripCountValue to be used for the trip count.
FFunction in which to insert the BasicBlocks.
PreInsertBeforeWhere to insert BBs that execute before the body, typically the body itself.
PostInsertBeforeWhere to insert BBs that execute after the body.
NameBase name used to derive BB and instruction names.
Returns
The CanonicalLoopInfo that represents the emitted loop.

Definition at line 1972 of file OMPIRBuilder.cpp.

References llvm::PHINode::addIncoming(), llvm::CanonicalLoopInfo::assertOK(), Builder, Cond, llvm::BasicBlock::Create(), llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateBr(), llvm::IRBuilderBase::CreateCondBr(), llvm::IRBuilderBase::CreateICmpULT(), llvm::IRBuilderBase::CreatePHI(), DL, F, llvm::ConstantInt::get(), llvm::Module::getContext(), llvm::Value::getType(), LoopInfos, M, Name, llvm::IRBuilderBase::SetCurrentDebugLocation(), and llvm::IRBuilderBase::SetInsertPoint().

Referenced by collapseLoops(), createCanonicalLoop(), and tileLoops().

◆ createMapperAllocas()

void OpenMPIRBuilder::createMapperAllocas ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
unsigned  NumOperands,
struct MapperAllocas MapperAllocas 
)

◆ createMasked()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createMasked ( const LocationDescription Loc,
BodyGenCallbackTy  BodyGenCB,
FinalizeCallbackTy  FiniCB,
Value Filter 
)

Generator for '#omp masked'.

Parameters
LocThe insert and source location description.
BodyGenCBCallback that will generate the region code.
FiniCBCallback to finialize variable copies.
Returns
The insertion position after the masked.

Definition at line 1948 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), llvm::Filter, getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, and updateToLocation().

◆ createMaster()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createMaster ( const LocationDescription Loc,
BodyGenCallbackTy  BodyGenCB,
FinalizeCallbackTy  FiniCB 
)

Generator for '#omp master'.

Parameters
LocThe insert and source location description.
BodyGenCBCallback that will generate the region code.
FiniCBCallback to finalize variable copies.
Returns
The insertion position after the master.

Definition at line 1923 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, and updateToLocation().

◆ createOffloadEntriesAndInfoMetadata()

void OpenMPIRBuilder::createOffloadEntriesAndInfoMetadata ( EmitMetadataErrorReportFunctionTy ErrorReportFunction)

◆ createOffloadEntry()

void OpenMPIRBuilder::createOffloadEntry ( Constant ID,
Constant Addr,
uint64_t  Size,
int32_t  Flags,
GlobalValue::LinkageTypes   
)

◆ createOffloadMapnames()

GlobalVariable * OpenMPIRBuilder::createOffloadMapnames ( SmallVectorImpl< llvm::Constant * > &  Names,
std::string  VarName 
)

◆ createOffloadMaptypes()

GlobalVariable * OpenMPIRBuilder::createOffloadMaptypes ( SmallVectorImpl< uint64_t > &  Mappings,
std::string  VarName 
)

Create the global variable holding the offload mappings information.

Definition at line 4302 of file OMPIRBuilder.cpp.

References llvm::ConstantDataArray::get(), llvm::Module::getContext(), llvm::Value::getType(), llvm::GlobalValue::Global, M, and llvm::GlobalValue::PrivateLinkage.

Referenced by createTargetData().

◆ createOMPAlloc()

CallInst * OpenMPIRBuilder::createOMPAlloc ( const LocationDescription Loc,
Value Size,
Value Allocator,
std::string  Name = "" 
)

Create a runtime call for kmpc_Alloc.

Parameters
LocThe insert and source location description.
SizeSize of allocated memory space
AllocatorAllocator information instruction
NameName of call Instruction for OMP_alloc
Returns
CallInst to the OMP_Alloc call

Definition at line 3790 of file OMPIRBuilder.cpp.

References Allocator, Builder, llvm::IRBuilderBase::CreateCall(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, Name, llvm::IRBuilderBase::restoreIP(), and Size.

◆ createOMPFree()

CallInst * OpenMPIRBuilder::createOMPFree ( const LocationDescription Loc,
Value Addr,
Value Allocator,
std::string  Name = "" 
)

Create a runtime call for kmpc_free.

Parameters
LocThe insert and source location description.
AddrAddress of memory space to be freed
AllocatorAllocator information instruction
NameName of call Instruction for OMP_Free
Returns
CallInst to the OMP_Free call

Definition at line 3807 of file OMPIRBuilder.cpp.

References Addr, Allocator, Builder, llvm::IRBuilderBase::CreateCall(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, Name, and llvm::IRBuilderBase::restoreIP().

◆ createOMPInteropDestroy()

CallInst * OpenMPIRBuilder::createOMPInteropDestroy ( const LocationDescription Loc,
Value InteropVar,
Value Device,
Value NumDependences,
Value DependenceAddress,
bool  HaveNowaitClause 
)

Create a runtime call for __tgt_interop_destroy.

Parameters
LocThe insert and source location description.
InteropVarvariable to be allocated
Devicedevide to which offloading will occur
NumDependencesnumber of dependence variables
DependenceAddresspointer to dependence variables
HaveNowaitClausedoes nowait clause exist
Returns
CallInst to the __tgt_interop_destroy call

Definition at line 3851 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), llvm::ConstantPointerNull::get(), llvm::ConstantInt::get(), llvm::Module::getContext(), llvm::Type::getInt8PtrTy(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), Int32, llvm::OpenMPIRBuilder::LocationDescription::IP, M, and llvm::IRBuilderBase::restoreIP().

◆ createOMPInteropInit()

CallInst * OpenMPIRBuilder::createOMPInteropInit ( const LocationDescription Loc,
Value InteropVar,
omp::OMPInteropType  InteropType,
Value Device,
Value NumDependences,
Value DependenceAddress,
bool  HaveNowaitClause 
)

Create a runtime call for __tgt_interop_init.

Parameters
LocThe insert and source location description.
InteropVarvariable to be allocated
InteropTypetype of interop operation
Devicedevide to which offloading will occur
NumDependencesnumber of dependence variables
DependenceAddresspointer to dependence variables
HaveNowaitClausedoes nowait clause exist
Returns
CallInst to the __tgt_interop_init call

Definition at line 3822 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), llvm::ConstantPointerNull::get(), llvm::ConstantInt::get(), llvm::Module::getContext(), llvm::Type::getInt8PtrTy(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), Int32, llvm::OpenMPIRBuilder::LocationDescription::IP, M, and llvm::IRBuilderBase::restoreIP().

◆ createOMPInteropUse()

CallInst * OpenMPIRBuilder::createOMPInteropUse ( const LocationDescription Loc,
Value InteropVar,
Value Device,
Value NumDependences,
Value DependenceAddress,
bool  HaveNowaitClause 
)

Create a runtime call for __tgt_interop_use.

Parameters
LocThe insert and source location description.
InteropVarvariable to be allocated
Devicedevide to which offloading will occur
NumDependencesnumber of dependence variables
DependenceAddresspointer to dependence variables
HaveNowaitClausedoes nowait clause exist
Returns
CallInst to the __tgt_interop_use call

Definition at line 3878 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), llvm::ConstantPointerNull::get(), llvm::ConstantInt::get(), llvm::Module::getContext(), llvm::Type::getInt8PtrTy(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), Int32, llvm::OpenMPIRBuilder::LocationDescription::IP, M, and llvm::IRBuilderBase::restoreIP().

◆ createOrderedDepend()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createOrderedDepend ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
unsigned  NumLoops,
ArrayRef< llvm::Value * >  StoreValues,
const Twine Name,
bool  IsDependSource 
)

Generator for '#omp ordered depend (source | sink)'.

Parameters
LocThe insert and source location description.
AllocaIPThe insertion point to be used for alloca instructions.
NumLoopsThe number of loops in depend clause.
StoreValuesThe value will be stored in vector address.
NameThe name of alloca instruction.
IsDependSourceIf true, depend source; otherwise, depend sink.
Returns
The insertion position after the ordered.

Definition at line 3552 of file OMPIRBuilder.cpp.

References llvm::all_of(), assert(), Builder, llvm::IRBuilderBase::CreateAlloca(), llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateInBoundsGEP(), llvm::IRBuilderBase::CreateStore(), llvm::ArrayType::get(), llvm::IRBuilderBase::getInt64(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::Value::getType(), I, Int64, llvm::OpenMPIRBuilder::LocationDescription::IP, Name, llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::saveIP(), llvm::AllocaInst::setAlignment(), llvm::StoreInst::setAlignment(), and updateToLocation().

◆ createOrderedThreadsSimd()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createOrderedThreadsSimd ( const LocationDescription Loc,
BodyGenCallbackTy  BodyGenCB,
FinalizeCallbackTy  FiniCB,
bool  IsThreads 
)

Generator for '#omp ordered [threads | simd]'.

Parameters
LocThe insert and source location description.
BodyGenCBCallback that will generate the region code.
FiniCBCallback to finalize variable copies.
IsThreadsIf true, with threads clause or without clause; otherwise, with simd clause;
Returns
The insertion position after the ordered.

Definition at line 3598 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, and updateToLocation().

◆ createParallel()

IRBuilder::InsertPoint OpenMPIRBuilder::createParallel ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
BodyGenCallbackTy  BodyGenCB,
PrivatizeCallbackTy  PrivCB,
FinalizeCallbackTy  FiniCB,
Value IfCondition,
Value NumThreads,
omp::ProcBindKind  ProcBind,
bool  IsCancellable 
)

Generator for '#omp parallel'.

Parameters
LocThe insert and source location description.
AllocaIPThe insertion points to be used for alloca instructions.
BodyGenCBCallback that will generate the region code.
PrivCBCallback to copy a given variable (think copy constructor).
FiniCBCallback to finalize variable copies.
IfConditionThe evaluated 'if' clause expression, if any.
NumThreadsThe evaluated 'num_threads' clause expression, if any.
ProcBindThe value of the 'proc_bind' clause (see ProcBindKind).
IsCancellableFlag to indicate a cancellable parallel region.
Returns
The insertion position after the parallel.

Definition at line 920 of file OMPIRBuilder.cpp.

References addOutlineInfo(), llvm::SmallVectorImpl< T >::append(), llvm::CallBase::arg_begin(), llvm::CallBase::arg_end(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::BasicBlock::begin(), Blocks, Builder, llvm::OpenMPIRBuilder::OutlineInfo::collectBlocks(), Cond, llvm::SmallPtrSetImpl< PtrType >::count(), llvm::IRBuilderBase::CreateAlloca(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateBr(), llvm::IRBuilderBase::CreateCall(), llvm::MDBuilder::createCallbackEncoding(), llvm::IRBuilderBase::CreateIntCast(), llvm::IRBuilderBase::CreateLoad(), llvm::IRBuilderBase::CreateSExtOrTrunc(), llvm::IRBuilderBase::CreateStore(), llvm::dbgs(), llvm::SetVector< T, Vector, Set >::empty(), llvm::BasicBlock::end(), llvm::OpenMPIRBuilder::OutlineInfo::EntryBB, llvm::Instruction::eraseFromParent(), llvm::OpenMPIRBuilder::OutlineInfo::ExcludeArgsFromAggregate, llvm::OpenMPIRBuilder::OutlineInfo::ExitBB, F, FinalizationStack, llvm::CodeExtractor::findAllocas(), llvm::CodeExtractor::findInputsOutputs(), llvm::MDNode::get(), llvm::ConstantPointerNull::get(), llvm::ConstantInt::get(), llvm::IRBuilderBase::InsertPoint::getBlock(), llvm::CallBase::getCalledFunction(), llvm::FunctionCallee::getCallee(), llvm::IRBuilderBase::getContext(), llvm::Module::getContext(), llvm::BasicBlock::getFirstInsertionPt(), llvm::IRBuilderBase::GetInsertBlock(), llvm::IRBuilderBase::getInt32(), llvm::Type::getInt32Ty(), llvm::Type::getInt8PtrTy(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::BasicBlock::getParent(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), I, Int32, llvm::OpenMPIRBuilder::LocationDescription::IP, isConflictIP(), LLVM_DEBUG, M, llvm::OpenMPIRBuilder::OutlineInfo::OuterAllocaBB, llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCB, Ptr, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), llvm::Value::setName(), llvm::BasicBlock::splitBasicBlock(), llvm::SplitBlock(), updateToLocation(), Uses, and Void.

◆ createPlatformSpecificName()

std::string OpenMPIRBuilder::createPlatformSpecificName ( ArrayRef< StringRef Parts) const

Get the create a name using the platform specific separators.

Parameters
Partsparts of the final name that needs separation The created name has a first separator between the first and second part and a second separator between all other parts. E.g. with FirstSeparator "$" and Separator "." and parts: "p1", "p2", "p3", "p4" The resulting name is "p1$p2.p3.p4" The separators are retrieved from the OpenMPIRBuilderConfig.

Definition at line 4257 of file OMPIRBuilder.cpp.

References Config, llvm::OpenMPIRBuilderConfig::firstSeparator(), and llvm::OpenMPIRBuilderConfig::separator().

Referenced by emitTargetRegionFunction().

◆ createReductions()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createReductions ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
ArrayRef< ReductionInfo ReductionInfos,
bool  IsNoWait = false 
)

Generator for '#omp reduction'.

Emits the IR instructing the runtime to perform the specific kind of reductions. Expects reduction variables to have been privatized and initialized to reduction-neutral values separately. Emits the calls to runtime functions as well as the reduction function and the basic blocks performing the reduction atomically and non-atomically.

The code emitted for the following:

type var_1;
type var_2;
#pragma omp <directive> reduction(reduction-op:var_1,var_2)
/* body */;

corresponds to the following sketch.

void _outlined_par() {
// N is the number of different reductions.
void *red_array[] = {privatized_var_1, privatized_var_2, ...};
switch(__kmpc_reduce(..., N, /*size of data in red array*/, red_array,
_omp_reduction_func,
_gomp_critical_user.reduction.var)) {
case 1: {
var_1 = var_1 <reduction-op> privatized_var_1;
var_2 = var_2 <reduction-op> privatized_var_2;
// ...
__kmpc_end_reduce(...);
break;
}
case 2: {
_Atomic<ReductionOp>(var_1, privatized_var_1);
_Atomic<ReductionOp>(var_2, privatized_var_2);
// ...
break;
}
default: break;
}
}
void _omp_reduction_func(void **lhs, void **rhs) {
*(type *)lhs[0] = *(type *)lhs[0] <reduction-op> *(type *)rhs[0];
*(type *)lhs[1] = *(type *)lhs[1] <reduction-op> *(type *)rhs[1];
// ...
}
#define op(i)
Straight line strength reduction
#define N
Parameters
LocThe location where the reduction was encountered. Must be within the associate directive and after the last local access to the reduction variables.
AllocaIPAn insertion point suitable for allocas usable in reductions.
ReductionInfosA list of info on each reduction variable.
IsNoWaitA flag set if the reduction is marked as nowait.

Definition at line 1759 of file OMPIRBuilder.cpp.

References llvm::all_of(), assert(), llvm::OpenMPIRBuilder::ReductionInfo::AtomicReductionGen, Builder, llvm::BasicBlock::Create(), llvm::IRBuilderBase::CreateAlloca(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateBr(), llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateConstInBoundsGEP2_64(), llvm::IRBuilderBase::CreateLoad(), llvm::IRBuilderBase::CreateRetVoid(), llvm::IRBuilderBase::CreateStore(), llvm::IRBuilderBase::CreateSwitch(), llvm::IRBuilderBase::CreateUnreachable(), DL, llvm::OpenMPIRBuilder::ReductionInfo::ElementType, llvm::BasicBlock::end(), llvm::enumerate(), llvm::Instruction::eraseFromParent(), llvm::ArrayType::get(), llvm::Function::getArg(), llvm::IRBuilderBase::InsertPoint::getBlock(), llvm::Module::getContext(), llvm::Module::getDataLayout(), getFreshReductionFunc(), llvm::IRBuilderBase::GetInsertBlock(), llvm::IRBuilderBase::getInt32(), llvm::IRBuilderBase::getInt64(), llvm::IRBuilderBase::getInt8PtrTy(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::BasicBlock::getParent(), llvm::IRBuilderBase::InsertPoint::getPoint(), llvm::Type::getPointerTo(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::OpenMPIRBuilder::LocationDescription::IP, LHS, llvm::OpenMPIRBuilder::ReductionInfo::PrivateVariable, llvm::OpenMPIRBuilder::ReductionInfo::ReductionGen, llvm::IRBuilderBase::restoreIP(), RHS, llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), llvm::ArrayRef< T >::size(), llvm::BasicBlock::splitBasicBlock(), updateToLocation(), and llvm::OpenMPIRBuilder::ReductionInfo::Variable.

◆ createSection()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createSection ( const LocationDescription Loc,
BodyGenCallbackTy  BodyGenCB,
FinalizeCallbackTy  FiniCB 
)

Generator for '#omp section'.

Parameters
LocThe insert and source location description.
BodyGenCBCallback that will generate the region body code.
FiniCBCallback to finalize variable copies.
Returns
The insertion position after the section.

Definition at line 1713 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateBr(), llvm::IRBuilderBase::InsertPoint::getBlock(), llvm::BasicBlock::getSinglePredecessor(), llvm::Instruction::getSuccessor(), llvm::BasicBlock::getTerminator(), I, llvm::OpenMPIRBuilder::LocationDescription::IP, llvm::IRBuilderBase::restoreIP(), and updateToLocation().

◆ createSections()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createSections ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
ArrayRef< StorableBodyGenCallbackTy SectionCBs,
PrivatizeCallbackTy  PrivCB,
FinalizeCallbackTy  FiniCB,
bool  IsCancellable,
bool  IsNowait 
)

Generator for '#omp sections'.

Parameters
LocThe insert and source location description.
AllocaIPThe insertion points to be used for alloca instructions.
SectionCBsCallbacks that will generate body of each section.
PrivCBCallback to copy a given variable (think copy constructor).
FiniCBCallback to finalize variable copies.
IsCancellableFlag to indicate a cancellable parallel region.
IsNowaitIf true, barrier - to ensure all sections are executed before moving forward will not be generated.
Returns
The insertion position after the sections.

Definition at line 1618 of file OMPIRBuilder.cpp.

References llvm::SwitchInst::addCase(), assert(), llvm::BasicBlock::begin(), Builder, llvm::BasicBlock::Create(), llvm::IRBuilderBase::CreateBr(), createCanonicalLoop(), llvm::IRBuilderBase::CreateSwitch(), llvm::OpenMPIRBuilder::LocationDescription::DL, FinalizationStack, llvm::ConstantInt::get(), llvm::Module::getContext(), llvm::IRBuilderBase::getInt32(), llvm::Type::getInt32Ty(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::BasicBlock::getParent(), llvm::Instruction::getParent(), I, llvm::OpenMPIRBuilder::LocationDescription::IP, isConflictIP(), M, llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), llvm::ArrayRef< T >::size(), llvm::splitBBWithSuffix(), and updateToLocation().

◆ createSingle()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createSingle ( const LocationDescription Loc,
BodyGenCallbackTy  BodyGenCB,
FinalizeCallbackTy  FiniCB,
bool  IsNowait,
llvm::Value DidIt 
)

Generator for '#omp single'.

Parameters
LocThe source location description.
BodyGenCBCallback that will generate the region code.
FiniCBCallback to finalize variable copies.
IsNowaitIf false, a barrier is emitted.
DidItLocal variable used as a flag to indicate 'single' thread
Returns
The insertion position after the single call.

Definition at line 3475 of file OMPIRBuilder.cpp.

References Builder, createBarrier(), llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateStore(), llvm::OpenMPIRBuilder::LocationDescription::DL, llvm::IRBuilderBase::getInt32(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::OpenMPIRBuilder::LocationDescription::IP, llvm::IRBuilderBase::saveIP(), and updateToLocation().

◆ createTarget()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTarget ( const LocationDescription Loc,
OpenMPIRBuilder::InsertPointTy  CodeGenIP,
TargetRegionEntryInfo EntryInfo,
int32_t  NumTeams,
int32_t  NumThreads,
SmallVectorImpl< Value * > &  Inputs,
TargetBodyGenCallbackTy  BodyGenCB 
)

Generator for '#omp target'.

Parameters
Locwhere the target data construct was encountered.
CodeGenIPThe insertion point where the call to the outlined function should be emitted.
EntryInfoThe entry information about the function.
NumTeamsNumber of teams specified in the num_teams clause.
NumThreadsNumber of teams specified in the thread_limit clause.
InputsThe input values to the region that will be passed. as arguments to the outlined function.
BodyGenCBCallback that will generate the region code.

Definition at line 4226 of file OMPIRBuilder.cpp.

References Builder, Config, emitTargetCall(), emitTargetOutlinedFunction(), llvm::OpenMPIRBuilderConfig::isEmbedded(), llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::saveIP(), and updateToLocation().

◆ createTargetData()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetData ( const LocationDescription Loc,
OpenMPIRBuilder::InsertPointTy  CodeGenIP,
SmallVectorImpl< uint64_t > &  MapTypeFlags,
SmallVectorImpl< Constant * > &  MapNames,
struct MapperAllocas MapperAllocas,
bool  IsBegin,
int64_t  DeviceID,
Value IfCond,
BodyGenCallbackTy  ProcessMapOpCB,
BodyGenCallbackTy  BodyGenCB = {} 
)

Generator for '#omp target data'.

Parameters
LocThe location where the target data construct was encountered.
CodeGenIPThe insertion point at which the target directive code should be placed.
MapTypeFlagsBitVector storing the mapType flags for the mapOperands.
MapNamesNames for the mapOperands.
MapperAllocasPointers to the AllocInsts for the map clause.
IsBeginIf true then emits begin mapper call otherwise emits end mapper call.
DeviceIDStores the DeviceID from the device clause.
IfCondValue which corresponds to the if clause condition.
ProcessMapOpCBCallback that generates code for the map clause.
BodyGenCBCallback that will generate the region code.

Definition at line 4079 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateConstInBoundsGEP2_32(), createOffloadMapnames(), createOffloadMaptypes(), llvm::IRBuilderBase::CreateUnreachable(), emitMapperCall(), llvm::ArrayType::get(), llvm::IRBuilderBase::getInt64Ty(), llvm::IRBuilderBase::getInt8PtrTy(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), llvm::SmallVectorBase< Size_T >::size(), llvm::SplitBlockAndInsertIfThen(), and updateToLocation().

◆ createTargetDeinit()

void OpenMPIRBuilder::createTargetDeinit ( const LocationDescription Loc,
bool  IsSPMD 
)

Create a runtime call for kmpc_target_deinit.

Parameters
LocThe insert and source location description.
IsSPMDFlag to indicate if the kernel is an SPMD kernel or not.

Definition at line 3977 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), llvm::Type::getInt8Ty(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), llvm::ConstantInt::getSigned(), llvm::omp::OMP_TGT_EXEC_MODE_GENERIC, llvm::omp::OMP_TGT_EXEC_MODE_SPMD, and updateToLocation().

Referenced by createOutlinedFunction().

◆ createTargetInit()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit ( const LocationDescription Loc,
bool  IsSPMD 
)

◆ createTask()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTask ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
BodyGenCallbackTy  BodyGenCB,
bool  Tied = true,
Value Final = nullptr,
Value IfCondition = nullptr,
SmallVector< DependData Dependencies = {} 
)

Generator for #omp task

Parameters
LocThe location where the task construct was encountered.
AllocaIPThe insertion point to be used for alloca instructions.
BodyGenCBCallback that will generate the region code.
TiedTrue if the task is tied, false if the task is untied.
Finali1 value which is true if the task is final, false if the task is not final.
IfConditioni1 value. If it evaluates to false, an undeferred task is generated, and the encountering thread must suspend the current task region, for which execution cannot be resumed until execution of the structured block that is associated with the generated task is completed.

Definition at line 1322 of file OMPIRBuilder.cpp.

References addOutlineInfo(), Addr, llvm::CallBase::arg_size(), assert(), llvm::BasicBlock::back(), llvm::sampleprof::Base, llvm::BasicBlock::begin(), Builder, llvm::BasicBlock::Create(), llvm::IRBuilderBase::CreateAlloca(), llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateConstInBoundsGEP2_64(), llvm::IRBuilderBase::CreateMemCpy(), llvm::IRBuilderBase::CreateOr(), llvm::IRBuilderBase::CreatePtrToInt(), llvm::IRBuilderBase::CreateRet(), llvm::IRBuilderBase::CreateSelect(), llvm::IRBuilderBase::CreateStore(), llvm::IRBuilderBase::CreateStructGEP(), llvm::OpenMPIRBuilder::OutlineInfo::EntryBB, llvm::Instruction::eraseFromParent(), llvm::OpenMPIRBuilder::OutlineInfo::ExitBB, Flags, llvm::ConstantPointerNull::get(), llvm::ArrayType::get(), llvm::FunctionType::get(), llvm::ConstantInt::get(), llvm::AllocaInst::getAllocatedType(), llvm::Function::getArg(), llvm::CallBase::getArgOperand(), llvm::ConstantExpr::getBitCast(), llvm::IRBuilderBase::InsertPoint::getBlock(), llvm::FunctionCallee::getCallee(), llvm::Module::getContext(), llvm::Module::getDataLayout(), llvm::Function::getEntryBlock(), llvm::IRBuilderBase::getInt32(), llvm::IRBuilderBase::getInt32Ty(), llvm::IRBuilderBase::getInt64(), llvm::IRBuilderBase::getInt64Ty(), llvm::Type::getInt8PtrTy(), llvm::IRBuilderBase::getInt8PtrTy(), llvm::IRBuilderBase::getInt8Ty(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::Module::getOrInsertFunction(), llvm::BasicBlock::getParent(), llvm::Value::getPointerAlignment(), llvm::Type::getPointerTo(), llvm::BasicBlock::getSinglePredecessor(), llvm::BasicBlock::getTerminator(), llvm::DataLayout::getTypeStoreSize(), M, llvm::OpenMPIRBuilder::OutlineInfo::OuterAllocaBB, P, llvm::OpenMPIRBuilder::OutlineInfo::PostOutlineCB, llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), llvm::SmallVectorBase< Size_T >::size(), Size, llvm::splitBB(), llvm::SplitBlockAndInsertIfThenElse(), and updateToLocation().

◆ createTaskgroup()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTaskgroup ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
BodyGenCallbackTy  BodyGenCB 
)

Generator for the taskgroup construct.

Parameters
LocThe location where the taskgroup construct was encountered.
AllocaIPThe insertion point to be used for alloca instructions.
BodyGenCBCallback that will generate the region code.

Definition at line 1590 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), llvm::IRBuilderBase::saveIP(), llvm::IRBuilderBase::SetInsertPoint(), llvm::splitBB(), and updateToLocation().

◆ createTaskwait()

void OpenMPIRBuilder::createTaskwait ( const LocationDescription Loc)

Generator for '#omp taskwait'.

Parameters
LocThe location where the taskwait directive was encountered.

Definition at line 1297 of file OMPIRBuilder.cpp.

References emitTaskwaitImpl(), and updateToLocation().

◆ createTaskyield()

void OpenMPIRBuilder::createTaskyield ( const LocationDescription Loc)

Generator for '#omp taskyield'.

Parameters
LocThe location where the taskyield directive was encountered.

Definition at line 1315 of file OMPIRBuilder.cpp.

References emitTaskyieldImpl(), and updateToLocation().

◆ emitBarrierImpl()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitBarrierImpl ( const LocationDescription Loc,
omp::Directive  DK,
bool  ForceSimpleCall,
bool  CheckCancelFlag 
)

Generate a barrier runtime call.

Parameters
LocThe location at which the request originated and is fulfilled.
DKThe directive which caused the barrier
ForceSimpleCallFlag to force a simple (=non-cancellation) barrier.
CheckCancelFlagFlag to indicate a cancel barrier return value should be checked and acted upon.
Returns
The insertion point after the barrier.

Definition at line 713 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), emitCancelationCheckImpl(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), isLastFinalizationInfoCancellable(), and llvm::IRBuilderBase::saveIP().

Referenced by createBarrier().

◆ emitCancelationCheckImpl()

void OpenMPIRBuilder::emitCancelationCheckImpl ( Value CancelFlag,
omp::Directive  CanceledDirective,
FinalizeCallbackTy  ExitCB = {} 
)

◆ emitFlush()

void OpenMPIRBuilder::emitFlush ( const LocationDescription Loc)

Generate a flush runtime call.

Parameters
LocThe location at which the request originated and is fulfilled.

Definition at line 1269 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), and getOrCreateSrcLocStr().

Referenced by createFlush().

◆ emitMapperCall()

void OpenMPIRBuilder::emitMapperCall ( const LocationDescription Loc,
Function MapperFunc,
Value SrcLocInfo,
Value MaptypesArg,
Value MapnamesArg,
struct MapperAllocas MapperAllocas,
int64_t  DeviceID,
unsigned  NumOperands 
)

Create the call for the target mapper function.

Parameters
LocThe source location description.
MapperFuncFunction to be called.
SrcLocInfoSource location information global.
MaptypesArgThe argument types.
MapnamesArgThe argument names.
MapperAllocasThe AllocaInst used for the call.
DeviceIDDevice ID for the call.
NumOperandsNumber of operands in the call.

Definition at line 4336 of file OMPIRBuilder.cpp.

References llvm::OpenMPIRBuilder::MapperAllocas::Args, llvm::OpenMPIRBuilder::MapperAllocas::ArgsBase, llvm::OpenMPIRBuilder::MapperAllocas::ArgSizes, Builder, llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateInBoundsGEP(), llvm::ArrayType::get(), llvm::IRBuilderBase::getInt32(), llvm::IRBuilderBase::getInt64(), llvm::Constant::getNullValue(), Int64, and updateToLocation().

Referenced by createTargetData().

◆ emitOffloadingArraysArgument()

void OpenMPIRBuilder::emitOffloadingArraysArgument ( IRBuilderBase Builder,
OpenMPIRBuilder::TargetDataRTArgs RTArgs,
OpenMPIRBuilder::TargetDataInfo Info,
bool  EmitDebug = false,
bool  ForEndCall = false 
)

◆ emitOffloadingEntry()

void OpenMPIRBuilder::emitOffloadingEntry ( Constant Addr,
StringRef  Name,
uint64_t  Size,
int32_t  Flags,
StringRef  SectionName = "omp_offloading_entries" 
)

Create an offloading section struct used to register this global at runtime.

Type struct __tgt_offload_entry{ void *addr; // Pointer to the offload entry info. // (function or global) char *name; // Name of the function or global. size_t size; // Size of the entry info (0 if it a function). int32_t flags; int32_t reserved; };

Parameters
AddrThe pointer to the global being registered.
NameThe symbol name associated with the global.
SizeThe size in bytes of the global (0 for functions).
FlagsFlags associated with the entry.
SectionNameThe section this entry will be placed at.

Definition at line 813 of file OMPIRBuilder.cpp.

References Addr, Flags, llvm::ConstantStruct::get(), llvm::ConstantInt::get(), llvm::Module::getContext(), llvm::Module::getDataLayout(), llvm::DataLayout::getDefaultGlobalsAddressSpace(), llvm::Type::getInt32Ty(), llvm::Type::getInt8PtrTy(), llvm::DataLayout::getIntPtrType(), llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(), llvm::ConstantDataArray::getString(), llvm::Value::getType(), llvm::GlobalValue::Global, Int32Ty, llvm::GlobalValue::InternalLinkage, M, Name, llvm::GlobalValue::NotThreadLocal, Size, and llvm::GlobalValue::WeakAnyLinkage.

Referenced by createOffloadEntry().

◆ emitTargetKernel()

OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetKernel ( const LocationDescription Loc,
InsertPointTy  AllocaIP,
Value *&  Return,
Value Ident,
Value DeviceID,
Value NumTeams,
Value NumThreads,
Value HostPtr,
ArrayRef< Value * >  KernelArgs 
)

Generate a target region entry call.

Parameters
LocThe location at which the request originated and is fulfilled.
AllocaIPThe insertion point to be used for alloca instructions.
ReturnReturn value of the created function returned by reference.
DeviceIDIdentifier for the device via the 'device' clause.
NumTeamsNumer of teams for the region via the 'num_teams' clause or 0 if unspecified and -1 if there is no 'teams' clause.
NumThreadsNumber of threads via the 'thread_limit' clause.
HostPtrPointer to the host-side pointer of the target kernel.
KernelArgsArray of arguments to the kernel.

Definition at line 851 of file OMPIRBuilder.cpp.

References Arg, Builder, llvm::IRBuilderBase::CreateAlignedStore(), llvm::IRBuilderBase::CreateAlloca(), llvm::IRBuilderBase::CreateCall(), llvm::IRBuilderBase::CreateStructGEP(), llvm::Module::getDataLayout(), getOrCreateRuntimeFunction(), llvm::DataLayout::getPrefTypeAlign(), I, llvm::OpenMPIRBuilder::LocationDescription::IP, M, llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::saveIP(), llvm::ArrayRef< T >::size(), Size, and updateToLocation().

◆ emitTargetRegionFunction()

void OpenMPIRBuilder::emitTargetRegionFunction ( TargetRegionEntryInfo EntryInfo,
FunctionGenCallback GenerateFunctionCallback,
int32_t  NumTeams,
int32_t  NumThreads,
bool  IsOffloadEntry,
Function *&  OutlinedFn,
Constant *&  OutlinedFnID 
)

Create a unique name for the entry function using the source location information of the current target region.

The name will be something like:

__omp_offloading_DD_FFFF_PP_lBB[_CC]

where DD_FFFF is an ID unique to the file (device and file IDs), PP is the mangled name of the function that encloses the target region and BB is the line number of the target region. CC is a count added when more than one region is located at the same location.

If this target outline function is not an offload entry, we don't need to register it. This may happen if it is guarded by an if clause that is false at compile time, or no target archs have been specified.

The created target region ID is used by the runtime library to identify the current target region, so it only has to be unique and not necessarily point to anything. It could be the pointer to the outlined function that implements the target region, but we aren't using that so that the compiler doesn't need to keep that, and could therefore inline the host function if proven worthwhile during optimization. In the other hand, if emitting code for the device, the ID has to be the function address so that it can retrieved from the offloading entry and launched by the runtime library. We also mark the outlined function to have external linkage in case we are emitting code for the device, because these functions will be entry points to the device.

Parameters
InfoManagerThe info manager keeping track of the offload entries
EntryInfoThe entry information about the function
GenerateFunctionCallbackThe callback function to generate the code
NumTeamsNumber default teams
NumThreadsNumber default threads
OutlinedFunctionPointer to the outlined function
EntryFnIDNameName of the ID o be created

Definition at line 4037 of file OMPIRBuilder.cpp.

References Config, createPlatformSpecificName(), llvm::OffloadEntriesInfoManager::getTargetRegionEntryFnName(), llvm::OpenMPIRBuilderConfig::isEmbedded(), OffloadInfoManager, llvm::OpenMPIRBuilderConfig::openMPOffloadMandatory(), and registerTargetRegionFunction().

Referenced by emitTargetOutlinedFunction().

◆ emitTaskwaitImpl()

void OpenMPIRBuilder::emitTaskwaitImpl ( const LocationDescription Loc)

Generate a taskwait runtime call.

Parameters
LocThe location at which the request originated and is fulfilled.

Definition at line 1284 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), and getOrCreateThreadID().

Referenced by createTaskwait().

◆ emitTaskyieldImpl()

void OpenMPIRBuilder::emitTaskyieldImpl ( const LocationDescription Loc)

Generate a taskyield runtime call.

Parameters
LocThe location at which the request originated and is fulfilled.

Definition at line 1303 of file OMPIRBuilder.cpp.

References Builder, llvm::IRBuilderBase::CreateCall(), llvm::Constant::getNullValue(), getOrCreateIdent(), getOrCreateRuntimeFunctionPtr(), getOrCreateSrcLocStr(), getOrCreateThreadID(), and Int32.

Referenced by createTaskyield().

◆ finalize()

void OpenMPIRBuilder::finalize ( Function Fn = nullptr)

◆ getInsertionPoint()

InsertPointTy llvm::OpenMPIRBuilder::getInsertionPoint ( )
inline

}

Return the insertion point used by the underlying IRBuilder.

Definition at line 1164 of file OMPIRBuilder.h.

References Builder, and llvm::IRBuilderBase::saveIP().

◆ getOpenMPDefaultSimdAlign()

unsigned OpenMPIRBuilder::getOpenMPDefaultSimdAlign ( const Triple TargetTriple,
const StringMap< bool > &  Features 
)
static

Get the default alignment value for given target.

Parameters
TargetTripleTarget triple
FeaturesStringMap which describes extra CPU features

Definition at line 3096 of file OMPIRBuilder.cpp.

References llvm::Triple::isPPC(), llvm::Triple::isWasm(), llvm::Triple::isX86(), and llvm::StringMap< ValueTy, AllocatorTy >::lookup().

◆ getOrCreateDefaultSrcLocStr()

Constant * OpenMPIRBuilder::getOrCreateDefaultSrcLocStr ( uint32_t SrcLocStrSize)

Return the (LLVM-IR) string describing the default source location.

Definition at line 670 of file OMPIRBuilder.cpp.

References getOrCreateSrcLocStr().

Referenced by getOrCreateSrcLocStr().

◆ getOrCreateIdent()

Constant * OpenMPIRBuilder::getOrCreateIdent ( Constant SrcLocStr,
uint32_t  SrcLocStrSize,
omp::IdentFlag  Flags = omp::IdentFlag(0),
unsigned  Reserve2Flags = 0 
)

◆ getOrCreateInternalVariable()

GlobalVariable * OpenMPIRBuilder::getOrCreateInternalVariable ( Type Ty,
const StringRef Name,
unsigned  AddressSpace = 0 
)

Gets (if variable with the given name already exist) or creates internal global variable with the specified Name.

The created variable has linkage CommonLinkage by default and is initialized by null value.

Parameters
TyType of the global variable. If it is exist already the type must be the same.
NameName of the variable.

Definition at line 4263 of file OMPIRBuilder.cpp.

References assert(), llvm::GlobalValue::CommonLinkage, llvm::DataLayout::getABITypeAlign(), llvm::Module::getDataLayout(), llvm::Constant::getNullValue(), InternalVars, M, Name, and llvm::GlobalValue::NotThreadLocal.

Referenced by createCachedThreadPrivate().

◆ getOrCreateRuntimeFunction()

FunctionCallee OpenMPIRBuilder::getOrCreateRuntimeFunction ( Module M,
omp::RuntimeFunction  FnID 
)

◆ getOrCreateRuntimeFunctionPtr()

Function * OpenMPIRBuilder::getOrCreateRuntimeFunctionPtr ( omp::RuntimeFunction  FnID)

◆ getOrCreateSrcLocStr() [1/4]

Constant * OpenMPIRBuilder::getOrCreateSrcLocStr ( const LocationDescription Loc,
uint32_t SrcLocStrSize 
)

◆ getOrCreateSrcLocStr() [2/4]

Constant * OpenMPIRBuilder::getOrCreateSrcLocStr ( DebugLoc  DL,
uint32_t SrcLocStrSize,
Function F = nullptr 
)

Return the (LLVM-IR) string describing the DebugLoc DL.

Use F as fallback if DL does not specify the function name.

Definition at line 675 of file OMPIRBuilder.cpp.

References DL, llvm::Function::empty(), F, llvm::Module::getName(), getOrCreateDefaultSrcLocStr(), getOrCreateSrcLocStr(), and M.

◆ getOrCreateSrcLocStr() [3/4]

Constant * OpenMPIRBuilder::getOrCreateSrcLocStr ( StringRef  FunctionName,
StringRef  FileName,
unsigned  Line,
unsigned  Column,
uint32_t SrcLocStrSize 
)

Return the (LLVM-IR) string describing the source location identified by the arguments.

Definition at line 651 of file OMPIRBuilder.cpp.

References llvm::SmallString< InternalLen >::append(), getOrCreateSrcLocStr(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::SmallString< InternalLen >::str().

◆ getOrCreateSrcLocStr() [4/4]

Constant * OpenMPIRBuilder::getOrCreateSrcLocStr ( StringRef  LocStr,
uint32_t SrcLocStrSize 
)

◆ getOrCreateThreadID()

Value * OpenMPIRBuilder::getOrCreateThreadID ( Value Ident)

◆ getSizeInBytes()

Value * OpenMPIRBuilder::getSizeInBytes ( Value BasePtr)

◆ initialize()

void OpenMPIRBuilder::initialize ( StringRef  HostFilePath = {})

Initialize the internal state, this will put structures types and potentially other helpers into the underlying module.

Must be called before any other method and only once! This internal state includes Types used in the OpenMPIRBuilder generated from OMPKinds.def as well as loading offload metadata for device from the OpenMP host IR file passed in as the HostFilePath argument.

Parameters
HostFilePathThe path to the host IR file, used to load in offload metadata for the device, allowing host and device to maintain the same metadata mapping.

Definition at line 449 of file OMPIRBuilder.cpp.

References llvm::StringRef::empty(), llvm::expectedToErrorOrAndEmitErrors(), llvm::MemoryBuffer::getFile(), loadOffloadInfoMetadata(), M, llvm::parseBitcodeFile(), and llvm::report_fatal_error().

◆ isLastFinalizationInfoCancellable()

bool llvm::OpenMPIRBuilder::isLastFinalizationInfoCancellable ( omp::Directive  DK)
inline

Return true if the last entry in the finalization stack is of kind DK and cancellable.

Definition at line 1282 of file OMPIRBuilder.h.

References FinalizationStack.

Referenced by emitBarrierImpl(), and emitCancelationCheckImpl().

◆ loadOffloadInfoMetadata()

void OpenMPIRBuilder::loadOffloadInfoMetadata ( Module M)

◆ popFinalizationCB()

void llvm::OpenMPIRBuilder::popFinalizationCB ( )
inline

Pop the last finalization callback from the finalization stack.

NOTE: Temporary solution until Clang CG is gone.

Definition at line 486 of file OMPIRBuilder.h.

References FinalizationStack.

◆ pushFinalizationCB()

void llvm::OpenMPIRBuilder::pushFinalizationCB ( const FinalizationInfo FI)
inline

Push a finalization callback on the finalization stack.

NOTE: Temporary solution until Clang CG is gone.

Definition at line 479 of file OMPIRBuilder.h.

References FinalizationStack.

◆ registerTargetRegionFunction()

Constant * OpenMPIRBuilder::registerTargetRegionFunction ( TargetRegionEntryInfo EntryInfo,
Function OutlinedFunction,
StringRef  EntryFnName,
StringRef  EntryFnIDName,
int32_t  NumTeams,
int32_t  NumThreads 
)

Registers the given function and sets up the attribtues of the function Returns the FunctionID.

Parameters
InfoManagerThe info manager keeping track of the offload entries
EntryInfoThe entry information about the function
OutlinedFunctionPointer to the outlined function
EntryFnNameName of the outlined function
EntryFnIDNameName of the ID o be created
NumTeamsNumber default teams
NumThreadsNumber default threads

Definition at line 4065 of file OMPIRBuilder.cpp.

References OffloadInfoManager, llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryTargetRegion, and llvm::OffloadEntriesInfoManager::registerTargetRegionEntryInfo().

Referenced by emitTargetRegionFunction().

◆ setConfig()

void llvm::OpenMPIRBuilder::setConfig ( OpenMPIRBuilderConfig  C)
inline

Definition at line 430 of file OMPIRBuilder.h.

References llvm::CallingConv::C, and Config.

◆ tileLoops()

std::vector< CanonicalLoopInfo * > OpenMPIRBuilder::tileLoops ( DebugLoc  DL,
ArrayRef< CanonicalLoopInfo * >  Loops,
ArrayRef< Value * >  TileSizes 
)

Tile a loop nest.

Tiles the loops of Loops by the tile sizes in TileSizes. Loops in / Loops must be perfectly nested, from outermost to innermost loop (i.e. Loops.front() is the outermost loop). The trip count llvm::Value of every loop and every tile sizes must be usable in the outermost loop's preheader. This implies that the loop nest is rectangular.

Example:

for (int i = 0; i < 15; ++i) // Canonical loop "i"
for (int j = 0; j < 14; ++j) // Canonical loop "j"
body(i, j);

After tiling with Loops={i,j} and TileSizes={5,7}, the loop is changed to

for (int i1 = 0; i1 < 3; ++i1)
for (int j1 = 0; j1 < 2; ++j1)
for (int i2 = 0; i2 < 5; ++i2)
for (int j2 = 0; j2 < 7; ++j2)
body(i1*3+i2, j1*3+j2);

The returned vector are the loops {i1,j1,i2,j2}. The loops i1 and j1 are referred to the floor, and the loops i2 and j2 are the tiles. Tiling also handles non-constant trip counts, non-constant tile sizes and trip counts that are not multiples of the tile size. In the latter case the tile loop of the last floor-loop iteration will have fewer iterations than specified as its tile size.

Parameters
DLDebug location for instructions added by tiling, for instance the floor- and tile trip count computation.
LoopsLoops to tile. The CanonicalLoopInfo objects are invalidated by this method, i.e. should not used after tiling.
TileSizesFor each loop in Loops, the tile size for that dimensions.
Returns
A list of generated loops. Contains twice as many loops as the input loop nest; the first half are the floor loops and the second half are the tile loops.

Definition at line 2780 of file OMPIRBuilder.cpp.

References assert(), Builder, llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateICmpEQ(), llvm::IRBuilderBase::CreateICmpNE(), createLoopSkeleton(), llvm::IRBuilderBase::CreateMul(), llvm::IRBuilderBase::CreateSelect(), llvm::IRBuilderBase::CreateUDiv(), llvm::IRBuilderBase::CreateURem(), llvm::IRBuilderBase::CreateZExt(), DL, llvm::SmallVectorImpl< T >::emplace_back(), llvm::enumerate(), F, llvm::ConstantInt::get(), llvm::CanonicalLoopInfo::getAfter(), llvm::CanonicalLoopInfo::getBody(), llvm::CanonicalLoopInfo::getExit(), llvm::CanonicalLoopInfo::getIndVar(), llvm::CanonicalLoopInfo::getLatch(), llvm::BasicBlock::getParent(), llvm::CanonicalLoopInfo::getPreheader(), llvm::CanonicalLoopInfo::getPreheaderIP(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), Loops, Name, P, llvm::SmallVectorTemplateBase< T, bool >::push_back(), redirectAllPredecessorsTo(), redirectTo(), removeUnusedBlocksFromParent(), llvm::Value::replaceAllUsesWith(), llvm::SmallVectorImpl< T >::reserve(), llvm::IRBuilderBase::restoreIP(), llvm::IRBuilderBase::SetCurrentDebugLocation(), llvm::IRBuilderBase::SetInsertPoint(), llvm::ArrayRef< T >::size(), Size, and TileSize.

Referenced by unrollLoopPartial().

◆ unrollLoopFull()

void OpenMPIRBuilder::unrollLoopFull ( DebugLoc  DL,
CanonicalLoopInfo Loop 
)

Fully unroll a loop.

Instead of unrolling the loop immediately (and duplicating its body instructions), it is deferred to LLVM's LoopUnrollPass by adding loop metadata.

Parameters
DLDebug location for instructions added by unrolling.
LoopThe loop to unroll. The loop will be invalidated.

Definition at line 3019 of file OMPIRBuilder.cpp.

References addLoopMetadata(), Builder, llvm::MDNode::get(), llvm::MDString::get(), and llvm::IRBuilderBase::getContext().

◆ unrollLoopHeuristic()

void OpenMPIRBuilder::unrollLoopHeuristic ( DebugLoc  DL,
CanonicalLoopInfo Loop 
)

Fully or partially unroll a loop.

How the loop is unrolled is determined using LLVM's LoopUnrollPass.

Parameters
DLDebug location for instructions added by unrolling.
LoopThe loop to unroll. The loop will be invalidated.

Definition at line 3026 of file OMPIRBuilder.cpp.

References addLoopMetadata(), Builder, llvm::MDNode::get(), llvm::MDString::get(), and llvm::IRBuilderBase::getContext().

◆ unrollLoopPartial()

void OpenMPIRBuilder::unrollLoopPartial ( DebugLoc  DL,
CanonicalLoopInfo Loop,
int32_t  Factor,
CanonicalLoopInfo **  UnrolledCLI 
)

Partially unroll a loop.

The CanonicalLoopInfo of the unrolled loop for use with chained loop-associated directive can be requested using UnrolledCLI. Not needing the CanonicalLoopInfo allows more efficient code generation by deferring the actual unrolling to the LoopUnrollPass using loop metadata. A loop-associated directive applied to the unrolled loop needs to know the new trip count which means that if using a heuristically determined unroll factor (Factor == 0), that factor must be computed immediately. We are using the same logic as the LoopUnrollPass to derived the unroll factor, but which assumes that some canonicalization has taken place (e.g. Mem2Reg, LICM, GVN, Inlining, etc.). That is, the heuristic will perform better when the unrolled loop's CanonicalLoopInfo is not needed.

Parameters
DLDebug location for instructions added by unrolling.
LoopThe loop to unroll. The loop will be invalidated.
FactorThe factor to unroll the loop by. A factor of 0 indicates that a heuristic should be used to determine the unroll-factor.
UnrolledCLIIf non-null, receives the CanonicalLoopInfo of the partially unrolled loop. Otherwise, uses loop metadata to defer unrolling to the LoopUnrollPass.

Definition at line 3385 of file OMPIRBuilder.cpp.

References addLoopMetadata(), assert(), computeHeuristicUnrollFactor(), DL, F, llvm::ConstantAsMetadata::get(), llvm::MDNode::get(), llvm::MDString::get(), llvm::ConstantInt::get(), llvm::Type::getInt32Ty(), llvm::Type::getIntegerBitWidth(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and tileLoops().

◆ updateToLocation()

bool llvm::OpenMPIRBuilder::updateToLocation ( const LocationDescription Loc)
inline

Member Data Documentation

◆ Builder

IRBuilder llvm::OpenMPIRBuilder::Builder

◆ Config

OpenMPIRBuilderConfig llvm::OpenMPIRBuilder::Config

◆ FinalizationStack

SmallVector<FinalizationInfo, 8> llvm::OpenMPIRBuilder::FinalizationStack

The finalization stack made up of finalize callbacks currently in-flight, wrapped into FinalizationInfo objects that reference also the finalization target block and the kind of cancellable directive.

Definition at line 1278 of file OMPIRBuilder.h.

Referenced by createParallel(), createSections(), emitCancelationCheckImpl(), isLastFinalizationInfoCancellable(), popFinalizationCB(), and pushFinalizationCB().

◆ IdentMap

DenseMap<std::pair<Constant *, uint64_t>, Constant *> llvm::OpenMPIRBuilder::IdentMap

Map to remember existing ident_t*.

Definition at line 1316 of file OMPIRBuilder.h.

Referenced by getOrCreateIdent().

◆ InternalVars

StringMap<Constant*, BumpPtrAllocator> llvm::OpenMPIRBuilder::InternalVars

An ordered map of auto-generated variables to their unique names.

It stores variables with the following names: 1) ".gomp_critical_user_" + <critical_section_name> + ".var" for "omp critical" directives; 2) <mangled_name_for_global_var> + ".cache." for cache for threadprivate variables.

Definition at line 1353 of file OMPIRBuilder.h.

Referenced by getOrCreateInternalVariable().

◆ LoopInfos

std::forward_list<CanonicalLoopInfo> llvm::OpenMPIRBuilder::LoopInfos

Collection of owned canonical loop objects that eventually need to be free'd.

Definition at line 1343 of file OMPIRBuilder.h.

Referenced by createLoopSkeleton().

◆ M

Module& llvm::OpenMPIRBuilder::M

◆ OffloadInfoManager

OffloadEntriesInfoManager llvm::OpenMPIRBuilder::OffloadInfoManager

Info manager to keep track of target regions.

Definition at line 1319 of file OMPIRBuilder.h.

Referenced by createOffloadEntriesAndInfoMetadata(), emitTargetRegionFunction(), finalize(), loadOffloadInfoMetadata(), and registerTargetRegionFunction().

◆ ompOffloadInfoName

const std::string llvm::OpenMPIRBuilder::ompOffloadInfoName = "omp_offload.info"

OMP Offload Info Metadata name string.

Definition at line 2229 of file OMPIRBuilder.h.

Referenced by loadOffloadInfoMetadata().

◆ OutlineInfos

SmallVector<OutlineInfo, 16> llvm::OpenMPIRBuilder::OutlineInfos

Collection of regions that need to be outlined during finalization.

Definition at line 1339 of file OMPIRBuilder.h.

Referenced by addOutlineInfo(), finalize(), and ~OpenMPIRBuilder().

◆ SrcLocStrMap

StringMap<Constant *> llvm::OpenMPIRBuilder::SrcLocStrMap

Map to remember source location strings.

Definition at line 1313 of file OMPIRBuilder.h.

Referenced by getOrCreateSrcLocStr().


The documentation for this class was generated from the following files: