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());
135 constexpr unsigned COFFSentinelEntryCount = 1;
136 unsigned EntryCount =
138 auto *ZeroInitializer =
141 auto *EntryType = ZeroInitializer->getType();
145 auto [StartName, StopName] =
149 Linkage, EntryInit, StartName);
152 Linkage, EntryInit, StopName);
192 Constant *Indices[] = {ConstantInt::get(Int32Ty, 0),
193 ConstantInt::get(Int32Ty, COFFSentinelEntryCount)};
195 EntriesB->getValueType(), EntriesB, Indices);
196 return std::make_pair(BeginAfterSentinel, EntriesE);
199 return std::make_pair(EntriesB, EntriesE);
209 if (EnvArch != ImageArch)
216 if (!EnvTargetID.
contains(
"xnack-"))
221 if (!EnvTargetID.
contains(
"xnack+"))
234 if (!EnvTargetID.
contains(
"sramecc-"))
239 if (!EnvTargetID.
contains(
"sramecc+"))
252class KernelInfoReader {
255 : KernelInfoMap(KIM) {}
260 if (
Note.getName() !=
"AMDGPU")
264 "Parse AMDGPU MetaData");
273 if (!Verifier.verify(MsgPackDoc.
getRoot()))
278 if (
auto Err = iterateAMDKernels(RootMap))
288 extractKernelData(msgpack::MapDocNode::MapTy::value_type V,
289 std::string &KernelName,
291 if (!V.first.isString())
298 const auto GetSequenceOfThreeInts = [](msgpack::DocNode &DN,
302 assert(DNA.size() == 3 &&
"ArrayNode has at most three elements");
305 for (
auto DNABegin = DNA.begin(), DNAEnd = DNA.end(); DNABegin != DNAEnd;
307 Vals[
I++] = DNABegin->getUInt();
311 if (IsKey(
V.first,
".name")) {
312 KernelName =
V.second.toString();
313 }
else if (IsKey(
V.first,
".sgpr_count")) {
315 }
else if (IsKey(
V.first,
".sgpr_spill_count")) {
317 }
else if (IsKey(
V.first,
".vgpr_count")) {
319 }
else if (IsKey(
V.first,
".vgpr_spill_count")) {
321 }
else if (IsKey(
V.first,
".agpr_count")) {
323 }
else if (IsKey(
V.first,
".private_segment_fixed_size")) {
325 }
else if (IsKey(
V.first,
".group_segment_fixed_size")) {
327 }
else if (IsKey(
V.first,
".reqd_workgroup_size")) {
329 }
else if (IsKey(
V.first,
".workgroup_size_hint")) {
331 }
else if (IsKey(
V.first,
".wavefront_size")) {
333 }
else if (IsKey(
V.first,
".max_flat_workgroup_size")) {
335 }
else if (IsKey(
V.first,
".args")) {
336 auto ArgsArray =
V.second.getArray();
337 for (
auto ArgIt = ArgsArray.begin(), ArgEnd = ArgsArray.end();
338 ArgIt != ArgEnd; ++ArgIt) {
339 auto ArgMap = ArgIt->getMap();
341 auto OffsetIt = ArgMap.find(
".offset");
342 if (OffsetIt == ArgMap.end())
345 "Missing required .offset key in kernel argument metadata map");
347 auto SizeIt = ArgMap.find(
".size");
348 if (SizeIt == ArgMap.end())
351 "Missing required .size key in kernel argument metadata map");
354 SizeIt->second.getUInt());
362 Expected<msgpack::ArrayDocNode> getAMDKernelsArray(msgpack::MapDocNode &MDN) {
363 auto Res = MDN.
find(
"amdhsa.kernels");
364 if (Res == MDN.
end())
366 "Could not find amdhsa.kernels key");
369 assert(Pair.second.isArray() &&
370 "AMDGPU kernel entries are arrays of entries");
372 return Pair.second.getArray();
379 Error generateKernelInfo(msgpack::ArrayDocNode::ArrayTy::iterator It) {
380 offloading::amdgpu::AMDGPUKernelMetaData KernelData;
381 std::string KernelName;
382 auto Entry = (*It).getMap();
384 if (
auto Err = extractKernelData(*
MI, KernelName, KernelData))
387 KernelInfoMap.insert({KernelName, KernelData});
392 Error iterateAMDKernels(msgpack::MapDocNode &MDN) {
393 auto KernelsOrErr = getAMDKernelsArray(MDN);
394 if (
auto Err = KernelsOrErr.takeError())
397 auto KernelsArr = *KernelsOrErr;
398 for (
auto It = KernelsArr.begin(),
E = KernelsArr.end(); It !=
E; ++It) {
404 if (
auto Err = generateKernelInfo(It))
411 StringMap<offloading::amdgpu::AMDGPUKernelMetaData> &KernelInfoMap;
422 if (
auto Err = ELFOrError.takeError())
429 KernelInfoReader Reader(KernelInfoMap);
434 for (
const auto &S : *Sections) {
438 for (
const auto N : ELFObj.
notes(S, Err)) {
442 if ((Err = Reader.processNote(
N, S.sh_addralign)))
458 OffloadBinary::OffloadingImage InnerImage;
459 InnerImage.TheImageKind = ImageKind;
460 InnerImage.TheOffloadKind = OffloadKind;
461 InnerImage.Flags = ImageFlags;
464 for (
const auto &[
Key,
Value] : MetaData)
467 InnerImage.Image = std::move(Img);
469 SmallString<0> InnerBinaryData = OffloadBinary::write(InnerImage);
478 constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] =
"1.0";
481 "Expected SPIR-V triple with Intel vendor");
484 MetaData[
"version"] = INTEL_ONEOMP_OFFLOAD_VERSION;
485 if (!CompileOpts.
empty())
486 MetaData[
"compile-opts"] = CompileOpts;
487 if (!LinkOpts.
empty())
488 MetaData[
"link-opts"] = LinkOpts;
505 uint32_t TotalSize = StringDataOffset;
507 TotalSize +=
N.size() + 1;
509 Out.
resize(StringDataOffset);
517 uint32_t CurrentOffset = StringDataOffset;
519 Entries[
I].OffsetToSymbol = CurrentOffset;
520 Entries[
I].SymbolSize = Names[
I].
size();
523 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 Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
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 std::pair< Constant *, Constant * > getOffloadEntryArray(Module &M)
Creates a pair of constants used to iterate the array of offloading entries by accessing the section ...
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 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.