40std::pair<Constant *, GlobalVariable *>
54 Triple.
isNVPTX() ?
"$offloading$entry_name" :
".offloading.entry_name";
63 Str->setAlignment(
Align(1));
66 NamedMDNode *MD = M.getOrInsertNamedMetadata(
"llvm.offloading.symbols");
73 ConstantInt::get(Int16Ty, 1),
74 ConstantInt::get(Int16Ty, Kind),
75 ConstantInt::get(
Int32Ty, Flags),
78 ConstantInt::get(Int64Ty,
Size),
79 ConstantInt::get(Int64Ty,
Data),
83 return {EntryInitializer, Str};
94 M, Kind, Addr, Name,
Size, Flags,
Data, AuxAddr);
97 Triple.
isNVPTX() ?
"$offloading$entry$" :
".offloading.entry.";
102 M.getDataLayout().getDefaultGlobalsAddressSpace());
113std::pair<GlobalVariable *, GlobalVariable *>
117 auto *ZeroInitilaizer =
153 return std::make_pair(EntriesB, EntriesE);
163 if (EnvArch != ImageArch)
170 if (!EnvTargetID.
contains(
"xnack-"))
175 if (!EnvTargetID.
contains(
"xnack+"))
188 if (!EnvTargetID.
contains(
"sramecc-"))
193 if (!EnvTargetID.
contains(
"sramecc+"))
206class KernelInfoReader {
209 : KernelInfoMap(KIM) {}
214 if (
Note.getName() !=
"AMDGPU")
218 "Parse AMDGPU MetaData");
227 if (!Verifier.verify(MsgPackDoc.
getRoot()))
232 if (
auto Err = iterateAMDKernels(RootMap))
242 extractKernelData(msgpack::MapDocNode::MapTy::value_type V,
243 std::string &KernelName,
245 if (!V.first.isString())
252 const auto GetSequenceOfThreeInts = [](msgpack::DocNode &DN,
256 assert(DNA.size() == 3 &&
"ArrayNode has at most three elements");
259 for (
auto DNABegin = DNA.begin(), DNAEnd = DNA.end(); DNABegin != DNAEnd;
261 Vals[
I++] = DNABegin->getUInt();
265 if (IsKey(
V.first,
".name")) {
266 KernelName =
V.second.toString();
267 }
else if (IsKey(
V.first,
".sgpr_count")) {
269 }
else if (IsKey(
V.first,
".sgpr_spill_count")) {
271 }
else if (IsKey(
V.first,
".vgpr_count")) {
273 }
else if (IsKey(
V.first,
".vgpr_spill_count")) {
275 }
else if (IsKey(
V.first,
".agpr_count")) {
277 }
else if (IsKey(
V.first,
".private_segment_fixed_size")) {
279 }
else if (IsKey(
V.first,
".group_segment_fixed_size")) {
281 }
else if (IsKey(
V.first,
".reqd_workgroup_size")) {
283 }
else if (IsKey(
V.first,
".workgroup_size_hint")) {
285 }
else if (IsKey(
V.first,
".wavefront_size")) {
287 }
else if (IsKey(
V.first,
".max_flat_workgroup_size")) {
295 Expected<msgpack::ArrayDocNode> getAMDKernelsArray(msgpack::MapDocNode &MDN) {
296 auto Res = MDN.
find(
"amdhsa.kernels");
297 if (Res == MDN.
end())
299 "Could not find amdhsa.kernels key");
302 assert(Pair.second.isArray() &&
303 "AMDGPU kernel entries are arrays of entries");
305 return Pair.second.getArray();
312 Error generateKernelInfo(msgpack::ArrayDocNode::ArrayTy::iterator It) {
313 offloading::amdgpu::AMDGPUKernelMetaData KernelData;
314 std::string KernelName;
315 auto Entry = (*It).getMap();
317 if (
auto Err = extractKernelData(*
MI, KernelName, KernelData))
320 KernelInfoMap.insert({KernelName, KernelData});
325 Error iterateAMDKernels(msgpack::MapDocNode &MDN) {
326 auto KernelsOrErr = getAMDKernelsArray(MDN);
327 if (
auto Err = KernelsOrErr.takeError())
330 auto KernelsArr = *KernelsOrErr;
331 for (
auto It = KernelsArr.begin(),
E = KernelsArr.end(); It !=
E; ++It) {
337 if (
auto Err = generateKernelInfo(It))
344 StringMap<offloading::amdgpu::AMDGPUKernelMetaData> &KernelInfoMap;
355 if (
auto Err = ELFOrError.takeError())
362 KernelInfoReader Reader(KernelInfoMap);
367 for (
const auto &S : *Sections) {
371 for (
const auto N : ELFObj.
notes(S, Err)) {
375 if ((Err = Reader.processNote(
N, S.sh_addralign)))
391 OffloadBinary::OffloadingImage InnerImage;
392 InnerImage.TheImageKind = ImageKind;
393 InnerImage.TheOffloadKind = OffloadKind;
394 InnerImage.Flags = ImageFlags;
397 for (
const auto &[
Key,
Value] : MetaData)
400 InnerImage.Image = std::move(Img);
402 SmallString<0> InnerBinaryData = OffloadBinary::write(InnerImage);
411 constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] =
"1.0";
414 "Expected SPIR-V triple with Intel vendor");
417 MetaData[
"version"] = INTEL_ONEOMP_OFFLOAD_VERSION;
418 if (!CompileOpts.
empty())
419 MetaData[
"compile-opts"] = CompileOpts;
420 if (!LinkOpts.
empty())
421 MetaData[
"link-opts"] = LinkOpts;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file declares classes for handling the YAML representation of ELF.
This file declares a class that exposes a simple in-memory representation of a document of MsgPack ob...
verify safepoint Safepoint IR Verifier
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
static LLVM_ABI ConstantAggregateZero * get(Type *Ty)
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
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)
This class implements a map that also provides access to all stored values in a deterministic order.
StringRef getBuffer() const
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
A Module instance is used to store all the information related to an LLVM module.
LLVM_ABI void addOperand(MDNode *M)
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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.
constexpr bool empty() const
empty - Check if the string is empty.
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 LLVM_ABI StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
static LLVM_ABI 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.
const std::string & getTriple() const
bool isNVPTX() const
Tests whether the target is NVPTX (32- or 64-bit).
VendorType getVendor() const
Get the parsed vendor type of this triple.
bool isSPIRV() const
Tests whether the target is SPIR-V (32/64-bit/Logical).
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 LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
LLVM Value Representation.
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.
LLVM_ABI 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
static uint64_t getAlignment()
@ C
The default llvm calling convention, compatible with C.
@ EF_AMDGPU_FEATURE_XNACK_ANY_V4
@ EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
@ EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
@ EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
@ EF_AMDGPU_FEATURE_XNACK_OFF_V4
@ EF_AMDGPU_FEATURE_XNACK_V4
@ EF_AMDGPU_FEATURE_SRAMECC_V4
@ EF_AMDGPU_FEATURE_XNACK_ON_V4
@ EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
@ EF_AMDGPU_FEATURE_SRAMECC_ON_V4
OffloadKind
The producer of the associated offloading image.
ImageKind
The type of contents the offloading image contains.
ELFFile< ELF64LE > ELF64LEFile
LLVM_ABI Error getAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer, StringMap< AMDGPUKernelMetaData > &KernelInfoMap, uint16_t &ELFABIVersion)
Reads AMDGPU specific metadata from the ELF file and propagates the KernelInfoMap.
LLVM_ABI bool isImageCompatibleWithEnv(StringRef ImageArch, uint32_t ImageFlags, StringRef EnvTargetID)
Check if an image is compatible with current system's environment.
LLVM_ABI Error containerizeOpenMPSPIRVImage(std::unique_ptr< MemoryBuffer > &Binary, llvm::Triple Triple, StringRef CompileOpts="", StringRef LinkOpts="")
Containerizes an OpenMP SPIR-V image into an OffloadBinary image.
LLVM_ABI GlobalVariable * emitOffloadingEntry(Module &M, object::OffloadKind Kind, Constant *Addr, StringRef Name, uint64_t Size, uint32_t Flags, uint64_t Data, Constant *AuxAddr=nullptr, StringRef SectionName="llvm_offload_entries")
Create an offloading section struct used to register this global at runtime.
LLVM_ABI Error containerizeImage(std::unique_ptr< MemoryBuffer > &Binary, llvm::Triple Triple, object::ImageKind ImageKind, object::OffloadKind OffloadKind, int32_t ImageFlags, MapVector< StringRef, StringRef > &MetaData)
Containerizes an image within an OffloadBinary image.
LLVM_ABI std::pair< Constant *, GlobalVariable * > getOffloadingEntryInitializer(Module &M, object::OffloadKind Kind, Constant *Addr, StringRef Name, uint64_t Size, uint32_t Flags, uint64_t Data, Constant *AuxAddr)
Create a constant struct initializer used to register this global at runtime.
LLVM_ABI StructType * getEntryTy(Module &M)
Returns the type of the offloading entry we use to store kernels and globals that will be registered ...
LLVM_ABI std::pair< GlobalVariable *, GlobalVariable * > getOffloadEntryArray(Module &M, StringRef SectionName="llvm_offload_entries")
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.
FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty
LLVM_ABI 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.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionAddr VTableAddr uintptr_t uintptr_t Data
LLVM_ABI 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.
Elf_Note_Impl< ELFType< E, Is64 > > Note
This is the record of an object that just be registered with the offloading runtime.
Common declarations for yaml2obj.