LLVM 22.0.0git
OMPIRBuilder.cpp File Reference

This file implements the OpenMPIRBuilder class, which is used as a convenient way to create LLVM instructions for OpenMP directives. More...

#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/CodeMetrics.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Frontend/Offloading/Utility.h"
#include "llvm/Frontend/OpenMP/OMPGridValues.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/PassInstrumentation.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/ReplaceConstant.h"
#include "llvm/IR/Value.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/CodeExtractor.h"
#include "llvm/Transforms/Utils/LoopPeel.h"
#include "llvm/Transforms/Utils/UnrollLoop.h"
#include <cstdint>
#include <optional>
#include "llvm/Frontend/OpenMP/OMPKinds.def"

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "openmp-ir-builder"
#define OMP_ATTRS_SET(VarName, AttrSet)
#define OMP_RTL_ATTRS(Enum, FnAttrSet, RetAttrSet, ArgAttrSets)
#define OMP_RTL(Enum, Str, IsVarArg, ReturnType, ...)
#define OMP_RTL(Enum, Str, ...)
#define OMP_CANCEL_KIND(Enum, Str, DirectiveEnum, Value)
#define OMP_CANCEL_KIND(Enum, Str, DirectiveEnum, Value)
#define OMP_TYPE(VarName, InitValue)
#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize)
#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...)
#define OMP_STRUCT_TYPE(VarName, StructName, Packed, ...)

Functions

static bool isConflictIP (IRBuilder<>::InsertPoint IP1, IRBuilder<>::InsertPoint IP2)
 Return whether IP1 and IP2 are ambiguous, i.e.
static bool isValidWorkshareLoopScheduleType (OMPScheduleType SchedType)
static void restoreIPandDebugLoc (llvm::IRBuilderBase &Builder, llvm::IRBuilderBase::InsertPoint IP)
 This is wrapper over IRBuilderBase::restoreIP that also restores the current debug location to the last instruction in the specified basic block if the insert point points to the end of the block.
static const omp::GVgetGridValue (const Triple &T, Function *Kernel)
static OMPScheduleType getOpenMPBaseScheduleType (llvm::omp::ScheduleKind ClauseKind, bool HasChunks, bool HasSimdModifier)
 Determine which scheduling algorithm to use, determined from schedule clause arguments.
static OMPScheduleType getOpenMPOrderingScheduleType (OMPScheduleType BaseScheduleType, bool HasOrderedClause)
 Adds ordering modifier flags to schedule type.
static OMPScheduleType getOpenMPMonotonicityScheduleType (OMPScheduleType ScheduleType, bool HasSimdModifier, bool HasMonotonic, bool HasNonmonotonic, bool HasOrderedClause)
 Adds monotonicity modifier flags to schedule type.
static OMPScheduleType computeOpenMPScheduleType (ScheduleKind ClauseKind, bool HasChunks, bool HasSimdModifier, bool HasMonotonicModifier, bool HasNonmonotonicModifier, bool HasOrderedClause)
 Determine the schedule type using schedule and ordering clause arguments.
static void redirectTo (BasicBlock *Source, BasicBlock *Target, DebugLoc DL)
 Make Source branch to Target.
ValuecreateFakeIntVal (IRBuilderBase &Builder, OpenMPIRBuilder::InsertPointTy OuterAllocaIP, llvm::SmallVectorImpl< Instruction * > &ToBeDeleted, OpenMPIRBuilder::InsertPointTy InnerAllocaIP, const Twine &Name="", bool AsPtr=true)
static void raiseUserConstantDataAllocasToEntryBlock (IRBuilderBase &Builder, Function *Function)
static void targetParallelCallback (OpenMPIRBuilder *OMPIRBuilder, Function &OutlinedFn, Function *OuterFn, BasicBlock *OuterAllocaBB, Value *Ident, Value *IfCondition, Value *NumThreads, Instruction *PrivTID, AllocaInst *PrivTIDAddr, Value *ThreadID, const SmallVector< Instruction *, 4 > &ToBeDeleted)
static void hostParallelCallback (OpenMPIRBuilder *OMPIRBuilder, Function &OutlinedFn, Function *OuterFn, Value *Ident, Value *IfCondition, Instruction *PrivTID, AllocaInst *PrivTIDAddr, const SmallVector< Instruction *, 4 > &ToBeDeleted)
static ValueemitTaskDependencies (OpenMPIRBuilder &OMPBuilder, const SmallVectorImpl< OpenMPIRBuilder::DependData > &Dependencies)
static OpenMPIRBuilder::InsertPointTy getInsertPointAfterInstr (Instruction *I)
static void checkReductionInfos (ArrayRef< OpenMPIRBuilder::ReductionInfo > ReductionInfos, bool IsGPU)
static FunctiongetFreshReductionFunc (Module &M)
static Error populateReductionFunction (Function *ReductionFunc, ArrayRef< OpenMPIRBuilder::ReductionInfo > ReductionInfos, IRBuilder<> &Builder, ArrayRef< bool > IsByRef, bool IsGPU)
static llvm::CallInstemitNoUnwindRuntimeCall (IRBuilder<> &Builder, llvm::FunctionCallee Callee, ArrayRef< llvm::Value * > Args, const llvm::Twine &Name)
static FunctionCallee getKmpcDistForStaticInitForType (Type *Ty, Module &M, OpenMPIRBuilder &OMPBuilder)
static FunctionCallee getKmpcForStaticInitForType (Type *Ty, Module &M, OpenMPIRBuilder &OMPBuilder)
static FunctionCallee getKmpcForStaticLoopForType (Type *Ty, OpenMPIRBuilder *OMPBuilder, WorksharingLoopType LoopType)
static void createTargetLoopWorkshareCall (OpenMPIRBuilder *OMPBuilder, WorksharingLoopType LoopType, BasicBlock *InsertBlock, Value *Ident, Value *LoopBodyArg, Value *TripCount, Function &LoopBodyFn)
static void workshareLoopTargetCallback (OpenMPIRBuilder *OMPIRBuilder, CanonicalLoopInfo *CLI, Value *Ident, Function &OutlinedFn, const SmallVector< Instruction *, 4 > &ToBeDeleted, WorksharingLoopType LoopType)
static FunctionCallee getKmpcForDynamicInitForType (Type *Ty, Module &M, OpenMPIRBuilder &OMPBuilder)
 Returns an LLVM function to call for initializing loop bounds using OpenMP dynamic scheduling depending on type.
static FunctionCallee getKmpcForDynamicNextForType (Type *Ty, Module &M, OpenMPIRBuilder &OMPBuilder)
 Returns an LLVM function to call for updating the next loop using OpenMP dynamic scheduling depending on type.
static FunctionCallee getKmpcForDynamicFiniForType (Type *Ty, Module &M, OpenMPIRBuilder &OMPBuilder)
 Returns an LLVM function to call for finalizing the dynamic loop using depending on type.
static void redirectAllPredecessorsTo (BasicBlock *OldTarget, BasicBlock *NewTarget, DebugLoc DL)
 Redirect all edges that branch to OldTarget to NewTarget.
static void removeUnusedBlocksFromParent (ArrayRef< BasicBlock * > BBs)
 Determine which blocks in BBs are reachable from outside and remove the ones that are not reachable from the function.
static void addBasicBlockMetadata (BasicBlock *BB, ArrayRef< Metadata * > Properties)
 Attach metadata Properties to the basic block described by BB.
static void addLoopMetadata (CanonicalLoopInfo *Loop, ArrayRef< Metadata * > Properties)
 Attach loop metadata Properties to the loop described by Loop.
static void addSimdMetadata (BasicBlock *Block, MDNode *AccessGroup, LoopInfo &LI)
 Attach llvm.access.group metadata to the memref instructions of Block.
static std::unique_ptr< TargetMachinecreateTargetMachine (Function *F, CodeGenOptLevel OptLevel)
 Create the TargetMachine object to query the backend for optimization preferences.
static int32_t computeHeuristicUnrollFactor (CanonicalLoopInfo *CLI)
 Heuristically determine the best-performant unroll factor for CLI.
static void updateNVPTXAttr (Function &Kernel, StringRef Name, int32_t Value, bool Min)
static void FixupDebugInfoForOutlinedFunction (OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, Function *Func, DenseMap< Value *, std::tuple< Value *, unsigned > > &ValueReplacementMap)
static ValueremoveASCastIfPresent (Value *V)
static Expected< Function * > createOutlinedFunction (OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, const OpenMPIRBuilder::TargetKernelDefaultAttrs &DefaultAttrs, StringRef FuncName, SmallVectorImpl< Value * > &Inputs, OpenMPIRBuilder::TargetBodyGenCallbackTy &CBFunc, OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy &ArgAccessorFuncCB)
static LoadInstloadSharedDataFromTaskDescriptor (OpenMPIRBuilder &OMPIRBuilder, IRBuilderBase &Builder, Value *TaskWithPrivates, Type *TaskWithPrivatesTy)
 Given a task descriptor, TaskWithPrivates, return the pointer to the block of pointers containing shared data between the parent task and the created task.
static FunctionemitTargetTaskProxyFunction (OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, CallInst *StaleCI, StructType *PrivatesTy, StructType *TaskWithPrivatesTy, const size_t NumOffloadingArrays, const int SharedArgsOperandNo)
 Create an entry point for a target task with the following.
static TypegetOffloadingArrayType (Value *V)
static StructTypecreateTaskWithPrivatesTy (OpenMPIRBuilder &OMPIRBuilder, ArrayRef< Value * > OffloadingArraysToPrivatize)
static Error emitTargetOutlinedFunction (OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, bool IsOffloadEntry, TargetRegionEntryInfo &EntryInfo, const OpenMPIRBuilder::TargetKernelDefaultAttrs &DefaultAttrs, Function *&OutlinedFn, Constant *&OutlinedFnID, SmallVectorImpl< Value * > &Inputs, OpenMPIRBuilder::TargetBodyGenCallbackTy &CBFunc, OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy &ArgAccessorFuncCB)
static void emitTargetCall (OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, OpenMPIRBuilder::InsertPointTy AllocaIP, OpenMPIRBuilder::TargetDataInfo &Info, const OpenMPIRBuilder::TargetKernelDefaultAttrs &DefaultAttrs, const OpenMPIRBuilder::TargetKernelRuntimeAttrs &RuntimeAttrs, Value *IfCond, Function *OutlinedFn, Constant *OutlinedFnID, SmallVectorImpl< Value * > &Args, OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB, OpenMPIRBuilder::CustomMapperCallbackTy CustomMapperCB, const SmallVector< llvm::OpenMPIRBuilder::DependData > &Dependencies, bool HasNoWait)

Variables

static cl::opt< boolOptimisticAttributes ("openmp-ir-builder-optimistic-attributes", cl::Hidden, cl::desc("Use optimistic attributes describing " "'as-if' properties of runtime calls."), cl::init(false))
static cl::opt< double > UnrollThresholdFactor ("openmp-ir-builder-unroll-threshold-factor", cl::Hidden, cl::desc("Factor for the unroll threshold to account for code " "simplifications still taking place"), cl::init(1.5))

Detailed Description

This file implements the OpenMPIRBuilder class, which is used as a convenient way to create LLVM instructions for OpenMP directives.

Definition in file OMPIRBuilder.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "openmp-ir-builder"

Definition at line 65 of file OMPIRBuilder.cpp.

◆ OMP_ARRAY_TYPE

#define OMP_ARRAY_TYPE ( VarName,
ElemTy,
ArraySize )
Value:
VarName##Ty = ArrayType::get(ElemTy, ArraySize); \
VarName##PtrTy = PointerType::get(Ctx, DefaultTargetAS);

◆ OMP_ATTRS_SET

#define OMP_ATTRS_SET ( VarName,
AttrSet )
Value:
AttributeSet VarName = AttrSet;
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:361

◆ OMP_CANCEL_KIND [1/2]

#define OMP_CANCEL_KIND ( Enum,
Str,
DirectiveEnum,
Value )
Value:
case DirectiveEnum: \
CancelKind = Builder.getInt32(Value); \
break;
LLVM Value Representation.
Definition Value.h:75

◆ OMP_CANCEL_KIND [2/2]

#define OMP_CANCEL_KIND ( Enum,
Str,
DirectiveEnum,
Value )
Value:
case DirectiveEnum: \
CancelKind = Builder.getInt32(Value); \
break;

◆ OMP_FUNCTION_TYPE

#define OMP_FUNCTION_TYPE ( VarName,
IsVarArg,
ReturnType,
... )
Value:
VarName = FunctionType::get(ReturnType, {__VA_ARGS__}, IsVarArg); \
VarName##Ptr = PointerType::get(Ctx, DefaultTargetAS);

◆ OMP_RTL [1/2]

#define OMP_RTL ( Enum,
Str,
IsVarArg,
ReturnType,
... )
Value:
case Enum: \
FnTy = FunctionType::get(ReturnType, ArrayRef<Type *>{__VA_ARGS__}, \
IsVarArg); \
Fn = M.getFunction(Str); \
break;
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41

◆ OMP_RTL [2/2]

#define OMP_RTL ( Enum,
Str,
... )
Value:
case Enum: \
break;
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition Function.h:166
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53

◆ OMP_RTL_ATTRS

#define OMP_RTL_ATTRS ( Enum,
FnAttrSet,
RetAttrSet,
ArgAttrSets )
Value:
case Enum: \
FnAttrs = FnAttrs.addAttributes(Ctx, FnAttrSet); \
addAttrSet(RetAttrs, RetAttrSet, /*Param*/ false); \
for (size_t ArgNo = 0; ArgNo < ArgAttrSets.size(); ++ArgNo) \
addAttrSet(ArgAttrs[ArgNo], ArgAttrSets[ArgNo]); \
Fn.setAttributes(AttributeList::get(Ctx, FnAttrs, RetAttrs, ArgAttrs)); \
break;

◆ OMP_STRUCT_TYPE

#define OMP_STRUCT_TYPE ( VarName,
StructName,
Packed,
... )
Value:
if (!T) \
T = StructType::create(Ctx, {__VA_ARGS__}, StructName, Packed); \
VarName = T; \
VarName##Ptr = PointerType::get(Ctx, DefaultTargetAS);
const std::string FatArchTraits< MachO::fat_arch >::StructName
#define T
static LLVM_ABI StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
Definition Type.cpp:739
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition Type.cpp:620

◆ OMP_TYPE

#define OMP_TYPE ( VarName,
InitValue )
Value:
VarName = InitValue;

Function Documentation

◆ addBasicBlockMetadata()

void addBasicBlockMetadata ( BasicBlock * BB,
ArrayRef< Metadata * > Properties )
static

◆ addLoopMetadata()

void addLoopMetadata ( CanonicalLoopInfo * Loop,
ArrayRef< Metadata * > Properties )
static

Attach loop metadata Properties to the loop described by Loop.

If the loop already has metadata, the loop properties are appended.

Definition at line 5773 of file OMPIRBuilder.cpp.

References addBasicBlockMetadata(), and assert().

◆ addSimdMetadata()

void addSimdMetadata ( BasicBlock * Block,
MDNode * AccessGroup,
LoopInfo & LI )
static

Attach llvm.access.group metadata to the memref instructions of Block.

Definition at line 5784 of file OMPIRBuilder.cpp.

References llvm::Block, and I.

◆ checkReductionInfos()

void checkReductionInfos ( ArrayRef< OpenMPIRBuilder::ReductionInfo > ReductionInfos,
bool IsGPU )
static

Definition at line 3541 of file OMPIRBuilder.cpp.

References assert().

◆ computeHeuristicUnrollFactor()

◆ computeOpenMPScheduleType()

OMPScheduleType computeOpenMPScheduleType ( ScheduleKind ClauseKind,
bool HasChunks,
bool HasSimdModifier,
bool HasMonotonicModifier,
bool HasNonmonotonicModifier,
bool HasOrderedClause )
static

Determine the schedule type using schedule and ordering clause arguments.

Definition at line 268 of file OMPIRBuilder.cpp.

References assert(), getOpenMPBaseScheduleType(), getOpenMPMonotonicityScheduleType(), getOpenMPOrderingScheduleType(), and isValidWorkshareLoopScheduleType().

◆ createFakeIntVal()

Value * createFakeIntVal ( IRBuilderBase & Builder,
OpenMPIRBuilder::InsertPointTy OuterAllocaIP,
llvm::SmallVectorImpl< Instruction * > & ToBeDeleted,
OpenMPIRBuilder::InsertPointTy InnerAllocaIP,
const Twine & Name = "",
bool AsPtr = true )

◆ createOutlinedFunction()

◆ createTargetLoopWorkshareCall()

void createTargetLoopWorkshareCall ( OpenMPIRBuilder * OMPBuilder,
WorksharingLoopType LoopType,
BasicBlock * InsertBlock,
Value * Ident,
Value * LoopBodyArg,
Value * TripCount,
Function & LoopBodyFn )
static

◆ createTargetMachine()

std::unique_ptr< TargetMachine > createTargetMachine ( Function * F,
CodeGenOptLevel OptLevel )
static

Create the TargetMachine object to query the backend for optimization preferences.

Ideally, this would be passed from the front-end to the OpenMPBuilder, but e.g. Clang does not pass it to its CodeGen layer and creates it only when needed for the LLVM pass pipline. We use some default options to avoid having to pass too many settings from the frontend that probably do not matter.

Currently, TargetMachine is only used sometimes by the unrollLoopPartial method. If we are going to use TargetMachine for more purposes, especially those that are sensitive to TargetOptions, RelocModel and CodeModel, it might become be worth requiring front-ends to pass on their TargetMachine, or at least cache it between methods. Note that while fontends such as Clang have just a single main TargetMachine per translation unit, "target-cpu" and "target-features" that determine the TargetMachine are per-function and can be overrided using attribute((target("OPTIONS"))).

Definition at line 6032 of file OMPIRBuilder.cpp.

References llvm::Target::createTargetMachine(), F, llvm::TargetRegistry::lookupTarget(), and Options.

Referenced by llvm::lto::backend(), computeHeuristicUnrollFactor(), LLVMCreateTargetMachineWithOptions(), splitCodeGen(), and llvm::lto::thinBackend().

◆ createTaskWithPrivatesTy()

StructType * createTaskWithPrivatesTy ( OpenMPIRBuilder & OMPIRBuilder,
ArrayRef< Value * > OffloadingArraysToPrivatize )
static

◆ emitNoUnwindRuntimeCall()

llvm::CallInst * emitNoUnwindRuntimeCall ( IRBuilder<> & Builder,
llvm::FunctionCallee Callee,
ArrayRef< llvm::Value * > Args,
const llvm::Twine & Name )
static

Definition at line 4049 of file OMPIRBuilder.cpp.

References Call.

◆ emitTargetCall()

void emitTargetCall ( OpenMPIRBuilder & OMPBuilder,
IRBuilderBase & Builder,
OpenMPIRBuilder::InsertPointTy AllocaIP,
OpenMPIRBuilder::TargetDataInfo & Info,
const OpenMPIRBuilder::TargetKernelDefaultAttrs & DefaultAttrs,
const OpenMPIRBuilder::TargetKernelRuntimeAttrs & RuntimeAttrs,
Value * IfCond,
Function * OutlinedFn,
Constant * OutlinedFnID,
SmallVectorImpl< Value * > & Args,
OpenMPIRBuilder::GenMapInfoCallbackTy GenMapInfoCB,
OpenMPIRBuilder::CustomMapperCallbackTy CustomMapperCB,
const SmallVector< llvm::OpenMPIRBuilder::DependData > & Dependencies,
bool HasNoWait )
static

◆ emitTargetOutlinedFunction()

Error emitTargetOutlinedFunction ( OpenMPIRBuilder & OMPBuilder,
IRBuilderBase & Builder,
bool IsOffloadEntry,
TargetRegionEntryInfo & EntryInfo,
const OpenMPIRBuilder::TargetKernelDefaultAttrs & DefaultAttrs,
Function *& OutlinedFn,
Constant *& OutlinedFnID,
SmallVectorImpl< Value * > & Inputs,
OpenMPIRBuilder::TargetBodyGenCallbackTy & CBFunc,
OpenMPIRBuilder::TargetGenArgAccessorsCallbackTy & ArgAccessorFuncCB )
static

Definition at line 7790 of file OMPIRBuilder.cpp.

References createOutlinedFunction().

◆ emitTargetTaskProxyFunction()

Function * emitTargetTaskProxyFunction ( OpenMPIRBuilder & OMPBuilder,
IRBuilderBase & Builder,
CallInst * StaleCI,
StructType * PrivatesTy,
StructType * TaskWithPrivatesTy,
const size_t NumOffloadingArrays,
const int SharedArgsOperandNo )
static

Create an entry point for a target task with the following.

It'll have the following signature void .omp_target_task_proxy_func(i32 thread.id, ptr task) This function is called from emitTargetTask once the code to launch the target kernel has been outlined already. NumOffloadingArrays is the number of offloading arrays that we need to copy into the task structure so that the deferred target task can access this data even after the stack frame of the generating task has been rolled back. Offloading arrays contain base pointers, pointers, sizes etc of the data that the target kernel will access. These in effect are the non-empty arrays of pointers held by OpenMPIRBuilder::TargetDataRTArgs.

Definition at line 7641 of file OMPIRBuilder.cpp.

References llvm::CallBase::arg_size(), assert(), llvm::cast(), llvm::BasicBlock::Create(), llvm::Function::Create(), llvm::dyn_cast(), llvm::FunctionType::get(), llvm::AllocaInst::getAlign(), llvm::AllocaInst::getAllocatedType(), llvm::CallBase::getArgOperand(), llvm::CallBase::getCalledFunction(), llvm::Type::getInt32Ty(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::Value::getPointerAlignment(), llvm::GlobalValue::InternalLinkage, loadSharedDataFromTaskDescriptor(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), and llvm::Value::setName().

◆ emitTaskDependencies()

Value * emitTaskDependencies ( OpenMPIRBuilder & OMPBuilder,
const SmallVectorImpl< OpenMPIRBuilder::DependData > & Dependencies )
static

◆ FixupDebugInfoForOutlinedFunction()

◆ getFreshReductionFunc()

◆ getGridValue()

◆ getInsertPointAfterInstr()

OpenMPIRBuilder::InsertPointTy getInsertPointAfterInstr ( Instruction * I)
static

Definition at line 2374 of file OMPIRBuilder.cpp.

References I, and IT.

◆ getKmpcDistForStaticInitForType()

FunctionCallee getKmpcDistForStaticInitForType ( Type * Ty,
Module & M,
OpenMPIRBuilder & OMPBuilder )
static

Definition at line 4642 of file OMPIRBuilder.cpp.

References llvm_unreachable.

◆ getKmpcForDynamicFiniForType()

FunctionCallee getKmpcForDynamicFiniForType ( Type * Ty,
Module & M,
OpenMPIRBuilder & OMPBuilder )
static

Returns an LLVM function to call for finalizing the dynamic loop using depending on type.

Only i32 and i64 are supported by the runtime. Always interpret integers as unsigned similarly to CanonicalLoopInfo.

Definition at line 5252 of file OMPIRBuilder.cpp.

References llvm_unreachable.

◆ getKmpcForDynamicInitForType()

FunctionCallee getKmpcForDynamicInitForType ( Type * Ty,
Module & M,
OpenMPIRBuilder & OMPBuilder )
static

Returns an LLVM function to call for initializing loop bounds using OpenMP dynamic scheduling depending on type.

Only i32 and i64 are supported by the runtime. Always interpret integers as unsigned similarly to CanonicalLoopInfo.

Definition at line 5221 of file OMPIRBuilder.cpp.

References llvm_unreachable.

◆ getKmpcForDynamicNextForType()

FunctionCallee getKmpcForDynamicNextForType ( Type * Ty,
Module & M,
OpenMPIRBuilder & OMPBuilder )
static

Returns an LLVM function to call for updating the next loop using OpenMP dynamic scheduling depending on type.

Only i32 and i64 are supported by the runtime. Always interpret integers as unsigned similarly to CanonicalLoopInfo.

Definition at line 5237 of file OMPIRBuilder.cpp.

References llvm_unreachable.

◆ getKmpcForStaticInitForType()

FunctionCallee getKmpcForStaticInitForType ( Type * Ty,
Module & M,
OpenMPIRBuilder & OMPBuilder )
static

Definition at line 4658 of file OMPIRBuilder.cpp.

References llvm_unreachable.

◆ getKmpcForStaticLoopForType()

FunctionCallee getKmpcForStaticLoopForType ( Type * Ty,
OpenMPIRBuilder * OMPBuilder,
WorksharingLoopType LoopType )
static

Definition at line 4937 of file OMPIRBuilder.cpp.

References llvm_unreachable.

Referenced by createTargetLoopWorkshareCall().

◆ getOffloadingArrayType()

Type * getOffloadingArrayType ( Value * V)
static

Definition at line 7745 of file OMPIRBuilder.cpp.

References llvm::dyn_cast(), GEP, and llvm_unreachable.

Referenced by createTaskWithPrivatesTy().

◆ getOpenMPBaseScheduleType()

OMPScheduleType getOpenMPBaseScheduleType ( llvm::omp::ScheduleKind ClauseKind,
bool HasChunks,
bool HasSimdModifier )
static

Determine which scheduling algorithm to use, determined from schedule clause arguments.

Definition at line 184 of file OMPIRBuilder.cpp.

References llvm::omp::BaseAuto, and llvm_unreachable.

Referenced by computeOpenMPScheduleType().

◆ getOpenMPMonotonicityScheduleType()

OMPScheduleType getOpenMPMonotonicityScheduleType ( OMPScheduleType ScheduleType,
bool HasSimdModifier,
bool HasMonotonic,
bool HasNonmonotonic,
bool HasOrderedClause )
static

Adds monotonicity modifier flags to schedule type.

Definition at line 232 of file OMPIRBuilder.cpp.

References assert(), and llvm::omp::ModifierMask.

Referenced by computeOpenMPScheduleType().

◆ getOpenMPOrderingScheduleType()

OMPScheduleType getOpenMPOrderingScheduleType ( OMPScheduleType BaseScheduleType,
bool HasOrderedClause )
static

Adds ordering modifier flags to schedule type.

Definition at line 208 of file OMPIRBuilder.cpp.

References assert().

Referenced by computeOpenMPScheduleType().

◆ hostParallelCallback()

◆ isConflictIP()

bool isConflictIP ( IRBuilder<>::InsertPoint IP1,
IRBuilder<>::InsertPoint IP2 )
static

Return whether IP1 and IP2 are ambiguous, i.e.

that inserting instructions at position IP1 may change the meaning of IP2 or vice-versa. This is because an InsertPoint stores the instruction before something is inserted. For instance, if both point to the same instruction, two IRBuilders alternating creating instruction will cause the instructions to be interleaved.

Definition at line 88 of file OMPIRBuilder.cpp.

◆ isValidWorkshareLoopScheduleType()

bool isValidWorkshareLoopScheduleType ( OMPScheduleType SchedType)
static

Definition at line 95 of file OMPIRBuilder.cpp.

Referenced by computeOpenMPScheduleType().

◆ loadSharedDataFromTaskDescriptor()

LoadInst * loadSharedDataFromTaskDescriptor ( OpenMPIRBuilder & OMPIRBuilder,
IRBuilderBase & Builder,
Value * TaskWithPrivates,
Type * TaskWithPrivatesTy )
static

Given a task descriptor, TaskWithPrivates, return the pointer to the block of pointers containing shared data between the parent task and the created task.

Definition at line 7607 of file OMPIRBuilder.cpp.

References llvm::PointerType::getUnqual().

Referenced by emitTargetTaskProxyFunction().

◆ populateReductionFunction()

Error populateReductionFunction ( Function * ReductionFunc,
ArrayRef< OpenMPIRBuilder::ReductionInfo > ReductionInfos,
IRBuilder<> & Builder,
ArrayRef< bool > IsByRef,
bool IsGPU )
static

◆ raiseUserConstantDataAllocasToEntryBlock()

◆ redirectAllPredecessorsTo()

void redirectAllPredecessorsTo ( BasicBlock * OldTarget,
BasicBlock * NewTarget,
DebugLoc DL )
static

Redirect all edges that branch to OldTarget to NewTarget.

That is, after this OldTarget will be orphaned.

Definition at line 5398 of file OMPIRBuilder.cpp.

References DL, llvm::make_early_inc_range(), llvm::predecessors(), and redirectTo().

◆ redirectTo()

void redirectTo ( BasicBlock * Source,
BasicBlock * Target,
DebugLoc DL )
static

Make Source branch to Target.

Handles two situations:

  • Source already has an unconditional branch.
  • Source is a degenerate block (no terminator because the BB is the current head of the IR construction).

Definition at line 289 of file OMPIRBuilder.cpp.

References assert(), llvm::cast(), llvm::BranchInst::Create(), DL, and llvm::BasicBlock::removePredecessor().

Referenced by redirectAllPredecessorsTo().

◆ removeASCastIfPresent()

Value * removeASCastIfPresent ( Value * V)
static

Definition at line 7415 of file OMPIRBuilder.cpp.

References llvm::cast(), and llvm::Operator::getOpcode().

Referenced by createOutlinedFunction().

◆ removeUnusedBlocksFromParent()

void removeUnusedBlocksFromParent ( ArrayRef< BasicBlock * > BBs)
static

Determine which blocks in BBs are reachable from outside and remove the ones that are not reachable from the function.

Definition at line 5406 of file OMPIRBuilder.cpp.

References llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::DeleteDeadBlocks(), llvm::dyn_cast(), llvm::SmallPtrSetImpl< PtrType >::end(), llvm::from_range, llvm::SmallPtrSetImpl< PtrType >::remove_if(), and llvm::Value::uses().

◆ restoreIPandDebugLoc()

void restoreIPandDebugLoc ( llvm::IRBuilderBase & Builder,
llvm::IRBuilderBase::InsertPoint IP )
static

This is wrapper over IRBuilderBase::restoreIP that also restores the current debug location to the last instruction in the specified basic block if the insert point points to the end of the block.

Definition at line 157 of file OMPIRBuilder.cpp.

References llvm::BasicBlock::back(), llvm::BasicBlock::empty(), llvm::BasicBlock::end(), llvm::Instruction::getStableDebugLoc(), and I.

◆ targetParallelCallback()

◆ updateNVPTXAttr()

void updateNVPTXAttr ( Function & Kernel,
StringRef Name,
int32_t Value,
bool Min )
static

Definition at line 6940 of file OMPIRBuilder.cpp.

References llvm::utostr().

◆ workshareLoopTargetCallback()

Variable Documentation

◆ OptimisticAttributes

cl::opt< bool > OptimisticAttributes("openmp-ir-builder-optimistic-attributes", cl::Hidden, cl::desc("Use optimistic attributes describing " "'as-if' properties of runtime calls."), cl::init(false)) ( "openmp-ir-builder-optimistic-attributes" ,
cl::Hidden ,
cl::desc("Use optimistic attributes describing " "'as-if' properties of runtime calls.") ,
cl::init(false)  )
static

◆ UnrollThresholdFactor

cl::opt< double > UnrollThresholdFactor("openmp-ir-builder-unroll-threshold-factor", cl::Hidden, cl::desc("Factor for the unroll threshold to account for code " "simplifications still taking place"), cl::init(1.5)) ( "openmp-ir-builder-unroll-threshold-factor" ,
cl::Hidden ,
cl::desc("Factor for the unroll threshold to account for code " "simplifications still taking place") ,
cl::init(1.5)  )
static