41std::pair<Constant *, GlobalVariable *>
55 Triple.
isNVPTX() ?
"$offloading$entry_name" :
".offloading.entry_name";
64 Str->setAlignment(
Align(1));
67 NamedMDNode *MD = M.getOrInsertNamedMetadata(
"llvm.offloading.symbols");
74 ConstantInt::get(Int16Ty, 1),
75 ConstantInt::get(Int16Ty, Kind),
76 ConstantInt::get(Int32Ty, Flags),
79 ConstantInt::get(Int64Ty,
Size),
80 ConstantInt::get(Int64Ty,
Data),
84 return {EntryInitializer, Str};
88 return M.getTargetTriple().isOSBinFormatMachO() ?
"__LLVM,offload_entries"
89 :
"llvm_offload_entries";
95static std::pair<std::string, std::string>
97 if (
T.isOSBinFormatMachO()) {
99 std::replace(SymSection.begin(), SymSection.end(),
',',
'$');
100 return {
"\1section$start$" + SymSection,
"\1section$end$" + SymSection};
112 M, Kind, Addr, Name,
Size, Flags,
Data, AuxAddr);
115 Triple.
isNVPTX() ?
"$offloading$entry$" :
".offloading.entry.";
120 M.getDataLayout().getDefaultGlobalsAddressSpace());
131std::pair<GlobalVariable *, GlobalVariable *>
136 auto *ZeroInitilaizer =
143 auto [StartName, StopName] =
147 Linkage, EntryInit, StartName);
150 Linkage, EntryInit, StopName);
183 return std::make_pair(EntriesB, EntriesE);
193 if (EnvArch != ImageArch)
200 if (!EnvTargetID.
contains(
"xnack-"))
205 if (!EnvTargetID.
contains(
"xnack+"))
218 if (!EnvTargetID.
contains(
"sramecc-"))
223 if (!EnvTargetID.
contains(
"sramecc+"))
236class KernelInfoReader {
239 : KernelInfoMap(KIM) {}
244 if (
Note.getName() !=
"AMDGPU")
248 "Parse AMDGPU MetaData");
257 if (!Verifier.verify(MsgPackDoc.
getRoot()))
262 if (
auto Err = iterateAMDKernels(RootMap))
272 extractKernelData(msgpack::MapDocNode::MapTy::value_type V,
273 std::string &KernelName,
275 if (!V.first.isString())
282 const auto GetSequenceOfThreeInts = [](msgpack::DocNode &DN,
286 assert(DNA.size() == 3 &&
"ArrayNode has at most three elements");
289 for (
auto DNABegin = DNA.begin(), DNAEnd = DNA.end(); DNABegin != DNAEnd;
291 Vals[
I++] = DNABegin->getUInt();
295 if (IsKey(
V.first,
".name")) {
296 KernelName =
V.second.toString();
297 }
else if (IsKey(
V.first,
".sgpr_count")) {
299 }
else if (IsKey(
V.first,
".sgpr_spill_count")) {
301 }
else if (IsKey(
V.first,
".vgpr_count")) {
303 }
else if (IsKey(
V.first,
".vgpr_spill_count")) {
305 }
else if (IsKey(
V.first,
".agpr_count")) {
307 }
else if (IsKey(
V.first,
".private_segment_fixed_size")) {
309 }
else if (IsKey(
V.first,
".group_segment_fixed_size")) {
311 }
else if (IsKey(
V.first,
".reqd_workgroup_size")) {
313 }
else if (IsKey(
V.first,
".workgroup_size_hint")) {
315 }
else if (IsKey(
V.first,
".wavefront_size")) {
317 }
else if (IsKey(
V.first,
".max_flat_workgroup_size")) {
319 }
else if (IsKey(
V.first,
".args")) {
320 auto ArgsArray =
V.second.getArray();
321 for (
auto ArgIt = ArgsArray.begin(), ArgEnd = ArgsArray.end();
322 ArgIt != ArgEnd; ++ArgIt) {
323 auto ArgMap = ArgIt->getMap();
325 auto OffsetIt = ArgMap.find(
".offset");
326 if (OffsetIt == ArgMap.end())
329 "Missing required .offset key in kernel argument metadata map");
331 auto SizeIt = ArgMap.find(
".size");
332 if (SizeIt == ArgMap.end())
335 "Missing required .size key in kernel argument metadata map");
338 SizeIt->second.getUInt());
346 Expected<msgpack::ArrayDocNode> getAMDKernelsArray(msgpack::MapDocNode &MDN) {
347 auto Res = MDN.
find(
"amdhsa.kernels");
348 if (Res == MDN.
end())
350 "Could not find amdhsa.kernels key");
353 assert(Pair.second.isArray() &&
354 "AMDGPU kernel entries are arrays of entries");
356 return Pair.second.getArray();
363 Error generateKernelInfo(msgpack::ArrayDocNode::ArrayTy::iterator It) {
364 offloading::amdgpu::AMDGPUKernelMetaData KernelData;
365 std::string KernelName;
366 auto Entry = (*It).getMap();
368 if (
auto Err = extractKernelData(*
MI, KernelName, KernelData))
371 KernelInfoMap.insert({KernelName, KernelData});
376 Error iterateAMDKernels(msgpack::MapDocNode &MDN) {
377 auto KernelsOrErr = getAMDKernelsArray(MDN);
378 if (
auto Err = KernelsOrErr.takeError())
381 auto KernelsArr = *KernelsOrErr;
382 for (
auto It = KernelsArr.begin(),
E = KernelsArr.end(); It !=
E; ++It) {
388 if (
auto Err = generateKernelInfo(It))
395 StringMap<offloading::amdgpu::AMDGPUKernelMetaData> &KernelInfoMap;
406 if (
auto Err = ELFOrError.takeError())
413 KernelInfoReader Reader(KernelInfoMap);
418 for (
const auto &S : *Sections) {
422 for (
const auto N : ELFObj.
notes(S, Err)) {
426 if ((Err = Reader.processNote(
N, S.sh_addralign)))
442 OffloadBinary::OffloadingImage InnerImage;
443 InnerImage.TheImageKind = ImageKind;
444 InnerImage.TheOffloadKind = OffloadKind;
445 InnerImage.Flags = ImageFlags;
448 for (
const auto &[
Key,
Value] : MetaData)
451 InnerImage.Image = std::move(Img);
453 SmallString<0> InnerBinaryData = OffloadBinary::write(InnerImage);
462 constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] =
"1.0";
465 "Expected SPIR-V triple with Intel vendor");
468 MetaData[
"version"] = INTEL_ONEOMP_OFFLOAD_VERSION;
469 if (!CompileOpts.
empty())
470 MetaData[
"compile-opts"] = CompileOpts;
471 if (!LinkOpts.
empty())
472 MetaData[
"link-opts"] = LinkOpts;
489 uint32_t TotalSize = StringDataOffset;
491 TotalSize +=
N.size() + 1;
493 Out.
resize(StringDataOffset);
501 uint32_t CurrentOffset = StringDataOffset;
503 Entries[
I].OffsetToSymbol = CurrentOffset;
504 Entries[
I].SymbolSize = Names[
I].
size();
507 CurrentOffset += Names[
I].
size() + 1;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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 std::pair< std::string, std::string > getOffloadEntryBoundarySymbols(const Triple &T, StringRef SectionName)
Returns the start/end symbol names for iterating offloading entries in a given section.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
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, bool ByteString=false)
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(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
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
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 isOSBinFormatMachO() const
Tests whether the environment is MachO.
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()
@ 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 void writeSymbolTable(ArrayRef< StringRef > Names, SmallString< 0 > &Out)
Serialize Names into Out.
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 GlobalVariable * emitOffloadingEntry(Module &M, object::OffloadKind Kind, Constant *Addr, StringRef Name, uint64_t Size, uint32_t Flags, uint64_t Data, Constant *AuxAddr=nullptr)
LLVM_ABI std::pair< GlobalVariable *, GlobalVariable * > getOffloadEntryArray(Module &M)
Creates a pair of globals used to iterate the array of offloading entries by accessing the section va...
LLVM_ABI StringRef getOffloadEntrySection(Module &M)
Create an offloading section struct used to register this global at runtime.
This is an optimization pass for GlobalISel generic memory operations.
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
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
LLVM_ABI void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.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.