14#ifndef LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
15#define LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
30#include <forward_list>
35class CanonicalLoopInfo;
37struct TargetRegionEntryInfo;
38class OffloadEntriesInfoManager;
104class OpenMPIRBuilderConfig {
110 std::optional<bool> IsTargetDevice;
120 std::optional<bool> IsGPU;
123 std::optional<bool> EmitLLVMUsedMetaInfo;
126 std::optional<bool> OpenMPOffloadMandatory;
129 std::optional<StringRef> FirstSeparator;
131 std::optional<StringRef> Separator;
134 std::optional<omp::GV> GridValue;
138 SmallVector<Triple> TargetTriples;
141 unsigned DefaultTargetAS = 0;
146 LLVM_ABI OpenMPIRBuilderConfig(
bool IsTargetDevice,
bool IsGPU,
147 bool OpenMPOffloadMandatory,
148 bool HasRequiresReverseOffload,
149 bool HasRequiresUnifiedAddress,
150 bool HasRequiresUnifiedSharedMemory,
151 bool HasRequiresDynamicAllocators);
154 bool isTargetDevice()
const {
155 assert(IsTargetDevice.has_value() &&
"IsTargetDevice is not set");
156 return *IsTargetDevice;
160 assert(IsGPU.has_value() &&
"IsGPU is not set");
164 bool openMPOffloadMandatory()
const {
165 assert(OpenMPOffloadMandatory.has_value() &&
166 "OpenMPOffloadMandatory is not set");
167 return *OpenMPOffloadMandatory;
171 assert(GridValue.has_value() &&
"GridValue is not set");
175 unsigned getDefaultTargetAS()
const {
return DefaultTargetAS; }
177 CallingConv::ID getRuntimeCC()
const {
return RuntimeCC; }
179 bool hasRequiresFlags()
const {
return RequiresFlags; }
180 LLVM_ABI bool hasRequiresReverseOffload()
const;
181 LLVM_ABI bool hasRequiresUnifiedAddress()
const;
182 LLVM_ABI bool hasRequiresUnifiedSharedMemory()
const;
183 LLVM_ABI bool hasRequiresDynamicAllocators()
const;
187 LLVM_ABI int64_t getRequiresFlags()
const;
191 StringRef firstSeparator()
const {
192 if (FirstSeparator.has_value())
193 return *FirstSeparator;
201 StringRef separator()
const {
202 if (Separator.has_value())
209 void setIsTargetDevice(
bool Value) { IsTargetDevice =
Value; }
211 void setEmitLLVMUsed(
bool Value =
true) { EmitLLVMUsedMetaInfo =
Value; }
212 void setOpenMPOffloadMandatory(
bool Value) { OpenMPOffloadMandatory =
Value; }
213 void setFirstSeparator(StringRef FS) { FirstSeparator =
FS; }
214 void setSeparator(StringRef S) { Separator = S; }
215 void setGridValue(omp::GV
G) { GridValue =
G; }
216 void setDefaultTargetAS(
unsigned AS) { DefaultTargetAS = AS; }
217 void setRuntimeCC(CallingConv::ID CC) { RuntimeCC = CC; }
226 int64_t RequiresFlags;
231struct TargetRegionEntryInfo {
233 static constexpr const char *KernelNamePrefix =
"__omp_offloading_";
235 std::string ParentName;
241 TargetRegionEntryInfo() : DeviceID(0), FileID(0),
Line(0),
Count(0) {}
242 TargetRegionEntryInfo(StringRef ParentName,
unsigned DeviceID,
243 unsigned FileID,
unsigned Line,
unsigned Count = 0)
244 : ParentName(ParentName), DeviceID(DeviceID), FileID(FileID),
Line(
Line),
248 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name, StringRef ParentName,
249 unsigned DeviceID,
unsigned FileID,
unsigned Line,
252 bool operator<(
const TargetRegionEntryInfo &
RHS)
const {
253 return std::make_tuple(ParentName, DeviceID, FileID, Line, Count) <
254 std::make_tuple(
RHS.ParentName,
RHS.DeviceID,
RHS.FileID,
RHS.Line,
260class OffloadEntriesInfoManager {
262 OpenMPIRBuilder *OMPBuilder;
263 unsigned OffloadingEntriesNum = 0;
267 class OffloadEntryInfo {
270 enum OffloadingEntryInfoKinds :
unsigned {
272 OffloadingEntryInfoTargetRegion = 0,
274 OffloadingEntryInfoDeviceGlobalVar = 1,
276 OffloadingEntryInfoInvalid = ~0
u
280 OffloadEntryInfo() =
delete;
281 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) :
Kind(
Kind) {}
282 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind,
unsigned Order,
285 ~OffloadEntryInfo() =
default;
288 bool isValid()
const {
return Order != ~0
u; }
289 unsigned getOrder()
const {
return Order; }
290 OffloadingEntryInfoKinds getKind()
const {
return Kind; }
292 void setFlags(uint32_t NewFlags) {
Flags = NewFlags; }
293 Constant *getAddress()
const {
return cast_or_null<Constant>(Addr); }
294 void setAddress(Constant *V) {
295 assert(!Addr.pointsToAliveValue() &&
"Address has been set before!");
298 static bool classof(
const OffloadEntryInfo *
Info) {
return true; }
308 unsigned Order = ~0
u;
310 OffloadingEntryInfoKinds
Kind = OffloadingEntryInfoInvalid;
316 unsigned size()
const {
return OffloadingEntriesNum; }
318 OffloadEntriesInfoManager(OpenMPIRBuilder *builder) : OMPBuilder(builder) {}
325 enum OMPTargetRegionEntryKind : uint32_t {
327 OMPTargetRegionEntryTargetRegion = 0x0,
331 class OffloadEntryInfoTargetRegion final :
public OffloadEntryInfo {
336 OffloadEntryInfoTargetRegion()
337 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
338 explicit OffloadEntryInfoTargetRegion(
unsigned Order, Constant *Addr,
340 OMPTargetRegionEntryKind Flags)
341 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order,
Flags),
347 void setID(Constant *V) {
348 assert(!ID &&
"ID has been set before!");
351 static bool classof(
const OffloadEntryInfo *
Info) {
352 return Info->getKind() == OffloadingEntryInfoTargetRegion;
359 initializeTargetRegionEntryInfo(
const TargetRegionEntryInfo &EntryInfo,
362 LLVM_ABI void registerTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
363 Constant *Addr, Constant *ID,
364 OMPTargetRegionEntryKind Flags);
367 LLVM_ABI bool hasTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
368 bool IgnoreAddressId =
false)
const;
372 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name,
373 const TargetRegionEntryInfo &EntryInfo);
376 typedef function_ref<void(
const TargetRegionEntryInfo &EntryInfo,
377 const OffloadEntryInfoTargetRegion &)>
378 OffloadTargetRegionEntryInfoActTy;
380 actOnTargetRegionEntriesInfo(
const OffloadTargetRegionEntryInfoActTy &Action);
387 enum OMPTargetGlobalVarEntryKind : uint32_t {
389 OMPTargetGlobalVarEntryTo = 0x0,
391 OMPTargetGlobalVarEntryLink = 0x1,
393 OMPTargetGlobalVarEntryEnter = 0x2,
395 OMPTargetGlobalVarEntryNone = 0x3,
397 OMPTargetGlobalVarEntryIndirect = 0x8,
399 OMPTargetGlobalRegisterRequires = 0x10,
401 OMPTargetGlobalVarEntryIndirectVTable = 0x20,
409 enum OMPTargetDeviceClauseKind : uint32_t {
411 OMPTargetDeviceClauseAny = 0x0,
413 OMPTargetDeviceClauseNoHost = 0x1,
415 OMPTargetDeviceClauseHost = 0x2,
417 OMPTargetDeviceClauseNone = 0x3
421 class OffloadEntryInfoDeviceGlobalVar final :
public OffloadEntryInfo {
424 GlobalValue::LinkageTypes
Linkage;
428 OffloadEntryInfoDeviceGlobalVar()
429 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
430 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order,
431 OMPTargetGlobalVarEntryKind Flags)
432 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags) {}
433 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order, Constant *Addr,
435 OMPTargetGlobalVarEntryKind Flags,
436 GlobalValue::LinkageTypes
Linkage,
437 const std::string &VarName)
438 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags),
443 int64_t getVarSize()
const {
return VarSize; }
445 void setVarSize(int64_t
Size) { VarSize =
Size; }
446 GlobalValue::LinkageTypes getLinkage()
const {
return Linkage; }
447 void setLinkage(GlobalValue::LinkageTypes LT) {
Linkage =
LT; }
448 static bool classof(
const OffloadEntryInfo *
Info) {
449 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
455 LLVM_ABI void initializeDeviceGlobalVarEntryInfo(
456 StringRef Name, OMPTargetGlobalVarEntryKind Flags,
unsigned Order);
459 LLVM_ABI void registerDeviceGlobalVarEntryInfo(
460 StringRef VarName, Constant *Addr, int64_t VarSize,
461 OMPTargetGlobalVarEntryKind Flags, GlobalValue::LinkageTypes
Linkage);
463 bool hasDeviceGlobalVarEntryInfo(StringRef VarName)
const {
464 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
467 typedef function_ref<void(StringRef,
const OffloadEntryInfoDeviceGlobalVar &)>
468 OffloadDeviceGlobalVarEntryInfoActTy;
469 LLVM_ABI void actOnDeviceGlobalVarEntriesInfo(
470 const OffloadDeviceGlobalVarEntryInfoActTy &Action);
475 getTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo)
const;
479 incrementTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo);
481 static TargetRegionEntryInfo
482 getTargetRegionEntryCountKey(
const TargetRegionEntryInfo &EntryInfo) {
483 return TargetRegionEntryInfo(EntryInfo.ParentName, EntryInfo.DeviceID,
484 EntryInfo.FileID, EntryInfo.Line, 0);
488 std::map<TargetRegionEntryInfo, unsigned> OffloadEntriesTargetRegionCount;
491 typedef std::map<TargetRegionEntryInfo, OffloadEntryInfoTargetRegion>
492 OffloadEntriesTargetRegionTy;
493 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
496 typedef StringMap<OffloadEntryInfoDeviceGlobalVar>
497 OffloadEntriesDeviceGlobalVarTy;
498 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
504class OpenMPIRBuilder {
508 OpenMPIRBuilder(
Module &M)
510 T(
M.getTargetTriple()), IsFinalized(
false) {}
513 class AtomicInfo :
public llvm::AtomicInfo {
517 AtomicInfo(IRBuilder<> *Builder, llvm::Type *Ty, uint64_t AtomicSizeInBits,
518 uint64_t ValueSizeInBits, llvm::Align AtomicAlign,
519 llvm::Align ValueAlign,
bool UseLibcall,
520 IRBuilderBase::InsertPoint AllocaIP,
llvm::Value *AtomicVar)
521 : llvm::AtomicInfo(Builder, Ty, AtomicSizeInBits, ValueSizeInBits,
522 AtomicAlign, ValueAlign, UseLibcall, AllocaIP),
523 AtomicVar(AtomicVar) {}
525 llvm::Value *getAtomicPointer()
const override {
return AtomicVar; }
526 void decorateWithTBAA(llvm::Instruction *
I)
override {}
527 llvm::AllocaInst *CreateAlloca(llvm::Type *Ty,
528 const llvm::Twine &Name)
const override {
529 llvm::AllocaInst *allocaInst = Builder->CreateAlloca(Ty);
540 void setConfig(OpenMPIRBuilderConfig
C) { Config =
C; }
552 LLVM_ABI void addAttributes(omp::RuntimeFunction FnID, Function &Fn);
555 using InsertPointTy = IRBuilder<>::InsertPoint;
558 using InsertPointOrErrorTy = Expected<InsertPointTy>;
569 createPlatformSpecificName(ArrayRef<StringRef> Parts)
const;
579 using FinalizeCallbackTy = std::function<
Error(InsertPointTy CodeGenIP)>;
581 struct FinalizationInfo {
582 FinalizationInfo(FinalizeCallbackTy FiniCB, omp::Directive DK,
584 : DK(DK), IsCancellable(IsCancellable), FiniCB(std::
move(FiniCB)) {}
587 const omp::Directive DK;
590 const bool IsCancellable;
595 Expected<BasicBlock *> getFiniBB(IRBuilderBase &Builder);
600 Error mergeFiniBB(IRBuilderBase &Builder, BasicBlock *ExistingFiniBB);
608 FinalizeCallbackTy FiniCB;
614 void pushFinalizationCB(
const FinalizationInfo &FI) {
615 FinalizationStack.push_back(FI);
621 void popFinalizationCB() { FinalizationStack.pop_back(); }
649 using BodyGenCallbackTy =
650 function_ref<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
680 using TaskDupCallbackTy = function_ref<Expected<InsertPointTy>(
681 InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
Value *DestPtr,
690 using StorableBodyGenCallbackTy =
691 std::function<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
703 using LoopBodyGenCallbackTy =
704 function_ref<
Error(InsertPointTy CodeGenIP,
Value *IndVar)>;
724 using PrivatizeCallbackTy = function_ref<InsertPointOrErrorTy(
725 InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
Value &Original,
730 struct LocationDescription {
731 LocationDescription(
const IRBuilderBase &IRB)
732 : IP(IRB.saveIP()),
DL(IRB.getCurrentDebugLocation()) {}
733 LocationDescription(
const InsertPointTy &IP) : IP(IP) {}
734 LocationDescription(
const InsertPointTy &IP,
const DebugLoc &
DL)
754 LLVM_ABI InsertPointOrErrorTy createBarrier(
const LocationDescription &Loc,
756 bool ForceSimpleCall =
false,
757 bool CheckCancelFlag =
true);
766 LLVM_ABI InsertPointOrErrorTy createCancel(
const LocationDescription &Loc,
768 omp::Directive CanceledDirective);
776 LLVM_ABI InsertPointOrErrorTy createCancellationPoint(
777 const LocationDescription &Loc, omp::Directive CanceledDirective);
780 LLVM_ABI Expected<ScanInfo *> scanInfoInitialize();
795 LLVM_ABI InsertPointOrErrorTy createParallel(
796 const LocationDescription &Loc, InsertPointTy AllocaIP,
797 BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
798 FinalizeCallbackTy FiniCB,
Value *IfCondition,
Value *NumThreads,
799 omp::ProcBindKind ProcBind,
bool IsCancellable);
820 LLVM_ABI Expected<CanonicalLoopInfo *>
821 createCanonicalLoop(
const LocationDescription &Loc,
822 LoopBodyGenCallbackTy BodyGenCB,
Value *TripCount,
823 const Twine &Name =
"loop");
856 LLVM_ABI Expected<SmallVector<llvm::CanonicalLoopInfo *>>
857 createCanonicalScanLoops(
const LocationDescription &Loc,
858 LoopBodyGenCallbackTy BodyGenCB,
Value *Start,
860 bool InclusiveStop, InsertPointTy ComputeIP,
861 const Twine &Name, ScanInfo *ScanRedInfo);
904 const LocationDescription &Loc,
Value *Start,
Value *Stop,
Value *Step,
905 bool IsSigned,
bool InclusiveStop,
const Twine &Name =
"loop");
937 LLVM_ABI Expected<CanonicalLoopInfo *> createCanonicalLoop(
938 const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB,
939 Value *Start,
Value *Stop,
Value *Step,
bool IsSigned,
bool InclusiveStop,
940 InsertPointTy ComputeIP = {},
const Twine &
Name =
"loop",
941 bool InScan =
false, ScanInfo *ScanRedInfo =
nullptr);
1003 LLVM_ABI CanonicalLoopInfo *collapseLoops(DebugLoc
DL,
1004 ArrayRef<CanonicalLoopInfo *>
Loops,
1005 InsertPointTy ComputeIP);
1012 getOpenMPDefaultSimdAlign(
const Triple &TargetTriple,
1013 const StringMap<bool> &Features);
1050 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
1051 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
1052 bool IsDeclaration,
bool IsExternallyVisible,
1053 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
1054 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
1055 std::vector<Triple> TargetTriple,
Type *LlvmPtrTy,
1056 std::function<Constant *()> GlobalInitializer,
1057 std::function<GlobalValue::LinkageTypes()> VariableLinkage);
1093 LLVM_ABI void registerTargetGlobalVariable(
1094 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
1095 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
1096 bool IsDeclaration,
bool IsExternallyVisible,
1097 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
1098 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
1099 std::vector<Triple> TargetTriple,
1100 std::function<Constant *()> GlobalInitializer,
1101 std::function<GlobalValue::LinkageTypes()> VariableLinkage,
1102 Type *LlvmPtrTy, Constant *Addr);
1105 LLVM_ABI unsigned getFlagMemberOffset();
1114 LLVM_ABI omp::OpenMPOffloadMappingFlags getMemberOfFlag(
unsigned Position);
1126 setCorrectMemberOfFlag(omp::OpenMPOffloadMappingFlags &Flags,
1127 omp::OpenMPOffloadMappingFlags MemberOfFlag);
1149 InsertPointTy applyWorkshareLoopTarget(DebugLoc
DL, CanonicalLoopInfo *CLI,
1150 InsertPointTy AllocaIP,
1151 omp::WorksharingLoopType LoopType,
1177 InsertPointOrErrorTy applyStaticWorkshareLoop(
1178 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1179 omp::WorksharingLoopType LoopType,
bool NeedsBarrier,
1180 bool HasDistSchedule =
false,
1181 omp::OMPScheduleType DistScheduleSchedType = omp::OMPScheduleType::None);
1203 InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(
1204 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1205 bool NeedsBarrier,
Value *ChunkSize,
1206 omp::OMPScheduleType SchedType =
1207 omp::OMPScheduleType::UnorderedStaticChunked,
1208 Value *DistScheduleChunkSize =
nullptr,
1209 omp::OMPScheduleType DistScheduleSchedType = omp::OMPScheduleType::None);
1231 InsertPointOrErrorTy applyDynamicWorkshareLoop(DebugLoc
DL,
1232 CanonicalLoopInfo *CLI,
1233 InsertPointTy AllocaIP,
1234 omp::OMPScheduleType SchedType,
1236 Value *Chunk =
nullptr);
1249 void createIfVersion(CanonicalLoopInfo *Loop,
Value *IfCond,
1250 ValueMap<const Value *, WeakTrackingVH> &VMap,
1251 LoopAnalysis &LIA, LoopInfo &LI, llvm::Loop *L,
1252 const Twine &NamePrefix =
"");
1270 Expected<Value *> createTaskDuplicationFunction(
Type *PrivatesTy,
1271 int32_t PrivatesIndex,
1272 TaskDupCallbackTy DupCB);
1314 LLVM_ABI InsertPointOrErrorTy applyWorkshareLoop(
1315 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1317 llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default,
1318 Value *ChunkSize =
nullptr,
bool HasSimdModifier =
false,
1319 bool HasMonotonicModifier =
false,
bool HasNonmonotonicModifier =
false,
1320 bool HasOrderedClause =
false,
1321 omp::WorksharingLoopType LoopType =
1322 omp::WorksharingLoopType::ForStaticLoop,
1323 bool NoLoop =
false,
bool HasDistSchedule =
false,
1324 Value *DistScheduleChunkSize =
nullptr);
1369 LLVM_ABI std::vector<CanonicalLoopInfo *>
1370 tileLoops(DebugLoc
DL, ArrayRef<CanonicalLoopInfo *>
Loops,
1371 ArrayRef<Value *> TileSizes);
1381 LLVM_ABI void unrollLoopFull(DebugLoc
DL, CanonicalLoopInfo *Loop);
1388 LLVM_ABI void unrollLoopHeuristic(DebugLoc
DL, CanonicalLoopInfo *Loop);
1412 LLVM_ABI void unrollLoopPartial(DebugLoc
DL, CanonicalLoopInfo *Loop,
1414 CanonicalLoopInfo **UnrolledCLI);
1429 LLVM_ABI void applySimd(CanonicalLoopInfo *Loop,
1430 MapVector<Value *, Value *> AlignedVars,
1431 Value *IfCond, omp::OrderKind Order,
1432 ConstantInt *Simdlen, ConstantInt *Safelen);
1437 LLVM_ABI void createFlush(
const LocationDescription &Loc);
1442 LLVM_ABI void createTaskwait(
const LocationDescription &Loc);
1447 LLVM_ABI void createTaskyield(
const LocationDescription &Loc);
1451 omp::RTLDependenceKindTy DepKind = omp::RTLDependenceKindTy::DepUnknown;
1454 explicit DependData() =
default;
1455 DependData(omp::RTLDependenceKindTy DepKind,
Type *DepValueType,
1457 : DepKind(DepKind), DepValueType(DepValueType), DepVal(DepVal) {}
1475 LLVM_ABI InsertPointOrErrorTy createTaskloop(
1476 const LocationDescription &Loc, InsertPointTy AllocaIP,
1477 BodyGenCallbackTy BodyGenCB,
1478 llvm::function_ref<llvm::Expected<llvm::CanonicalLoopInfo *>()> LoopInfo,
1480 TaskDupCallbackTy DupCB =
nullptr,
1481 Value *TaskContextStructPtrVal =
nullptr);
1503 createTask(
const LocationDescription &Loc, InsertPointTy AllocaIP,
1504 BodyGenCallbackTy BodyGenCB,
bool Tied =
true,
1505 Value *Final =
nullptr,
Value *IfCondition =
nullptr,
1506 SmallVector<DependData> Dependencies = {},
bool Mergeable =
false,
1507 Value *EventHandle =
nullptr,
Value *Priority =
nullptr);
1514 LLVM_ABI InsertPointOrErrorTy createTaskgroup(
const LocationDescription &Loc,
1515 InsertPointTy AllocaIP,
1516 BodyGenCallbackTy BodyGenCB);
1518 using FileIdentifierInfoCallbackTy =
1519 std::function<std::tuple<std::string, uint64_t>()>;
1528 LLVM_ABI static TargetRegionEntryInfo
1529 getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
1530 vfs::FileSystem &VFS, StringRef ParentName =
"");
1533 enum class ReductionGenCBKind { Clang, MLIR };
1545 using ReductionGenClangCBTy =
1546 std::function<InsertPointTy(InsertPointTy CodeGenIP,
unsigned Index,
1554 using ReductionGenCBTy = std::function<InsertPointOrErrorTy(
1561 using ReductionGenAtomicCBTy = std::function<InsertPointOrErrorTy(
1564 using ReductionGenDataPtrPtrCBTy = std::function<InsertPointOrErrorTy(
1565 InsertPointTy,
Value *ByRefVal,
Value *&Res)>;
1571 struct ReductionInfo {
1572 ReductionInfo(
Type *ElementType,
Value *Variable,
Value *PrivateVariable,
1573 EvalKind EvaluationKind, ReductionGenCBTy ReductionGen,
1574 ReductionGenClangCBTy ReductionGenClang,
1575 ReductionGenAtomicCBTy AtomicReductionGen,
1576 ReductionGenDataPtrPtrCBTy DataPtrPtrGen,
1577 Type *ByRefAllocatedType =
nullptr,
1578 Type *ByRefElementType =
nullptr)
1580 PrivateVariable(PrivateVariable), EvaluationKind(EvaluationKind),
1581 ReductionGen(ReductionGen), ReductionGenClang(ReductionGenClang),
1582 AtomicReductionGen(AtomicReductionGen), DataPtrPtrGen(DataPtrPtrGen),
1583 ByRefAllocatedType(ByRefAllocatedType),
1584 ByRefElementType(ByRefElementType) {}
1586 ReductionInfo(
Value *PrivateVariable)
1588 PrivateVariable(PrivateVariable), EvaluationKind(EvalKind::
Scalar),
1589 ReductionGen(), ReductionGenClang(), AtomicReductionGen(),
1600 Value *PrivateVariable;
1603 EvalKind EvaluationKind;
1608 ReductionGenCBTy ReductionGen;
1613 ReductionGenClangCBTy ReductionGenClang;
1619 ReductionGenAtomicCBTy AtomicReductionGen;
1621 ReductionGenDataPtrPtrCBTy DataPtrPtrGen;
1628 Type *ByRefAllocatedType;
1634 Type *ByRefElementType;
1637 enum class CopyAction :
unsigned {
1645 struct CopyOptionsTy {
1646 Value *RemoteLaneOffset =
nullptr;
1647 Value *ScratchpadIndex =
nullptr;
1648 Value *ScratchpadWidth =
nullptr;
1654 Value *getGPUThreadID();
1657 Value *getGPUWarpSize();
1662 Value *getNVPTXWarpID();
1667 Value *getNVPTXLaneID();
1670 Value *castValueToType(InsertPointTy AllocaIP,
Value *From,
Type *ToType);
1674 Value *createRuntimeShuffleFunction(InsertPointTy AllocaIP,
Value *Element,
1678 void shuffleAndStore(InsertPointTy AllocaIP,
Value *SrcAddr,
Value *DstAddr,
1684 Error emitReductionListCopy(
1685 InsertPointTy AllocaIP, CopyAction Action,
Type *ReductionArrayTy,
1686 ArrayRef<ReductionInfo> ReductionInfos,
Value *SrcBase,
Value *DestBase,
1687 ArrayRef<bool> IsByRef,
1688 CopyOptionsTy CopyOptions = {
nullptr,
nullptr,
nullptr});
1765 Expected<Function *> emitShuffleAndReduceFunction(
1766 ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1767 Function *ReduceFn, AttributeList FuncAttrs, ArrayRef<bool> IsByRef);
1777 Error emitScanBasedDirectiveIR(
1778 llvm::function_ref<
Error()> InputLoopGen,
1779 llvm::function_ref<
Error(LocationDescription Loc)> ScanLoopGen,
1780 ScanInfo *ScanRedInfo);
1785 void createScanBBs(ScanInfo *ScanRedInfo);
1795 Error emitScanBasedDirectiveDeclsIR(InsertPointTy AllocaIP,
1796 ArrayRef<llvm::Value *> ScanVars,
1797 ArrayRef<llvm::Type *> ScanVarsType,
1798 ScanInfo *ScanRedInfo);
1806 Error emitScanBasedDirectiveFinalsIR(
1807 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1808 ScanInfo *ScanInfo);
1831 Expected<Function *>
1832 emitInterWarpCopyFunction(
const LocationDescription &Loc,
1833 ArrayRef<ReductionInfo> ReductionInfos,
1834 AttributeList FuncAttrs, ArrayRef<bool> IsByRef);
1849 Expected<Function *>
1850 emitListToGlobalCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1851 Type *ReductionsBufferTy,
1852 AttributeList FuncAttrs, ArrayRef<bool> IsByRef);
1867 Expected<Function *>
1868 emitGlobalToListCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1869 Type *ReductionsBufferTy,
1870 AttributeList FuncAttrs, ArrayRef<bool> IsByRef);
1889 Expected<Function *>
1890 emitListToGlobalReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1891 Function *ReduceFn,
Type *ReductionsBufferTy,
1892 AttributeList FuncAttrs,
1893 ArrayRef<bool> IsByRef);
1912 Expected<Function *>
1913 emitGlobalToListReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1914 Function *ReduceFn,
Type *ReductionsBufferTy,
1915 AttributeList FuncAttrs,
1916 ArrayRef<bool> IsByRef);
1919 std::string getReductionFuncName(StringRef Name)
const;
1930 Expected<Function *> createReductionFunction(
1931 StringRef ReducerName, ArrayRef<ReductionInfo> ReductionInfos,
1932 ArrayRef<bool> IsByRef,
1933 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
1934 AttributeList FuncAttrs = {});
2198 LLVM_ABI InsertPointOrErrorTy createReductionsGPU(
2199 const LocationDescription &Loc, InsertPointTy AllocaIP,
2200 InsertPointTy CodeGenIP, ArrayRef<ReductionInfo> ReductionInfos,
2201 ArrayRef<bool> IsByRef,
bool IsNoWait =
false,
2202 bool IsTeamsReduction =
false,
2203 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
2204 std::optional<omp::GV> GridValue = {},
unsigned ReductionBufNum = 1024,
2205 Value *SrcLocInfo =
nullptr);
2272 LLVM_ABI InsertPointOrErrorTy createReductions(
2273 const LocationDescription &Loc, InsertPointTy AllocaIP,
2274 ArrayRef<ReductionInfo> ReductionInfos, ArrayRef<bool> IsByRef,
2275 bool IsNoWait =
false,
bool IsTeamsReduction =
false);
2280 InsertPointTy getInsertionPoint() {
return Builder.saveIP(); }
2283 bool updateToLocation(
const LocationDescription &Loc) {
2284 Builder.restoreIP(Loc.IP);
2285 Builder.SetCurrentDebugLocation(Loc.DL);
2286 return Loc.IP.getBlock() !=
nullptr;
2291 omp::RuntimeFunction FnID);
2293 LLVM_ABI Function *getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID);
2295 CallInst *createRuntimeFunctionCall(FunctionCallee Callee,
2296 ArrayRef<Value *> Args,
2297 StringRef Name =
"");
2301 uint32_t &SrcLocStrSize);
2309 StringRef FileName,
unsigned Line,
2311 uint32_t &SrcLocStrSize);
2316 Function *
F =
nullptr);
2320 uint32_t &SrcLocStrSize);
2325 uint32_t SrcLocStrSize,
2326 omp::IdentFlag Flags = omp::IdentFlag(0),
2327 unsigned Reserve2Flags = 0);
2331 LLVM_ABI GlobalValue *createGlobalFlag(
unsigned Value, StringRef Name);
2334 LLVM_ABI void emitUsed(StringRef Name, ArrayRef<llvm::WeakTrackingVH> List);
2338 emitKernelExecutionMode(StringRef KernelName, omp::OMPTgtExecModeFlags
Mode);
2348 omp::Directive CanceledDirective);
2361 LLVM_ABI InsertPointTy emitTargetKernel(
const LocationDescription &Loc,
2362 InsertPointTy AllocaIP,
2366 ArrayRef<Value *> KernelArgs);
2371 LLVM_ABI void emitFlush(
const LocationDescription &Loc);
2376 SmallVector<FinalizationInfo, 8> FinalizationStack;
2380 bool isLastFinalizationInfoCancellable(omp::Directive DK) {
2381 return !FinalizationStack.empty() &&
2382 FinalizationStack.back().IsCancellable &&
2383 FinalizationStack.back().DK == DK;
2389 LLVM_ABI void emitTaskwaitImpl(
const LocationDescription &Loc);
2394 LLVM_ABI void emitTaskyieldImpl(
const LocationDescription &Loc);
2402 OpenMPIRBuilderConfig Config;
2408 IRBuilder<> Builder;
2411 StringMap<Constant *> SrcLocStrMap;
2414 DenseMap<std::pair<Constant *, uint64_t>,
Constant *> IdentMap;
2417 OffloadEntriesInfoManager OffloadInfoManager;
2424 struct OutlineInfo {
2425 using PostOutlineCBTy = std::function<void(Function &)>;
2426 PostOutlineCBTy PostOutlineCB;
2427 BasicBlock *EntryBB, *ExitBB, *OuterAllocaBB;
2428 SmallVector<Value *, 2> ExcludeArgsFromAggregate;
2429 SetVector<Value *> Inputs, Outputs;
2431 bool FixUpNonEntryAllocas =
false;
2436 SmallVectorImpl<BasicBlock *> &BlockVector);
2443 SmallVector<OutlineInfo, 16> OutlineInfos;
2448 SmallVector<llvm::Function *, 16> ConstantAllocaRaiseCandidates;
2452 std::forward_list<CanonicalLoopInfo> LoopInfos;
2455 std::forward_list<ScanInfo> ScanInfos;
2458 void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
2465 StringMap<GlobalVariable *, BumpPtrAllocator> InternalVars;
2472 LLVM_ABI void emitBranch(BasicBlock *Target);
2477 LLVM_ABI void emitBlock(BasicBlock *BB, Function *CurFn,
2478 bool IsFinished =
false);
2490 BodyGenCallbackTy ElseGen,
2491 InsertPointTy AllocaIP = {});
2495 createOffloadMaptypes(SmallVectorImpl<uint64_t> &Mappings,
2496 std::string VarName);
2500 createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
2501 std::string VarName);
2503 struct MapperAllocas {
2504 AllocaInst *ArgsBase =
nullptr;
2505 AllocaInst *
Args =
nullptr;
2506 AllocaInst *ArgSizes =
nullptr;
2510 LLVM_ABI void createMapperAllocas(
const LocationDescription &Loc,
2511 InsertPointTy AllocaIP,
2512 unsigned NumOperands,
2513 struct MapperAllocas &MapperAllocas);
2524 LLVM_ABI void emitMapperCall(
const LocationDescription &Loc,
2525 Function *MapperFunc,
Value *SrcLocInfo,
2527 struct MapperAllocas &MapperAllocas,
2528 int64_t DeviceID,
unsigned NumOperands);
2531 struct TargetDataRTArgs {
2533 Value *BasePointersArray =
nullptr;
2535 Value *PointersArray =
nullptr;
2537 Value *SizesArray =
nullptr;
2541 Value *MapTypesArray =
nullptr;
2545 Value *MapTypesArrayEnd =
nullptr;
2547 Value *MappersArray =
nullptr;
2550 Value *MapNamesArray =
nullptr;
2552 explicit TargetDataRTArgs() =
default;
2553 explicit TargetDataRTArgs(
Value *BasePointersArray,
Value *PointersArray,
2555 Value *MapTypesArrayEnd,
Value *MappersArray,
2556 Value *MapNamesArray)
2557 : BasePointersArray(BasePointersArray), PointersArray(PointersArray),
2558 SizesArray(SizesArray), MapTypesArray(MapTypesArray),
2559 MapTypesArrayEnd(MapTypesArrayEnd), MappersArray(MappersArray),
2560 MapNamesArray(MapNamesArray) {}
2570 struct TargetKernelDefaultAttrs {
2571 omp::OMPTgtExecModeFlags ExecFlags =
2572 omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
2573 SmallVector<int32_t, 3> MaxTeams = {-1};
2574 int32_t MinTeams = 1;
2576 int32_t MinThreads = 1;
2577 int32_t ReductionDataSize = 0;
2578 int32_t ReductionBufferLength = 0;
2586 struct TargetKernelRuntimeAttrs {
2587 SmallVector<Value *, 3> MaxTeams = {
nullptr};
2588 Value *MinTeams =
nullptr;
2589 SmallVector<Value *, 3> TargetThreadLimit = {
nullptr};
2590 SmallVector<Value *, 3> TeamsThreadLimit = {
nullptr};
2598 Value *LoopTripCount =
nullptr;
2601 Value *DeviceID =
nullptr;
2606 struct TargetKernelArgs {
2608 unsigned NumTargetItems = 0;
2610 TargetDataRTArgs RTArgs;
2612 Value *NumIterations =
nullptr;
2614 ArrayRef<Value *> NumTeams;
2616 ArrayRef<Value *> NumThreads;
2618 Value *DynCGroupMem =
nullptr;
2620 bool HasNoWait =
false;
2622 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback =
2623 omp::OMPDynGroupprivateFallbackType::Abort;
2626 TargetKernelArgs() =
default;
2627 TargetKernelArgs(
unsigned NumTargetItems, TargetDataRTArgs RTArgs,
2628 Value *NumIterations, ArrayRef<Value *> NumTeams,
2629 ArrayRef<Value *> NumThreads,
Value *DynCGroupMem,
2631 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback)
2632 : NumTargetItems(NumTargetItems), RTArgs(RTArgs),
2633 NumIterations(NumIterations), NumTeams(NumTeams),
2634 NumThreads(NumThreads), DynCGroupMem(DynCGroupMem),
2635 HasNoWait(HasNoWait), DynCGroupMemFallback(DynCGroupMemFallback) {}
2641 LLVM_ABI static void getKernelArgsVector(TargetKernelArgs &KernelArgs,
2642 IRBuilderBase &Builder,
2643 SmallVector<Value *> &ArgsVector);
2647 class TargetDataInfo {
2649 bool RequiresDevicePointerInfo =
false;
2652 bool SeparateBeginEndCalls =
false;
2655 TargetDataRTArgs RTArgs;
2657 SmallMapVector<const Value *, std::pair<Value *, Value *>, 4>
2661 bool HasMapper =
false;
2663 unsigned NumberOfPtrs = 0
u;
2665 bool EmitDebug =
false;
2668 bool HasNoWait =
false;
2670 explicit TargetDataInfo() =
default;
2671 explicit TargetDataInfo(
bool RequiresDevicePointerInfo,
2672 bool SeparateBeginEndCalls)
2673 : RequiresDevicePointerInfo(RequiresDevicePointerInfo),
2674 SeparateBeginEndCalls(SeparateBeginEndCalls) {}
2676 void clearArrayInfo() {
2677 RTArgs = TargetDataRTArgs();
2683 return RTArgs.BasePointersArray && RTArgs.PointersArray &&
2684 RTArgs.SizesArray && RTArgs.MapTypesArray &&
2685 (!HasMapper || RTArgs.MappersArray) && NumberOfPtrs;
2687 bool requiresDevicePointerInfo() {
return RequiresDevicePointerInfo; }
2688 bool separateBeginEndCalls() {
return SeparateBeginEndCalls; }
2692 using MapValuesArrayTy = SmallVector<Value *, 4>;
2693 using MapDeviceInfoArrayTy = SmallVector<DeviceInfoTy, 4>;
2694 using MapFlagsArrayTy = SmallVector<omp::OpenMPOffloadMappingFlags, 4>;
2695 using MapNamesArrayTy = SmallVector<Constant *, 4>;
2696 using MapDimArrayTy = SmallVector<uint64_t, 4>;
2697 using MapNonContiguousArrayTy = SmallVector<MapValuesArrayTy, 4>;
2703 struct StructNonContiguousInfo {
2704 bool IsNonContiguous =
false;
2706 MapNonContiguousArrayTy
Offsets;
2707 MapNonContiguousArrayTy Counts;
2708 MapNonContiguousArrayTy Strides;
2710 MapValuesArrayTy BasePointers;
2711 MapValuesArrayTy Pointers;
2712 MapDeviceInfoArrayTy DevicePointers;
2713 MapValuesArrayTy
Sizes;
2714 MapFlagsArrayTy
Types;
2715 MapNamesArrayTy Names;
2716 StructNonContiguousInfo NonContigInfo;
2719 void append(MapInfosTy &CurInfo) {
2720 BasePointers.append(CurInfo.BasePointers.begin(),
2721 CurInfo.BasePointers.end());
2722 Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
2723 DevicePointers.append(CurInfo.DevicePointers.begin(),
2724 CurInfo.DevicePointers.end());
2725 Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
2726 Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
2727 Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
2728 NonContigInfo.Dims.append(CurInfo.NonContigInfo.Dims.begin(),
2729 CurInfo.NonContigInfo.Dims.end());
2730 NonContigInfo.Offsets.append(CurInfo.NonContigInfo.Offsets.begin(),
2731 CurInfo.NonContigInfo.Offsets.end());
2732 NonContigInfo.Counts.append(CurInfo.NonContigInfo.Counts.begin(),
2733 CurInfo.NonContigInfo.Counts.end());
2734 NonContigInfo.Strides.append(CurInfo.NonContigInfo.Strides.begin(),
2735 CurInfo.NonContigInfo.Strides.end());
2738 using MapInfosOrErrorTy = Expected<MapInfosTy &>;
2744 using EmitFallbackCallbackTy =
2745 function_ref<InsertPointOrErrorTy(InsertPointTy)>;
2749 using CustomMapperCallbackTy =
2750 function_ref<Expected<Function *>(
unsigned int)>;
2762 LLVM_ABI InsertPointOrErrorTy emitKernelLaunch(
2763 const LocationDescription &Loc,
Value *OutlinedFnID,
2764 EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args,
2765 Value *DeviceID,
Value *RTLoc, InsertPointTy AllocaIP);
2777 using TargetTaskBodyCallbackTy =
2779 IRBuilderBase::InsertPoint TargetTaskAllocaIP)>;
2791 LLVM_ABI InsertPointOrErrorTy emitTargetTask(
2792 TargetTaskBodyCallbackTy TaskBodyCB,
Value *DeviceID,
Value *RTLoc,
2793 OpenMPIRBuilder::InsertPointTy AllocaIP,
2794 const SmallVector<llvm::OpenMPIRBuilder::DependData> &Dependencies,
2795 const TargetDataRTArgs &RTArgs,
bool HasNoWait);
2801 LLVM_ABI void emitOffloadingArraysArgument(
2802 IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs,
2803 OpenMPIRBuilder::TargetDataInfo &
Info,
bool ForEndCall =
false);
2806 LLVM_ABI void emitNonContiguousDescriptor(InsertPointTy AllocaIP,
2807 InsertPointTy CodeGenIP,
2808 MapInfosTy &CombinedInfo,
2809 TargetDataInfo &
Info);
2817 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
2818 TargetDataInfo &
Info, CustomMapperCallbackTy CustomMapperCB,
2819 bool IsNonContiguous =
false,
2820 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2829 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &
Info,
2830 TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
2831 CustomMapperCallbackTy CustomMapperCB,
bool IsNonContiguous =
false,
2832 bool ForEndCall =
false,
2833 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2837 LLVM_ABI void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t
Size,
2838 int32_t Flags, GlobalValue::LinkageTypes,
2839 StringRef Name =
"");
2843 enum EmitMetadataErrorKind {
2844 EMIT_MD_TARGET_REGION_ERROR,
2845 EMIT_MD_DECLARE_TARGET_ERROR,
2846 EMIT_MD_GLOBAL_VAR_LINK_ERROR,
2847 EMIT_MD_GLOBAL_VAR_INDIRECT_ERROR
2851 using EmitMetadataErrorReportFunctionTy =
2852 std::function<void(EmitMetadataErrorKind, TargetRegionEntryInfo)>;
2861 LLVM_ABI void createOffloadEntriesAndInfoMetadata(
2862 EmitMetadataErrorReportFunctionTy &ErrorReportFunction);
2875 LLVM_ABI InsertPointTy createCopyPrivate(
const LocationDescription &Loc,
2892 createSingle(
const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2893 FinalizeCallbackTy FiniCB,
bool IsNowait,
2894 ArrayRef<llvm::Value *> CPVars = {},
2895 ArrayRef<llvm::Function *> CPFuncs = {});
2904 LLVM_ABI InsertPointOrErrorTy createMaster(
const LocationDescription &Loc,
2905 BodyGenCallbackTy BodyGenCB,
2906 FinalizeCallbackTy FiniCB);
2915 LLVM_ABI InsertPointOrErrorTy createMasked(
const LocationDescription &Loc,
2916 BodyGenCallbackTy BodyGenCB,
2917 FinalizeCallbackTy FiniCB,
2938 LLVM_ABI InsertPointOrErrorTy emitScanReduction(
2939 const LocationDescription &Loc,
2940 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
2941 ScanInfo *ScanRedInfo);
2956 LLVM_ABI InsertPointOrErrorTy createScan(
const LocationDescription &Loc,
2957 InsertPointTy AllocaIP,
2958 ArrayRef<llvm::Value *> ScanVars,
2959 ArrayRef<llvm::Type *> ScanVarsType,
2961 ScanInfo *ScanRedInfo);
2972 LLVM_ABI InsertPointOrErrorTy createCritical(
const LocationDescription &Loc,
2973 BodyGenCallbackTy BodyGenCB,
2974 FinalizeCallbackTy FiniCB,
2975 StringRef CriticalName,
2989 createOrderedDepend(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2990 unsigned NumLoops, ArrayRef<llvm::Value *> StoreValues,
2991 const Twine &Name,
bool IsDependSource);
3002 LLVM_ABI InsertPointOrErrorTy createOrderedThreadsSimd(
3003 const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
3004 FinalizeCallbackTy FiniCB,
bool IsThreads);
3018 createSections(
const LocationDescription &Loc, InsertPointTy AllocaIP,
3019 ArrayRef<StorableBodyGenCallbackTy> SectionCBs,
3020 PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB,
3021 bool IsCancellable,
bool IsNowait);
3029 LLVM_ABI InsertPointOrErrorTy createSection(
const LocationDescription &Loc,
3030 BodyGenCallbackTy BodyGenCB,
3031 FinalizeCallbackTy FiniCB);
3045 LLVM_ABI InsertPointOrErrorTy createTeams(
const LocationDescription &Loc,
3046 BodyGenCallbackTy BodyGenCB,
3047 Value *NumTeamsLower =
nullptr,
3048 Value *NumTeamsUpper =
nullptr,
3049 Value *ThreadLimit =
nullptr,
3050 Value *IfExpr =
nullptr);
3057 LLVM_ABI InsertPointOrErrorTy createDistribute(
const LocationDescription &Loc,
3058 InsertPointTy AllocaIP,
3059 BodyGenCallbackTy BodyGenCB);
3073 LLVM_ABI InsertPointTy createCopyinClauseBlocks(InsertPointTy IP,
3076 llvm::IntegerType *IntPtrTy,
3077 bool BranchtoEnd =
true);
3098 LLVM_ABI CallInst *createOMPFree(
const LocationDescription &Loc,
Value *Addr,
3110 createCachedThreadPrivate(
const LocationDescription &Loc,
3112 const llvm::Twine &Name = Twine(
""));
3125 LLVM_ABI CallInst *createOMPInteropInit(
const LocationDescription &Loc,
3127 omp::OMPInteropType InteropType,
3129 Value *DependenceAddress,
3130 bool HaveNowaitClause);
3142 LLVM_ABI CallInst *createOMPInteropDestroy(
const LocationDescription &Loc,
3144 Value *NumDependences,
3145 Value *DependenceAddress,
3146 bool HaveNowaitClause);
3158 LLVM_ABI CallInst *createOMPInteropUse(
const LocationDescription &Loc,
3160 Value *NumDependences,
3161 Value *DependenceAddress,
3162 bool HaveNowaitClause);
3176 LLVM_ABI InsertPointTy createTargetInit(
3177 const LocationDescription &Loc,
3178 const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
3187 LLVM_ABI void createTargetDeinit(
const LocationDescription &Loc,
3188 int32_t TeamsReductionDataSize = 0,
3189 int32_t TeamsReductionBufferLength = 1024);
3199 LLVM_ABI static std::pair<int32_t, int32_t>
3200 readThreadBoundsForKernel(
const Triple &
T, Function &Kernel);
3201 LLVM_ABI static void writeThreadBoundsForKernel(
const Triple &
T,
3202 Function &Kernel, int32_t LB,
3207 LLVM_ABI static std::pair<int32_t, int32_t>
3208 readTeamBoundsForKernel(
const Triple &
T, Function &Kernel);
3209 LLVM_ABI static void writeTeamsForKernel(
const Triple &
T, Function &Kernel,
3210 int32_t LB, int32_t UB);
3215 void setOutlinedTargetRegionFunctionAttributes(Function *OutlinedFn);
3220 Constant *createOutlinedFunctionID(Function *OutlinedFn,
3221 StringRef EntryFnIDName);
3224 Constant *createTargetRegionEntryAddr(Function *OutlinedFunction,
3225 StringRef EntryFnName);
3229 using FunctionGenCallback =
3230 std::function<Expected<Function *>(StringRef FunctionName)>;
3264 TargetRegionEntryInfo &EntryInfo,
3265 FunctionGenCallback &GenerateFunctionCallback,
bool IsOffloadEntry,
3266 Function *&OutlinedFn, Constant *&OutlinedFnID);
3277 registerTargetRegionFunction(TargetRegionEntryInfo &EntryInfo,
3278 Function *OutlinedFunction,
3279 StringRef EntryFnName, StringRef EntryFnIDName);
3292 enum BodyGenTy { Priv, DupNoPriv, NoPriv };
3297 using GenMapInfoCallbackTy =
3298 function_ref<MapInfosTy &(InsertPointTy CodeGenIP)>;
3307 void emitUDMapperArrayInitOrDel(Function *MapperFn,
llvm::Value *MapperHandle,
3311 llvm::BasicBlock *ExitBB,
bool IsInit);
3354 LLVM_ABI Expected<Function *> emitUserDefinedMapper(
3355 function_ref<MapInfosOrErrorTy(
3357 PrivAndGenMapInfoCB,
3358 llvm::Type *ElemTy, StringRef FuncName,
3359 CustomMapperCallbackTy CustomMapperCB);
3378 LLVM_ABI InsertPointOrErrorTy createTargetData(
3379 const LocationDescription &Loc, InsertPointTy AllocaIP,
3380 InsertPointTy CodeGenIP,
Value *DeviceID,
Value *IfCond,
3381 TargetDataInfo &
Info, GenMapInfoCallbackTy GenMapInfoCB,
3382 CustomMapperCallbackTy CustomMapperCB,
3383 omp::RuntimeFunction *MapperFunc =
nullptr,
3384 function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
3385 BodyGenTy BodyGenType)>
3386 BodyGenCB =
nullptr,
3387 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr,
3388 Value *SrcLocInfo =
nullptr);
3390 using TargetBodyGenCallbackTy = function_ref<InsertPointOrErrorTy(
3391 InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
3393 using TargetGenArgAccessorsCallbackTy = function_ref<InsertPointOrErrorTy(
3394 Argument &Arg,
Value *Input,
Value *&RetVal, InsertPointTy AllocaIP,
3395 InsertPointTy CodeGenIP)>;
3425 LLVM_ABI InsertPointOrErrorTy createTarget(
3426 const LocationDescription &Loc,
bool IsOffloadEntry,
3427 OpenMPIRBuilder::InsertPointTy AllocaIP,
3428 OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetDataInfo &
Info,
3429 TargetRegionEntryInfo &EntryInfo,
3430 const TargetKernelDefaultAttrs &DefaultAttrs,
3431 const TargetKernelRuntimeAttrs &RuntimeAttrs,
Value *IfCond,
3432 SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
3433 TargetBodyGenCallbackTy BodyGenCB,
3434 TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
3435 CustomMapperCallbackTy CustomMapperCB,
3436 const SmallVector<DependData> &Dependencies,
bool HasNowait =
false,
3437 Value *DynCGroupMem =
nullptr,
3438 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback =
3439 omp::OMPDynGroupprivateFallbackType::Abort);
3444 LLVM_ABI FunctionCallee createForStaticInitFunction(
unsigned IVSize,
3446 bool IsGPUDistribute);
3450 LLVM_ABI FunctionCallee createDispatchInitFunction(
unsigned IVSize,
3455 LLVM_ABI FunctionCallee createDispatchNextFunction(
unsigned IVSize,
3460 LLVM_ABI FunctionCallee createDispatchFiniFunction(
unsigned IVSize,
3464 LLVM_ABI FunctionCallee createDispatchDeinitFunction();
3472#define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
3473#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
3474 ArrayType *VarName##Ty = nullptr; \
3475 PointerType *VarName##PtrTy = nullptr;
3476#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
3477 FunctionType *VarName = nullptr; \
3478 PointerType *VarName##Ptr = nullptr;
3479#define OMP_STRUCT_TYPE(VarName, StrName, ...) \
3480 StructType *VarName = nullptr; \
3481 PointerType *VarName##Ptr = nullptr;
3482#include "llvm/Frontend/OpenMP/OMPKinds.def"
3489 void initializeTypes(
Module &M);
3503 InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD,
Value *EntryCall,
3505 bool Conditional =
false);
3518 InsertPointOrErrorTy emitCommonDirectiveExit(omp::Directive OMPD,
3519 InsertPointTy FinIP,
3520 Instruction *ExitCall,
3521 bool HasFinalize =
true);
3539 InsertPointOrErrorTy
3540 EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
3541 Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
3542 FinalizeCallbackTy FiniCB,
bool Conditional =
false,
3543 bool HasFinalize =
true,
bool IsCancellable =
false);
3551 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
3552 StringRef FirstSeparator,
3553 StringRef Separator);
3560 Value *getOMPCriticalRegionLock(StringRef CriticalName);
3574 using AtomicUpdateCallbackTy =
3575 const function_ref<Expected<Value *>(
Value *XOld, IRBuilder<> &IRB)>;
3587 bool checkAndEmitFlushAfterAtomic(
const LocationDescription &Loc,
3588 AtomicOrdering AO, AtomicKind AK);
3614 Expected<std::pair<Value *, Value *>>
3615 emitAtomicUpdate(InsertPointTy AllocaIP,
Value *
X,
Type *XElemTy,
Value *Expr,
3616 AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3617 AtomicUpdateCallbackTy &UpdateOp,
bool VolatileX,
3618 bool IsXBinopExpr,
bool IsIgnoreDenormalMode,
3619 bool IsFineGrainedMemory,
bool IsRemoteMemory);
3625 AtomicRMWInst::BinOp RMWOp);
3631 struct AtomicOpValue {
3632 Value *Var =
nullptr;
3633 Type *ElemTy =
nullptr;
3634 bool IsSigned =
false;
3649 LLVM_ABI InsertPointTy createAtomicRead(
const LocationDescription &Loc,
3650 AtomicOpValue &
X, AtomicOpValue &V,
3652 InsertPointTy AllocaIP);
3664 LLVM_ABI InsertPointTy createAtomicWrite(
const LocationDescription &Loc,
3665 AtomicOpValue &
X,
Value *Expr,
3667 InsertPointTy AllocaIP);
3689 LLVM_ABI InsertPointOrErrorTy createAtomicUpdate(
3690 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3691 Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3692 AtomicUpdateCallbackTy &UpdateOp,
bool IsXBinopExpr,
3693 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3694 bool IsRemoteMemory =
false);
3725 LLVM_ABI InsertPointOrErrorTy createAtomicCapture(
3726 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3727 AtomicOpValue &V,
Value *Expr, AtomicOrdering AO,
3728 AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
3729 bool UpdateExpr,
bool IsPostfixUpdate,
bool IsXBinopExpr,
3730 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3731 bool IsRemoteMemory =
false);
3779 createAtomicCompare(
const LocationDescription &Loc, AtomicOpValue &
X,
3780 AtomicOpValue &V, AtomicOpValue &R,
Value *
E,
Value *
D,
3781 AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
3782 bool IsXBinopExpr,
bool IsPostfixUpdate,
bool IsFailOnly);
3783 LLVM_ABI InsertPointTy createAtomicCompare(
3784 const LocationDescription &Loc, AtomicOpValue &
X, AtomicOpValue &V,
3785 AtomicOpValue &R,
Value *
E,
Value *
D, AtomicOrdering AO,
3786 omp::OMPAtomicCompareOp Op,
bool IsXBinopExpr,
bool IsPostfixUpdate,
3787 bool IsFailOnly, AtomicOrdering Failure);
3805 LLVM_ABI CanonicalLoopInfo *createLoopSkeleton(DebugLoc
DL,
Value *TripCount,
3807 BasicBlock *PreInsertBefore,
3808 BasicBlock *PostInsertBefore,
3809 const Twine &Name = {});
3811 const std::string ompOffloadInfoName =
"omp_offload.info";
3828 LLVM_ABI void loadOffloadInfoMetadata(vfs::FileSystem &VFS,
3829 StringRef HostFilePath);
3838 getOrCreateInternalVariable(
Type *Ty,
const StringRef &Name,
3839 std::optional<unsigned> AddressSpace = {});
3940class CanonicalLoopInfo {
3941 friend class OpenMPIRBuilder;
3950 Value *LastIter =
nullptr;
3960 void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
3965 void setTripCount(
Value *TripCount);
3981 void mapIndVar(llvm::function_ref<
Value *(Instruction *)> Updater);
3985 void setLastIter(
Value *IterVar) { LastIter = std::move(IterVar); }
3994 Value *getLastIter() {
return LastIter; }
3999 bool isValid()
const {
return Header; }
4026 return cast<BranchInst>(
Cond->getTerminator())->getSuccessor(0);
4050 return Exit->getSingleSuccessor();
4056 Value *getTripCount()
const {
4059 assert(isa<CmpInst>(CmpI) &&
"First inst must compare IV with TripCount");
4060 return CmpI->getOperand(1);
4068 assert(isa<PHINode>(IndVarPHI) &&
"First inst must be the IV PHI");
4073 Type *getIndVarType()
const {
4075 return getIndVar()->getType();
4079 OpenMPIRBuilder::InsertPointTy getPreheaderIP()
const {
4082 return {Preheader, std::prev(Preheader->end())};
4086 OpenMPIRBuilder::InsertPointTy getBodyIP()
const {
4089 return {Body, Body->begin()};
4093 OpenMPIRBuilder::InsertPointTy getAfterIP()
const {
4096 return {After, After->begin()};
4101 return Header->getParent();
4159 llvm::BasicBlock *OMPBeforeScanBlock =
nullptr;
4162 llvm::BasicBlock *OMPAfterScanBlock =
nullptr;
4165 llvm::BasicBlock *OMPScanDispatch =
nullptr;
4168 llvm::BasicBlock *OMPScanLoopExit =
nullptr;
4171 llvm::BasicBlock *OMPScanInit =
nullptr;
4174 llvm::BasicBlock *OMPScanFinish =
nullptr;
4178 bool OMPFirstScanLoop =
false;
4182 llvm::SmallDenseMap<llvm::Value *, llvm::Value *> *ScanBuffPtrs;
4193 ScanBuffPtrs =
new llvm::SmallDenseMap<llvm::Value *, llvm::Value *>();
4195 ScanInfo(ScanInfo &) =
delete;
4196 ScanInfo &operator=(
const ScanInfo &) =
delete;
4198 ~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
This file implements a set that has insertion order iteration characteristics.
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, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
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.
@ C
The default llvm calling convention, compatible with C.
@ 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
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.