LLVM 23.0.0git
OffloadBundle.cpp
Go to the documentation of this file.
1//===- OffloadBundle.cpp - Utilities for offload bundles---*- C++ -*-===//
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
11#include "llvm/IR/Module.h"
14#include "llvm/Object/Archive.h"
15#include "llvm/Object/Binary.h"
16#include "llvm/Object/COFF.h"
18#include "llvm/Object/Error.h"
23#include "llvm/Support/Timer.h"
24
25using namespace llvm;
26using namespace llvm::object;
27
28static TimerGroup OffloadBundlerTimerGroup("Offload Bundler Timer Group",
29 "Timer group for offload bundler");
30
31// Extract an Offload bundle (usually a Offload Bundle) from a fat_bin
32// section.
34 StringRef FileName,
36
37 size_t Offset = 0;
38 size_t NextbundleStart = 0;
39 StringRef Magic;
40 std::unique_ptr<MemoryBuffer> Buffer;
41
42 // There could be multiple offloading bundles stored at this section.
43 while ((NextbundleStart != StringRef::npos) &&
44 (Offset < Contents.getBuffer().size())) {
45 Buffer =
47 /*RequiresNullTerminator=*/false);
48
49 if (identify_magic((*Buffer).getBuffer()) ==
51 Magic = "CCOB";
52 // Decompress this bundle first.
53 NextbundleStart = (*Buffer).getBuffer().find(Magic, Magic.size());
54 if (NextbundleStart == StringRef::npos)
55 NextbundleStart = (*Buffer).getBuffer().size();
56
59 (*Buffer).getBuffer().take_front(NextbundleStart), FileName,
60 false);
61 if (std::error_code EC = CodeOrErr.getError())
62 return createFileError(FileName, EC);
63
64 Expected<std::unique_ptr<MemoryBuffer>> DecompressedBufferOrErr =
65 CompressedOffloadBundle::decompress(**CodeOrErr, nullptr);
66 if (!DecompressedBufferOrErr)
67 return createStringError("failed to decompress input: " +
68 toString(DecompressedBufferOrErr.takeError()));
69
70 auto FatBundleOrErr = OffloadBundleFatBin::create(
71 **DecompressedBufferOrErr, Offset, FileName, true);
72 if (!FatBundleOrErr)
73 return FatBundleOrErr.takeError();
74
75 // Add current Bundle to list.
76 Bundles.emplace_back(std::move(**FatBundleOrErr));
77
78 } else if (identify_magic((*Buffer).getBuffer()) ==
80 // Create the OffloadBundleFatBin object. This will also create the Bundle
81 // Entry list info.
82 auto FatBundleOrErr = OffloadBundleFatBin::create(
83 *Buffer, SectionOffset + Offset, FileName);
84 if (!FatBundleOrErr)
85 return FatBundleOrErr.takeError();
86
87 // Add current Bundle to list.
88 Bundles.emplace_back(std::move(**FatBundleOrErr));
89
90 Magic = "__CLANG_OFFLOAD_BUNDLE__";
91 NextbundleStart = (*Buffer).getBuffer().find(Magic, Magic.size());
92 }
93
94 if (NextbundleStart != StringRef::npos)
95 Offset += NextbundleStart;
96 }
97
98 return Error::success();
99}
100
102 uint64_t SectionOffset) {
103 uint64_t NumOfEntries = 0;
104
106
107 // Read the Magic String first.
108 StringRef Magic;
109 if (auto EC = Reader.readFixedString(Magic, 24))
111
112 // Read the number of Code Objects (Entries) in the current Bundle.
113 if (auto EC = Reader.readInteger(NumOfEntries))
115
116 NumberOfEntries = NumOfEntries;
117
118 // For each Bundle Entry (code object).
119 for (uint64_t I = 0; I < NumOfEntries; I++) {
120 uint64_t EntrySize;
121 uint64_t EntryOffset;
122 uint64_t EntryIDSize;
123 StringRef EntryID;
124
125 if (Error Err = Reader.readInteger(EntryOffset))
126 return Err;
127
128 if (Error Err = Reader.readInteger(EntrySize))
129 return Err;
130
131 if (Error Err = Reader.readInteger(EntryIDSize))
132 return Err;
133
134 if (Error Err = Reader.readFixedString(EntryID, EntryIDSize))
135 return Err;
136
137 auto Entry = std::make_unique<OffloadBundleEntry>(
138 EntryOffset + SectionOffset, EntrySize, EntryIDSize, EntryID);
139
140 Entries.push_back(*Entry);
141 }
142
143 return Error::success();
144}
145
148 StringRef FileName, bool Decompress) {
149 if (Buf.getBufferSize() < 24)
151
152 // Check for magic bytes.
154 (identify_magic(Buf.getBuffer()) !=
157
158 std::unique_ptr<OffloadBundleFatBin> TheBundle(
159 new OffloadBundleFatBin(Buf, FileName, Decompress));
160
161 // Read the Bundle Entries.
162 Error Err =
163 TheBundle->readEntries(Buf.getBuffer(), Decompress ? 0 : SectionOffset);
164 if (Err)
165 return Err;
166
167 return std::move(TheBundle);
168}
169
171 // This will extract all entries in the Bundle.
172 for (OffloadBundleEntry &Entry : Entries) {
173
174 if (Entry.Size == 0)
175 continue;
176
177 // create output file name. Which should be
178 // <fileName>-offset<Offset>-size<Size>.co"
179 std::string Str = getFileName().str() + "-offset" + itostr(Entry.Offset) +
180 "-size" + itostr(Entry.Size) + ".co";
181 if (Error Err = object::extractCodeObject(Source, Entry.Offset, Entry.Size,
182 StringRef(Str)))
183 return Err;
184 }
185
186 return Error::success();
187}
188
191 // Ignore unsupported object formats.
192 if (!Obj.isELF() && !Obj.isCOFF())
193 return Error::success();
194
195 // Iterate through Sections until we find an offload_bundle section.
196 for (SectionRef Sec : Obj.sections()) {
197 Expected<StringRef> Buffer = Sec.getContents();
198 if (!Buffer)
199 return Buffer.takeError();
200
201 // If it does not start with the reserved suffix, just skip this section.
203 (llvm::identify_magic(*Buffer) ==
205
206 uint64_t SectionOffset = 0;
207 if (Obj.isELF()) {
208 SectionOffset = ELFSectionRef(Sec).getOffset();
209 } else if (Obj.isCOFF()) // TODO: add COFF Support.
211 "COFF object files not supported");
212
213 MemoryBufferRef Contents(*Buffer, Obj.getFileName());
214 if (Error Err = extractOffloadBundle(Contents, SectionOffset,
215 Obj.getFileName(), Bundles))
216 return Err;
217 }
218 }
219 return Error::success();
220}
221
223 size_t Size, StringRef OutputFileName) {
225 FileOutputBuffer::create(OutputFileName, Size);
226
227 if (!BufferOrErr)
228 return BufferOrErr.takeError();
229
230 Expected<MemoryBufferRef> InputBuffOrErr = Source.getMemoryBufferRef();
231 if (Error Err = InputBuffOrErr.takeError())
232 return createFileError(Source.getFileName(), std::move(Err));
233
234 if (Size > InputBuffOrErr->getBufferSize())
235 return createStringError("size in URI (%zu) is larger than source (%zu)",
236 Size, InputBuffOrErr->getBufferSize());
237
238 if (Offset > InputBuffOrErr->getBufferSize())
239 return createStringError(
240 "offset in URI (%zu) is beyond the end of the source (%zu)", Offset,
241 InputBuffOrErr->getBufferSize());
242
243 if (Offset + Size > InputBuffOrErr->getBufferSize())
244 return createStringError(
245 "offset + size (%zu) in URI is beyond the end of the source (%zu)",
246 Offset + Size, InputBuffOrErr->getBufferSize());
247
248 std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
249 std::copy(InputBuffOrErr->getBufferStart() + Offset,
250 InputBuffOrErr->getBufferStart() + Offset + Size,
251 Buf->getBufferStart());
252 if (Error E = Buf->commit())
253 return createFileError(OutputFileName, std::move(E));
254
255 return Error::success();
256}
257
259 int64_t Size, StringRef OutputFileName) {
261 FileOutputBuffer::create(OutputFileName, Size);
262 if (!BufferOrErr)
263 return BufferOrErr.takeError();
264
265 std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
266 std::copy(Buffer.getBufferStart() + Offset,
267 Buffer.getBufferStart() + Offset + Size, Buf->getBufferStart());
268
269 return Buf->commit();
270}
271
272// given a file name, offset, and size, extract data into a code object file,
273// into file "<SourceFile>-offset<Offset>-size<Size>.co".
275 // create a URI object
278
279 if (!UriOrErr)
280 return UriOrErr.takeError();
281
282 OffloadBundleURI &Uri = **UriOrErr;
283 std::string OutputFile = Uri.FileName.str();
284 OutputFile +=
285 "-offset" + itostr(Uri.Offset) + "-size" + itostr(Uri.Size) + ".co";
286
287 // Create an ObjectFile object from uri.file_uri.
288 auto ObjOrErr = ObjectFile::createObjectFile(Uri.FileName);
289 if (!ObjOrErr)
290 return ObjOrErr.takeError();
291
292 auto Obj = ObjOrErr->getBinary();
293 if (Error Err =
294 object::extractCodeObject(*Obj, Uri.Offset, Uri.Size, OutputFile))
295 return createFileError(Uri.FileName, std::move(Err));
296
297 return Error::success();
298}
299
300// Utility function to format numbers with commas.
301static std::string formatWithCommas(unsigned long long Value) {
302 std::string Num = std::to_string(Value);
303 int InsertPosition = Num.length() - 3;
304 while (InsertPosition > 0) {
305 Num.insert(InsertPosition, ",");
306 InsertPosition -= 3;
307 }
308 return Num;
309}
310
311Expected<std::unique_ptr<MemoryBuffer>>
314 raw_ostream *VerboseStream) {
316 return createStringError("compression not supported.");
317 Timer HashTimer("Hash Calculation Timer", "Hash calculation time",
319 if (VerboseStream)
320 HashTimer.startTimer();
321 MD5 Hash;
322 MD5::MD5Result Result;
323 Hash.update(Input.getBuffer());
324 Hash.final(Result);
325 uint64_t TruncatedHash = Result.low();
326 if (VerboseStream)
327 HashTimer.stopTimer();
328
329 SmallVector<uint8_t, 0> CompressedBuffer;
330 auto BufferUint8 = ArrayRef<uint8_t>(
331 reinterpret_cast<const uint8_t *>(Input.getBuffer().data()),
332 Input.getBuffer().size());
333 Timer CompressTimer("Compression Timer", "Compression time",
335 if (VerboseStream)
336 CompressTimer.startTimer();
337 compression::compress(P, BufferUint8, CompressedBuffer);
338 if (VerboseStream)
339 CompressTimer.stopTimer();
340
341 uint16_t CompressionMethod = static_cast<uint16_t>(P.format);
342
343 // Store sizes in 64-bit variables first.
344 uint64_t UncompressedSize64 = Input.getBuffer().size();
345 uint64_t TotalFileSize64;
346
347 // Calculate total file size based on version.
348 if (Version == 2) {
349 // For V2, ensure the sizes don't exceed 32-bit limit.
350 if (UncompressedSize64 > std::numeric_limits<uint32_t>::max())
351 return createStringError("uncompressed size (%llu) exceeds version 2 "
352 "unsigned 32-bit integer limit",
353 UncompressedSize64);
354 TotalFileSize64 = MagicNumber.size() + sizeof(uint32_t) + sizeof(Version) +
355 sizeof(CompressionMethod) + sizeof(uint32_t) +
356 sizeof(TruncatedHash) + CompressedBuffer.size();
357 if (TotalFileSize64 > std::numeric_limits<uint32_t>::max())
358 return createStringError("total file size (%llu) exceeds version 2 "
359 "unsigned 32-bit integer limit",
360 TotalFileSize64);
361
362 } else { // Version 3.
363 TotalFileSize64 = MagicNumber.size() + sizeof(uint64_t) + sizeof(Version) +
364 sizeof(CompressionMethod) + sizeof(uint64_t) +
365 sizeof(TruncatedHash) + CompressedBuffer.size();
366 }
367
368 SmallVector<char, 0> FinalBuffer;
369 raw_svector_ostream OS(FinalBuffer);
370 OS << MagicNumber;
371 OS.write(reinterpret_cast<const char *>(&Version), sizeof(Version));
372 OS.write(reinterpret_cast<const char *>(&CompressionMethod),
373 sizeof(CompressionMethod));
374
375 // Write size fields according to version.
376 if (Version == 2) {
377 uint32_t TotalFileSize32 = static_cast<uint32_t>(TotalFileSize64);
378 uint32_t UncompressedSize32 = static_cast<uint32_t>(UncompressedSize64);
379 OS.write(reinterpret_cast<const char *>(&TotalFileSize32),
380 sizeof(TotalFileSize32));
381 OS.write(reinterpret_cast<const char *>(&UncompressedSize32),
382 sizeof(UncompressedSize32));
383 } else { // Version 3.
384 OS.write(reinterpret_cast<const char *>(&TotalFileSize64),
385 sizeof(TotalFileSize64));
386 OS.write(reinterpret_cast<const char *>(&UncompressedSize64),
387 sizeof(UncompressedSize64));
388 }
389
390 OS.write(reinterpret_cast<const char *>(&TruncatedHash),
391 sizeof(TruncatedHash));
392 OS.write(reinterpret_cast<const char *>(CompressedBuffer.data()),
393 CompressedBuffer.size());
394
395 if (VerboseStream) {
396 auto MethodUsed = P.format == compression::Format::Zstd ? "zstd" : "zlib";
397 double CompressionRate =
398 static_cast<double>(UncompressedSize64) / CompressedBuffer.size();
399 double CompressionTimeSeconds = CompressTimer.getTotalTime().getWallTime();
400 double CompressionSpeedMBs =
401 (UncompressedSize64 / (1024.0 * 1024.0)) / CompressionTimeSeconds;
402 *VerboseStream << "Compressed bundle format version: " << Version << "\n"
403 << "Total file size (including headers): "
404 << formatWithCommas(TotalFileSize64) << " bytes\n"
405 << "Compression method used: " << MethodUsed << "\n"
406 << "Compression level: " << P.level << "\n"
407 << "Binary size before compression: "
408 << formatWithCommas(UncompressedSize64) << " bytes\n"
409 << "Binary size after compression: "
410 << formatWithCommas(CompressedBuffer.size()) << " bytes\n"
411 << "Compression rate: " << format("%.2lf", CompressionRate)
412 << "\n"
413 << "Compression ratio: "
414 << format("%.2lf%%", 100.0 / CompressionRate) << "\n"
415 << "Compression speed: "
416 << format("%.2lf MB/s", CompressionSpeedMBs) << "\n"
417 << "Truncated MD5 hash: " << format_hex(TruncatedHash, 16)
418 << "\n";
419 }
420
422 StringRef(FinalBuffer.data(), FinalBuffer.size()));
423}
424
425// Use packed structs to avoid padding, such that the structs map the serialized
426// format.
461
462// Helper method to get header size based on version.
463static size_t getHeaderSize(uint16_t Version) {
464 switch (Version) {
465 case 1:
467 case 2:
469 case 3:
471 default:
472 llvm_unreachable("Unsupported version");
473 }
474}
475
476Expected<CompressedOffloadBundle::CompressedBundleHeader>
480
482 std::memcpy(&Header, Blob.data(), std::min(Blob.size(), sizeof(Header)));
483
484 CompressedBundleHeader Normalized;
485 Normalized.Version = Header.Common.Version;
486
487 size_t RequiredSize = getHeaderSize(Normalized.Version);
488
489 if (Blob.size() < RequiredSize)
490 return createStringError("compressed bundle header size too small");
491
492 switch (Normalized.Version) {
493 case 1:
494 Normalized.UncompressedFileSize = Header.V1.UncompressedFileSize;
495 Normalized.Hash = Header.V1.Hash;
496 break;
497 case 2:
498 Normalized.FileSize = Header.V2.FileSize;
499 Normalized.UncompressedFileSize = Header.V2.UncompressedFileSize;
500 Normalized.Hash = Header.V2.Hash;
501 break;
502 case 3:
503 Normalized.FileSize = Header.V3.FileSize;
504 Normalized.UncompressedFileSize = Header.V3.UncompressedFileSize;
505 Normalized.Hash = Header.V3.Hash;
506 break;
507 default:
508 return createStringError("unknown compressed bundle version");
509 }
510
511 // Determine compression format.
512 switch (Header.Common.Method) {
513 case static_cast<uint16_t>(compression::Format::Zlib):
514 case static_cast<uint16_t>(compression::Format::Zstd):
515 Normalized.CompressionFormat =
516 static_cast<compression::Format>(Header.Common.Method);
517 break;
518 default:
519 return createStringError("unknown compressing method");
520 }
521
522 return Normalized;
523}
524
527 raw_ostream *VerboseStream) {
528 StringRef Blob = Input.getBuffer();
529
530 // Check minimum header size (using V1 as it's the smallest).
533
535 if (VerboseStream)
536 *VerboseStream << "Uncompressed bundle\n";
538 }
539
542 if (!HeaderOrErr)
543 return HeaderOrErr.takeError();
544
545 const CompressedBundleHeader &Normalized = *HeaderOrErr;
546 unsigned ThisVersion = Normalized.Version;
547 size_t HeaderSize = getHeaderSize(ThisVersion);
548
549 compression::Format CompressionFormat = Normalized.CompressionFormat;
550
551 size_t TotalFileSize = Normalized.FileSize.value_or(0);
552 size_t UncompressedSize = Normalized.UncompressedFileSize;
553 auto StoredHash = Normalized.Hash;
554
555 Timer DecompressTimer("Decompression Timer", "Decompression time",
557 if (VerboseStream)
558 DecompressTimer.startTimer();
559
560 SmallVector<uint8_t, 0> DecompressedData;
561 StringRef CompressedData =
562 Blob.substr(HeaderSize, TotalFileSize - HeaderSize);
563
564 if (Error DecompressionError = compression::decompress(
565 CompressionFormat, arrayRefFromStringRef(CompressedData),
566 DecompressedData, UncompressedSize))
567 return createStringError("could not decompress embedded file contents: " +
568 toString(std::move(DecompressionError)));
569
570 if (VerboseStream) {
571 DecompressTimer.stopTimer();
572
573 double DecompressionTimeSeconds =
574 DecompressTimer.getTotalTime().getWallTime();
575
576 // Recalculate MD5 hash for integrity check.
577 Timer HashRecalcTimer("Hash Recalculation Timer", "Hash recalculation time",
579 HashRecalcTimer.startTimer();
580 MD5 Hash;
581 MD5::MD5Result Result;
582 Hash.update(ArrayRef<uint8_t>(DecompressedData));
583 Hash.final(Result);
584 uint64_t RecalculatedHash = Result.low();
585 HashRecalcTimer.stopTimer();
586 bool HashMatch = (StoredHash == RecalculatedHash);
587
588 double CompressionRate =
589 static_cast<double>(UncompressedSize) / CompressedData.size();
590 double DecompressionSpeedMBs =
591 (UncompressedSize / (1024.0 * 1024.0)) / DecompressionTimeSeconds;
592
593 *VerboseStream << "Compressed bundle format version: " << ThisVersion
594 << "\n";
595 if (ThisVersion >= 2)
596 *VerboseStream << "Total file size (from header): "
597 << formatWithCommas(TotalFileSize) << " bytes\n";
598 *VerboseStream
599 << "Decompression method: "
600 << (CompressionFormat == compression::Format::Zlib ? "zlib" : "zstd")
601 << "\n"
602 << "Size before decompression: "
603 << formatWithCommas(CompressedData.size()) << " bytes\n"
604 << "Size after decompression: " << formatWithCommas(UncompressedSize)
605 << " bytes\n"
606 << "Compression rate: " << format("%.2lf", CompressionRate) << "\n"
607 << "Compression ratio: " << format("%.2lf%%", 100.0 / CompressionRate)
608 << "\n"
609 << "Decompression speed: "
610 << format("%.2lf MB/s", DecompressionSpeedMBs) << "\n"
611 << "Stored hash: " << format_hex(StoredHash, 16) << "\n"
612 << "Recalculated hash: " << format_hex(RecalculatedHash, 16) << "\n"
613 << "Hashes match: " << (HashMatch ? "Yes" : "No") << "\n";
614 }
615
616 return MemoryBuffer::getMemBufferCopy(toStringRef(DecompressedData));
617}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_PACKED_END
Definition Compiler.h:555
#define LLVM_PACKED_START
Definition Compiler.h:554
Module.h This file contains the declarations for the Module class.
#define I(x, y, z)
Definition MD5.cpp:57
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")
#define P(N)
The Input class is used to parse a yaml document into in-memory structs and vectors.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
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.
Definition ErrorOr.h:56
std::error_code getError() const
Definition ErrorOr.h:152
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 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.
Definition MD5.cpp:188
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition MD5.cpp:233
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:591
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:629
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
double getWallTime() const
Definition Timer.h:45
The TimerGroup class is used to group together related timers into a single report that is printed wh...
Definition Timer.h:191
This class is used to track the amount of time spent between invocations of its startTimer()/stopTime...
Definition Timer.h:87
LLVM_ABI void stopTimer()
Stop the timer.
Definition Timer.cpp:159
LLVM_ABI void startTimer()
Start the timer running.
Definition Timer.cpp:150
TimeRecord getTotalTime() const
Return the duration for which this timer has been running.
Definition Timer.h:145
LLVM Value Representation.
Definition Value.h:75
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)
This class is the base class for all object file types.
Definition ObjectFile.h:231
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)
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...
Definition ObjectFile.h:83
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
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 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.
LLVM_ABI Error extractCodeObject(const ObjectFile &Source, size_t Offset, size_t Size, StringRef OutputFileName)
Extract code object memory from the given Source object file at Offset and of Size,...
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.
Definition Magic.cpp:33
@ Offset
Definition DWP.cpp:557
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition Error.h:1415
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.
Definition Error.h:1321
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:334
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition Format.h:191
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:129
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.
Definition Error.cpp:107
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
std::string itostr(int64_t X)
@ offload_bundle
Clang offload bundle file.
Definition Magic.h:60
@ offload_bundle_compressed
Compressed clang offload bundle file.
Definition Magic.h:61
static llvm::Expected< CompressedBundleHeader > tryParse(llvm::StringRef)
Bundle entry in binary clang-offload-bundler format.
static Expected< std::unique_ptr< OffloadBundleURI > > createOffloadBundleURI(StringRef Str, UriTypeT Type)