14#ifndef LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
15#define LLVM_FRONTEND_OPENMP_OMPIRBUILDER_H
28#include <forward_list>
33class CanonicalLoopInfo;
35struct TargetRegionEntryInfo;
36class OffloadEntriesInfoManager;
102class OpenMPIRBuilderConfig {
108 std::optional<bool> IsTargetDevice;
118 std::optional<bool> IsGPU;
121 std::optional<bool> EmitLLVMUsedMetaInfo;
124 std::optional<bool> OpenMPOffloadMandatory;
127 std::optional<StringRef> FirstSeparator;
129 std::optional<StringRef> Separator;
132 std::optional<omp::GV> GridValue;
136 SmallVector<Triple> TargetTriples;
139 unsigned DefaultTargetAS = 0;
142 LLVM_ABI OpenMPIRBuilderConfig(
bool IsTargetDevice,
bool IsGPU,
143 bool OpenMPOffloadMandatory,
144 bool HasRequiresReverseOffload,
145 bool HasRequiresUnifiedAddress,
146 bool HasRequiresUnifiedSharedMemory,
147 bool HasRequiresDynamicAllocators);
150 bool isTargetDevice()
const {
151 assert(IsTargetDevice.has_value() &&
"IsTargetDevice is not set");
152 return *IsTargetDevice;
156 assert(IsGPU.has_value() &&
"IsGPU is not set");
160 bool openMPOffloadMandatory()
const {
161 assert(OpenMPOffloadMandatory.has_value() &&
162 "OpenMPOffloadMandatory is not set");
163 return *OpenMPOffloadMandatory;
167 assert(GridValue.has_value() &&
"GridValue is not set");
171 unsigned getDefaultTargetAS()
const {
return DefaultTargetAS; }
173 bool hasRequiresFlags()
const {
return RequiresFlags; }
174 LLVM_ABI bool hasRequiresReverseOffload()
const;
175 LLVM_ABI bool hasRequiresUnifiedAddress()
const;
176 LLVM_ABI bool hasRequiresUnifiedSharedMemory()
const;
177 LLVM_ABI bool hasRequiresDynamicAllocators()
const;
181 LLVM_ABI int64_t getRequiresFlags()
const;
185 StringRef firstSeparator()
const {
186 if (FirstSeparator.has_value())
187 return *FirstSeparator;
195 StringRef separator()
const {
196 if (Separator.has_value())
203 void setIsTargetDevice(
bool Value) { IsTargetDevice =
Value; }
205 void setEmitLLVMUsed(
bool Value =
true) { EmitLLVMUsedMetaInfo =
Value; }
206 void setOpenMPOffloadMandatory(
bool Value) { OpenMPOffloadMandatory =
Value; }
207 void setFirstSeparator(StringRef FS) { FirstSeparator =
FS; }
208 void setSeparator(StringRef S) { Separator = S; }
209 void setGridValue(omp::GV
G) { GridValue =
G; }
210 void setDefaultTargetAS(
unsigned AS) { DefaultTargetAS = AS; }
219 int64_t RequiresFlags;
224struct TargetRegionEntryInfo {
226 static constexpr const char *KernelNamePrefix =
"__omp_offloading_";
228 std::string ParentName;
234 TargetRegionEntryInfo() : DeviceID(0), FileID(0),
Line(0),
Count(0) {}
235 TargetRegionEntryInfo(StringRef ParentName,
unsigned DeviceID,
236 unsigned FileID,
unsigned Line,
unsigned Count = 0)
237 : ParentName(ParentName), DeviceID(DeviceID), FileID(FileID),
Line(
Line),
241 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name, StringRef ParentName,
242 unsigned DeviceID,
unsigned FileID,
unsigned Line,
245 bool operator<(
const TargetRegionEntryInfo &
RHS)
const {
246 return std::make_tuple(ParentName, DeviceID, FileID, Line, Count) <
247 std::make_tuple(
RHS.ParentName,
RHS.DeviceID,
RHS.FileID,
RHS.Line,
253class OffloadEntriesInfoManager {
255 OpenMPIRBuilder *OMPBuilder;
256 unsigned OffloadingEntriesNum = 0;
260 class OffloadEntryInfo {
263 enum OffloadingEntryInfoKinds :
unsigned {
265 OffloadingEntryInfoTargetRegion = 0,
267 OffloadingEntryInfoDeviceGlobalVar = 1,
269 OffloadingEntryInfoInvalid = ~0
u
273 OffloadEntryInfo() =
delete;
274 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind) :
Kind(
Kind) {}
275 explicit OffloadEntryInfo(OffloadingEntryInfoKinds Kind,
unsigned Order,
278 ~OffloadEntryInfo() =
default;
281 bool isValid()
const {
return Order != ~0
u; }
282 unsigned getOrder()
const {
return Order; }
283 OffloadingEntryInfoKinds getKind()
const {
return Kind; }
285 void setFlags(uint32_t NewFlags) {
Flags = NewFlags; }
286 Constant *getAddress()
const {
return cast_or_null<Constant>(Addr); }
287 void setAddress(Constant *V) {
288 assert(!Addr.pointsToAliveValue() &&
"Address has been set before!");
291 static bool classof(
const OffloadEntryInfo *
Info) {
return true; }
301 unsigned Order = ~0
u;
303 OffloadingEntryInfoKinds
Kind = OffloadingEntryInfoInvalid;
309 unsigned size()
const {
return OffloadingEntriesNum; }
311 OffloadEntriesInfoManager(OpenMPIRBuilder *builder) : OMPBuilder(builder) {}
318 enum OMPTargetRegionEntryKind : uint32_t {
320 OMPTargetRegionEntryTargetRegion = 0x0,
324 class OffloadEntryInfoTargetRegion final :
public OffloadEntryInfo {
329 OffloadEntryInfoTargetRegion()
330 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion) {}
331 explicit OffloadEntryInfoTargetRegion(
unsigned Order, Constant *Addr,
333 OMPTargetRegionEntryKind Flags)
334 : OffloadEntryInfo(OffloadingEntryInfoTargetRegion, Order,
Flags),
340 void setID(Constant *V) {
341 assert(!ID &&
"ID has been set before!");
344 static bool classof(
const OffloadEntryInfo *
Info) {
345 return Info->getKind() == OffloadingEntryInfoTargetRegion;
352 initializeTargetRegionEntryInfo(
const TargetRegionEntryInfo &EntryInfo,
355 LLVM_ABI void registerTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
356 Constant *Addr, Constant *ID,
357 OMPTargetRegionEntryKind Flags);
360 LLVM_ABI bool hasTargetRegionEntryInfo(TargetRegionEntryInfo EntryInfo,
361 bool IgnoreAddressId =
false)
const;
365 getTargetRegionEntryFnName(SmallVectorImpl<char> &Name,
366 const TargetRegionEntryInfo &EntryInfo);
369 typedef function_ref<void(
const TargetRegionEntryInfo &EntryInfo,
370 const OffloadEntryInfoTargetRegion &)>
371 OffloadTargetRegionEntryInfoActTy;
373 actOnTargetRegionEntriesInfo(
const OffloadTargetRegionEntryInfoActTy &Action);
380 enum OMPTargetGlobalVarEntryKind : uint32_t {
382 OMPTargetGlobalVarEntryTo = 0x0,
384 OMPTargetGlobalVarEntryLink = 0x1,
386 OMPTargetGlobalVarEntryEnter = 0x2,
388 OMPTargetGlobalVarEntryNone = 0x3,
390 OMPTargetGlobalVarEntryIndirect = 0x8,
392 OMPTargetGlobalRegisterRequires = 0x10,
400 enum OMPTargetDeviceClauseKind : uint32_t {
402 OMPTargetDeviceClauseAny = 0x0,
404 OMPTargetDeviceClauseNoHost = 0x1,
406 OMPTargetDeviceClauseHost = 0x2,
408 OMPTargetDeviceClauseNone = 0x3
412 class OffloadEntryInfoDeviceGlobalVar final :
public OffloadEntryInfo {
415 GlobalValue::LinkageTypes
Linkage;
419 OffloadEntryInfoDeviceGlobalVar()
420 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar) {}
421 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order,
422 OMPTargetGlobalVarEntryKind Flags)
423 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags) {}
424 explicit OffloadEntryInfoDeviceGlobalVar(
unsigned Order, Constant *Addr,
426 OMPTargetGlobalVarEntryKind Flags,
427 GlobalValue::LinkageTypes
Linkage,
428 const std::string &VarName)
429 : OffloadEntryInfo(OffloadingEntryInfoDeviceGlobalVar, Order,
Flags),
434 int64_t getVarSize()
const {
return VarSize; }
436 void setVarSize(int64_t
Size) { VarSize =
Size; }
437 GlobalValue::LinkageTypes getLinkage()
const {
return Linkage; }
438 void setLinkage(GlobalValue::LinkageTypes LT) {
Linkage =
LT; }
439 static bool classof(
const OffloadEntryInfo *
Info) {
440 return Info->getKind() == OffloadingEntryInfoDeviceGlobalVar;
446 LLVM_ABI void initializeDeviceGlobalVarEntryInfo(
447 StringRef Name, OMPTargetGlobalVarEntryKind Flags,
unsigned Order);
450 LLVM_ABI void registerDeviceGlobalVarEntryInfo(
451 StringRef VarName, Constant *Addr, int64_t VarSize,
452 OMPTargetGlobalVarEntryKind Flags, GlobalValue::LinkageTypes
Linkage);
454 bool hasDeviceGlobalVarEntryInfo(StringRef VarName)
const {
455 return OffloadEntriesDeviceGlobalVar.count(VarName) > 0;
458 typedef function_ref<void(StringRef,
const OffloadEntryInfoDeviceGlobalVar &)>
459 OffloadDeviceGlobalVarEntryInfoActTy;
460 LLVM_ABI void actOnDeviceGlobalVarEntriesInfo(
461 const OffloadDeviceGlobalVarEntryInfoActTy &Action);
466 getTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo)
const;
470 incrementTargetRegionEntryInfoCount(
const TargetRegionEntryInfo &EntryInfo);
472 static TargetRegionEntryInfo
473 getTargetRegionEntryCountKey(
const TargetRegionEntryInfo &EntryInfo) {
474 return TargetRegionEntryInfo(EntryInfo.ParentName, EntryInfo.DeviceID,
475 EntryInfo.FileID, EntryInfo.Line, 0);
479 std::map<TargetRegionEntryInfo, unsigned> OffloadEntriesTargetRegionCount;
482 typedef std::map<TargetRegionEntryInfo, OffloadEntryInfoTargetRegion>
483 OffloadEntriesTargetRegionTy;
484 OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
487 typedef StringMap<OffloadEntryInfoDeviceGlobalVar>
488 OffloadEntriesDeviceGlobalVarTy;
489 OffloadEntriesDeviceGlobalVarTy OffloadEntriesDeviceGlobalVar;
495class OpenMPIRBuilder {
499 OpenMPIRBuilder(
Module &M)
501 T(
M.getTargetTriple()), IsFinalized(
false) {}
504 class AtomicInfo :
public llvm::AtomicInfo {
508 AtomicInfo(IRBuilder<> *Builder, llvm::Type *Ty, uint64_t AtomicSizeInBits,
509 uint64_t ValueSizeInBits, llvm::Align AtomicAlign,
510 llvm::Align ValueAlign,
bool UseLibcall,
511 IRBuilderBase::InsertPoint AllocaIP,
llvm::Value *AtomicVar)
512 : llvm::AtomicInfo(Builder, Ty, AtomicSizeInBits, ValueSizeInBits,
513 AtomicAlign, ValueAlign, UseLibcall, AllocaIP),
514 AtomicVar(AtomicVar) {}
516 llvm::Value *getAtomicPointer()
const override {
return AtomicVar; }
517 void decorateWithTBAA(llvm::Instruction *
I)
override {}
518 llvm::AllocaInst *CreateAlloca(llvm::Type *Ty,
519 const llvm::Twine &Name)
const override {
520 llvm::AllocaInst *allocaInst = Builder->CreateAlloca(Ty);
531 void setConfig(OpenMPIRBuilderConfig
C) { Config =
C; }
543 LLVM_ABI void addAttributes(omp::RuntimeFunction FnID, Function &Fn);
546 using InsertPointTy = IRBuilder<>::InsertPoint;
549 using InsertPointOrErrorTy = Expected<InsertPointTy>;
560 createPlatformSpecificName(ArrayRef<StringRef> Parts)
const;
570 using FinalizeCallbackTy = std::function<
Error(InsertPointTy CodeGenIP)>;
572 struct FinalizationInfo {
575 FinalizeCallbackTy FiniCB;
588 void pushFinalizationCB(
const FinalizationInfo &FI) {
589 FinalizationStack.push_back(FI);
595 void popFinalizationCB() { FinalizationStack.pop_back(); }
623 using BodyGenCallbackTy =
624 function_ref<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
632 using StorableBodyGenCallbackTy =
633 std::function<
Error(InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
645 using LoopBodyGenCallbackTy =
646 function_ref<
Error(InsertPointTy CodeGenIP,
Value *IndVar)>;
666 using PrivatizeCallbackTy = function_ref<InsertPointOrErrorTy(
667 InsertPointTy AllocaIP, InsertPointTy CodeGenIP,
Value &Original,
672 struct LocationDescription {
673 LocationDescription(
const IRBuilderBase &IRB)
674 : IP(IRB.saveIP()),
DL(IRB.getCurrentDebugLocation()) {}
675 LocationDescription(
const InsertPointTy &IP) : IP(IP) {}
676 LocationDescription(
const InsertPointTy &IP,
const DebugLoc &
DL)
696 LLVM_ABI InsertPointOrErrorTy createBarrier(
const LocationDescription &Loc,
698 bool ForceSimpleCall =
false,
699 bool CheckCancelFlag =
true);
708 LLVM_ABI InsertPointOrErrorTy createCancel(
const LocationDescription &Loc,
710 omp::Directive CanceledDirective);
718 LLVM_ABI InsertPointOrErrorTy createCancellationPoint(
719 const LocationDescription &Loc, omp::Directive CanceledDirective);
722 LLVM_ABI Expected<ScanInfo *> scanInfoInitialize();
737 LLVM_ABI InsertPointOrErrorTy createParallel(
738 const LocationDescription &Loc, InsertPointTy AllocaIP,
739 BodyGenCallbackTy BodyGenCB, PrivatizeCallbackTy PrivCB,
740 FinalizeCallbackTy FiniCB,
Value *IfCondition,
Value *NumThreads,
741 omp::ProcBindKind ProcBind,
bool IsCancellable);
762 LLVM_ABI Expected<CanonicalLoopInfo *>
763 createCanonicalLoop(
const LocationDescription &Loc,
764 LoopBodyGenCallbackTy BodyGenCB,
Value *TripCount,
765 const Twine &Name =
"loop");
798 LLVM_ABI Expected<SmallVector<llvm::CanonicalLoopInfo *>>
799 createCanonicalScanLoops(
const LocationDescription &Loc,
800 LoopBodyGenCallbackTy BodyGenCB,
Value *Start,
802 bool InclusiveStop, InsertPointTy ComputeIP,
803 const Twine &Name, ScanInfo *ScanRedInfo);
846 const LocationDescription &Loc,
Value *Start,
Value *Stop,
Value *Step,
847 bool IsSigned,
bool InclusiveStop,
const Twine &Name =
"loop");
879 LLVM_ABI Expected<CanonicalLoopInfo *> createCanonicalLoop(
880 const LocationDescription &Loc, LoopBodyGenCallbackTy BodyGenCB,
881 Value *Start,
Value *Stop,
Value *Step,
bool IsSigned,
bool InclusiveStop,
882 InsertPointTy ComputeIP = {},
const Twine &
Name =
"loop",
883 bool InScan =
false, ScanInfo *ScanRedInfo =
nullptr);
945 LLVM_ABI CanonicalLoopInfo *collapseLoops(DebugLoc
DL,
946 ArrayRef<CanonicalLoopInfo *>
Loops,
947 InsertPointTy ComputeIP);
954 getOpenMPDefaultSimdAlign(
const Triple &TargetTriple,
955 const StringMap<bool> &Features);
992 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
993 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
994 bool IsDeclaration,
bool IsExternallyVisible,
995 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
996 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
997 std::vector<Triple> TargetTriple,
Type *LlvmPtrTy,
998 std::function<Constant *()> GlobalInitializer,
999 std::function<GlobalValue::LinkageTypes()> VariableLinkage);
1035 LLVM_ABI void registerTargetGlobalVariable(
1036 OffloadEntriesInfoManager::OMPTargetGlobalVarEntryKind CaptureClause,
1037 OffloadEntriesInfoManager::OMPTargetDeviceClauseKind DeviceClause,
1038 bool IsDeclaration,
bool IsExternallyVisible,
1039 TargetRegionEntryInfo EntryInfo, StringRef MangledName,
1040 std::vector<GlobalVariable *> &GeneratedRefs,
bool OpenMPSIMD,
1041 std::vector<Triple> TargetTriple,
1042 std::function<Constant *()> GlobalInitializer,
1043 std::function<GlobalValue::LinkageTypes()> VariableLinkage,
1044 Type *LlvmPtrTy, Constant *Addr);
1047 LLVM_ABI unsigned getFlagMemberOffset();
1056 LLVM_ABI omp::OpenMPOffloadMappingFlags getMemberOfFlag(
unsigned Position);
1068 setCorrectMemberOfFlag(omp::OpenMPOffloadMappingFlags &Flags,
1069 omp::OpenMPOffloadMappingFlags MemberOfFlag);
1090 InsertPointTy applyWorkshareLoopTarget(DebugLoc
DL, CanonicalLoopInfo *CLI,
1091 InsertPointTy AllocaIP,
1092 omp::WorksharingLoopType LoopType);
1113 InsertPointOrErrorTy applyStaticWorkshareLoop(
1114 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1115 omp::WorksharingLoopType LoopType,
bool NeedsBarrier);
1130 InsertPointOrErrorTy applyStaticChunkedWorkshareLoop(DebugLoc
DL,
1131 CanonicalLoopInfo *CLI,
1132 InsertPointTy AllocaIP,
1156 InsertPointOrErrorTy applyDynamicWorkshareLoop(DebugLoc
DL,
1157 CanonicalLoopInfo *CLI,
1158 InsertPointTy AllocaIP,
1159 omp::OMPScheduleType SchedType,
1161 Value *Chunk =
nullptr);
1174 void createIfVersion(CanonicalLoopInfo *Loop,
Value *IfCond,
1175 ValueMap<const Value *, WeakTrackingVH> &VMap,
1176 LoopAnalysis &LIA, LoopInfo &LI, llvm::Loop *L,
1177 const Twine &NamePrefix =
"");
1214 LLVM_ABI InsertPointOrErrorTy applyWorkshareLoop(
1215 DebugLoc
DL, CanonicalLoopInfo *CLI, InsertPointTy AllocaIP,
1217 llvm::omp::ScheduleKind SchedKind = llvm::omp::OMP_SCHEDULE_Default,
1218 Value *ChunkSize =
nullptr,
bool HasSimdModifier =
false,
1219 bool HasMonotonicModifier =
false,
bool HasNonmonotonicModifier =
false,
1220 bool HasOrderedClause =
false,
1221 omp::WorksharingLoopType LoopType =
1222 omp::WorksharingLoopType::ForStaticLoop);
1267 LLVM_ABI std::vector<CanonicalLoopInfo *>
1268 tileLoops(DebugLoc
DL, ArrayRef<CanonicalLoopInfo *>
Loops,
1269 ArrayRef<Value *> TileSizes);
1279 LLVM_ABI void unrollLoopFull(DebugLoc
DL, CanonicalLoopInfo *Loop);
1286 LLVM_ABI void unrollLoopHeuristic(DebugLoc
DL, CanonicalLoopInfo *Loop);
1310 LLVM_ABI void unrollLoopPartial(DebugLoc
DL, CanonicalLoopInfo *Loop,
1312 CanonicalLoopInfo **UnrolledCLI);
1327 LLVM_ABI void applySimd(CanonicalLoopInfo *Loop,
1328 MapVector<Value *, Value *> AlignedVars,
1329 Value *IfCond, omp::OrderKind Order,
1330 ConstantInt *Simdlen, ConstantInt *Safelen);
1335 LLVM_ABI void createFlush(
const LocationDescription &Loc);
1340 LLVM_ABI void createTaskwait(
const LocationDescription &Loc);
1345 LLVM_ABI void createTaskyield(
const LocationDescription &Loc);
1349 omp::RTLDependenceKindTy DepKind = omp::RTLDependenceKindTy::DepUnknown;
1352 explicit DependData() =
default;
1353 DependData(omp::RTLDependenceKindTy DepKind,
Type *DepValueType,
1355 : DepKind(DepKind), DepValueType(DepValueType), DepVal(DepVal) {}
1378 createTask(
const LocationDescription &Loc, InsertPointTy AllocaIP,
1379 BodyGenCallbackTy BodyGenCB,
bool Tied =
true,
1380 Value *Final =
nullptr,
Value *IfCondition =
nullptr,
1381 SmallVector<DependData> Dependencies = {},
bool Mergeable =
false,
1382 Value *EventHandle =
nullptr,
Value *Priority =
nullptr);
1389 LLVM_ABI InsertPointOrErrorTy createTaskgroup(
const LocationDescription &Loc,
1390 InsertPointTy AllocaIP,
1391 BodyGenCallbackTy BodyGenCB);
1393 using FileIdentifierInfoCallbackTy =
1394 std::function<std::tuple<std::string, uint64_t>()>;
1403 LLVM_ABI static TargetRegionEntryInfo
1404 getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
1405 StringRef ParentName =
"");
1408 enum class ReductionGenCBKind { Clang, MLIR };
1420 using ReductionGenClangCBTy =
1421 std::function<InsertPointTy(InsertPointTy CodeGenIP,
unsigned Index,
1429 using ReductionGenCBTy = std::function<InsertPointOrErrorTy(
1436 using ReductionGenAtomicCBTy = std::function<InsertPointOrErrorTy(
1443 struct ReductionInfo {
1444 ReductionInfo(
Type *ElementType,
Value *Variable,
Value *PrivateVariable,
1445 EvalKind EvaluationKind, ReductionGenCBTy ReductionGen,
1446 ReductionGenClangCBTy ReductionGenClang,
1447 ReductionGenAtomicCBTy AtomicReductionGen)
1449 PrivateVariable(PrivateVariable), EvaluationKind(EvaluationKind),
1450 ReductionGen(ReductionGen), ReductionGenClang(ReductionGenClang),
1451 AtomicReductionGen(AtomicReductionGen) {}
1452 ReductionInfo(
Value *PrivateVariable)
1454 PrivateVariable(PrivateVariable), EvaluationKind(EvalKind::
Scalar),
1455 ReductionGen(), ReductionGenClang(), AtomicReductionGen() {}
1464 Value *PrivateVariable;
1467 EvalKind EvaluationKind;
1472 ReductionGenCBTy ReductionGen;
1477 ReductionGenClangCBTy ReductionGenClang;
1483 ReductionGenAtomicCBTy AtomicReductionGen;
1486 enum class CopyAction :
unsigned {
1494 struct CopyOptionsTy {
1495 Value *RemoteLaneOffset =
nullptr;
1496 Value *ScratchpadIndex =
nullptr;
1497 Value *ScratchpadWidth =
nullptr;
1503 Value *getGPUThreadID();
1506 Value *getGPUWarpSize();
1511 Value *getNVPTXWarpID();
1516 Value *getNVPTXLaneID();
1519 Value *castValueToType(InsertPointTy AllocaIP,
Value *From,
Type *ToType);
1523 Value *createRuntimeShuffleFunction(InsertPointTy AllocaIP,
Value *Element,
1527 void shuffleAndStore(InsertPointTy AllocaIP,
Value *SrcAddr,
Value *DstAddr,
1529 Type *ReductionArrayTy);
1533 void emitReductionListCopy(
1534 InsertPointTy AllocaIP, CopyAction Action,
Type *ReductionArrayTy,
1535 ArrayRef<ReductionInfo> ReductionInfos,
Value *SrcBase,
Value *DestBase,
1536 CopyOptionsTy CopyOptions = {
nullptr,
nullptr,
nullptr});
1611 Function *emitShuffleAndReduceFunction(
1612 ArrayRef<OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1613 Function *ReduceFn, AttributeList FuncAttrs);
1623 Error emitScanBasedDirectiveIR(
1624 llvm::function_ref<
Error()> InputLoopGen,
1625 llvm::function_ref<
Error(LocationDescription Loc)> ScanLoopGen,
1626 ScanInfo *ScanRedInfo);
1631 void createScanBBs(ScanInfo *ScanRedInfo);
1641 Error emitScanBasedDirectiveDeclsIR(InsertPointTy AllocaIP,
1642 ArrayRef<llvm::Value *> ScanVars,
1643 ArrayRef<llvm::Type *> ScanVarsType,
1644 ScanInfo *ScanRedInfo);
1652 Error emitScanBasedDirectiveFinalsIR(
1653 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
1654 ScanInfo *ScanInfo);
1675 Expected<Function *>
1676 emitInterWarpCopyFunction(
const LocationDescription &Loc,
1677 ArrayRef<ReductionInfo> ReductionInfos,
1678 AttributeList FuncAttrs);
1693 Function *emitListToGlobalCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1694 Type *ReductionsBufferTy,
1695 AttributeList FuncAttrs);
1710 Function *emitGlobalToListCopyFunction(ArrayRef<ReductionInfo> ReductionInfos,
1711 Type *ReductionsBufferTy,
1712 AttributeList FuncAttrs);
1732 emitListToGlobalReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1733 Function *ReduceFn,
Type *ReductionsBufferTy,
1734 AttributeList FuncAttrs);
1754 emitGlobalToListReduceFunction(ArrayRef<ReductionInfo> ReductionInfos,
1755 Function *ReduceFn,
Type *ReductionsBufferTy,
1756 AttributeList FuncAttrs);
1759 std::string getReductionFuncName(StringRef Name)
const;
1770 Expected<Function *> createReductionFunction(
1771 StringRef ReducerName, ArrayRef<ReductionInfo> ReductionInfos,
1772 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
1773 AttributeList FuncAttrs = {});
2035 LLVM_ABI InsertPointOrErrorTy createReductionsGPU(
2036 const LocationDescription &Loc, InsertPointTy AllocaIP,
2037 InsertPointTy CodeGenIP, ArrayRef<ReductionInfo> ReductionInfos,
2038 bool IsNoWait =
false,
bool IsTeamsReduction =
false,
2039 ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
2040 std::optional<omp::GV> GridValue = {},
unsigned ReductionBufNum = 1024,
2041 Value *SrcLocInfo =
nullptr);
2108 LLVM_ABI InsertPointOrErrorTy createReductions(
2109 const LocationDescription &Loc, InsertPointTy AllocaIP,
2110 ArrayRef<ReductionInfo> ReductionInfos, ArrayRef<bool> IsByRef,
2111 bool IsNoWait =
false,
bool IsTeamsReduction =
false);
2116 InsertPointTy getInsertionPoint() {
return Builder.saveIP(); }
2119 bool updateToLocation(
const LocationDescription &Loc) {
2120 Builder.restoreIP(Loc.IP);
2121 Builder.SetCurrentDebugLocation(Loc.DL);
2122 return Loc.IP.getBlock() !=
nullptr;
2127 omp::RuntimeFunction FnID);
2129 LLVM_ABI Function *getOrCreateRuntimeFunctionPtr(omp::RuntimeFunction FnID);
2133 uint32_t &SrcLocStrSize);
2141 StringRef FileName,
unsigned Line,
2143 uint32_t &SrcLocStrSize);
2148 Function *
F =
nullptr);
2152 uint32_t &SrcLocStrSize);
2157 uint32_t SrcLocStrSize,
2158 omp::IdentFlag Flags = omp::IdentFlag(0),
2159 unsigned Reserve2Flags = 0);
2163 LLVM_ABI GlobalValue *createGlobalFlag(
unsigned Value, StringRef Name);
2166 LLVM_ABI void emitUsed(StringRef Name, ArrayRef<llvm::WeakTrackingVH> List);
2170 emitKernelExecutionMode(StringRef KernelName, omp::OMPTgtExecModeFlags
Mode);
2180 omp::Directive CanceledDirective,
2181 FinalizeCallbackTy ExitCB = {});
2194 LLVM_ABI InsertPointTy emitTargetKernel(
const LocationDescription &Loc,
2195 InsertPointTy AllocaIP,
2199 ArrayRef<Value *> KernelArgs);
2204 LLVM_ABI void emitFlush(
const LocationDescription &Loc);
2209 SmallVector<FinalizationInfo, 8> FinalizationStack;
2213 bool isLastFinalizationInfoCancellable(omp::Directive DK) {
2214 return !FinalizationStack.empty() &&
2215 FinalizationStack.back().IsCancellable &&
2216 FinalizationStack.back().DK == DK;
2222 LLVM_ABI void emitTaskwaitImpl(
const LocationDescription &Loc);
2227 LLVM_ABI void emitTaskyieldImpl(
const LocationDescription &Loc);
2235 OpenMPIRBuilderConfig Config;
2241 IRBuilder<> Builder;
2244 StringMap<Constant *> SrcLocStrMap;
2247 DenseMap<std::pair<Constant *, uint64_t>,
Constant *> IdentMap;
2250 OffloadEntriesInfoManager OffloadInfoManager;
2257 struct OutlineInfo {
2258 using PostOutlineCBTy = std::function<void(Function &)>;
2259 PostOutlineCBTy PostOutlineCB;
2260 BasicBlock *EntryBB, *ExitBB, *OuterAllocaBB;
2261 SmallVector<Value *, 2> ExcludeArgsFromAggregate;
2266 SmallVectorImpl<BasicBlock *> &BlockVector);
2273 SmallVector<OutlineInfo, 16> OutlineInfos;
2278 SmallVector<llvm::Function *, 16> ConstantAllocaRaiseCandidates;
2282 std::forward_list<CanonicalLoopInfo> LoopInfos;
2285 std::forward_list<ScanInfo> ScanInfos;
2288 void addOutlineInfo(OutlineInfo &&OI) { OutlineInfos.emplace_back(OI); }
2295 StringMap<GlobalVariable *, BumpPtrAllocator> InternalVars;
2302 LLVM_ABI void emitBranch(BasicBlock *Target);
2307 LLVM_ABI void emitBlock(BasicBlock *BB, Function *CurFn,
2308 bool IsFinished =
false);
2320 BodyGenCallbackTy ElseGen,
2321 InsertPointTy AllocaIP = {});
2325 createOffloadMaptypes(SmallVectorImpl<uint64_t> &Mappings,
2326 std::string VarName);
2330 createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
2331 std::string VarName);
2333 struct MapperAllocas {
2334 AllocaInst *ArgsBase =
nullptr;
2335 AllocaInst *
Args =
nullptr;
2336 AllocaInst *ArgSizes =
nullptr;
2340 LLVM_ABI void createMapperAllocas(
const LocationDescription &Loc,
2341 InsertPointTy AllocaIP,
2342 unsigned NumOperands,
2343 struct MapperAllocas &MapperAllocas);
2354 LLVM_ABI void emitMapperCall(
const LocationDescription &Loc,
2355 Function *MapperFunc,
Value *SrcLocInfo,
2357 struct MapperAllocas &MapperAllocas,
2358 int64_t DeviceID,
unsigned NumOperands);
2361 struct TargetDataRTArgs {
2363 Value *BasePointersArray =
nullptr;
2365 Value *PointersArray =
nullptr;
2367 Value *SizesArray =
nullptr;
2371 Value *MapTypesArray =
nullptr;
2375 Value *MapTypesArrayEnd =
nullptr;
2377 Value *MappersArray =
nullptr;
2380 Value *MapNamesArray =
nullptr;
2382 explicit TargetDataRTArgs() {}
2383 explicit TargetDataRTArgs(
Value *BasePointersArray,
Value *PointersArray,
2385 Value *MapTypesArrayEnd,
Value *MappersArray,
2386 Value *MapNamesArray)
2387 : BasePointersArray(BasePointersArray), PointersArray(PointersArray),
2388 SizesArray(SizesArray), MapTypesArray(MapTypesArray),
2389 MapTypesArrayEnd(MapTypesArrayEnd), MappersArray(MappersArray),
2390 MapNamesArray(MapNamesArray) {}
2400 struct TargetKernelDefaultAttrs {
2401 omp::OMPTgtExecModeFlags ExecFlags =
2402 omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC;
2403 SmallVector<int32_t, 3> MaxTeams = {-1};
2404 int32_t MinTeams = 1;
2406 int32_t MinThreads = 1;
2407 int32_t ReductionDataSize = 0;
2408 int32_t ReductionBufferLength = 0;
2416 struct TargetKernelRuntimeAttrs {
2417 SmallVector<Value *, 3> MaxTeams = {
nullptr};
2418 Value *MinTeams =
nullptr;
2419 SmallVector<Value *, 3> TargetThreadLimit = {
nullptr};
2420 SmallVector<Value *, 3> TeamsThreadLimit = {
nullptr};
2428 Value *LoopTripCount =
nullptr;
2433 struct TargetKernelArgs {
2435 unsigned NumTargetItems = 0;
2437 TargetDataRTArgs RTArgs;
2439 Value *NumIterations =
nullptr;
2441 ArrayRef<Value *> NumTeams;
2443 ArrayRef<Value *> NumThreads;
2445 Value *DynCGGroupMem =
nullptr;
2447 bool HasNoWait =
false;
2450 TargetKernelArgs() {}
2451 TargetKernelArgs(
unsigned NumTargetItems, TargetDataRTArgs RTArgs,
2452 Value *NumIterations, ArrayRef<Value *> NumTeams,
2453 ArrayRef<Value *> NumThreads,
Value *DynCGGroupMem,
2455 : NumTargetItems(NumTargetItems), RTArgs(RTArgs),
2456 NumIterations(NumIterations), NumTeams(NumTeams),
2457 NumThreads(NumThreads), DynCGGroupMem(DynCGGroupMem),
2458 HasNoWait(HasNoWait) {}
2464 LLVM_ABI static void getKernelArgsVector(TargetKernelArgs &KernelArgs,
2465 IRBuilderBase &Builder,
2466 SmallVector<Value *> &ArgsVector);
2470 class TargetDataInfo {
2472 bool RequiresDevicePointerInfo =
false;
2475 bool SeparateBeginEndCalls =
false;
2478 TargetDataRTArgs RTArgs;
2480 SmallMapVector<const Value *, std::pair<Value *, Value *>, 4>
2484 bool HasMapper =
false;
2486 unsigned NumberOfPtrs = 0
u;
2488 bool EmitDebug =
false;
2491 bool HasNoWait =
false;
2493 explicit TargetDataInfo() {}
2494 explicit TargetDataInfo(
bool RequiresDevicePointerInfo,
2495 bool SeparateBeginEndCalls)
2496 : RequiresDevicePointerInfo(RequiresDevicePointerInfo),
2497 SeparateBeginEndCalls(SeparateBeginEndCalls) {}
2499 void clearArrayInfo() {
2500 RTArgs = TargetDataRTArgs();
2506 return RTArgs.BasePointersArray && RTArgs.PointersArray &&
2507 RTArgs.SizesArray && RTArgs.MapTypesArray &&
2508 (!HasMapper || RTArgs.MappersArray) && NumberOfPtrs;
2510 bool requiresDevicePointerInfo() {
return RequiresDevicePointerInfo; }
2511 bool separateBeginEndCalls() {
return SeparateBeginEndCalls; }
2515 using MapValuesArrayTy = SmallVector<Value *, 4>;
2516 using MapDeviceInfoArrayTy = SmallVector<DeviceInfoTy, 4>;
2517 using MapFlagsArrayTy = SmallVector<omp::OpenMPOffloadMappingFlags, 4>;
2518 using MapNamesArrayTy = SmallVector<Constant *, 4>;
2519 using MapDimArrayTy = SmallVector<uint64_t, 4>;
2520 using MapNonContiguousArrayTy = SmallVector<MapValuesArrayTy, 4>;
2526 struct StructNonContiguousInfo {
2527 bool IsNonContiguous =
false;
2529 MapNonContiguousArrayTy
Offsets;
2530 MapNonContiguousArrayTy Counts;
2531 MapNonContiguousArrayTy Strides;
2533 MapValuesArrayTy BasePointers;
2534 MapValuesArrayTy Pointers;
2535 MapDeviceInfoArrayTy DevicePointers;
2536 MapValuesArrayTy
Sizes;
2537 MapFlagsArrayTy
Types;
2538 MapNamesArrayTy Names;
2539 StructNonContiguousInfo NonContigInfo;
2542 void append(MapInfosTy &CurInfo) {
2543 BasePointers.append(CurInfo.BasePointers.begin(),
2544 CurInfo.BasePointers.end());
2545 Pointers.append(CurInfo.Pointers.begin(), CurInfo.Pointers.end());
2546 DevicePointers.append(CurInfo.DevicePointers.begin(),
2547 CurInfo.DevicePointers.end());
2548 Sizes.append(CurInfo.Sizes.begin(), CurInfo.Sizes.end());
2549 Types.append(CurInfo.Types.begin(), CurInfo.Types.end());
2550 Names.append(CurInfo.Names.begin(), CurInfo.Names.end());
2551 NonContigInfo.Dims.append(CurInfo.NonContigInfo.Dims.begin(),
2552 CurInfo.NonContigInfo.Dims.end());
2553 NonContigInfo.Offsets.append(CurInfo.NonContigInfo.Offsets.begin(),
2554 CurInfo.NonContigInfo.Offsets.end());
2555 NonContigInfo.Counts.append(CurInfo.NonContigInfo.Counts.begin(),
2556 CurInfo.NonContigInfo.Counts.end());
2557 NonContigInfo.Strides.append(CurInfo.NonContigInfo.Strides.begin(),
2558 CurInfo.NonContigInfo.Strides.end());
2561 using MapInfosOrErrorTy = Expected<MapInfosTy &>;
2567 using EmitFallbackCallbackTy =
2568 function_ref<InsertPointOrErrorTy(InsertPointTy)>;
2572 using CustomMapperCallbackTy =
2573 function_ref<Expected<Function *>(
unsigned int)>;
2585 LLVM_ABI InsertPointOrErrorTy emitKernelLaunch(
2586 const LocationDescription &Loc,
Value *OutlinedFnID,
2587 EmitFallbackCallbackTy EmitTargetCallFallbackCB, TargetKernelArgs &Args,
2588 Value *DeviceID,
Value *RTLoc, InsertPointTy AllocaIP);
2600 using TargetTaskBodyCallbackTy =
2602 IRBuilderBase::InsertPoint TargetTaskAllocaIP)>;
2614 LLVM_ABI InsertPointOrErrorTy emitTargetTask(
2615 TargetTaskBodyCallbackTy TaskBodyCB,
Value *DeviceID,
Value *RTLoc,
2616 OpenMPIRBuilder::InsertPointTy AllocaIP,
2617 const SmallVector<llvm::OpenMPIRBuilder::DependData> &Dependencies,
2618 const TargetDataRTArgs &RTArgs,
bool HasNoWait);
2624 LLVM_ABI void emitOffloadingArraysArgument(
2625 IRBuilderBase &Builder, OpenMPIRBuilder::TargetDataRTArgs &RTArgs,
2626 OpenMPIRBuilder::TargetDataInfo &
Info,
bool ForEndCall =
false);
2629 LLVM_ABI void emitNonContiguousDescriptor(InsertPointTy AllocaIP,
2630 InsertPointTy CodeGenIP,
2631 MapInfosTy &CombinedInfo,
2632 TargetDataInfo &
Info);
2640 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
2641 TargetDataInfo &
Info, CustomMapperCallbackTy CustomMapperCB,
2642 bool IsNonContiguous =
false,
2643 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2652 InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &
Info,
2653 TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
2654 CustomMapperCallbackTy CustomMapperCB,
bool IsNonContiguous =
false,
2655 bool ForEndCall =
false,
2656 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr);
2660 LLVM_ABI void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t
Size,
2661 int32_t Flags, GlobalValue::LinkageTypes,
2662 StringRef Name =
"");
2666 enum EmitMetadataErrorKind {
2667 EMIT_MD_TARGET_REGION_ERROR,
2668 EMIT_MD_DECLARE_TARGET_ERROR,
2669 EMIT_MD_GLOBAL_VAR_LINK_ERROR
2673 using EmitMetadataErrorReportFunctionTy =
2674 std::function<void(EmitMetadataErrorKind, TargetRegionEntryInfo)>;
2683 LLVM_ABI void createOffloadEntriesAndInfoMetadata(
2684 EmitMetadataErrorReportFunctionTy &ErrorReportFunction);
2697 LLVM_ABI InsertPointTy createCopyPrivate(
const LocationDescription &Loc,
2714 createSingle(
const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2715 FinalizeCallbackTy FiniCB,
bool IsNowait,
2716 ArrayRef<llvm::Value *> CPVars = {},
2717 ArrayRef<llvm::Function *> CPFuncs = {});
2726 LLVM_ABI InsertPointOrErrorTy createMaster(
const LocationDescription &Loc,
2727 BodyGenCallbackTy BodyGenCB,
2728 FinalizeCallbackTy FiniCB);
2737 LLVM_ABI InsertPointOrErrorTy createMasked(
const LocationDescription &Loc,
2738 BodyGenCallbackTy BodyGenCB,
2739 FinalizeCallbackTy FiniCB,
2760 LLVM_ABI InsertPointOrErrorTy emitScanReduction(
2761 const LocationDescription &Loc,
2762 ArrayRef<llvm::OpenMPIRBuilder::ReductionInfo> ReductionInfos,
2763 ScanInfo *ScanRedInfo);
2778 LLVM_ABI InsertPointOrErrorTy createScan(
const LocationDescription &Loc,
2779 InsertPointTy AllocaIP,
2780 ArrayRef<llvm::Value *> ScanVars,
2781 ArrayRef<llvm::Type *> ScanVarsType,
2783 ScanInfo *ScanRedInfo);
2794 LLVM_ABI InsertPointOrErrorTy createCritical(
const LocationDescription &Loc,
2795 BodyGenCallbackTy BodyGenCB,
2796 FinalizeCallbackTy FiniCB,
2797 StringRef CriticalName,
2811 createOrderedDepend(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2812 unsigned NumLoops, ArrayRef<llvm::Value *> StoreValues,
2813 const Twine &Name,
bool IsDependSource);
2824 LLVM_ABI InsertPointOrErrorTy createOrderedThreadsSimd(
2825 const LocationDescription &Loc, BodyGenCallbackTy BodyGenCB,
2826 FinalizeCallbackTy FiniCB,
bool IsThreads);
2840 createSections(
const LocationDescription &Loc, InsertPointTy AllocaIP,
2841 ArrayRef<StorableBodyGenCallbackTy> SectionCBs,
2842 PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB,
2843 bool IsCancellable,
bool IsNowait);
2851 LLVM_ABI InsertPointOrErrorTy createSection(
const LocationDescription &Loc,
2852 BodyGenCallbackTy BodyGenCB,
2853 FinalizeCallbackTy FiniCB);
2867 LLVM_ABI InsertPointOrErrorTy createTeams(
const LocationDescription &Loc,
2868 BodyGenCallbackTy BodyGenCB,
2869 Value *NumTeamsLower =
nullptr,
2870 Value *NumTeamsUpper =
nullptr,
2871 Value *ThreadLimit =
nullptr,
2872 Value *IfExpr =
nullptr);
2879 LLVM_ABI InsertPointOrErrorTy createDistribute(
const LocationDescription &Loc,
2880 InsertPointTy AllocaIP,
2881 BodyGenCallbackTy BodyGenCB);
2895 LLVM_ABI InsertPointTy createCopyinClauseBlocks(InsertPointTy IP,
2898 llvm::IntegerType *IntPtrTy,
2899 bool BranchtoEnd =
true);
2920 LLVM_ABI CallInst *createOMPFree(
const LocationDescription &Loc,
Value *Addr,
2932 createCachedThreadPrivate(
const LocationDescription &Loc,
2934 const llvm::Twine &Name = Twine(
""));
2947 LLVM_ABI CallInst *createOMPInteropInit(
const LocationDescription &Loc,
2949 omp::OMPInteropType InteropType,
2951 Value *DependenceAddress,
2952 bool HaveNowaitClause);
2964 LLVM_ABI CallInst *createOMPInteropDestroy(
const LocationDescription &Loc,
2966 Value *NumDependences,
2967 Value *DependenceAddress,
2968 bool HaveNowaitClause);
2980 LLVM_ABI CallInst *createOMPInteropUse(
const LocationDescription &Loc,
2982 Value *NumDependences,
2983 Value *DependenceAddress,
2984 bool HaveNowaitClause);
2998 LLVM_ABI InsertPointTy createTargetInit(
2999 const LocationDescription &Loc,
3000 const llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &Attrs);
3009 LLVM_ABI void createTargetDeinit(
const LocationDescription &Loc,
3010 int32_t TeamsReductionDataSize = 0,
3011 int32_t TeamsReductionBufferLength = 1024);
3021 LLVM_ABI static std::pair<int32_t, int32_t>
3022 readThreadBoundsForKernel(
const Triple &
T, Function &Kernel);
3023 LLVM_ABI static void writeThreadBoundsForKernel(
const Triple &
T,
3024 Function &Kernel, int32_t LB,
3029 LLVM_ABI static std::pair<int32_t, int32_t>
3030 readTeamBoundsForKernel(
const Triple &
T, Function &Kernel);
3031 LLVM_ABI static void writeTeamsForKernel(
const Triple &
T, Function &Kernel,
3032 int32_t LB, int32_t UB);
3037 void setOutlinedTargetRegionFunctionAttributes(Function *OutlinedFn);
3042 Constant *createOutlinedFunctionID(Function *OutlinedFn,
3043 StringRef EntryFnIDName);
3046 Constant *createTargetRegionEntryAddr(Function *OutlinedFunction,
3047 StringRef EntryFnName);
3051 using FunctionGenCallback =
3052 std::function<Expected<Function *>(StringRef FunctionName)>;
3086 TargetRegionEntryInfo &EntryInfo,
3087 FunctionGenCallback &GenerateFunctionCallback,
bool IsOffloadEntry,
3088 Function *&OutlinedFn, Constant *&OutlinedFnID);
3099 registerTargetRegionFunction(TargetRegionEntryInfo &EntryInfo,
3100 Function *OutlinedFunction,
3101 StringRef EntryFnName, StringRef EntryFnIDName);
3114 enum BodyGenTy { Priv, DupNoPriv, NoPriv };
3119 using GenMapInfoCallbackTy =
3120 function_ref<MapInfosTy &(InsertPointTy CodeGenIP)>;
3129 void emitUDMapperArrayInitOrDel(Function *MapperFn,
llvm::Value *MapperHandle,
3133 llvm::BasicBlock *ExitBB,
bool IsInit);
3176 LLVM_ABI Expected<Function *> emitUserDefinedMapper(
3177 function_ref<MapInfosOrErrorTy(
3179 PrivAndGenMapInfoCB,
3180 llvm::Type *ElemTy, StringRef FuncName,
3181 CustomMapperCallbackTy CustomMapperCB);
3200 LLVM_ABI InsertPointOrErrorTy createTargetData(
3201 const LocationDescription &Loc, InsertPointTy AllocaIP,
3202 InsertPointTy CodeGenIP,
Value *DeviceID,
Value *IfCond,
3203 TargetDataInfo &
Info, GenMapInfoCallbackTy GenMapInfoCB,
3204 CustomMapperCallbackTy CustomMapperCB,
3205 omp::RuntimeFunction *MapperFunc =
nullptr,
3206 function_ref<InsertPointOrErrorTy(InsertPointTy CodeGenIP,
3207 BodyGenTy BodyGenType)>
3208 BodyGenCB =
nullptr,
3209 function_ref<
void(
unsigned int,
Value *)> DeviceAddrCB =
nullptr,
3210 Value *SrcLocInfo =
nullptr);
3212 using TargetBodyGenCallbackTy = function_ref<InsertPointOrErrorTy(
3213 InsertPointTy AllocaIP, InsertPointTy CodeGenIP)>;
3215 using TargetGenArgAccessorsCallbackTy = function_ref<InsertPointOrErrorTy(
3216 Argument &Arg,
Value *Input,
Value *&RetVal, InsertPointTy AllocaIP,
3217 InsertPointTy CodeGenIP)>;
3243 LLVM_ABI InsertPointOrErrorTy createTarget(
3244 const LocationDescription &Loc,
bool IsOffloadEntry,
3245 OpenMPIRBuilder::InsertPointTy AllocaIP,
3246 OpenMPIRBuilder::InsertPointTy CodeGenIP, TargetDataInfo &
Info,
3247 TargetRegionEntryInfo &EntryInfo,
3248 const TargetKernelDefaultAttrs &DefaultAttrs,
3249 const TargetKernelRuntimeAttrs &RuntimeAttrs,
Value *IfCond,
3250 SmallVectorImpl<Value *> &Inputs, GenMapInfoCallbackTy GenMapInfoCB,
3251 TargetBodyGenCallbackTy BodyGenCB,
3252 TargetGenArgAccessorsCallbackTy ArgAccessorFuncCB,
3253 CustomMapperCallbackTy CustomMapperCB,
3254 const SmallVector<DependData> &Dependencies,
bool HasNowait =
false);
3259 LLVM_ABI FunctionCallee createForStaticInitFunction(
unsigned IVSize,
3261 bool IsGPUDistribute);
3265 LLVM_ABI FunctionCallee createDispatchInitFunction(
unsigned IVSize,
3270 LLVM_ABI FunctionCallee createDispatchNextFunction(
unsigned IVSize,
3275 LLVM_ABI FunctionCallee createDispatchFiniFunction(
unsigned IVSize,
3279 LLVM_ABI FunctionCallee createDispatchDeinitFunction();
3287#define OMP_TYPE(VarName, InitValue) Type *VarName = nullptr;
3288#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
3289 ArrayType *VarName##Ty = nullptr; \
3290 PointerType *VarName##PtrTy = nullptr;
3291#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
3292 FunctionType *VarName = nullptr; \
3293 PointerType *VarName##Ptr = nullptr;
3294#define OMP_STRUCT_TYPE(VarName, StrName, ...) \
3295 StructType *VarName = nullptr; \
3296 PointerType *VarName##Ptr = nullptr;
3297#include "llvm/Frontend/OpenMP/OMPKinds.def"
3304 void initializeTypes(
Module &M);
3318 InsertPointTy emitCommonDirectiveEntry(omp::Directive OMPD,
Value *EntryCall,
3320 bool Conditional =
false);
3332 InsertPointOrErrorTy emitCommonDirectiveExit(omp::Directive OMPD,
3333 InsertPointTy FinIP,
3334 Instruction *ExitCall,
3335 bool HasFinalize =
true);
3353 InsertPointOrErrorTy
3354 EmitOMPInlinedRegion(omp::Directive OMPD, Instruction *EntryCall,
3355 Instruction *ExitCall, BodyGenCallbackTy BodyGenCB,
3356 FinalizeCallbackTy FiniCB,
bool Conditional =
false,
3357 bool HasFinalize =
true,
bool IsCancellable =
false);
3365 static std::string getNameWithSeparators(ArrayRef<StringRef> Parts,
3366 StringRef FirstSeparator,
3367 StringRef Separator);
3374 Value *getOMPCriticalRegionLock(StringRef CriticalName);
3388 using AtomicUpdateCallbackTy =
3389 const function_ref<Expected<Value *>(
Value *XOld, IRBuilder<> &IRB)>;
3401 bool checkAndEmitFlushAfterAtomic(
const LocationDescription &Loc,
3402 AtomicOrdering AO, AtomicKind AK);
3428 Expected<std::pair<Value *, Value *>>
3429 emitAtomicUpdate(InsertPointTy AllocaIP,
Value *
X,
Type *XElemTy,
Value *Expr,
3430 AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3431 AtomicUpdateCallbackTy &UpdateOp,
bool VolatileX,
3432 bool IsXBinopExpr,
bool IsIgnoreDenormalMode,
3433 bool IsFineGrainedMemory,
bool IsRemoteMemory);
3439 AtomicRMWInst::BinOp RMWOp);
3445 struct AtomicOpValue {
3446 Value *Var =
nullptr;
3447 Type *ElemTy =
nullptr;
3448 bool IsSigned =
false;
3463 LLVM_ABI InsertPointTy createAtomicRead(
const LocationDescription &Loc,
3464 AtomicOpValue &
X, AtomicOpValue &V,
3466 InsertPointTy AllocaIP);
3478 LLVM_ABI InsertPointTy createAtomicWrite(
const LocationDescription &Loc,
3479 AtomicOpValue &
X,
Value *Expr,
3481 InsertPointTy AllocaIP);
3503 LLVM_ABI InsertPointOrErrorTy createAtomicUpdate(
3504 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3505 Value *Expr, AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
3506 AtomicUpdateCallbackTy &UpdateOp,
bool IsXBinopExpr,
3507 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3508 bool IsRemoteMemory =
false);
3539 LLVM_ABI InsertPointOrErrorTy createAtomicCapture(
3540 const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &
X,
3541 AtomicOpValue &V,
Value *Expr, AtomicOrdering AO,
3542 AtomicRMWInst::BinOp RMWOp, AtomicUpdateCallbackTy &UpdateOp,
3543 bool UpdateExpr,
bool IsPostfixUpdate,
bool IsXBinopExpr,
3544 bool IsIgnoreDenormalMode =
false,
bool IsFineGrainedMemory =
false,
3545 bool IsRemoteMemory =
false);
3593 createAtomicCompare(
const LocationDescription &Loc, AtomicOpValue &
X,
3594 AtomicOpValue &V, AtomicOpValue &R,
Value *
E,
Value *
D,
3595 AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
3596 bool IsXBinopExpr,
bool IsPostfixUpdate,
bool IsFailOnly);
3597 LLVM_ABI InsertPointTy createAtomicCompare(
3598 const LocationDescription &Loc, AtomicOpValue &
X, AtomicOpValue &V,
3599 AtomicOpValue &R,
Value *
E,
Value *
D, AtomicOrdering AO,
3600 omp::OMPAtomicCompareOp Op,
bool IsXBinopExpr,
bool IsPostfixUpdate,
3601 bool IsFailOnly, AtomicOrdering Failure);
3619 LLVM_ABI CanonicalLoopInfo *createLoopSkeleton(DebugLoc
DL,
Value *TripCount,
3621 BasicBlock *PreInsertBefore,
3622 BasicBlock *PostInsertBefore,
3623 const Twine &Name = {});
3625 const std::string ompOffloadInfoName =
"omp_offload.info";
3642 LLVM_ABI void loadOffloadInfoMetadata(vfs::FileSystem &VFS,
3643 StringRef HostFilePath);
3652 getOrCreateInternalVariable(
Type *Ty,
const StringRef &Name,
3653 unsigned AddressSpace = 0);
3754class CanonicalLoopInfo {
3755 friend class OpenMPIRBuilder;
3764 Value *LastIter =
nullptr;
3774 void collectControlBlocks(SmallVectorImpl<BasicBlock *> &BBs);
3779 void setTripCount(
Value *TripCount);
3795 void mapIndVar(llvm::function_ref<
Value *(Instruction *)> Updater);
3799 void setLastIter(
Value *IterVar) { LastIter = std::move(IterVar); }
3808 Value *getLastIter() {
return LastIter; }
3813 bool isValid()
const {
return Header; }
3840 return cast<BranchInst>(
Cond->getTerminator())->getSuccessor(0);
3864 return Exit->getSingleSuccessor();
3870 Value *getTripCount()
const {
3873 assert(isa<CmpInst>(CmpI) &&
"First inst must compare IV with TripCount");
3874 return CmpI->getOperand(1);
3882 assert(isa<PHINode>(IndVarPHI) &&
"First inst must be the IV PHI");
3887 Type *getIndVarType()
const {
3889 return getIndVar()->getType();
3893 OpenMPIRBuilder::InsertPointTy getPreheaderIP()
const {
3896 return {Preheader, std::prev(Preheader->end())};
3900 OpenMPIRBuilder::InsertPointTy getBodyIP()
const {
3903 return {Body, Body->begin()};
3907 OpenMPIRBuilder::InsertPointTy getAfterIP()
const {
3910 return {After, After->begin()};
3915 return Header->getParent();
3973 llvm::BasicBlock *OMPBeforeScanBlock =
nullptr;
3976 llvm::BasicBlock *OMPAfterScanBlock =
nullptr;
3979 llvm::BasicBlock *OMPScanDispatch =
nullptr;
3982 llvm::BasicBlock *OMPScanLoopExit =
nullptr;
3985 llvm::BasicBlock *OMPScanInit =
nullptr;
3988 llvm::BasicBlock *OMPScanFinish =
nullptr;
3992 bool OMPFirstScanLoop =
false;
3996 llvm::SmallDenseMap<llvm::Value *, llvm::Value *> *ScanBuffPtrs;
4007 ScanBuffPtrs =
new llvm::SmallDenseMap<llvm::Value *, llvm::Value *>();
4010 ~ScanInfo() {
delete (ScanBuffPtrs); }
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis false
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
Module.h This file contains the declarations for the Module class.
static std::string getVarName(InstrProfInstBase *Inc, StringRef Prefix, bool &Renamed)
Get the name of a profiling variable for a particular function.
bool operator<(const DeltaInfo &LHS, int64_t Delta)
Machine Check Debug Module
This file defines constans and helpers used when dealing with OpenMP.
Provides definitions for Target specific Grid Values.
static const omp::GV & getGridValue(const Triple &T, Function *Kernel)
const SmallVectorImpl< MachineOperand > & Cond
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
std::unordered_set< BasicBlock * > BlockSet
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static uint32_t getFlags(const Symbol *Sym)
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static cl::opt< unsigned > MaxThreads("xcore-max-threads", cl::Optional, cl::desc("Maximum number of threads (for emulation thread-local storage)"), cl::Hidden, cl::value_desc("number"), cl::init(8))
static const uint32_t IV[8]
LLVM Basic Block Representation.
InsertPoint - A saved insertion point.
Common base class shared among various IRBuilders.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Analysis pass that exposes the LoopInfo for a function.
Represents a single loop in the control flow graph.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
The virtual file system interface.
LLVM_ABI bool isGPU(const Module &M)
Return true iff M target a GPU (and we can use GPU AS reasoning).
constexpr char IsVolatile[]
Key for Kernel::Arg::Metadata::mIsVolatile.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ BasicBlock
Various leaf nodes.
ElementType
The element type of an SRV or UAV resource.
Context & getContext() const
friend class Instruction
Iterator for Instructions in a `BasicBlock.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
FunctionAddr VTableAddr Count