31 "struct.__tgt_offload_entry", PointerType::getUnqual(
C),
32 PointerType::getUnqual(
C), M.getDataLayout().getIntPtrType(
C),
38std::pair<Constant *, GlobalVariable *>
41 int32_t Flags, int32_t Data) {
43 Type *Int8PtrTy = PointerType::getUnqual(M.getContext());
45 Type *SizeTy = M.getDataLayout().getIntPtrType(M.getContext());
50 Triple.
isNVPTX() ?
"$offloading$entry_name" :
".offloading.entry_name";
56 Str->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
62 ConstantInt::get(SizeTy,
Size),
63 ConstantInt::get(Int32Ty, Flags),
64 ConstantInt::get(Int32Ty, Data),
67 return {EntryInitializer, Str};
75 auto [EntryInitializer, NameGV] =
79 Triple.
isNVPTX() ?
"$offloading$entry$" :
".offloading.entry.";
84 M.getDataLayout().getDefaultGlobalsAddressSpace());
91 Entry->setAlignment(
Align(1));
94std::pair<GlobalVariable *, GlobalVariable *>
98 auto *ZeroInitilaizer =
101 auto *EntryType = ArrayType::get(
getEntryTy(M), 0);
120 M, ZeroInitilaizer->getType(),
true, GlobalVariable::InternalLinkage,
133 return std::make_pair(EntriesB, EntriesE);
143 if (EnvArch != ImageArch)
147 switch (ImageFlags & EF_AMDGPU_FEATURE_XNACK_V4) {
148 case EF_AMDGPU_FEATURE_XNACK_OFF_V4:
150 if (!EnvTargetID.
contains(
"xnack-"))
153 case EF_AMDGPU_FEATURE_XNACK_ON_V4:
155 if (!EnvTargetID.
contains(
"xnack+"))
158 case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4:
159 case EF_AMDGPU_FEATURE_XNACK_ANY_V4:
165 switch (ImageFlags & EF_AMDGPU_FEATURE_SRAMECC_V4) {
166 case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4:
168 if (!EnvTargetID.
contains(
"sramecc-"))
171 case EF_AMDGPU_FEATURE_SRAMECC_ON_V4:
173 if (!EnvTargetID.
contains(
"sramecc+"))
176 case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4:
177 case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4:
186class KernelInfoReader {
189 : KernelInfoMap(KIM) {}
194 if (
Note.getName() !=
"AMDGPU")
198 "Parse AMDGPU MetaData");
212 if (
auto Err = iterateAMDKernels(RootMap))
222 extractKernelData(msgpack::MapDocNode::MapTy::value_type V,
223 std::string &KernelName,
225 if (!V.first.isString())
236 assert(DNA.size() == 3 &&
"ArrayNode has at most three elements");
239 for (
auto DNABegin = DNA.begin(), DNAEnd = DNA.end(); DNABegin != DNAEnd;
241 Vals[
I++] = DNABegin->getUInt();
245 if (IsKey(
V.first,
".name")) {
246 KernelName =
V.second.toString();
247 }
else if (IsKey(
V.first,
".sgpr_count")) {
249 }
else if (IsKey(
V.first,
".sgpr_spill_count")) {
251 }
else if (IsKey(
V.first,
".vgpr_count")) {
253 }
else if (IsKey(
V.first,
".vgpr_spill_count")) {
255 }
else if (IsKey(
V.first,
".agpr_count")) {
257 }
else if (IsKey(
V.first,
".private_segment_fixed_size")) {
259 }
else if (IsKey(
V.first,
".group_segment_fixed_size")) {
261 }
else if (IsKey(
V.first,
".reqd_workgroup_size")) {
263 }
else if (IsKey(
V.first,
".workgroup_size_hint")) {
265 }
else if (IsKey(
V.first,
".wavefront_size")) {
267 }
else if (IsKey(
V.first,
".max_flat_workgroup_size")) {
276 auto Res = MDN.
find(
"amdhsa.kernels");
277 if (Res == MDN.
end())
279 "Could not find amdhsa.kernels key");
282 assert(Pair.second.isArray() &&
283 "AMDGPU kernel entries are arrays of entries");
285 return Pair.second.getArray();
292 Error generateKernelInfo(msgpack::ArrayDocNode::ArrayTy::iterator It) {
294 std::string KernelName;
295 auto Entry = (*It).getMap();
297 if (
auto Err = extractKernelData(*
MI, KernelName, KernelData))
300 KernelInfoMap.insert({KernelName, KernelData});
306 auto KernelsOrErr = getAMDKernelsArray(MDN);
307 if (
auto Err = KernelsOrErr.takeError())
310 auto KernelsArr = *KernelsOrErr;
311 for (
auto It = KernelsArr.begin(), E = KernelsArr.end(); It != E; ++It) {
317 if (
auto Err = generateKernelInfo(It))
335 if (
auto Err = ELFOrError.takeError())
342 KernelInfoReader Reader(KernelInfoMap);
347 for (
const auto &S : *Sections) {
351 for (
const auto N : ELFObj.
notes(S, Err)) {
355 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.
StringRef getBuffer() const
A Module instance is used to store all the information related to an LLVM module.
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.