LLVM 24.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;
25using namespace llvm::offloading::sycl;
26
39
40std::pair<Constant *, GlobalVariable *>
42 Constant *Addr, StringRef Name,
43 uint64_t Size, uint32_t Flags,
44 uint64_t Data, Constant *AuxAddr) {
45 const llvm::Triple &Triple = M.getTargetTriple();
46 Type *PtrTy = PointerType::getUnqual(M.getContext());
47 Type *Int64Ty = Type::getInt64Ty(M.getContext());
48 Type *Int32Ty = Type::getInt32Ty(M.getContext());
49 Type *Int16Ty = Type::getInt16Ty(M.getContext());
50
51 Constant *AddrName = ConstantDataArray::getString(M.getContext(), Name);
52
53 StringRef Prefix =
54 Triple.isNVPTX() ? "$offloading$entry_name" : ".offloading.entry_name";
55
56 // Create the constant string used to look up the symbol in the device.
57 auto *Str =
58 new GlobalVariable(M, AddrName->getType(), /*isConstant=*/true,
59 GlobalValue::InternalLinkage, AddrName, Prefix);
60 StringRef SectionName = ".llvm.rodata.offloading";
61 Str->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
62 Str->setSection(SectionName);
63 Str->setAlignment(Align(1));
64
65 // Make a metadata node for these constants so it can be queried from IR.
66 NamedMDNode *MD = M.getOrInsertNamedMetadata("llvm.offloading.symbols");
67 Metadata *MDVals[] = {ConstantAsMetadata::get(Str)};
68 MD->addOperand(llvm::MDNode::get(M.getContext(), MDVals));
69
70 // Construct the offloading entry.
71 Constant *EntryData[] = {
73 ConstantInt::get(Int16Ty, 1),
74 ConstantInt::get(Int16Ty, Kind),
75 ConstantInt::get(Int32Ty, Flags),
78 ConstantInt::get(Int64Ty, Size),
79 ConstantInt::get(Int64Ty, Data),
82 Constant *EntryInitializer = ConstantStruct::get(getEntryTy(M), EntryData);
83 return {EntryInitializer, Str};
84}
85
87 return M.getTargetTriple().isOSBinFormatMachO() ? "__LLVM,offload_entries"
88 : "llvm_offload_entries";
89}
90
91/// Returns the start/end symbol names for iterating offloading entries in a
92/// given section. Mach-O uses \1section$start$/\1section$end$ convention;
93/// ELF/COFF use __start_/__stop_ prefixes.
94static std::pair<std::string, std::string>
96 if (T.isOSBinFormatMachO()) {
97 std::string SymSection = SectionName.str();
98 std::replace(SymSection.begin(), SymSection.end(), ',', '$');
99 return {"\1section$start$" + SymSection, "\1section$end$" + SymSection};
100 }
101 return {("__start_" + SectionName).str(), ("__stop_" + SectionName).str()};
102}
103
105 Module &M, object::OffloadKind Kind, Constant *Addr, StringRef Name,
106 uint64_t Size, uint32_t Flags, uint64_t Data, Constant *AuxAddr) {
107 const llvm::Triple &Triple = M.getTargetTriple();
109
110 auto [EntryInitializer, NameGV] = getOffloadingEntryInitializer(
111 M, Kind, Addr, Name, Size, Flags, Data, AuxAddr);
112
113 StringRef Prefix =
114 Triple.isNVPTX() ? "$offloading$entry$" : ".offloading.entry.";
115 auto *Entry = new GlobalVariable(
116 M, getEntryTy(M),
117 /*isConstant=*/true, GlobalValue::WeakAnyLinkage, EntryInitializer,
118 Prefix + Name, nullptr, GlobalValue::NotThreadLocal,
119 M.getDataLayout().getDefaultGlobalsAddressSpace());
120
121 // The entry has to be created in the section the linker expects it to be.
123 Entry->setSection((SectionName + "$OE").str());
124 else
125 Entry->setSection(SectionName);
126 Entry->setAlignment(Align(object::OffloadBinary::getAlignment()));
127 return Entry;
128}
129
130std::pair<Constant *, Constant *> offloading::getOffloadEntryArray(Module &M) {
131 const llvm::Triple &Triple = M.getTargetTriple();
133
134 constexpr unsigned COFFSentinelEntryCount = 1;
135 unsigned EntryCount =
136 Triple.isOSBinFormatCOFF() ? COFFSentinelEntryCount : 0u;
137 auto *ZeroInitializer =
139 auto *EntryInit = Triple.isOSBinFormatCOFF() ? ZeroInitializer : nullptr;
140 auto *EntryType = ZeroInitializer->getType();
143
144 auto [StartName, StopName] =
146
147 auto *EntriesB = new GlobalVariable(M, EntryType, /*isConstant=*/true,
148 Linkage, EntryInit, StartName);
149 EntriesB->setVisibility(GlobalValue::HiddenVisibility);
150 auto *EntriesE = new GlobalVariable(M, EntryType, /*isConstant=*/true,
151 Linkage, EntryInit, StopName);
152 EntriesE->setVisibility(GlobalValue::HiddenVisibility);
153
154 if (Triple.isOSBinFormatELF()) {
155 // We assume that external begin/end symbols that we have created above will
156 // be defined by the linker. This is done whenever a section name with a
157 // valid C-identifier is present. We define a dummy variable here to force
158 // the linker to always provide these symbols.
159 auto *DummyEntry = new GlobalVariable(
160 M, ZeroInitializer->getType(), true, GlobalVariable::InternalLinkage,
161 ZeroInitializer, "__dummy." + SectionName);
162 DummyEntry->setSection(SectionName);
163 DummyEntry->setAlignment(Align(object::OffloadBinary::getAlignment()));
164 appendToUsed(M, DummyEntry);
165 } else if (Triple.isOSBinFormatMachO()) {
166 // Mach-O needs a dummy variable in the section (like ELF) to ensure the
167 // linker provides the section boundary symbols. Mark it used so the
168 // section survives dead-stripping.
169 auto *DummyEntry = new GlobalVariable(
170 M, ZeroInitializer->getType(), true, GlobalVariable::InternalLinkage,
171 ZeroInitializer, "__dummy." + SectionName);
172 DummyEntry->setSection(SectionName);
173 DummyEntry->setAlignment(Align(object::OffloadBinary::getAlignment()));
174 appendToUsed(M, DummyEntry);
175 } else {
176 // The COFF linker will merge sections containing a '$' together into a
177 // single section. The order of entries in this section will be sorted
178 // alphabetically by the characters following the '$' in the name. Set the
179 // sections here to ensure that the beginning and end symbols are sorted.
180 EntriesB->setSection((SectionName + "$OA").str());
181 EntriesE->setSection((SectionName + "$OZ").str());
182 EntriesB->setAlignment(Align(object::OffloadBinary::getAlignment()));
183 EntriesE->setAlignment(Align(object::OffloadBinary::getAlignment()));
184
185 // COFF lays out offload entries by sorted subsections: $OA is a synthetic
186 // begin sentinel, $OE contains real entries, and $OZ is a synthetic end
187 // sentinel. Keep the boundary sections non-empty so lld-link does not
188 // discard them under /opt:ref, but skip the begin sentinel for runtime
189 // users.
190 Type *Int32Ty = Type::getInt32Ty(M.getContext());
191 Constant *Indices[] = {ConstantInt::get(Int32Ty, 0),
192 ConstantInt::get(Int32Ty, COFFSentinelEntryCount)};
193 Constant *BeginAfterSentinel = ConstantExpr::getGetElementPtr(
194 M.getDataLayout(), EntriesB->getValueType(), EntriesB, Indices,
196 return std::make_pair(BeginAfterSentinel, EntriesE);
197 }
198
199 return std::make_pair(EntriesB, EntriesE);
200}
201
203 uint32_t ImageFlags,
204 StringRef EnvTargetID) {
205 using namespace llvm::ELF;
206 StringRef EnvArch = EnvTargetID.split(":").first;
207
208 // Trivial check if the base processors match.
209 if (EnvArch != ImageArch)
210 return false;
211
212 // Check if the image is requesting xnack on or off.
213 switch (ImageFlags & EF_AMDGPU_FEATURE_XNACK_V4) {
215 // The image is 'xnack-' so the environment must be 'xnack-'.
216 if (!EnvTargetID.contains("xnack-"))
217 return false;
218 break;
220 // The image is 'xnack+' so the environment must be 'xnack+'.
221 if (!EnvTargetID.contains("xnack+"))
222 return false;
223 break;
226 default:
227 break;
228 }
229
230 // Check if the image is requesting sramecc on or off.
231 switch (ImageFlags & EF_AMDGPU_FEATURE_SRAMECC_V4) {
233 // The image is 'sramecc-' so the environment must be 'sramecc-'.
234 if (!EnvTargetID.contains("sramecc-"))
235 return false;
236 break;
238 // The image is 'sramecc+' so the environment must be 'sramecc+'.
239 if (!EnvTargetID.contains("sramecc+"))
240 return false;
241 break;
244 break;
245 }
246
247 return true;
248}
249
250namespace {
251/// Reads the AMDGPU specific per-kernel-metadata from an image.
252class KernelInfoReader {
253public:
255 : KernelInfoMap(KIM) {}
256
257 /// Process ELF note to read AMDGPU metadata from respective information
258 /// fields.
259 Error processNote(const llvm::object::ELF64LE::Note &Note, size_t Align) {
260 if (Note.getName() != "AMDGPU")
261 return Error::success(); // We are not interested in other things
262
263 assert(Note.getType() == ELF::NT_AMDGPU_METADATA &&
264 "Parse AMDGPU MetaData");
265 auto Desc = Note.getDesc(Align);
266 StringRef MsgPackString =
267 StringRef(reinterpret_cast<const char *>(Desc.data()), Desc.size());
268 msgpack::Document MsgPackDoc;
269 if (!MsgPackDoc.readFromBlob(MsgPackString, /*Multi=*/false))
270 return Error::success();
271
273 if (!Verifier.verify(MsgPackDoc.getRoot()))
274 return Error::success();
275
276 auto RootMap = MsgPackDoc.getRoot().getMap(true);
277
278 if (auto Err = iterateAMDKernels(RootMap))
279 return Err;
280
281 return Error::success();
282 }
283
284private:
285 /// Extracts the relevant information via simple string look-up in the msgpack
286 /// document elements.
287 Error
288 extractKernelData(msgpack::MapDocNode::MapTy::value_type V,
289 std::string &KernelName,
291 if (!V.first.isString())
292 return Error::success();
293
294 const auto IsKey = [](const msgpack::DocNode &DK, StringRef SK) {
295 return DK.getString() == SK;
296 };
297
298 const auto GetSequenceOfThreeInts = [](msgpack::DocNode &DN,
299 uint32_t *Vals) {
300 assert(DN.isArray() && "MsgPack DocNode is an array node");
301 auto DNA = DN.getArray();
302 assert(DNA.size() == 3 && "ArrayNode has at most three elements");
303
304 int I = 0;
305 for (auto DNABegin = DNA.begin(), DNAEnd = DNA.end(); DNABegin != DNAEnd;
306 ++DNABegin) {
307 Vals[I++] = DNABegin->getUInt();
308 }
309 };
310
311 if (IsKey(V.first, ".name")) {
312 KernelName = V.second.toString();
313 } else if (IsKey(V.first, ".sgpr_count")) {
314 KernelData.SGPRCount = V.second.getUInt();
315 } else if (IsKey(V.first, ".sgpr_spill_count")) {
316 KernelData.SGPRSpillCount = V.second.getUInt();
317 } else if (IsKey(V.first, ".vgpr_count")) {
318 KernelData.VGPRCount = V.second.getUInt();
319 } else if (IsKey(V.first, ".vgpr_spill_count")) {
320 KernelData.VGPRSpillCount = V.second.getUInt();
321 } else if (IsKey(V.first, ".agpr_count")) {
322 KernelData.AGPRCount = V.second.getUInt();
323 } else if (IsKey(V.first, ".private_segment_fixed_size")) {
324 KernelData.PrivateSegmentSize = V.second.getUInt();
325 } else if (IsKey(V.first, ".group_segment_fixed_size")) {
326 KernelData.GroupSegmentList = V.second.getUInt();
327 } else if (IsKey(V.first, ".reqd_workgroup_size")) {
328 GetSequenceOfThreeInts(V.second, KernelData.RequestedWorkgroupSize);
329 } else if (IsKey(V.first, ".workgroup_size_hint")) {
330 GetSequenceOfThreeInts(V.second, KernelData.WorkgroupSizeHint);
331 } else if (IsKey(V.first, ".wavefront_size")) {
332 KernelData.WavefrontSize = V.second.getUInt();
333 } else if (IsKey(V.first, ".max_flat_workgroup_size")) {
334 KernelData.MaxFlatWorkgroupSize = V.second.getUInt();
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();
340
341 auto OffsetIt = ArgMap.find(".offset");
342 if (OffsetIt == ArgMap.end())
343 return createStringError(
345 "Missing required .offset key in kernel argument metadata map");
346
347 auto SizeIt = ArgMap.find(".size");
348 if (SizeIt == ArgMap.end())
349 return createStringError(
351 "Missing required .size key in kernel argument metadata map");
352
353 KernelData.ArgMDs.emplace_back(OffsetIt->second.getUInt(),
354 SizeIt->second.getUInt());
355 }
356 }
357
358 return Error::success();
359 }
360
361 /// Get the "amdhsa.kernels" element from the msgpack Document
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");
367
368 auto Pair = *Res;
369 assert(Pair.second.isArray() &&
370 "AMDGPU kernel entries are arrays of entries");
371
372 return Pair.second.getArray();
373 }
374
375 /// Iterate all entries for one "amdhsa.kernels" entry. Each entry is a
376 /// MapDocNode that either maps a string to a single value (most of them) or
377 /// to another array of things. Currently, we only handle the case that maps
378 /// to scalar value.
379 Error generateKernelInfo(msgpack::ArrayDocNode::ArrayTy::iterator It) {
380 offloading::amdgpu::AMDGPUKernelMetaData KernelData;
381 std::string KernelName;
382 auto Entry = (*It).getMap();
383 for (auto MI = Entry.begin(), E = Entry.end(); MI != E; ++MI)
384 if (auto Err = extractKernelData(*MI, KernelName, KernelData))
385 return Err;
386
387 KernelInfoMap.insert({KernelName, KernelData});
388 return Error::success();
389 }
390
391 /// Go over the list of AMD kernels in the "amdhsa.kernels" entry
392 Error iterateAMDKernels(msgpack::MapDocNode &MDN) {
393 auto KernelsOrErr = getAMDKernelsArray(MDN);
394 if (auto Err = KernelsOrErr.takeError())
395 return Err;
396
397 auto KernelsArr = *KernelsOrErr;
398 for (auto It = KernelsArr.begin(), E = KernelsArr.end(); It != E; ++It) {
399 if (!It->isMap())
400 continue; // we expect <key,value> pairs
401
402 // Obtain the value for the different entries. Each array entry is a
403 // MapDocNode
404 if (auto Err = generateKernelInfo(It))
405 return Err;
406 }
407 return Error::success();
408 }
409
410 // Kernel names are the keys
411 StringMap<offloading::amdgpu::AMDGPUKernelMetaData> &KernelInfoMap;
412};
413} // namespace
414
416 MemoryBufferRef MemBuffer,
418 uint16_t &ELFABIVersion) {
419 Error Err = Error::success(); // Used later as out-parameter
420
421 auto ELFOrError = object::ELF64LEFile::create(MemBuffer.getBuffer());
422 if (auto Err = ELFOrError.takeError())
423 return Err;
424
425 const object::ELF64LEFile ELFObj = ELFOrError.get();
427 if (!Sections)
428 return Sections.takeError();
429 KernelInfoReader Reader(KernelInfoMap);
430
431 // Read the code object version from ELF image header
432 auto Header = ELFObj.getHeader();
433 ELFABIVersion = (uint8_t)(Header.e_ident[ELF::EI_ABIVERSION]);
434 for (const auto &S : *Sections) {
435 if (S.sh_type != ELF::SHT_NOTE)
436 continue;
437
438 for (const auto N : ELFObj.notes(S, Err)) {
439 if (Err)
440 return Err;
441 // Fills the KernelInfoTabel entries in the reader
442 if ((Err = Reader.processNote(N, S.sh_addralign)))
443 return Err;
444 }
445 }
446 return Error::success();
447}
448
449Error offloading::containerizeImage(std::unique_ptr<MemoryBuffer> &Img,
451 object::ImageKind ImageKind,
452 object::OffloadKind OffloadKind,
453 int32_t ImageFlags,
455 using namespace object;
456
457 // Create inner OffloadBinary containing the raw image.
458 OffloadBinary::OffloadingImage InnerImage;
459 InnerImage.TheImageKind = ImageKind;
460 InnerImage.TheOffloadKind = OffloadKind;
461 InnerImage.Flags = ImageFlags;
462
463 InnerImage.StringData["triple"] = Triple.getTriple();
464 for (const auto &[Key, Value] : MetaData)
465 InnerImage.StringData[Key] = Value;
466
467 InnerImage.Image = std::move(Img);
468
469 SmallString<0> InnerBinaryData = OffloadBinary::write(InnerImage);
470
471 Img = MemoryBuffer::getMemBufferCopy(InnerBinaryData);
472 return Error::success();
473}
474
476 std::unique_ptr<MemoryBuffer> &Binary, llvm::Triple Triple,
477 StringRef CompileOpts, StringRef LinkOpts) {
478 constexpr char INTEL_ONEOMP_OFFLOAD_VERSION[] = "1.0";
479
481 "Expected SPIR-V triple with Intel vendor");
482
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;
489
491 object::OffloadKind::OFK_OpenMP, /*ImageFlags=*/0,
492 MetaData);
493}
494
496 uint32_t Count = Names.size();
497
498 // Compute the byte offset where string data begins: right after the header
499 // and the entry array.
500 uint32_t StringDataOffset =
501 sizeof(SymbolTableHeader) + Count * sizeof(SymbolTableEntry);
502
503 // Compute total size and reserve to prevent reallocation while writing
504 // entries via pointer (append() could otherwise invalidate the pointer).
505 uint32_t TotalSize = StringDataOffset;
506 for (StringRef N : Names)
507 TotalSize += N.size() + 1;
508 Out.reserve(TotalSize);
509 Out.resize(StringDataOffset);
510
511 // Write the header.
512 auto *Header = reinterpret_cast<SymbolTableHeader *>(Out.data());
513 Header->Count = Count;
514
515 // Write each entry and append the corresponding null-terminated name.
516 auto *Entries = reinterpret_cast<SymbolTableEntry *>(Header + 1);
517 uint32_t CurrentOffset = StringDataOffset;
518 for (uint32_t I = 0; I < Count; ++I) {
519 Entries[I].OffsetToSymbol = CurrentOffset;
520 Entries[I].SymbolSize = Names[I].size();
521 Out.append(Names[I]);
522 Out.push_back('\0');
523 CurrentOffset += Names[I].size() + 1;
524 }
525}
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< 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...
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
#define T
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.
Definition Utility.cpp:95
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
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:548
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 Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
Definition Constants.h:1474
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
static GEPNoWrapFlags inBounds()
@ 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:1579
This class implements a map that also provides access to all stored values in a deterministic order.
Definition MapVector.h:38
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:68
A tuple of MDNodes.
Definition Metadata.h:1767
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...
Definition SmallString.h:26
reference emplace_back(ArgTypes &&... Args)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition StringRef.h:446
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:778
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition Type.cpp:662
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition Triple.h:875
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Definition Triple.h:869
const std::string & getTriple() const
Definition Triple.h:581
bool isNVPTX() const
Tests whether the target is NVPTX (32- or 64-bit).
Definition Triple.h:987
VendorType getVendor() const
Get the parsed vendor type of this triple.
Definition Triple.h:520
bool isSPIRV() const
Tests whether the target is SPIR-V (32/64-bit/Logical).
Definition Triple.h:975
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition Triple.h:866
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:300
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:298
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
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:346
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:535
Expected< Elf_Shdr_Range > sections() const
Definition ELF.h:1037
static uint64_t getAlignment()
@ Entry
Definition COFF.h:862
@ NT_AMDGPU_METADATA
Definition ELF.h:1999
@ EI_ABIVERSION
Definition ELF.h:59
@ SHT_NOTE
Definition ELF.h:1163
@ EF_AMDGPU_FEATURE_XNACK_ANY_V4
Definition ELF.h:910
@ EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4
Definition ELF.h:921
@ EF_AMDGPU_FEATURE_SRAMECC_OFF_V4
Definition ELF.h:925
@ EF_AMDGPU_FEATURE_XNACK_UNSUPPORTED_V4
Definition ELF.h:908
@ EF_AMDGPU_FEATURE_XNACK_OFF_V4
Definition ELF.h:912
@ EF_AMDGPU_FEATURE_XNACK_V4
Definition ELF.h:906
@ EF_AMDGPU_FEATURE_SRAMECC_V4
Definition ELF.h:919
@ EF_AMDGPU_FEATURE_XNACK_ON_V4
Definition ELF.h:914
@ EF_AMDGPU_FEATURE_SRAMECC_ANY_V4
Definition ELF.h:923
@ EF_AMDGPU_FEATURE_SRAMECC_ON_V4
Definition ELF.h:927
OffloadKind
The producer of the associated offloading image.
ImageKind
The type of contents the offloading image contains.
ELFFile< ELF64LE > ELF64LEFile
Definition ELF.h:601
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:415
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:202
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.
Definition Utility.cpp:475
LLVM_ABI void writeSymbolTable(ArrayRef< StringRef > Names, SmallString< 0 > &Out)
Serialize Names into Out.
Definition Utility.cpp:495
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 ...
Definition Utility.cpp:130
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.
Definition Utility.cpp:449
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:41
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:27
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)
Definition Utility.cpp:104
LLVM_ABI StringRef getOffloadEntrySection(Module &M)
Create an offloading section struct used to register this global at runtime.
Definition Utility.cpp:86
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...
Definition Error.cpp:94
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
Op::Description Desc
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
LLVM_ABI void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Elf_Note_Impl< ELFType< E, Is64 > > Note
Definition ELFTypes.h:90
This is the record of an object that just be registered with the offloading runtime.
Definition Utility.h:31
Struct for holding metadata related to AMDGPU kernels, for more information about the metadata and it...
Definition Utility.h:127
uint32_t SGPRSpillCount
Number of stores from a scalar register to a register allocator created spill location.
Definition Utility.h:142
uint32_t SGPRCount
Number of scalar registers required by a wavefront.
Definition Utility.h:137
SmallVector< std::pair< uint32_t, uint32_t >, 8 > ArgMDs
Per-argument {offset, size} in bytes, read from the ".args" array in code object metadata.
Definition Utility.h:160
uint32_t VGPRSpillCount
Number of stores from a vector register to a register allocator created spill location.
Definition Utility.h:145
uint32_t VGPRCount
Number of vector registers required by each work-item.
Definition Utility.h:139
uint32_t PrivateSegmentSize
The amount of fixed private address space memory required for a work-item in bytes.
Definition Utility.h:135
uint32_t GroupSegmentList
The amount of group segment memory required by a work-group in bytes.
Definition Utility.h:132
uint32_t MaxFlatWorkgroupSize
Maximum flat work-group size supported by the kernel in work-items.
Definition Utility.h:156
uint32_t WorkgroupSizeHint[3]
Corresponds to the OpenCL work_group_size_hint attribute.
Definition Utility.h:152
uint32_t AGPRCount
Number of accumulator registers required by each work-item.
Definition Utility.h:147
uint32_t RequestedWorkgroupSize[3]
Corresponds to the OpenCL reqd_work_group_size attribute.
Definition Utility.h:149
Serialized symbol table stored in the "symbols" entry of a SYCL OffloadBinary.
Definition Utility.h:199
uint32_t Count
Number of symbol entries.
Definition Utility.h:200
Common declarations for yaml2obj.