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 Expected<Function *>
1772 emitListToGlobalCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1773 Type *ReductionsBufferTy,
1774 AttributeList FuncAttrs, ArrayRef<bool> IsByRef);
1789 Expected<Function *>
1790 emitGlobalToListCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1791 Type *ReductionsBufferTy,
1792 AttributeList FuncAttrs, ArrayRef<bool> IsByRef);
1811 Expected<Function *>
1812 emitListToGlobalReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1813 Function *ReduceFn,
Type *ReductionsBufferTy,
1814 AttributeList FuncAttrs,
1815 ArrayRef<bool> IsByRef);
1834 Expected<Function *>
1835 emitGlobalToListReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1836 Function *ReduceFn,
Type *ReductionsBufferTy,
1837 AttributeList FuncAttrs,
1838 ArrayRef<bool> IsByRef);
1841 std::string getReductionFuncName(StringRef Name)
const;
1852 Expected<Function *> createReductionFunction(
1853 StringRef ReducerName, ArrayRef<ReductionInfo> ReductionInfos,
1854 ArrayRef<bool> IsByRef,
1855 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
1856 AttributeList FuncAttrs = {});
2120 LLVM_ABI InsertPointOrErrorTy createReductionsGPU(
2121 const LocationDescription &Loc, InsertPointTy AllocaIP,
2122 InsertPointTy CodeGenIP, ArrayRef<ReductionInfo> ReductionInfos,
2123 ArrayRef<bool> IsByRef,
bool IsNoWait =
false,
2124 bool IsTeamsReduction =
false,
2125 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
2126 std::optional<omp::GV> GridValue = {},
unsigned ReductionBufNum = 1024,
2127 Value *SrcLocInfo =
nullptr);
2194 LLVM_ABI InsertPointOrErrorTy createReductions(
2195 const LocationDescription &Loc, InsertPointTy AllocaIP,
2196 ArrayRef<ReductionInfo> ReductionInfos, ArrayRef<bool> IsByRef,
2197 bool IsNoWait =
false,
bool IsTeamsReduction =
false);
2202 InsertPointTy getInsertionPoint() {
return Builder.saveIP(); }
2205 bool updateToLocation(
const LocationDescription &Loc) {
2206 Builder.restoreIP(Loc.IP);
2207 Builder.SetCurrentDebugLocation(Loc.DL);
2208 return Loc.IP.getBlock() !=
nullptr;
2213 omp::RuntimeFunction FnID);
2215 LLVM_ABI Function *getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID);
2217 CallInst *createRuntimeFunctionCall(FunctionCallee Callee,
2218 ArrayRef<Value *> Args,
2219 StringRef Name =
"");
2223 uint32_t &SrcLocStrSize);
2231 StringRef FileName,
unsigned Line,
2233 uint32_t &SrcLocStrSize);
2238 Function *
F =
nullptr);
2242 uint32_t &SrcLocStrSize);
2247 uint32_t SrcLocStrSize,
2248 omp::IdentFlag Flags = omp::IdentFlag(0),
2249 unsigned Reserve2Flags = 0);
2253 LLVM_ABI GlobalValue *createGlobalFlag(
unsigned Value, StringRef Name);
2256 LLVM_ABI void emitUsed(StringRef Name, ArrayRef<llvm::WeakTrackingVH> List);
2260 emitKernelExecutionMode(StringRef KernelName, omp::OMPTgtExecModeFlags
Mode);
2270 omp::Directive CanceledDirective);
2283 LLVM_ABI InsertPointTy emitTargetKernel(
const LocationDescription &Loc,
2284 InsertPointTy AllocaIP,
2288 ArrayRef<Value *> KernelArgs);
2293 LLVM_ABI void emitFlush(
const LocationDescription &Loc);
2298 SmallVector<FinalizationInfo, 8> FinalizationStack;
2302 bool isLastFinalizationInfoCancellable(omp::Directive DK) {
2303 return !FinalizationStack.empty() &&
2304 FinalizationStack.back().IsCancellable &&
2305 FinalizationStack.back().DK == DK;
2311 LLVM_ABI void emitTaskwaitImpl(
const LocationDescription &Loc);
2316 LLVM_ABI void emitTaskyieldImpl(
const LocationDescription &Loc);
2324 OpenMPIRBuilderConfig Config;
2330 IRBuilder<> Builder;
2333 StringMap<Constant *> SrcLocStrMap;
2336 DenseMap<std::pair<Constant *, uint64_t>,
Constant *> IdentMap;
2339 OffloadEntriesInfoManager OffloadInfoManager;
2346 struct OutlineInfo {
2347 using PostOutlineCBTy = std::function<void(Function &)>;
2348 PostOutlineCBTy PostOutlineCB;
2349 BasicBlock *EntryBB, *ExitBB, *OuterAllocaBB;
2350 SmallVector<Value *, 2> ExcludeArgsFromAggregate;
2355 SmallVectorImpl<BasicBlock *> &BlockVector);
2362 SmallVector<OutlineInfo, 16> OutlineInfos;
2367 SmallVector<llvm::Function *, 16> ConstantAllocaRaiseCandidates;
2371 std::forward_list<CanonicalLoopInfo> LoopInfos;
2374 std::forward_list<ScanInfo> ScanInfos;
2377 void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
2384 StringMap<GlobalVariable *, BumpPtrAllocator> InternalVars;
2391 LLVM_ABI void emitBranch(BasicBlock *Target);
2396 LLVM_ABI void emitBlock(BasicBlock *BB, Function *CurFn,
2397 bool IsFinished =
false);
2409 BodyGenCallbackTy ElseGen,
2410 InsertPointTy AllocaIP = {});
2414 createOffloadMaptypes(SmallVectorImpl<uint64_t> &Mappings,
2415 std::string VarName);
2419 createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
2420 std::string VarName);
2422 struct MapperAllocas {
2423 AllocaInst *ArgsBase =
nullptr;
2424 AllocaInst *
Args =
nullptr;
2425 AllocaInst *ArgSizes =
nullptr;
2429 LLVM_ABI void createMapperAllocas(
const LocationDescription &Loc,
2430 InsertPointTy AllocaIP,
2431 unsigned NumOperands,
2432 struct MapperAllocas &MapperAllocas);
2443 LLVM_ABI void emitMapperCall(
const LocationDescription &Loc,
2444 Function *MapperFunc,
Value *SrcLocInfo,
2446 struct MapperAllocas &MapperAllocas,
2447 int64_t DeviceID,
unsigned NumOperands);
2450 struct TargetDataRTArgs {
2452 Value *BasePointersArray =
nullptr;
2454 Value *PointersArray =
nullptr;
2456 Value *SizesArray =
nullptr;
2460 Value *MapTypesArray =
nullptr;
2464 Value *MapTypesArrayEnd =
nullptr;
2466 Value *MappersArray =
nullptr;
2469 Value *MapNamesArray =
nullptr;
2471 explicit TargetDataRTArgs() =
default;
2472 explicit TargetDataRTArgs(
Value *BasePointersArray,
Value *PointersArray,
2474 Value *MapTypesArrayEnd,
Value *MappersArray,
2475 Value *MapNamesArray)
2476 : BasePointersArray(BasePointersArray), PointersArray(PointersArray),
2477 SizesArray(SizesArray), MapTypesArray(MapTypesArray),
2478 MapTypesArrayEnd(MapTypesArrayEnd), MappersArray(MappersArray),
2479 MapNamesArray(MapNamesArray) {}
2489 struct TargetKernelDefaultAttrs {
2490 omp::OMPTgtExecModeFlags ExecFlags =
2491 omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
2492 SmallVector<int32_t, 3> MaxTeams = {-1};
2493 int32_t MinTeams = 1;
2495 int32_t MinThreads = 1;
2496 int32_t ReductionDataSize = 0;
2497 int32_t ReductionBufferLength = 0;
2505 struct TargetKernelRuntimeAttrs {
2506 SmallVector<Value *, 3> MaxTeams = {
nullptr};
2507 Value *MinTeams =
nullptr;
2508 SmallVector<Value *, 3> TargetThreadLimit = {
nullptr};
2509 SmallVector<Value *, 3> TeamsThreadLimit = {
nullptr};
2517 Value *LoopTripCount =
nullptr;
2522 struct TargetKernelArgs {
2524 unsigned NumTargetItems = 0;
2526 TargetDataRTArgs RTArgs;
2528 Value *NumIterations =
nullptr;
2530 ArrayRef<Value *> NumTeams;
2532 ArrayRef<Value *> NumThreads;
2534 Value *DynCGroupMem =
nullptr;
2536 bool HasNoWait =
false;
2538 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback =
2539 omp::OMPDynGroupprivateFallbackType::Abort;
2542 TargetKernelArgs() =
default;
2543 TargetKernelArgs(
unsigned NumTargetItems, TargetDataRTArgs RTArgs,
2544 Value *NumIterations, ArrayRef<Value *> NumTeams,
2545 ArrayRef<Value *> NumThreads,
Value *DynCGroupMem,
2547 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback)
2548 : NumTargetItems(NumTargetItems), RTArgs(RTArgs),
2549 NumIterations(NumIterations), NumTeams(NumTeams),
2550 NumThreads(NumThreads), DynCGroupMem(DynCGroupMem),
2551 HasNoWait(HasNoWait), DynCGroupMemFallback(DynCGroupMemFallback) {}
2557 LLVM_ABI static void getKernelArgsVector(TargetKernelArgs &KernelArgs,
2558 IRBuilderBase &Builder,
2559 SmallVector<Value *> &ArgsVector);
2563 class TargetDataInfo {
2565 bool RequiresDevicePointerInfo =
false;
2568 bool SeparateBeginEndCalls =
false;
2571 TargetDataRTArgs RTArgs;
2573 SmallMapVector<const Value *, std::pair<Value *, Value *>, 4>
2577 bool HasMapper =
false;
2579 unsigned NumberOfPtrs = 0
u;
2581 bool EmitDebug =
false;
2584 bool HasNoWait =
false;
2586 explicit TargetDataInfo() =
default;
2587 explicit TargetDataInfo(
bool RequiresDevicePointerInfo,
2588 bool SeparateBeginEndCalls)
2589 : RequiresDevicePointerInfo(RequiresDevicePointerInfo),
2590 SeparateBeginEndCalls(SeparateBeginEndCalls) {}
2592 void clearArrayInfo() {
2593 RTArgs = TargetDataRTArgs();
2599 return RTArgs.BasePointersArray && RTArgs.PointersArray &&
2600 RTArgs.SizesArray && RTArgs.MapTypesArray &&
2601 (!HasMapper || RTArgs.MappersArray) && NumberOfPtrs;
2603 bool requiresDevicePointerInfo() {
return RequiresDevicePointerInfo; }
2604 bool separateBeginEndCalls() {
return SeparateBeginEndCalls; }
2608 using MapValuesArrayTy = SmallVector<Value *, 4>;
2609 using MapDeviceInfoArrayTy = SmallVector<DeviceInfoTy, 4>;
2610 using MapFlagsArrayTy = SmallVector<omp::OpenMPOffloadMappingFlags, 4>;
2611 using MapNamesArrayTy = SmallVector<Constant *, 4>;
2612 using MapDimArrayTy = SmallVector<uint64_t, 4>;
2613 using MapNonContiguousArrayTy = SmallVector<MapValuesArrayTy, 4>;
2619 struct StructNonContiguousInfo {
2620 bool IsNonContiguous =
false;
2622 MapNonContiguousArrayTy
Offsets;
2623 MapNonContiguousArrayTy Counts;
2624 MapNonContiguousArrayTy Strides;
2626 MapValuesArrayTy BasePointers;
2627 MapValuesArrayTy Pointers;
2628 MapDeviceInfoArrayTy DevicePointers;
2629 MapValuesArrayTy
Sizes;
2630 MapFlagsArrayTy
Types;
2631 MapNamesArrayTy Names;
2632 StructNonContiguousInfo NonContigInfo;
2635 void append(MapInfosTy &CurInfo) {
2636 BasePointers.append(CurInfo.BasePointers.begin(),
2637 CurInfo.BasePointers.end());
2638 Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
2639 DevicePointers.append(CurInfo.DevicePointers.begin(),
2640 CurInfo.DevicePointers.end());
2641 Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
2642 Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
2643 Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
2644 NonContigInfo.Dims.append(CurInfo.NonContigInfo.Dims.begin(),
2645 CurInfo.NonContigInfo.Dims.end());
2646 NonContigInfo.Offsets.append(CurInfo.NonContigInfo.Offsets.begin(),
2647 CurInfo.NonContigInfo.Offsets.end());
2648 NonContigInfo.Counts.append(CurInfo.NonContigInfo.Counts.begin(),
2649 CurInfo.NonContigInfo.Counts.end());
2650 NonContigInfo.Strides.append(CurInfo.NonContigInfo.Strides.begin(),
2651 CurInfo.NonContigInfo.Strides.end());
2654 using MapInfosOrErrorTy = Expected<MapInfosTy &>;
2660 using EmitFallbackCallbackTy =
2661 function_ref<InsertPointOrErrorTy(InsertPointTy)>;
2665 using CustomMapperCallbackTy =
2666 function_ref<Expected<Function *>(
unsigned int)>;
2678 LLVM_ABI InsertPointOrErrorTy emitKernelLaunch(
2679 const LocationDescription &Loc,
Value *OutlinedFnID,
2680 EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args,
2681 Value *DeviceID,
Value *RTLoc, InsertPointTy AllocaIP);
2693 using TargetTaskBodyCallbackTy =
2695 IRBuilderBase::InsertPoint TargetTaskAllocaIP)>;
2707 LLVM_ABI InsertPointOrErrorTy emitTargetTask(
2708 TargetTaskBodyCallbackTy TaskBodyCB,
Value *DeviceID,
Value *RTLoc,
2709 OpenMPIRBuilder::InsertPointTy AllocaIP,
2710 const SmallVector<llvm::OpenMPIRBuilder::DependData> &Dependencies,
2711 const TargetDataRTArgs &RTArgs,
bool HasNoWait);
2717 LLVM_ABI void emitOffloadingArraysArgument(
2718 IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs,
2719 OpenMPIRBuilder::TargetDataInfo &
Info,
bool ForEndCall =
false);
2722 LLVM_ABI void emitNonContiguousDescriptor(InsertPointTy AllocaIP,
2723 InsertPointTy CodeGenIP,
2724 MapInfosTy &CombinedInfo,
2725 TargetDataInfo &
Info);
2733 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
2734 TargetDataInfo &
Info, CustomMapperCallbackTy CustomMapperCB,
2735 bool IsNonContiguous =
false,
2736 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2745 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &
Info,
2746 TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
2747 CustomMapperCallbackTy CustomMapperCB,
bool IsNonContiguous =
false,
2748 bool ForEndCall =
false,
2749 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2753 LLVM_ABI void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t
Size,
2754 int32_t Flags, GlobalValue::LinkageTypes,
2755 StringRef Name =
"");
2759 enum EmitMetadataErrorKind {
2760 EMIT_MD_TARGET_REGION_ERROR,
2761 EMIT_MD_DECLARE_TARGET_ERROR,
2762 EMIT_MD_GLOBAL_VAR_LINK_ERROR
2766 using EmitMetadataErrorReportFunctionTy =
2767 std::function<void(EmitMetadataErrorKind, TargetRegionEntryInfo)>;
2776 LLVM_ABI void createOffloadEntriesAndInfoMetadata(
2777 EmitMetadataErrorReportFunctionTy &ErrorReportFunction);
2790 LLVM_ABI InsertPointTy createCopyPrivate(
const LocationDescription &Loc,
2807 createSingle(
const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2808 FinalizeCallbackTy FiniCB,
bool IsNowait,
2809 ArrayRef<llvm::Value *> CPVars = {},
2810 ArrayRef<llvm::Function *> CPFuncs = {});
2819 LLVM_ABI InsertPointOrErrorTy createMaster(
const LocationDescription &Loc,
2820 BodyGenCallbackTy BodyGenCB,
2821 FinalizeCallbackTy FiniCB);
2830 LLVM_ABI InsertPointOrErrorTy createMasked(
const LocationDescription &Loc,
2831 BodyGenCallbackTy BodyGenCB,
2832 FinalizeCallbackTy FiniCB,
2853 LLVM_ABI InsertPointOrErrorTy emitScanReduction(
2854 const LocationDescription &Loc,
2855 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
2856 ScanInfo *ScanRedInfo);
2871 LLVM_ABI InsertPointOrErrorTy createScan(
const LocationDescription &Loc,
2872 InsertPointTy AllocaIP,
2873 ArrayRef<llvm::Value *> ScanVars,
2874 ArrayRef<llvm::Type *> ScanVarsType,
2876 ScanInfo *ScanRedInfo);
2887 LLVM_ABI InsertPointOrErrorTy createCritical(
const LocationDescription &Loc,
2888 BodyGenCallbackTy BodyGenCB,
2889 FinalizeCallbackTy FiniCB,
2890 StringRef CriticalName,
2904 createOrderedDepend(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2905 unsigned NumLoops, ArrayRef<llvm::Value *> StoreValues,
2906 const Twine &Name,
bool IsDependSource);
2917 LLVM_ABI InsertPointOrErrorTy createOrderedThreadsSimd(
2918 const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2919 FinalizeCallbackTy FiniCB,
bool IsThreads);
2933 createSections(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2934 ArrayRef<StorableBodyGenCallbackTy> SectionCBs,
2935 PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB,
2936 bool IsCancellable,
bool IsNowait);
2944 LLVM_ABI InsertPointOrErrorTy createSection(
const LocationDescription &Loc,
2945 BodyGenCallbackTy BodyGenCB,
2946 FinalizeCallbackTy FiniCB);
2960 LLVM_ABI InsertPointOrErrorTy createTeams(
const LocationDescription &Loc,
2961 BodyGenCallbackTy BodyGenCB,
2962 Value *NumTeamsLower =
nullptr,
2963 Value *NumTeamsUpper =
nullptr,
2964 Value *ThreadLimit =
nullptr,
2965 Value *IfExpr =
nullptr);
2972 LLVM_ABI InsertPointOrErrorTy createDistribute(
const LocationDescription &Loc,
2973 InsertPointTy AllocaIP,
2974 BodyGenCallbackTy BodyGenCB);
2988 LLVM_ABI InsertPointTy createCopyinClauseBlocks(InsertPointTy IP,
2991 llvm::IntegerType *IntPtrTy,
2992 bool BranchtoEnd =
true);
3013 LLVM_ABI CallInst *createOMPFree(
const LocationDescription &Loc,
Value *Addr,
3025 createCachedThreadPrivate(
const LocationDescription &Loc,
3027 const llvm::Twine &Name = Twine(
""));
3040 LLVM_ABI CallInst *createOMPInteropInit(
const LocationDescription &Loc,
3042 omp::OMPInteropType InteropType,
3044 Value *DependenceAddress,
3045 bool HaveNowaitClause);
3057 LLVM_ABI CallInst *createOMPInteropDestroy(
const LocationDescription &Loc,
3059 Value *NumDependences,
3060 Value *DependenceAddress,
3061 bool HaveNowaitClause);
3073 LLVM_ABI CallInst *createOMPInteropUse(
const LocationDescription &Loc,
3075 Value *NumDependences,
3076 Value *DependenceAddress,
3077 bool HaveNowaitClause);
3091 LLVM_ABI InsertPointTy createTargetInit(
3092 const LocationDescription &Loc,
3093 const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
3102 LLVM_ABI void createTargetDeinit(
const LocationDescription &Loc,
3103 int32_t TeamsReductionDataSize = 0,
3104 int32_t TeamsReductionBufferLength = 1024);
3114 LLVM_ABI static std::pair<int32_t, int32_t>
3115 readThreadBoundsForKernel(
const Triple &
T, Function &Kernel);
3116 LLVM_ABI static void writeThreadBoundsForKernel(
const Triple &
T,
3117 Function &Kernel, int32_t LB,
3122 LLVM_ABI static std::pair<int32_t, int32_t>
3123 readTeamBoundsForKernel(
const Triple &
T, Function &Kernel);
3124 LLVM_ABI static void writeTeamsForKernel(
const Triple &
T, Function &Kernel,
3125 int32_t LB, int32_t UB);
3130 void setOutlinedTargetRegionFunctionAttributes(Function *OutlinedFn);
3135 Constant *createOutlinedFunctionID(Function *OutlinedFn,
3136 StringRef EntryFnIDName);
3139 Constant *createTargetRegionEntryAddr(Function *OutlinedFunction,
3140 StringRef EntryFnName);
3144 using FunctionGenCallback =
3145 std::function<Expected<Function *>(StringRef FunctionName)>;
3179 TargetRegionEntryInfo &EntryInfo,
3180 FunctionGenCallback &GenerateFunctionCallback,
bool IsOffloadEntry,
3181 Function *&OutlinedFn, Constant *&OutlinedFnID);
3192 registerTargetRegionFunction(TargetRegionEntryInfo &EntryInfo,
3193 Function *OutlinedFunction,
3194 StringRef EntryFnName, StringRef EntryFnIDName);
3207 enum BodyGenTy { Priv, DupNoPriv, NoPriv };
3212 using GenMapInfoCallbackTy =
3213 function_ref<MapInfosTy &(InsertPointTy CodeGenIP)>;
3222 void emitUDMapperArrayInitOrDel(Function *MapperFn,
llvm::Value *MapperHandle,
3226 llvm::BasicBlock *ExitBB,
bool IsInit);
3269 LLVM_ABI Expected<Function *> emitUserDefinedMapper(
3270 function_ref<MapInfosOrErrorTy(
3272 PrivAndGenMapInfoCB,
3273 llvm::Type *ElemTy, StringRef FuncName,
3274 CustomMapperCallbackTy CustomMapperCB);
3293 LLVM_ABI InsertPointOrErrorTy createTargetData(
3294 const LocationDescription &Loc, InsertPointTy AllocaIP,
3295 InsertPointTy CodeGenIP,
Value *DeviceID,
Value *IfCond,
3296 TargetDataInfo &
Info, GenMapInfoCallbackTy GenMapInfoCB,
3297 CustomMapperCallbackTy CustomMapperCB,
3298 omp::RuntimeFunction *MapperFunc =
nullptr,
3299 function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
3300 BodyGenTy BodyGenType)>
3301 BodyGenCB =
nullptr,
3302 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr,
3303 Value *SrcLocInfo =
nullptr);
3305 using TargetBodyGenCallbackTy = function_ref<InsertPointOrErrorTy(
3306 InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
3308 using TargetGenArgAccessorsCallbackTy = function_ref<InsertPointOrErrorTy(
3309 Argument &Arg,
Value *Input,
Value *&RetVal, InsertPointTy AllocaIP,
3310 InsertPointTy CodeGenIP)>;
3340 LLVM_ABI InsertPointOrErrorTy createTarget(
3341 const LocationDescription &Loc,
bool IsOffloadEntry,
3342 OpenMPIRBuilder::InsertPointTy AllocaIP,
3343 OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetDataInfo &
Info,
3344 TargetRegionEntryInfo &EntryInfo,
3345 const TargetKernelDefaultAttrs &DefaultAttrs,
3346 const TargetKernelRuntimeAttrs &RuntimeAttrs,
Value *IfCond,
3347 SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
3348 TargetBodyGenCallbackTy BodyGenCB,
3349 TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
3350 CustomMapperCallbackTy CustomMapperCB,
3351 const SmallVector<DependData> &Dependencies,
bool HasNowait =
false,
3352 Value *DynCGroupMem =
nullptr,
3353 omp::OMPDynGroupprivateFallbackType DynCGroupMemFallback =
3354 omp::OMPDynGroupprivateFallbackType::Abort);
3359 LLVM_ABI FunctionCallee createForStaticInitFunction(
unsigned IVSize,
3361 bool IsGPUDistribute);
3365 LLVM_ABI FunctionCallee createDispatchInitFunction(
unsigned IVSize,
3370 LLVM_ABI FunctionCallee createDispatchNextFunction(
unsigned IVSize,
3375 LLVM_ABI FunctionCallee createDispatchFiniFunction(
unsigned IVSize,
3379 LLVM_ABI FunctionCallee createDispatchDeinitFunction();
3387#define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
3388#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
3389 ArrayType *VarName##Ty = nullptr; \
3390 PointerType *VarName##PtrTy = nullptr;
3391#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
3392 FunctionType *VarName = nullptr; \
3393 PointerType *VarName##Ptr = nullptr;
3394#define OMP_STRUCT_TYPE(VarName, StrName, ...) \
3395 StructType *VarName = nullptr; \
3396 PointerType *VarName##Ptr = nullptr;
3397#include "llvm/Frontend/OpenMP/OMPKinds.def"
3404 void initializeTypes(
Module &M);
3418 InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD,
Value *EntryCall,
3420 bool Conditional =
false);
3433 InsertPointOrErrorTy emitCommonDirectiveExit(omp::Directive OMPD,
3434 InsertPointTy FinIP,
3435 Instruction *ExitCall,
3436 bool HasFinalize =
true);
3454 InsertPointOrErrorTy
3455 EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
3456 Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
3457 FinalizeCallbackTy FiniCB,
bool Conditional =
false,
3458 bool HasFinalize =
true,
bool IsCancellable =
false);
3466 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
3467 StringRef FirstSeparator,
3468 StringRef Separator);
3475 Value *getOMPCriticalRegionLock(StringRef CriticalName);
3489 using AtomicUpdateCallbackTy =
3490 const function_ref<Expected<Value *>(
Value *XOld, IRBuilder<> &IRB)>;
3502 bool checkAndEmitFlushAfterAtomic(
const LocationDescription &Loc,
3503 AtomicOrdering AO, AtomicKind AK);
3529 Expected<std::pair<Value *, Value *>>
3530 emitAtomicUpdate(InsertPointTy AllocaIP,
Value *
X,
Type *XElemTy,
Value *Expr,
3531 AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3532 AtomicUpdateCallbackTy &UpdateOp,
bool VolatileX,
3533 bool IsXBinopExpr,
bool IsIgnoreDenormalMode,
3534 bool IsFineGrainedMemory,
bool IsRemoteMemory);
3540 AtomicRMWInst::BinOp RMWOp);
3546 struct AtomicOpValue {
3547 Value *Var =
nullptr;
3548 Type *ElemTy =
nullptr;
3549 bool IsSigned =
false;
3564 LLVM_ABI InsertPointTy createAtomicRead(
const LocationDescription &Loc,
3565 AtomicOpValue &
X, AtomicOpValue &V,
3567 InsertPointTy AllocaIP);
3579 LLVM_ABI InsertPointTy createAtomicWrite(
const LocationDescription &Loc,
3580 AtomicOpValue &
X,
Value *Expr,
3582 InsertPointTy AllocaIP);
3604 LLVM_ABI InsertPointOrErrorTy createAtomicUpdate(
3605 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3606 Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3607 AtomicUpdateCallbackTy &UpdateOp,
bool IsXBinopExpr,
3608 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3609 bool IsRemoteMemory =
false);
3640 LLVM_ABI InsertPointOrErrorTy createAtomicCapture(
3641 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3642 AtomicOpValue &V,
Value *Expr, AtomicOrdering AO,
3643 AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
3644 bool UpdateExpr,
bool IsPostfixUpdate,
bool IsXBinopExpr,
3645 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3646 bool IsRemoteMemory =
false);
3694 createAtomicCompare(
const LocationDescription &Loc, AtomicOpValue &
X,
3695 AtomicOpValue &V, AtomicOpValue &R,
Value *
E,
Value *
D,
3696 AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
3697 bool IsXBinopExpr,
bool IsPostfixUpdate,
bool IsFailOnly);
3698 LLVM_ABI InsertPointTy createAtomicCompare(
3699 const LocationDescription &Loc, AtomicOpValue &
X, AtomicOpValue &V,
3700 AtomicOpValue &R,
Value *
E,
Value *
D, AtomicOrdering AO,
3701 omp::OMPAtomicCompareOp Op,
bool IsXBinopExpr,
bool IsPostfixUpdate,
3702 bool IsFailOnly, AtomicOrdering Failure);
3720 LLVM_ABI CanonicalLoopInfo *createLoopSkeleton(DebugLoc
DL,
Value *TripCount,
3722 BasicBlock *PreInsertBefore,
3723 BasicBlock *PostInsertBefore,
3724 const Twine &Name = {});
3726 const std::string ompOffloadInfoName =
"omp_offload.info";
3743 LLVM_ABI void loadOffloadInfoMetadata(vfs::FileSystem &VFS,
3744 StringRef HostFilePath);
3753 getOrCreateInternalVariable(
Type *Ty,
const StringRef &Name,
3754 std::optional<unsigned> AddressSpace = {});
3855class CanonicalLoopInfo {
3856 friend class OpenMPIRBuilder;
3865 Value *LastIter =
nullptr;
3875 void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
3880 void setTripCount(
Value *TripCount);
3896 void mapIndVar(llvm::function_ref<
Value *(Instruction *)> Updater);
3900 void setLastIter(
Value *IterVar) { LastIter = std::move(IterVar); }
3909 Value *getLastIter() {
return LastIter; }
3914 bool isValid()
const {
return Header; }
3941 return cast<BranchInst>(
Cond->getTerminator())->getSuccessor(0);
3965 return Exit->getSingleSuccessor();
3971 Value *getTripCount()
const {
3974 assert(isa<CmpInst>(CmpI) &&
"First inst must compare IV with TripCount");
3975 return CmpI->getOperand(1);
3983 assert(isa<PHINode>(IndVarPHI) &&
"First inst must be the IV PHI");
3988 Type *getIndVarType()
const {
3990 return getIndVar()->getType();
3994 OpenMPIRBuilder::InsertPointTy getPreheaderIP()
const {
3997 return {Preheader, std::prev(Preheader->end())};
4001 OpenMPIRBuilder::InsertPointTy getBodyIP()
const {
4004 return {Body, Body->begin()};
4008 OpenMPIRBuilder::InsertPointTy getAfterIP()
const {
4011 return {After, After->begin()};
4016 return Header->getParent();
4074 llvm::BasicBlock *OMPBeforeScanBlock =
nullptr;
4077 llvm::BasicBlock *OMPAfterScanBlock =
nullptr;
4080 llvm::BasicBlock *OMPScanDispatch =
nullptr;
4083 llvm::BasicBlock *OMPScanLoopExit =
nullptr;
4086 llvm::BasicBlock *OMPScanInit =
nullptr;
4089 llvm::BasicBlock *OMPScanFinish =
nullptr;
4093 bool OMPFirstScanLoop =
false;
4097 llvm::SmallDenseMap<llvm::Value *, llvm::Value *> *ScanBuffPtrs;
4108 ScanBuffPtrs =
new llvm::SmallDenseMap<llvm::Value *, llvm::Value *>();
4110 ScanInfo(ScanInfo &) =
delete;
4111 ScanInfo &operator=(
const ScanInfo &) =
delete;
4113 ~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.