29                                           "Timer group for offload bundler");
 
   38  size_t NextbundleStart = 0;
 
   40  std::unique_ptr<MemoryBuffer> Buffer;
 
   53      NextbundleStart = (*Buffer).getBuffer().find(Magic, Magic.size());
 
   55        NextbundleStart = (*Buffer).getBuffer().size();
 
   59              (*Buffer).getBuffer().take_front(NextbundleStart), FileName,
 
   61      if (std::error_code EC = CodeOrErr.
getError())
 
   66      if (!DecompressedBufferOrErr)
 
   71          **DecompressedBufferOrErr, 
Offset, FileName, 
true);
 
   73        return FatBundleOrErr.takeError();
 
   83          *Buffer, SectionOffset + 
Offset, FileName);
 
   85        return FatBundleOrErr.takeError();
 
   90      Magic = 
"__CLANG_OFFLOAD_BUNDLE__";
 
   91      NextbundleStart = (*Buffer).getBuffer().find(Magic, Magic.size());
 
 
  116  NumberOfEntries = NumOfEntries;
 
  137    auto Entry = std::make_unique<OffloadBundleEntry>(
 
  138        EntryOffset + SectionOffset, EntrySize, EntryIDSize, EntryID);
 
  140    Entries.push_back(*Entry);
 
 
  158  std::unique_ptr<OffloadBundleFatBin> TheBundle(
 
  163      TheBundle->readEntries(Buf.
getBuffer(), Decompress ? 0 : SectionOffset);
 
  167  return std::move(TheBundle);
 
 
  180                      "-size" + 
itostr(Entry.Size) + 
".co";
 
 
  209                                 "COFF object files not supported");
 
 
  232  std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
 
  233  std::copy(InputBuffOrErr->getBufferStart() + 
Offset,
 
  234            InputBuffOrErr->getBufferStart() + 
Offset + 
Size,
 
  235            Buf->getBufferStart());
 
  236  if (
Error E = Buf->commit())
 
 
  249  std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
 
  253  return Buf->commit();
 
 
  273    return ObjOrErr.takeError();
 
  275  auto Obj = ObjOrErr->getBinary();
 
 
  285  std::string Num = std::to_string(
Value);
 
 
  294Expected<std::unique_ptr<MemoryBuffer>>
 
  300  Timer HashTimer(
"Hash Calculation Timer", 
"Hash calculation time",
 
  308  uint64_t TruncatedHash = Result.low();
 
  314      reinterpret_cast<const uint8_t *
>(
Input.getBuffer().data()),
 
  315      Input.getBuffer().size());
 
  316  Timer CompressTimer(
"Compression Timer", 
"Compression time",
 
  333    if (UncompressedSize64 > std::numeric_limits<uint32_t>::max())
 
  335                               "unsigned 32-bit integer limit",
 
  337    TotalFileSize64 = MagicNumber.size() + 
sizeof(
uint32_t) + 
sizeof(
Version) +
 
  338                      sizeof(CompressionMethod) + 
sizeof(
uint32_t) +
 
  339                      sizeof(TruncatedHash) + CompressedBuffer.
size();
 
  340    if (TotalFileSize64 > std::numeric_limits<uint32_t>::max())
 
  342                               "unsigned 32-bit integer limit",
 
  346    TotalFileSize64 = MagicNumber.size() + 
sizeof(
uint64_t) + 
sizeof(
Version) +
 
  347                      sizeof(CompressionMethod) + 
sizeof(
uint64_t) +
 
  348                      sizeof(TruncatedHash) + CompressedBuffer.
size();
 
  355  OS.
write(
reinterpret_cast<const char *
>(&CompressionMethod),
 
  356           sizeof(CompressionMethod));
 
  362    OS.
write(
reinterpret_cast<const char *
>(&TotalFileSize32),
 
  363             sizeof(TotalFileSize32));
 
  364    OS.
write(
reinterpret_cast<const char *
>(&UncompressedSize32),
 
  365             sizeof(UncompressedSize32));
 
  367    OS.
write(
reinterpret_cast<const char *
>(&TotalFileSize64),
 
  368             sizeof(TotalFileSize64));
 
  369    OS.
write(
reinterpret_cast<const char *
>(&UncompressedSize64),
 
  370             sizeof(UncompressedSize64));
 
  373  OS.
write(
reinterpret_cast<const char *
>(&TruncatedHash),
 
  374           sizeof(TruncatedHash));
 
  375  OS.
write(
reinterpret_cast<const char *
>(CompressedBuffer.
data()),
 
  376           CompressedBuffer.
size());
 
  380    double CompressionRate =
 
  381        static_cast<double>(UncompressedSize64) / CompressedBuffer.
size();
 
  383    double CompressionSpeedMBs =
 
  384        (UncompressedSize64 / (1024.0 * 1024.0)) / CompressionTimeSeconds;
 
  385    *VerboseStream << 
"Compressed bundle format version: " << 
Version << 
"\n" 
  386                   << 
"Total file size (including headers): " 
  388                   << 
"Compression method used: " << MethodUsed << 
"\n" 
  389                   << 
"Compression level: " << 
P.level << 
"\n" 
  390                   << 
"Binary size before compression: " 
  392                   << 
"Binary size after compression: " 
  394                   << 
"Compression rate: " << 
format(
"%.2lf", CompressionRate)
 
  396                   << 
"Compression ratio: " 
  397                   << 
format(
"%.2lf%%", 100.0 / CompressionRate) << 
"\n" 
  398                   << 
"Compression speed: " 
  399                   << 
format(
"%.2lf MB/s", CompressionSpeedMBs) << 
"\n" 
  400                   << 
"Truncated MD5 hash: " << 
format_hex(TruncatedHash, 16)
 
 
  459Expected<CompressedOffloadBundle::CompressedBundleHeader>
 
  465  std::memcpy(&Header, Blob.
data(), std::min(Blob.
size(), 
sizeof(Header)));
 
  468  Normalized.
Version = Header.Common.Version;
 
  472  if (Blob.
size() < RequiredSize)
 
  478    Normalized.
Hash = Header.V1.Hash;
 
  481    Normalized.
FileSize = Header.V2.FileSize;
 
  483    Normalized.
Hash = Header.V2.Hash;
 
  486    Normalized.
FileSize = Header.V3.FileSize;
 
  488    Normalized.
Hash = Header.V3.Hash;
 
  495  switch (Header.Common.Method) {
 
 
  519      *VerboseStream << 
"Uncompressed bundle\n";
 
  529  unsigned ThisVersion = Normalized.
Version;
 
  534  size_t TotalFileSize = Normalized.
FileSize.value_or(0);
 
  536  auto StoredHash = Normalized.
Hash;
 
  538  Timer DecompressTimer(
"Decompression Timer", 
"Decompression time",
 
  545      Blob.
substr(HeaderSize, TotalFileSize - HeaderSize);
 
  549          DecompressedData, UncompressedSize))
 
  551                             toString(std::move(DecompressionError)));
 
  556    double DecompressionTimeSeconds =
 
  560    Timer HashRecalcTimer(
"Hash Recalculation Timer", 
"Hash recalculation time",
 
  567    uint64_t RecalculatedHash = Result.low();
 
  569    bool HashMatch = (StoredHash == RecalculatedHash);
 
  571    double CompressionRate =
 
  572        static_cast<double>(UncompressedSize) / CompressedData.
size();
 
  573    double DecompressionSpeedMBs =
 
  574        (UncompressedSize / (1024.0 * 1024.0)) / DecompressionTimeSeconds;
 
  576    *VerboseStream << 
"Compressed bundle format version: " << ThisVersion
 
  578    if (ThisVersion >= 2)
 
  579      *VerboseStream << 
"Total file size (from header): " 
  582        << 
"Decompression method: " 
  585        << 
"Size before decompression: " 
  589        << 
"Compression rate: " << 
format(
"%.2lf", CompressionRate) << 
"\n" 
  590        << 
"Compression ratio: " << 
format(
"%.2lf%%", 100.0 / CompressionRate)
 
  592        << 
"Decompression speed: " 
  593        << 
format(
"%.2lf MB/s", DecompressionSpeedMBs) << 
"\n" 
  594        << 
"Stored hash: " << 
format_hex(StoredHash, 16) << 
"\n" 
  595        << 
"Recalculated hash: " << 
format_hex(RecalculatedHash, 16) << 
"\n" 
  596        << 
"Hashes match: " << (HashMatch ? 
"Yes" : 
"No") << 
"\n";
 
 
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
 
#define LLVM_PACKED_START
 
Module.h This file contains the declarations for the Module class.
 
static LLVM_PACKED_END size_t getHeaderSize(uint16_t Version)
 
Error extractOffloadBundle(MemoryBufferRef Contents, uint64_t SectionOffset, StringRef FileName, SmallVectorImpl< OffloadBundleFatBin > &Bundles)
 
static std::string formatWithCommas(unsigned long long Value)
 
static TimerGroup OffloadBundlerTimerGroup("Offload Bundler Timer Group", "Timer group for offload bundler")
 
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
 
Provides read only access to a subclass of BinaryStream.
 
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
 
LLVM_ABI Error readFixedString(StringRef &Dest, uint32_t Length)
Read a Length byte string into Dest.
 
Represents either an error or a value T.
 
std::error_code getError() 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.
 
static LLVM_ABI Expected< std::unique_ptr< FileOutputBuffer > > create(StringRef FilePath, size_t Size, unsigned Flags=0)
Factory method to create an OutputBuffer object which manages a read/write buffer of the specified si...
 
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
 
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
 
size_t getBufferSize() const
 
const char * getBufferStart() const
 
StringRef getBuffer() const
 
This interface provides simple read-only access to a block of memory, and provides simple methods for...
 
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.
 
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
 
reference emplace_back(ArgTypes &&... Args)
 
pointer data()
Return a pointer to the vector's buffer, even if empty().
 
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
 
StringRef - Represent a constant reference to a string, i.e.
 
static constexpr size_t npos
 
std::string str() const
str - Get the contents as an std::string.
 
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
 
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.
 
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
 
double getWallTime() const
 
The TimerGroup class is used to group together related timers into a single report that is printed wh...
 
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
 
LLVM_ABI void stopTimer()
Stop the timer.
 
LLVM_ABI void startTimer()
Start the timer running.
 
TimeRecord getTotalTime() const
Return the duration for which this timer has been running.
 
LLVM Value Representation.
 
StringRef getFileName() const
 
static llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > decompress(const llvm::MemoryBuffer &Input, raw_ostream *VerboseStream=nullptr)
 
static llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input, uint16_t Version, raw_ostream *VerboseStream=nullptr)
 
uint64_t getOffset() const
 
This class is the base class for all object file types.
 
section_iterator_range sections() const
 
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
 
LLVM_ABI Error readEntries(StringRef Section, uint64_t SectionOffset)
 
OffloadBundleFatBin(MemoryBufferRef Source, StringRef File, bool Decompress=false)
 
LLVM_ABI Error extractBundle(const ObjectFile &Source)
 
StringRef getFileName() const
 
static LLVM_ABI Expected< std::unique_ptr< OffloadBundleFatBin > > create(MemoryBufferRef, uint64_t SectionOffset, StringRef FileName, bool Decompress=false)
 
This is a value type class that represents a single section in the list of sections in the object fil...
 
This class implements an extremely fast bulk output stream that can only output to a stream.
 
raw_ostream & write(unsigned char C)
 
A raw_ostream that writes to an SmallVector or SmallString.
 
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
 
LLVM_ABI bool isAvailable()
 
LLVM_ABI bool isAvailable()
 
LLVM_ABI Error decompress(DebugCompressionType T, ArrayRef< uint8_t > Input, uint8_t *Output, size_t UncompressedSize)
 
LLVM_ABI void compress(Params P, ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &Output)
 
LLVM_ABI Error extractCodeObject(const ObjectFile &Source, int64_t Offset, int64_t Size, StringRef OutputFileName)
Extract code object memory from the given Source object file at Offset and of Size,...
 
LLVM_ABI Error extractOffloadBundleByURI(StringRef URIstr)
Extracts an Offload Bundle Entry given by URI.
 
LLVM_ABI Error extractOffloadBundleFatBinary(const ObjectFile &Obj, SmallVectorImpl< OffloadBundleFatBin > &Bundles)
Extracts fat binary in binary clang-offload-bundler format from object Obj and return it in Bundles.
 
This is an optimization pass for GlobalISel generic memory operations.
 
LLVM_ABI file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
 
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
 
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
 
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
 
FunctionAddr VTableAddr uintptr_t uintptr_t Version
 
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
 
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
 
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
 
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
 
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
 
std::string itostr(int64_t X)
 
@ offload_bundle
Clang offload bundle file.
 
@ offload_bundle_compressed
Compressed clang offload bundle file.
 
Bundle entry in binary clang-offload-bundler format.
 
static Expected< std::unique_ptr< OffloadBundleURI > > createOffloadBundleURI(StringRef Str, UriTypeT Type)