14#ifndef LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
15#define LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
28#include <forward_list>
33class CanonicalLoopInfo;
35struct TargetRegionEntryInfo;
36class OffloadEntriesInfoManager;
102class OpenMPIRBuilderConfig {
108 std::optional<bool> IsTargetDevice;
118 std::optional<bool> IsGPU;
121 std::optional<bool> EmitLLVMUsedMetaInfo;
124 std::optional<bool> OpenMPOffloadMandatory;
127 std::optional<StringRef> FirstSeparator;
129 std::optional<StringRef> Separator;
132 std::optional<omp::GV> GridValue;
136 SmallVector<Triple> TargetTriples;
139 unsigned DefaultTargetAS = 0;
142 LLVM_ABI OpenMPIRBuilderConfig(
bool IsTargetDevice,
bool IsGPU,
143 bool OpenMPOffloadMandatory,
144 bool HasRequiresReverseOffload,
145 bool HasRequiresUnifiedAddress,
146 bool HasRequiresUnifiedSharedMemory,
147 bool HasRequiresDynamicAllocators);
150 bool isTargetDevice()
const {
151 assert(IsTargetDevice.has_value() &&
"IsTargetDevice is not set");
152 return *IsTargetDevice;
156 assert(IsGPU.has_value() &&
"IsGPU is not set");
160 bool openMPOffloadMandatory()
const {
161 assert(OpenMPOffloadMandatory.has_value() &&
162 "OpenMPOffloadMandatory is not set");
163 return *OpenMPOffloadMandatory;
167 assert(GridValue.has_value() &&
"GridValue is not set");
171 unsigned getDefaultTargetAS()
const {
return DefaultTargetAS; }
173 bool hasRequiresFlags()
const {
return RequiresFlags; }
174 LLVM_ABI bool hasRequiresReverseOffload()
const;
175 LLVM_ABI bool hasRequiresUnifiedAddress()
const;
176 LLVM_ABI bool hasRequiresUnifiedSharedMemory()
const;
177 LLVM_ABI bool hasRequiresDynamicAllocators()
const;
181 LLVM_ABI int64_t getRequiresFlags()
const;
185 StringRef firstSeparator()
const {
186 if (FirstSeparator.has_value())
187 return *FirstSeparator;
195 StringRef separator()
const {
196 if (Separator.has_value())
203 void setIsTargetDevice(
bool Value) { IsTargetDevice =
Value; }
205 void setEmitLLVMUsed(
bool Value =
true) { EmitLLVMUsedMetaInfo =
Value; }
206 void setOpenMPOffloadMandatory(
bool Value) { OpenMPOffloadMandatory =
Value; }
207 void setFirstSeparator(StringRef FS) { FirstSeparator =
FS; }
208 void setSeparator(StringRef S) { Separator = S; }
209 void setGridValue(omp::GV
G) { GridValue =
G; }
210 void setDefaultTargetAS(
unsigned AS) { DefaultTargetAS = AS; }
219 int64_t RequiresFlags;
224struct TargetRegionEntryInfo {
226 static constexpr const char *KernelNamePrefix =
"__omp_offloading_";
228 std::string ParentName;
234 TargetRegionEntryInfo() : DeviceID(0), FileID(0),
Line(0),
Count(0) {}
235 TargetRegionEntryInfo(StringRef ParentName,
unsigned DeviceID,
236 unsigned FileID,
unsigned Line,
unsigned Count = 0)
237 : ParentName(ParentName), DeviceID(DeviceID), FileID(FileID),
Line(
Line),
241 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name, StringRef ParentName,
242 unsigned DeviceID,
unsigned FileID,
unsigned Line,
245 bool operator<(
const TargetRegionEntryInfo &
RHS)
const {
246 return std::make_tuple(ParentName, DeviceID, FileID, Line, Count) <
247 std::make_tuple(
RHS.ParentName,
RHS.DeviceID,
RHS.FileID,
RHS.Line,
253class OffloadEntriesInfoManager {
255 OpenMPIRBuilder *OMPBuilder;
256 unsigned OffloadingEntriesNum = 0;
260 class OffloadEntryInfo {
263 enum OffloadingEntryInfoKinds :
unsigned {
265 OffloadingEntryInfoTargetRegion = 0,
267 OffloadingEntryInfoDeviceGlobalVar = 1,
269 OffloadingEntryInfoInvalid = ~0
u
273 OffloadEntryInfo() =
delete;
274 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) :
Kind(
Kind) {}
275 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind,
unsigned Order,
278 ~OffloadEntryInfo() =
default;
281 bool isValid()
const {
return Order != ~0
u; }
282 unsigned getOrder()
const {
return Order; }
283 OffloadingEntryInfoKinds getKind()
const {
return Kind; }
285 void setFlags(uint32_t NewFlags) {
Flags = NewFlags; }
286 Constant *getAddress()
const {
return cast_or_null<Constant>(Addr); }
287 void setAddress(Constant *V) {
288 assert(!Addr.pointsToAliveValue() &&
"Address has been set before!");
291 static bool classof(
const OffloadEntryInfo *
Info) {
return true; }
301 unsigned Order = ~0
u;
303 OffloadingEntryInfoKinds
Kind = OffloadingEntryInfoInvalid;
309 unsigned size()
const {
return OffloadingEntriesNum; }
311 OffloadEntriesInfoManager(OpenMPIRBuilder *builder) : OMPBuilder(builder) {}
318 enum OMPTargetRegionEntryKind : uint32_t {
320 OMPTargetRegionEntryTargetRegion = 0x0,
324 class OffloadEntryInfoTargetRegion final :
public OffloadEntryInfo {
329 OffloadEntryInfoTargetRegion()
330 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
331 explicit OffloadEntryInfoTargetRegion(
unsigned Order, Constant *Addr,
333 OMPTargetRegionEntryKind Flags)
334 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order,
Flags),
340 void setID(Constant *V) {
341 assert(!ID &&
"ID has been set before!");
344 static bool classof(
const OffloadEntryInfo *
Info) {
345 return Info->getKind() == OffloadingEntryInfoTargetRegion;
352 initializeTargetRegionEntryInfo(
const TargetRegionEntryInfo &EntryInfo,
355 LLVM_ABI void registerTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
356 Constant *Addr, Constant *ID,
357 OMPTargetRegionEntryKind Flags);
360 LLVM_ABI bool hasTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
361 bool IgnoreAddressId =
false)
const;
365 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name,
366 const TargetRegionEntryInfo &EntryInfo);
369 typedef function_ref<void(
const TargetRegionEntryInfo &EntryInfo,
370 const OffloadEntryInfoTargetRegion &)>
371 OffloadTargetRegionEntryInfoActTy;
373 actOnTargetRegionEntriesInfo(
const OffloadTargetRegionEntryInfoActTy &Action);
380 enum OMPTargetGlobalVarEntryKind : uint32_t {
382 OMPTargetGlobalVarEntryTo = 0x0,
384 OMPTargetGlobalVarEntryLink = 0x1,
386 OMPTargetGlobalVarEntryEnter = 0x2,
388 OMPTargetGlobalVarEntryNone = 0x3,
390 OMPTargetGlobalVarEntryIndirect = 0x8,
392 OMPTargetGlobalRegisterRequires = 0x10,
400 enum OMPTargetDeviceClauseKind : uint32_t {
402 OMPTargetDeviceClauseAny = 0x0,
404 OMPTargetDeviceClauseNoHost = 0x1,
406 OMPTargetDeviceClauseHost = 0x2,
408 OMPTargetDeviceClauseNone = 0x3
412 class OffloadEntryInfoDeviceGlobalVar final :
public OffloadEntryInfo {
415 GlobalValue::LinkageTypes
Linkage;
419 OffloadEntryInfoDeviceGlobalVar()
420 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
421 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order,
422 OMPTargetGlobalVarEntryKind Flags)
423 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags) {}
424 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order, Constant *Addr,
426 OMPTargetGlobalVarEntryKind Flags,
427 GlobalValue::LinkageTypes
Linkage,
428 const std::string &VarName)
429 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags),
434 int64_t getVarSize()
const {
return VarSize; }
436 void setVarSize(int64_t
Size) { VarSize =
Size; }
437 GlobalValue::LinkageTypes getLinkage()
const {
return Linkage; }
438 void setLinkage(GlobalValue::LinkageTypes LT) {
Linkage =
LT; }
439 static bool classof(
const OffloadEntryInfo *
Info) {
440 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
446 LLVM_ABI void initializeDeviceGlobalVarEntryInfo(
447 StringRef Name, OMPTargetGlobalVarEntryKind Flags,
unsigned Order);
450 LLVM_ABI void registerDeviceGlobalVarEntryInfo(
451 StringRef VarName, Constant *Addr, int64_t VarSize,
452 OMPTargetGlobalVarEntryKind Flags, GlobalValue::LinkageTypes
Linkage);
454 bool hasDeviceGlobalVarEntryInfo(StringRef VarName)
const {
455 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
458 typedef function_ref<void(StringRef,
const OffloadEntryInfoDeviceGlobalVar &)>
459 OffloadDeviceGlobalVarEntryInfoActTy;
460 LLVM_ABI void actOnDeviceGlobalVarEntriesInfo(
461 const OffloadDeviceGlobalVarEntryInfoActTy &Action);
466 getTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo)
const;
470 incrementTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo);
472 static TargetRegionEntryInfo
473 getTargetRegionEntryCountKey(
const TargetRegionEntryInfo &EntryInfo) {
474 return TargetRegionEntryInfo(EntryInfo.ParentName, EntryInfo.DeviceID,
475 EntryInfo.FileID, EntryInfo.Line, 0);
479 std::map<TargetRegionEntryInfo, unsigned> OffloadEntriesTargetRegionCount;
482 typedef std::map<TargetRegionEntryInfo, OffloadEntryInfoTargetRegion>
483 OffloadEntriesTargetRegionTy;
484 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
487 typedef StringMap<OffloadEntryInfoDeviceGlobalVar>
488 OffloadEntriesDeviceGlobalVarTy;
489 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
495class OpenMPIRBuilder {
499 OpenMPIRBuilder(
Module &M)
501 T(
M.getTargetTriple()), IsFinalized(
false) {}
504 class AtomicInfo :
public llvm::AtomicInfo {
508 AtomicInfo(IRBuilder<> *Builder, llvm::Type *Ty, uint64_t AtomicSizeInBits,
509 uint64_t ValueSizeInBits, llvm::Align AtomicAlign,
510 llvm::Align ValueAlign,
bool UseLibcall,
511 IRBuilderBase::InsertPoint AllocaIP,
llvm::Value *AtomicVar)
512 : llvm::AtomicInfo(Builder, Ty, AtomicSizeInBits, ValueSizeInBits,
513 AtomicAlign, ValueAlign, UseLibcall, AllocaIP),
514 AtomicVar(AtomicVar) {}
516 llvm::Value *getAtomicPointer()
const override {
return AtomicVar; }
517 void decorateWithTBAA(llvm::Instruction *
I)
override {}
518 llvm::AllocaInst *CreateAlloca(llvm::Type *Ty,
519 const llvm::Twine &Name)
const override {
520 llvm::AllocaInst *allocaInst = Builder->CreateAlloca(Ty);
531 void setConfig(OpenMPIRBuilderConfig
C) { Config =
C; }
543 LLVM_ABI void addAttributes(omp::RuntimeFunction FnID, Function &Fn);
546 using InsertPointTy = IRBuilder<>::InsertPoint;
549 using InsertPointOrErrorTy = Expected<InsertPointTy>;
560 createPlatformSpecificName(ArrayRef<StringRef> Parts)
const;
570 using FinalizeCallbackTy = std::function<
Error(InsertPointTy CodeGenIP)>;
572 struct FinalizationInfo {
575 FinalizeCallbackTy FiniCB;
588 void pushFinalizationCB(
const FinalizationInfo &FI) {
589 FinalizationStack.push_back(FI);
595 void popFinalizationCB() { FinalizationStack.pop_back(); }
623 using BodyGenCallbackTy =
624 function_ref<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
632 using StorableBodyGenCallbackTy =
633 std::function<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
645 using LoopBodyGenCallbackTy =
646 function_ref<
Error(InsertPointTy CodeGenIP,
Value *IndVar)>;
666 using PrivatizeCallbackTy = function_ref<InsertPointOrErrorTy(
667 InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
Value &Original,
672 struct LocationDescription {
673 LocationDescription(
const IRBuilderBase &IRB)
674 : IP(IRB.saveIP()),
DL(IRB.getCurrentDebugLocation()) {}
675 LocationDescription(
const InsertPointTy &IP) : IP(IP) {}
676 LocationDescription(
const InsertPointTy &IP,
const DebugLoc &
DL)
696 LLVM_ABI InsertPointOrErrorTy createBarrier(
const LocationDescription &Loc,
698 bool ForceSimpleCall =
false,
699 bool CheckCancelFlag =
true);
708 LLVM_ABI InsertPointOrErrorTy createCancel(
const LocationDescription &Loc,
710 omp::Directive CanceledDirective);
718 LLVM_ABI InsertPointOrErrorTy createCancellationPoint(
719 const LocationDescription &Loc, omp::Directive CanceledDirective);
722 LLVM_ABI Expected<ScanInfo *> scanInfoInitialize();
737 LLVM_ABI InsertPointOrErrorTy createParallel(
738 const LocationDescription &Loc, InsertPointTy AllocaIP,
739 BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
740 FinalizeCallbackTy FiniCB,
Value *IfCondition,
Value *NumThreads,
741 omp::ProcBindKind ProcBind,
bool IsCancellable);
762 LLVM_ABI Expected<CanonicalLoopInfo *>
763 createCanonicalLoop(
const LocationDescription &Loc,
764 LoopBodyGenCallbackTy BodyGenCB,
Value *TripCount,
765 const Twine &Name =
"loop");
798 LLVM_ABI Expected<SmallVector<llvm::CanonicalLoopInfo *>>
799 createCanonicalScanLoops(
const LocationDescription &Loc,
800 LoopBodyGenCallbackTy BodyGenCB,
Value *Start,
802 bool InclusiveStop, InsertPointTy ComputeIP,
803 const Twine &Name, ScanInfo *ScanRedInfo);
846 const LocationDescription &Loc,
Value *Start,
Value *Stop,
Value *Step,
847 bool IsSigned,
bool InclusiveStop,
const Twine &Name =
"loop");
879 LLVM_ABI Expected<CanonicalLoopInfo *> createCanonicalLoop(
880 const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB,
881 Value *Start,
Value *Stop,
Value *Step,
bool IsSigned,
bool InclusiveStop,
882 InsertPointTy ComputeIP = {},
const Twine &
Name =
"loop",
883 bool InScan =
false, ScanInfo *ScanRedInfo =
nullptr);
945 LLVM_ABI CanonicalLoopInfo *collapseLoops(DebugLoc
DL,
946 ArrayRef<CanonicalLoopInfo *>
Loops,
947 InsertPointTy ComputeIP);
954 getOpenMPDefaultSimdAlign(
const Triple &TargetTriple,
955 const StringMap<bool> &Features);
992 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
993 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
994 bool IsDeclaration,
bool IsExternallyVisible,
995 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
996 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
997 std::vector<Triple> TargetTriple,
Type *LlvmPtrTy,
998 std::function<Constant *()> GlobalInitializer,
999 std::function<GlobalValue::LinkageTypes()> VariableLinkage);
1035 LLVM_ABI void registerTargetGlobalVariable(
1036 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
1037 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
1038 bool IsDeclaration,
bool IsExternallyVisible,
1039 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
1040 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
1041 std::vector<Triple> TargetTriple,
1042 std::function<Constant *()> GlobalInitializer,
1043 std::function<GlobalValue::LinkageTypes()> VariableLinkage,
1044 Type *LlvmPtrTy, Constant *Addr);
1047 LLVM_ABI unsigned getFlagMemberOffset();
1056 LLVM_ABI omp::OpenMPOffloadMappingFlags getMemberOfFlag(
unsigned Position);
1068 setCorrectMemberOfFlag(omp::OpenMPOffloadMappingFlags &Flags,
1069 omp::OpenMPOffloadMappingFlags MemberOfFlag);
1091 InsertPointTy applyWorkshareLoopTarget(DebugLoc
DL, CanonicalLoopInfo *CLI,
1092 InsertPointTy AllocaIP,
1093 omp::WorksharingLoopType LoopType,
1115 InsertPointOrErrorTy applyStaticWorkshareLoop(
1116 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1117 omp::WorksharingLoopType LoopType,
bool NeedsBarrier);
1132 InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(DebugLoc
DL,
1133 CanonicalLoopInfo *CLI,
1134 InsertPointTy AllocaIP,
1158 InsertPointOrErrorTy applyDynamicWorkshareLoop(DebugLoc
DL,
1159 CanonicalLoopInfo *CLI,
1160 InsertPointTy AllocaIP,
1161 omp::OMPScheduleType SchedType,
1163 Value *Chunk =
nullptr);
1176 void createIfVersion(CanonicalLoopInfo *Loop,
Value *IfCond,
1177 ValueMap<const Value *, WeakTrackingVH> &VMap,
1178 LoopAnalysis &LIA, LoopInfo &LI, llvm::Loop *L,
1179 const Twine &NamePrefix =
"");
1217 LLVM_ABI InsertPointOrErrorTy applyWorkshareLoop(
1218 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1220 llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default,
1221 Value *ChunkSize =
nullptr,
bool HasSimdModifier =
false,
1222 bool HasMonotonicModifier =
false,
bool HasNonmonotonicModifier =
false,
1223 bool HasOrderedClause =
false,
1224 omp::WorksharingLoopType LoopType =
1225 omp::WorksharingLoopType::ForStaticLoop,
1226 bool NoLoop =
false);
1271 LLVM_ABI std::vector<CanonicalLoopInfo *>
1272 tileLoops(DebugLoc
DL, ArrayRef<CanonicalLoopInfo *>
Loops,
1273 ArrayRef<Value *> TileSizes);
1283 LLVM_ABI void unrollLoopFull(DebugLoc
DL, CanonicalLoopInfo *Loop);
1290 LLVM_ABI void unrollLoopHeuristic(DebugLoc
DL, CanonicalLoopInfo *Loop);
1314 LLVM_ABI void unrollLoopPartial(DebugLoc
DL, CanonicalLoopInfo *Loop,
1316 CanonicalLoopInfo **UnrolledCLI);
1331 LLVM_ABI void applySimd(CanonicalLoopInfo *Loop,
1332 MapVector<Value *, Value *> AlignedVars,
1333 Value *IfCond, omp::OrderKind Order,
1334 ConstantInt *Simdlen, ConstantInt *Safelen);
1339 LLVM_ABI void createFlush(
const LocationDescription &Loc);
1344 LLVM_ABI void createTaskwait(
const LocationDescription &Loc);
1349 LLVM_ABI void createTaskyield(
const LocationDescription &Loc);
1353 omp::RTLDependenceKindTy DepKind = omp::RTLDependenceKindTy::DepUnknown;
1356 explicit DependData() =
default;
1357 DependData(omp::RTLDependenceKindTy DepKind,
Type *DepValueType,
1359 : DepKind(DepKind), DepValueType(DepValueType), DepVal(DepVal) {}
1382 createTask(
const LocationDescription &Loc, InsertPointTy AllocaIP,
1383 BodyGenCallbackTy BodyGenCB,
bool Tied =
true,
1384 Value *Final =
nullptr,
Value *IfCondition =
nullptr,
1385 SmallVector<DependData> Dependencies = {},
bool Mergeable =
false,
1386 Value *EventHandle =
nullptr,
Value *Priority =
nullptr);
1393 LLVM_ABI InsertPointOrErrorTy createTaskgroup(
const LocationDescription &Loc,
1394 InsertPointTy AllocaIP,
1395 BodyGenCallbackTy BodyGenCB);
1397 using FileIdentifierInfoCallbackTy =
1398 std::function<std::tuple<std::string, uint64_t>()>;
1407 LLVM_ABI static TargetRegionEntryInfo
1408 getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
1409 vfs::FileSystem &VFS, StringRef ParentName =
"");
1412 enum class ReductionGenCBKind { Clang, MLIR };
1424 using ReductionGenClangCBTy =
1425 std::function<InsertPointTy(InsertPointTy CodeGenIP,
unsigned Index,
1433 using ReductionGenCBTy = std::function<InsertPointOrErrorTy(
1440 using ReductionGenAtomicCBTy = std::function<InsertPointOrErrorTy(
1447 struct ReductionInfo {
1448 ReductionInfo(
Type *ElementType,
Value *Variable,
Value *PrivateVariable,
1449 EvalKind EvaluationKind, ReductionGenCBTy ReductionGen,
1450 ReductionGenClangCBTy ReductionGenClang,
1451 ReductionGenAtomicCBTy AtomicReductionGen)
1453 PrivateVariable(PrivateVariable), EvaluationKind(EvaluationKind),
1454 ReductionGen(ReductionGen), ReductionGenClang(ReductionGenClang),
1455 AtomicReductionGen(AtomicReductionGen) {}
1456 ReductionInfo(
Value *PrivateVariable)
1458 PrivateVariable(PrivateVariable), EvaluationKind(EvalKind::
Scalar),
1459 ReductionGen(), ReductionGenClang(), AtomicReductionGen() {}
1468 Value *PrivateVariable;
1471 EvalKind EvaluationKind;
1476 ReductionGenCBTy ReductionGen;
1481 ReductionGenClangCBTy ReductionGenClang;
1487 ReductionGenAtomicCBTy AtomicReductionGen;
1490 enum class CopyAction :
unsigned {
1498 struct CopyOptionsTy {
1499 Value *RemoteLaneOffset =
nullptr;
1500 Value *ScratchpadIndex =
nullptr;
1501 Value *ScratchpadWidth =
nullptr;
1507 Value *getGPUThreadID();
1510 Value *getGPUWarpSize();
1515 Value *getNVPTXWarpID();
1520 Value *getNVPTXLaneID();
1523 Value *castValueToType(InsertPointTy AllocaIP,
Value *From,
Type *ToType);
1527 Value *createRuntimeShuffleFunction(InsertPointTy AllocaIP,
Value *Element,
1531 void shuffleAndStore(InsertPointTy AllocaIP,
Value *SrcAddr,
Value *DstAddr,
1533 Type *ReductionArrayTy);
1537 void emitReductionListCopy(
1538 InsertPointTy AllocaIP, CopyAction Action,
Type *ReductionArrayTy,
1539 ArrayRef<ReductionInfo> ReductionInfos,
Value *SrcBase,
Value *DestBase,
1540 CopyOptionsTy CopyOptions = {
nullptr,
nullptr,
nullptr});
1615 Function *emitShuffleAndReduceFunction(
1616 ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1617 Function *ReduceFn, AttributeList FuncAttrs);
1627 Error emitScanBasedDirectiveIR(
1628 llvm::function_ref<
Error()> InputLoopGen,
1629 llvm::function_ref<
Error(LocationDescription Loc)> ScanLoopGen,
1630 ScanInfo *ScanRedInfo);
1635 void createScanBBs(ScanInfo *ScanRedInfo);
1645 Error emitScanBasedDirectiveDeclsIR(InsertPointTy AllocaIP,
1646 ArrayRef<llvm::Value *> ScanVars,
1647 ArrayRef<llvm::Type *> ScanVarsType,
1648 ScanInfo *ScanRedInfo);
1656 Error emitScanBasedDirectiveFinalsIR(
1657 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1658 ScanInfo *ScanInfo);
1679 Expected<Function *>
1680 emitInterWarpCopyFunction(
const LocationDescription &Loc,
1681 ArrayRef<ReductionInfo> ReductionInfos,
1682 AttributeList FuncAttrs);
1697 Function *emitListToGlobalCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1698 Type *ReductionsBufferTy,
1699 AttributeList FuncAttrs);
1714 Function *emitGlobalToListCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1715 Type *ReductionsBufferTy,
1716 AttributeList FuncAttrs);
1736 emitListToGlobalReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1737 Function *ReduceFn,
Type *ReductionsBufferTy,
1738 AttributeList FuncAttrs);
1758 emitGlobalToListReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1759 Function *ReduceFn,
Type *ReductionsBufferTy,
1760 AttributeList FuncAttrs);
1763 std::string getReductionFuncName(StringRef Name)
const;
1774 Expected<Function *> createReductionFunction(
1775 StringRef ReducerName, ArrayRef<ReductionInfo> ReductionInfos,
1776 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
1777 AttributeList FuncAttrs = {});
2039 LLVM_ABI InsertPointOrErrorTy createReductionsGPU(
2040 const LocationDescription &Loc, InsertPointTy AllocaIP,
2041 InsertPointTy CodeGenIP, ArrayRef<ReductionInfo> ReductionInfos,
2042 bool IsNoWait =
false,
bool IsTeamsReduction =
false,
2043 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
2044 std::optional<omp::GV> GridValue = {},
unsigned ReductionBufNum = 1024,
2045 Value *SrcLocInfo =
nullptr);
2112 LLVM_ABI InsertPointOrErrorTy createReductions(
2113 const LocationDescription &Loc, InsertPointTy AllocaIP,
2114 ArrayRef<ReductionInfo> ReductionInfos, ArrayRef<bool> IsByRef,
2115 bool IsNoWait =
false,
bool IsTeamsReduction =
false);
2120 InsertPointTy getInsertionPoint() {
return Builder.saveIP(); }
2123 bool updateToLocation(
const LocationDescription &Loc) {
2124 Builder.restoreIP(Loc.IP);
2125 Builder.SetCurrentDebugLocation(Loc.DL);
2126 return Loc.IP.getBlock() !=
nullptr;
2131 omp::RuntimeFunction FnID);
2133 LLVM_ABI Function *getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID);
2137 uint32_t &SrcLocStrSize);
2145 StringRef FileName,
unsigned Line,
2147 uint32_t &SrcLocStrSize);
2152 Function *
F =
nullptr);
2156 uint32_t &SrcLocStrSize);
2161 uint32_t SrcLocStrSize,
2162 omp::IdentFlag Flags = omp::IdentFlag(0),
2163 unsigned Reserve2Flags = 0);
2167 LLVM_ABI GlobalValue *createGlobalFlag(
unsigned Value, StringRef Name);
2170 LLVM_ABI void emitUsed(StringRef Name, ArrayRef<llvm::WeakTrackingVH> List);
2174 emitKernelExecutionMode(StringRef KernelName, omp::OMPTgtExecModeFlags
Mode);
2184 omp::Directive CanceledDirective,
2185 FinalizeCallbackTy ExitCB = {});
2198 LLVM_ABI InsertPointTy emitTargetKernel(
const LocationDescription &Loc,
2199 InsertPointTy AllocaIP,
2203 ArrayRef<Value *> KernelArgs);
2208 LLVM_ABI void emitFlush(
const LocationDescription &Loc);
2213 SmallVector<FinalizationInfo, 8> FinalizationStack;
2217 bool isLastFinalizationInfoCancellable(omp::Directive DK) {
2218 return !FinalizationStack.empty() &&
2219 FinalizationStack.back().IsCancellable &&
2220 FinalizationStack.back().DK == DK;
2226 LLVM_ABI void emitTaskwaitImpl(
const LocationDescription &Loc);
2231 LLVM_ABI void emitTaskyieldImpl(
const LocationDescription &Loc);
2239 OpenMPIRBuilderConfig Config;
2245 IRBuilder<> Builder;
2248 StringMap<Constant *> SrcLocStrMap;
2251 DenseMap<std::pair<Constant *, uint64_t>,
Constant *> IdentMap;
2254 OffloadEntriesInfoManager OffloadInfoManager;
2261 struct OutlineInfo {
2262 using PostOutlineCBTy = std::function<void(Function &)>;
2263 PostOutlineCBTy PostOutlineCB;
2264 BasicBlock *EntryBB, *ExitBB, *OuterAllocaBB;
2265 SmallVector<Value *, 2> ExcludeArgsFromAggregate;
2270 SmallVectorImpl<BasicBlock *> &BlockVector);
2277 SmallVector<OutlineInfo, 16> OutlineInfos;
2282 SmallVector<llvm::Function *, 16> ConstantAllocaRaiseCandidates;
2286 std::forward_list<CanonicalLoopInfo> LoopInfos;
2289 std::forward_list<ScanInfo> ScanInfos;
2292 void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
2299 StringMap<GlobalVariable *, BumpPtrAllocator> InternalVars;
2306 LLVM_ABI void emitBranch(BasicBlock *Target);
2311 LLVM_ABI void emitBlock(BasicBlock *BB, Function *CurFn,
2312 bool IsFinished =
false);
2324 BodyGenCallbackTy ElseGen,
2325 InsertPointTy AllocaIP = {});
2329 createOffloadMaptypes(SmallVectorImpl<uint64_t> &Mappings,
2330 std::string VarName);
2334 createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
2335 std::string VarName);
2337 struct MapperAllocas {
2338 AllocaInst *ArgsBase =
nullptr;
2339 AllocaInst *
Args =
nullptr;
2340 AllocaInst *ArgSizes =
nullptr;
2344 LLVM_ABI void createMapperAllocas(
const LocationDescription &Loc,
2345 InsertPointTy AllocaIP,
2346 unsigned NumOperands,
2347 struct MapperAllocas &MapperAllocas);
2358 LLVM_ABI void emitMapperCall(
const LocationDescription &Loc,
2359 Function *MapperFunc,
Value *SrcLocInfo,
2361 struct MapperAllocas &MapperAllocas,
2362 int64_t DeviceID,
unsigned NumOperands);
2365 struct TargetDataRTArgs {
2367 Value *BasePointersArray =
nullptr;
2369 Value *PointersArray =
nullptr;
2371 Value *SizesArray =
nullptr;
2375 Value *MapTypesArray =
nullptr;
2379 Value *MapTypesArrayEnd =
nullptr;
2381 Value *MappersArray =
nullptr;
2384 Value *MapNamesArray =
nullptr;
2386 explicit TargetDataRTArgs() =
default;
2387 explicit TargetDataRTArgs(
Value *BasePointersArray,
Value *PointersArray,
2389 Value *MapTypesArrayEnd,
Value *MappersArray,
2390 Value *MapNamesArray)
2391 : BasePointersArray(BasePointersArray), PointersArray(PointersArray),
2392 SizesArray(SizesArray), MapTypesArray(MapTypesArray),
2393 MapTypesArrayEnd(MapTypesArrayEnd), MappersArray(MappersArray),
2394 MapNamesArray(MapNamesArray) {}
2404 struct TargetKernelDefaultAttrs {
2405 omp::OMPTgtExecModeFlags ExecFlags =
2406 omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
2407 SmallVector<int32_t, 3> MaxTeams = {-1};
2408 int32_t MinTeams = 1;
2410 int32_t MinThreads = 1;
2411 int32_t ReductionDataSize = 0;
2412 int32_t ReductionBufferLength = 0;
2420 struct TargetKernelRuntimeAttrs {
2421 SmallVector<Value *, 3> MaxTeams = {
nullptr};
2422 Value *MinTeams =
nullptr;
2423 SmallVector<Value *, 3> TargetThreadLimit = {
nullptr};
2424 SmallVector<Value *, 3> TeamsThreadLimit = {
nullptr};
2432 Value *LoopTripCount =
nullptr;
2437 struct TargetKernelArgs {
2439 unsigned NumTargetItems = 0;
2441 TargetDataRTArgs RTArgs;
2443 Value *NumIterations =
nullptr;
2445 ArrayRef<Value *> NumTeams;
2447 ArrayRef<Value *> NumThreads;
2449 Value *DynCGroupMem =
nullptr;
2451 bool HasNoWait =
false;
2453 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback =
2454 omp::OMPDynGroupprivateFallbackType::Abort;
2457 TargetKernelArgs() =
default;
2458 TargetKernelArgs(
unsigned NumTargetItems, TargetDataRTArgs RTArgs,
2459 Value *NumIterations, ArrayRef<Value *> NumTeams,
2460 ArrayRef<Value *> NumThreads,
Value *DynCGroupMem,
2462 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback)
2463 : NumTargetItems(NumTargetItems), RTArgs(RTArgs),
2464 NumIterations(NumIterations), NumTeams(NumTeams),
2465 NumThreads(NumThreads), DynCGroupMem(DynCGroupMem),
2466 HasNoWait(HasNoWait), DynCGroupMemFallback(DynCGroupMemFallback) {}
2472 LLVM_ABI static void getKernelArgsVector(TargetKernelArgs &KernelArgs,
2473 IRBuilderBase &Builder,
2474 SmallVector<Value *> &ArgsVector);
2478 class TargetDataInfo {
2480 bool RequiresDevicePointerInfo =
false;
2483 bool SeparateBeginEndCalls =
false;
2486 TargetDataRTArgs RTArgs;
2488 SmallMapVector<const Value *, std::pair<Value *, Value *>, 4>
2492 bool HasMapper =
false;
2494 unsigned NumberOfPtrs = 0
u;
2496 bool EmitDebug =
false;
2499 bool HasNoWait =
false;
2501 explicit TargetDataInfo() =
default;
2502 explicit TargetDataInfo(
bool RequiresDevicePointerInfo,
2503 bool SeparateBeginEndCalls)
2504 : RequiresDevicePointerInfo(RequiresDevicePointerInfo),
2505 SeparateBeginEndCalls(SeparateBeginEndCalls) {}
2507 void clearArrayInfo() {
2508 RTArgs = TargetDataRTArgs();
2514 return RTArgs.BasePointersArray && RTArgs.PointersArray &&
2515 RTArgs.SizesArray && RTArgs.MapTypesArray &&
2516 (!HasMapper || RTArgs.MappersArray) && NumberOfPtrs;
2518 bool requiresDevicePointerInfo() {
return RequiresDevicePointerInfo; }
2519 bool separateBeginEndCalls() {
return SeparateBeginEndCalls; }
2523 using MapValuesArrayTy = SmallVector<Value *, 4>;
2524 using MapDeviceInfoArrayTy = SmallVector<DeviceInfoTy, 4>;
2525 using MapFlagsArrayTy = SmallVector<omp::OpenMPOffloadMappingFlags, 4>;
2526 using MapNamesArrayTy = SmallVector<Constant *, 4>;
2527 using MapDimArrayTy = SmallVector<uint64_t, 4>;
2528 using MapNonContiguousArrayTy = SmallVector<MapValuesArrayTy, 4>;
2534 struct StructNonContiguousInfo {
2535 bool IsNonContiguous =
false;
2537 MapNonContiguousArrayTy
Offsets;
2538 MapNonContiguousArrayTy Counts;
2539 MapNonContiguousArrayTy Strides;
2541 MapValuesArrayTy BasePointers;
2542 MapValuesArrayTy Pointers;
2543 MapDeviceInfoArrayTy DevicePointers;
2544 MapValuesArrayTy
Sizes;
2545 MapFlagsArrayTy
Types;
2546 MapNamesArrayTy Names;
2547 StructNonContiguousInfo NonContigInfo;
2550 void append(MapInfosTy &CurInfo) {
2551 BasePointers.append(CurInfo.BasePointers.begin(),
2552 CurInfo.BasePointers.end());
2553 Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
2554 DevicePointers.append(CurInfo.DevicePointers.begin(),
2555 CurInfo.DevicePointers.end());
2556 Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
2557 Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
2558 Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
2559 NonContigInfo.Dims.append(CurInfo.NonContigInfo.Dims.begin(),
2560 CurInfo.NonContigInfo.Dims.end());
2561 NonContigInfo.Offsets.append(CurInfo.NonContigInfo.Offsets.begin(),
2562 CurInfo.NonContigInfo.Offsets.end());
2563 NonContigInfo.Counts.append(CurInfo.NonContigInfo.Counts.begin(),
2564 CurInfo.NonContigInfo.Counts.end());
2565 NonContigInfo.Strides.append(CurInfo.NonContigInfo.Strides.begin(),
2566 CurInfo.NonContigInfo.Strides.end());
2569 using MapInfosOrErrorTy = Expected<MapInfosTy &>;
2575 using EmitFallbackCallbackTy =
2576 function_ref<InsertPointOrErrorTy(InsertPointTy)>;
2580 using CustomMapperCallbackTy =
2581 function_ref<Expected<Function *>(
unsigned int)>;
2593 LLVM_ABI InsertPointOrErrorTy emitKernelLaunch(
2594 const LocationDescription &Loc,
Value *OutlinedFnID,
2595 EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args,
2596 Value *DeviceID,
Value *RTLoc, InsertPointTy AllocaIP);
2608 using TargetTaskBodyCallbackTy =
2610 IRBuilderBase::InsertPoint TargetTaskAllocaIP)>;
2622 LLVM_ABI InsertPointOrErrorTy emitTargetTask(
2623 TargetTaskBodyCallbackTy TaskBodyCB,
Value *DeviceID,
Value *RTLoc,
2624 OpenMPIRBuilder::InsertPointTy AllocaIP,
2625 const SmallVector<llvm::OpenMPIRBuilder::DependData> &Dependencies,
2626 const TargetDataRTArgs &RTArgs,
bool HasNoWait);
2632 LLVM_ABI void emitOffloadingArraysArgument(
2633 IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs,
2634 OpenMPIRBuilder::TargetDataInfo &
Info,
bool ForEndCall =
false);
2637 LLVM_ABI void emitNonContiguousDescriptor(InsertPointTy AllocaIP,
2638 InsertPointTy CodeGenIP,
2639 MapInfosTy &CombinedInfo,
2640 TargetDataInfo &
Info);
2648 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
2649 TargetDataInfo &
Info, CustomMapperCallbackTy CustomMapperCB,
2650 bool IsNonContiguous =
false,
2651 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2660 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &
Info,
2661 TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
2662 CustomMapperCallbackTy CustomMapperCB,
bool IsNonContiguous =
false,
2663 bool ForEndCall =
false,
2664 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2668 LLVM_ABI void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t
Size,
2669 int32_t Flags, GlobalValue::LinkageTypes,
2670 StringRef Name =
"");
2674 enum EmitMetadataErrorKind {
2675 EMIT_MD_TARGET_REGION_ERROR,
2676 EMIT_MD_DECLARE_TARGET_ERROR,
2677 EMIT_MD_GLOBAL_VAR_LINK_ERROR
2681 using EmitMetadataErrorReportFunctionTy =
2682 std::function<void(EmitMetadataErrorKind, TargetRegionEntryInfo)>;
2691 LLVM_ABI void createOffloadEntriesAndInfoMetadata(
2692 EmitMetadataErrorReportFunctionTy &ErrorReportFunction);
2705 LLVM_ABI InsertPointTy createCopyPrivate(
const LocationDescription &Loc,
2722 createSingle(
const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2723 FinalizeCallbackTy FiniCB,
bool IsNowait,
2724 ArrayRef<llvm::Value *> CPVars = {},
2725 ArrayRef<llvm::Function *> CPFuncs = {});
2734 LLVM_ABI InsertPointOrErrorTy createMaster(
const LocationDescription &Loc,
2735 BodyGenCallbackTy BodyGenCB,
2736 FinalizeCallbackTy FiniCB);
2745 LLVM_ABI InsertPointOrErrorTy createMasked(
const LocationDescription &Loc,
2746 BodyGenCallbackTy BodyGenCB,
2747 FinalizeCallbackTy FiniCB,
2768 LLVM_ABI InsertPointOrErrorTy emitScanReduction(
2769 const LocationDescription &Loc,
2770 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
2771 ScanInfo *ScanRedInfo);
2786 LLVM_ABI InsertPointOrErrorTy createScan(
const LocationDescription &Loc,
2787 InsertPointTy AllocaIP,
2788 ArrayRef<llvm::Value *> ScanVars,
2789 ArrayRef<llvm::Type *> ScanVarsType,
2791 ScanInfo *ScanRedInfo);
2802 LLVM_ABI InsertPointOrErrorTy createCritical(
const LocationDescription &Loc,
2803 BodyGenCallbackTy BodyGenCB,
2804 FinalizeCallbackTy FiniCB,
2805 StringRef CriticalName,
2819 createOrderedDepend(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2820 unsigned NumLoops, ArrayRef<llvm::Value *> StoreValues,
2821 const Twine &Name,
bool IsDependSource);
2832 LLVM_ABI InsertPointOrErrorTy createOrderedThreadsSimd(
2833 const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2834 FinalizeCallbackTy FiniCB,
bool IsThreads);
2848 createSections(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2849 ArrayRef<StorableBodyGenCallbackTy> SectionCBs,
2850 PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB,
2851 bool IsCancellable,
bool IsNowait);
2859 LLVM_ABI InsertPointOrErrorTy createSection(
const LocationDescription &Loc,
2860 BodyGenCallbackTy BodyGenCB,
2861 FinalizeCallbackTy FiniCB);
2875 LLVM_ABI InsertPointOrErrorTy createTeams(
const LocationDescription &Loc,
2876 BodyGenCallbackTy BodyGenCB,
2877 Value *NumTeamsLower =
nullptr,
2878 Value *NumTeamsUpper =
nullptr,
2879 Value *ThreadLimit =
nullptr,
2880 Value *IfExpr =
nullptr);
2887 LLVM_ABI InsertPointOrErrorTy createDistribute(
const LocationDescription &Loc,
2888 InsertPointTy AllocaIP,
2889 BodyGenCallbackTy BodyGenCB);
2903 LLVM_ABI InsertPointTy createCopyinClauseBlocks(InsertPointTy IP,
2906 llvm::IntegerType *IntPtrTy,
2907 bool BranchtoEnd =
true);
2928 LLVM_ABI CallInst *createOMPFree(
const LocationDescription &Loc,
Value *Addr,
2940 createCachedThreadPrivate(
const LocationDescription &Loc,
2942 const llvm::Twine &Name = Twine(
""));
2955 LLVM_ABI CallInst *createOMPInteropInit(
const LocationDescription &Loc,
2957 omp::OMPInteropType InteropType,
2959 Value *DependenceAddress,
2960 bool HaveNowaitClause);
2972 LLVM_ABI CallInst *createOMPInteropDestroy(
const LocationDescription &Loc,
2974 Value *NumDependences,
2975 Value *DependenceAddress,
2976 bool HaveNowaitClause);
2988 LLVM_ABI CallInst *createOMPInteropUse(
const LocationDescription &Loc,
2990 Value *NumDependences,
2991 Value *DependenceAddress,
2992 bool HaveNowaitClause);
3006 LLVM_ABI InsertPointTy createTargetInit(
3007 const LocationDescription &Loc,
3008 const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
3017 LLVM_ABI void createTargetDeinit(
const LocationDescription &Loc,
3018 int32_t TeamsReductionDataSize = 0,
3019 int32_t TeamsReductionBufferLength = 1024);
3029 LLVM_ABI static std::pair<int32_t, int32_t>
3030 readThreadBoundsForKernel(
const Triple &
T, Function &Kernel);
3031 LLVM_ABI static void writeThreadBoundsForKernel(
const Triple &
T,
3032 Function &Kernel, int32_t LB,
3037 LLVM_ABI static std::pair<int32_t, int32_t>
3038 readTeamBoundsForKernel(
const Triple &
T, Function &Kernel);
3039 LLVM_ABI static void writeTeamsForKernel(
const Triple &
T, Function &Kernel,
3040 int32_t LB, int32_t UB);
3045 void setOutlinedTargetRegionFunctionAttributes(Function *OutlinedFn);
3050 Constant *createOutlinedFunctionID(Function *OutlinedFn,
3051 StringRef EntryFnIDName);
3054 Constant *createTargetRegionEntryAddr(Function *OutlinedFunction,
3055 StringRef EntryFnName);
3059 using FunctionGenCallback =
3060 std::function<Expected<Function *>(StringRef FunctionName)>;
3094 TargetRegionEntryInfo &EntryInfo,
3095 FunctionGenCallback &GenerateFunctionCallback,
bool IsOffloadEntry,
3096 Function *&OutlinedFn, Constant *&OutlinedFnID);
3107 registerTargetRegionFunction(TargetRegionEntryInfo &EntryInfo,
3108 Function *OutlinedFunction,
3109 StringRef EntryFnName, StringRef EntryFnIDName);
3122 enum BodyGenTy { Priv, DupNoPriv, NoPriv };
3127 using GenMapInfoCallbackTy =
3128 function_ref<MapInfosTy &(InsertPointTy CodeGenIP)>;
3137 void emitUDMapperArrayInitOrDel(Function *MapperFn,
llvm::Value *MapperHandle,
3141 llvm::BasicBlock *ExitBB,
bool IsInit);
3184 LLVM_ABI Expected<Function *> emitUserDefinedMapper(
3185 function_ref<MapInfosOrErrorTy(
3187 PrivAndGenMapInfoCB,
3188 llvm::Type *ElemTy, StringRef FuncName,
3189 CustomMapperCallbackTy CustomMapperCB);
3208 LLVM_ABI InsertPointOrErrorTy createTargetData(
3209 const LocationDescription &Loc, InsertPointTy AllocaIP,
3210 InsertPointTy CodeGenIP,
Value *DeviceID,
Value *IfCond,
3211 TargetDataInfo &
Info, GenMapInfoCallbackTy GenMapInfoCB,
3212 CustomMapperCallbackTy CustomMapperCB,
3213 omp::RuntimeFunction *MapperFunc =
nullptr,
3214 function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
3215 BodyGenTy BodyGenType)>
3216 BodyGenCB =
nullptr,
3217 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr,
3218 Value *SrcLocInfo =
nullptr);
3220 using TargetBodyGenCallbackTy = function_ref<InsertPointOrErrorTy(
3221 InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
3223 using TargetGenArgAccessorsCallbackTy = function_ref<InsertPointOrErrorTy(
3224 Argument &Arg,
Value *Input,
Value *&RetVal, InsertPointTy AllocaIP,
3225 InsertPointTy CodeGenIP)>;
3255 LLVM_ABI InsertPointOrErrorTy createTarget(
3256 const LocationDescription &Loc,
bool IsOffloadEntry,
3257 OpenMPIRBuilder::InsertPointTy AllocaIP,
3258 OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetDataInfo &
Info,
3259 TargetRegionEntryInfo &EntryInfo,
3260 const TargetKernelDefaultAttrs &DefaultAttrs,
3261 const TargetKernelRuntimeAttrs &RuntimeAttrs,
Value *IfCond,
3262 SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
3263 TargetBodyGenCallbackTy BodyGenCB,
3264 TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
3265 CustomMapperCallbackTy CustomMapperCB,
3266 const SmallVector<DependData> &Dependencies,
bool HasNowait =
false,
3267 Value *DynCGroupMem =
nullptr,
3268 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback =
3269 omp::OMPDynGroupprivateFallbackType::Abort);
3274 LLVM_ABI FunctionCallee createForStaticInitFunction(
unsigned IVSize,
3276 bool IsGPUDistribute);
3280 LLVM_ABI FunctionCallee createDispatchInitFunction(
unsigned IVSize,
3285 LLVM_ABI FunctionCallee createDispatchNextFunction(
unsigned IVSize,
3290 LLVM_ABI FunctionCallee createDispatchFiniFunction(
unsigned IVSize,
3294 LLVM_ABI FunctionCallee createDispatchDeinitFunction();
3302#define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
3303#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
3304 ArrayType *VarName##Ty = nullptr; \
3305 PointerType *VarName##PtrTy = nullptr;
3306#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
3307 FunctionType *VarName = nullptr; \
3308 PointerType *VarName##Ptr = nullptr;
3309#define OMP_STRUCT_TYPE(VarName, StrName, ...) \
3310 StructType *VarName = nullptr; \
3311 PointerType *VarName##Ptr = nullptr;
3312#include "llvm/Frontend/OpenMP/OMPKinds.def"
3319 void initializeTypes(
Module &M);
3333 InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD,
Value *EntryCall,
3335 bool Conditional =
false);
3347 InsertPointOrErrorTy emitCommonDirectiveExit(omp::Directive OMPD,
3348 InsertPointTy FinIP,
3349 Instruction *ExitCall,
3350 bool HasFinalize =
true);
3368 InsertPointOrErrorTy
3369 EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
3370 Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
3371 FinalizeCallbackTy FiniCB,
bool Conditional =
false,
3372 bool HasFinalize =
true,
bool IsCancellable =
false);
3380 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
3381 StringRef FirstSeparator,
3382 StringRef Separator);
3389 Value *getOMPCriticalRegionLock(StringRef CriticalName);
3403 using AtomicUpdateCallbackTy =
3404 const function_ref<Expected<Value *>(
Value *XOld, IRBuilder<> &IRB)>;
3416 bool checkAndEmitFlushAfterAtomic(
const LocationDescription &Loc,
3417 AtomicOrdering AO, AtomicKind AK);
3443 Expected<std::pair<Value *, Value *>>
3444 emitAtomicUpdate(InsertPointTy AllocaIP,
Value *
X,
Type *XElemTy,
Value *Expr,
3445 AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3446 AtomicUpdateCallbackTy &UpdateOp,
bool VolatileX,
3447 bool IsXBinopExpr,
bool IsIgnoreDenormalMode,
3448 bool IsFineGrainedMemory,
bool IsRemoteMemory);
3454 AtomicRMWInst::BinOp RMWOp);
3460 struct AtomicOpValue {
3461 Value *Var =
nullptr;
3462 Type *ElemTy =
nullptr;
3463 bool IsSigned =
false;
3478 LLVM_ABI InsertPointTy createAtomicRead(
const LocationDescription &Loc,
3479 AtomicOpValue &
X, AtomicOpValue &V,
3481 InsertPointTy AllocaIP);
3493 LLVM_ABI InsertPointTy createAtomicWrite(
const LocationDescription &Loc,
3494 AtomicOpValue &
X,
Value *Expr,
3496 InsertPointTy AllocaIP);
3518 LLVM_ABI InsertPointOrErrorTy createAtomicUpdate(
3519 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3520 Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3521 AtomicUpdateCallbackTy &UpdateOp,
bool IsXBinopExpr,
3522 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3523 bool IsRemoteMemory =
false);
3554 LLVM_ABI InsertPointOrErrorTy createAtomicCapture(
3555 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3556 AtomicOpValue &V,
Value *Expr, AtomicOrdering AO,
3557 AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
3558 bool UpdateExpr,
bool IsPostfixUpdate,
bool IsXBinopExpr,
3559 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3560 bool IsRemoteMemory =
false);
3608 createAtomicCompare(
const LocationDescription &Loc, AtomicOpValue &
X,
3609 AtomicOpValue &V, AtomicOpValue &R,
Value *
E,
Value *
D,
3610 AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
3611 bool IsXBinopExpr,
bool IsPostfixUpdate,
bool IsFailOnly);
3612 LLVM_ABI InsertPointTy createAtomicCompare(
3613 const LocationDescription &Loc, AtomicOpValue &
X, AtomicOpValue &V,
3614 AtomicOpValue &R,
Value *
E,
Value *
D, AtomicOrdering AO,
3615 omp::OMPAtomicCompareOp Op,
bool IsXBinopExpr,
bool IsPostfixUpdate,
3616 bool IsFailOnly, AtomicOrdering Failure);
3634 LLVM_ABI CanonicalLoopInfo *createLoopSkeleton(DebugLoc
DL,
Value *TripCount,
3636 BasicBlock *PreInsertBefore,
3637 BasicBlock *PostInsertBefore,
3638 const Twine &Name = {});
3640 const std::string ompOffloadInfoName =
"omp_offload.info";
3657 LLVM_ABI void loadOffloadInfoMetadata(vfs::FileSystem &VFS,
3658 StringRef HostFilePath);
3667 getOrCreateInternalVariable(
Type *Ty,
const StringRef &Name,
3668 std::optional<unsigned> AddressSpace = {});
3769class CanonicalLoopInfo {
3770 friend class OpenMPIRBuilder;
3779 Value *LastIter =
nullptr;
3789 void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
3794 void setTripCount(
Value *TripCount);
3810 void mapIndVar(llvm::function_ref<
Value *(Instruction *)> Updater);
3814 void setLastIter(
Value *IterVar) { LastIter = std::move(IterVar); }
3823 Value *getLastIter() {
return LastIter; }
3828 bool isValid()
const {
return Header; }
3855 return cast<BranchInst>(
Cond->getTerminator())->getSuccessor(0);
3879 return Exit->getSingleSuccessor();
3885 Value *getTripCount()
const {
3888 assert(isa<CmpInst>(CmpI) &&
"First inst must compare IV with TripCount");
3889 return CmpI->getOperand(1);
3897 assert(isa<PHINode>(IndVarPHI) &&
"First inst must be the IV PHI");
3902 Type *getIndVarType()
const {
3904 return getIndVar()->getType();
3908 OpenMPIRBuilder::InsertPointTy getPreheaderIP()
const {
3911 return {Preheader, std::prev(Preheader->end())};
3915 OpenMPIRBuilder::InsertPointTy getBodyIP()
const {
3918 return {Body, Body->begin()};
3922 OpenMPIRBuilder::InsertPointTy getAfterIP()
const {
3925 return {After, After->begin()};
3930 return Header->getParent();
3988 llvm::BasicBlock *OMPBeforeScanBlock =
nullptr;
3991 llvm::BasicBlock *OMPAfterScanBlock =
nullptr;
3994 llvm::BasicBlock *OMPScanDispatch =
nullptr;
3997 llvm::BasicBlock *OMPScanLoopExit =
nullptr;
4000 llvm::BasicBlock *OMPScanInit =
nullptr;
4003 llvm::BasicBlock *OMPScanFinish =
nullptr;
4007 bool OMPFirstScanLoop =
false;
4011 llvm::SmallDenseMap<llvm::Value *, llvm::Value *> *ScanBuffPtrs;
4022 ScanBuffPtrs =
new llvm::SmallDenseMap<llvm::Value *, llvm::Value *>();
4024 ScanInfo(ScanInfo &) =
delete;
4025 ScanInfo &operator=(
const ScanInfo &) =
delete;
4027 ~ScanInfo() {
delete (ScanBuffPtrs); }
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis false
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
Module.h This file contains the declarations for the Module class.
static std::string getVarName(InstrProfInstBase *Inc, StringRef Prefix, bool &Renamed)
Get the name of a profiling variable for a particular function.
bool operator<(const DeltaInfo &LHS, int64_t Delta)
Machine Check Debug Module
This file defines constans and helpers used when dealing with OpenMP.
Provides definitions for Target specific Grid Values.
static const omp::GV & getGridValue(const Triple &T, Function *Kernel)
const SmallVectorImpl< MachineOperand > & Cond
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
std::unordered_set< BasicBlock * > BlockSet
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static uint32_t getFlags(const Symbol *Sym)
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static cl::opt< unsigned > MaxThreads("xcore-max-threads", cl::Optional, cl::desc("Maximum number of threads (for emulation thread-local storage)"), cl::Hidden, cl::value_desc("number"), cl::init(8))
static const uint32_t IV[8]
LLVM Basic Block Representation.
InsertPoint - A saved insertion point.
Common base class shared among various IRBuilders.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Analysis pass that exposes the LoopInfo for a function.
Represents a single loop in the control flow graph.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
The virtual file system interface.
LLVM_ABI bool isGPU(const Module &M)
Return true iff M target a GPU (and we can use GPU AS reasoning).
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ BasicBlock
Various leaf nodes.
ElementType
The element type of an SRV or UAV resource.
Context & getContext() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
FunctionAddr VTableAddr Count