14#ifndef LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
15#define LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
28#include <forward_list>
33class CanonicalLoopInfo;
35struct TargetRegionEntryInfo;
36class OffloadEntriesInfoManager;
98class OpenMPIRBuilderConfig {
104 std::optional<bool> IsTargetDevice;
114 std::optional<bool> IsGPU;
117 std::optional<bool> EmitLLVMUsedMetaInfo;
120 std::optional<bool> OpenMPOffloadMandatory;
123 std::optional<StringRef> FirstSeparator;
125 std::optional<StringRef> Separator;
128 std::optional<omp::GV> GridValue;
132 SmallVector<Triple> TargetTriples;
135 LLVM_ABI OpenMPIRBuilderConfig(
bool IsTargetDevice,
bool IsGPU,
136 bool OpenMPOffloadMandatory,
137 bool HasRequiresReverseOffload,
138 bool HasRequiresUnifiedAddress,
139 bool HasRequiresUnifiedSharedMemory,
140 bool HasRequiresDynamicAllocators);
143 bool isTargetDevice()
const {
144 assert(IsTargetDevice.has_value() &&
"IsTargetDevice is not set");
145 return *IsTargetDevice;
149 assert(IsGPU.has_value() &&
"IsGPU is not set");
153 bool openMPOffloadMandatory()
const {
154 assert(OpenMPOffloadMandatory.has_value() &&
155 "OpenMPOffloadMandatory is not set");
156 return *OpenMPOffloadMandatory;
160 assert(GridValue.has_value() &&
"GridValue is not set");
164 bool hasRequiresFlags()
const {
return RequiresFlags; }
165 LLVM_ABI bool hasRequiresReverseOffload()
const;
166 LLVM_ABI bool hasRequiresUnifiedAddress()
const;
167 LLVM_ABI bool hasRequiresUnifiedSharedMemory()
const;
168 LLVM_ABI bool hasRequiresDynamicAllocators()
const;
172 LLVM_ABI int64_t getRequiresFlags()
const;
176 StringRef firstSeparator()
const {
177 if (FirstSeparator.has_value())
178 return *FirstSeparator;
186 StringRef separator()
const {
187 if (Separator.has_value())
194 void setIsTargetDevice(
bool Value) { IsTargetDevice =
Value; }
196 void setEmitLLVMUsed(
bool Value =
true) { EmitLLVMUsedMetaInfo =
Value; }
197 void setOpenMPOffloadMandatory(
bool Value) { OpenMPOffloadMandatory =
Value; }
198 void setFirstSeparator(StringRef FS) { FirstSeparator =
FS; }
199 void setSeparator(StringRef S) { Separator = S; }
200 void setGridValue(omp::GV
G) { GridValue =
G; }
209 int64_t RequiresFlags;
214struct TargetRegionEntryInfo {
216 static constexpr const char *KernelNamePrefix =
"__omp_offloading_";
218 std::string ParentName;
224 TargetRegionEntryInfo() : DeviceID(0), FileID(0),
Line(0),
Count(0) {}
225 TargetRegionEntryInfo(StringRef ParentName,
unsigned DeviceID,
226 unsigned FileID,
unsigned Line,
unsigned Count = 0)
227 : ParentName(ParentName), DeviceID(DeviceID), FileID(FileID),
Line(
Line),
231 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name, StringRef ParentName,
232 unsigned DeviceID,
unsigned FileID,
unsigned Line,
235 bool operator<(
const TargetRegionEntryInfo &
RHS)
const {
236 return std::make_tuple(ParentName, DeviceID, FileID, Line, Count) <
237 std::make_tuple(
RHS.ParentName,
RHS.DeviceID,
RHS.FileID,
RHS.Line,
243class OffloadEntriesInfoManager {
245 OpenMPIRBuilder *OMPBuilder;
246 unsigned OffloadingEntriesNum = 0;
250 class OffloadEntryInfo {
253 enum OffloadingEntryInfoKinds :
unsigned {
255 OffloadingEntryInfoTargetRegion = 0,
257 OffloadingEntryInfoDeviceGlobalVar = 1,
259 OffloadingEntryInfoInvalid = ~0
u
263 OffloadEntryInfo() =
delete;
264 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) :
Kind(
Kind) {}
265 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind,
unsigned Order,
268 ~OffloadEntryInfo() =
default;
271 bool isValid()
const {
return Order != ~0
u; }
272 unsigned getOrder()
const {
return Order; }
273 OffloadingEntryInfoKinds getKind()
const {
return Kind; }
275 void setFlags(uint32_t NewFlags) {
Flags = NewFlags; }
276 Constant *getAddress()
const {
return cast_or_null<Constant>(Addr); }
277 void setAddress(Constant *V) {
278 assert(!Addr.pointsToAliveValue() &&
"Address has been set before!");
281 static bool classof(
const OffloadEntryInfo *
Info) {
return true; }
291 unsigned Order = ~0
u;
293 OffloadingEntryInfoKinds
Kind = OffloadingEntryInfoInvalid;
299 unsigned size()
const {
return OffloadingEntriesNum; }
301 OffloadEntriesInfoManager(OpenMPIRBuilder *builder) : OMPBuilder(builder) {}
308 enum OMPTargetRegionEntryKind : uint32_t {
310 OMPTargetRegionEntryTargetRegion = 0x0,
314 class OffloadEntryInfoTargetRegion final :
public OffloadEntryInfo {
319 OffloadEntryInfoTargetRegion()
320 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
321 explicit OffloadEntryInfoTargetRegion(
unsigned Order, Constant *Addr,
323 OMPTargetRegionEntryKind Flags)
324 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order,
Flags),
330 void setID(Constant *V) {
331 assert(!ID &&
"ID has been set before!");
334 static bool classof(
const OffloadEntryInfo *
Info) {
335 return Info->getKind() == OffloadingEntryInfoTargetRegion;
342 initializeTargetRegionEntryInfo(
const TargetRegionEntryInfo &EntryInfo,
345 LLVM_ABI void registerTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
346 Constant *Addr, Constant *ID,
347 OMPTargetRegionEntryKind Flags);
350 LLVM_ABI bool hasTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
351 bool IgnoreAddressId =
false)
const;
355 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name,
356 const TargetRegionEntryInfo &EntryInfo);
359 typedef function_ref<void(
const TargetRegionEntryInfo &EntryInfo,
360 const OffloadEntryInfoTargetRegion &)>
361 OffloadTargetRegionEntryInfoActTy;
363 actOnTargetRegionEntriesInfo(
const OffloadTargetRegionEntryInfoActTy &Action);
370 enum OMPTargetGlobalVarEntryKind : uint32_t {
372 OMPTargetGlobalVarEntryTo = 0x0,
374 OMPTargetGlobalVarEntryLink = 0x1,
376 OMPTargetGlobalVarEntryEnter = 0x2,
378 OMPTargetGlobalVarEntryNone = 0x3,
380 OMPTargetGlobalVarEntryIndirect = 0x8,
382 OMPTargetGlobalRegisterRequires = 0x10,
390 enum OMPTargetDeviceClauseKind : uint32_t {
392 OMPTargetDeviceClauseAny = 0x0,
394 OMPTargetDeviceClauseNoHost = 0x1,
396 OMPTargetDeviceClauseHost = 0x2,
398 OMPTargetDeviceClauseNone = 0x3
402 class OffloadEntryInfoDeviceGlobalVar final :
public OffloadEntryInfo {
405 GlobalValue::LinkageTypes
Linkage;
409 OffloadEntryInfoDeviceGlobalVar()
410 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
411 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order,
412 OMPTargetGlobalVarEntryKind Flags)
413 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags) {}
414 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order, Constant *Addr,
416 OMPTargetGlobalVarEntryKind Flags,
417 GlobalValue::LinkageTypes
Linkage,
418 const std::string &VarName)
419 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags),
424 int64_t getVarSize()
const {
return VarSize; }
426 void setVarSize(int64_t
Size) { VarSize =
Size; }
427 GlobalValue::LinkageTypes getLinkage()
const {
return Linkage; }
428 void setLinkage(GlobalValue::LinkageTypes LT) {
Linkage =
LT; }
429 static bool classof(
const OffloadEntryInfo *
Info) {
430 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
436 LLVM_ABI void initializeDeviceGlobalVarEntryInfo(
437 StringRef Name, OMPTargetGlobalVarEntryKind Flags,
unsigned Order);
440 LLVM_ABI void registerDeviceGlobalVarEntryInfo(
441 StringRef VarName, Constant *Addr, int64_t VarSize,
442 OMPTargetGlobalVarEntryKind Flags, GlobalValue::LinkageTypes
Linkage);
444 bool hasDeviceGlobalVarEntryInfo(StringRef VarName)
const {
445 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
448 typedef function_ref<void(StringRef,
const OffloadEntryInfoDeviceGlobalVar &)>
449 OffloadDeviceGlobalVarEntryInfoActTy;
450 LLVM_ABI void actOnDeviceGlobalVarEntriesInfo(
451 const OffloadDeviceGlobalVarEntryInfoActTy &Action);
456 getTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo)
const;
460 incrementTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo);
462 static TargetRegionEntryInfo
463 getTargetRegionEntryCountKey(
const TargetRegionEntryInfo &EntryInfo) {
464 return TargetRegionEntryInfo(EntryInfo.ParentName, EntryInfo.DeviceID,
465 EntryInfo.FileID, EntryInfo.Line, 0);
469 std::map<TargetRegionEntryInfo, unsigned> OffloadEntriesTargetRegionCount;
472 typedef std::map<TargetRegionEntryInfo, OffloadEntryInfoTargetRegion>
473 OffloadEntriesTargetRegionTy;
474 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
477 typedef StringMap<OffloadEntryInfoDeviceGlobalVar>
478 OffloadEntriesDeviceGlobalVarTy;
479 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
485class OpenMPIRBuilder {
489 OpenMPIRBuilder(
Module &M)
491 T(
M.getTargetTriple()), IsFinalized(
false) {}
494 class AtomicInfo :
public llvm::AtomicInfo {
498 AtomicInfo(IRBuilder<> *Builder, llvm::Type *Ty, uint64_t AtomicSizeInBits,
499 uint64_t ValueSizeInBits, llvm::Align AtomicAlign,
500 llvm::Align ValueAlign,
bool UseLibcall,
501 IRBuilderBase::InsertPoint AllocaIP,
llvm::Value *AtomicVar)
502 : llvm::AtomicInfo(Builder, Ty, AtomicSizeInBits, ValueSizeInBits,
503 AtomicAlign, ValueAlign, UseLibcall, AllocaIP),
504 AtomicVar(AtomicVar) {}
506 llvm::Value *getAtomicPointer()
const override {
return AtomicVar; }
507 void decorateWithTBAA(llvm::Instruction *
I)
override {}
508 llvm::AllocaInst *CreateAlloca(llvm::Type *Ty,
509 const llvm::Twine &Name)
const override {
510 llvm::AllocaInst *allocaInst = Builder->CreateAlloca(Ty);
521 void setConfig(OpenMPIRBuilderConfig
C) { Config =
C; }
533 LLVM_ABI void addAttributes(omp::RuntimeFunction FnID, Function &Fn);
536 using InsertPointTy = IRBuilder<>::InsertPoint;
539 using InsertPointOrErrorTy = Expected<InsertPointTy>;
550 createPlatformSpecificName(ArrayRef<StringRef> Parts)
const;
560 using FinalizeCallbackTy = std::function<
Error(InsertPointTy CodeGenIP)>;
562 struct FinalizationInfo {
565 FinalizeCallbackTy FiniCB;
578 void pushFinalizationCB(
const FinalizationInfo &FI) {
579 FinalizationStack.push_back(FI);
585 void popFinalizationCB() { FinalizationStack.pop_back(); }
613 using BodyGenCallbackTy =
614 function_ref<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
622 using StorableBodyGenCallbackTy =
623 std::function<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
635 using LoopBodyGenCallbackTy =
636 function_ref<
Error(InsertPointTy CodeGenIP,
Value *IndVar)>;
656 using PrivatizeCallbackTy = function_ref<InsertPointOrErrorTy(
657 InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
Value &Original,
662 struct LocationDescription {
663 LocationDescription(
const IRBuilderBase &IRB)
664 : IP(IRB.saveIP()),
DL(IRB.getCurrentDebugLocation()) {}
665 LocationDescription(
const InsertPointTy &IP) : IP(IP) {}
666 LocationDescription(
const InsertPointTy &IP,
const DebugLoc &
DL)
686 LLVM_ABI InsertPointOrErrorTy createBarrier(
const LocationDescription &Loc,
688 bool ForceSimpleCall =
false,
689 bool CheckCancelFlag =
true);
698 LLVM_ABI InsertPointOrErrorTy createCancel(
const LocationDescription &Loc,
700 omp::Directive CanceledDirective);
708 LLVM_ABI InsertPointOrErrorTy createCancellationPoint(
709 const LocationDescription &Loc, omp::Directive CanceledDirective);
712 LLVM_ABI Expected<ScanInfo *> scanInfoInitialize();
727 LLVM_ABI InsertPointOrErrorTy createParallel(
728 const LocationDescription &Loc, InsertPointTy AllocaIP,
729 BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
730 FinalizeCallbackTy FiniCB,
Value *IfCondition,
Value *NumThreads,
731 omp::ProcBindKind ProcBind,
bool IsCancellable);
752 LLVM_ABI Expected<CanonicalLoopInfo *>
753 createCanonicalLoop(
const LocationDescription &Loc,
754 LoopBodyGenCallbackTy BodyGenCB,
Value *TripCount,
755 const Twine &Name =
"loop");
788 LLVM_ABI Expected<SmallVector<llvm::CanonicalLoopInfo *>>
789 createCanonicalScanLoops(
const LocationDescription &Loc,
790 LoopBodyGenCallbackTy BodyGenCB,
Value *Start,
792 bool InclusiveStop, InsertPointTy ComputeIP,
793 const Twine &Name, ScanInfo *ScanRedInfo);
836 const LocationDescription &Loc,
Value *Start,
Value *Stop,
Value *Step,
837 bool IsSigned,
bool InclusiveStop,
const Twine &Name =
"loop");
869 LLVM_ABI Expected<CanonicalLoopInfo *> createCanonicalLoop(
870 const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB,
871 Value *Start,
Value *Stop,
Value *Step,
bool IsSigned,
bool InclusiveStop,
872 InsertPointTy ComputeIP = {},
const Twine &
Name =
"loop",
873 bool InScan =
false, ScanInfo *ScanRedInfo =
nullptr);
935 LLVM_ABI CanonicalLoopInfo *collapseLoops(DebugLoc
DL,
936 ArrayRef<CanonicalLoopInfo *>
Loops,
937 InsertPointTy ComputeIP);
944 getOpenMPDefaultSimdAlign(
const Triple &TargetTriple,
945 const StringMap<bool> &Features);
982 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
983 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
984 bool IsDeclaration,
bool IsExternallyVisible,
985 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
986 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
987 std::vector<Triple> TargetTriple,
Type *LlvmPtrTy,
988 std::function<Constant *()> GlobalInitializer,
989 std::function<GlobalValue::LinkageTypes()> VariableLinkage);
1025 LLVM_ABI void registerTargetGlobalVariable(
1026 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
1027 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
1028 bool IsDeclaration,
bool IsExternallyVisible,
1029 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
1030 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
1031 std::vector<Triple> TargetTriple,
1032 std::function<Constant *()> GlobalInitializer,
1033 std::function<GlobalValue::LinkageTypes()> VariableLinkage,
1034 Type *LlvmPtrTy, Constant *Addr);
1037 LLVM_ABI unsigned getFlagMemberOffset();
1046 LLVM_ABI omp::OpenMPOffloadMappingFlags getMemberOfFlag(
unsigned Position);
1058 setCorrectMemberOfFlag(omp::OpenMPOffloadMappingFlags &Flags,
1059 omp::OpenMPOffloadMappingFlags MemberOfFlag);
1080 InsertPointTy applyWorkshareLoopTarget(DebugLoc
DL, CanonicalLoopInfo *CLI,
1081 InsertPointTy AllocaIP,
1082 omp::WorksharingLoopType LoopType);
1103 InsertPointOrErrorTy applyStaticWorkshareLoop(
1104 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1105 omp::WorksharingLoopType LoopType,
bool NeedsBarrier);
1120 InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(DebugLoc
DL,
1121 CanonicalLoopInfo *CLI,
1122 InsertPointTy AllocaIP,
1146 InsertPointOrErrorTy applyDynamicWorkshareLoop(DebugLoc
DL,
1147 CanonicalLoopInfo *CLI,
1148 InsertPointTy AllocaIP,
1149 omp::OMPScheduleType SchedType,
1151 Value *Chunk =
nullptr);
1164 void createIfVersion(CanonicalLoopInfo *Loop,
Value *IfCond,
1165 ValueMap<const Value *, WeakTrackingVH> &VMap,
1166 LoopAnalysis &LIA, LoopInfo &LI, llvm::Loop *L,
1167 const Twine &NamePrefix =
"");
1204 LLVM_ABI InsertPointOrErrorTy applyWorkshareLoop(
1205 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1207 llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default,
1208 Value *ChunkSize =
nullptr,
bool HasSimdModifier =
false,
1209 bool HasMonotonicModifier =
false,
bool HasNonmonotonicModifier =
false,
1210 bool HasOrderedClause =
false,
1211 omp::WorksharingLoopType LoopType =
1212 omp::WorksharingLoopType::ForStaticLoop);
1257 LLVM_ABI std::vector<CanonicalLoopInfo *>
1258 tileLoops(DebugLoc
DL, ArrayRef<CanonicalLoopInfo *>
Loops,
1259 ArrayRef<Value *> TileSizes);
1269 LLVM_ABI void unrollLoopFull(DebugLoc
DL, CanonicalLoopInfo *Loop);
1276 LLVM_ABI void unrollLoopHeuristic(DebugLoc
DL, CanonicalLoopInfo *Loop);
1300 LLVM_ABI void unrollLoopPartial(DebugLoc
DL, CanonicalLoopInfo *Loop,
1302 CanonicalLoopInfo **UnrolledCLI);
1317 LLVM_ABI void applySimd(CanonicalLoopInfo *Loop,
1318 MapVector<Value *, Value *> AlignedVars,
1319 Value *IfCond, omp::OrderKind Order,
1320 ConstantInt *Simdlen, ConstantInt *Safelen);
1325 LLVM_ABI void createFlush(
const LocationDescription &Loc);
1330 LLVM_ABI void createTaskwait(
const LocationDescription &Loc);
1335 LLVM_ABI void createTaskyield(
const LocationDescription &Loc);
1339 omp::RTLDependenceKindTy DepKind = omp::RTLDependenceKindTy::DepUnknown;
1342 explicit DependData() =
default;
1343 DependData(omp::RTLDependenceKindTy DepKind,
Type *DepValueType,
1345 : DepKind(DepKind), DepValueType(DepValueType), DepVal(DepVal) {}
1368 createTask(
const LocationDescription &Loc, InsertPointTy AllocaIP,
1369 BodyGenCallbackTy BodyGenCB,
bool Tied =
true,
1370 Value *Final =
nullptr,
Value *IfCondition =
nullptr,
1371 SmallVector<DependData> Dependencies = {},
bool Mergeable =
false,
1372 Value *EventHandle =
nullptr,
Value *Priority =
nullptr);
1379 LLVM_ABI InsertPointOrErrorTy createTaskgroup(
const LocationDescription &Loc,
1380 InsertPointTy AllocaIP,
1381 BodyGenCallbackTy BodyGenCB);
1383 using FileIdentifierInfoCallbackTy =
1384 std::function<std::tuple<std::string, uint64_t>()>;
1393 LLVM_ABI static TargetRegionEntryInfo
1394 getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
1395 StringRef ParentName =
"");
1398 enum class ReductionGenCBKind { Clang, MLIR };
1410 using ReductionGenClangCBTy =
1411 std::function<InsertPointTy(InsertPointTy CodeGenIP,
unsigned Index,
1419 using ReductionGenCBTy = std::function<InsertPointOrErrorTy(
1426 using ReductionGenAtomicCBTy = std::function<InsertPointOrErrorTy(
1433 struct ReductionInfo {
1434 ReductionInfo(
Type *ElementType,
Value *Variable,
Value *PrivateVariable,
1435 EvalKind EvaluationKind, ReductionGenCBTy ReductionGen,
1436 ReductionGenClangCBTy ReductionGenClang,
1437 ReductionGenAtomicCBTy AtomicReductionGen)
1439 PrivateVariable(PrivateVariable), EvaluationKind(EvaluationKind),
1440 ReductionGen(ReductionGen), ReductionGenClang(ReductionGenClang),
1441 AtomicReductionGen(AtomicReductionGen) {}
1442 ReductionInfo(
Value *PrivateVariable)
1444 PrivateVariable(PrivateVariable), EvaluationKind(EvalKind::
Scalar),
1445 ReductionGen(), ReductionGenClang(), AtomicReductionGen() {}
1454 Value *PrivateVariable;
1457 EvalKind EvaluationKind;
1462 ReductionGenCBTy ReductionGen;
1467 ReductionGenClangCBTy ReductionGenClang;
1473 ReductionGenAtomicCBTy AtomicReductionGen;
1476 enum class CopyAction :
unsigned {
1484 struct CopyOptionsTy {
1485 Value *RemoteLaneOffset =
nullptr;
1486 Value *ScratchpadIndex =
nullptr;
1487 Value *ScratchpadWidth =
nullptr;
1493 Value *getGPUThreadID();
1496 Value *getGPUWarpSize();
1501 Value *getNVPTXWarpID();
1506 Value *getNVPTXLaneID();
1509 Value *castValueToType(InsertPointTy AllocaIP,
Value *From,
Type *ToType);
1513 Value *createRuntimeShuffleFunction(InsertPointTy AllocaIP,
Value *Element,
1517 void shuffleAndStore(InsertPointTy AllocaIP,
Value *SrcAddr,
Value *DstAddr,
1519 Type *ReductionArrayTy);
1523 void emitReductionListCopy(
1524 InsertPointTy AllocaIP, CopyAction Action,
Type *ReductionArrayTy,
1525 ArrayRef<ReductionInfo> ReductionInfos,
Value *SrcBase,
Value *DestBase,
1526 CopyOptionsTy CopyOptions = {
nullptr,
nullptr,
nullptr});
1601 Function *emitShuffleAndReduceFunction(
1602 ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1603 Function *ReduceFn, AttributeList FuncAttrs);
1613 Error emitScanBasedDirectiveIR(
1614 llvm::function_ref<
Error()> InputLoopGen,
1615 llvm::function_ref<
Error(LocationDescription Loc)> ScanLoopGen,
1616 ScanInfo *ScanRedInfo);
1621 void createScanBBs(ScanInfo *ScanRedInfo);
1631 Error emitScanBasedDirectiveDeclsIR(InsertPointTy AllocaIP,
1632 ArrayRef<llvm::Value *> ScanVars,
1633 ArrayRef<llvm::Type *> ScanVarsType,
1634 ScanInfo *ScanRedInfo);
1642 Error emitScanBasedDirectiveFinalsIR(
1643 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1644 ScanInfo *ScanInfo);
1665 Expected<Function *>
1666 emitInterWarpCopyFunction(
const LocationDescription &Loc,
1667 ArrayRef<ReductionInfo> ReductionInfos,
1668 AttributeList FuncAttrs);
1683 Function *emitListToGlobalCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1684 Type *ReductionsBufferTy,
1685 AttributeList FuncAttrs);
1700 Function *emitGlobalToListCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1701 Type *ReductionsBufferTy,
1702 AttributeList FuncAttrs);
1722 emitListToGlobalReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1723 Function *ReduceFn,
Type *ReductionsBufferTy,
1724 AttributeList FuncAttrs);
1744 emitGlobalToListReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1745 Function *ReduceFn,
Type *ReductionsBufferTy,
1746 AttributeList FuncAttrs);
1749 std::string getReductionFuncName(StringRef Name)
const;
1760 Expected<Function *> createReductionFunction(
1761 StringRef ReducerName, ArrayRef<ReductionInfo> ReductionInfos,
1762 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
1763 AttributeList FuncAttrs = {});
2025 LLVM_ABI InsertPointOrErrorTy createReductionsGPU(
2026 const LocationDescription &Loc, InsertPointTy AllocaIP,
2027 InsertPointTy CodeGenIP, ArrayRef<ReductionInfo> ReductionInfos,
2028 bool IsNoWait =
false,
bool IsTeamsReduction =
false,
2029 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
2030 std::optional<omp::GV> GridValue = {},
unsigned ReductionBufNum = 1024,
2031 Value *SrcLocInfo =
nullptr);
2098 LLVM_ABI InsertPointOrErrorTy createReductions(
2099 const LocationDescription &Loc, InsertPointTy AllocaIP,
2100 ArrayRef<ReductionInfo> ReductionInfos, ArrayRef<bool> IsByRef,
2101 bool IsNoWait =
false,
bool IsTeamsReduction =
false);
2106 InsertPointTy getInsertionPoint() {
return Builder.saveIP(); }
2109 bool updateToLocation(
const LocationDescription &Loc) {
2110 Builder.restoreIP(Loc.IP);
2111 Builder.SetCurrentDebugLocation(Loc.DL);
2112 return Loc.IP.getBlock() !=
nullptr;
2117 omp::RuntimeFunction FnID);
2119 LLVM_ABI Function *getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID);
2123 uint32_t &SrcLocStrSize);
2131 StringRef FileName,
unsigned Line,
2133 uint32_t &SrcLocStrSize);
2138 Function *
F =
nullptr);
2142 uint32_t &SrcLocStrSize);
2147 uint32_t SrcLocStrSize,
2148 omp::IdentFlag Flags = omp::IdentFlag(0),
2149 unsigned Reserve2Flags = 0);
2153 LLVM_ABI GlobalValue *createGlobalFlag(
unsigned Value, StringRef Name);
2156 LLVM_ABI void emitUsed(StringRef Name, ArrayRef<llvm::WeakTrackingVH> List);
2160 emitKernelExecutionMode(StringRef KernelName, omp::OMPTgtExecModeFlags
Mode);
2170 omp::Directive CanceledDirective,
2171 FinalizeCallbackTy ExitCB = {});
2184 LLVM_ABI InsertPointTy emitTargetKernel(
const LocationDescription &Loc,
2185 InsertPointTy AllocaIP,
2189 ArrayRef<Value *> KernelArgs);
2194 LLVM_ABI void emitFlush(
const LocationDescription &Loc);
2199 SmallVector<FinalizationInfo, 8> FinalizationStack;
2203 bool isLastFinalizationInfoCancellable(omp::Directive DK) {
2204 return !FinalizationStack.empty() &&
2205 FinalizationStack.back().IsCancellable &&
2206 FinalizationStack.back().DK == DK;
2212 LLVM_ABI void emitTaskwaitImpl(
const LocationDescription &Loc);
2217 LLVM_ABI void emitTaskyieldImpl(
const LocationDescription &Loc);
2225 OpenMPIRBuilderConfig Config;
2231 IRBuilder<> Builder;
2234 StringMap<Constant *> SrcLocStrMap;
2237 DenseMap<std::pair<Constant *, uint64_t>,
Constant *> IdentMap;
2240 OffloadEntriesInfoManager OffloadInfoManager;
2247 struct OutlineInfo {
2248 using PostOutlineCBTy = std::function<void(Function &)>;
2249 PostOutlineCBTy PostOutlineCB;
2250 BasicBlock *EntryBB, *ExitBB, *OuterAllocaBB;
2251 SmallVector<Value *, 2> ExcludeArgsFromAggregate;
2256 SmallVectorImpl<BasicBlock *> &BlockVector);
2263 SmallVector<OutlineInfo, 16> OutlineInfos;
2268 SmallVector<llvm::Function *, 16> ConstantAllocaRaiseCandidates;
2272 std::forward_list<CanonicalLoopInfo> LoopInfos;
2275 std::forward_list<ScanInfo> ScanInfos;
2278 void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
2285 StringMap<GlobalVariable *, BumpPtrAllocator> InternalVars;
2292 LLVM_ABI void emitBranch(BasicBlock *Target);
2297 LLVM_ABI void emitBlock(BasicBlock *BB, Function *CurFn,
2298 bool IsFinished =
false);
2310 BodyGenCallbackTy ElseGen,
2311 InsertPointTy AllocaIP = {});
2315 createOffloadMaptypes(SmallVectorImpl<uint64_t> &Mappings,
2316 std::string VarName);
2320 createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
2321 std::string VarName);
2323 struct MapperAllocas {
2324 AllocaInst *ArgsBase =
nullptr;
2325 AllocaInst *
Args =
nullptr;
2326 AllocaInst *ArgSizes =
nullptr;
2330 LLVM_ABI void createMapperAllocas(
const LocationDescription &Loc,
2331 InsertPointTy AllocaIP,
2332 unsigned NumOperands,
2333 struct MapperAllocas &MapperAllocas);
2344 LLVM_ABI void emitMapperCall(
const LocationDescription &Loc,
2345 Function *MapperFunc,
Value *SrcLocInfo,
2347 struct MapperAllocas &MapperAllocas,
2348 int64_t DeviceID,
unsigned NumOperands);
2351 struct TargetDataRTArgs {
2353 Value *BasePointersArray =
nullptr;
2355 Value *PointersArray =
nullptr;
2357 Value *SizesArray =
nullptr;
2361 Value *MapTypesArray =
nullptr;
2365 Value *MapTypesArrayEnd =
nullptr;
2367 Value *MappersArray =
nullptr;
2370 Value *MapNamesArray =
nullptr;
2372 explicit TargetDataRTArgs() {}
2373 explicit TargetDataRTArgs(
Value *BasePointersArray,
Value *PointersArray,
2375 Value *MapTypesArrayEnd,
Value *MappersArray,
2376 Value *MapNamesArray)
2377 : BasePointersArray(BasePointersArray), PointersArray(PointersArray),
2378 SizesArray(SizesArray), MapTypesArray(MapTypesArray),
2379 MapTypesArrayEnd(MapTypesArrayEnd), MappersArray(MappersArray),
2380 MapNamesArray(MapNamesArray) {}
2390 struct TargetKernelDefaultAttrs {
2391 omp::OMPTgtExecModeFlags ExecFlags =
2392 omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
2393 SmallVector<int32_t, 3> MaxTeams = {-1};
2394 int32_t MinTeams = 1;
2396 int32_t MinThreads = 1;
2397 int32_t ReductionDataSize = 0;
2398 int32_t ReductionBufferLength = 0;
2406 struct TargetKernelRuntimeAttrs {
2407 SmallVector<Value *, 3> MaxTeams = {
nullptr};
2408 Value *MinTeams =
nullptr;
2409 SmallVector<Value *, 3> TargetThreadLimit = {
nullptr};
2410 SmallVector<Value *, 3> TeamsThreadLimit = {
nullptr};
2418 Value *LoopTripCount =
nullptr;
2423 struct TargetKernelArgs {
2425 unsigned NumTargetItems = 0;
2427 TargetDataRTArgs RTArgs;
2429 Value *NumIterations =
nullptr;
2431 ArrayRef<Value *> NumTeams;
2433 ArrayRef<Value *> NumThreads;
2435 Value *DynCGGroupMem =
nullptr;
2437 bool HasNoWait =
false;
2440 TargetKernelArgs() {}
2441 TargetKernelArgs(
unsigned NumTargetItems, TargetDataRTArgs RTArgs,
2442 Value *NumIterations, ArrayRef<Value *> NumTeams,
2443 ArrayRef<Value *> NumThreads,
Value *DynCGGroupMem,
2445 : NumTargetItems(NumTargetItems), RTArgs(RTArgs),
2446 NumIterations(NumIterations), NumTeams(NumTeams),
2447 NumThreads(NumThreads), DynCGGroupMem(DynCGGroupMem),
2448 HasNoWait(HasNoWait) {}
2454 LLVM_ABI static void getKernelArgsVector(TargetKernelArgs &KernelArgs,
2455 IRBuilderBase &Builder,
2456 SmallVector<Value *> &ArgsVector);
2460 class TargetDataInfo {
2462 bool RequiresDevicePointerInfo =
false;
2465 bool SeparateBeginEndCalls =
false;
2468 TargetDataRTArgs RTArgs;
2470 SmallMapVector<const Value *, std::pair<Value *, Value *>, 4>
2474 bool HasMapper =
false;
2476 unsigned NumberOfPtrs = 0
u;
2478 bool EmitDebug =
false;
2481 bool HasNoWait =
false;
2483 explicit TargetDataInfo() {}
2484 explicit TargetDataInfo(
bool RequiresDevicePointerInfo,
2485 bool SeparateBeginEndCalls)
2486 : RequiresDevicePointerInfo(RequiresDevicePointerInfo),
2487 SeparateBeginEndCalls(SeparateBeginEndCalls) {}
2489 void clearArrayInfo() {
2490 RTArgs = TargetDataRTArgs();
2496 return RTArgs.BasePointersArray && RTArgs.PointersArray &&
2497 RTArgs.SizesArray && RTArgs.MapTypesArray &&
2498 (!HasMapper || RTArgs.MappersArray) && NumberOfPtrs;
2500 bool requiresDevicePointerInfo() {
return RequiresDevicePointerInfo; }
2501 bool separateBeginEndCalls() {
return SeparateBeginEndCalls; }
2505 using MapValuesArrayTy = SmallVector<Value *, 4>;
2506 using MapDeviceInfoArrayTy = SmallVector<DeviceInfoTy, 4>;
2507 using MapFlagsArrayTy = SmallVector<omp::OpenMPOffloadMappingFlags, 4>;
2508 using MapNamesArrayTy = SmallVector<Constant *, 4>;
2509 using MapDimArrayTy = SmallVector<uint64_t, 4>;
2510 using MapNonContiguousArrayTy = SmallVector<MapValuesArrayTy, 4>;
2516 struct StructNonContiguousInfo {
2517 bool IsNonContiguous =
false;
2519 MapNonContiguousArrayTy
Offsets;
2520 MapNonContiguousArrayTy Counts;
2521 MapNonContiguousArrayTy Strides;
2523 MapValuesArrayTy BasePointers;
2524 MapValuesArrayTy Pointers;
2525 MapDeviceInfoArrayTy DevicePointers;
2526 MapValuesArrayTy
Sizes;
2527 MapFlagsArrayTy
Types;
2528 MapNamesArrayTy Names;
2529 StructNonContiguousInfo NonContigInfo;
2532 void append(MapInfosTy &CurInfo) {
2533 BasePointers.append(CurInfo.BasePointers.begin(),
2534 CurInfo.BasePointers.end());
2535 Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
2536 DevicePointers.append(CurInfo.DevicePointers.begin(),
2537 CurInfo.DevicePointers.end());
2538 Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
2539 Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
2540 Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
2541 NonContigInfo.Dims.append(CurInfo.NonContigInfo.Dims.begin(),
2542 CurInfo.NonContigInfo.Dims.end());
2543 NonContigInfo.Offsets.append(CurInfo.NonContigInfo.Offsets.begin(),
2544 CurInfo.NonContigInfo.Offsets.end());
2545 NonContigInfo.Counts.append(CurInfo.NonContigInfo.Counts.begin(),
2546 CurInfo.NonContigInfo.Counts.end());
2547 NonContigInfo.Strides.append(CurInfo.NonContigInfo.Strides.begin(),
2548 CurInfo.NonContigInfo.Strides.end());
2551 using MapInfosOrErrorTy = Expected<MapInfosTy &>;
2557 using EmitFallbackCallbackTy =
2558 function_ref<InsertPointOrErrorTy(InsertPointTy)>;
2562 using CustomMapperCallbackTy =
2563 function_ref<Expected<Function *>(
unsigned int)>;
2575 LLVM_ABI InsertPointOrErrorTy emitKernelLaunch(
2576 const LocationDescription &Loc,
Value *OutlinedFnID,
2577 EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args,
2578 Value *DeviceID,
Value *RTLoc, InsertPointTy AllocaIP);
2590 using TargetTaskBodyCallbackTy =
2592 IRBuilderBase::InsertPoint TargetTaskAllocaIP)>;
2604 LLVM_ABI InsertPointOrErrorTy emitTargetTask(
2605 TargetTaskBodyCallbackTy TaskBodyCB,
Value *DeviceID,
Value *RTLoc,
2606 OpenMPIRBuilder::InsertPointTy AllocaIP,
2607 const SmallVector<llvm::OpenMPIRBuilder::DependData> &Dependencies,
2608 const TargetDataRTArgs &RTArgs,
bool HasNoWait);
2614 LLVM_ABI void emitOffloadingArraysArgument(
2615 IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs,
2616 OpenMPIRBuilder::TargetDataInfo &
Info,
bool ForEndCall =
false);
2619 LLVM_ABI void emitNonContiguousDescriptor(InsertPointTy AllocaIP,
2620 InsertPointTy CodeGenIP,
2621 MapInfosTy &CombinedInfo,
2622 TargetDataInfo &
Info);
2630 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
2631 TargetDataInfo &
Info, CustomMapperCallbackTy CustomMapperCB,
2632 bool IsNonContiguous =
false,
2633 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2642 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &
Info,
2643 TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
2644 CustomMapperCallbackTy CustomMapperCB,
bool IsNonContiguous =
false,
2645 bool ForEndCall =
false,
2646 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2650 LLVM_ABI void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t
Size,
2651 int32_t Flags, GlobalValue::LinkageTypes,
2652 StringRef Name =
"");
2656 enum EmitMetadataErrorKind {
2657 EMIT_MD_TARGET_REGION_ERROR,
2658 EMIT_MD_DECLARE_TARGET_ERROR,
2659 EMIT_MD_GLOBAL_VAR_LINK_ERROR
2663 using EmitMetadataErrorReportFunctionTy =
2664 std::function<void(EmitMetadataErrorKind, TargetRegionEntryInfo)>;
2673 LLVM_ABI void createOffloadEntriesAndInfoMetadata(
2674 EmitMetadataErrorReportFunctionTy &ErrorReportFunction);
2687 LLVM_ABI InsertPointTy createCopyPrivate(
const LocationDescription &Loc,
2704 createSingle(
const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2705 FinalizeCallbackTy FiniCB,
bool IsNowait,
2706 ArrayRef<llvm::Value *> CPVars = {},
2707 ArrayRef<llvm::Function *> CPFuncs = {});
2716 LLVM_ABI InsertPointOrErrorTy createMaster(
const LocationDescription &Loc,
2717 BodyGenCallbackTy BodyGenCB,
2718 FinalizeCallbackTy FiniCB);
2727 LLVM_ABI InsertPointOrErrorTy createMasked(
const LocationDescription &Loc,
2728 BodyGenCallbackTy BodyGenCB,
2729 FinalizeCallbackTy FiniCB,
2750 LLVM_ABI InsertPointOrErrorTy emitScanReduction(
2751 const LocationDescription &Loc,
2752 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
2753 ScanInfo *ScanRedInfo);
2768 LLVM_ABI InsertPointOrErrorTy createScan(
const LocationDescription &Loc,
2769 InsertPointTy AllocaIP,
2770 ArrayRef<llvm::Value *> ScanVars,
2771 ArrayRef<llvm::Type *> ScanVarsType,
2773 ScanInfo *ScanRedInfo);
2784 LLVM_ABI InsertPointOrErrorTy createCritical(
const LocationDescription &Loc,
2785 BodyGenCallbackTy BodyGenCB,
2786 FinalizeCallbackTy FiniCB,
2787 StringRef CriticalName,
2801 createOrderedDepend(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2802 unsigned NumLoops, ArrayRef<llvm::Value *> StoreValues,
2803 const Twine &Name,
bool IsDependSource);
2814 LLVM_ABI InsertPointOrErrorTy createOrderedThreadsSimd(
2815 const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2816 FinalizeCallbackTy FiniCB,
bool IsThreads);
2830 createSections(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2831 ArrayRef<StorableBodyGenCallbackTy> SectionCBs,
2832 PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB,
2833 bool IsCancellable,
bool IsNowait);
2841 LLVM_ABI InsertPointOrErrorTy createSection(
const LocationDescription &Loc,
2842 BodyGenCallbackTy BodyGenCB,
2843 FinalizeCallbackTy FiniCB);
2857 LLVM_ABI InsertPointOrErrorTy createTeams(
const LocationDescription &Loc,
2858 BodyGenCallbackTy BodyGenCB,
2859 Value *NumTeamsLower =
nullptr,
2860 Value *NumTeamsUpper =
nullptr,
2861 Value *ThreadLimit =
nullptr,
2862 Value *IfExpr =
nullptr);
2869 LLVM_ABI InsertPointOrErrorTy createDistribute(
const LocationDescription &Loc,
2870 InsertPointTy AllocaIP,
2871 BodyGenCallbackTy BodyGenCB);
2885 LLVM_ABI InsertPointTy createCopyinClauseBlocks(InsertPointTy IP,
2888 llvm::IntegerType *IntPtrTy,
2889 bool BranchtoEnd =
true);
2910 LLVM_ABI CallInst *createOMPFree(
const LocationDescription &Loc,
Value *Addr,
2922 createCachedThreadPrivate(
const LocationDescription &Loc,
2924 const llvm::Twine &Name = Twine(
""));
2937 LLVM_ABI CallInst *createOMPInteropInit(
const LocationDescription &Loc,
2939 omp::OMPInteropType InteropType,
2941 Value *DependenceAddress,
2942 bool HaveNowaitClause);
2954 LLVM_ABI CallInst *createOMPInteropDestroy(
const LocationDescription &Loc,
2956 Value *NumDependences,
2957 Value *DependenceAddress,
2958 bool HaveNowaitClause);
2970 LLVM_ABI CallInst *createOMPInteropUse(
const LocationDescription &Loc,
2972 Value *NumDependences,
2973 Value *DependenceAddress,
2974 bool HaveNowaitClause);
2988 LLVM_ABI InsertPointTy createTargetInit(
2989 const LocationDescription &Loc,
2990 const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
2999 LLVM_ABI void createTargetDeinit(
const LocationDescription &Loc,
3000 int32_t TeamsReductionDataSize = 0,
3001 int32_t TeamsReductionBufferLength = 1024);
3011 LLVM_ABI static std::pair<int32_t, int32_t>
3012 readThreadBoundsForKernel(
const Triple &
T, Function &Kernel);
3013 LLVM_ABI static void writeThreadBoundsForKernel(
const Triple &
T,
3014 Function &Kernel, int32_t LB,
3019 LLVM_ABI static std::pair<int32_t, int32_t>
3020 readTeamBoundsForKernel(
const Triple &
T, Function &Kernel);
3021 LLVM_ABI static void writeTeamsForKernel(
const Triple &
T, Function &Kernel,
3022 int32_t LB, int32_t UB);
3027 void setOutlinedTargetRegionFunctionAttributes(Function *OutlinedFn);
3032 Constant *createOutlinedFunctionID(Function *OutlinedFn,
3033 StringRef EntryFnIDName);
3036 Constant *createTargetRegionEntryAddr(Function *OutlinedFunction,
3037 StringRef EntryFnName);
3041 using FunctionGenCallback =
3042 std::function<Expected<Function *>(StringRef FunctionName)>;
3076 TargetRegionEntryInfo &EntryInfo,
3077 FunctionGenCallback &GenerateFunctionCallback,
bool IsOffloadEntry,
3078 Function *&OutlinedFn, Constant *&OutlinedFnID);
3089 registerTargetRegionFunction(TargetRegionEntryInfo &EntryInfo,
3090 Function *OutlinedFunction,
3091 StringRef EntryFnName, StringRef EntryFnIDName);
3104 enum BodyGenTy { Priv, DupNoPriv, NoPriv };
3109 using GenMapInfoCallbackTy =
3110 function_ref<MapInfosTy &(InsertPointTy CodeGenIP)>;
3119 void emitUDMapperArrayInitOrDel(Function *MapperFn,
llvm::Value *MapperHandle,
3123 llvm::BasicBlock *ExitBB,
bool IsInit);
3166 LLVM_ABI Expected<Function *> emitUserDefinedMapper(
3167 function_ref<MapInfosOrErrorTy(
3169 PrivAndGenMapInfoCB,
3170 llvm::Type *ElemTy, StringRef FuncName,
3171 CustomMapperCallbackTy CustomMapperCB);
3190 LLVM_ABI InsertPointOrErrorTy createTargetData(
3191 const LocationDescription &Loc, InsertPointTy AllocaIP,
3192 InsertPointTy CodeGenIP,
Value *DeviceID,
Value *IfCond,
3193 TargetDataInfo &
Info, GenMapInfoCallbackTy GenMapInfoCB,
3194 CustomMapperCallbackTy CustomMapperCB,
3195 omp::RuntimeFunction *MapperFunc =
nullptr,
3196 function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
3197 BodyGenTy BodyGenType)>
3198 BodyGenCB =
nullptr,
3199 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr,
3200 Value *SrcLocInfo =
nullptr);
3202 using TargetBodyGenCallbackTy = function_ref<InsertPointOrErrorTy(
3203 InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
3205 using TargetGenArgAccessorsCallbackTy = function_ref<InsertPointOrErrorTy(
3206 Argument &Arg,
Value *Input,
Value *&RetVal, InsertPointTy AllocaIP,
3207 InsertPointTy CodeGenIP)>;
3233 LLVM_ABI InsertPointOrErrorTy createTarget(
3234 const LocationDescription &Loc,
bool IsOffloadEntry,
3235 OpenMPIRBuilder::InsertPointTy AllocaIP,
3236 OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetDataInfo &
Info,
3237 TargetRegionEntryInfo &EntryInfo,
3238 const TargetKernelDefaultAttrs &DefaultAttrs,
3239 const TargetKernelRuntimeAttrs &RuntimeAttrs,
Value *IfCond,
3240 SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
3241 TargetBodyGenCallbackTy BodyGenCB,
3242 TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
3243 CustomMapperCallbackTy CustomMapperCB,
3244 const SmallVector<DependData> &Dependencies,
bool HasNowait =
false);
3249 LLVM_ABI FunctionCallee createForStaticInitFunction(
unsigned IVSize,
3251 bool IsGPUDistribute);
3255 LLVM_ABI FunctionCallee createDispatchInitFunction(
unsigned IVSize,
3260 LLVM_ABI FunctionCallee createDispatchNextFunction(
unsigned IVSize,
3265 LLVM_ABI FunctionCallee createDispatchFiniFunction(
unsigned IVSize,
3269 LLVM_ABI FunctionCallee createDispatchDeinitFunction();
3277#define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
3278#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
3279 ArrayType *VarName##Ty = nullptr; \
3280 PointerType *VarName##PtrTy = nullptr;
3281#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
3282 FunctionType *VarName = nullptr; \
3283 PointerType *VarName##Ptr = nullptr;
3284#define OMP_STRUCT_TYPE(VarName, StrName, ...) \
3285 StructType *VarName = nullptr; \
3286 PointerType *VarName##Ptr = nullptr;
3287#include "llvm/Frontend/OpenMP/OMPKinds.def"
3294 void initializeTypes(
Module &M);
3308 InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD,
Value *EntryCall,
3310 bool Conditional =
false);
3322 InsertPointOrErrorTy emitCommonDirectiveExit(omp::Directive OMPD,
3323 InsertPointTy FinIP,
3324 Instruction *ExitCall,
3325 bool HasFinalize =
true);
3343 InsertPointOrErrorTy
3344 EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
3345 Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
3346 FinalizeCallbackTy FiniCB,
bool Conditional =
false,
3347 bool HasFinalize =
true,
bool IsCancellable =
false);
3355 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
3356 StringRef FirstSeparator,
3357 StringRef Separator);
3364 Value *getOMPCriticalRegionLock(StringRef CriticalName);
3378 using AtomicUpdateCallbackTy =
3379 const function_ref<Expected<Value *>(
Value *XOld, IRBuilder<> &IRB)>;
3391 bool checkAndEmitFlushAfterAtomic(
const LocationDescription &Loc,
3392 AtomicOrdering AO, AtomicKind AK);
3418 Expected<std::pair<Value *, Value *>>
3419 emitAtomicUpdate(InsertPointTy AllocaIP,
Value *
X,
Type *XElemTy,
Value *Expr,
3420 AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3421 AtomicUpdateCallbackTy &UpdateOp,
bool VolatileX,
3422 bool IsXBinopExpr,
bool IsIgnoreDenormalMode,
3423 bool IsFineGrainedMemory,
bool IsRemoteMemory);
3429 AtomicRMWInst::BinOp RMWOp);
3435 struct AtomicOpValue {
3436 Value *Var =
nullptr;
3437 Type *ElemTy =
nullptr;
3438 bool IsSigned =
false;
3453 LLVM_ABI InsertPointTy createAtomicRead(
const LocationDescription &Loc,
3454 AtomicOpValue &
X, AtomicOpValue &V,
3456 InsertPointTy AllocaIP);
3468 LLVM_ABI InsertPointTy createAtomicWrite(
const LocationDescription &Loc,
3469 AtomicOpValue &
X,
Value *Expr,
3471 InsertPointTy AllocaIP);
3493 LLVM_ABI InsertPointOrErrorTy createAtomicUpdate(
3494 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3495 Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3496 AtomicUpdateCallbackTy &UpdateOp,
bool IsXBinopExpr,
3497 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3498 bool IsRemoteMemory =
false);
3529 LLVM_ABI InsertPointOrErrorTy createAtomicCapture(
3530 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3531 AtomicOpValue &V,
Value *Expr, AtomicOrdering AO,
3532 AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
3533 bool UpdateExpr,
bool IsPostfixUpdate,
bool IsXBinopExpr,
3534 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3535 bool IsRemoteMemory =
false);
3583 createAtomicCompare(
const LocationDescription &Loc, AtomicOpValue &
X,
3584 AtomicOpValue &V, AtomicOpValue &R,
Value *
E,
Value *
D,
3585 AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
3586 bool IsXBinopExpr,
bool IsPostfixUpdate,
bool IsFailOnly);
3587 LLVM_ABI InsertPointTy createAtomicCompare(
3588 const LocationDescription &Loc, AtomicOpValue &
X, AtomicOpValue &V,
3589 AtomicOpValue &R,
Value *
E,
Value *
D, AtomicOrdering AO,
3590 omp::OMPAtomicCompareOp Op,
bool IsXBinopExpr,
bool IsPostfixUpdate,
3591 bool IsFailOnly, AtomicOrdering Failure);
3609 LLVM_ABI CanonicalLoopInfo *createLoopSkeleton(DebugLoc
DL,
Value *TripCount,
3611 BasicBlock *PreInsertBefore,
3612 BasicBlock *PostInsertBefore,
3613 const Twine &Name = {});
3615 const std::string ompOffloadInfoName =
"omp_offload.info";
3632 LLVM_ABI void loadOffloadInfoMetadata(StringRef HostFilePath);
3641 getOrCreateInternalVariable(
Type *Ty,
const StringRef &Name,
3642 unsigned AddressSpace = 0);
3743class CanonicalLoopInfo {
3744 friend class OpenMPIRBuilder;
3753 Value *LastIter =
nullptr;
3763 void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
3768 void setTripCount(
Value *TripCount);
3784 void mapIndVar(llvm::function_ref<
Value *(Instruction *)> Updater);
3788 void setLastIter(
Value *IterVar) { LastIter = std::move(IterVar); }
3797 Value *getLastIter() {
return LastIter; }
3802 bool isValid()
const {
return Header; }
3829 return cast<BranchInst>(
Cond->getTerminator())->getSuccessor(0);
3853 return Exit->getSingleSuccessor();
3859 Value *getTripCount()
const {
3862 assert(isa<CmpInst>(CmpI) &&
"First inst must compare IV with TripCount");
3863 return CmpI->getOperand(1);
3871 assert(isa<PHINode>(IndVarPHI) &&
"First inst must be the IV PHI");
3876 Type *getIndVarType()
const {
3878 return getIndVar()->getType();
3882 OpenMPIRBuilder::InsertPointTy getPreheaderIP()
const {
3885 return {Preheader, std::prev(Preheader->end())};
3889 OpenMPIRBuilder::InsertPointTy getBodyIP()
const {
3892 return {Body, Body->begin()};
3896 OpenMPIRBuilder::InsertPointTy getAfterIP()
const {
3899 return {After, After->begin()};
3904 return Header->getParent();
3962 llvm::BasicBlock *OMPBeforeScanBlock =
nullptr;
3965 llvm::BasicBlock *OMPAfterScanBlock =
nullptr;
3968 llvm::BasicBlock *OMPScanDispatch =
nullptr;
3971 llvm::BasicBlock *OMPScanLoopExit =
nullptr;
3974 llvm::BasicBlock *OMPScanInit =
nullptr;
3977 llvm::BasicBlock *OMPScanFinish =
nullptr;
3981 bool OMPFirstScanLoop =
false;
3985 llvm::SmallDenseMap<llvm::Value *, llvm::Value *> *ScanBuffPtrs;
3996 ScanBuffPtrs =
new llvm::SmallDenseMap<llvm::Value *, llvm::Value *>();
3999 ~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.
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