30 "struct.__tgt_offload_entry", PointerType::getUnqual(
C),
31 PointerType::getUnqual(
C), M.getDataLayout().getIntPtrType(
C),
37std::pair<Constant *, GlobalVariable *>
40 int32_t Flags, int32_t Data) {
42 Type *Int8PtrTy = PointerType::getUnqual(M.getContext());
44 Type *SizeTy = M.getDataLayout().getIntPtrType(M.getContext());
49 Triple.
isNVPTX() ?
"$offloading$entry_name" :
".offloading.entry_name";
56 Str->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
58 Str->setAlignment(
Align(1));
61 NamedMDNode *MD = M.getOrInsertNamedMetadata(
"llvm.offloading.symbols");
69 ConstantInt::get(SizeTy,
Size),
70 ConstantInt::get(Int32Ty, Flags),
71 ConstantInt::get(Int32Ty, Data),
74 return {EntryInitializer, Str};
82 auto [EntryInitializer, NameGV] =
86 Triple.
isNVPTX() ?
"$offloading$entry$" :
".offloading.entry.";
91 M.getDataLayout().getDefaultGlobalsAddressSpace());
98 Entry->setAlignment(
Align(1));
101std::pair<GlobalVariable *, GlobalVariable *>
105 auto *ZeroInitilaizer =
108 auto *EntryType = ArrayType::get(
getEntryTy(M), 0);
127 M, ZeroInitilaizer->getType(),
true, GlobalVariable::InternalLinkage,
140 return std::make_pair(EntriesB, EntriesE);
150 if (EnvArch != ImageArch)
154 switch (ImageFlags & EF_AMDGPU_FEATURE_XNACK_V4) {
155 case EF_AMDGPU_FEATURE_XNACK_OFF_V4:
157 if (!EnvTargetID.
contains(
"xnack-"))
160 case EF_AMDGPU_FEATURE_XNACK_ON_V4:
162 if (!EnvTargetID.
contains(
"xnack+"))
165 case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4:
166 case EF_AMDGPU_FEATURE_XNACK_ANY_V4:
172 switch (ImageFlags & EF_AMDGPU_FEATURE_SRAMECC_V4) {
173 case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4:
175 if (!EnvTargetID.
contains(
"sramecc-"))
178 case EF_AMDGPU_FEATURE_SRAMECC_ON_V4:
180 if (!EnvTargetID.
contains(
"sramecc+"))
183 case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4:
184 case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4:
193class KernelInfoReader {
196 : KernelInfoMap(KIM) {}
201 if (
Note.getName() !=
"AMDGPU")
205 "Parse AMDGPU MetaData");
219 if (
auto Err = iterateAMDKernels(RootMap))
229 extractKernelData(msgpack::MapDocNode::MapTy::value_type V,
230 std::string &KernelName,
232 if (!V.first.isString())
243 assert(DNA.size() == 3 &&
"ArrayNode has at most three elements");
246 for (
auto DNABegin = DNA.begin(), DNAEnd = DNA.end(); DNABegin != DNAEnd;
248 Vals[
I++] = DNABegin->getUInt();
252 if (IsKey(
V.first,
".name")) {
253 KernelName =
V.second.toString();
254 }
else if (IsKey(
V.first,
".sgpr_count")) {
256 }
else if (IsKey(
V.first,
".sgpr_spill_count")) {
258 }
else if (IsKey(
V.first,
".vgpr_count")) {
260 }
else if (IsKey(
V.first,
".vgpr_spill_count")) {
262 }
else if (IsKey(
V.first,
".agpr_count")) {
264 }
else if (IsKey(
V.first,
".private_segment_fixed_size")) {
266 }
else if (IsKey(
V.first,
".group_segment_fixed_size")) {
268 }
else if (IsKey(
V.first,
".reqd_workgroup_size")) {
270 }
else if (IsKey(
V.first,
".workgroup_size_hint")) {
272 }
else if (IsKey(
V.first,
".wavefront_size")) {
274 }
else if (IsKey(
V.first,
".max_flat_workgroup_size")) {
283 auto Res = MDN.
find(
"amdhsa.kernels");
284 if (Res == MDN.
end())
286 "Could not find amdhsa.kernels key");
289 assert(Pair.second.isArray() &&
290 "AMDGPU kernel entries are arrays of entries");
292 return Pair.second.getArray();
299 Error generateKernelInfo(msgpack::ArrayDocNode::ArrayTy::iterator It) {
301 std::string KernelName;
302 auto Entry = (*It).getMap();
304 if (
auto Err = extractKernelData(*
MI, KernelName, KernelData))
307 KernelInfoMap.insert({KernelName, KernelData});
313 auto KernelsOrErr = getAMDKernelsArray(MDN);
314 if (
auto Err = KernelsOrErr.takeError())
317 auto KernelsArr = *KernelsOrErr;
318 for (
auto It = KernelsArr.begin(), E = KernelsArr.end(); It != E; ++It) {
324 if (
auto Err = generateKernelInfo(It))
342 if (
auto Err = ELFOrError.takeError())
349 KernelInfoReader Reader(KernelInfoMap);
354 for (
const auto &S : *Sections) {
358 for (
const auto N : ELFObj.
notes(S, Err)) {
362 if ((Err = Reader.processNote(
N, S.sh_addralign)))
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file declares a class that exposes a simple in-memory representation of a document of MsgPack ob...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
verify safepoint Safepoint IR Verifier
static ConstantAggregateZero * get(Type *Ty)
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
@ HiddenVisibility
The GV is hidden.
@ InternalLinkage
Rename collisions when linking (static functions).
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
This is an important class for using LLVM in a threaded context.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
StringRef getBuffer() const
A Module instance is used to store all the information related to an LLVM module.
void addOperand(MDNode *M)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Class to represent struct types.
static StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Triple - Helper class for working with autoconf configuration names.
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
bool isNVPTX() const
Tests whether the target is NVPTX (32- or 64-bit).
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
The instances of the Type class are immutable: once they are created, they are never changed.
static IntegerType * getInt32Ty(LLVMContext &C)
Type * getType() const
All values are typed, get the type of this value.
A node in a MsgPack Document.
MapDocNode & getMap(bool Convert=false)
Get a MapDocNode for a map node.
ArrayDocNode & getArray(bool Convert=false)
Get an ArrayDocNode for an array node.
StringRef getString() const
Simple in-memory representation of a document of msgpack objects with ability to find and create arra...
DocNode & getRoot()
Get ref to the document's root element.
bool readFromBlob(StringRef Blob, bool Multi, function_ref< int(DocNode *DestNode, DocNode SrcNode, DocNode MapKey)> Merger=[](DocNode *DestNode, DocNode SrcNode, DocNode MapKey) { return -1;})
Read a document from a binary msgpack blob, merging into anything already in the Document.
MapTy::iterator find(DocNode Key)
const Elf_Ehdr & getHeader() const
static Expected< ELFFile > create(StringRef Object)
iterator_range< Elf_Note_Iterator > notes(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator range over notes of a program header.
Expected< Elf_Shdr_Range > sections() const
@ C
The default llvm calling convention, compatible with C.
Error getAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer, StringMap< AMDGPUKernelMetaData > &KernelInfoMap, uint16_t &ELFABIVersion)
Reads AMDGPU specific metadata from the ELF file and propagates the KernelInfoMap.
bool isImageCompatibleWithEnv(StringRef ImageArch, uint32_t ImageFlags, StringRef EnvTargetID)
Check if an image is compatible with current system's environment.
std::pair< Constant *, GlobalVariable * > getOffloadingEntryInitializer(Module &M, Constant *Addr, StringRef Name, uint64_t Size, int32_t Flags, int32_t Data)
Create a constant struct initializer used to register this global at runtime.
StructType * getEntryTy(Module &M)
Returns the type of the offloading entry we use to store kernels and globals that will be registered ...
void emitOffloadingEntry(Module &M, Constant *Addr, StringRef Name, uint64_t Size, int32_t Flags, int32_t Data, StringRef SectionName)
Create an offloading section struct used to register this global at runtime.
std::pair< GlobalVariable *, GlobalVariable * > getOffloadEntryArray(Module &M, StringRef SectionName)
Creates a pair of globals used to iterate the array of offloading entries by accessing the section va...
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Description of the encoding of one expression Op.