35 PointerType::getUnqual(
C));
39std::pair<Constant *, GlobalVariable *>
45 Type *PtrTy = PointerType::getUnqual(M.getContext());
53 Triple.
isNVPTX() ?
"$offloading$entry_name" :
".offloading.entry_name";
60 Str->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
62 Str->setAlignment(
Align(1));
65 NamedMDNode *MD = M.getOrInsertNamedMetadata(
"llvm.offloading.symbols");
71 ConstantExpr::getNullValue(Int64Ty),
72 ConstantInt::get(Int16Ty, 1),
73 ConstantInt::get(Int16Ty, Kind),
74 ConstantInt::get(Int32Ty, Flags),
77 ConstantInt::get(Int64Ty,
Size),
78 ConstantInt::get(Int64Ty, Data),
80 : ConstantExpr::getNullValue(PtrTy)};
82 return {EntryInitializer, Str};
96 Triple.
isNVPTX() ?
"$offloading$entry$" :
".offloading.entry.";
101 M.getDataLayout().getDefaultGlobalsAddressSpace());
111std::pair<GlobalVariable *, GlobalVariable *>
115 auto *ZeroInitilaizer =
118 auto *EntryType = ArrayType::get(
getEntryTy(M), 0);
137 M, ZeroInitilaizer->getType(),
true, GlobalVariable::InternalLinkage,
151 return std::make_pair(EntriesB, EntriesE);
161 if (EnvArch != ImageArch)
165 switch (ImageFlags & EF_AMDGPU_FEATURE_XNACK_V4) {
166 case EF_AMDGPU_FEATURE_XNACK_OFF_V4:
168 if (!EnvTargetID.
contains(
"xnack-"))
171 case EF_AMDGPU_FEATURE_XNACK_ON_V4:
173 if (!EnvTargetID.
contains(
"xnack+"))
176 case EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4:
177 case EF_AMDGPU_FEATURE_XNACK_ANY_V4:
183 switch (ImageFlags & EF_AMDGPU_FEATURE_SRAMECC_V4) {
184 case EF_AMDGPU_FEATURE_SRAMECC_OFF_V4:
186 if (!EnvTargetID.
contains(
"sramecc-"))
189 case EF_AMDGPU_FEATURE_SRAMECC_ON_V4:
191 if (!EnvTargetID.
contains(
"sramecc+"))
194 case EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4:
195 case EF_AMDGPU_FEATURE_SRAMECC_ANY_V4:
204class KernelInfoReader {
207 : KernelInfoMap(KIM) {}
212 if (
Note.getName() !=
"AMDGPU")
216 "Parse AMDGPU MetaData");
230 if (
auto Err = iterateAMDKernels(RootMap))
240 extractKernelData(msgpack::MapDocNode::MapTy::value_type V,
241 std::string &KernelName,
243 if (!V.first.isString())
254 assert(DNA.size() == 3 &&
"ArrayNode has at most three elements");
257 for (
auto DNABegin = DNA.begin(), DNAEnd = DNA.end(); DNABegin != DNAEnd;
259 Vals[
I++] = DNABegin->getUInt();
263 if (IsKey(
V.first,
".name")) {
264 KernelName =
V.second.toString();
265 }
else if (IsKey(
V.first,
".sgpr_count")) {
267 }
else if (IsKey(
V.first,
".sgpr_spill_count")) {
269 }
else if (IsKey(
V.first,
".vgpr_count")) {
271 }
else if (IsKey(
V.first,
".vgpr_spill_count")) {
273 }
else if (IsKey(
V.first,
".agpr_count")) {
275 }
else if (IsKey(
V.first,
".private_segment_fixed_size")) {
277 }
else if (IsKey(
V.first,
".group_segment_fixed_size")) {
279 }
else if (IsKey(
V.first,
".reqd_workgroup_size")) {
281 }
else if (IsKey(
V.first,
".workgroup_size_hint")) {
283 }
else if (IsKey(
V.first,
".wavefront_size")) {
285 }
else if (IsKey(
V.first,
".max_flat_workgroup_size")) {
294 auto Res = MDN.
find(
"amdhsa.kernels");
295 if (Res == MDN.
end())
297 "Could not find amdhsa.kernels key");
300 assert(Pair.second.isArray() &&
301 "AMDGPU kernel entries are arrays of entries");
303 return Pair.second.getArray();
310 Error generateKernelInfo(msgpack::ArrayDocNode::ArrayTy::iterator It) {
312 std::string KernelName;
313 auto Entry = (*It).getMap();
315 if (
auto Err = extractKernelData(*
MI, KernelName, KernelData))
318 KernelInfoMap.insert({KernelName, KernelData});
324 auto KernelsOrErr = getAMDKernelsArray(MDN);
325 if (
auto Err = KernelsOrErr.takeError())
328 auto KernelsArr = *KernelsOrErr;
329 for (
auto It = KernelsArr.begin(), E = KernelsArr.end(); It != E; ++It) {
335 if (
auto Err = generateKernelInfo(It))
353 if (
auto Err = ELFOrError.takeError())
360 KernelInfoReader Reader(KernelInfoMap);
365 for (
const auto &S : *Sections) {
369 for (
const auto N : ELFObj.
notes(S, Err)) {
373 if ((Err = Reader.processNote(
N, S.sh_addralign)))
380 std::unique_ptr<MemoryBuffer> &Img) {
381 constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] =
"1.0";
382 constexpr int NT_INTEL_ONEOMP_OFFLOAD_VERSION = 1;
383 constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT = 2;
384 constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX = 3;
387 std::vector<ELFYAML::NoteEntry> Notes;
388 std::string Version = toHex(INTEL_ONEOMP_OFFLOAD_VERSION);
391 NT_INTEL_ONEOMP_OFFLOAD_VERSION});
402 unsigned ImageFmt = 1;
405 CompileOpts +
Twine(
'\0') + LinkOpts)
409 NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX});
411 std::string ImgCount = toHex(
Twine(1).str());
414 NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT});
416 std::string YamlFile;
433 Section.AddressAlign = 0;
434 Section.Name =
".note.inteloneompoffload";
435 Section.Notes.emplace(std::move(Notes));
438 Object.Header = Header;
439 Object.Chunks.push_back(
440 std::make_unique<ELFYAML::NoteSection>(std::move(Section)));
445 ImageSection.AddressAlign = 0;
446 std::string
Name =
"__openmp_offload_spirv_0";
447 ImageSection.Name =
Name;
448 ImageSection.Content =
450 Object.Chunks.push_back(
451 std::make_unique<ELFYAML::RawContentSection>(std::move(ImageSection)));
454 Object, YamlFileStream,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 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.
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)
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)
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 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.
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt16Ty(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.
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()
A raw_ostream that writes to an std::string.
Specialized YAMLIO scalar type for representing a binary blob.
@ C
The default llvm calling convention, compatible with C.
OffloadKind
The producer of the associated offloading image.
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)
Containerizes an offloading binary into the ELF binary format expected by the Intel runtime offload p...
LLVM_ABI void 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 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...
LLVM_ABI bool yaml2elf(ELFYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH, uint64_t MaxSize)
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_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.
Description of the encoding of one expression Op.
This is the record of an object that just be registered with the offloading runtime.
Common declarations for yaml2obj.