MLIR  22.0.0git
Classes | Functions
OpenMPToLLVMIRTranslation.cpp File Reference
#include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
#include "mlir/Analysis/TopologicalSortUtils.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/Dialect/OpenMP/OpenMPInterfaces.h"
#include "mlir/IR/Operation.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Target/LLVMIR/Dialect/OpenMPCommon.h"
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Frontend/OpenMP/OMPConstants.h"
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/ReplaceConstant.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include <cstdint>
#include <iterator>
#include <numeric>
#include <optional>
#include <utility>

Go to the source code of this file.

Classes

struct  PrivateVarsInfo
 A util to collect info needed to convert delayed privatizers from MLIR to LLVM. More...
 

Functions

static omp::PrivateClauseOp findPrivatizer (Operation *from, SymbolRefAttr symbolName)
 Looks up from the operation from and returns the PrivateClauseOp with name symbolName. More...
 
static LogicalResult checkImplementationStatus (Operation &op)
 Check whether translation to LLVM IR for the given operation is currently supported. More...
 
static LogicalResult handleError (llvm::Error error, Operation &op)
 
template<typename T >
static LogicalResult handleError (llvm::Expected< T > &result, Operation &op)
 
static llvm::OpenMPIRBuilder::InsertPointTy findAllocaInsertPoint (llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Find the insertion point for allocas given the current insertion point for normal operations in the builder. More...
 
static llvm::CanonicalLoopInfo * findCurrentLoopInfo (LLVM::ModuleTranslation &moduleTranslation)
 Find the loop information structure for the loop nest being translated. More...
 
static llvm::Expected< llvm::BasicBlock * > convertOmpOpRegions (Region &region, StringRef blockName, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, SmallVectorImpl< llvm::PHINode * > *continuationBlockPHIs=nullptr)
 Converts the given region that appears within an OpenMP dialect operation to LLVM IR, creating a branch from the sourceBlock to the entry block of the region, and a branch from any block with an successor-less OpenMP terminator to continuationBlock. More...
 
static llvm::omp::ProcBindKind getProcBindKind (omp::ClauseProcBindKind kind)
 Convert ProcBindKind from MLIR-generated enum to LLVM enum. More...
 
static void forwardArgs (LLVM::ModuleTranslation &moduleTranslation, omp::BlockArgOpenMPOpInterface blockArgIface)
 Maps block arguments from blockArgIface (which are MLIR values) to the corresponding LLVM values of the interface's operands. More...
 
static LogicalResult convertOmpMasked (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP 'masked' operation into LLVM IR using OpenMPIRBuilder. More...
 
static LogicalResult convertOmpMaster (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP 'master' operation into LLVM IR using OpenMPIRBuilder. More...
 
static LogicalResult convertOmpCritical (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP 'critical' operation into LLVM IR using OpenMPIRBuilder. More...
 
template<typename T >
static void collectReductionDecls (T op, SmallVectorImpl< omp::DeclareReductionOp > &reductions)
 Populates reductions with reduction declarations used in the given op. More...
 
static LogicalResult inlineConvertOmpRegions (Region &region, StringRef blockName, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, SmallVectorImpl< llvm::Value * > *continuationBlockArgs=nullptr)
 Translates the blocks contained in the given region and appends them to at the current insertion point of builder. More...
 
static OwningReductionGen makeReductionGen (omp::DeclareReductionOp decl, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Create an OpenMPIRBuilder-compatible reduction generator for the given reduction declaration. More...
 
static OwningAtomicReductionGen makeAtomicReductionGen (omp::DeclareReductionOp decl, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Create an OpenMPIRBuilder-compatible atomic reduction generator for the given reduction declaration. More...
 
static LogicalResult convertOmpOrdered (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP 'ordered' operation into LLVM IR using OpenMPIRBuilder. More...
 
static LogicalResult convertOmpOrderedRegion (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP 'ordered_region' operation into LLVM IR using OpenMPIRBuilder. More...
 
template<typename T >
static LogicalResult allocReductionVars (T loop, ArrayRef< BlockArgument > reductionArgs, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, const llvm::OpenMPIRBuilder::InsertPointTy &allocaIP, SmallVectorImpl< omp::DeclareReductionOp > &reductionDecls, SmallVectorImpl< llvm::Value * > &privateReductionVariables, DenseMap< Value, llvm::Value * > &reductionVariableMap, SmallVectorImpl< DeferredStore > &deferredStores, llvm::ArrayRef< bool > isByRefs)
 Allocate space for privatized reduction variables. More...
 
template<typename T >
static void mapInitializationArgs (T loop, LLVM::ModuleTranslation &moduleTranslation, SmallVectorImpl< omp::DeclareReductionOp > &reductionDecls, DenseMap< Value, llvm::Value * > &reductionVariableMap, unsigned i)
 Map input arguments to reduction initialization region. More...
 
static void setInsertPointForPossiblyEmptyBlock (llvm::IRBuilderBase &builder, llvm::BasicBlock *block=nullptr)
 
template<typename OP >
static LogicalResult initReductionVars (OP op, ArrayRef< BlockArgument > reductionArgs, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, llvm::BasicBlock *latestAllocaBlock, SmallVectorImpl< omp::DeclareReductionOp > &reductionDecls, SmallVectorImpl< llvm::Value * > &privateReductionVariables, DenseMap< Value, llvm::Value * > &reductionVariableMap, llvm::ArrayRef< bool > isByRef, SmallVectorImpl< DeferredStore > &deferredStores)
 Inline reductions' init regions. More...
 
template<typename T >
static void collectReductionInfo (T loop, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, SmallVectorImpl< omp::DeclareReductionOp > &reductionDecls, SmallVectorImpl< OwningReductionGen > &owningReductionGens, SmallVectorImpl< OwningAtomicReductionGen > &owningAtomicReductionGens, const ArrayRef< llvm::Value * > privateReductionVariables, SmallVectorImpl< llvm::OpenMPIRBuilder::ReductionInfo > &reductionInfos)
 Collect reduction info. More...
 
static LogicalResult inlineOmpRegionCleanup (llvm::SmallVectorImpl< Region * > &cleanupRegions, llvm::ArrayRef< llvm::Value * > privateVariables, LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase &builder, StringRef regionName, bool shouldLoadCleanupRegionArg=true)
 handling of DeclareReductionOp's cleanup region More...
 
template<class OP >
static LogicalResult createReductionsAndCleanup (OP op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, llvm::OpenMPIRBuilder::InsertPointTy &allocaIP, SmallVectorImpl< omp::DeclareReductionOp > &reductionDecls, ArrayRef< llvm::Value * > privateReductionVariables, ArrayRef< bool > isByRef, bool isNowait=false, bool isTeamsReduction=false)
 
static ArrayRef< bool > getIsByRef (std::optional< ArrayRef< bool >> attr)
 
template<typename OP >
static LogicalResult allocAndInitializeReductionVars (OP op, ArrayRef< BlockArgument > reductionArgs, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, llvm::OpenMPIRBuilder::InsertPointTy &allocaIP, SmallVectorImpl< omp::DeclareReductionOp > &reductionDecls, SmallVectorImpl< llvm::Value * > &privateReductionVariables, DenseMap< Value, llvm::Value * > &reductionVariableMap, llvm::ArrayRef< bool > isByRef)
 
static llvm::Value * findAssociatedValue (Value privateVar, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, llvm::DenseMap< Value, Value > *mappedPrivateVars=nullptr)
 Return the llvm::Value * corresponding to the privateVar that is being privatized. More...
 
static llvm::Expected< llvm::Value * > initPrivateVar (llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, omp::PrivateClauseOp &privDecl, Value mlirPrivVar, BlockArgument &blockArg, llvm::Value *llvmPrivateVar, llvm::BasicBlock *privInitBlock, llvm::DenseMap< Value, Value > *mappedPrivateVars=nullptr)
 Initialize a single (first)private variable. More...
 
static llvm::Error initPrivateVars (llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, PrivateVarsInfo &privateVarsInfo, llvm::DenseMap< Value, Value > *mappedPrivateVars=nullptr)
 
static llvm::Expected< llvm::BasicBlock * > allocatePrivateVars (llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, PrivateVarsInfo &privateVarsInfo, const llvm::OpenMPIRBuilder::InsertPointTy &allocaIP, llvm::DenseMap< Value, Value > *mappedPrivateVars=nullptr)
 Allocate and initialize delayed private variables. More...
 
static LogicalResult copyFirstPrivateVars (mlir::Operation *op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, SmallVectorImpl< mlir::Value > &mlirPrivateVars, ArrayRef< llvm::Value * > llvmPrivateVars, SmallVectorImpl< omp::PrivateClauseOp > &privateDecls, bool insertBarrier, llvm::DenseMap< Value, Value > *mappedPrivateVars=nullptr)
 
static LogicalResult cleanupPrivateVars (llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, Location loc, SmallVectorImpl< llvm::Value * > &llvmPrivateVars, SmallVectorImpl< omp::PrivateClauseOp > &privateDecls)
 
static bool constructIsCancellable (Operation *op)
 Returns true if the construct contains omp.cancel or omp.cancellation_point. More...
 
static LogicalResult convertOmpSections (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertOmpSingle (omp::SingleOp &singleOp, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP single construct into LLVM IR using OpenMPIRBuilder. More...
 
static bool teamsReductionContainedInDistribute (omp::TeamsOp teamsOp)
 
static LogicalResult convertOmpTeams (omp::TeamsOp op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static void buildDependData (std::optional< ArrayAttr > dependKinds, OperandRange dependVars, LLVM::ModuleTranslation &moduleTranslation, SmallVectorImpl< llvm::OpenMPIRBuilder::DependData > &dds)
 
static void pushCancelFinalizationCB (SmallVectorImpl< llvm::BranchInst * > &cancelTerminators, llvm::IRBuilderBase &llvmBuilder, llvm::OpenMPIRBuilder &ompBuilder, mlir::Operation *op, llvm::omp::Directive cancelDirective)
 Shared implementation of a callback which adds a termiator for the new block created for the branch taken when an openmp construct is cancelled. More...
 
static void popCancelFinalizationCB (const ArrayRef< llvm::BranchInst * > cancelTerminators, llvm::OpenMPIRBuilder &ompBuilder, const llvm::OpenMPIRBuilder::InsertPointTy &afterIP)
 If we cancelled the construct, we should branch to the finalization block of that construct. More...
 
static LogicalResult convertOmpTaskOp (omp::TaskOp taskOp, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP task construct into LLVM IR using OpenMPIRBuilder. More...
 
static LogicalResult convertOmpTaskgroupOp (omp::TaskgroupOp tgOp, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP taskgroup construct into LLVM IR using OpenMPIRBuilder. More...
 
static LogicalResult convertOmpTaskwaitOp (omp::TaskwaitOp twOp, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertOmpWsloop (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP workshare loop into LLVM IR using OpenMPIRBuilder. More...
 
static LogicalResult convertOmpParallel (omp::ParallelOp opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts the OpenMP parallel operation to LLVM IR. More...
 
static llvm::omp::OrderKind convertOrderKind (std::optional< omp::ClauseOrderKind > o)
 Convert Order attribute to llvm::omp::OrderKind. More...
 
static LogicalResult convertOmpSimd (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP simd loop into LLVM IR using OpenMPIRBuilder. More...
 
static LogicalResult convertOmpLoopNest (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP loop nest into LLVM IR using OpenMPIRBuilder. More...
 
static LogicalResult convertOmpCanonicalLoopOp (omp::CanonicalLoopOp op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Convert an omp.canonical_loop to LLVM-IR. More...
 
static LogicalResult applyUnrollHeuristic (omp::UnrollHeuristicOp op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Apply a #pragma omp unroll / "!$omp unroll" transformation using the OpenMPIRBuilder. More...
 
static llvm::AtomicOrdering convertAtomicOrdering (std::optional< omp::ClauseMemoryOrderKind > ao)
 Convert an Atomic Ordering attribute to llvm::AtomicOrdering. More...
 
static LogicalResult convertOmpAtomicRead (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Convert omp.atomic.read operation to LLVM IR. More...
 
static LogicalResult convertOmpAtomicWrite (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an omp.atomic.write operation to LLVM IR. More...
 
static llvm::AtomicRMWInst::BinOp convertBinOpToAtomic (Operation &op)
 Converts an LLVM dialect binary operation to the corresponding enum value for atomicrmw supported binary operation. More...
 
static void extractAtomicControlFlags (omp::AtomicUpdateOp atomicUpdateOp, bool &isIgnoreDenormalMode, bool &isFineGrainedMemory, bool &isRemoteMemory)
 
static LogicalResult convertOmpAtomicUpdate (omp::AtomicUpdateOp &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP atomic update operation using OpenMPIRBuilder. More...
 
static LogicalResult convertOmpAtomicCapture (omp::AtomicCaptureOp atomicCaptureOp, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static llvm::omp::Directive convertCancellationConstructType (omp::ClauseCancellationConstructType directive)
 
static LogicalResult convertOmpCancel (omp::CancelOp op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertOmpCancellationPoint (omp::CancellationPointOp op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertOmpThreadprivate (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Converts an OpenMP Threadprivate operation into LLVM IR using OpenMPIRBuilder. More...
 
static llvm::OffloadEntriesInfoManager::OMPTargetDeviceClauseKind convertToDeviceClauseKind (mlir::omp::DeclareTargetDeviceType deviceClause)
 
static llvm::OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind convertToCaptureClauseKind (mlir::omp::DeclareTargetCaptureClause captureClause)
 
static llvm::SmallString< 64 > getDeclareTargetRefPtrSuffix (LLVM::GlobalOp globalOp, llvm::OpenMPIRBuilder &ompBuilder)
 
static bool isDeclareTargetLink (mlir::Value value)
 
static llvm::Value * getRefPtrIfDeclareTarget (mlir::Value value, LLVM::ModuleTranslation &moduleTranslation)
 
static uint64_t getArrayElementSizeInBits (LLVM::LLVMArrayType arrTy, DataLayout &dl)
 
static llvm::Value * getSizeInBytes (DataLayout &dl, const mlir::Type &type, Operation *clauseOp, llvm::Value *basePointer, llvm::Type *baseType, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static void collectMapDataFromMapOperands (MapInfoData &mapData, SmallVectorImpl< Value > &mapVars, LLVM::ModuleTranslation &moduleTranslation, DataLayout &dl, llvm::IRBuilderBase &builder, ArrayRef< Value > useDevPtrOperands={}, ArrayRef< Value > useDevAddrOperands={}, ArrayRef< Value > hasDevAddrOperands={})
 
static int getMapDataMemberIdx (MapInfoData &mapData, omp::MapInfoOp memberOp)
 
static omp::MapInfoOp getFirstOrLastMappedMemberPtr (omp::MapInfoOp mapInfo, bool first)
 
static std::vector< llvm::Value * > calculateBoundsOffset (LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase &builder, bool isArrayTy, OperandRange bounds)
 This function calculates the array/pointer offset for map data provided with bounds operations, e.g. More...
 
static llvm::omp::OpenMPOffloadMappingFlags mapParentWithMembers (LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase &builder, llvm::OpenMPIRBuilder &ompBuilder, DataLayout &dl, MapInfosTy &combinedInfo, MapInfoData &mapData, uint64_t mapDataIndex, bool isTargetParams)
 
static bool checkIfPointerMap (omp::MapInfoOp mapOp)
 
static void processMapMembersWithParent (LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase &builder, llvm::OpenMPIRBuilder &ompBuilder, DataLayout &dl, MapInfosTy &combinedInfo, MapInfoData &mapData, uint64_t mapDataIndex, llvm::omp::OpenMPOffloadMappingFlags memberOfFlag)
 
static void processIndividualMap (MapInfoData &mapData, size_t mapDataIdx, MapInfosTy &combinedInfo, bool isTargetParams, int mapDataParentIdx=-1)
 
static void processMapWithMembersOf (LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase &builder, llvm::OpenMPIRBuilder &ompBuilder, DataLayout &dl, MapInfosTy &combinedInfo, MapInfoData &mapData, uint64_t mapDataIndex, bool isTargetParams)
 
static void createAlteredByCaptureMap (MapInfoData &mapData, LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase &builder)
 
static void genMapInfos (llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, DataLayout &dl, MapInfosTy &combinedInfo, MapInfoData &mapData, bool isTargetParams=false)
 
static llvm::Expected< llvm::Function * > emitUserDefinedMapper (Operation *declMapperOp, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, llvm::StringRef mapperFuncName)
 
static llvm::Expected< llvm::Function * > getOrCreateUserDefinedMapperFunc (Operation *op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertOmpTargetData (Operation *op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertOmpDistribute (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertFlagsAttr (Operation *op, mlir::omp::FlagsAttr attribute, LLVM::ModuleTranslation &moduleTranslation)
 Lowers the FlagsAttr which is applied to the module on the device pass when offloading, this attribute contains OpenMP RTL globals that can be passed as flags to the frontend, otherwise they are set to default. More...
 
static void getTargetEntryUniqueInfo (llvm::TargetRegionEntryInfo &targetInfo, omp::TargetOp targetOp, llvm::StringRef parentName="")
 
static void handleDeclareTargetMapVar (MapInfoData &mapData, LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase &builder, llvm::Function *func)
 
static llvm::IRBuilderBase::InsertPoint createDeviceArgumentAccessor (MapInfoData &mapData, llvm::Argument &arg, llvm::Value *input, llvm::Value *&retVal, llvm::IRBuilderBase &builder, llvm::OpenMPIRBuilder &ompBuilder, LLVM::ModuleTranslation &moduleTranslation, llvm::IRBuilderBase::InsertPoint allocaIP, llvm::IRBuilderBase::InsertPoint codeGenIP)
 
static void extractHostEvalClauses (omp::TargetOp targetOp, Value &numThreads, Value &numTeamsLower, Value &numTeamsUpper, Value &threadLimit, llvm::SmallVectorImpl< Value > *lowerBounds=nullptr, llvm::SmallVectorImpl< Value > *upperBounds=nullptr, llvm::SmallVectorImpl< Value > *steps=nullptr)
 Follow uses of host_eval-defined block arguments of the given omp.target operation and populate output variables with their corresponding host value (i.e. More...
 
template<typename OpTy >
static OpTy castOrGetParentOfType (Operation *op, bool immediateParent=false)
 If op is of the given type parameter, return it casted to that type. More...
 
static std::optional< int64_t > extractConstInteger (Value value)
 If the given value is defined by an llvm.mlir.constant operation and it is of an integer type, return its value. More...
 
static uint64_t getTypeByteSize (mlir::Type type, const DataLayout &dl)
 
template<typename OpTy >
static uint64_t getReductionDataSize (OpTy &op)
 
static void initTargetDefaultAttrs (omp::TargetOp targetOp, Operation *capturedOp, llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &attrs, bool isTargetDevice, bool isGPU)
 Populate default MinTeams, MaxTeams and MaxThreads to their default values as stated by the corresponding clauses, if constant. More...
 
static void initTargetRuntimeAttrs (llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation, omp::TargetOp targetOp, Operation *capturedOp, llvm::OpenMPIRBuilder::TargetKernelRuntimeAttrs &attrs)
 Gather LLVM runtime values for all clauses evaluated in the host that are passed to the kernel invocation. More...
 
static LogicalResult convertOmpTarget (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertDeclareTargetAttr (Operation *op, mlir::omp::DeclareTargetAttr attribute, LLVM::ModuleTranslation &moduleTranslation)
 
static bool isTargetDeviceOp (Operation *op)
 
static llvm::Function * getOmpTargetAlloc (llvm::IRBuilderBase &builder, llvm::Module *llvmModule)
 
static LogicalResult convertTargetAllocMemOp (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static llvm::Function * getOmpTargetFree (llvm::IRBuilderBase &builder, llvm::Module *llvmModule)
 
static LogicalResult convertTargetFreeMemOp (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertHostOrTargetOperation (Operation *op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Given an OpenMP MLIR operation, create the corresponding LLVM IR (including OpenMP runtime calls). More...
 
static LogicalResult convertTargetDeviceOp (Operation *op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 
static LogicalResult convertTargetOpsInNest (Operation *op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 

Function Documentation

◆ allocAndInitializeReductionVars()

template<typename OP >
static LogicalResult allocAndInitializeReductionVars ( OP  op,
ArrayRef< BlockArgument reductionArgs,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
llvm::OpenMPIRBuilder::InsertPointTy &  allocaIP,
SmallVectorImpl< omp::DeclareReductionOp > &  reductionDecls,
SmallVectorImpl< llvm::Value * > &  privateReductionVariables,
DenseMap< Value, llvm::Value * > &  reductionVariableMap,
llvm::ArrayRef< bool >  isByRef 
)
static

◆ allocatePrivateVars()

static llvm::Expected<llvm::BasicBlock *> allocatePrivateVars ( llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
PrivateVarsInfo privateVarsInfo,
const llvm::OpenMPIRBuilder::InsertPointTy &  allocaIP,
llvm::DenseMap< Value, Value > *  mappedPrivateVars = nullptr 
)
static

Allocate and initialize delayed private variables.

Returns the basic block which comes after all of these allocations. llvm::Value * for each of these private variables are populated in llvmPrivateVars.

Definition at line 1591 of file OpenMPToLLVMIRTranslation.cpp.

References PrivateVarsInfo::blockArgs, PrivateVarsInfo::llvmVars, PrivateVarsInfo::mlirVars, and PrivateVarsInfo::privatizers.

Referenced by convertOmpDistribute(), convertOmpParallel(), convertOmpSimd(), convertOmpTarget(), and convertOmpWsloop().

◆ allocReductionVars()

template<typename T >
static LogicalResult allocReductionVars ( loop,
ArrayRef< BlockArgument reductionArgs,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
const llvm::OpenMPIRBuilder::InsertPointTy &  allocaIP,
SmallVectorImpl< omp::DeclareReductionOp > &  reductionDecls,
SmallVectorImpl< llvm::Value * > &  privateReductionVariables,
DenseMap< Value, llvm::Value * > &  reductionVariableMap,
SmallVectorImpl< DeferredStore > &  deferredStores,
llvm::ArrayRef< bool >  isByRefs 
)
static

Allocate space for privatized reduction variables.

deferredStores contains information to create store operations which needs to be inserted after all allocas

Definition at line 1111 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::Region::empty(), mlir::remark::failed(), and inlineConvertOmpRegions().

Referenced by allocAndInitializeReductionVars(), convertOmpParallel(), convertOmpSimd(), and convertOmpWsloop().

◆ applyUnrollHeuristic()

static LogicalResult applyUnrollHeuristic ( omp::UnrollHeuristicOp  op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Apply a #pragma omp unroll / "!$omp unroll" transformation using the OpenMPIRBuilder.

Definition at line 3141 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertHostOrTargetOperation().

◆ buildDependData()

static void buildDependData ( std::optional< ArrayAttr >  dependKinds,
OperandRange  dependVars,
LLVM::ModuleTranslation &  moduleTranslation,
SmallVectorImpl< llvm::OpenMPIRBuilder::DependData > &  dds 
)
static

Definition at line 2003 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertOmpTarget(), and convertOmpTaskOp().

◆ calculateBoundsOffset()

static std::vector<llvm::Value *> calculateBoundsOffset ( LLVM::ModuleTranslation &  moduleTranslation,
llvm::IRBuilderBase &  builder,
bool  isArrayTy,
OperandRange  bounds 
)
static

This function calculates the array/pointer offset for map data provided with bounds operations, e.g.

when provided something like the following:

Fortran map(tofrom: array(2:5, 3:2)) or C++ map(tofrom: array[1:4][2:3]) We must calculate the initial pointer offset to pass across, this function performs this using bounds.

NOTE: which while specified in row-major order it currently needs to be flipped for Fortran's column order array allocation and access (as opposed to C++'s row-major, hence the backwards processing where order is important). This is likely important to keep in mind for the future when we incorporate a C++ frontend, both frontends will need to agree on the ordering of generated bounds operations (one may have to flip them) to make the below lowering frontend agnostic. The offload size calcualtion may also have to be adjusted for C++.

Definition at line 3997 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by createAlteredByCaptureMap().

◆ castOrGetParentOfType()

template<typename OpTy >
static OpTy castOrGetParentOfType ( Operation op,
bool  immediateParent = false 
)
static

If op is of the given type parameter, return it casted to that type.

Otherwise, if its immediate parent operation (or some other higher-level parent, if immediateParent is false) is of that type, return that parent casted to the given type.

If op is null or neither it or its parent(s) are of the specified type, return a null operation.

Definition at line 5268 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::Operation::getParentOfType(), and mlir::Operation::getParentOp().

◆ checkIfPointerMap()

static bool checkIfPointerMap ( omp::MapInfoOp  mapOp)
static

◆ checkImplementationStatus()

static LogicalResult checkImplementationStatus ( Operation op)
static

◆ cleanupPrivateVars()

static LogicalResult cleanupPrivateVars ( llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
Location  loc,
SmallVectorImpl< llvm::Value * > &  llvmPrivateVars,
SmallVectorImpl< omp::PrivateClauseOp > &  privateDecls 
)
static

◆ collectMapDataFromMapOperands()

static void collectMapDataFromMapOperands ( MapInfoData &  mapData,
SmallVectorImpl< Value > &  mapVars,
LLVM::ModuleTranslation &  moduleTranslation,
DataLayout dl,
llvm::IRBuilderBase &  builder,
ArrayRef< Value useDevPtrOperands = {},
ArrayRef< Value useDevAddrOperands = {},
ArrayRef< Value hasDevAddrOperands = {} 
)
static

◆ collectReductionDecls()

template<typename T >
static void collectReductionDecls ( op,
SmallVectorImpl< omp::DeclareReductionOp > &  reductions 
)
static

Populates reductions with reduction declarations used in the given op.

Definition at line 870 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertOmpDistribute(), convertOmpParallel(), convertOmpSections(), convertOmpSimd(), convertOmpTeams(), convertOmpWsloop(), and getReductionDataSize().

◆ collectReductionInfo()

template<typename T >
static void collectReductionInfo ( loop,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
SmallVectorImpl< omp::DeclareReductionOp > &  reductionDecls,
SmallVectorImpl< OwningReductionGen > &  owningReductionGens,
SmallVectorImpl< OwningAtomicReductionGen > &  owningAtomicReductionGens,
const ArrayRef< llvm::Value * >  privateReductionVariables,
SmallVectorImpl< llvm::OpenMPIRBuilder::ReductionInfo > &  reductionInfos 
)
static

Collect reduction info.

Definition at line 1314 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::getType(), makeAtomicReductionGen(), and makeReductionGen().

Referenced by convertOmpParallel(), and createReductionsAndCleanup().

◆ constructIsCancellable()

static bool constructIsCancellable ( Operation op)
static

Returns true if the construct contains omp.cancel or omp.cancellation_point.

Definition at line 1724 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::WalkResult::advance(), mlir::WalkResult::interrupt(), and mlir::Operation::walk().

Referenced by convertOmpParallel(), convertOmpSections(), and pushCancelFinalizationCB().

◆ convertAtomicOrdering()

static llvm::AtomicOrdering convertAtomicOrdering ( std::optional< omp::ClauseMemoryOrderKind >  ao)
static

Convert an Atomic Ordering attribute to llvm::AtomicOrdering.

Definition at line 3159 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertOmpAtomicCapture(), convertOmpAtomicRead(), convertOmpAtomicUpdate(), and convertOmpAtomicWrite().

◆ convertBinOpToAtomic()

static llvm::AtomicRMWInst::BinOp convertBinOpToAtomic ( Operation op)
static

Converts an LLVM dialect binary operation to the corresponding enum value for atomicrmw supported binary operation.

Definition at line 3231 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertOmpAtomicCapture(), and convertOmpAtomicUpdate().

◆ convertCancellationConstructType()

static llvm::omp::Directive convertCancellationConstructType ( omp::ClauseCancellationConstructType  directive)
static

◆ convertDeclareTargetAttr()

static LogicalResult convertDeclareTargetAttr ( Operation op,
mlir::omp::DeclareTargetAttr  attribute,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertFlagsAttr()

static LogicalResult convertFlagsAttr ( Operation op,
mlir::omp::FlagsAttr  attribute,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Lowers the FlagsAttr which is applied to the module on the device pass when offloading, this attribute contains OpenMP RTL globals that can be passed as flags to the frontend, otherwise they are set to default.

Definition at line 4956 of file OpenMPToLLVMIRTranslation.cpp.

◆ convertHostOrTargetOperation()

static LogicalResult convertHostOrTargetOperation ( Operation op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpAtomicCapture()

static LogicalResult convertOmpAtomicCapture ( omp::AtomicCaptureOp  atomicCaptureOp,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpAtomicRead()

static LogicalResult convertOmpAtomicRead ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Convert omp.atomic.read operation to LLVM IR.

Definition at line 3180 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), convertAtomicOrdering(), mlir::remark::failed(), and findAllocaInsertPoint().

Referenced by convertHostOrTargetOperation().

◆ convertOmpAtomicUpdate()

static LogicalResult convertOmpAtomicUpdate ( omp::AtomicUpdateOp &  opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpAtomicWrite()

static LogicalResult convertOmpAtomicWrite ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an omp.atomic.write operation to LLVM IR.

Definition at line 3207 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), convertAtomicOrdering(), mlir::remark::failed(), and findAllocaInsertPoint().

Referenced by convertHostOrTargetOperation().

◆ convertOmpCancel()

static LogicalResult convertOmpCancel ( omp::CancelOp  op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpCancellationPoint()

static LogicalResult convertOmpCancellationPoint ( omp::CancellationPointOp  op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpCanonicalLoopOp()

static LogicalResult convertOmpCanonicalLoopOp ( omp::CanonicalLoopOp  op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Convert an omp.canonical_loop to LLVM-IR.

Definition at line 3098 of file OpenMPToLLVMIRTranslation.cpp.

References convertOmpOpRegions(), and toString().

Referenced by convertHostOrTargetOperation().

◆ convertOmpCritical()

static LogicalResult convertOmpCritical ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an OpenMP 'critical' operation into LLVM IR using OpenMPIRBuilder.

Definition at line 783 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), convertOmpOpRegions(), mlir::remark::failed(), mlir::get(), and handleError().

Referenced by convertHostOrTargetOperation().

◆ convertOmpDistribute()

static LogicalResult convertOmpDistribute ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpLoopNest()

static LogicalResult convertOmpLoopNest ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an OpenMP loop nest into LLVM IR using OpenMPIRBuilder.

Definition at line 2975 of file OpenMPToLLVMIRTranslation.cpp.

References convertOmpOpRegions(), mlir::remark::failed(), mlir::get(), handleError(), mlir::WalkResult::interrupt(), and mlir::tile().

Referenced by convertHostOrTargetOperation().

◆ convertOmpMasked()

static LogicalResult convertOmpMasked ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an OpenMP 'masked' operation into LLVM IR using OpenMPIRBuilder.

Definition at line 704 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), convertOmpOpRegions(), mlir::remark::failed(), mlir::get(), and handleError().

Referenced by convertHostOrTargetOperation().

◆ convertOmpMaster()

static LogicalResult convertOmpMaster ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an OpenMP 'master' operation into LLVM IR using OpenMPIRBuilder.

Definition at line 748 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), convertOmpOpRegions(), mlir::remark::failed(), and handleError().

Referenced by convertHostOrTargetOperation().

◆ convertOmpOpRegions()

static llvm::Expected<llvm::BasicBlock *> convertOmpOpRegions ( Region region,
StringRef  blockName,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
SmallVectorImpl< llvm::PHINode * > *  continuationBlockPHIs = nullptr 
)
static

Converts the given region that appears within an OpenMP dialect operation to LLVM IR, creating a branch from the sourceBlock to the entry block of the region, and a branch from any block with an successor-less OpenMP terminator to continuationBlock.

Populates continuationBlockPHIs with the PHI nodes of the continuation block if provided.

Definition at line 550 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::LLVM::detail::connectPHINodes(), mlir::remark::failed(), mlir::Region::getBlocks(), mlir::getBlocksSortedByDominance(), mlir::Operation::getNumOperands(), mlir::Operation::getOperand(), and mlir::Region::getParentOp().

Referenced by convertOmpCanonicalLoopOp(), convertOmpCritical(), convertOmpDistribute(), convertOmpLoopNest(), convertOmpMasked(), convertOmpMaster(), convertOmpOrderedRegion(), convertOmpParallel(), convertOmpSections(), convertOmpSimd(), convertOmpSingle(), convertOmpTarget(), convertOmpTaskgroupOp(), convertOmpTaskOp(), convertOmpTeams(), convertOmpWsloop(), convertTargetOpsInNest(), and inlineConvertOmpRegions().

◆ convertOmpOrdered()

static LogicalResult convertOmpOrdered ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an OpenMP 'ordered' operation into LLVM IR using OpenMPIRBuilder.

Definition at line 1029 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), mlir::remark::failed(), and findAllocaInsertPoint().

Referenced by convertHostOrTargetOperation().

◆ convertOmpOrderedRegion()

static LogicalResult convertOmpOrderedRegion ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an OpenMP 'ordered_region' operation into LLVM IR using OpenMPIRBuilder.

Definition at line 1062 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), convertOmpOpRegions(), mlir::remark::failed(), and handleError().

Referenced by convertHostOrTargetOperation().

◆ convertOmpParallel()

static LogicalResult convertOmpParallel ( omp::ParallelOp  opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpSections()

static LogicalResult convertOmpSections ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpSimd()

static LogicalResult convertOmpSimd ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpSingle()

static LogicalResult convertOmpSingle ( omp::SingleOp &  singleOp,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an OpenMP single construct into LLVM IR using OpenMPIRBuilder.

Definition at line 1845 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), convertOmpOpRegions(), mlir::remark::failed(), and handleError().

Referenced by convertHostOrTargetOperation().

◆ convertOmpTarget()

static LogicalResult convertOmpTarget ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpTargetData()

static LogicalResult convertOmpTargetData ( Operation op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpTaskgroupOp()

static LogicalResult convertOmpTaskgroupOp ( omp::TaskgroupOp  tgOp,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an OpenMP taskgroup construct into LLVM IR using OpenMPIRBuilder.

Definition at line 2431 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), convertOmpOpRegions(), mlir::remark::failed(), findAllocaInsertPoint(), and handleError().

Referenced by convertHostOrTargetOperation().

◆ convertOmpTaskOp()

static LogicalResult convertOmpTaskOp ( omp::TaskOp  taskOp,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpTaskwaitOp()

static LogicalResult convertOmpTaskwaitOp ( omp::TaskwaitOp  twOp,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpTeams()

static LogicalResult convertOmpTeams ( omp::TeamsOp  op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOmpThreadprivate()

static LogicalResult convertOmpThreadprivate ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Converts an OpenMP Threadprivate operation into LLVM IR using OpenMPIRBuilder.

Definition at line 3517 of file OpenMPToLLVMIRTranslation.cpp.

References checkImplementationStatus(), mlir::Operation::emitError(), mlir::remark::failed(), mlir::Value::getDefiningOp(), mlir::Operation::getOperand(), and mlir::Operation::getResult().

Referenced by convertHostOrTargetOperation().

◆ convertOmpWsloop()

static LogicalResult convertOmpWsloop ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertOrderKind()

static llvm::omp::OrderKind convertOrderKind ( std::optional< omp::ClauseOrderKind >  o)
static

Convert Order attribute to llvm::omp::OrderKind.

Definition at line 2811 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertOmpSimd().

◆ convertTargetAllocMemOp()

static LogicalResult convertTargetAllocMemOp ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Definition at line 5959 of file OpenMPToLLVMIRTranslation.cpp.

References getOmpTargetAlloc().

Referenced by convertHostOrTargetOperation().

◆ convertTargetDeviceOp()

static LogicalResult convertTargetDeviceOp ( Operation op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Definition at line 6217 of file OpenMPToLLVMIRTranslation.cpp.

References convertHostOrTargetOperation().

◆ convertTargetFreeMemOp()

static LogicalResult convertTargetFreeMemOp ( Operation opInst,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Definition at line 6003 of file OpenMPToLLVMIRTranslation.cpp.

References getOmpTargetFree().

Referenced by convertHostOrTargetOperation().

◆ convertTargetOpsInNest()

static LogicalResult convertTargetOpsInNest ( Operation op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ convertToCaptureClauseKind()

static llvm::OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind convertToCaptureClauseKind ( mlir::omp::DeclareTargetCaptureClause  captureClause)
static

Definition at line 3573 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertDeclareTargetAttr().

◆ convertToDeviceClauseKind()

static llvm::OffloadEntriesInfoManager::OMPTargetDeviceClauseKind convertToDeviceClauseKind ( mlir::omp::DeclareTargetDeviceType  deviceClause)
static

Definition at line 3557 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertDeclareTargetAttr().

◆ copyFirstPrivateVars()

static LogicalResult copyFirstPrivateVars ( mlir::Operation op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
SmallVectorImpl< mlir::Value > &  mlirPrivateVars,
ArrayRef< llvm::Value * >  llvmPrivateVars,
SmallVectorImpl< omp::PrivateClauseOp > &  privateDecls,
bool  insertBarrier,
llvm::DenseMap< Value, Value > *  mappedPrivateVars = nullptr 
)
static

◆ createAlteredByCaptureMap()

static void createAlteredByCaptureMap ( MapInfoData &  mapData,
LLVM::ModuleTranslation &  moduleTranslation,
llvm::IRBuilderBase &  builder 
)
static

◆ createDeviceArgumentAccessor()

static llvm::IRBuilderBase::InsertPoint createDeviceArgumentAccessor ( MapInfoData &  mapData,
llvm::Argument &  arg,
llvm::Value *  input,
llvm::Value *&  retVal,
llvm::IRBuilderBase &  builder,
llvm::OpenMPIRBuilder &  ompBuilder,
LLVM::ModuleTranslation &  moduleTranslation,
llvm::IRBuilderBase::InsertPoint  allocaIP,
llvm::IRBuilderBase::InsertPoint  codeGenIP 
)
static

Definition at line 5107 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::get().

Referenced by convertOmpTarget().

◆ createReductionsAndCleanup()

template<class OP >
static LogicalResult createReductionsAndCleanup ( OP  op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
llvm::OpenMPIRBuilder::InsertPointTy &  allocaIP,
SmallVectorImpl< omp::DeclareReductionOp > &  reductionDecls,
ArrayRef< llvm::Value * >  privateReductionVariables,
ArrayRef< bool >  isByRef,
bool  isNowait = false,
bool  isTeamsReduction = false 
)
static

◆ emitUserDefinedMapper()

static llvm::Expected<llvm::Function *> emitUserDefinedMapper ( Operation declMapperOp,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
llvm::StringRef  mapperFuncName 
)
static

◆ extractAtomicControlFlags()

static void extractAtomicControlFlags ( omp::AtomicUpdateOp  atomicUpdateOp,
bool &  isIgnoreDenormalMode,
bool &  isFineGrainedMemory,
bool &  isRemoteMemory 
)
static

◆ extractConstInteger()

static std::optional<int64_t> extractConstInteger ( Value  value)
static

If the given value is defined by an llvm.mlir.constant operation and it is of an integer type, return its value.

Definition at line 5283 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::Value::getDefiningOp().

Referenced by initTargetDefaultAttrs().

◆ extractHostEvalClauses()

static void extractHostEvalClauses ( omp::TargetOp  targetOp,
Value numThreads,
Value numTeamsLower,
Value numTeamsUpper,
Value threadLimit,
llvm::SmallVectorImpl< Value > *  lowerBounds = nullptr,
llvm::SmallVectorImpl< Value > *  upperBounds = nullptr,
llvm::SmallVectorImpl< Value > *  steps = nullptr 
)
static

Follow uses of host_eval-defined block arguments of the given omp.target operation and populate output variables with their corresponding host value (i.e.

operand evaluated outside of the target region), based on their uses inside of the target region.

Loop bounds and steps are only optionally populated, if output vectors are provided.

Definition at line 5202 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::detail::enumerate(), and mlir::Operation::getUsers().

Referenced by initTargetDefaultAttrs(), and initTargetRuntimeAttrs().

◆ findAllocaInsertPoint()

static llvm::OpenMPIRBuilder::InsertPointTy findAllocaInsertPoint ( llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ findAssociatedValue()

static llvm::Value* findAssociatedValue ( Value  privateVar,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
llvm::DenseMap< Value, Value > *  mappedPrivateVars = nullptr 
)
static

Return the llvm::Value * corresponding to the privateVar that is being privatized.

It isn't always as simple as looking up moduleTranslation with privateVar. For instance, in case of an allocatable, the descriptor for the allocatable is privatized. This descriptor is mapped using an MapInfoOp. So, this function will return a pointer to the llvm::Value corresponding to the block argument for the mapped descriptor.

Definition at line 1489 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::Value::getType().

Referenced by copyFirstPrivateVars(), and initPrivateVar().

◆ findCurrentLoopInfo()

static llvm::CanonicalLoopInfo* findCurrentLoopInfo ( LLVM::ModuleTranslation &  moduleTranslation)
static

Find the loop information structure for the loop nest being translated.

It will return a null value unless called from the translation function for a loop wrapper operation after successfully translating its body.

Definition at line 535 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::WalkResult::interrupt().

Referenced by convertOmpDistribute(), convertOmpSimd(), and convertOmpWsloop().

◆ findPrivatizer()

static omp::PrivateClauseOp findPrivatizer ( Operation from,
SymbolRefAttr  symbolName 
)
static

Looks up from the operation from and returns the PrivateClauseOp with name symbolName.

Definition at line 268 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertOmpTarget().

◆ forwardArgs()

static void forwardArgs ( LLVM::ModuleTranslation &  moduleTranslation,
omp::BlockArgOpenMPOpInterface  blockArgIface 
)
static

Maps block arguments from blockArgIface (which are MLIR values) to the corresponding LLVM values of the interface's operands.

This is useful when an OpenMP region with entry block arguments is converted to LLVM. In this case the block arguments are (part of) of the OpenMP region's entry arguments and the operands are (part of) of the operands to the OpenMP op containing the region.

Definition at line 694 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertTargetOpsInNest().

◆ genMapInfos()

static void genMapInfos ( llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
DataLayout dl,
MapInfosTy &  combinedInfo,
MapInfoData &  mapData,
bool  isTargetParams = false 
)
static

◆ getArrayElementSizeInBits()

static uint64_t getArrayElementSizeInBits ( LLVM::LLVMArrayType  arrTy,
DataLayout dl 
)
static

Definition at line 3706 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::DataLayout::getTypeSizeInBits().

Referenced by getSizeInBytes().

◆ getDeclareTargetRefPtrSuffix()

static llvm::SmallString<64> getDeclareTargetRefPtrSuffix ( LLVM::GlobalOp  globalOp,
llvm::OpenMPIRBuilder &  ompBuilder 
)
static

Definition at line 3587 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::SymbolTable::Private.

Referenced by getRefPtrIfDeclareTarget().

◆ getFirstOrLastMappedMemberPtr()

static omp::MapInfoOp getFirstOrLastMappedMemberPtr ( omp::MapInfoOp  mapInfo,
bool  first 
)
static

Definition at line 3940 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by mapParentWithMembers().

◆ getIsByRef()

static ArrayRef<bool> getIsByRef ( std::optional< ArrayRef< bool >>  attr)
static

◆ getMapDataMemberIdx()

static int getMapDataMemberIdx ( MapInfoData &  mapData,
omp::MapInfoOp  memberOp 
)
static

◆ getOmpTargetAlloc()

static llvm::Function* getOmpTargetAlloc ( llvm::IRBuilderBase &  builder,
llvm::Module *  llvmModule 
)
static

Definition at line 5946 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::get().

Referenced by convertTargetAllocMemOp().

◆ getOmpTargetFree()

static llvm::Function* getOmpTargetFree ( llvm::IRBuilderBase &  builder,
llvm::Module *  llvmModule 
)
static

Definition at line 5990 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::get().

Referenced by convertTargetFreeMemOp().

◆ getOrCreateUserDefinedMapperFunc()

static llvm::Expected<llvm::Function *> getOrCreateUserDefinedMapperFunc ( Operation op,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ getProcBindKind()

static llvm::omp::ProcBindKind getProcBindKind ( omp::ClauseProcBindKind  kind)
static

Convert ProcBindKind from MLIR-generated enum to LLVM enum.

Definition at line 674 of file OpenMPToLLVMIRTranslation.cpp.

References kind.

Referenced by convertOmpParallel().

◆ getReductionDataSize()

template<typename OpTy >
static uint64_t getReductionDataSize ( OpTy &  op)
static

◆ getRefPtrIfDeclareTarget()

static llvm::Value* getRefPtrIfDeclareTarget ( mlir::Value  value,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ getSizeInBytes()

static llvm::Value* getSizeInBytes ( DataLayout dl,
const mlir::Type type,
Operation clauseOp,
llvm::Value *  basePointer,
llvm::Type *  baseType,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

◆ getTargetEntryUniqueInfo()

static void getTargetEntryUniqueInfo ( llvm::TargetRegionEntryInfo &  targetInfo,
omp::TargetOp  targetOp,
llvm::StringRef  parentName = "" 
)
static

Definition at line 4993 of file OpenMPToLLVMIRTranslation.cpp.

References getDevice(), and mlir::spirv::hash_value().

Referenced by convertOmpTarget().

◆ getTypeByteSize()

static uint64_t getTypeByteSize ( mlir::Type  type,
const DataLayout dl 
)
static

◆ handleDeclareTargetMapVar()

static void handleDeclareTargetMapVar ( MapInfoData &  mapData,
LLVM::ModuleTranslation &  moduleTranslation,
llvm::IRBuilderBase &  builder,
llvm::Function *  func 
)
static

Definition at line 5015 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertOmpTarget().

◆ handleError() [1/2]

static LogicalResult handleError ( llvm::Error  error,
Operation op 
)
static

◆ handleError() [2/2]

template<typename T >
static LogicalResult handleError ( llvm::Expected< T > &  result,
Operation op 
)
static

Definition at line 477 of file OpenMPToLLVMIRTranslation.cpp.

References handleError().

◆ initPrivateVar()

static llvm::Expected<llvm::Value *> initPrivateVar ( llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
omp::PrivateClauseOp &  privDecl,
Value  mlirPrivVar,
BlockArgument blockArg,
llvm::Value *  llvmPrivateVar,
llvm::BasicBlock *  privInitBlock,
llvm::DenseMap< Value, Value > *  mappedPrivateVars = nullptr 
)
static

Initialize a single (first)private variable.

You probably want to use allocateAndInitPrivateVars instead of this. This returns the private variable which has been initialized. This variable should be mapped before constructing the body of the Op.

Definition at line 1520 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::Region::empty(), mlir::remark::failed(), findAssociatedValue(), and inlineConvertOmpRegions().

Referenced by convertOmpTaskOp(), and initPrivateVars().

◆ initPrivateVars()

static llvm::Error initPrivateVars ( llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
PrivateVarsInfo privateVarsInfo,
llvm::DenseMap< Value, Value > *  mappedPrivateVars = nullptr 
)
static

◆ initReductionVars()

template<typename OP >
static LogicalResult initReductionVars ( OP  op,
ArrayRef< BlockArgument reductionArgs,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
llvm::BasicBlock *  latestAllocaBlock,
SmallVectorImpl< omp::DeclareReductionOp > &  reductionDecls,
SmallVectorImpl< llvm::Value * > &  privateReductionVariables,
DenseMap< Value, llvm::Value * > &  reductionVariableMap,
llvm::ArrayRef< bool >  isByRef,
SmallVectorImpl< DeferredStore > &  deferredStores 
)
static

Inline reductions' init regions.

This functions assumes that the builder's insertion point is where the user wants the init regions to be inlined; i.e. it does not try to find a proper insertion location for the init regions. It also leaves the `builder's insertions point in a state where the user can continue the code-gen directly afterwards.

Definition at line 1219 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::remark::failed(), inlineConvertOmpRegions(), mapInitializationArgs(), and setInsertPointForPossiblyEmptyBlock().

Referenced by allocAndInitializeReductionVars(), convertOmpParallel(), convertOmpSimd(), and convertOmpWsloop().

◆ initTargetDefaultAttrs()

static void initTargetDefaultAttrs ( omp::TargetOp  targetOp,
Operation capturedOp,
llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &  attrs,
bool  isTargetDevice,
bool  isGPU 
)
static

Populate default MinTeams, MaxTeams and MaxThreads to their default values as stated by the corresponding clauses, if constant.

These default values must be set before the creation of the outlined LLVM function for the target region, so that they can be used to initialize the corresponding global ConfigurationEnvironmentTy structure.

Definition at line 5326 of file OpenMPToLLVMIRTranslation.cpp.

References extractConstInteger(), extractHostEvalClauses(), and getReductionDataSize().

Referenced by convertOmpTarget().

◆ initTargetRuntimeAttrs()

static void initTargetRuntimeAttrs ( llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
omp::TargetOp  targetOp,
Operation capturedOp,
llvm::OpenMPIRBuilder::TargetKernelRuntimeAttrs &  attrs 
)
static

Gather LLVM runtime values for all clauses evaluated in the host that are passed to the kernel invocation.

This function must be called only when compiling for the host. Also, it will only provide correct results if it's called after the body of targetOp has been fully generated.

Definition at line 5446 of file OpenMPToLLVMIRTranslation.cpp.

References extractHostEvalClauses().

Referenced by convertOmpTarget().

◆ inlineConvertOmpRegions()

static LogicalResult inlineConvertOmpRegions ( Region region,
StringRef  blockName,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation,
SmallVectorImpl< llvm::Value * > *  continuationBlockArgs = nullptr 
)
static

Translates the blocks contained in the given region and appends them to at the current insertion point of builder.

The operations of the entry block are appended to the current insertion block. If set, continuationBlockArgs is populated with translated values that correspond to the values omp.yield'ed from the region.

Definition at line 889 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::Block::back(), convertOmpOpRegions(), mlir::Region::empty(), mlir::remark::failed(), mlir::Region::front(), mlir::Operation::getOperands(), mlir::Region::getParentOp(), handleError(), and mlir::Region::hasOneBlock().

Referenced by allocReductionVars(), convertOmpTargetData(), copyFirstPrivateVars(), initPrivateVar(), initReductionVars(), inlineOmpRegionCleanup(), makeAtomicReductionGen(), and makeReductionGen().

◆ inlineOmpRegionCleanup()

static LogicalResult inlineOmpRegionCleanup ( llvm::SmallVectorImpl< Region * > &  cleanupRegions,
llvm::ArrayRef< llvm::Value * >  privateVariables,
LLVM::ModuleTranslation &  moduleTranslation,
llvm::IRBuilderBase &  builder,
StringRef  regionName,
bool  shouldLoadCleanupRegionArg = true 
)
static

◆ isDeclareTargetLink()

static bool isDeclareTargetLink ( mlir::Value  value)
static

Definition at line 3606 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::Value::getDefiningOp().

Referenced by checkIfPointerMap().

◆ isTargetDeviceOp()

static bool isTargetDeviceOp ( Operation op)
static

◆ makeAtomicReductionGen()

static OwningAtomicReductionGen makeAtomicReductionGen ( omp::DeclareReductionOp  decl,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Create an OpenMPIRBuilder-compatible atomic reduction generator for the given reduction declaration.

The generator uses builder but ignores its insertion point. Returns null if there is no atomic region available in the reduction declaration.

Definition at line 999 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::remark::failed(), and inlineConvertOmpRegions().

Referenced by collectReductionInfo().

◆ makeReductionGen()

static OwningReductionGen makeReductionGen ( omp::DeclareReductionOp  decl,
llvm::IRBuilderBase &  builder,
LLVM::ModuleTranslation &  moduleTranslation 
)
static

Create an OpenMPIRBuilder-compatible reduction generator for the given reduction declaration.

The generator uses builder but ignores its insertion point.

Definition at line 969 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::remark::failed(), and inlineConvertOmpRegions().

Referenced by collectReductionInfo(), and convertOmpSimd().

◆ mapInitializationArgs()

template<typename T >
static void mapInitializationArgs ( loop,
LLVM::ModuleTranslation &  moduleTranslation,
SmallVectorImpl< omp::DeclareReductionOp > &  reductionDecls,
DenseMap< Value, llvm::Value * > &  reductionVariableMap,
unsigned  i 
)
static

Map input arguments to reduction initialization region.

Definition at line 1179 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::Region::front(), and mlir::Block::getNumArguments().

Referenced by initReductionVars().

◆ mapParentWithMembers()

static llvm::omp::OpenMPOffloadMappingFlags mapParentWithMembers ( LLVM::ModuleTranslation &  moduleTranslation,
llvm::IRBuilderBase &  builder,
llvm::OpenMPIRBuilder &  ompBuilder,
DataLayout dl,
MapInfosTy &  combinedInfo,
MapInfoData &  mapData,
uint64_t  mapDataIndex,
bool  isTargetParams 
)
static

◆ popCancelFinalizationCB()

static void popCancelFinalizationCB ( const ArrayRef< llvm::BranchInst * >  cancelTerminators,
llvm::OpenMPIRBuilder &  ompBuilder,
const llvm::OpenMPIRBuilder::InsertPointTy &  afterIP 
)
static

If we cancelled the construct, we should branch to the finalization block of that construct.

OMPIRBuilder structures the CFG such that the cleanup block is immediately before the continuation block. Now this finalization has been created we can fix the branch.

Definition at line 2072 of file OpenMPToLLVMIRTranslation.cpp.

Referenced by convertOmpTaskOp(), and convertOmpWsloop().

◆ processIndividualMap()

static void processIndividualMap ( MapInfoData &  mapData,
size_t  mapDataIdx,
MapInfosTy &  combinedInfo,
bool  isTargetParams,
int  mapDataParentIdx = -1 
)
static

Definition at line 4291 of file OpenMPToLLVMIRTranslation.cpp.

References checkIfPointerMap().

Referenced by genMapInfos(), and processMapWithMembersOf().

◆ processMapMembersWithParent()

static void processMapMembersWithParent ( LLVM::ModuleTranslation &  moduleTranslation,
llvm::IRBuilderBase &  builder,
llvm::OpenMPIRBuilder &  ompBuilder,
DataLayout dl,
MapInfosTy &  combinedInfo,
MapInfoData &  mapData,
uint64_t  mapDataIndex,
llvm::omp::OpenMPOffloadMappingFlags  memberOfFlag 
)
static

◆ processMapWithMembersOf()

static void processMapWithMembersOf ( LLVM::ModuleTranslation &  moduleTranslation,
llvm::IRBuilderBase &  builder,
llvm::OpenMPIRBuilder &  ompBuilder,
DataLayout dl,
MapInfosTy &  combinedInfo,
MapInfoData &  mapData,
uint64_t  mapDataIndex,
bool  isTargetParams 
)
static

◆ pushCancelFinalizationCB()

static void pushCancelFinalizationCB ( SmallVectorImpl< llvm::BranchInst * > &  cancelTerminators,
llvm::IRBuilderBase &  llvmBuilder,
llvm::OpenMPIRBuilder &  ompBuilder,
mlir::Operation op,
llvm::omp::Directive  cancelDirective 
)
static

Shared implementation of a callback which adds a termiator for the new block created for the branch taken when an openmp construct is cancelled.

The terminator is saved in cancelTerminators. This callback is invoked only if there is cancellation inside of the taskgroup body. The terminator will need to be fixed to branch to the correct block to cleanup the construct.

Definition at line 2042 of file OpenMPToLLVMIRTranslation.cpp.

References constructIsCancellable().

Referenced by convertOmpTaskOp(), and convertOmpWsloop().

◆ setInsertPointForPossiblyEmptyBlock()

static void setInsertPointForPossiblyEmptyBlock ( llvm::IRBuilderBase &  builder,
llvm::BasicBlock *  block = nullptr 
)
static

◆ teamsReductionContainedInDistribute()

static bool teamsReductionContainedInDistribute ( omp::TeamsOp  teamsOp)
static

Definition at line 1886 of file OpenMPToLLVMIRTranslation.cpp.

References mlir::Operation::erase().

Referenced by convertOmpDistribute(), and convertOmpTeams().