14#ifndef LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
15#define LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
28#include <forward_list>
33class CanonicalLoopInfo;
35struct TargetRegionEntryInfo;
36class OffloadEntriesInfoManager;
102class OpenMPIRBuilderConfig {
108 std::optional<bool> IsTargetDevice;
118 std::optional<bool> IsGPU;
121 std::optional<bool> EmitLLVMUsedMetaInfo;
124 std::optional<bool> OpenMPOffloadMandatory;
127 std::optional<StringRef> FirstSeparator;
129 std::optional<StringRef> Separator;
132 std::optional<omp::GV> GridValue;
136 SmallVector<Triple> TargetTriples;
139 unsigned DefaultTargetAS = 0;
142 LLVM_ABI OpenMPIRBuilderConfig(
bool IsTargetDevice,
bool IsGPU,
143 bool OpenMPOffloadMandatory,
144 bool HasRequiresReverseOffload,
145 bool HasRequiresUnifiedAddress,
146 bool HasRequiresUnifiedSharedMemory,
147 bool HasRequiresDynamicAllocators);
150 bool isTargetDevice()
const {
151 assert(IsTargetDevice.has_value() &&
"IsTargetDevice is not set");
152 return *IsTargetDevice;
156 assert(IsGPU.has_value() &&
"IsGPU is not set");
160 bool openMPOffloadMandatory()
const {
161 assert(OpenMPOffloadMandatory.has_value() &&
162 "OpenMPOffloadMandatory is not set");
163 return *OpenMPOffloadMandatory;
167 assert(GridValue.has_value() &&
"GridValue is not set");
171 unsigned getDefaultTargetAS()
const {
return DefaultTargetAS; }
173 bool hasRequiresFlags()
const {
return RequiresFlags; }
174 LLVM_ABI bool hasRequiresReverseOffload()
const;
175 LLVM_ABI bool hasRequiresUnifiedAddress()
const;
176 LLVM_ABI bool hasRequiresUnifiedSharedMemory()
const;
177 LLVM_ABI bool hasRequiresDynamicAllocators()
const;
181 LLVM_ABI int64_t getRequiresFlags()
const;
185 StringRef firstSeparator()
const {
186 if (FirstSeparator.has_value())
187 return *FirstSeparator;
195 StringRef separator()
const {
196 if (Separator.has_value())
203 void setIsTargetDevice(
bool Value) { IsTargetDevice =
Value; }
205 void setEmitLLVMUsed(
bool Value =
true) { EmitLLVMUsedMetaInfo =
Value; }
206 void setOpenMPOffloadMandatory(
bool Value) { OpenMPOffloadMandatory =
Value; }
207 void setFirstSeparator(StringRef FS) { FirstSeparator =
FS; }
208 void setSeparator(StringRef S) { Separator = S; }
209 void setGridValue(omp::GV
G) { GridValue =
G; }
210 void setDefaultTargetAS(
unsigned AS) { DefaultTargetAS = AS; }
219 int64_t RequiresFlags;
224struct TargetRegionEntryInfo {
226 static constexpr const char *KernelNamePrefix =
"__omp_offloading_";
228 std::string ParentName;
234 TargetRegionEntryInfo() : DeviceID(0), FileID(0),
Line(0),
Count(0) {}
235 TargetRegionEntryInfo(StringRef ParentName,
unsigned DeviceID,
236 unsigned FileID,
unsigned Line,
unsigned Count = 0)
237 : ParentName(ParentName), DeviceID(DeviceID), FileID(FileID),
Line(
Line),
241 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name, StringRef ParentName,
242 unsigned DeviceID,
unsigned FileID,
unsigned Line,
245 bool operator<(
const TargetRegionEntryInfo &
RHS)
const {
246 return std::make_tuple(ParentName, DeviceID, FileID, Line, Count) <
247 std::make_tuple(
RHS.ParentName,
RHS.DeviceID,
RHS.FileID,
RHS.Line,
253class OffloadEntriesInfoManager {
255 OpenMPIRBuilder *OMPBuilder;
256 unsigned OffloadingEntriesNum = 0;
260 class OffloadEntryInfo {
263 enum OffloadingEntryInfoKinds :
unsigned {
265 OffloadingEntryInfoTargetRegion = 0,
267 OffloadingEntryInfoDeviceGlobalVar = 1,
269 OffloadingEntryInfoInvalid = ~0
u
273 OffloadEntryInfo() =
delete;
274 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) :
Kind(
Kind) {}
275 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind,
unsigned Order,
278 ~OffloadEntryInfo() =
default;
281 bool isValid()
const {
return Order != ~0
u; }
282 unsigned getOrder()
const {
return Order; }
283 OffloadingEntryInfoKinds getKind()
const {
return Kind; }
285 void setFlags(uint32_t NewFlags) {
Flags = NewFlags; }
286 Constant *getAddress()
const {
return cast_or_null<Constant>(Addr); }
287 void setAddress(Constant *V) {
288 assert(!Addr.pointsToAliveValue() &&
"Address has been set before!");
291 static bool classof(
const OffloadEntryInfo *
Info) {
return true; }
301 unsigned Order = ~0
u;
303 OffloadingEntryInfoKinds
Kind = OffloadingEntryInfoInvalid;
309 unsigned size()
const {
return OffloadingEntriesNum; }
311 OffloadEntriesInfoManager(OpenMPIRBuilder *builder) : OMPBuilder(builder) {}
318 enum OMPTargetRegionEntryKind : uint32_t {
320 OMPTargetRegionEntryTargetRegion = 0x0,
324 class OffloadEntryInfoTargetRegion final :
public OffloadEntryInfo {
329 OffloadEntryInfoTargetRegion()
330 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
331 explicit OffloadEntryInfoTargetRegion(
unsigned Order, Constant *Addr,
333 OMPTargetRegionEntryKind Flags)
334 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order,
Flags),
340 void setID(Constant *V) {
341 assert(!ID &&
"ID has been set before!");
344 static bool classof(
const OffloadEntryInfo *
Info) {
345 return Info->getKind() == OffloadingEntryInfoTargetRegion;
352 initializeTargetRegionEntryInfo(
const TargetRegionEntryInfo &EntryInfo,
355 LLVM_ABI void registerTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
356 Constant *Addr, Constant *ID,
357 OMPTargetRegionEntryKind Flags);
360 LLVM_ABI bool hasTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
361 bool IgnoreAddressId =
false)
const;
365 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name,
366 const TargetRegionEntryInfo &EntryInfo);
369 typedef function_ref<void(
const TargetRegionEntryInfo &EntryInfo,
370 const OffloadEntryInfoTargetRegion &)>
371 OffloadTargetRegionEntryInfoActTy;
373 actOnTargetRegionEntriesInfo(
const OffloadTargetRegionEntryInfoActTy &Action);
380 enum OMPTargetGlobalVarEntryKind : uint32_t {
382 OMPTargetGlobalVarEntryTo = 0x0,
384 OMPTargetGlobalVarEntryLink = 0x1,
386 OMPTargetGlobalVarEntryEnter = 0x2,
388 OMPTargetGlobalVarEntryNone = 0x3,
390 OMPTargetGlobalVarEntryIndirect = 0x8,
392 OMPTargetGlobalRegisterRequires = 0x10,
400 enum OMPTargetDeviceClauseKind : uint32_t {
402 OMPTargetDeviceClauseAny = 0x0,
404 OMPTargetDeviceClauseNoHost = 0x1,
406 OMPTargetDeviceClauseHost = 0x2,
408 OMPTargetDeviceClauseNone = 0x3
412 class OffloadEntryInfoDeviceGlobalVar final :
public OffloadEntryInfo {
415 GlobalValue::LinkageTypes
Linkage;
419 OffloadEntryInfoDeviceGlobalVar()
420 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
421 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order,
422 OMPTargetGlobalVarEntryKind Flags)
423 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags) {}
424 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order, Constant *Addr,
426 OMPTargetGlobalVarEntryKind Flags,
427 GlobalValue::LinkageTypes
Linkage,
428 const std::string &VarName)
429 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags),
434 int64_t getVarSize()
const {
return VarSize; }
436 void setVarSize(int64_t
Size) { VarSize =
Size; }
437 GlobalValue::LinkageTypes getLinkage()
const {
return Linkage; }
438 void setLinkage(GlobalValue::LinkageTypes LT) {
Linkage =
LT; }
439 static bool classof(
const OffloadEntryInfo *
Info) {
440 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
446 LLVM_ABI void initializeDeviceGlobalVarEntryInfo(
447 StringRef Name, OMPTargetGlobalVarEntryKind Flags,
unsigned Order);
450 LLVM_ABI void registerDeviceGlobalVarEntryInfo(
451 StringRef VarName, Constant *Addr, int64_t VarSize,
452 OMPTargetGlobalVarEntryKind Flags, GlobalValue::LinkageTypes
Linkage);
454 bool hasDeviceGlobalVarEntryInfo(StringRef VarName)
const {
455 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
458 typedef function_ref<void(StringRef,
const OffloadEntryInfoDeviceGlobalVar &)>
459 OffloadDeviceGlobalVarEntryInfoActTy;
460 LLVM_ABI void actOnDeviceGlobalVarEntriesInfo(
461 const OffloadDeviceGlobalVarEntryInfoActTy &Action);
466 getTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo)
const;
470 incrementTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo);
472 static TargetRegionEntryInfo
473 getTargetRegionEntryCountKey(
const TargetRegionEntryInfo &EntryInfo) {
474 return TargetRegionEntryInfo(EntryInfo.ParentName, EntryInfo.DeviceID,
475 EntryInfo.FileID, EntryInfo.Line, 0);
479 std::map<TargetRegionEntryInfo, unsigned> OffloadEntriesTargetRegionCount;
482 typedef std::map<TargetRegionEntryInfo, OffloadEntryInfoTargetRegion>
483 OffloadEntriesTargetRegionTy;
484 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
487 typedef StringMap<OffloadEntryInfoDeviceGlobalVar>
488 OffloadEntriesDeviceGlobalVarTy;
489 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
495class OpenMPIRBuilder {
499 OpenMPIRBuilder(
Module &M)
501 T(
M.getTargetTriple()), IsFinalized(
false) {}
504 class AtomicInfo :
public llvm::AtomicInfo {
508 AtomicInfo(IRBuilder<> *Builder, llvm::Type *Ty, uint64_t AtomicSizeInBits,
509 uint64_t ValueSizeInBits, llvm::Align AtomicAlign,
510 llvm::Align ValueAlign,
bool UseLibcall,
511 IRBuilderBase::InsertPoint AllocaIP,
llvm::Value *AtomicVar)
512 : llvm::AtomicInfo(Builder, Ty, AtomicSizeInBits, ValueSizeInBits,
513 AtomicAlign, ValueAlign, UseLibcall, AllocaIP),
514 AtomicVar(AtomicVar) {}
516 llvm::Value *getAtomicPointer()
const override {
return AtomicVar; }
517 void decorateWithTBAA(llvm::Instruction *
I)
override {}
518 llvm::AllocaInst *CreateAlloca(llvm::Type *Ty,
519 const llvm::Twine &Name)
const override {
520 llvm::AllocaInst *allocaInst = Builder->CreateAlloca(Ty);
531 void setConfig(OpenMPIRBuilderConfig
C) { Config =
C; }
543 LLVM_ABI void addAttributes(omp::RuntimeFunction FnID, Function &Fn);
546 using InsertPointTy = IRBuilder<>::InsertPoint;
549 using InsertPointOrErrorTy = Expected<InsertPointTy>;
560 createPlatformSpecificName(ArrayRef<StringRef> Parts)
const;
570 using FinalizeCallbackTy = std::function<
Error(InsertPointTy CodeGenIP)>;
572 struct FinalizationInfo {
575 FinalizeCallbackTy FiniCB;
588 void pushFinalizationCB(
const FinalizationInfo &FI) {
589 FinalizationStack.push_back(FI);
595 void popFinalizationCB() { FinalizationStack.pop_back(); }
623 using BodyGenCallbackTy =
624 function_ref<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
632 using StorableBodyGenCallbackTy =
633 std::function<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
645 using LoopBodyGenCallbackTy =
646 function_ref<
Error(InsertPointTy CodeGenIP,
Value *IndVar)>;
666 using PrivatizeCallbackTy = function_ref<InsertPointOrErrorTy(
667 InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
Value &Original,
672 struct LocationDescription {
673 LocationDescription(
const IRBuilderBase &IRB)
674 : IP(IRB.saveIP()),
DL(IRB.getCurrentDebugLocation()) {}
675 LocationDescription(
const InsertPointTy &IP) : IP(IP) {}
676 LocationDescription(
const InsertPointTy &IP,
const DebugLoc &
DL)
696 LLVM_ABI InsertPointOrErrorTy createBarrier(
const LocationDescription &Loc,
698 bool ForceSimpleCall =
false,
699 bool CheckCancelFlag =
true);
708 LLVM_ABI InsertPointOrErrorTy createCancel(
const LocationDescription &Loc,
710 omp::Directive CanceledDirective);
718 LLVM_ABI InsertPointOrErrorTy createCancellationPoint(
719 const LocationDescription &Loc, omp::Directive CanceledDirective);
722 LLVM_ABI Expected<ScanInfo *> scanInfoInitialize();
737 LLVM_ABI InsertPointOrErrorTy createParallel(
738 const LocationDescription &Loc, InsertPointTy AllocaIP,
739 BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
740 FinalizeCallbackTy FiniCB,
Value *IfCondition,
Value *NumThreads,
741 omp::ProcBindKind ProcBind,
bool IsCancellable);
762 LLVM_ABI Expected<CanonicalLoopInfo *>
763 createCanonicalLoop(
const LocationDescription &Loc,
764 LoopBodyGenCallbackTy BodyGenCB,
Value *TripCount,
765 const Twine &Name =
"loop");
798 LLVM_ABI Expected<SmallVector<llvm::CanonicalLoopInfo *>>
799 createCanonicalScanLoops(
const LocationDescription &Loc,
800 LoopBodyGenCallbackTy BodyGenCB,
Value *Start,
802 bool InclusiveStop, InsertPointTy ComputeIP,
803 const Twine &Name, ScanInfo *ScanRedInfo);
846 const LocationDescription &Loc,
Value *Start,
Value *Stop,
Value *Step,
847 bool IsSigned,
bool InclusiveStop,
const Twine &Name =
"loop");
879 LLVM_ABI Expected<CanonicalLoopInfo *> createCanonicalLoop(
880 const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB,
881 Value *Start,
Value *Stop,
Value *Step,
bool IsSigned,
bool InclusiveStop,
882 InsertPointTy ComputeIP = {},
const Twine &
Name =
"loop",
883 bool InScan =
false, ScanInfo *ScanRedInfo =
nullptr);
945 LLVM_ABI CanonicalLoopInfo *collapseLoops(DebugLoc
DL,
946 ArrayRef<CanonicalLoopInfo *>
Loops,
947 InsertPointTy ComputeIP);
954 getOpenMPDefaultSimdAlign(
const Triple &TargetTriple,
955 const StringMap<bool> &Features);
992 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
993 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
994 bool IsDeclaration,
bool IsExternallyVisible,
995 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
996 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
997 std::vector<Triple> TargetTriple,
Type *LlvmPtrTy,
998 std::function<Constant *()> GlobalInitializer,
999 std::function<GlobalValue::LinkageTypes()> VariableLinkage);
1035 LLVM_ABI void registerTargetGlobalVariable(
1036 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
1037 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
1038 bool IsDeclaration,
bool IsExternallyVisible,
1039 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
1040 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
1041 std::vector<Triple> TargetTriple,
1042 std::function<Constant *()> GlobalInitializer,
1043 std::function<GlobalValue::LinkageTypes()> VariableLinkage,
1044 Type *LlvmPtrTy, Constant *Addr);
1047 LLVM_ABI unsigned getFlagMemberOffset();
1056 LLVM_ABI omp::OpenMPOffloadMappingFlags getMemberOfFlag(
unsigned Position);
1068 setCorrectMemberOfFlag(omp::OpenMPOffloadMappingFlags &Flags,
1069 omp::OpenMPOffloadMappingFlags MemberOfFlag);
1091 InsertPointTy applyWorkshareLoopTarget(DebugLoc
DL, CanonicalLoopInfo *CLI,
1092 InsertPointTy AllocaIP,
1093 omp::WorksharingLoopType LoopType,
1115 InsertPointOrErrorTy applyStaticWorkshareLoop(
1116 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1117 omp::WorksharingLoopType LoopType,
bool NeedsBarrier);
1132 InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(DebugLoc
DL,
1133 CanonicalLoopInfo *CLI,
1134 InsertPointTy AllocaIP,
1158 InsertPointOrErrorTy applyDynamicWorkshareLoop(DebugLoc
DL,
1159 CanonicalLoopInfo *CLI,
1160 InsertPointTy AllocaIP,
1161 omp::OMPScheduleType SchedType,
1163 Value *Chunk =
nullptr);
1176 void createIfVersion(CanonicalLoopInfo *Loop,
Value *IfCond,
1177 ValueMap<const Value *, WeakTrackingVH> &VMap,
1178 LoopAnalysis &LIA, LoopInfo &LI, llvm::Loop *L,
1179 const Twine &NamePrefix =
"");
1217 LLVM_ABI InsertPointOrErrorTy applyWorkshareLoop(
1218 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1220 llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default,
1221 Value *ChunkSize =
nullptr,
bool HasSimdModifier =
false,
1222 bool HasMonotonicModifier =
false,
bool HasNonmonotonicModifier =
false,
1223 bool HasOrderedClause =
false,
1224 omp::WorksharingLoopType LoopType =
1225 omp::WorksharingLoopType::ForStaticLoop,
1226 bool NoLoop =
false);
1271 LLVM_ABI std::vector<CanonicalLoopInfo *>
1272 tileLoops(DebugLoc
DL, ArrayRef<CanonicalLoopInfo *>
Loops,
1273 ArrayRef<Value *> TileSizes);
1283 LLVM_ABI void unrollLoopFull(DebugLoc
DL, CanonicalLoopInfo *Loop);
1290 LLVM_ABI void unrollLoopHeuristic(DebugLoc
DL, CanonicalLoopInfo *Loop);
1314 LLVM_ABI void unrollLoopPartial(DebugLoc
DL, CanonicalLoopInfo *Loop,
1316 CanonicalLoopInfo **UnrolledCLI);
1331 LLVM_ABI void applySimd(CanonicalLoopInfo *Loop,
1332 MapVector<Value *, Value *> AlignedVars,
1333 Value *IfCond, omp::OrderKind Order,
1334 ConstantInt *Simdlen, ConstantInt *Safelen);
1339 LLVM_ABI void createFlush(
const LocationDescription &Loc);
1344 LLVM_ABI void createTaskwait(
const LocationDescription &Loc);
1349 LLVM_ABI void createTaskyield(
const LocationDescription &Loc);
1353 omp::RTLDependenceKindTy DepKind = omp::RTLDependenceKindTy::DepUnknown;
1356 explicit DependData() =
default;
1357 DependData(omp::RTLDependenceKindTy DepKind,
Type *DepValueType,
1359 : DepKind(DepKind), DepValueType(DepValueType), DepVal(DepVal) {}
1382 createTask(
const LocationDescription &Loc, InsertPointTy AllocaIP,
1383 BodyGenCallbackTy BodyGenCB,
bool Tied =
true,
1384 Value *Final =
nullptr,
Value *IfCondition =
nullptr,
1385 SmallVector<DependData> Dependencies = {},
bool Mergeable =
false,
1386 Value *EventHandle =
nullptr,
Value *Priority =
nullptr);
1393 LLVM_ABI InsertPointOrErrorTy createTaskgroup(
const LocationDescription &Loc,
1394 InsertPointTy AllocaIP,
1395 BodyGenCallbackTy BodyGenCB);
1397 using FileIdentifierInfoCallbackTy =
1398 std::function<std::tuple<std::string, uint64_t>()>;
1407 LLVM_ABI static TargetRegionEntryInfo
1408 getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
1409 StringRef ParentName =
"");
1412 enum class ReductionGenCBKind { Clang, MLIR };
1424 using ReductionGenClangCBTy =
1425 std::function<InsertPointTy(InsertPointTy CodeGenIP,
unsigned Index,
1433 using ReductionGenCBTy = std::function<InsertPointOrErrorTy(
1440 using ReductionGenAtomicCBTy = std::function<InsertPointOrErrorTy(
1447 struct ReductionInfo {
1448 ReductionInfo(
Type *ElementType,
Value *Variable,
Value *PrivateVariable,
1449 EvalKind EvaluationKind, ReductionGenCBTy ReductionGen,
1450 ReductionGenClangCBTy ReductionGenClang,
1451 ReductionGenAtomicCBTy AtomicReductionGen)
1453 PrivateVariable(PrivateVariable), EvaluationKind(EvaluationKind),
1454 ReductionGen(ReductionGen), ReductionGenClang(ReductionGenClang),
1455 AtomicReductionGen(AtomicReductionGen) {}
1456 ReductionInfo(
Value *PrivateVariable)
1458 PrivateVariable(PrivateVariable), EvaluationKind(EvalKind::
Scalar),
1459 ReductionGen(), ReductionGenClang(), AtomicReductionGen() {}
1468 Value *PrivateVariable;
1471 EvalKind EvaluationKind;
1476 ReductionGenCBTy ReductionGen;
1481 ReductionGenClangCBTy ReductionGenClang;
1487 ReductionGenAtomicCBTy AtomicReductionGen;
1490 enum class CopyAction :
unsigned {
1498 struct CopyOptionsTy {
1499 Value *RemoteLaneOffset =
nullptr;
1500 Value *ScratchpadIndex =
nullptr;
1501 Value *ScratchpadWidth =
nullptr;
1507 Value *getGPUThreadID();
1510 Value *getGPUWarpSize();
1515 Value *getNVPTXWarpID();
1520 Value *getNVPTXLaneID();
1523 Value *castValueToType(InsertPointTy AllocaIP,
Value *From,
Type *ToType);
1527 Value *createRuntimeShuffleFunction(InsertPointTy AllocaIP,
Value *Element,
1531 void shuffleAndStore(InsertPointTy AllocaIP,
Value *SrcAddr,
Value *DstAddr,
1533 Type *ReductionArrayTy);
1537 void emitReductionListCopy(
1538 InsertPointTy AllocaIP, CopyAction Action,
Type *ReductionArrayTy,
1539 ArrayRef<ReductionInfo> ReductionInfos,
Value *SrcBase,
Value *DestBase,
1540 CopyOptionsTy CopyOptions = {
nullptr,
nullptr,
nullptr});
1615 Function *emitShuffleAndReduceFunction(
1616 ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1617 Function *ReduceFn, AttributeList FuncAttrs);
1627 Error emitScanBasedDirectiveIR(
1628 llvm::function_ref<
Error()> InputLoopGen,
1629 llvm::function_ref<
Error(LocationDescription Loc)> ScanLoopGen,
1630 ScanInfo *ScanRedInfo);
1635 void createScanBBs(ScanInfo *ScanRedInfo);
1645 Error emitScanBasedDirectiveDeclsIR(InsertPointTy AllocaIP,
1646 ArrayRef<llvm::Value *> ScanVars,
1647 ArrayRef<llvm::Type *> ScanVarsType,
1648 ScanInfo *ScanRedInfo);
1656 Error emitScanBasedDirectiveFinalsIR(
1657 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1658 ScanInfo *ScanInfo);
1679 Expected<Function *>
1680 emitInterWarpCopyFunction(
const LocationDescription &Loc,
1681 ArrayRef<ReductionInfo> ReductionInfos,
1682 AttributeList FuncAttrs);
1697 Function *emitListToGlobalCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1698 Type *ReductionsBufferTy,
1699 AttributeList FuncAttrs);
1714 Function *emitGlobalToListCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1715 Type *ReductionsBufferTy,
1716 AttributeList FuncAttrs);
1736 emitListToGlobalReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1737 Function *ReduceFn,
Type *ReductionsBufferTy,
1738 AttributeList FuncAttrs);
1758 emitGlobalToListReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1759 Function *ReduceFn,
Type *ReductionsBufferTy,
1760 AttributeList FuncAttrs);
1763 std::string getReductionFuncName(StringRef Name)
const;
1774 Expected<Function *> createReductionFunction(
1775 StringRef ReducerName, ArrayRef<ReductionInfo> ReductionInfos,
1776 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
1777 AttributeList FuncAttrs = {});
2039 LLVM_ABI InsertPointOrErrorTy createReductionsGPU(
2040 const LocationDescription &Loc, InsertPointTy AllocaIP,
2041 InsertPointTy CodeGenIP, ArrayRef<ReductionInfo> ReductionInfos,
2042 bool IsNoWait =
false,
bool IsTeamsReduction =
false,
2043 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
2044 std::optional<omp::GV> GridValue = {},
unsigned ReductionBufNum = 1024,
2045 Value *SrcLocInfo =
nullptr);
2112 LLVM_ABI InsertPointOrErrorTy createReductions(
2113 const LocationDescription &Loc, InsertPointTy AllocaIP,
2114 ArrayRef<ReductionInfo> ReductionInfos, ArrayRef<bool> IsByRef,
2115 bool IsNoWait =
false,
bool IsTeamsReduction =
false);
2120 InsertPointTy getInsertionPoint() {
return Builder.saveIP(); }
2123 bool updateToLocation(
const LocationDescription &Loc) {
2124 Builder.restoreIP(Loc.IP);
2125 Builder.SetCurrentDebugLocation(Loc.DL);
2126 return Loc.IP.getBlock() !=
nullptr;
2131 omp::RuntimeFunction FnID);
2133 LLVM_ABI Function *getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID);
2137 uint32_t &SrcLocStrSize);
2145 StringRef FileName,
unsigned Line,
2147 uint32_t &SrcLocStrSize);
2152 Function *
F =
nullptr);
2156 uint32_t &SrcLocStrSize);
2161 uint32_t SrcLocStrSize,
2162 omp::IdentFlag Flags = omp::IdentFlag(0),
2163 unsigned Reserve2Flags = 0);
2167 LLVM_ABI GlobalValue *createGlobalFlag(
unsigned Value, StringRef Name);
2170 LLVM_ABI void emitUsed(StringRef Name, ArrayRef<llvm::WeakTrackingVH> List);
2174 emitKernelExecutionMode(StringRef KernelName, omp::OMPTgtExecModeFlags
Mode);
2184 omp::Directive CanceledDirective,
2185 FinalizeCallbackTy ExitCB = {});
2198 LLVM_ABI InsertPointTy emitTargetKernel(
const LocationDescription &Loc,
2199 InsertPointTy AllocaIP,
2203 ArrayRef<Value *> KernelArgs);
2208 LLVM_ABI void emitFlush(
const LocationDescription &Loc);
2213 SmallVector<FinalizationInfo, 8> FinalizationStack;
2217 bool isLastFinalizationInfoCancellable(omp::Directive DK) {
2218 return !FinalizationStack.empty() &&
2219 FinalizationStack.back().IsCancellable &&
2220 FinalizationStack.back().DK == DK;
2226 LLVM_ABI void emitTaskwaitImpl(
const LocationDescription &Loc);
2231 LLVM_ABI void emitTaskyieldImpl(
const LocationDescription &Loc);
2239 OpenMPIRBuilderConfig Config;
2245 IRBuilder<> Builder;
2248 StringMap<Constant *> SrcLocStrMap;
2251 DenseMap<std::pair<Constant *, uint64_t>,
Constant *> IdentMap;
2254 OffloadEntriesInfoManager OffloadInfoManager;
2261 struct OutlineInfo {
2262 using PostOutlineCBTy = std::function<void(Function &)>;
2263 PostOutlineCBTy PostOutlineCB;
2264 BasicBlock *EntryBB, *ExitBB, *OuterAllocaBB;
2265 SmallVector<Value *, 2> ExcludeArgsFromAggregate;
2270 SmallVectorImpl<BasicBlock *> &BlockVector);
2277 SmallVector<OutlineInfo, 16> OutlineInfos;
2282 SmallVector<llvm::Function *, 16> ConstantAllocaRaiseCandidates;
2286 std::forward_list<CanonicalLoopInfo> LoopInfos;
2289 std::forward_list<ScanInfo> ScanInfos;
2292 void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
2299 StringMap<GlobalVariable *, BumpPtrAllocator> InternalVars;
2306 LLVM_ABI void emitBranch(BasicBlock *Target);
2311 LLVM_ABI void emitBlock(BasicBlock *BB, Function *CurFn,
2312 bool IsFinished =
false);
2324 BodyGenCallbackTy ElseGen,
2325 InsertPointTy AllocaIP = {});
2329 createOffloadMaptypes(SmallVectorImpl<uint64_t> &Mappings,
2330 std::string VarName);
2334 createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
2335 std::string VarName);
2337 struct MapperAllocas {
2338 AllocaInst *ArgsBase =
nullptr;
2339 AllocaInst *
Args =
nullptr;
2340 AllocaInst *ArgSizes =
nullptr;
2344 LLVM_ABI void createMapperAllocas(
const LocationDescription &Loc,
2345 InsertPointTy AllocaIP,
2346 unsigned NumOperands,
2347 struct MapperAllocas &MapperAllocas);
2358 LLVM_ABI void emitMapperCall(
const LocationDescription &Loc,
2359 Function *MapperFunc,
Value *SrcLocInfo,
2361 struct MapperAllocas &MapperAllocas,
2362 int64_t DeviceID,
unsigned NumOperands);
2365 struct TargetDataRTArgs {
2367 Value *BasePointersArray =
nullptr;
2369 Value *PointersArray =
nullptr;
2371 Value *SizesArray =
nullptr;
2375 Value *MapTypesArray =
nullptr;
2379 Value *MapTypesArrayEnd =
nullptr;
2381 Value *MappersArray =
nullptr;
2384 Value *MapNamesArray =
nullptr;
2386 explicit TargetDataRTArgs() {}
2387 explicit TargetDataRTArgs(
Value *BasePointersArray,
Value *PointersArray,
2389 Value *MapTypesArrayEnd,
Value *MappersArray,
2390 Value *MapNamesArray)
2391 : BasePointersArray(BasePointersArray), PointersArray(PointersArray),
2392 SizesArray(SizesArray), MapTypesArray(MapTypesArray),
2393 MapTypesArrayEnd(MapTypesArrayEnd), MappersArray(MappersArray),
2394 MapNamesArray(MapNamesArray) {}
2404 struct TargetKernelDefaultAttrs {
2405 omp::OMPTgtExecModeFlags ExecFlags =
2406 omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
2407 SmallVector<int32_t, 3> MaxTeams = {-1};
2408 int32_t MinTeams = 1;
2410 int32_t MinThreads = 1;
2411 int32_t ReductionDataSize = 0;
2412 int32_t ReductionBufferLength = 0;
2420 struct TargetKernelRuntimeAttrs {
2421 SmallVector<Value *, 3> MaxTeams = {
nullptr};
2422 Value *MinTeams =
nullptr;
2423 SmallVector<Value *, 3> TargetThreadLimit = {
nullptr};
2424 SmallVector<Value *, 3> TeamsThreadLimit = {
nullptr};
2432 Value *LoopTripCount =
nullptr;
2437 struct TargetKernelArgs {
2439 unsigned NumTargetItems = 0;
2441 TargetDataRTArgs RTArgs;
2443 Value *NumIterations =
nullptr;
2445 ArrayRef<Value *> NumTeams;
2447 ArrayRef<Value *> NumThreads;
2449 Value *DynCGGroupMem =
nullptr;
2451 bool HasNoWait =
false;
2454 TargetKernelArgs() {}
2455 TargetKernelArgs(
unsigned NumTargetItems, TargetDataRTArgs RTArgs,
2456 Value *NumIterations, ArrayRef<Value *> NumTeams,
2457 ArrayRef<Value *> NumThreads,
Value *DynCGGroupMem,
2459 : NumTargetItems(NumTargetItems), RTArgs(RTArgs),
2460 NumIterations(NumIterations), NumTeams(NumTeams),
2461 NumThreads(NumThreads), DynCGGroupMem(DynCGGroupMem),
2462 HasNoWait(HasNoWait) {}
2468 LLVM_ABI static void getKernelArgsVector(TargetKernelArgs &KernelArgs,
2469 IRBuilderBase &Builder,
2470 SmallVector<Value *> &ArgsVector);
2474 class TargetDataInfo {
2476 bool RequiresDevicePointerInfo =
false;
2479 bool SeparateBeginEndCalls =
false;
2482 TargetDataRTArgs RTArgs;
2484 SmallMapVector<const Value *, std::pair<Value *, Value *>, 4>
2488 bool HasMapper =
false;
2490 unsigned NumberOfPtrs = 0
u;
2492 bool EmitDebug =
false;
2495 bool HasNoWait =
false;
2497 explicit TargetDataInfo() {}
2498 explicit TargetDataInfo(
bool RequiresDevicePointerInfo,
2499 bool SeparateBeginEndCalls)
2500 : RequiresDevicePointerInfo(RequiresDevicePointerInfo),
2501 SeparateBeginEndCalls(SeparateBeginEndCalls) {}
2503 void clearArrayInfo() {
2504 RTArgs = TargetDataRTArgs();
2510 return RTArgs.BasePointersArray && RTArgs.PointersArray &&
2511 RTArgs.SizesArray && RTArgs.MapTypesArray &&
2512 (!HasMapper || RTArgs.MappersArray) && NumberOfPtrs;
2514 bool requiresDevicePointerInfo() {
return RequiresDevicePointerInfo; }
2515 bool separateBeginEndCalls() {
return SeparateBeginEndCalls; }
2519 using MapValuesArrayTy = SmallVector<Value *, 4>;
2520 using MapDeviceInfoArrayTy = SmallVector<DeviceInfoTy, 4>;
2521 using MapFlagsArrayTy = SmallVector<omp::OpenMPOffloadMappingFlags, 4>;
2522 using MapNamesArrayTy = SmallVector<Constant *, 4>;
2523 using MapDimArrayTy = SmallVector<uint64_t, 4>;
2524 using MapNonContiguousArrayTy = SmallVector<MapValuesArrayTy, 4>;
2530 struct StructNonContiguousInfo {
2531 bool IsNonContiguous =
false;
2533 MapNonContiguousArrayTy
Offsets;
2534 MapNonContiguousArrayTy Counts;
2535 MapNonContiguousArrayTy Strides;
2537 MapValuesArrayTy BasePointers;
2538 MapValuesArrayTy Pointers;
2539 MapDeviceInfoArrayTy DevicePointers;
2540 MapValuesArrayTy
Sizes;
2541 MapFlagsArrayTy
Types;
2542 MapNamesArrayTy Names;
2543 StructNonContiguousInfo NonContigInfo;
2546 void append(MapInfosTy &CurInfo) {
2547 BasePointers.append(CurInfo.BasePointers.begin(),
2548 CurInfo.BasePointers.end());
2549 Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
2550 DevicePointers.append(CurInfo.DevicePointers.begin(),
2551 CurInfo.DevicePointers.end());
2552 Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
2553 Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
2554 Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
2555 NonContigInfo.Dims.append(CurInfo.NonContigInfo.Dims.begin(),
2556 CurInfo.NonContigInfo.Dims.end());
2557 NonContigInfo.Offsets.append(CurInfo.NonContigInfo.Offsets.begin(),
2558 CurInfo.NonContigInfo.Offsets.end());
2559 NonContigInfo.Counts.append(CurInfo.NonContigInfo.Counts.begin(),
2560 CurInfo.NonContigInfo.Counts.end());
2561 NonContigInfo.Strides.append(CurInfo.NonContigInfo.Strides.begin(),
2562 CurInfo.NonContigInfo.Strides.end());
2565 using MapInfosOrErrorTy = Expected<MapInfosTy &>;
2571 using EmitFallbackCallbackTy =
2572 function_ref<InsertPointOrErrorTy(InsertPointTy)>;
2576 using CustomMapperCallbackTy =
2577 function_ref<Expected<Function *>(
unsigned int)>;
2589 LLVM_ABI InsertPointOrErrorTy emitKernelLaunch(
2590 const LocationDescription &Loc,
Value *OutlinedFnID,
2591 EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args,
2592 Value *DeviceID,
Value *RTLoc, InsertPointTy AllocaIP);
2604 using TargetTaskBodyCallbackTy =
2606 IRBuilderBase::InsertPoint TargetTaskAllocaIP)>;
2618 LLVM_ABI InsertPointOrErrorTy emitTargetTask(
2619 TargetTaskBodyCallbackTy TaskBodyCB,
Value *DeviceID,
Value *RTLoc,
2620 OpenMPIRBuilder::InsertPointTy AllocaIP,
2621 const SmallVector<llvm::OpenMPIRBuilder::DependData> &Dependencies,
2622 const TargetDataRTArgs &RTArgs,
bool HasNoWait);
2628 LLVM_ABI void emitOffloadingArraysArgument(
2629 IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs,
2630 OpenMPIRBuilder::TargetDataInfo &
Info,
bool ForEndCall =
false);
2633 LLVM_ABI void emitNonContiguousDescriptor(InsertPointTy AllocaIP,
2634 InsertPointTy CodeGenIP,
2635 MapInfosTy &CombinedInfo,
2636 TargetDataInfo &
Info);
2644 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
2645 TargetDataInfo &
Info, CustomMapperCallbackTy CustomMapperCB,
2646 bool IsNonContiguous =
false,
2647 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2656 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &
Info,
2657 TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
2658 CustomMapperCallbackTy CustomMapperCB,
bool IsNonContiguous =
false,
2659 bool ForEndCall =
false,
2660 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2664 LLVM_ABI void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t
Size,
2665 int32_t Flags, GlobalValue::LinkageTypes,
2666 StringRef Name =
"");
2670 enum EmitMetadataErrorKind {
2671 EMIT_MD_TARGET_REGION_ERROR,
2672 EMIT_MD_DECLARE_TARGET_ERROR,
2673 EMIT_MD_GLOBAL_VAR_LINK_ERROR
2677 using EmitMetadataErrorReportFunctionTy =
2678 std::function<void(EmitMetadataErrorKind, TargetRegionEntryInfo)>;
2687 LLVM_ABI void createOffloadEntriesAndInfoMetadata(
2688 EmitMetadataErrorReportFunctionTy &ErrorReportFunction);
2701 LLVM_ABI InsertPointTy createCopyPrivate(
const LocationDescription &Loc,
2718 createSingle(
const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2719 FinalizeCallbackTy FiniCB,
bool IsNowait,
2720 ArrayRef<llvm::Value *> CPVars = {},
2721 ArrayRef<llvm::Function *> CPFuncs = {});
2730 LLVM_ABI InsertPointOrErrorTy createMaster(
const LocationDescription &Loc,
2731 BodyGenCallbackTy BodyGenCB,
2732 FinalizeCallbackTy FiniCB);
2741 LLVM_ABI InsertPointOrErrorTy createMasked(
const LocationDescription &Loc,
2742 BodyGenCallbackTy BodyGenCB,
2743 FinalizeCallbackTy FiniCB,
2764 LLVM_ABI InsertPointOrErrorTy emitScanReduction(
2765 const LocationDescription &Loc,
2766 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
2767 ScanInfo *ScanRedInfo);
2782 LLVM_ABI InsertPointOrErrorTy createScan(
const LocationDescription &Loc,
2783 InsertPointTy AllocaIP,
2784 ArrayRef<llvm::Value *> ScanVars,
2785 ArrayRef<llvm::Type *> ScanVarsType,
2787 ScanInfo *ScanRedInfo);
2798 LLVM_ABI InsertPointOrErrorTy createCritical(
const LocationDescription &Loc,
2799 BodyGenCallbackTy BodyGenCB,
2800 FinalizeCallbackTy FiniCB,
2801 StringRef CriticalName,
2815 createOrderedDepend(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2816 unsigned NumLoops, ArrayRef<llvm::Value *> StoreValues,
2817 const Twine &Name,
bool IsDependSource);
2828 LLVM_ABI InsertPointOrErrorTy createOrderedThreadsSimd(
2829 const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2830 FinalizeCallbackTy FiniCB,
bool IsThreads);
2844 createSections(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2845 ArrayRef<StorableBodyGenCallbackTy> SectionCBs,
2846 PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB,
2847 bool IsCancellable,
bool IsNowait);
2855 LLVM_ABI InsertPointOrErrorTy createSection(
const LocationDescription &Loc,
2856 BodyGenCallbackTy BodyGenCB,
2857 FinalizeCallbackTy FiniCB);
2871 LLVM_ABI InsertPointOrErrorTy createTeams(
const LocationDescription &Loc,
2872 BodyGenCallbackTy BodyGenCB,
2873 Value *NumTeamsLower =
nullptr,
2874 Value *NumTeamsUpper =
nullptr,
2875 Value *ThreadLimit =
nullptr,
2876 Value *IfExpr =
nullptr);
2883 LLVM_ABI InsertPointOrErrorTy createDistribute(
const LocationDescription &Loc,
2884 InsertPointTy AllocaIP,
2885 BodyGenCallbackTy BodyGenCB);
2899 LLVM_ABI InsertPointTy createCopyinClauseBlocks(InsertPointTy IP,
2902 llvm::IntegerType *IntPtrTy,
2903 bool BranchtoEnd =
true);
2924 LLVM_ABI CallInst *createOMPFree(
const LocationDescription &Loc,
Value *Addr,
2936 createCachedThreadPrivate(
const LocationDescription &Loc,
2938 const llvm::Twine &Name = Twine(
""));
2951 LLVM_ABI CallInst *createOMPInteropInit(
const LocationDescription &Loc,
2953 omp::OMPInteropType InteropType,
2955 Value *DependenceAddress,
2956 bool HaveNowaitClause);
2968 LLVM_ABI CallInst *createOMPInteropDestroy(
const LocationDescription &Loc,
2970 Value *NumDependences,
2971 Value *DependenceAddress,
2972 bool HaveNowaitClause);
2984 LLVM_ABI CallInst *createOMPInteropUse(
const LocationDescription &Loc,
2986 Value *NumDependences,
2987 Value *DependenceAddress,
2988 bool HaveNowaitClause);
3002 LLVM_ABI InsertPointTy createTargetInit(
3003 const LocationDescription &Loc,
3004 const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
3013 LLVM_ABI void createTargetDeinit(
const LocationDescription &Loc,
3014 int32_t TeamsReductionDataSize = 0,
3015 int32_t TeamsReductionBufferLength = 1024);
3025 LLVM_ABI static std::pair<int32_t, int32_t>
3026 readThreadBoundsForKernel(
const Triple &
T, Function &Kernel);
3027 LLVM_ABI static void writeThreadBoundsForKernel(
const Triple &
T,
3028 Function &Kernel, int32_t LB,
3033 LLVM_ABI static std::pair<int32_t, int32_t>
3034 readTeamBoundsForKernel(
const Triple &
T, Function &Kernel);
3035 LLVM_ABI static void writeTeamsForKernel(
const Triple &
T, Function &Kernel,
3036 int32_t LB, int32_t UB);
3041 void setOutlinedTargetRegionFunctionAttributes(Function *OutlinedFn);
3046 Constant *createOutlinedFunctionID(Function *OutlinedFn,
3047 StringRef EntryFnIDName);
3050 Constant *createTargetRegionEntryAddr(Function *OutlinedFunction,
3051 StringRef EntryFnName);
3055 using FunctionGenCallback =
3056 std::function<Expected<Function *>(StringRef FunctionName)>;
3090 TargetRegionEntryInfo &EntryInfo,
3091 FunctionGenCallback &GenerateFunctionCallback,
bool IsOffloadEntry,
3092 Function *&OutlinedFn, Constant *&OutlinedFnID);
3103 registerTargetRegionFunction(TargetRegionEntryInfo &EntryInfo,
3104 Function *OutlinedFunction,
3105 StringRef EntryFnName, StringRef EntryFnIDName);
3118 enum BodyGenTy { Priv, DupNoPriv, NoPriv };
3123 using GenMapInfoCallbackTy =
3124 function_ref<MapInfosTy &(InsertPointTy CodeGenIP)>;
3133 void emitUDMapperArrayInitOrDel(Function *MapperFn,
llvm::Value *MapperHandle,
3137 llvm::BasicBlock *ExitBB,
bool IsInit);
3180 LLVM_ABI Expected<Function *> emitUserDefinedMapper(
3181 function_ref<MapInfosOrErrorTy(
3183 PrivAndGenMapInfoCB,
3184 llvm::Type *ElemTy, StringRef FuncName,
3185 CustomMapperCallbackTy CustomMapperCB);
3204 LLVM_ABI InsertPointOrErrorTy createTargetData(
3205 const LocationDescription &Loc, InsertPointTy AllocaIP,
3206 InsertPointTy CodeGenIP,
Value *DeviceID,
Value *IfCond,
3207 TargetDataInfo &
Info, GenMapInfoCallbackTy GenMapInfoCB,
3208 CustomMapperCallbackTy CustomMapperCB,
3209 omp::RuntimeFunction *MapperFunc =
nullptr,
3210 function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
3211 BodyGenTy BodyGenType)>
3212 BodyGenCB =
nullptr,
3213 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr,
3214 Value *SrcLocInfo =
nullptr);
3216 using TargetBodyGenCallbackTy = function_ref<InsertPointOrErrorTy(
3217 InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
3219 using TargetGenArgAccessorsCallbackTy = function_ref<InsertPointOrErrorTy(
3220 Argument &Arg,
Value *Input,
Value *&RetVal, InsertPointTy AllocaIP,
3221 InsertPointTy CodeGenIP)>;
3247 LLVM_ABI InsertPointOrErrorTy createTarget(
3248 const LocationDescription &Loc,
bool IsOffloadEntry,
3249 OpenMPIRBuilder::InsertPointTy AllocaIP,
3250 OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetDataInfo &
Info,
3251 TargetRegionEntryInfo &EntryInfo,
3252 const TargetKernelDefaultAttrs &DefaultAttrs,
3253 const TargetKernelRuntimeAttrs &RuntimeAttrs,
Value *IfCond,
3254 SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
3255 TargetBodyGenCallbackTy BodyGenCB,
3256 TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
3257 CustomMapperCallbackTy CustomMapperCB,
3258 const SmallVector<DependData> &Dependencies,
bool HasNowait =
false);
3263 LLVM_ABI FunctionCallee createForStaticInitFunction(
unsigned IVSize,
3265 bool IsGPUDistribute);
3269 LLVM_ABI FunctionCallee createDispatchInitFunction(
unsigned IVSize,
3274 LLVM_ABI FunctionCallee createDispatchNextFunction(
unsigned IVSize,
3279 LLVM_ABI FunctionCallee createDispatchFiniFunction(
unsigned IVSize,
3283 LLVM_ABI FunctionCallee createDispatchDeinitFunction();
3291#define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
3292#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
3293 ArrayType *VarName##Ty = nullptr; \
3294 PointerType *VarName##PtrTy = nullptr;
3295#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
3296 FunctionType *VarName = nullptr; \
3297 PointerType *VarName##Ptr = nullptr;
3298#define OMP_STRUCT_TYPE(VarName, StrName, ...) \
3299 StructType *VarName = nullptr; \
3300 PointerType *VarName##Ptr = nullptr;
3301#include "llvm/Frontend/OpenMP/OMPKinds.def"
3308 void initializeTypes(
Module &M);
3322 InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD,
Value *EntryCall,
3324 bool Conditional =
false);
3336 InsertPointOrErrorTy emitCommonDirectiveExit(omp::Directive OMPD,
3337 InsertPointTy FinIP,
3338 Instruction *ExitCall,
3339 bool HasFinalize =
true);
3357 InsertPointOrErrorTy
3358 EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
3359 Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
3360 FinalizeCallbackTy FiniCB,
bool Conditional =
false,
3361 bool HasFinalize =
true,
bool IsCancellable =
false);
3369 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
3370 StringRef FirstSeparator,
3371 StringRef Separator);
3378 Value *getOMPCriticalRegionLock(StringRef CriticalName);
3392 using AtomicUpdateCallbackTy =
3393 const function_ref<Expected<Value *>(
Value *XOld, IRBuilder<> &IRB)>;
3405 bool checkAndEmitFlushAfterAtomic(
const LocationDescription &Loc,
3406 AtomicOrdering AO, AtomicKind AK);
3432 Expected<std::pair<Value *, Value *>>
3433 emitAtomicUpdate(InsertPointTy AllocaIP,
Value *
X,
Type *XElemTy,
Value *Expr,
3434 AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3435 AtomicUpdateCallbackTy &UpdateOp,
bool VolatileX,
3436 bool IsXBinopExpr,
bool IsIgnoreDenormalMode,
3437 bool IsFineGrainedMemory,
bool IsRemoteMemory);
3443 AtomicRMWInst::BinOp RMWOp);
3449 struct AtomicOpValue {
3450 Value *Var =
nullptr;
3451 Type *ElemTy =
nullptr;
3452 bool IsSigned =
false;
3467 LLVM_ABI InsertPointTy createAtomicRead(
const LocationDescription &Loc,
3468 AtomicOpValue &
X, AtomicOpValue &V,
3470 InsertPointTy AllocaIP);
3482 LLVM_ABI InsertPointTy createAtomicWrite(
const LocationDescription &Loc,
3483 AtomicOpValue &
X,
Value *Expr,
3485 InsertPointTy AllocaIP);
3507 LLVM_ABI InsertPointOrErrorTy createAtomicUpdate(
3508 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3509 Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3510 AtomicUpdateCallbackTy &UpdateOp,
bool IsXBinopExpr,
3511 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3512 bool IsRemoteMemory =
false);
3543 LLVM_ABI InsertPointOrErrorTy createAtomicCapture(
3544 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3545 AtomicOpValue &V,
Value *Expr, AtomicOrdering AO,
3546 AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
3547 bool UpdateExpr,
bool IsPostfixUpdate,
bool IsXBinopExpr,
3548 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3549 bool IsRemoteMemory =
false);
3597 createAtomicCompare(
const LocationDescription &Loc, AtomicOpValue &
X,
3598 AtomicOpValue &V, AtomicOpValue &R,
Value *
E,
Value *
D,
3599 AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
3600 bool IsXBinopExpr,
bool IsPostfixUpdate,
bool IsFailOnly);
3601 LLVM_ABI InsertPointTy createAtomicCompare(
3602 const LocationDescription &Loc, AtomicOpValue &
X, AtomicOpValue &V,
3603 AtomicOpValue &R,
Value *
E,
Value *
D, AtomicOrdering AO,
3604 omp::OMPAtomicCompareOp Op,
bool IsXBinopExpr,
bool IsPostfixUpdate,
3605 bool IsFailOnly, AtomicOrdering Failure);
3623 LLVM_ABI CanonicalLoopInfo *createLoopSkeleton(DebugLoc
DL,
Value *TripCount,
3625 BasicBlock *PreInsertBefore,
3626 BasicBlock *PostInsertBefore,
3627 const Twine &Name = {});
3629 const std::string ompOffloadInfoName =
"omp_offload.info";
3646 LLVM_ABI void loadOffloadInfoMetadata(vfs::FileSystem &VFS,
3647 StringRef HostFilePath);
3656 getOrCreateInternalVariable(
Type *Ty,
const StringRef &Name,
3657 unsigned AddressSpace = 0);
3758class CanonicalLoopInfo {
3759 friend class OpenMPIRBuilder;
3768 Value *LastIter =
nullptr;
3778 void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
3783 void setTripCount(
Value *TripCount);
3799 void mapIndVar(llvm::function_ref<
Value *(Instruction *)> Updater);
3803 void setLastIter(
Value *IterVar) { LastIter = std::move(IterVar); }
3812 Value *getLastIter() {
return LastIter; }
3817 bool isValid()
const {
return Header; }
3844 return cast<BranchInst>(
Cond->getTerminator())->getSuccessor(0);
3868 return Exit->getSingleSuccessor();
3874 Value *getTripCount()
const {
3877 assert(isa<CmpInst>(CmpI) &&
"First inst must compare IV with TripCount");
3878 return CmpI->getOperand(1);
3886 assert(isa<PHINode>(IndVarPHI) &&
"First inst must be the IV PHI");
3891 Type *getIndVarType()
const {
3893 return getIndVar()->getType();
3897 OpenMPIRBuilder::InsertPointTy getPreheaderIP()
const {
3900 return {Preheader, std::prev(Preheader->end())};
3904 OpenMPIRBuilder::InsertPointTy getBodyIP()
const {
3907 return {Body, Body->begin()};
3911 OpenMPIRBuilder::InsertPointTy getAfterIP()
const {
3914 return {After, After->begin()};
3919 return Header->getParent();
3977 llvm::BasicBlock *OMPBeforeScanBlock =
nullptr;
3980 llvm::BasicBlock *OMPAfterScanBlock =
nullptr;
3983 llvm::BasicBlock *OMPScanDispatch =
nullptr;
3986 llvm::BasicBlock *OMPScanLoopExit =
nullptr;
3989 llvm::BasicBlock *OMPScanInit =
nullptr;
3992 llvm::BasicBlock *OMPScanFinish =
nullptr;
3996 bool OMPFirstScanLoop =
false;
4000 llvm::SmallDenseMap<llvm::Value *, llvm::Value *> *ScanBuffPtrs;
4011 ScanBuffPtrs =
new llvm::SmallDenseMap<llvm::Value *, llvm::Value *>();
4014 ~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