LLVM 22.0.0git
Utility.cpp
Go to the documentation of this file.
1//===- Utility.cpp ------ Collection of generic offloading utilities ------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
13#include "llvm/IR/Constants.h"
14#include "llvm/IR/GlobalValue.h"
16#include "llvm/IR/Value.h"
22
23using namespace llvm;
24using namespace llvm::offloading;
25
38
39std::pair<Constant *, GlobalVariable *>
41 Constant *Addr, StringRef Name,
42 uint64_t Size, uint32_t Flags,
43 uint64_t Data, Constant *AuxAddr) {
44 const llvm::Triple &Triple = M.getTargetTriple();
45 Type *PtrTy = PointerType::getUnqual(M.getContext());
46 Type *Int64Ty = Type::getInt64Ty(M.getContext());
47 Type *Int32Ty = Type::getInt32Ty(M.getContext());
48 Type *Int16Ty = Type::getInt16Ty(M.getContext());
49
50 Constant *AddrName = ConstantDataArray::getString(M.getContext(), Name);
51
52 StringRef Prefix =
53 Triple.isNVPTX() ? "$offloading$entry_name" : ".offloading.entry_name";
54
55 // Create the constant string used to look up the symbol in the device.
56 auto *Str =
57 new GlobalVariable(M, AddrName->getType(), /*isConstant=*/true,
58 GlobalValue::InternalLinkage, AddrName, Prefix);
59 StringRef SectionName = ".llvm.rodata.offloading";
60 Str->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
61 Str->setSection(SectionName);
62 Str->setAlignment(Align(1));
63
64 // Make a metadata node for these constants so it can be queried from IR.
65 NamedMDNode *MD = M.getOrInsertNamedMetadata("llvm.offloading.symbols");
66 Metadata *MDVals[] = {ConstantAsMetadata::get(Str)};
67 MD->addOperand(llvm::MDNode::get(M.getContext(), MDVals));
68
69 // Construct the offloading entry.
70 Constant *EntryData[] = {
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),
81 Constant *EntryInitializer = ConstantStruct::get(getEntryTy(M), EntryData);
82 return {EntryInitializer, Str};
83}
84
87 Constant *Addr, StringRef Name, uint64_t Size,
88 uint32_t Flags, uint64_t Data,
89 Constant *AuxAddr, StringRef SectionName) {
90 const llvm::Triple &Triple = M.getTargetTriple();
91
92 auto [EntryInitializer, NameGV] = getOffloadingEntryInitializer(
93 M, Kind, Addr, Name, Size, Flags, Data, AuxAddr);
94
95 StringRef Prefix =
96 Triple.isNVPTX() ? "$offloading$entry$" : ".offloading.entry.";
97 auto *Entry = new GlobalVariable(
98 M, getEntryTy(M),
99 /*isConstant=*/true, GlobalValue::WeakAnyLinkage, EntryInitializer,
100 Prefix + Name, nullptr, GlobalValue::NotThreadLocal,
101 M.getDataLayout().getDefaultGlobalsAddressSpace());
102
103 // The entry has to be created in the section the linker expects it to be.
105 Entry->setSection((SectionName + "$OE").str());
106 else
107 Entry->setSection(SectionName);
108 Entry->setAlignment(Align(object::OffloadBinary::getAlignment()));
109 return Entry;
110}
111
112std::pair<GlobalVariable *, GlobalVariable *>
114 const llvm::Triple &Triple = M.getTargetTriple();
115
116 auto *ZeroInitilaizer =
118 auto *EntryInit = Triple.isOSBinFormatCOFF() ? ZeroInitilaizer : nullptr;
119 auto *EntryType = ArrayType::get(getEntryTy(M), 0);
122
123 auto *EntriesB =
124 new GlobalVariable(M, EntryType, /*isConstant=*/true, Linkage, EntryInit,
125 "__start_" + SectionName);
126 EntriesB->setVisibility(GlobalValue::HiddenVisibility);
127 auto *EntriesE =
128 new GlobalVariable(M, EntryType, /*isConstant=*/true, Linkage, EntryInit,
129 "__stop_" + SectionName);
130 EntriesE->setVisibility(GlobalValue::HiddenVisibility);
131
132 if (Triple.isOSBinFormatELF()) {
133 // We assume that external begin/end symbols that we have created above will
134 // be defined by the linker. This is done whenever a section name with a
135 // valid C-identifier is present. We define a dummy variable here to force
136 // the linker to always provide these symbols.
137 auto *DummyEntry = new GlobalVariable(
138 M, ZeroInitilaizer->getType(), true, GlobalVariable::InternalLinkage,
139 ZeroInitilaizer, "__dummy." + SectionName);
140 DummyEntry->setSection(SectionName);
141 DummyEntry->setAlignment(Align(object::OffloadBinary::getAlignment()));
142 appendToCompilerUsed(M, DummyEntry);
143 } else {
144 // The COFF linker will merge sections containing a '$' together into a
145 // single section. The order of entries in this section will be sorted
146 // alphabetically by the characters following the '$' in the name. Set the
147 // sections here to ensure that the beginning and end symbols are sorted.
148 EntriesB->setSection((SectionName + "$OA").str());
149 EntriesE->setSection((SectionName + "$OZ").str());
150 }
151
152 return std::make_pair(EntriesB, EntriesE);
153}
154
156 uint32_t ImageFlags,
157 StringRef EnvTargetID) {
158 using namespace llvm::ELF;
159 StringRef EnvArch = EnvTargetID.split(":").first;
160
161 // Trivial check if the base processors match.
162 if (EnvArch != ImageArch)
163 return false;
164
165 // Check if the image is requesting xnack on or off.
166 switch (ImageFlags & EF_AMDGPU_FEATURE_XNACK_V4) {
168 // The image is 'xnack-' so the environment must be 'xnack-'.
169 if (!EnvTargetID.contains("xnack-"))
170 return false;
171 break;
173 // The image is 'xnack+' so the environment must be 'xnack+'.
174 if (!EnvTargetID.contains("xnack+"))
175 return false;
176 break;
179 default:
180 break;
181 }
182
183 // Check if the image is requesting sramecc on or off.
184 switch (ImageFlags & EF_AMDGPU_FEATURE_SRAMECC_V4) {
186 // The image is 'sramecc-' so the environment must be 'sramecc-'.
187 if (!EnvTargetID.contains("sramecc-"))
188 return false;
189 break;
191 // The image is 'sramecc+' so the environment must be 'sramecc+'.
192 if (!EnvTargetID.contains("sramecc+"))
193 return false;
194 break;
197 break;
198 }
199
200 return true;
201}
202
203namespace {
204/// Reads the AMDGPU specific per-kernel-metadata from an image.
205class KernelInfoReader {
206public:
208 : KernelInfoMap(KIM) {}
209
210 /// Process ELF note to read AMDGPU metadata from respective information
211 /// fields.
212 Error processNote(const llvm::object::ELF64LE::Note &Note, size_t Align) {
213 if (Note.getName() != "AMDGPU")
214 return Error::success(); // We are not interested in other things
215
216 assert(Note.getType() == ELF::NT_AMDGPU_METADATA &&
217 "Parse AMDGPU MetaData");
218 auto Desc = Note.getDesc(Align);
219 StringRef MsgPackString =
220 StringRef(reinterpret_cast<const char *>(Desc.data()), Desc.size());
221 msgpack::Document MsgPackDoc;
222 if (!MsgPackDoc.readFromBlob(MsgPackString, /*Multi=*/false))
223 return Error::success();
224
226 if (!Verifier.verify(MsgPackDoc.getRoot()))
227 return Error::success();
228
229 auto RootMap = MsgPackDoc.getRoot().getMap(true);
230
231 if (auto Err = iterateAMDKernels(RootMap))
232 return Err;
233
234 return Error::success();
235 }
236
237private:
238 /// Extracts the relevant information via simple string look-up in the msgpack
239 /// document elements.
240 Error
241 extractKernelData(msgpack::MapDocNode::MapTy::value_type V,
242 std::string &KernelName,
244 if (!V.first.isString())
245 return Error::success();
246
247 const auto IsKey = [](const msgpack::DocNode &DK, StringRef SK) {
248 return DK.getString() == SK;
249 };
250
251 const auto GetSequenceOfThreeInts = [](msgpack::DocNode &DN,
252 uint32_t *Vals) {
253 assert(DN.isArray() && "MsgPack DocNode is an array node");
254 auto DNA = DN.getArray();
255 assert(DNA.size() == 3 && "ArrayNode has at most three elements");
256
257 int I = 0;
258 for (auto DNABegin = DNA.begin(), DNAEnd = DNA.end(); DNABegin != DNAEnd;
259 ++DNABegin) {
260 Vals[I++] = DNABegin->getUInt();
261 }
262 };
263
264 if (IsKey(V.first, ".name")) {
265 KernelName = V.second.toString();
266 } else if (IsKey(V.first, ".sgpr_count")) {
267 KernelData.SGPRCount = V.second.getUInt();
268 } else if (IsKey(V.first, ".sgpr_spill_count")) {
269 KernelData.SGPRSpillCount = V.second.getUInt();
270 } else if (IsKey(V.first, ".vgpr_count")) {
271 KernelData.VGPRCount = V.second.getUInt();
272 } else if (IsKey(V.first, ".vgpr_spill_count")) {
273 KernelData.VGPRSpillCount = V.second.getUInt();
274 } else if (IsKey(V.first, ".agpr_count")) {
275 KernelData.AGPRCount = V.second.getUInt();
276 } else if (IsKey(V.first, ".private_segment_fixed_size")) {
277 KernelData.PrivateSegmentSize = V.second.getUInt();
278 } else if (IsKey(V.first, ".group_segment_fixed_size")) {
279 KernelData.GroupSegmentList = V.second.getUInt();
280 } else if (IsKey(V.first, ".reqd_workgroup_size")) {
281 GetSequenceOfThreeInts(V.second, KernelData.RequestedWorkgroupSize);
282 } else if (IsKey(V.first, ".workgroup_size_hint")) {
283 GetSequenceOfThreeInts(V.second, KernelData.WorkgroupSizeHint);
284 } else if (IsKey(V.first, ".wavefront_size")) {
285 KernelData.WavefrontSize = V.second.getUInt();
286 } else if (IsKey(V.first, ".max_flat_workgroup_size")) {
287 KernelData.MaxFlatWorkgroupSize = V.second.getUInt();
288 }
289
290 return Error::success();
291 }
292
293 /// Get the "amdhsa.kernels" element from the msgpack Document
294 Expected<msgpack::ArrayDocNode> getAMDKernelsArray(msgpack::MapDocNode &MDN) {
295 auto Res = MDN.find("amdhsa.kernels");
296 if (Res == MDN.end())
298 "Could not find amdhsa.kernels key");
299
300 auto Pair = *Res;
301 assert(Pair.second.isArray() &&
302 "AMDGPU kernel entries are arrays of entries");
303
304 return Pair.second.getArray();
305 }
306
307 /// Iterate all entries for one "amdhsa.kernels" entry. Each entry is a
308 /// MapDocNode that either maps a string to a single value (most of them) or
309 /// to another array of things. Currently, we only handle the case that maps
310 /// to scalar value.
311 Error generateKernelInfo(msgpack::ArrayDocNode::ArrayTy::iterator It) {
312 offloading::amdgpu::AMDGPUKernelMetaData KernelData;
313 std::string KernelName;
314 auto Entry = (*It).getMap();
315 for (auto MI = Entry.begin(), E = Entry.end(); MI != E; ++MI)
316 if (auto Err = extractKernelData(*MI, KernelName, KernelData))
317 return Err;
318
319 KernelInfoMap.insert({KernelName, KernelData});
320 return Error::success();
321 }
322
323 /// Go over the list of AMD kernels in the "amdhsa.kernels" entry
324 Error iterateAMDKernels(msgpack::MapDocNode &MDN) {
325 auto KernelsOrErr = getAMDKernelsArray(MDN);
326 if (auto Err = KernelsOrErr.takeError())
327 return Err;
328
329 auto KernelsArr = *KernelsOrErr;
330 for (auto It = KernelsArr.begin(), E = KernelsArr.end(); It != E; ++It) {
331 if (!It->isMap())
332 continue; // we expect <key,value> pairs
333
334 // Obtain the value for the different entries. Each array entry is a
335 // MapDocNode
336 if (auto Err = generateKernelInfo(It))
337 return Err;
338 }
339 return Error::success();
340 }
341
342 // Kernel names are the keys
343 StringMap<offloading::amdgpu::AMDGPUKernelMetaData> &KernelInfoMap;
344};
345} // namespace
346
348 MemoryBufferRef MemBuffer,
350 uint16_t &ELFABIVersion) {
351 Error Err = Error::success(); // Used later as out-parameter
352
353 auto ELFOrError = object::ELF64LEFile::create(MemBuffer.getBuffer());
354 if (auto Err = ELFOrError.takeError())
355 return Err;
356
357 const object::ELF64LEFile ELFObj = ELFOrError.get();
359 if (!Sections)
360 return Sections.takeError();
361 KernelInfoReader Reader(KernelInfoMap);
362
363 // Read the code object version from ELF image header
364 auto Header = ELFObj.getHeader();
365 ELFABIVersion = (uint8_t)(Header.e_ident[ELF::EI_ABIVERSION]);
366 for (const auto &S : *Sections) {
367 if (S.sh_type != ELF::SHT_NOTE)
368 continue;
369
370 for (const auto N : ELFObj.notes(S, Err)) {
371 if (Err)
372 return Err;
373 // Fills the KernelInfoTabel entries in the reader
374 if ((Err = Reader.processNote(N, S.sh_addralign)))
375 return Err;
376 }
377 }
378 return Error::success();
379}
381 std::unique_ptr<MemoryBuffer> &Img) {
382 constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] = "1.0";
383 constexpr int NT_INTEL_ONEOMP_OFFLOAD_VERSION = 1;
384 constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT = 2;
385 constexpr int NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX = 3;
386
387 // Start creating notes for the ELF container.
388 std::vector<ELFYAML::NoteEntry> Notes;
389 std::string Version = toHex(INTEL_ONEOMP_OFFLOAD_VERSION);
390 Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD",
392 NT_INTEL_ONEOMP_OFFLOAD_VERSION});
393
394 // The AuxInfo string will hold auxiliary information for the image.
395 // ELFYAML::NoteEntry structures will hold references to the
396 // string, so we have to make sure the string is valid.
397 std::string AuxInfo;
398
399 // TODO: Pass compile/link opts
400 StringRef CompileOpts = "";
401 StringRef LinkOpts = "";
402
403 unsigned ImageFmt = 1; // SPIR-V format
404
405 AuxInfo = toHex((Twine(0) + Twine('\0') + Twine(ImageFmt) + Twine('\0') +
406 CompileOpts + Twine('\0') + LinkOpts)
407 .str());
408 Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD",
409 yaml::BinaryRef(AuxInfo),
410 NT_INTEL_ONEOMP_OFFLOAD_IMAGE_AUX});
411
412 std::string ImgCount = toHex(Twine(1).str()); // always one image per ELF
413 Notes.emplace_back(ELFYAML::NoteEntry{"INTELONEOMPOFFLOAD",
414 yaml::BinaryRef(ImgCount),
415 NT_INTEL_ONEOMP_OFFLOAD_IMAGE_COUNT});
416
417 std::string YamlFile;
418 llvm::raw_string_ostream YamlFileStream(YamlFile);
419
420 // Write the YAML template file.
421
422 // We use 64-bit little-endian ELF currently.
423 ELFYAML::FileHeader Header{};
424 Header.Class = ELF::ELFCLASS64;
425 Header.Data = ELF::ELFDATA2LSB;
426 Header.Type = ELF::ET_DYN;
427 Header.Machine = ELF::EM_INTELGT;
428
429 // Create a section with notes.
430 ELFYAML::NoteSection Section{};
431 Section.Type = ELF::SHT_NOTE;
432 Section.AddressAlign = 0;
433 Section.Name = ".note.inteloneompoffload";
434 Section.Notes.emplace(std::move(Notes));
435
436 ELFYAML::Object Object{};
437 Object.Header = Header;
438 Object.Chunks.push_back(
439 std::make_unique<ELFYAML::NoteSection>(std::move(Section)));
440
441 // Create the section that will hold the image
442 ELFYAML::RawContentSection ImageSection{};
443 ImageSection.Type = ELF::SHT_PROGBITS;
444 ImageSection.AddressAlign = 0;
445 std::string Name = "__openmp_offload_spirv_0";
446 ImageSection.Name = Name;
447 ImageSection.Content =
449 Object.Chunks.push_back(
450 std::make_unique<ELFYAML::RawContentSection>(std::move(ImageSection)));
451 Error Err = Error::success();
453 Object, YamlFileStream,
454 [&Err](const Twine &Msg) { Err = createStringError(Msg); }, UINT64_MAX);
455 if (Err)
456 return Err;
457
458 Img = MemoryBuffer::getMemBufferCopy(YamlFile);
459 return Error::success();
460}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This is a verifier for AMDGPU HSA metadata, which can verify both well-typed metadata and untyped met...
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.
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:58
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 ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:536
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.
Definition Constant.h:43
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.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
@ HiddenVisibility
The GV is hidden.
Definition GlobalValue.h:69
@ InternalLinkage
Rename collisions when linking (static functions).
Definition GlobalValue.h:60
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition GlobalValue.h:58
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition GlobalValue.h:57
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1569
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.
Root of the metadata hierarchy.
Definition Metadata.h:64
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A tuple of MDNodes.
Definition Metadata.h:1757
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...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:702
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition StringRef.h:426
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.
Definition Type.cpp:739
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition Type.cpp:620
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition Triple.h:774
bool isNVPTX() const
Tests whether the target is NVPTX (32- or 64-bit).
Definition Triple.h:899
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition Triple.h:769
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:298
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:296
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
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
Definition ELF.h:284
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.
Definition ELF.h:467
Expected< Elf_Shdr_Range > sections() const
Definition ELF.h:930
static uint64_t getAlignment()
A raw_ostream that writes to an std::string.
Specialized YAMLIO scalar type for representing a binary blob.
Definition YAML.h:64
#define UINT64_MAX
Definition DataTypes.h:77
@ Entry
Definition COFF.h:862
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ EI_ABIVERSION
Definition ELF.h:59
@ EM_INTELGT
Definition ELF.h:306
@ SHT_PROGBITS
Definition ELF.h:1143
@ SHT_NOTE
Definition ELF.h:1149
@ ELFDATA2LSB
Definition ELF.h:340
@ ELFCLASS64
Definition ELF.h:334
@ ET_DYN
Definition ELF.h:121
@ EF_AMDGPU_FEATURE_XNACK_ANY_V4
Definition ELF.h:899
@ EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
Definition ELF.h:910
@ EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
Definition ELF.h:914
@ EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
Definition ELF.h:897
@ EF_AMDGPU_FEATURE_XNACK_OFF_V4
Definition ELF.h:901
@ EF_AMDGPU_FEATURE_XNACK_V4
Definition ELF.h:895
@ EF_AMDGPU_FEATURE_SRAMECC_V4
Definition ELF.h:908
@ EF_AMDGPU_FEATURE_XNACK_ON_V4
Definition ELF.h:903
@ EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
Definition ELF.h:912
@ EF_AMDGPU_FEATURE_SRAMECC_ON_V4
Definition ELF.h:916
@ NT_AMDGPU_METADATA
Definition ELF.h:1980
OffloadKind
The producer of the associated offloading image.
ELFFile< ELF64LE > ELF64LEFile
Definition ELF.h:533
LLVM_ABI Error getAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer, StringMap< AMDGPUKernelMetaData > &KernelInfoMap, uint16_t &ELFABIVersion)
Reads AMDGPU specific metadata from the ELF file and propagates the KernelInfoMap.
Definition Utility.cpp:347
LLVM_ABI bool isImageCompatibleWithEnv(StringRef ImageArch, uint32_t ImageFlags, StringRef EnvTargetID)
Check if an image is compatible with current system's environment.
Definition Utility.cpp:155
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...
Definition Utility.cpp:380
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.
Definition Utility.cpp:86
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.
Definition Utility.cpp:40
LLVM_ABI StructType * getEntryTy(Module &M)
Returns the type of the offloading entry we use to store kernels and globals that will be registered ...
Definition Utility.cpp:26
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...
Definition Utility.cpp:113
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.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty
Definition InstrProf.h:296
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:98
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305
Op::Description Desc
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:302
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)
Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
llvm::yaml::Hex64 AddressAlign
Definition ELFYAML.h:271
std::optional< yaml::BinaryRef > Content
Definition ELFYAML.h:274
Elf_Note_Impl< ELFType< E, Is64 > > Note
Definition ELFTypes.h:78
This is the record of an object that just be registered with the offloading runtime.
Definition Utility.h:28
Struct for holding metadata related to AMDGPU kernels, for more information about the metadata and it...
Definition Utility.h:121
uint32_t SGPRSpillCount
Number of stores from a scalar register to a register allocator created spill location.
Definition Utility.h:136
uint32_t SGPRCount
Number of scalar registers required by a wavefront.
Definition Utility.h:131
uint32_t VGPRSpillCount
Number of stores from a vector register to a register allocator created spill location.
Definition Utility.h:139
uint32_t VGPRCount
Number of vector registers required by each work-item.
Definition Utility.h:133
uint32_t PrivateSegmentSize
The amount of fixed private address space memory required for a work-item in bytes.
Definition Utility.h:129
uint32_t GroupSegmentList
The amount of group segment memory required by a work-group in bytes.
Definition Utility.h:126
uint32_t MaxFlatWorkgroupSize
Maximum flat work-group size supported by the kernel in work-items.
Definition Utility.h:150
uint32_t WorkgroupSizeHint[3]
Corresponds to the OpenCL work_group_size_hint attribute.
Definition Utility.h:146
uint32_t AGPRCount
Number of accumulator registers required by each work-item.
Definition Utility.h:141
uint32_t RequestedWorkgroupSize[3]
Corresponds to the OpenCL reqd_work_group_size attribute.
Definition Utility.h:143
Common declarations for yaml2obj.