14#ifndef LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
15#define LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
29#include <forward_list>
34class CanonicalLoopInfo;
36struct TargetRegionEntryInfo;
37class OffloadEntriesInfoManager;
103class OpenMPIRBuilderConfig {
109 std::optional<bool> IsTargetDevice;
119 std::optional<bool> IsGPU;
122 std::optional<bool> EmitLLVMUsedMetaInfo;
125 std::optional<bool> OpenMPOffloadMandatory;
128 std::optional<StringRef> FirstSeparator;
130 std::optional<StringRef> Separator;
133 std::optional<omp::GV> GridValue;
137 SmallVector<Triple> TargetTriples;
140 unsigned DefaultTargetAS = 0;
145 LLVM_ABI OpenMPIRBuilderConfig(
bool IsTargetDevice,
bool IsGPU,
146 bool OpenMPOffloadMandatory,
147 bool HasRequiresReverseOffload,
148 bool HasRequiresUnifiedAddress,
149 bool HasRequiresUnifiedSharedMemory,
150 bool HasRequiresDynamicAllocators);
153 bool isTargetDevice()
const {
154 assert(IsTargetDevice.has_value() &&
"IsTargetDevice is not set");
155 return *IsTargetDevice;
159 assert(IsGPU.has_value() &&
"IsGPU is not set");
163 bool openMPOffloadMandatory()
const {
164 assert(OpenMPOffloadMandatory.has_value() &&
165 "OpenMPOffloadMandatory is not set");
166 return *OpenMPOffloadMandatory;
170 assert(GridValue.has_value() &&
"GridValue is not set");
174 unsigned getDefaultTargetAS()
const {
return DefaultTargetAS; }
176 CallingConv::ID getRuntimeCC()
const {
return RuntimeCC; }
178 bool hasRequiresFlags()
const {
return RequiresFlags; }
179 LLVM_ABI bool hasRequiresReverseOffload()
const;
180 LLVM_ABI bool hasRequiresUnifiedAddress()
const;
181 LLVM_ABI bool hasRequiresUnifiedSharedMemory()
const;
182 LLVM_ABI bool hasRequiresDynamicAllocators()
const;
186 LLVM_ABI int64_t getRequiresFlags()
const;
190 StringRef firstSeparator()
const {
191 if (FirstSeparator.has_value())
192 return *FirstSeparator;
200 StringRef separator()
const {
201 if (Separator.has_value())
208 void setIsTargetDevice(
bool Value) { IsTargetDevice =
Value; }
210 void setEmitLLVMUsed(
bool Value =
true) { EmitLLVMUsedMetaInfo =
Value; }
211 void setOpenMPOffloadMandatory(
bool Value) { OpenMPOffloadMandatory =
Value; }
212 void setFirstSeparator(StringRef FS) { FirstSeparator =
FS; }
213 void setSeparator(StringRef S) { Separator = S; }
214 void setGridValue(omp::GV
G) { GridValue =
G; }
215 void setDefaultTargetAS(
unsigned AS) { DefaultTargetAS = AS; }
216 void setRuntimeCC(CallingConv::ID CC) { RuntimeCC = CC; }
225 int64_t RequiresFlags;
230struct TargetRegionEntryInfo {
232 static constexpr const char *KernelNamePrefix =
"__omp_offloading_";
234 std::string ParentName;
240 TargetRegionEntryInfo() : DeviceID(0), FileID(0),
Line(0),
Count(0) {}
241 TargetRegionEntryInfo(StringRef ParentName,
unsigned DeviceID,
242 unsigned FileID,
unsigned Line,
unsigned Count = 0)
243 : ParentName(ParentName), DeviceID(DeviceID), FileID(FileID),
Line(
Line),
247 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name, StringRef ParentName,
248 unsigned DeviceID,
unsigned FileID,
unsigned Line,
251 bool operator<(
const TargetRegionEntryInfo &
RHS)
const {
252 return std::make_tuple(ParentName, DeviceID, FileID, Line, Count) <
253 std::make_tuple(
RHS.ParentName,
RHS.DeviceID,
RHS.FileID,
RHS.Line,
259class OffloadEntriesInfoManager {
261 OpenMPIRBuilder *OMPBuilder;
262 unsigned OffloadingEntriesNum = 0;
266 class OffloadEntryInfo {
269 enum OffloadingEntryInfoKinds :
unsigned {
271 OffloadingEntryInfoTargetRegion = 0,
273 OffloadingEntryInfoDeviceGlobalVar = 1,
275 OffloadingEntryInfoInvalid = ~0
u
279 OffloadEntryInfo() =
delete;
280 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) :
Kind(
Kind) {}
281 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind,
unsigned Order,
284 ~OffloadEntryInfo() =
default;
287 bool isValid()
const {
return Order != ~0
u; }
288 unsigned getOrder()
const {
return Order; }
289 OffloadingEntryInfoKinds getKind()
const {
return Kind; }
291 void setFlags(uint32_t NewFlags) {
Flags = NewFlags; }
292 Constant *getAddress()
const {
return cast_or_null<Constant>(Addr); }
293 void setAddress(Constant *V) {
294 assert(!Addr.pointsToAliveValue() &&
"Address has been set before!");
297 static bool classof(
const OffloadEntryInfo *
Info) {
return true; }
307 unsigned Order = ~0
u;
309 OffloadingEntryInfoKinds
Kind = OffloadingEntryInfoInvalid;
315 unsigned size()
const {
return OffloadingEntriesNum; }
317 OffloadEntriesInfoManager(OpenMPIRBuilder *builder) : OMPBuilder(builder) {}
324 enum OMPTargetRegionEntryKind : uint32_t {
326 OMPTargetRegionEntryTargetRegion = 0x0,
330 class OffloadEntryInfoTargetRegion final :
public OffloadEntryInfo {
335 OffloadEntryInfoTargetRegion()
336 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
337 explicit OffloadEntryInfoTargetRegion(
unsigned Order, Constant *Addr,
339 OMPTargetRegionEntryKind Flags)
340 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order,
Flags),
346 void setID(Constant *V) {
347 assert(!ID &&
"ID has been set before!");
350 static bool classof(
const OffloadEntryInfo *
Info) {
351 return Info->getKind() == OffloadingEntryInfoTargetRegion;
358 initializeTargetRegionEntryInfo(
const TargetRegionEntryInfo &EntryInfo,
361 LLVM_ABI void registerTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
362 Constant *Addr, Constant *ID,
363 OMPTargetRegionEntryKind Flags);
366 LLVM_ABI bool hasTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
367 bool IgnoreAddressId =
false)
const;
371 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name,
372 const TargetRegionEntryInfo &EntryInfo);
375 typedef function_ref<void(
const TargetRegionEntryInfo &EntryInfo,
376 const OffloadEntryInfoTargetRegion &)>
377 OffloadTargetRegionEntryInfoActTy;
379 actOnTargetRegionEntriesInfo(
const OffloadTargetRegionEntryInfoActTy &Action);
386 enum OMPTargetGlobalVarEntryKind : uint32_t {
388 OMPTargetGlobalVarEntryTo = 0x0,
390 OMPTargetGlobalVarEntryLink = 0x1,
392 OMPTargetGlobalVarEntryEnter = 0x2,
394 OMPTargetGlobalVarEntryNone = 0x3,
396 OMPTargetGlobalVarEntryIndirect = 0x8,
398 OMPTargetGlobalRegisterRequires = 0x10,
406 enum OMPTargetDeviceClauseKind : uint32_t {
408 OMPTargetDeviceClauseAny = 0x0,
410 OMPTargetDeviceClauseNoHost = 0x1,
412 OMPTargetDeviceClauseHost = 0x2,
414 OMPTargetDeviceClauseNone = 0x3
418 class OffloadEntryInfoDeviceGlobalVar final :
public OffloadEntryInfo {
421 GlobalValue::LinkageTypes
Linkage;
425 OffloadEntryInfoDeviceGlobalVar()
426 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
427 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order,
428 OMPTargetGlobalVarEntryKind Flags)
429 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags) {}
430 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order, Constant *Addr,
432 OMPTargetGlobalVarEntryKind Flags,
433 GlobalValue::LinkageTypes
Linkage,
434 const std::string &VarName)
435 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags),
440 int64_t getVarSize()
const {
return VarSize; }
442 void setVarSize(int64_t
Size) { VarSize =
Size; }
443 GlobalValue::LinkageTypes getLinkage()
const {
return Linkage; }
444 void setLinkage(GlobalValue::LinkageTypes LT) {
Linkage =
LT; }
445 static bool classof(
const OffloadEntryInfo *
Info) {
446 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
452 LLVM_ABI void initializeDeviceGlobalVarEntryInfo(
453 StringRef Name, OMPTargetGlobalVarEntryKind Flags,
unsigned Order);
456 LLVM_ABI void registerDeviceGlobalVarEntryInfo(
457 StringRef VarName, Constant *Addr, int64_t VarSize,
458 OMPTargetGlobalVarEntryKind Flags, GlobalValue::LinkageTypes
Linkage);
460 bool hasDeviceGlobalVarEntryInfo(StringRef VarName)
const {
461 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
464 typedef function_ref<void(StringRef,
const OffloadEntryInfoDeviceGlobalVar &)>
465 OffloadDeviceGlobalVarEntryInfoActTy;
466 LLVM_ABI void actOnDeviceGlobalVarEntriesInfo(
467 const OffloadDeviceGlobalVarEntryInfoActTy &Action);
472 getTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo)
const;
476 incrementTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo);
478 static TargetRegionEntryInfo
479 getTargetRegionEntryCountKey(
const TargetRegionEntryInfo &EntryInfo) {
480 return TargetRegionEntryInfo(EntryInfo.ParentName, EntryInfo.DeviceID,
481 EntryInfo.FileID, EntryInfo.Line, 0);
485 std::map<TargetRegionEntryInfo, unsigned> OffloadEntriesTargetRegionCount;
488 typedef std::map<TargetRegionEntryInfo, OffloadEntryInfoTargetRegion>
489 OffloadEntriesTargetRegionTy;
490 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
493 typedef StringMap<OffloadEntryInfoDeviceGlobalVar>
494 OffloadEntriesDeviceGlobalVarTy;
495 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
501class OpenMPIRBuilder {
505 OpenMPIRBuilder(
Module &M)
507 T(
M.getTargetTriple()), IsFinalized(
false) {}
510 class AtomicInfo :
public llvm::AtomicInfo {
514 AtomicInfo(IRBuilder<> *Builder, llvm::Type *Ty, uint64_t AtomicSizeInBits,
515 uint64_t ValueSizeInBits, llvm::Align AtomicAlign,
516 llvm::Align ValueAlign,
bool UseLibcall,
517 IRBuilderBase::InsertPoint AllocaIP,
llvm::Value *AtomicVar)
518 : llvm::AtomicInfo(Builder, Ty, AtomicSizeInBits, ValueSizeInBits,
519 AtomicAlign, ValueAlign, UseLibcall, AllocaIP),
520 AtomicVar(AtomicVar) {}
522 llvm::Value *getAtomicPointer()
const override {
return AtomicVar; }
523 void decorateWithTBAA(llvm::Instruction *
I)
override {}
524 llvm::AllocaInst *CreateAlloca(llvm::Type *Ty,
525 const llvm::Twine &Name)
const override {
526 llvm::AllocaInst *allocaInst = Builder->CreateAlloca(Ty);
537 void setConfig(OpenMPIRBuilderConfig
C) { Config =
C; }
549 LLVM_ABI void addAttributes(omp::RuntimeFunction FnID, Function &Fn);
552 using InsertPointTy = IRBuilder<>::InsertPoint;
555 using InsertPointOrErrorTy = Expected<InsertPointTy>;
566 createPlatformSpecificName(ArrayRef<StringRef> Parts)
const;
576 using FinalizeCallbackTy = std::function<
Error(InsertPointTy CodeGenIP)>;
578 struct FinalizationInfo {
579 FinalizationInfo(FinalizeCallbackTy FiniCB, omp::Directive DK,
581 : DK(DK), IsCancellable(IsCancellable), FiniCB(std::
move(FiniCB)) {}
584 const omp::Directive DK;
587 const bool IsCancellable;
592 Expected<BasicBlock *> getFiniBB(IRBuilderBase &Builder);
597 Error mergeFiniBB(IRBuilderBase &Builder, BasicBlock *ExistingFiniBB);
605 FinalizeCallbackTy FiniCB;
611 void pushFinalizationCB(
const FinalizationInfo &FI) {
612 FinalizationStack.push_back(FI);
618 void popFinalizationCB() { FinalizationStack.pop_back(); }
646 using BodyGenCallbackTy =
647 function_ref<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
655 using StorableBodyGenCallbackTy =
656 std::function<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
668 using LoopBodyGenCallbackTy =
669 function_ref<
Error(InsertPointTy CodeGenIP,
Value *IndVar)>;
689 using PrivatizeCallbackTy = function_ref<InsertPointOrErrorTy(
690 InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
Value &Original,
695 struct LocationDescription {
696 LocationDescription(
const IRBuilderBase &IRB)
697 : IP(IRB.saveIP()),
DL(IRB.getCurrentDebugLocation()) {}
698 LocationDescription(
const InsertPointTy &IP) : IP(IP) {}
699 LocationDescription(
const InsertPointTy &IP,
const DebugLoc &
DL)
719 LLVM_ABI InsertPointOrErrorTy createBarrier(
const LocationDescription &Loc,
721 bool ForceSimpleCall =
false,
722 bool CheckCancelFlag =
true);
731 LLVM_ABI InsertPointOrErrorTy createCancel(
const LocationDescription &Loc,
733 omp::Directive CanceledDirective);
741 LLVM_ABI InsertPointOrErrorTy createCancellationPoint(
742 const LocationDescription &Loc, omp::Directive CanceledDirective);
745 LLVM_ABI Expected<ScanInfo *> scanInfoInitialize();
760 LLVM_ABI InsertPointOrErrorTy createParallel(
761 const LocationDescription &Loc, InsertPointTy AllocaIP,
762 BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
763 FinalizeCallbackTy FiniCB,
Value *IfCondition,
Value *NumThreads,
764 omp::ProcBindKind ProcBind,
bool IsCancellable);
785 LLVM_ABI Expected<CanonicalLoopInfo *>
786 createCanonicalLoop(
const LocationDescription &Loc,
787 LoopBodyGenCallbackTy BodyGenCB,
Value *TripCount,
788 const Twine &Name =
"loop");
821 LLVM_ABI Expected<SmallVector<llvm::CanonicalLoopInfo *>>
822 createCanonicalScanLoops(
const LocationDescription &Loc,
823 LoopBodyGenCallbackTy BodyGenCB,
Value *Start,
825 bool InclusiveStop, InsertPointTy ComputeIP,
826 const Twine &Name, ScanInfo *ScanRedInfo);
869 const LocationDescription &Loc,
Value *Start,
Value *Stop,
Value *Step,
870 bool IsSigned,
bool InclusiveStop,
const Twine &Name =
"loop");
902 LLVM_ABI Expected<CanonicalLoopInfo *> createCanonicalLoop(
903 const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB,
904 Value *Start,
Value *Stop,
Value *Step,
bool IsSigned,
bool InclusiveStop,
905 InsertPointTy ComputeIP = {},
const Twine &
Name =
"loop",
906 bool InScan =
false, ScanInfo *ScanRedInfo =
nullptr);
968 LLVM_ABI CanonicalLoopInfo *collapseLoops(DebugLoc
DL,
969 ArrayRef<CanonicalLoopInfo *>
Loops,
970 InsertPointTy ComputeIP);
977 getOpenMPDefaultSimdAlign(
const Triple &TargetTriple,
978 const StringMap<bool> &Features);
1015 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
1016 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
1017 bool IsDeclaration,
bool IsExternallyVisible,
1018 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
1019 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
1020 std::vector<Triple> TargetTriple,
Type *LlvmPtrTy,
1021 std::function<Constant *()> GlobalInitializer,
1022 std::function<GlobalValue::LinkageTypes()> VariableLinkage);
1058 LLVM_ABI void registerTargetGlobalVariable(
1059 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
1060 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
1061 bool IsDeclaration,
bool IsExternallyVisible,
1062 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
1063 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
1064 std::vector<Triple> TargetTriple,
1065 std::function<Constant *()> GlobalInitializer,
1066 std::function<GlobalValue::LinkageTypes()> VariableLinkage,
1067 Type *LlvmPtrTy, Constant *Addr);
1070 LLVM_ABI unsigned getFlagMemberOffset();
1079 LLVM_ABI omp::OpenMPOffloadMappingFlags getMemberOfFlag(
unsigned Position);
1091 setCorrectMemberOfFlag(omp::OpenMPOffloadMappingFlags &Flags,
1092 omp::OpenMPOffloadMappingFlags MemberOfFlag);
1114 InsertPointTy applyWorkshareLoopTarget(DebugLoc
DL, CanonicalLoopInfo *CLI,
1115 InsertPointTy AllocaIP,
1116 omp::WorksharingLoopType LoopType,
1142 InsertPointOrErrorTy applyStaticWorkshareLoop(
1143 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1144 omp::WorksharingLoopType LoopType,
bool NeedsBarrier,
1145 bool HasDistSchedule =
false,
1146 omp::OMPScheduleType DistScheduleSchedType = omp::OMPScheduleType::None);
1168 InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(
1169 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1170 bool NeedsBarrier,
Value *ChunkSize,
1171 omp::OMPScheduleType SchedType =
1172 omp::OMPScheduleType::UnorderedStaticChunked,
1173 Value *DistScheduleChunkSize =
nullptr,
1174 omp::OMPScheduleType DistScheduleSchedType = omp::OMPScheduleType::None);
1196 InsertPointOrErrorTy applyDynamicWorkshareLoop(DebugLoc
DL,
1197 CanonicalLoopInfo *CLI,
1198 InsertPointTy AllocaIP,
1199 omp::OMPScheduleType SchedType,
1201 Value *Chunk =
nullptr);
1214 void createIfVersion(CanonicalLoopInfo *Loop,
Value *IfCond,
1215 ValueMap<const Value *, WeakTrackingVH> &VMap,
1216 LoopAnalysis &LIA, LoopInfo &LI, llvm::Loop *L,
1217 const Twine &NamePrefix =
"");
1259 LLVM_ABI InsertPointOrErrorTy applyWorkshareLoop(
1260 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1262 llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default,
1263 Value *ChunkSize =
nullptr,
bool HasSimdModifier =
false,
1264 bool HasMonotonicModifier =
false,
bool HasNonmonotonicModifier =
false,
1265 bool HasOrderedClause =
false,
1266 omp::WorksharingLoopType LoopType =
1267 omp::WorksharingLoopType::ForStaticLoop,
1268 bool NoLoop =
false,
bool HasDistSchedule =
false,
1269 Value *DistScheduleChunkSize =
nullptr);
1314 LLVM_ABI std::vector<CanonicalLoopInfo *>
1315 tileLoops(DebugLoc
DL, ArrayRef<CanonicalLoopInfo *>
Loops,
1316 ArrayRef<Value *> TileSizes);
1326 LLVM_ABI void unrollLoopFull(DebugLoc
DL, CanonicalLoopInfo *Loop);
1333 LLVM_ABI void unrollLoopHeuristic(DebugLoc
DL, CanonicalLoopInfo *Loop);
1357 LLVM_ABI void unrollLoopPartial(DebugLoc
DL, CanonicalLoopInfo *Loop,
1359 CanonicalLoopInfo **UnrolledCLI);
1374 LLVM_ABI void applySimd(CanonicalLoopInfo *Loop,
1375 MapVector<Value *, Value *> AlignedVars,
1376 Value *IfCond, omp::OrderKind Order,
1377 ConstantInt *Simdlen, ConstantInt *Safelen);
1382 LLVM_ABI void createFlush(
const LocationDescription &Loc);
1387 LLVM_ABI void createTaskwait(
const LocationDescription &Loc);
1392 LLVM_ABI void createTaskyield(
const LocationDescription &Loc);
1396 omp::RTLDependenceKindTy DepKind = omp::RTLDependenceKindTy::DepUnknown;
1399 explicit DependData() =
default;
1400 DependData(omp::RTLDependenceKindTy DepKind,
Type *DepValueType,
1402 : DepKind(DepKind), DepValueType(DepValueType), DepVal(DepVal) {}
1425 createTask(
const LocationDescription &Loc, InsertPointTy AllocaIP,
1426 BodyGenCallbackTy BodyGenCB,
bool Tied =
true,
1427 Value *Final =
nullptr,
Value *IfCondition =
nullptr,
1428 SmallVector<DependData> Dependencies = {},
bool Mergeable =
false,
1429 Value *EventHandle =
nullptr,
Value *Priority =
nullptr);
1436 LLVM_ABI InsertPointOrErrorTy createTaskgroup(
const LocationDescription &Loc,
1437 InsertPointTy AllocaIP,
1438 BodyGenCallbackTy BodyGenCB);
1440 using FileIdentifierInfoCallbackTy =
1441 std::function<std::tuple<std::string, uint64_t>()>;
1450 LLVM_ABI static TargetRegionEntryInfo
1451 getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
1452 vfs::FileSystem &VFS, StringRef ParentName =
"");
1455 enum class ReductionGenCBKind { Clang, MLIR };
1467 using ReductionGenClangCBTy =
1468 std::function<InsertPointTy(InsertPointTy CodeGenIP,
unsigned Index,
1476 using ReductionGenCBTy = std::function<InsertPointOrErrorTy(
1483 using ReductionGenAtomicCBTy = std::function<InsertPointOrErrorTy(
1486 using ReductionGenDataPtrPtrCBTy = std::function<InsertPointOrErrorTy(
1487 InsertPointTy,
Value *ByRefVal,
Value *&Res)>;
1493 struct ReductionInfo {
1494 ReductionInfo(
Type *ElementType,
Value *Variable,
Value *PrivateVariable,
1495 EvalKind EvaluationKind, ReductionGenCBTy ReductionGen,
1496 ReductionGenClangCBTy ReductionGenClang,
1497 ReductionGenAtomicCBTy AtomicReductionGen,
1498 ReductionGenDataPtrPtrCBTy DataPtrPtrGen,
1499 Type *ByRefAllocatedType =
nullptr,
1500 Type *ByRefElementType =
nullptr)
1502 PrivateVariable(PrivateVariable), EvaluationKind(EvaluationKind),
1503 ReductionGen(ReductionGen), ReductionGenClang(ReductionGenClang),
1504 AtomicReductionGen(AtomicReductionGen), DataPtrPtrGen(DataPtrPtrGen),
1505 ByRefAllocatedType(ByRefAllocatedType),
1506 ByRefElementType(ByRefElementType) {}
1508 ReductionInfo(
Value *PrivateVariable)
1510 PrivateVariable(PrivateVariable), EvaluationKind(EvalKind::
Scalar),
1511 ReductionGen(), ReductionGenClang(), AtomicReductionGen(),
1522 Value *PrivateVariable;
1525 EvalKind EvaluationKind;
1530 ReductionGenCBTy ReductionGen;
1535 ReductionGenClangCBTy ReductionGenClang;
1541 ReductionGenAtomicCBTy AtomicReductionGen;
1543 ReductionGenDataPtrPtrCBTy DataPtrPtrGen;
1550 Type *ByRefAllocatedType;
1556 Type *ByRefElementType;
1559 enum class CopyAction :
unsigned {
1567 struct CopyOptionsTy {
1568 Value *RemoteLaneOffset =
nullptr;
1569 Value *ScratchpadIndex =
nullptr;
1570 Value *ScratchpadWidth =
nullptr;
1576 Value *getGPUThreadID();
1579 Value *getGPUWarpSize();
1584 Value *getNVPTXWarpID();
1589 Value *getNVPTXLaneID();
1592 Value *castValueToType(InsertPointTy AllocaIP,
Value *From,
Type *ToType);
1596 Value *createRuntimeShuffleFunction(InsertPointTy AllocaIP,
Value *Element,
1600 void shuffleAndStore(InsertPointTy AllocaIP,
Value *SrcAddr,
Value *DstAddr,
1606 Error emitReductionListCopy(
1607 InsertPointTy AllocaIP, CopyAction Action,
Type *ReductionArrayTy,
1608 ArrayRef<ReductionInfo> ReductionInfos,
Value *SrcBase,
Value *DestBase,
1609 ArrayRef<bool> IsByRef,
1610 CopyOptionsTy CopyOptions = {
nullptr,
nullptr,
nullptr});
1687 Expected<Function *> emitShuffleAndReduceFunction(
1688 ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1689 Function *ReduceFn, AttributeList FuncAttrs, ArrayRef<bool> IsByRef);
1699 Error emitScanBasedDirectiveIR(
1700 llvm::function_ref<
Error()> InputLoopGen,
1701 llvm::function_ref<
Error(LocationDescription Loc)> ScanLoopGen,
1702 ScanInfo *ScanRedInfo);
1707 void createScanBBs(ScanInfo *ScanRedInfo);
1717 Error emitScanBasedDirectiveDeclsIR(InsertPointTy AllocaIP,
1718 ArrayRef<llvm::Value *> ScanVars,
1719 ArrayRef<llvm::Type *> ScanVarsType,
1720 ScanInfo *ScanRedInfo);
1728 Error emitScanBasedDirectiveFinalsIR(
1729 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1730 ScanInfo *ScanInfo);
1753 Expected<Function *>
1754 emitInterWarpCopyFunction(
const LocationDescription &Loc,
1755 ArrayRef<ReductionInfo> ReductionInfos,
1756 AttributeList FuncAttrs, ArrayRef<bool> IsByRef);
1771 Function *emitListToGlobalCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1772 Type *ReductionsBufferTy,
1773 AttributeList FuncAttrs);
1788 Function *emitGlobalToListCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1789 Type *ReductionsBufferTy,
1790 AttributeList FuncAttrs);
1810 emitListToGlobalReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1811 Function *ReduceFn,
Type *ReductionsBufferTy,
1812 AttributeList FuncAttrs);
1832 emitGlobalToListReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1833 Function *ReduceFn,
Type *ReductionsBufferTy,
1834 AttributeList FuncAttrs);
1837 std::string getReductionFuncName(StringRef Name)
const;
1848 Expected<Function *> createReductionFunction(
1849 StringRef ReducerName, ArrayRef<ReductionInfo> ReductionInfos,
1850 ArrayRef<bool> IsByRef,
1851 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
1852 AttributeList FuncAttrs = {});
2116 LLVM_ABI InsertPointOrErrorTy createReductionsGPU(
2117 const LocationDescription &Loc, InsertPointTy AllocaIP,
2118 InsertPointTy CodeGenIP, ArrayRef<ReductionInfo> ReductionInfos,
2119 ArrayRef<bool> IsByRef,
bool IsNoWait =
false,
2120 bool IsTeamsReduction =
false,
2121 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
2122 std::optional<omp::GV> GridValue = {},
unsigned ReductionBufNum = 1024,
2123 Value *SrcLocInfo =
nullptr);
2190 LLVM_ABI InsertPointOrErrorTy createReductions(
2191 const LocationDescription &Loc, InsertPointTy AllocaIP,
2192 ArrayRef<ReductionInfo> ReductionInfos, ArrayRef<bool> IsByRef,
2193 bool IsNoWait =
false,
bool IsTeamsReduction =
false);
2198 InsertPointTy getInsertionPoint() {
return Builder.saveIP(); }
2201 bool updateToLocation(
const LocationDescription &Loc) {
2202 Builder.restoreIP(Loc.IP);
2203 Builder.SetCurrentDebugLocation(Loc.DL);
2204 return Loc.IP.getBlock() !=
nullptr;
2209 omp::RuntimeFunction FnID);
2211 LLVM_ABI Function *getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID);
2213 CallInst *createRuntimeFunctionCall(FunctionCallee Callee,
2214 ArrayRef<Value *> Args,
2215 StringRef Name =
"");
2219 uint32_t &SrcLocStrSize);
2227 StringRef FileName,
unsigned Line,
2229 uint32_t &SrcLocStrSize);
2234 Function *
F =
nullptr);
2238 uint32_t &SrcLocStrSize);
2243 uint32_t SrcLocStrSize,
2244 omp::IdentFlag Flags = omp::IdentFlag(0),
2245 unsigned Reserve2Flags = 0);
2249 LLVM_ABI GlobalValue *createGlobalFlag(
unsigned Value, StringRef Name);
2252 LLVM_ABI void emitUsed(StringRef Name, ArrayRef<llvm::WeakTrackingVH> List);
2256 emitKernelExecutionMode(StringRef KernelName, omp::OMPTgtExecModeFlags
Mode);
2266 omp::Directive CanceledDirective);
2279 LLVM_ABI InsertPointTy emitTargetKernel(
const LocationDescription &Loc,
2280 InsertPointTy AllocaIP,
2284 ArrayRef<Value *> KernelArgs);
2289 LLVM_ABI void emitFlush(
const LocationDescription &Loc);
2294 SmallVector<FinalizationInfo, 8> FinalizationStack;
2298 bool isLastFinalizationInfoCancellable(omp::Directive DK) {
2299 return !FinalizationStack.empty() &&
2300 FinalizationStack.back().IsCancellable &&
2301 FinalizationStack.back().DK == DK;
2307 LLVM_ABI void emitTaskwaitImpl(
const LocationDescription &Loc);
2312 LLVM_ABI void emitTaskyieldImpl(
const LocationDescription &Loc);
2320 OpenMPIRBuilderConfig Config;
2326 IRBuilder<> Builder;
2329 StringMap<Constant *> SrcLocStrMap;
2332 DenseMap<std::pair<Constant *, uint64_t>,
Constant *> IdentMap;
2335 OffloadEntriesInfoManager OffloadInfoManager;
2342 struct OutlineInfo {
2343 using PostOutlineCBTy = std::function<void(Function &)>;
2344 PostOutlineCBTy PostOutlineCB;
2345 BasicBlock *EntryBB, *ExitBB, *OuterAllocaBB;
2346 SmallVector<Value *, 2> ExcludeArgsFromAggregate;
2351 SmallVectorImpl<BasicBlock *> &BlockVector);
2358 SmallVector<OutlineInfo, 16> OutlineInfos;
2363 SmallVector<llvm::Function *, 16> ConstantAllocaRaiseCandidates;
2367 std::forward_list<CanonicalLoopInfo> LoopInfos;
2370 std::forward_list<ScanInfo> ScanInfos;
2373 void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
2380 StringMap<GlobalVariable *, BumpPtrAllocator> InternalVars;
2387 LLVM_ABI void emitBranch(BasicBlock *Target);
2392 LLVM_ABI void emitBlock(BasicBlock *BB, Function *CurFn,
2393 bool IsFinished =
false);
2405 BodyGenCallbackTy ElseGen,
2406 InsertPointTy AllocaIP = {});
2410 createOffloadMaptypes(SmallVectorImpl<uint64_t> &Mappings,
2411 std::string VarName);
2415 createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
2416 std::string VarName);
2418 struct MapperAllocas {
2419 AllocaInst *ArgsBase =
nullptr;
2420 AllocaInst *
Args =
nullptr;
2421 AllocaInst *ArgSizes =
nullptr;
2425 LLVM_ABI void createMapperAllocas(
const LocationDescription &Loc,
2426 InsertPointTy AllocaIP,
2427 unsigned NumOperands,
2428 struct MapperAllocas &MapperAllocas);
2439 LLVM_ABI void emitMapperCall(
const LocationDescription &Loc,
2440 Function *MapperFunc,
Value *SrcLocInfo,
2442 struct MapperAllocas &MapperAllocas,
2443 int64_t DeviceID,
unsigned NumOperands);
2446 struct TargetDataRTArgs {
2448 Value *BasePointersArray =
nullptr;
2450 Value *PointersArray =
nullptr;
2452 Value *SizesArray =
nullptr;
2456 Value *MapTypesArray =
nullptr;
2460 Value *MapTypesArrayEnd =
nullptr;
2462 Value *MappersArray =
nullptr;
2465 Value *MapNamesArray =
nullptr;
2467 explicit TargetDataRTArgs() =
default;
2468 explicit TargetDataRTArgs(
Value *BasePointersArray,
Value *PointersArray,
2470 Value *MapTypesArrayEnd,
Value *MappersArray,
2471 Value *MapNamesArray)
2472 : BasePointersArray(BasePointersArray), PointersArray(PointersArray),
2473 SizesArray(SizesArray), MapTypesArray(MapTypesArray),
2474 MapTypesArrayEnd(MapTypesArrayEnd), MappersArray(MappersArray),
2475 MapNamesArray(MapNamesArray) {}
2485 struct TargetKernelDefaultAttrs {
2486 omp::OMPTgtExecModeFlags ExecFlags =
2487 omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
2488 SmallVector<int32_t, 3> MaxTeams = {-1};
2489 int32_t MinTeams = 1;
2491 int32_t MinThreads = 1;
2492 int32_t ReductionDataSize = 0;
2493 int32_t ReductionBufferLength = 0;
2501 struct TargetKernelRuntimeAttrs {
2502 SmallVector<Value *, 3> MaxTeams = {
nullptr};
2503 Value *MinTeams =
nullptr;
2504 SmallVector<Value *, 3> TargetThreadLimit = {
nullptr};
2505 SmallVector<Value *, 3> TeamsThreadLimit = {
nullptr};
2513 Value *LoopTripCount =
nullptr;
2518 struct TargetKernelArgs {
2520 unsigned NumTargetItems = 0;
2522 TargetDataRTArgs RTArgs;
2524 Value *NumIterations =
nullptr;
2526 ArrayRef<Value *> NumTeams;
2528 ArrayRef<Value *> NumThreads;
2530 Value *DynCGroupMem =
nullptr;
2532 bool HasNoWait =
false;
2534 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback =
2535 omp::OMPDynGroupprivateFallbackType::Abort;
2538 TargetKernelArgs() =
default;
2539 TargetKernelArgs(
unsigned NumTargetItems, TargetDataRTArgs RTArgs,
2540 Value *NumIterations, ArrayRef<Value *> NumTeams,
2541 ArrayRef<Value *> NumThreads,
Value *DynCGroupMem,
2543 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback)
2544 : NumTargetItems(NumTargetItems), RTArgs(RTArgs),
2545 NumIterations(NumIterations), NumTeams(NumTeams),
2546 NumThreads(NumThreads), DynCGroupMem(DynCGroupMem),
2547 HasNoWait(HasNoWait), DynCGroupMemFallback(DynCGroupMemFallback) {}
2553 LLVM_ABI static void getKernelArgsVector(TargetKernelArgs &KernelArgs,
2554 IRBuilderBase &Builder,
2555 SmallVector<Value *> &ArgsVector);
2559 class TargetDataInfo {
2561 bool RequiresDevicePointerInfo =
false;
2564 bool SeparateBeginEndCalls =
false;
2567 TargetDataRTArgs RTArgs;
2569 SmallMapVector<const Value *, std::pair<Value *, Value *>, 4>
2573 bool HasMapper =
false;
2575 unsigned NumberOfPtrs = 0
u;
2577 bool EmitDebug =
false;
2580 bool HasNoWait =
false;
2582 explicit TargetDataInfo() =
default;
2583 explicit TargetDataInfo(
bool RequiresDevicePointerInfo,
2584 bool SeparateBeginEndCalls)
2585 : RequiresDevicePointerInfo(RequiresDevicePointerInfo),
2586 SeparateBeginEndCalls(SeparateBeginEndCalls) {}
2588 void clearArrayInfo() {
2589 RTArgs = TargetDataRTArgs();
2595 return RTArgs.BasePointersArray && RTArgs.PointersArray &&
2596 RTArgs.SizesArray && RTArgs.MapTypesArray &&
2597 (!HasMapper || RTArgs.MappersArray) && NumberOfPtrs;
2599 bool requiresDevicePointerInfo() {
return RequiresDevicePointerInfo; }
2600 bool separateBeginEndCalls() {
return SeparateBeginEndCalls; }
2604 using MapValuesArrayTy = SmallVector<Value *, 4>;
2605 using MapDeviceInfoArrayTy = SmallVector<DeviceInfoTy, 4>;
2606 using MapFlagsArrayTy = SmallVector<omp::OpenMPOffloadMappingFlags, 4>;
2607 using MapNamesArrayTy = SmallVector<Constant *, 4>;
2608 using MapDimArrayTy = SmallVector<uint64_t, 4>;
2609 using MapNonContiguousArrayTy = SmallVector<MapValuesArrayTy, 4>;
2615 struct StructNonContiguousInfo {
2616 bool IsNonContiguous =
false;
2618 MapNonContiguousArrayTy
Offsets;
2619 MapNonContiguousArrayTy Counts;
2620 MapNonContiguousArrayTy Strides;
2622 MapValuesArrayTy BasePointers;
2623 MapValuesArrayTy Pointers;
2624 MapDeviceInfoArrayTy DevicePointers;
2625 MapValuesArrayTy
Sizes;
2626 MapFlagsArrayTy
Types;
2627 MapNamesArrayTy Names;
2628 StructNonContiguousInfo NonContigInfo;
2631 void append(MapInfosTy &CurInfo) {
2632 BasePointers.append(CurInfo.BasePointers.begin(),
2633 CurInfo.BasePointers.end());
2634 Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
2635 DevicePointers.append(CurInfo.DevicePointers.begin(),
2636 CurInfo.DevicePointers.end());
2637 Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
2638 Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
2639 Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
2640 NonContigInfo.Dims.append(CurInfo.NonContigInfo.Dims.begin(),
2641 CurInfo.NonContigInfo.Dims.end());
2642 NonContigInfo.Offsets.append(CurInfo.NonContigInfo.Offsets.begin(),
2643 CurInfo.NonContigInfo.Offsets.end());
2644 NonContigInfo.Counts.append(CurInfo.NonContigInfo.Counts.begin(),
2645 CurInfo.NonContigInfo.Counts.end());
2646 NonContigInfo.Strides.append(CurInfo.NonContigInfo.Strides.begin(),
2647 CurInfo.NonContigInfo.Strides.end());
2650 using MapInfosOrErrorTy = Expected<MapInfosTy &>;
2656 using EmitFallbackCallbackTy =
2657 function_ref<InsertPointOrErrorTy(InsertPointTy)>;
2661 using CustomMapperCallbackTy =
2662 function_ref<Expected<Function *>(
unsigned int)>;
2674 LLVM_ABI InsertPointOrErrorTy emitKernelLaunch(
2675 const LocationDescription &Loc,
Value *OutlinedFnID,
2676 EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args,
2677 Value *DeviceID,
Value *RTLoc, InsertPointTy AllocaIP);
2689 using TargetTaskBodyCallbackTy =
2691 IRBuilderBase::InsertPoint TargetTaskAllocaIP)>;
2703 LLVM_ABI InsertPointOrErrorTy emitTargetTask(
2704 TargetTaskBodyCallbackTy TaskBodyCB,
Value *DeviceID,
Value *RTLoc,
2705 OpenMPIRBuilder::InsertPointTy AllocaIP,
2706 const SmallVector<llvm::OpenMPIRBuilder::DependData> &Dependencies,
2707 const TargetDataRTArgs &RTArgs,
bool HasNoWait);
2713 LLVM_ABI void emitOffloadingArraysArgument(
2714 IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs,
2715 OpenMPIRBuilder::TargetDataInfo &
Info,
bool ForEndCall =
false);
2718 LLVM_ABI void emitNonContiguousDescriptor(InsertPointTy AllocaIP,
2719 InsertPointTy CodeGenIP,
2720 MapInfosTy &CombinedInfo,
2721 TargetDataInfo &
Info);
2729 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
2730 TargetDataInfo &
Info, CustomMapperCallbackTy CustomMapperCB,
2731 bool IsNonContiguous =
false,
2732 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2741 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &
Info,
2742 TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
2743 CustomMapperCallbackTy CustomMapperCB,
bool IsNonContiguous =
false,
2744 bool ForEndCall =
false,
2745 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2749 LLVM_ABI void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t
Size,
2750 int32_t Flags, GlobalValue::LinkageTypes,
2751 StringRef Name =
"");
2755 enum EmitMetadataErrorKind {
2756 EMIT_MD_TARGET_REGION_ERROR,
2757 EMIT_MD_DECLARE_TARGET_ERROR,
2758 EMIT_MD_GLOBAL_VAR_LINK_ERROR
2762 using EmitMetadataErrorReportFunctionTy =
2763 std::function<void(EmitMetadataErrorKind, TargetRegionEntryInfo)>;
2772 LLVM_ABI void createOffloadEntriesAndInfoMetadata(
2773 EmitMetadataErrorReportFunctionTy &ErrorReportFunction);
2786 LLVM_ABI InsertPointTy createCopyPrivate(
const LocationDescription &Loc,
2803 createSingle(
const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2804 FinalizeCallbackTy FiniCB,
bool IsNowait,
2805 ArrayRef<llvm::Value *> CPVars = {},
2806 ArrayRef<llvm::Function *> CPFuncs = {});
2815 LLVM_ABI InsertPointOrErrorTy createMaster(
const LocationDescription &Loc,
2816 BodyGenCallbackTy BodyGenCB,
2817 FinalizeCallbackTy FiniCB);
2826 LLVM_ABI InsertPointOrErrorTy createMasked(
const LocationDescription &Loc,
2827 BodyGenCallbackTy BodyGenCB,
2828 FinalizeCallbackTy FiniCB,
2849 LLVM_ABI InsertPointOrErrorTy emitScanReduction(
2850 const LocationDescription &Loc,
2851 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
2852 ScanInfo *ScanRedInfo);
2867 LLVM_ABI InsertPointOrErrorTy createScan(
const LocationDescription &Loc,
2868 InsertPointTy AllocaIP,
2869 ArrayRef<llvm::Value *> ScanVars,
2870 ArrayRef<llvm::Type *> ScanVarsType,
2872 ScanInfo *ScanRedInfo);
2883 LLVM_ABI InsertPointOrErrorTy createCritical(
const LocationDescription &Loc,
2884 BodyGenCallbackTy BodyGenCB,
2885 FinalizeCallbackTy FiniCB,
2886 StringRef CriticalName,
2900 createOrderedDepend(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2901 unsigned NumLoops, ArrayRef<llvm::Value *> StoreValues,
2902 const Twine &Name,
bool IsDependSource);
2913 LLVM_ABI InsertPointOrErrorTy createOrderedThreadsSimd(
2914 const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2915 FinalizeCallbackTy FiniCB,
bool IsThreads);
2929 createSections(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2930 ArrayRef<StorableBodyGenCallbackTy> SectionCBs,
2931 PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB,
2932 bool IsCancellable,
bool IsNowait);
2940 LLVM_ABI InsertPointOrErrorTy createSection(
const LocationDescription &Loc,
2941 BodyGenCallbackTy BodyGenCB,
2942 FinalizeCallbackTy FiniCB);
2956 LLVM_ABI InsertPointOrErrorTy createTeams(
const LocationDescription &Loc,
2957 BodyGenCallbackTy BodyGenCB,
2958 Value *NumTeamsLower =
nullptr,
2959 Value *NumTeamsUpper =
nullptr,
2960 Value *ThreadLimit =
nullptr,
2961 Value *IfExpr =
nullptr);
2968 LLVM_ABI InsertPointOrErrorTy createDistribute(
const LocationDescription &Loc,
2969 InsertPointTy AllocaIP,
2970 BodyGenCallbackTy BodyGenCB);
2984 LLVM_ABI InsertPointTy createCopyinClauseBlocks(InsertPointTy IP,
2987 llvm::IntegerType *IntPtrTy,
2988 bool BranchtoEnd =
true);
3009 LLVM_ABI CallInst *createOMPFree(
const LocationDescription &Loc,
Value *Addr,
3021 createCachedThreadPrivate(
const LocationDescription &Loc,
3023 const llvm::Twine &Name = Twine(
""));
3036 LLVM_ABI CallInst *createOMPInteropInit(
const LocationDescription &Loc,
3038 omp::OMPInteropType InteropType,
3040 Value *DependenceAddress,
3041 bool HaveNowaitClause);
3053 LLVM_ABI CallInst *createOMPInteropDestroy(
const LocationDescription &Loc,
3055 Value *NumDependences,
3056 Value *DependenceAddress,
3057 bool HaveNowaitClause);
3069 LLVM_ABI CallInst *createOMPInteropUse(
const LocationDescription &Loc,
3071 Value *NumDependences,
3072 Value *DependenceAddress,
3073 bool HaveNowaitClause);
3087 LLVM_ABI InsertPointTy createTargetInit(
3088 const LocationDescription &Loc,
3089 const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
3098 LLVM_ABI void createTargetDeinit(
const LocationDescription &Loc,
3099 int32_t TeamsReductionDataSize = 0,
3100 int32_t TeamsReductionBufferLength = 1024);
3110 LLVM_ABI static std::pair<int32_t, int32_t>
3111 readThreadBoundsForKernel(
const Triple &
T, Function &Kernel);
3112 LLVM_ABI static void writeThreadBoundsForKernel(
const Triple &
T,
3113 Function &Kernel, int32_t LB,
3118 LLVM_ABI static std::pair<int32_t, int32_t>
3119 readTeamBoundsForKernel(
const Triple &
T, Function &Kernel);
3120 LLVM_ABI static void writeTeamsForKernel(
const Triple &
T, Function &Kernel,
3121 int32_t LB, int32_t UB);
3126 void setOutlinedTargetRegionFunctionAttributes(Function *OutlinedFn);
3131 Constant *createOutlinedFunctionID(Function *OutlinedFn,
3132 StringRef EntryFnIDName);
3135 Constant *createTargetRegionEntryAddr(Function *OutlinedFunction,
3136 StringRef EntryFnName);
3140 using FunctionGenCallback =
3141 std::function<Expected<Function *>(StringRef FunctionName)>;
3175 TargetRegionEntryInfo &EntryInfo,
3176 FunctionGenCallback &GenerateFunctionCallback,
bool IsOffloadEntry,
3177 Function *&OutlinedFn, Constant *&OutlinedFnID);
3188 registerTargetRegionFunction(TargetRegionEntryInfo &EntryInfo,
3189 Function *OutlinedFunction,
3190 StringRef EntryFnName, StringRef EntryFnIDName);
3203 enum BodyGenTy { Priv, DupNoPriv, NoPriv };
3208 using GenMapInfoCallbackTy =
3209 function_ref<MapInfosTy &(InsertPointTy CodeGenIP)>;
3218 void emitUDMapperArrayInitOrDel(Function *MapperFn,
llvm::Value *MapperHandle,
3222 llvm::BasicBlock *ExitBB,
bool IsInit);
3265 LLVM_ABI Expected<Function *> emitUserDefinedMapper(
3266 function_ref<MapInfosOrErrorTy(
3268 PrivAndGenMapInfoCB,
3269 llvm::Type *ElemTy, StringRef FuncName,
3270 CustomMapperCallbackTy CustomMapperCB);
3289 LLVM_ABI InsertPointOrErrorTy createTargetData(
3290 const LocationDescription &Loc, InsertPointTy AllocaIP,
3291 InsertPointTy CodeGenIP,
Value *DeviceID,
Value *IfCond,
3292 TargetDataInfo &
Info, GenMapInfoCallbackTy GenMapInfoCB,
3293 CustomMapperCallbackTy CustomMapperCB,
3294 omp::RuntimeFunction *MapperFunc =
nullptr,
3295 function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
3296 BodyGenTy BodyGenType)>
3297 BodyGenCB =
nullptr,
3298 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr,
3299 Value *SrcLocInfo =
nullptr);
3301 using TargetBodyGenCallbackTy = function_ref<InsertPointOrErrorTy(
3302 InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
3304 using TargetGenArgAccessorsCallbackTy = function_ref<InsertPointOrErrorTy(
3305 Argument &Arg,
Value *Input,
Value *&RetVal, InsertPointTy AllocaIP,
3306 InsertPointTy CodeGenIP)>;
3336 LLVM_ABI InsertPointOrErrorTy createTarget(
3337 const LocationDescription &Loc,
bool IsOffloadEntry,
3338 OpenMPIRBuilder::InsertPointTy AllocaIP,
3339 OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetDataInfo &
Info,
3340 TargetRegionEntryInfo &EntryInfo,
3341 const TargetKernelDefaultAttrs &DefaultAttrs,
3342 const TargetKernelRuntimeAttrs &RuntimeAttrs,
Value *IfCond,
3343 SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
3344 TargetBodyGenCallbackTy BodyGenCB,
3345 TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
3346 CustomMapperCallbackTy CustomMapperCB,
3347 const SmallVector<DependData> &Dependencies,
bool HasNowait =
false,
3348 Value *DynCGroupMem =
nullptr,
3349 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback =
3350 omp::OMPDynGroupprivateFallbackType::Abort);
3355 LLVM_ABI FunctionCallee createForStaticInitFunction(
unsigned IVSize,
3357 bool IsGPUDistribute);
3361 LLVM_ABI FunctionCallee createDispatchInitFunction(
unsigned IVSize,
3366 LLVM_ABI FunctionCallee createDispatchNextFunction(
unsigned IVSize,
3371 LLVM_ABI FunctionCallee createDispatchFiniFunction(
unsigned IVSize,
3375 LLVM_ABI FunctionCallee createDispatchDeinitFunction();
3383#define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
3384#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
3385 ArrayType *VarName##Ty = nullptr; \
3386 PointerType *VarName##PtrTy = nullptr;
3387#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
3388 FunctionType *VarName = nullptr; \
3389 PointerType *VarName##Ptr = nullptr;
3390#define OMP_STRUCT_TYPE(VarName, StrName, ...) \
3391 StructType *VarName = nullptr; \
3392 PointerType *VarName##Ptr = nullptr;
3393#include "llvm/Frontend/OpenMP/OMPKinds.def"
3400 void initializeTypes(
Module &M);
3414 InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD,
Value *EntryCall,
3416 bool Conditional =
false);
3429 InsertPointOrErrorTy emitCommonDirectiveExit(omp::Directive OMPD,
3430 InsertPointTy FinIP,
3431 Instruction *ExitCall,
3432 bool HasFinalize =
true);
3450 InsertPointOrErrorTy
3451 EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
3452 Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
3453 FinalizeCallbackTy FiniCB,
bool Conditional =
false,
3454 bool HasFinalize =
true,
bool IsCancellable =
false);
3462 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
3463 StringRef FirstSeparator,
3464 StringRef Separator);
3471 Value *getOMPCriticalRegionLock(StringRef CriticalName);
3485 using AtomicUpdateCallbackTy =
3486 const function_ref<Expected<Value *>(
Value *XOld, IRBuilder<> &IRB)>;
3498 bool checkAndEmitFlushAfterAtomic(
const LocationDescription &Loc,
3499 AtomicOrdering AO, AtomicKind AK);
3525 Expected<std::pair<Value *, Value *>>
3526 emitAtomicUpdate(InsertPointTy AllocaIP,
Value *
X,
Type *XElemTy,
Value *Expr,
3527 AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3528 AtomicUpdateCallbackTy &UpdateOp,
bool VolatileX,
3529 bool IsXBinopExpr,
bool IsIgnoreDenormalMode,
3530 bool IsFineGrainedMemory,
bool IsRemoteMemory);
3536 AtomicRMWInst::BinOp RMWOp);
3542 struct AtomicOpValue {
3543 Value *Var =
nullptr;
3544 Type *ElemTy =
nullptr;
3545 bool IsSigned =
false;
3560 LLVM_ABI InsertPointTy createAtomicRead(
const LocationDescription &Loc,
3561 AtomicOpValue &
X, AtomicOpValue &V,
3563 InsertPointTy AllocaIP);
3575 LLVM_ABI InsertPointTy createAtomicWrite(
const LocationDescription &Loc,
3576 AtomicOpValue &
X,
Value *Expr,
3578 InsertPointTy AllocaIP);
3600 LLVM_ABI InsertPointOrErrorTy createAtomicUpdate(
3601 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3602 Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3603 AtomicUpdateCallbackTy &UpdateOp,
bool IsXBinopExpr,
3604 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3605 bool IsRemoteMemory =
false);
3636 LLVM_ABI InsertPointOrErrorTy createAtomicCapture(
3637 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3638 AtomicOpValue &V,
Value *Expr, AtomicOrdering AO,
3639 AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
3640 bool UpdateExpr,
bool IsPostfixUpdate,
bool IsXBinopExpr,
3641 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3642 bool IsRemoteMemory =
false);
3690 createAtomicCompare(
const LocationDescription &Loc, AtomicOpValue &
X,
3691 AtomicOpValue &V, AtomicOpValue &R,
Value *
E,
Value *
D,
3692 AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
3693 bool IsXBinopExpr,
bool IsPostfixUpdate,
bool IsFailOnly);
3694 LLVM_ABI InsertPointTy createAtomicCompare(
3695 const LocationDescription &Loc, AtomicOpValue &
X, AtomicOpValue &V,
3696 AtomicOpValue &R,
Value *
E,
Value *
D, AtomicOrdering AO,
3697 omp::OMPAtomicCompareOp Op,
bool IsXBinopExpr,
bool IsPostfixUpdate,
3698 bool IsFailOnly, AtomicOrdering Failure);
3716 LLVM_ABI CanonicalLoopInfo *createLoopSkeleton(DebugLoc
DL,
Value *TripCount,
3718 BasicBlock *PreInsertBefore,
3719 BasicBlock *PostInsertBefore,
3720 const Twine &Name = {});
3722 const std::string ompOffloadInfoName =
"omp_offload.info";
3739 LLVM_ABI void loadOffloadInfoMetadata(vfs::FileSystem &VFS,
3740 StringRef HostFilePath);
3749 getOrCreateInternalVariable(
Type *Ty,
const StringRef &Name,
3750 std::optional<unsigned> AddressSpace = {});
3851class CanonicalLoopInfo {
3852 friend class OpenMPIRBuilder;
3861 Value *LastIter =
nullptr;
3871 void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
3876 void setTripCount(
Value *TripCount);
3892 void mapIndVar(llvm::function_ref<
Value *(Instruction *)> Updater);
3896 void setLastIter(
Value *IterVar) { LastIter = std::move(IterVar); }
3905 Value *getLastIter() {
return LastIter; }
3910 bool isValid()
const {
return Header; }
3937 return cast<BranchInst>(
Cond->getTerminator())->getSuccessor(0);
3961 return Exit->getSingleSuccessor();
3967 Value *getTripCount()
const {
3970 assert(isa<CmpInst>(CmpI) &&
"First inst must compare IV with TripCount");
3971 return CmpI->getOperand(1);
3979 assert(isa<PHINode>(IndVarPHI) &&
"First inst must be the IV PHI");
3984 Type *getIndVarType()
const {
3986 return getIndVar()->getType();
3990 OpenMPIRBuilder::InsertPointTy getPreheaderIP()
const {
3993 return {Preheader, std::prev(Preheader->end())};
3997 OpenMPIRBuilder::InsertPointTy getBodyIP()
const {
4000 return {Body, Body->begin()};
4004 OpenMPIRBuilder::InsertPointTy getAfterIP()
const {
4007 return {After, After->begin()};
4012 return Header->getParent();
4070 llvm::BasicBlock *OMPBeforeScanBlock =
nullptr;
4073 llvm::BasicBlock *OMPAfterScanBlock =
nullptr;
4076 llvm::BasicBlock *OMPScanDispatch =
nullptr;
4079 llvm::BasicBlock *OMPScanLoopExit =
nullptr;
4082 llvm::BasicBlock *OMPScanInit =
nullptr;
4085 llvm::BasicBlock *OMPScanFinish =
nullptr;
4089 bool OMPFirstScanLoop =
false;
4093 llvm::SmallDenseMap<llvm::Value *, llvm::Value *> *ScanBuffPtrs;
4104 ScanBuffPtrs =
new llvm::SmallDenseMap<llvm::Value *, llvm::Value *>();
4106 ScanInfo(ScanInfo &) =
delete;
4107 ScanInfo &operator=(
const ScanInfo &) =
delete;
4109 ~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, 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.