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);
182 return std::make_pair(EntriesB, EntriesE);
192 if (EnvArch != ImageArch)
199 if (!EnvTargetID.
contains(
"xnack-"))
204 if (!EnvTargetID.
contains(
"xnack+"))
217 if (!EnvTargetID.
contains(
"sramecc-"))
222 if (!EnvTargetID.
contains(
"sramecc+"))
235class KernelInfoReader {
238 : KernelInfoMap(KIM) {}
243 if (
Note.getName() !=
"AMDGPU")
247 "Parse AMDGPU MetaData");
256 if (!Verifier.verify(MsgPackDoc.
getRoot()))
261 if (
auto Err = iterateAMDKernels(RootMap))
271 extractKernelData(msgpack::MapDocNode::MapTy::value_type V,
272 std::string &KernelName,
274 if (!V.first.isString())
281 const auto GetSequenceOfThreeInts = [](msgpack::DocNode &DN,
285 assert(DNA.size() == 3 &&
"ArrayNode has at most three elements");
288 for (
auto DNABegin = DNA.begin(), DNAEnd = DNA.end(); DNABegin != DNAEnd;
290 Vals[
I++] = DNABegin->getUInt();
294 if (IsKey(
V.first,
".name")) {
295 KernelName =
V.second.toString();
296 }
else if (IsKey(
V.first,
".sgpr_count")) {
298 }
else if (IsKey(
V.first,
".sgpr_spill_count")) {
300 }
else if (IsKey(
V.first,
".vgpr_count")) {
302 }
else if (IsKey(
V.first,
".vgpr_spill_count")) {
304 }
else if (IsKey(
V.first,
".agpr_count")) {
306 }
else if (IsKey(
V.first,
".private_segment_fixed_size")) {
308 }
else if (IsKey(
V.first,
".group_segment_fixed_size")) {
310 }
else if (IsKey(
V.first,
".reqd_workgroup_size")) {
312 }
else if (IsKey(
V.first,
".workgroup_size_hint")) {
314 }
else if (IsKey(
V.first,
".wavefront_size")) {
316 }
else if (IsKey(
V.first,
".max_flat_workgroup_size")) {
324 Expected<msgpack::ArrayDocNode> getAMDKernelsArray(msgpack::MapDocNode &MDN) {
325 auto Res = MDN.
find(
"amdhsa.kernels");
326 if (Res == MDN.
end())
328 "Could not find amdhsa.kernels key");
331 assert(Pair.second.isArray() &&
332 "AMDGPU kernel entries are arrays of entries");
334 return Pair.second.getArray();
341 Error generateKernelInfo(msgpack::ArrayDocNode::ArrayTy::iterator It) {
342 offloading::amdgpu::AMDGPUKernelMetaData KernelData;
343 std::string KernelName;
344 auto Entry = (*It).getMap();
346 if (
auto Err = extractKernelData(*
MI, KernelName, KernelData))
349 KernelInfoMap.insert({KernelName, KernelData});
354 Error iterateAMDKernels(msgpack::MapDocNode &MDN) {
355 auto KernelsOrErr = getAMDKernelsArray(MDN);
356 if (
auto Err = KernelsOrErr.takeError())
359 auto KernelsArr = *KernelsOrErr;
360 for (
auto It = KernelsArr.begin(),
E = KernelsArr.end(); It !=
E; ++It) {
366 if (
auto Err = generateKernelInfo(It))
373 StringMap<offloading::amdgpu::AMDGPUKernelMetaData> &KernelInfoMap;
384 if (
auto Err = ELFOrError.takeError())
391 KernelInfoReader Reader(KernelInfoMap);
396 for (
const auto &S : *Sections) {
400 for (
const auto N : ELFObj.
notes(S, Err)) {
404 if ((Err = Reader.processNote(
N, S.sh_addralign)))
420 OffloadBinary::OffloadingImage InnerImage;
421 InnerImage.TheImageKind = ImageKind;
422 InnerImage.TheOffloadKind = OffloadKind;
423 InnerImage.Flags = ImageFlags;
426 for (
const auto &[
Key,
Value] : MetaData)
429 InnerImage.Image = std::move(Img);
431 SmallString<0> InnerBinaryData = OffloadBinary::write(InnerImage);
440 constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] =
"1.0";
443 "Expected SPIR-V triple with Intel vendor");
446 MetaData[
"version"] = INTEL_ONEOMP_OFFLOAD_VERSION;
447 if (!CompileOpts.
empty())
448 MetaData[
"compile-opts"] = CompileOpts;
449 if (!LinkOpts.
empty())
450 MetaData[
"link-opts"] = LinkOpts;
467 Out.
resize(StringDataOffset);
475 uint32_t CurrentOffset = StringDataOffset;
477 Entries[
I].OffsetToSymbol = CurrentOffset;
478 Entries[
I].SymbolSize = Names[
I].
size();
481 CurrentOffset += Names[
I].
size() + 1;
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 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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - 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(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...
void append(StringRef RHS)
Append from a StringRef.
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",...
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 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()
@ 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 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.
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.
FunctionAddr VTableAddr Count
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.