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 LLVM_ABI OpenMPIRBuilderConfig(
bool IsTargetDevice,
bool IsGPU,
140 bool OpenMPOffloadMandatory,
141 bool HasRequiresReverseOffload,
142 bool HasRequiresUnifiedAddress,
143 bool HasRequiresUnifiedSharedMemory,
144 bool HasRequiresDynamicAllocators);
147 bool isTargetDevice()
const {
148 assert(IsTargetDevice.has_value() &&
"IsTargetDevice is not set");
149 return *IsTargetDevice;
153 assert(IsGPU.has_value() &&
"IsGPU is not set");
157 bool openMPOffloadMandatory()
const {
158 assert(OpenMPOffloadMandatory.has_value() &&
159 "OpenMPOffloadMandatory is not set");
160 return *OpenMPOffloadMandatory;
164 assert(GridValue.has_value() &&
"GridValue is not set");
168 bool hasRequiresFlags()
const {
return RequiresFlags; }
169 LLVM_ABI bool hasRequiresReverseOffload()
const;
170 LLVM_ABI bool hasRequiresUnifiedAddress()
const;
171 LLVM_ABI bool hasRequiresUnifiedSharedMemory()
const;
172 LLVM_ABI bool hasRequiresDynamicAllocators()
const;
176 LLVM_ABI int64_t getRequiresFlags()
const;
180 StringRef firstSeparator()
const {
181 if (FirstSeparator.has_value())
182 return *FirstSeparator;
190 StringRef separator()
const {
191 if (Separator.has_value())
198 void setIsTargetDevice(
bool Value) { IsTargetDevice =
Value; }
200 void setEmitLLVMUsed(
bool Value =
true) { EmitLLVMUsedMetaInfo =
Value; }
201 void setOpenMPOffloadMandatory(
bool Value) { OpenMPOffloadMandatory =
Value; }
202 void setFirstSeparator(StringRef FS) { FirstSeparator =
FS; }
203 void setSeparator(StringRef S) { Separator = S; }
204 void setGridValue(omp::GV
G) { GridValue =
G; }
213 int64_t RequiresFlags;
218struct TargetRegionEntryInfo {
220 static constexpr const char *KernelNamePrefix =
"__omp_offloading_";
222 std::string ParentName;
228 TargetRegionEntryInfo() : DeviceID(0), FileID(0),
Line(0),
Count(0) {}
229 TargetRegionEntryInfo(StringRef ParentName,
unsigned DeviceID,
230 unsigned FileID,
unsigned Line,
unsigned Count = 0)
231 : ParentName(ParentName), DeviceID(DeviceID), FileID(FileID),
Line(
Line),
235 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name, StringRef ParentName,
236 unsigned DeviceID,
unsigned FileID,
unsigned Line,
239 bool operator<(
const TargetRegionEntryInfo &
RHS)
const {
240 return std::make_tuple(ParentName, DeviceID, FileID, Line, Count) <
241 std::make_tuple(
RHS.ParentName,
RHS.DeviceID,
RHS.FileID,
RHS.Line,
247class OffloadEntriesInfoManager {
249 OpenMPIRBuilder *OMPBuilder;
250 unsigned OffloadingEntriesNum = 0;
254 class OffloadEntryInfo {
257 enum OffloadingEntryInfoKinds :
unsigned {
259 OffloadingEntryInfoTargetRegion = 0,
261 OffloadingEntryInfoDeviceGlobalVar = 1,
263 OffloadingEntryInfoInvalid = ~0
u
267 OffloadEntryInfo() =
delete;
268 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) :
Kind(
Kind) {}
269 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind,
unsigned Order,
272 ~OffloadEntryInfo() =
default;
275 bool isValid()
const {
return Order != ~0
u; }
276 unsigned getOrder()
const {
return Order; }
277 OffloadingEntryInfoKinds getKind()
const {
return Kind; }
279 void setFlags(uint32_t NewFlags) {
Flags = NewFlags; }
280 Constant *getAddress()
const {
return cast_or_null<Constant>(Addr); }
281 void setAddress(Constant *V) {
282 assert(!Addr.pointsToAliveValue() &&
"Address has been set before!");
285 static bool classof(
const OffloadEntryInfo *
Info) {
return true; }
295 unsigned Order = ~0
u;
297 OffloadingEntryInfoKinds
Kind = OffloadingEntryInfoInvalid;
303 unsigned size()
const {
return OffloadingEntriesNum; }
305 OffloadEntriesInfoManager(OpenMPIRBuilder *builder) : OMPBuilder(builder) {}
312 enum OMPTargetRegionEntryKind : uint32_t {
314 OMPTargetRegionEntryTargetRegion = 0x0,
318 class OffloadEntryInfoTargetRegion final :
public OffloadEntryInfo {
323 OffloadEntryInfoTargetRegion()
324 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
325 explicit OffloadEntryInfoTargetRegion(
unsigned Order, Constant *Addr,
327 OMPTargetRegionEntryKind Flags)
328 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order,
Flags),
334 void setID(Constant *V) {
335 assert(!ID &&
"ID has been set before!");
338 static bool classof(
const OffloadEntryInfo *
Info) {
339 return Info->getKind() == OffloadingEntryInfoTargetRegion;
346 initializeTargetRegionEntryInfo(
const TargetRegionEntryInfo &EntryInfo,
349 LLVM_ABI void registerTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
350 Constant *Addr, Constant *ID,
351 OMPTargetRegionEntryKind Flags);
354 LLVM_ABI bool hasTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
355 bool IgnoreAddressId =
false)
const;
359 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name,
360 const TargetRegionEntryInfo &EntryInfo);
363 typedef function_ref<void(
const TargetRegionEntryInfo &EntryInfo,
364 const OffloadEntryInfoTargetRegion &)>
365 OffloadTargetRegionEntryInfoActTy;
367 actOnTargetRegionEntriesInfo(
const OffloadTargetRegionEntryInfoActTy &Action);
374 enum OMPTargetGlobalVarEntryKind : uint32_t {
376 OMPTargetGlobalVarEntryTo = 0x0,
378 OMPTargetGlobalVarEntryLink = 0x1,
380 OMPTargetGlobalVarEntryEnter = 0x2,
382 OMPTargetGlobalVarEntryNone = 0x3,
384 OMPTargetGlobalVarEntryIndirect = 0x8,
386 OMPTargetGlobalRegisterRequires = 0x10,
394 enum OMPTargetDeviceClauseKind : uint32_t {
396 OMPTargetDeviceClauseAny = 0x0,
398 OMPTargetDeviceClauseNoHost = 0x1,
400 OMPTargetDeviceClauseHost = 0x2,
402 OMPTargetDeviceClauseNone = 0x3
406 class OffloadEntryInfoDeviceGlobalVar final :
public OffloadEntryInfo {
409 GlobalValue::LinkageTypes
Linkage;
413 OffloadEntryInfoDeviceGlobalVar()
414 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
415 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order,
416 OMPTargetGlobalVarEntryKind Flags)
417 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags) {}
418 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order, Constant *Addr,
420 OMPTargetGlobalVarEntryKind Flags,
421 GlobalValue::LinkageTypes
Linkage,
422 const std::string &VarName)
423 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags),
428 int64_t getVarSize()
const {
return VarSize; }
430 void setVarSize(int64_t
Size) { VarSize =
Size; }
431 GlobalValue::LinkageTypes getLinkage()
const {
return Linkage; }
432 void setLinkage(GlobalValue::LinkageTypes LT) {
Linkage =
LT; }
433 static bool classof(
const OffloadEntryInfo *
Info) {
434 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
440 LLVM_ABI void initializeDeviceGlobalVarEntryInfo(
441 StringRef Name, OMPTargetGlobalVarEntryKind Flags,
unsigned Order);
444 LLVM_ABI void registerDeviceGlobalVarEntryInfo(
445 StringRef VarName, Constant *Addr, int64_t VarSize,
446 OMPTargetGlobalVarEntryKind Flags, GlobalValue::LinkageTypes
Linkage);
448 bool hasDeviceGlobalVarEntryInfo(StringRef VarName)
const {
449 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
452 typedef function_ref<void(StringRef,
const OffloadEntryInfoDeviceGlobalVar &)>
453 OffloadDeviceGlobalVarEntryInfoActTy;
454 LLVM_ABI void actOnDeviceGlobalVarEntriesInfo(
455 const OffloadDeviceGlobalVarEntryInfoActTy &Action);
460 getTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo)
const;
464 incrementTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo);
466 static TargetRegionEntryInfo
467 getTargetRegionEntryCountKey(
const TargetRegionEntryInfo &EntryInfo) {
468 return TargetRegionEntryInfo(EntryInfo.ParentName, EntryInfo.DeviceID,
469 EntryInfo.FileID, EntryInfo.Line, 0);
473 std::map<TargetRegionEntryInfo, unsigned> OffloadEntriesTargetRegionCount;
476 typedef std::map<TargetRegionEntryInfo, OffloadEntryInfoTargetRegion>
477 OffloadEntriesTargetRegionTy;
478 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
481 typedef StringMap<OffloadEntryInfoDeviceGlobalVar>
482 OffloadEntriesDeviceGlobalVarTy;
483 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
489class OpenMPIRBuilder {
493 OpenMPIRBuilder(
Module &M)
495 T(
M.getTargetTriple()), IsFinalized(
false) {}
498 class AtomicInfo :
public llvm::AtomicInfo {
502 AtomicInfo(IRBuilder<> *Builder, llvm::Type *Ty, uint64_t AtomicSizeInBits,
503 uint64_t ValueSizeInBits, llvm::Align AtomicAlign,
504 llvm::Align ValueAlign,
bool UseLibcall,
505 IRBuilderBase::InsertPoint AllocaIP,
llvm::Value *AtomicVar)
506 : llvm::AtomicInfo(Builder, Ty, AtomicSizeInBits, ValueSizeInBits,
507 AtomicAlign, ValueAlign, UseLibcall, AllocaIP),
508 AtomicVar(AtomicVar) {}
510 llvm::Value *getAtomicPointer()
const override {
return AtomicVar; }
511 void decorateWithTBAA(llvm::Instruction *
I)
override {}
512 llvm::AllocaInst *CreateAlloca(llvm::Type *Ty,
513 const llvm::Twine &Name)
const override {
514 llvm::AllocaInst *allocaInst = Builder->CreateAlloca(Ty);
525 void setConfig(OpenMPIRBuilderConfig
C) { Config =
C; }
537 LLVM_ABI void addAttributes(omp::RuntimeFunction FnID, Function &Fn);
540 using InsertPointTy = IRBuilder<>::InsertPoint;
543 using InsertPointOrErrorTy = Expected<InsertPointTy>;
554 createPlatformSpecificName(ArrayRef<StringRef> Parts)
const;
564 using FinalizeCallbackTy = std::function<
Error(InsertPointTy CodeGenIP)>;
566 struct FinalizationInfo {
569 FinalizeCallbackTy FiniCB;
582 void pushFinalizationCB(
const FinalizationInfo &FI) {
583 FinalizationStack.push_back(FI);
589 void popFinalizationCB() { FinalizationStack.pop_back(); }
617 using BodyGenCallbackTy =
618 function_ref<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
626 using StorableBodyGenCallbackTy =
627 std::function<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
639 using LoopBodyGenCallbackTy =
640 function_ref<
Error(InsertPointTy CodeGenIP,
Value *IndVar)>;
660 using PrivatizeCallbackTy = function_ref<InsertPointOrErrorTy(
661 InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
Value &Original,
666 struct LocationDescription {
667 LocationDescription(
const IRBuilderBase &IRB)
668 : IP(IRB.saveIP()),
DL(IRB.getCurrentDebugLocation()) {}
669 LocationDescription(
const InsertPointTy &IP) : IP(IP) {}
670 LocationDescription(
const InsertPointTy &IP,
const DebugLoc &
DL)
690 LLVM_ABI InsertPointOrErrorTy createBarrier(
const LocationDescription &Loc,
692 bool ForceSimpleCall =
false,
693 bool CheckCancelFlag =
true);
702 LLVM_ABI InsertPointOrErrorTy createCancel(
const LocationDescription &Loc,
704 omp::Directive CanceledDirective);
712 LLVM_ABI InsertPointOrErrorTy createCancellationPoint(
713 const LocationDescription &Loc, omp::Directive CanceledDirective);
716 LLVM_ABI Expected<ScanInfo *> scanInfoInitialize();
731 LLVM_ABI InsertPointOrErrorTy createParallel(
732 const LocationDescription &Loc, InsertPointTy AllocaIP,
733 BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
734 FinalizeCallbackTy FiniCB,
Value *IfCondition,
Value *NumThreads,
735 omp::ProcBindKind ProcBind,
bool IsCancellable);
756 LLVM_ABI Expected<CanonicalLoopInfo *>
757 createCanonicalLoop(
const LocationDescription &Loc,
758 LoopBodyGenCallbackTy BodyGenCB,
Value *TripCount,
759 const Twine &Name =
"loop");
792 LLVM_ABI Expected<SmallVector<llvm::CanonicalLoopInfo *>>
793 createCanonicalScanLoops(
const LocationDescription &Loc,
794 LoopBodyGenCallbackTy BodyGenCB,
Value *Start,
796 bool InclusiveStop, InsertPointTy ComputeIP,
797 const Twine &Name, ScanInfo *ScanRedInfo);
840 const LocationDescription &Loc,
Value *Start,
Value *Stop,
Value *Step,
841 bool IsSigned,
bool InclusiveStop,
const Twine &Name =
"loop");
873 LLVM_ABI Expected<CanonicalLoopInfo *> createCanonicalLoop(
874 const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB,
875 Value *Start,
Value *Stop,
Value *Step,
bool IsSigned,
bool InclusiveStop,
876 InsertPointTy ComputeIP = {},
const Twine &
Name =
"loop",
877 bool InScan =
false, ScanInfo *ScanRedInfo =
nullptr);
939 LLVM_ABI CanonicalLoopInfo *collapseLoops(DebugLoc
DL,
940 ArrayRef<CanonicalLoopInfo *>
Loops,
941 InsertPointTy ComputeIP);
948 getOpenMPDefaultSimdAlign(
const Triple &TargetTriple,
949 const StringMap<bool> &Features);
986 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
987 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
988 bool IsDeclaration,
bool IsExternallyVisible,
989 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
990 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
991 std::vector<Triple> TargetTriple,
Type *LlvmPtrTy,
992 std::function<Constant *()> GlobalInitializer,
993 std::function<GlobalValue::LinkageTypes()> VariableLinkage);
1029 LLVM_ABI void registerTargetGlobalVariable(
1030 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
1031 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
1032 bool IsDeclaration,
bool IsExternallyVisible,
1033 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
1034 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
1035 std::vector<Triple> TargetTriple,
1036 std::function<Constant *()> GlobalInitializer,
1037 std::function<GlobalValue::LinkageTypes()> VariableLinkage,
1038 Type *LlvmPtrTy, Constant *Addr);
1041 LLVM_ABI unsigned getFlagMemberOffset();
1050 LLVM_ABI omp::OpenMPOffloadMappingFlags getMemberOfFlag(
unsigned Position);
1062 setCorrectMemberOfFlag(omp::OpenMPOffloadMappingFlags &Flags,
1063 omp::OpenMPOffloadMappingFlags MemberOfFlag);
1084 InsertPointTy applyWorkshareLoopTarget(DebugLoc
DL, CanonicalLoopInfo *CLI,
1085 InsertPointTy AllocaIP,
1086 omp::WorksharingLoopType LoopType);
1107 InsertPointOrErrorTy applyStaticWorkshareLoop(
1108 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1109 omp::WorksharingLoopType LoopType,
bool NeedsBarrier);
1124 InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(DebugLoc
DL,
1125 CanonicalLoopInfo *CLI,
1126 InsertPointTy AllocaIP,
1150 InsertPointOrErrorTy applyDynamicWorkshareLoop(DebugLoc
DL,
1151 CanonicalLoopInfo *CLI,
1152 InsertPointTy AllocaIP,
1153 omp::OMPScheduleType SchedType,
1155 Value *Chunk =
nullptr);
1168 void createIfVersion(CanonicalLoopInfo *Loop,
Value *IfCond,
1169 ValueMap<const Value *, WeakTrackingVH> &VMap,
1170 LoopAnalysis &LIA, LoopInfo &LI, llvm::Loop *L,
1171 const Twine &NamePrefix =
"");
1208 LLVM_ABI InsertPointOrErrorTy applyWorkshareLoop(
1209 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1211 llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default,
1212 Value *ChunkSize =
nullptr,
bool HasSimdModifier =
false,
1213 bool HasMonotonicModifier =
false,
bool HasNonmonotonicModifier =
false,
1214 bool HasOrderedClause =
false,
1215 omp::WorksharingLoopType LoopType =
1216 omp::WorksharingLoopType::ForStaticLoop);
1261 LLVM_ABI std::vector<CanonicalLoopInfo *>
1262 tileLoops(DebugLoc
DL, ArrayRef<CanonicalLoopInfo *>
Loops,
1263 ArrayRef<Value *> TileSizes);
1273 LLVM_ABI void unrollLoopFull(DebugLoc
DL, CanonicalLoopInfo *Loop);
1280 LLVM_ABI void unrollLoopHeuristic(DebugLoc
DL, CanonicalLoopInfo *Loop);
1304 LLVM_ABI void unrollLoopPartial(DebugLoc
DL, CanonicalLoopInfo *Loop,
1306 CanonicalLoopInfo **UnrolledCLI);
1321 LLVM_ABI void applySimd(CanonicalLoopInfo *Loop,
1322 MapVector<Value *, Value *> AlignedVars,
1323 Value *IfCond, omp::OrderKind Order,
1324 ConstantInt *Simdlen, ConstantInt *Safelen);
1329 LLVM_ABI void createFlush(
const LocationDescription &Loc);
1334 LLVM_ABI void createTaskwait(
const LocationDescription &Loc);
1339 LLVM_ABI void createTaskyield(
const LocationDescription &Loc);
1343 omp::RTLDependenceKindTy DepKind = omp::RTLDependenceKindTy::DepUnknown;
1346 explicit DependData() =
default;
1347 DependData(omp::RTLDependenceKindTy DepKind,
Type *DepValueType,
1349 : DepKind(DepKind), DepValueType(DepValueType), DepVal(DepVal) {}
1372 createTask(
const LocationDescription &Loc, InsertPointTy AllocaIP,
1373 BodyGenCallbackTy BodyGenCB,
bool Tied =
true,
1374 Value *Final =
nullptr,
Value *IfCondition =
nullptr,
1375 SmallVector<DependData> Dependencies = {},
bool Mergeable =
false,
1376 Value *EventHandle =
nullptr,
Value *Priority =
nullptr);
1383 LLVM_ABI InsertPointOrErrorTy createTaskgroup(
const LocationDescription &Loc,
1384 InsertPointTy AllocaIP,
1385 BodyGenCallbackTy BodyGenCB);
1387 using FileIdentifierInfoCallbackTy =
1388 std::function<std::tuple<std::string, uint64_t>()>;
1397 LLVM_ABI static TargetRegionEntryInfo
1398 getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
1399 StringRef ParentName =
"");
1402 enum class ReductionGenCBKind { Clang, MLIR };
1414 using ReductionGenClangCBTy =
1415 std::function<InsertPointTy(InsertPointTy CodeGenIP,
unsigned Index,
1423 using ReductionGenCBTy = std::function<InsertPointOrErrorTy(
1430 using ReductionGenAtomicCBTy = std::function<InsertPointOrErrorTy(
1437 struct ReductionInfo {
1438 ReductionInfo(
Type *ElementType,
Value *Variable,
Value *PrivateVariable,
1439 EvalKind EvaluationKind, ReductionGenCBTy ReductionGen,
1440 ReductionGenClangCBTy ReductionGenClang,
1441 ReductionGenAtomicCBTy AtomicReductionGen)
1443 PrivateVariable(PrivateVariable), EvaluationKind(EvaluationKind),
1444 ReductionGen(ReductionGen), ReductionGenClang(ReductionGenClang),
1445 AtomicReductionGen(AtomicReductionGen) {}
1446 ReductionInfo(
Value *PrivateVariable)
1448 PrivateVariable(PrivateVariable), EvaluationKind(EvalKind::
Scalar),
1449 ReductionGen(), ReductionGenClang(), AtomicReductionGen() {}
1458 Value *PrivateVariable;
1461 EvalKind EvaluationKind;
1466 ReductionGenCBTy ReductionGen;
1471 ReductionGenClangCBTy ReductionGenClang;
1477 ReductionGenAtomicCBTy AtomicReductionGen;
1480 enum class CopyAction :
unsigned {
1488 struct CopyOptionsTy {
1489 Value *RemoteLaneOffset =
nullptr;
1490 Value *ScratchpadIndex =
nullptr;
1491 Value *ScratchpadWidth =
nullptr;
1497 Value *getGPUThreadID();
1500 Value *getGPUWarpSize();
1505 Value *getNVPTXWarpID();
1510 Value *getNVPTXLaneID();
1513 Value *castValueToType(InsertPointTy AllocaIP,
Value *From,
Type *ToType);
1517 Value *createRuntimeShuffleFunction(InsertPointTy AllocaIP,
Value *Element,
1521 void shuffleAndStore(InsertPointTy AllocaIP,
Value *SrcAddr,
Value *DstAddr,
1523 Type *ReductionArrayTy);
1527 void emitReductionListCopy(
1528 InsertPointTy AllocaIP, CopyAction Action,
Type *ReductionArrayTy,
1529 ArrayRef<ReductionInfo> ReductionInfos,
Value *SrcBase,
Value *DestBase,
1530 CopyOptionsTy CopyOptions = {
nullptr,
nullptr,
nullptr});
1605 Function *emitShuffleAndReduceFunction(
1606 ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1607 Function *ReduceFn, AttributeList FuncAttrs);
1617 Error emitScanBasedDirectiveIR(
1618 llvm::function_ref<
Error()> InputLoopGen,
1619 llvm::function_ref<
Error(LocationDescription Loc)> ScanLoopGen,
1620 ScanInfo *ScanRedInfo);
1625 void createScanBBs(ScanInfo *ScanRedInfo);
1635 Error emitScanBasedDirectiveDeclsIR(InsertPointTy AllocaIP,
1636 ArrayRef<llvm::Value *> ScanVars,
1637 ArrayRef<llvm::Type *> ScanVarsType,
1638 ScanInfo *ScanRedInfo);
1646 Error emitScanBasedDirectiveFinalsIR(
1647 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1648 ScanInfo *ScanInfo);
1669 Expected<Function *>
1670 emitInterWarpCopyFunction(
const LocationDescription &Loc,
1671 ArrayRef<ReductionInfo> ReductionInfos,
1672 AttributeList FuncAttrs);
1687 Function *emitListToGlobalCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1688 Type *ReductionsBufferTy,
1689 AttributeList FuncAttrs);
1704 Function *emitGlobalToListCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1705 Type *ReductionsBufferTy,
1706 AttributeList FuncAttrs);
1726 emitListToGlobalReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1727 Function *ReduceFn,
Type *ReductionsBufferTy,
1728 AttributeList FuncAttrs);
1748 emitGlobalToListReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1749 Function *ReduceFn,
Type *ReductionsBufferTy,
1750 AttributeList FuncAttrs);
1753 std::string getReductionFuncName(StringRef Name)
const;
1764 Expected<Function *> createReductionFunction(
1765 StringRef ReducerName, ArrayRef<ReductionInfo> ReductionInfos,
1766 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
1767 AttributeList FuncAttrs = {});
2029 LLVM_ABI InsertPointOrErrorTy createReductionsGPU(
2030 const LocationDescription &Loc, InsertPointTy AllocaIP,
2031 InsertPointTy CodeGenIP, ArrayRef<ReductionInfo> ReductionInfos,
2032 bool IsNoWait =
false,
bool IsTeamsReduction =
false,
2033 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
2034 std::optional<omp::GV> GridValue = {},
unsigned ReductionBufNum = 1024,
2035 Value *SrcLocInfo =
nullptr);
2102 LLVM_ABI InsertPointOrErrorTy createReductions(
2103 const LocationDescription &Loc, InsertPointTy AllocaIP,
2104 ArrayRef<ReductionInfo> ReductionInfos, ArrayRef<bool> IsByRef,
2105 bool IsNoWait =
false,
bool IsTeamsReduction =
false);
2110 InsertPointTy getInsertionPoint() {
return Builder.saveIP(); }
2113 bool updateToLocation(
const LocationDescription &Loc) {
2114 Builder.restoreIP(Loc.IP);
2115 Builder.SetCurrentDebugLocation(Loc.DL);
2116 return Loc.IP.getBlock() !=
nullptr;
2121 omp::RuntimeFunction FnID);
2123 LLVM_ABI Function *getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID);
2127 uint32_t &SrcLocStrSize);
2135 StringRef FileName,
unsigned Line,
2137 uint32_t &SrcLocStrSize);
2142 Function *
F =
nullptr);
2146 uint32_t &SrcLocStrSize);
2151 uint32_t SrcLocStrSize,
2152 omp::IdentFlag Flags = omp::IdentFlag(0),
2153 unsigned Reserve2Flags = 0);
2157 LLVM_ABI GlobalValue *createGlobalFlag(
unsigned Value, StringRef Name);
2160 LLVM_ABI void emitUsed(StringRef Name, ArrayRef<llvm::WeakTrackingVH> List);
2164 emitKernelExecutionMode(StringRef KernelName, omp::OMPTgtExecModeFlags
Mode);
2174 omp::Directive CanceledDirective,
2175 FinalizeCallbackTy ExitCB = {});
2188 LLVM_ABI InsertPointTy emitTargetKernel(
const LocationDescription &Loc,
2189 InsertPointTy AllocaIP,
2193 ArrayRef<Value *> KernelArgs);
2198 LLVM_ABI void emitFlush(
const LocationDescription &Loc);
2203 SmallVector<FinalizationInfo, 8> FinalizationStack;
2207 bool isLastFinalizationInfoCancellable(omp::Directive DK) {
2208 return !FinalizationStack.empty() &&
2209 FinalizationStack.back().IsCancellable &&
2210 FinalizationStack.back().DK == DK;
2216 LLVM_ABI void emitTaskwaitImpl(
const LocationDescription &Loc);
2221 LLVM_ABI void emitTaskyieldImpl(
const LocationDescription &Loc);
2229 OpenMPIRBuilderConfig Config;
2235 IRBuilder<> Builder;
2238 StringMap<Constant *> SrcLocStrMap;
2241 DenseMap<std::pair<Constant *, uint64_t>,
Constant *> IdentMap;
2244 OffloadEntriesInfoManager OffloadInfoManager;
2251 struct OutlineInfo {
2252 using PostOutlineCBTy = std::function<void(Function &)>;
2253 PostOutlineCBTy PostOutlineCB;
2254 BasicBlock *EntryBB, *ExitBB, *OuterAllocaBB;
2255 SmallVector<Value *, 2> ExcludeArgsFromAggregate;
2260 SmallVectorImpl<BasicBlock *> &BlockVector);
2267 SmallVector<OutlineInfo, 16> OutlineInfos;
2272 SmallVector<llvm::Function *, 16> ConstantAllocaRaiseCandidates;
2276 std::forward_list<CanonicalLoopInfo> LoopInfos;
2279 std::forward_list<ScanInfo> ScanInfos;
2282 void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
2289 StringMap<GlobalVariable *, BumpPtrAllocator> InternalVars;
2296 LLVM_ABI void emitBranch(BasicBlock *Target);
2301 LLVM_ABI void emitBlock(BasicBlock *BB, Function *CurFn,
2302 bool IsFinished =
false);
2314 BodyGenCallbackTy ElseGen,
2315 InsertPointTy AllocaIP = {});
2319 createOffloadMaptypes(SmallVectorImpl<uint64_t> &Mappings,
2320 std::string VarName);
2324 createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
2325 std::string VarName);
2327 struct MapperAllocas {
2328 AllocaInst *ArgsBase =
nullptr;
2329 AllocaInst *
Args =
nullptr;
2330 AllocaInst *ArgSizes =
nullptr;
2334 LLVM_ABI void createMapperAllocas(
const LocationDescription &Loc,
2335 InsertPointTy AllocaIP,
2336 unsigned NumOperands,
2337 struct MapperAllocas &MapperAllocas);
2348 LLVM_ABI void emitMapperCall(
const LocationDescription &Loc,
2349 Function *MapperFunc,
Value *SrcLocInfo,
2351 struct MapperAllocas &MapperAllocas,
2352 int64_t DeviceID,
unsigned NumOperands);
2355 struct TargetDataRTArgs {
2357 Value *BasePointersArray =
nullptr;
2359 Value *PointersArray =
nullptr;
2361 Value *SizesArray =
nullptr;
2365 Value *MapTypesArray =
nullptr;
2369 Value *MapTypesArrayEnd =
nullptr;
2371 Value *MappersArray =
nullptr;
2374 Value *MapNamesArray =
nullptr;
2376 explicit TargetDataRTArgs() {}
2377 explicit TargetDataRTArgs(
Value *BasePointersArray,
Value *PointersArray,
2379 Value *MapTypesArrayEnd,
Value *MappersArray,
2380 Value *MapNamesArray)
2381 : BasePointersArray(BasePointersArray), PointersArray(PointersArray),
2382 SizesArray(SizesArray), MapTypesArray(MapTypesArray),
2383 MapTypesArrayEnd(MapTypesArrayEnd), MappersArray(MappersArray),
2384 MapNamesArray(MapNamesArray) {}
2394 struct TargetKernelDefaultAttrs {
2395 omp::OMPTgtExecModeFlags ExecFlags =
2396 omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
2397 SmallVector<int32_t, 3> MaxTeams = {-1};
2398 int32_t MinTeams = 1;
2400 int32_t MinThreads = 1;
2401 int32_t ReductionDataSize = 0;
2402 int32_t ReductionBufferLength = 0;
2410 struct TargetKernelRuntimeAttrs {
2411 SmallVector<Value *, 3> MaxTeams = {
nullptr};
2412 Value *MinTeams =
nullptr;
2413 SmallVector<Value *, 3> TargetThreadLimit = {
nullptr};
2414 SmallVector<Value *, 3> TeamsThreadLimit = {
nullptr};
2422 Value *LoopTripCount =
nullptr;
2427 struct TargetKernelArgs {
2429 unsigned NumTargetItems = 0;
2431 TargetDataRTArgs RTArgs;
2433 Value *NumIterations =
nullptr;
2435 ArrayRef<Value *> NumTeams;
2437 ArrayRef<Value *> NumThreads;
2439 Value *DynCGGroupMem =
nullptr;
2441 bool HasNoWait =
false;
2444 TargetKernelArgs() {}
2445 TargetKernelArgs(
unsigned NumTargetItems, TargetDataRTArgs RTArgs,
2446 Value *NumIterations, ArrayRef<Value *> NumTeams,
2447 ArrayRef<Value *> NumThreads,
Value *DynCGGroupMem,
2449 : NumTargetItems(NumTargetItems), RTArgs(RTArgs),
2450 NumIterations(NumIterations), NumTeams(NumTeams),
2451 NumThreads(NumThreads), DynCGGroupMem(DynCGGroupMem),
2452 HasNoWait(HasNoWait) {}
2458 LLVM_ABI static void getKernelArgsVector(TargetKernelArgs &KernelArgs,
2459 IRBuilderBase &Builder,
2460 SmallVector<Value *> &ArgsVector);
2464 class TargetDataInfo {
2466 bool RequiresDevicePointerInfo =
false;
2469 bool SeparateBeginEndCalls =
false;
2472 TargetDataRTArgs RTArgs;
2474 SmallMapVector<const Value *, std::pair<Value *, Value *>, 4>
2478 bool HasMapper =
false;
2480 unsigned NumberOfPtrs = 0
u;
2482 bool EmitDebug =
false;
2485 bool HasNoWait =
false;
2487 explicit TargetDataInfo() {}
2488 explicit TargetDataInfo(
bool RequiresDevicePointerInfo,
2489 bool SeparateBeginEndCalls)
2490 : RequiresDevicePointerInfo(RequiresDevicePointerInfo),
2491 SeparateBeginEndCalls(SeparateBeginEndCalls) {}
2493 void clearArrayInfo() {
2494 RTArgs = TargetDataRTArgs();
2500 return RTArgs.BasePointersArray && RTArgs.PointersArray &&
2501 RTArgs.SizesArray && RTArgs.MapTypesArray &&
2502 (!HasMapper || RTArgs.MappersArray) && NumberOfPtrs;
2504 bool requiresDevicePointerInfo() {
return RequiresDevicePointerInfo; }
2505 bool separateBeginEndCalls() {
return SeparateBeginEndCalls; }
2509 using MapValuesArrayTy = SmallVector<Value *, 4>;
2510 using MapDeviceInfoArrayTy = SmallVector<DeviceInfoTy, 4>;
2511 using MapFlagsArrayTy = SmallVector<omp::OpenMPOffloadMappingFlags, 4>;
2512 using MapNamesArrayTy = SmallVector<Constant *, 4>;
2513 using MapDimArrayTy = SmallVector<uint64_t, 4>;
2514 using MapNonContiguousArrayTy = SmallVector<MapValuesArrayTy, 4>;
2520 struct StructNonContiguousInfo {
2521 bool IsNonContiguous =
false;
2523 MapNonContiguousArrayTy
Offsets;
2524 MapNonContiguousArrayTy Counts;
2525 MapNonContiguousArrayTy Strides;
2527 MapValuesArrayTy BasePointers;
2528 MapValuesArrayTy Pointers;
2529 MapDeviceInfoArrayTy DevicePointers;
2530 MapValuesArrayTy
Sizes;
2531 MapFlagsArrayTy
Types;
2532 MapNamesArrayTy Names;
2533 StructNonContiguousInfo NonContigInfo;
2536 void append(MapInfosTy &CurInfo) {
2537 BasePointers.append(CurInfo.BasePointers.begin(),
2538 CurInfo.BasePointers.end());
2539 Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
2540 DevicePointers.append(CurInfo.DevicePointers.begin(),
2541 CurInfo.DevicePointers.end());
2542 Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
2543 Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
2544 Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
2545 NonContigInfo.Dims.append(CurInfo.NonContigInfo.Dims.begin(),
2546 CurInfo.NonContigInfo.Dims.end());
2547 NonContigInfo.Offsets.append(CurInfo.NonContigInfo.Offsets.begin(),
2548 CurInfo.NonContigInfo.Offsets.end());
2549 NonContigInfo.Counts.append(CurInfo.NonContigInfo.Counts.begin(),
2550 CurInfo.NonContigInfo.Counts.end());
2551 NonContigInfo.Strides.append(CurInfo.NonContigInfo.Strides.begin(),
2552 CurInfo.NonContigInfo.Strides.end());
2555 using MapInfosOrErrorTy = Expected<MapInfosTy &>;
2561 using EmitFallbackCallbackTy =
2562 function_ref<InsertPointOrErrorTy(InsertPointTy)>;
2566 using CustomMapperCallbackTy =
2567 function_ref<Expected<Function *>(
unsigned int)>;
2579 LLVM_ABI InsertPointOrErrorTy emitKernelLaunch(
2580 const LocationDescription &Loc,
Value *OutlinedFnID,
2581 EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args,
2582 Value *DeviceID,
Value *RTLoc, InsertPointTy AllocaIP);
2594 using TargetTaskBodyCallbackTy =
2596 IRBuilderBase::InsertPoint TargetTaskAllocaIP)>;
2608 LLVM_ABI InsertPointOrErrorTy emitTargetTask(
2609 TargetTaskBodyCallbackTy TaskBodyCB,
Value *DeviceID,
Value *RTLoc,
2610 OpenMPIRBuilder::InsertPointTy AllocaIP,
2611 const SmallVector<llvm::OpenMPIRBuilder::DependData> &Dependencies,
2612 const TargetDataRTArgs &RTArgs,
bool HasNoWait);
2618 LLVM_ABI void emitOffloadingArraysArgument(
2619 IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs,
2620 OpenMPIRBuilder::TargetDataInfo &
Info,
bool ForEndCall =
false);
2623 LLVM_ABI void emitNonContiguousDescriptor(InsertPointTy AllocaIP,
2624 InsertPointTy CodeGenIP,
2625 MapInfosTy &CombinedInfo,
2626 TargetDataInfo &
Info);
2634 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
2635 TargetDataInfo &
Info, CustomMapperCallbackTy CustomMapperCB,
2636 bool IsNonContiguous =
false,
2637 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2646 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &
Info,
2647 TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
2648 CustomMapperCallbackTy CustomMapperCB,
bool IsNonContiguous =
false,
2649 bool ForEndCall =
false,
2650 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2654 LLVM_ABI void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t
Size,
2655 int32_t Flags, GlobalValue::LinkageTypes,
2656 StringRef Name =
"");
2660 enum EmitMetadataErrorKind {
2661 EMIT_MD_TARGET_REGION_ERROR,
2662 EMIT_MD_DECLARE_TARGET_ERROR,
2663 EMIT_MD_GLOBAL_VAR_LINK_ERROR
2667 using EmitMetadataErrorReportFunctionTy =
2668 std::function<void(EmitMetadataErrorKind, TargetRegionEntryInfo)>;
2677 LLVM_ABI void createOffloadEntriesAndInfoMetadata(
2678 EmitMetadataErrorReportFunctionTy &ErrorReportFunction);
2691 LLVM_ABI InsertPointTy createCopyPrivate(
const LocationDescription &Loc,
2708 createSingle(
const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2709 FinalizeCallbackTy FiniCB,
bool IsNowait,
2710 ArrayRef<llvm::Value *> CPVars = {},
2711 ArrayRef<llvm::Function *> CPFuncs = {});
2720 LLVM_ABI InsertPointOrErrorTy createMaster(
const LocationDescription &Loc,
2721 BodyGenCallbackTy BodyGenCB,
2722 FinalizeCallbackTy FiniCB);
2731 LLVM_ABI InsertPointOrErrorTy createMasked(
const LocationDescription &Loc,
2732 BodyGenCallbackTy BodyGenCB,
2733 FinalizeCallbackTy FiniCB,
2754 LLVM_ABI InsertPointOrErrorTy emitScanReduction(
2755 const LocationDescription &Loc,
2756 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
2757 ScanInfo *ScanRedInfo);
2772 LLVM_ABI InsertPointOrErrorTy createScan(
const LocationDescription &Loc,
2773 InsertPointTy AllocaIP,
2774 ArrayRef<llvm::Value *> ScanVars,
2775 ArrayRef<llvm::Type *> ScanVarsType,
2777 ScanInfo *ScanRedInfo);
2788 LLVM_ABI InsertPointOrErrorTy createCritical(
const LocationDescription &Loc,
2789 BodyGenCallbackTy BodyGenCB,
2790 FinalizeCallbackTy FiniCB,
2791 StringRef CriticalName,
2805 createOrderedDepend(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2806 unsigned NumLoops, ArrayRef<llvm::Value *> StoreValues,
2807 const Twine &Name,
bool IsDependSource);
2818 LLVM_ABI InsertPointOrErrorTy createOrderedThreadsSimd(
2819 const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2820 FinalizeCallbackTy FiniCB,
bool IsThreads);
2834 createSections(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2835 ArrayRef<StorableBodyGenCallbackTy> SectionCBs,
2836 PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB,
2837 bool IsCancellable,
bool IsNowait);
2845 LLVM_ABI InsertPointOrErrorTy createSection(
const LocationDescription &Loc,
2846 BodyGenCallbackTy BodyGenCB,
2847 FinalizeCallbackTy FiniCB);
2861 LLVM_ABI InsertPointOrErrorTy createTeams(
const LocationDescription &Loc,
2862 BodyGenCallbackTy BodyGenCB,
2863 Value *NumTeamsLower =
nullptr,
2864 Value *NumTeamsUpper =
nullptr,
2865 Value *ThreadLimit =
nullptr,
2866 Value *IfExpr =
nullptr);
2873 LLVM_ABI InsertPointOrErrorTy createDistribute(
const LocationDescription &Loc,
2874 InsertPointTy AllocaIP,
2875 BodyGenCallbackTy BodyGenCB);
2889 LLVM_ABI InsertPointTy createCopyinClauseBlocks(InsertPointTy IP,
2892 llvm::IntegerType *IntPtrTy,
2893 bool BranchtoEnd =
true);
2914 LLVM_ABI CallInst *createOMPFree(
const LocationDescription &Loc,
Value *Addr,
2926 createCachedThreadPrivate(
const LocationDescription &Loc,
2928 const llvm::Twine &Name = Twine(
""));
2941 LLVM_ABI CallInst *createOMPInteropInit(
const LocationDescription &Loc,
2943 omp::OMPInteropType InteropType,
2945 Value *DependenceAddress,
2946 bool HaveNowaitClause);
2958 LLVM_ABI CallInst *createOMPInteropDestroy(
const LocationDescription &Loc,
2960 Value *NumDependences,
2961 Value *DependenceAddress,
2962 bool HaveNowaitClause);
2974 LLVM_ABI CallInst *createOMPInteropUse(
const LocationDescription &Loc,
2976 Value *NumDependences,
2977 Value *DependenceAddress,
2978 bool HaveNowaitClause);
2992 LLVM_ABI InsertPointTy createTargetInit(
2993 const LocationDescription &Loc,
2994 const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
3003 LLVM_ABI void createTargetDeinit(
const LocationDescription &Loc,
3004 int32_t TeamsReductionDataSize = 0,
3005 int32_t TeamsReductionBufferLength = 1024);
3015 LLVM_ABI static std::pair<int32_t, int32_t>
3016 readThreadBoundsForKernel(
const Triple &
T, Function &Kernel);
3017 LLVM_ABI static void writeThreadBoundsForKernel(
const Triple &
T,
3018 Function &Kernel, int32_t LB,
3023 LLVM_ABI static std::pair<int32_t, int32_t>
3024 readTeamBoundsForKernel(
const Triple &
T, Function &Kernel);
3025 LLVM_ABI static void writeTeamsForKernel(
const Triple &
T, Function &Kernel,
3026 int32_t LB, int32_t UB);
3031 void setOutlinedTargetRegionFunctionAttributes(Function *OutlinedFn);
3036 Constant *createOutlinedFunctionID(Function *OutlinedFn,
3037 StringRef EntryFnIDName);
3040 Constant *createTargetRegionEntryAddr(Function *OutlinedFunction,
3041 StringRef EntryFnName);
3045 using FunctionGenCallback =
3046 std::function<Expected<Function *>(StringRef FunctionName)>;
3080 TargetRegionEntryInfo &EntryInfo,
3081 FunctionGenCallback &GenerateFunctionCallback,
bool IsOffloadEntry,
3082 Function *&OutlinedFn, Constant *&OutlinedFnID);
3093 registerTargetRegionFunction(TargetRegionEntryInfo &EntryInfo,
3094 Function *OutlinedFunction,
3095 StringRef EntryFnName, StringRef EntryFnIDName);
3108 enum BodyGenTy { Priv, DupNoPriv, NoPriv };
3113 using GenMapInfoCallbackTy =
3114 function_ref<MapInfosTy &(InsertPointTy CodeGenIP)>;
3123 void emitUDMapperArrayInitOrDel(Function *MapperFn,
llvm::Value *MapperHandle,
3127 llvm::BasicBlock *ExitBB,
bool IsInit);
3170 LLVM_ABI Expected<Function *> emitUserDefinedMapper(
3171 function_ref<MapInfosOrErrorTy(
3173 PrivAndGenMapInfoCB,
3174 llvm::Type *ElemTy, StringRef FuncName,
3175 CustomMapperCallbackTy CustomMapperCB);
3194 LLVM_ABI InsertPointOrErrorTy createTargetData(
3195 const LocationDescription &Loc, InsertPointTy AllocaIP,
3196 InsertPointTy CodeGenIP,
Value *DeviceID,
Value *IfCond,
3197 TargetDataInfo &
Info, GenMapInfoCallbackTy GenMapInfoCB,
3198 CustomMapperCallbackTy CustomMapperCB,
3199 omp::RuntimeFunction *MapperFunc =
nullptr,
3200 function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
3201 BodyGenTy BodyGenType)>
3202 BodyGenCB =
nullptr,
3203 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr,
3204 Value *SrcLocInfo =
nullptr);
3206 using TargetBodyGenCallbackTy = function_ref<InsertPointOrErrorTy(
3207 InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
3209 using TargetGenArgAccessorsCallbackTy = function_ref<InsertPointOrErrorTy(
3210 Argument &Arg,
Value *Input,
Value *&RetVal, InsertPointTy AllocaIP,
3211 InsertPointTy CodeGenIP)>;
3237 LLVM_ABI InsertPointOrErrorTy createTarget(
3238 const LocationDescription &Loc,
bool IsOffloadEntry,
3239 OpenMPIRBuilder::InsertPointTy AllocaIP,
3240 OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetDataInfo &
Info,
3241 TargetRegionEntryInfo &EntryInfo,
3242 const TargetKernelDefaultAttrs &DefaultAttrs,
3243 const TargetKernelRuntimeAttrs &RuntimeAttrs,
Value *IfCond,
3244 SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
3245 TargetBodyGenCallbackTy BodyGenCB,
3246 TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
3247 CustomMapperCallbackTy CustomMapperCB,
3248 const SmallVector<DependData> &Dependencies,
bool HasNowait =
false);
3253 LLVM_ABI FunctionCallee createForStaticInitFunction(
unsigned IVSize,
3255 bool IsGPUDistribute);
3259 LLVM_ABI FunctionCallee createDispatchInitFunction(
unsigned IVSize,
3264 LLVM_ABI FunctionCallee createDispatchNextFunction(
unsigned IVSize,
3269 LLVM_ABI FunctionCallee createDispatchFiniFunction(
unsigned IVSize,
3273 LLVM_ABI FunctionCallee createDispatchDeinitFunction();
3281#define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
3282#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
3283 ArrayType *VarName##Ty = nullptr; \
3284 PointerType *VarName##PtrTy = nullptr;
3285#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
3286 FunctionType *VarName = nullptr; \
3287 PointerType *VarName##Ptr = nullptr;
3288#define OMP_STRUCT_TYPE(VarName, StrName, ...) \
3289 StructType *VarName = nullptr; \
3290 PointerType *VarName##Ptr = nullptr;
3291#include "llvm/Frontend/OpenMP/OMPKinds.def"
3298 void initializeTypes(
Module &M);
3312 InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD,
Value *EntryCall,
3314 bool Conditional =
false);
3326 InsertPointOrErrorTy emitCommonDirectiveExit(omp::Directive OMPD,
3327 InsertPointTy FinIP,
3328 Instruction *ExitCall,
3329 bool HasFinalize =
true);
3347 InsertPointOrErrorTy
3348 EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
3349 Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
3350 FinalizeCallbackTy FiniCB,
bool Conditional =
false,
3351 bool HasFinalize =
true,
bool IsCancellable =
false);
3359 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
3360 StringRef FirstSeparator,
3361 StringRef Separator);
3368 Value *getOMPCriticalRegionLock(StringRef CriticalName);
3382 using AtomicUpdateCallbackTy =
3383 const function_ref<Expected<Value *>(
Value *XOld, IRBuilder<> &IRB)>;
3395 bool checkAndEmitFlushAfterAtomic(
const LocationDescription &Loc,
3396 AtomicOrdering AO, AtomicKind AK);
3422 Expected<std::pair<Value *, Value *>>
3423 emitAtomicUpdate(InsertPointTy AllocaIP,
Value *
X,
Type *XElemTy,
Value *Expr,
3424 AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3425 AtomicUpdateCallbackTy &UpdateOp,
bool VolatileX,
3426 bool IsXBinopExpr,
bool IsIgnoreDenormalMode,
3427 bool IsFineGrainedMemory,
bool IsRemoteMemory);
3433 AtomicRMWInst::BinOp RMWOp);
3439 struct AtomicOpValue {
3440 Value *Var =
nullptr;
3441 Type *ElemTy =
nullptr;
3442 bool IsSigned =
false;
3457 LLVM_ABI InsertPointTy createAtomicRead(
const LocationDescription &Loc,
3458 AtomicOpValue &
X, AtomicOpValue &V,
3460 InsertPointTy AllocaIP);
3472 LLVM_ABI InsertPointTy createAtomicWrite(
const LocationDescription &Loc,
3473 AtomicOpValue &
X,
Value *Expr,
3475 InsertPointTy AllocaIP);
3497 LLVM_ABI InsertPointOrErrorTy createAtomicUpdate(
3498 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3499 Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3500 AtomicUpdateCallbackTy &UpdateOp,
bool IsXBinopExpr,
3501 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3502 bool IsRemoteMemory =
false);
3533 LLVM_ABI InsertPointOrErrorTy createAtomicCapture(
3534 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3535 AtomicOpValue &V,
Value *Expr, AtomicOrdering AO,
3536 AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
3537 bool UpdateExpr,
bool IsPostfixUpdate,
bool IsXBinopExpr,
3538 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3539 bool IsRemoteMemory =
false);
3587 createAtomicCompare(
const LocationDescription &Loc, AtomicOpValue &
X,
3588 AtomicOpValue &V, AtomicOpValue &R,
Value *
E,
Value *
D,
3589 AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
3590 bool IsXBinopExpr,
bool IsPostfixUpdate,
bool IsFailOnly);
3591 LLVM_ABI InsertPointTy createAtomicCompare(
3592 const LocationDescription &Loc, AtomicOpValue &
X, AtomicOpValue &V,
3593 AtomicOpValue &R,
Value *
E,
Value *
D, AtomicOrdering AO,
3594 omp::OMPAtomicCompareOp Op,
bool IsXBinopExpr,
bool IsPostfixUpdate,
3595 bool IsFailOnly, AtomicOrdering Failure);
3613 LLVM_ABI CanonicalLoopInfo *createLoopSkeleton(DebugLoc
DL,
Value *TripCount,
3615 BasicBlock *PreInsertBefore,
3616 BasicBlock *PostInsertBefore,
3617 const Twine &Name = {});
3619 const std::string ompOffloadInfoName =
"omp_offload.info";
3636 LLVM_ABI void loadOffloadInfoMetadata(vfs::FileSystem &VFS,
3637 StringRef HostFilePath);
3646 getOrCreateInternalVariable(
Type *Ty,
const StringRef &Name,
3647 unsigned AddressSpace = 0);
3748class CanonicalLoopInfo {
3749 friend class OpenMPIRBuilder;
3758 Value *LastIter =
nullptr;
3768 void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
3773 void setTripCount(
Value *TripCount);
3789 void mapIndVar(llvm::function_ref<
Value *(Instruction *)> Updater);
3793 void setLastIter(
Value *IterVar) { LastIter = std::move(IterVar); }
3802 Value *getLastIter() {
return LastIter; }
3807 bool isValid()
const {
return Header; }
3834 return cast<BranchInst>(
Cond->getTerminator())->getSuccessor(0);
3858 return Exit->getSingleSuccessor();
3864 Value *getTripCount()
const {
3867 assert(isa<CmpInst>(CmpI) &&
"First inst must compare IV with TripCount");
3868 return CmpI->getOperand(1);
3876 assert(isa<PHINode>(IndVarPHI) &&
"First inst must be the IV PHI");
3881 Type *getIndVarType()
const {
3883 return getIndVar()->getType();
3887 OpenMPIRBuilder::InsertPointTy getPreheaderIP()
const {
3890 return {Preheader, std::prev(Preheader->end())};
3894 OpenMPIRBuilder::InsertPointTy getBodyIP()
const {
3897 return {Body, Body->begin()};
3901 OpenMPIRBuilder::InsertPointTy getAfterIP()
const {
3904 return {After, After->begin()};
3909 return Header->getParent();
3967 llvm::BasicBlock *OMPBeforeScanBlock =
nullptr;
3970 llvm::BasicBlock *OMPAfterScanBlock =
nullptr;
3973 llvm::BasicBlock *OMPScanDispatch =
nullptr;
3976 llvm::BasicBlock *OMPScanLoopExit =
nullptr;
3979 llvm::BasicBlock *OMPScanInit =
nullptr;
3982 llvm::BasicBlock *OMPScanFinish =
nullptr;
3986 bool OMPFirstScanLoop =
false;
3990 llvm::SmallDenseMap<llvm::Value *, llvm::Value *> *ScanBuffPtrs;
4001 ScanBuffPtrs =
new llvm::SmallDenseMap<llvm::Value *, llvm::Value *>();
4004 ~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