42 std::unique_ptr<MemoryBuffer> Buffer =
46 Buffer->getBufferStart()))
48 Buffer->getBufferIdentifier());
51 return BinaryOrErr.takeError();
60 return NewBinaryOrErr.takeError();
61 Binaries.
emplace_back(std::move(*NewBinaryOrErr), std::move(BufferCopy));
86 if (!NameOrErr->starts_with(
".llvm.offloading"))
95 if (
Error Err = extractOffloadFiles(Contents, Binaries))
111 "Failed to create module");
115 auto *MD =
M->getNamedMetadata(
"llvm.embedded.objects");
119 for (
const MDNode *
Op : MD->operands()) {
123 MDString *SectionID = dyn_cast<MDString>(
Op->getOperand(1));
124 if (!SectionID || SectionID->
getString() !=
".llvm.offloading")
128 mdconst::dyn_extract_or_null<GlobalVariable>(
Op->getOperand(0));
132 auto *CDS = dyn_cast<ConstantDataSequential>(GV->
getInitializer());
137 if (
Error Err = extractOffloadFiles(Contents, Binaries))
148 for (
auto Child : Library.children(Err)) {
149 auto ChildBufferOrErr = Child.getMemoryBufferRef();
150 if (!ChildBufferOrErr)
151 return ChildBufferOrErr.takeError();
152 std::unique_ptr<MemoryBuffer> ChildBuffer =
157 ChildBuffer->getBufferStart()))
159 ChildBufferOrErr->getBuffer(),
160 ChildBufferOrErr->getBufferIdentifier());
187 const Header *TheHeader =
reinterpret_cast<const Header *
>(Start);
199 const Entry *TheEntry =
206 return std::unique_ptr<OffloadBinary>(
213 for (
auto &KeyAndValue : OffloadingData.
StringData) {
214 StrTab.
add(KeyAndValue.first);
215 StrTab.
add(KeyAndValue.second);
224 StringEntrySize + StrTab.
getSize(),
251 OS << StringRef(reinterpret_cast<char *>(&TheHeader),
sizeof(
Header));
252 OS << StringRef(reinterpret_cast<char *>(&TheEntry),
sizeof(
Entry));
253 for (
auto &KeyAndValue : OffloadingData.
StringData) {
257 OS << StringRef(reinterpret_cast<char *>(&Map),
sizeof(
StringEntry));
262 OS << OffloadingData.
Image->getBuffer();
277 return extractFromBitcode(Buffer, Binaries);
286 return extractFromObject(*ObjFile->
get(), Binaries);
293 return extractFromArchive(*LibFile->
get(), Binaries);
296 return extractOffloadFiles(Buffer, Binaries);
358 if (
LHS.first !=
RHS.first)
362 if (
LHS.second ==
"generic" ||
RHS.second ==
"generic")
371 if (
LHS.second.split(
":").first !=
RHS.second.split(
":").first)
375 if (
LHS.second.contains(
"xnack+") &&
RHS.second.contains(
"xnack-"))
377 if (
LHS.second.contains(
"xnack-") &&
RHS.second.contains(
"xnack+"))
379 if (
LHS.second.contains(
"sramecc-") &&
RHS.second.contains(
"sramecc+"))
381 if (
LHS.second.contains(
"sramecc+") &&
RHS.second.contains(
"sramecc-"))
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
This class represents an Operation in the Expression.
uint64_t getNumOperands() const
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.
reference get()
Returns a reference to the stored T value.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This is an important class for using LLVM in a threaded context.
StringRef getString() const
size_t getBufferSize() const
StringRef getBufferIdentifier() const
const char * getBufferStart() const
StringRef getBuffer() const
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
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.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
StringRef - Represent a constant reference to a string, i.e.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Utility for building string tables with deduplicated suffixes.
size_t getOffset(CachedHashStringRef S) const
Get the offest of a string in the string table.
void write(raw_ostream &OS) const
size_t add(CachedHashStringRef S)
Add a string to the builder.
void finalize()
Analyze the strings and build the final table.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
static Expected< std::unique_ptr< Archive > > create(MemoryBufferRef Source)
StringRef getData() const
StringRef getFileName() const
This class is the base class for all object file types.
section_iterator_range sections() const
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
A simple binary serialization of an offloading file.
static uint64_t getAlignment()
static SmallString< 0 > write(const OffloadingImage &)
Serialize the contents of File to a binary buffer to be read later.
static Expected< std::unique_ptr< OffloadBinary > > create(MemoryBufferRef)
Attempt to parse the offloading binary stored in Data.
static const uint32_t Version
The current version of the binary used for backwards compatibility.
std::pair< StringRef, StringRef > TargetID
This is a value type class that represents a single section in the list of sections in the object fil...
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
uint64_t tell() const
tell - Return the current offset with the file.
A raw_ostream that writes to an SmallVector or SmallString.
Error extractOffloadBinaries(MemoryBufferRef Buffer, SmallVectorImpl< OffloadFile > &Binaries)
Extracts embedded device offloading code from a memory Buffer to a list of Binaries.
ImageKind getImageKind(StringRef Name)
Convert a string Name to an image kind.
bool areTargetsCompatible(const OffloadFile::TargetID &LHS, const OffloadFile::TargetID &RHS)
If the target is AMD we check the target IDs for mutual compatibility.
OffloadKind
The producer of the associated offloading image.
OffloadKind getOffloadKind(StringRef Name)
Convert a string Name to an offload kind.
StringRef getImageKindName(ImageKind Name)
Convert an image kind to its string representation.
ImageKind
The type of contents the offloading image contains.
StringRef getOffloadKindName(OffloadKind Name)
Convert an offload kind to its string representation.
This is an optimization pass for GlobalISel generic memory operations.
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
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.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
bool isAddrAligned(Align Lhs, const void *Addr)
Checks that Addr is a multiple of the alignment.
std::unique_ptr< Module > getLazyIRModule(std::unique_ptr< MemoryBuffer > Buffer, SMDiagnostic &Err, LLVMContext &Context, bool ShouldLazyLoadMetadata=false)
If the given MemoryBuffer holds a bitcode image, return a Module for it which does lazy deserializati...
This struct is a compact representation of a valid (non-zero power of two) alignment.
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
@ elf_relocatable
ELF Relocatable object file.
@ archive
ar style archive file
@ elf_shared_object
ELF dynamically linked shared lib.
@ elf_executable
ELF Executable image.
@ offload_binary
LLVM offload object file.
@ coff_object
COFF object file.
OffloadKind TheOffloadKind
The offloading metadata that will be serialized to a memory buffer.
OffloadKind TheOffloadKind
std::unique_ptr< MemoryBuffer > Image
MapVector< StringRef, StringRef > StringData