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()) {
212 COFF.getSection(COFF.getSectionID(Sec));
213 if (!SecOrErr)
214 return SecOrErr.takeError();
215 SectionOffset = (*SecOrErr)->PointerToRawData;
216 }
217
218 MemoryBufferRef Contents(*Buffer, Obj.getFileName());
219 if (Error Err = extractOffloadBundle(Contents, SectionOffset,
220 Obj.getFileName(), Bundles))
221 return Err;
222 }
223 }
224 return Error::success();
225}
226
228 size_t Size, StringRef OutputFileName) {
230 FileOutputBuffer::create(OutputFileName, Size);
231
232 if (!BufferOrErr)
233 return BufferOrErr.takeError();
234
235 Expected<MemoryBufferRef> InputBuffOrErr = Source.getMemoryBufferRef();
236 if (Error Err = InputBuffOrErr.takeError())
237 return createFileError(Source.getFileName(), std::move(Err));
238
239 if (Size > InputBuffOrErr->getBufferSize())
240 return createStringError("size in URI (%zu) is larger than source (%zu)",
241 Size, InputBuffOrErr->getBufferSize());
242
243 if (Offset > InputBuffOrErr->getBufferSize())
244 return createStringError(
245 "offset in URI (%zu) is beyond the end of the source (%zu)", Offset,
246 InputBuffOrErr->getBufferSize());
247
248 if (Offset + Size > InputBuffOrErr->getBufferSize())
249 return createStringError(
250 "offset + size (%zu) in URI is beyond the end of the source (%zu)",
251 Offset + Size, InputBuffOrErr->getBufferSize());
252
253 std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
254 std::copy(InputBuffOrErr->getBufferStart() + Offset,
255 InputBuffOrErr->getBufferStart() + Offset + Size,
256 Buf->getBufferStart());
257 if (Error E = Buf->commit())
258 return createFileError(OutputFileName, std::move(E));
259
260 return Error::success();
261}
262
264 int64_t Size, StringRef OutputFileName) {
266 FileOutputBuffer::create(OutputFileName, Size);
267 if (!BufferOrErr)
268 return BufferOrErr.takeError();
269
270 std::unique_ptr<FileOutputBuffer> Buf = std::move(*BufferOrErr);
271 std::copy(Buffer.getBufferStart() + Offset,
272 Buffer.getBufferStart() + Offset + Size, Buf->getBufferStart());
273
274 return Buf->commit();
275}
276
277// given a file name, offset, and size, extract data into a code object file,
278// into file "<SourceFile>-offset<Offset>-size<Size>.co".
280 // create a URI object
283
284 if (!UriOrErr)
285 return UriOrErr.takeError();
286
287 OffloadBundleURI &Uri = **UriOrErr;
288 std::string OutputFile = Uri.FileName.str();
289 OutputFile +=
290 "-offset" + itostr(Uri.Offset) + "-size" + itostr(Uri.Size) + ".co";
291
292 // Create an ObjectFile object from uri.file_uri.
293 auto ObjOrErr = ObjectFile::createObjectFile(Uri.FileName);
294 if (!ObjOrErr)
295 return ObjOrErr.takeError();
296
297 auto Obj = ObjOrErr->getBinary();
298 if (Error Err =
299 object::extractCodeObject(*Obj, Uri.Offset, Uri.Size, OutputFile))
300 return createFileError(Uri.FileName, std::move(Err));
301
302 return Error::success();
303}
304
305// Utility function to format numbers with commas.
306static std::string formatWithCommas(unsigned long long Value) {
307 std::string Num = std::to_string(Value);
308 int InsertPosition = Num.length() - 3;
309 while (InsertPosition > 0) {
310 Num.insert(InsertPosition, ",");
311 InsertPosition -= 3;
312 }
313 return Num;
314}
315
316Expected<std::unique_ptr<MemoryBuffer>>
319 raw_ostream *VerboseStream) {
321 return createStringError("compression not supported.");
322 Timer HashTimer("Hash Calculation Timer", "Hash calculation time",
324 if (VerboseStream)
325 HashTimer.startTimer();
326 MD5 Hash;
327 MD5::MD5Result Result;
328 Hash.update(Input.getBuffer());
329 Hash.final(Result);
330 uint64_t TruncatedHash = Result.low();
331 if (VerboseStream)
332 HashTimer.stopTimer();
333
334 SmallVector<uint8_t, 0> CompressedBuffer;
335 auto BufferUint8 = ArrayRef<uint8_t>(
336 reinterpret_cast<const uint8_t *>(Input.getBuffer().data()),
337 Input.getBuffer().size());
338 Timer CompressTimer("Compression Timer", "Compression time",
340 if (VerboseStream)
341 CompressTimer.startTimer();
342 compression::compress(P, BufferUint8, CompressedBuffer);
343 if (VerboseStream)
344 CompressTimer.stopTimer();
345
346 uint16_t CompressionMethod = static_cast<uint16_t>(P.format);
347
348 // Store sizes in 64-bit variables first.
349 uint64_t UncompressedSize64 = Input.getBuffer().size();
350 uint64_t TotalFileSize64;
351
352 // Calculate total file size based on version.
353 if (Version == 2) {
354 // For V2, ensure the sizes don't exceed 32-bit limit.
355 if (UncompressedSize64 > std::numeric_limits<uint32_t>::max())
356 return createStringError("uncompressed size (%llu) exceeds version 2 "
357 "unsigned 32-bit integer limit",
358 UncompressedSize64);
359 TotalFileSize64 = MagicNumber.size() + sizeof(uint32_t) + sizeof(Version) +
360 sizeof(CompressionMethod) + sizeof(uint32_t) +
361 sizeof(TruncatedHash) + CompressedBuffer.size();
362 if (TotalFileSize64 > std::numeric_limits<uint32_t>::max())
363 return createStringError("total file size (%llu) exceeds version 2 "
364 "unsigned 32-bit integer limit",
365 TotalFileSize64);
366
367 } else { // Version 3.
368 TotalFileSize64 = MagicNumber.size() + sizeof(uint64_t) + sizeof(Version) +
369 sizeof(CompressionMethod) + sizeof(uint64_t) +
370 sizeof(TruncatedHash) + CompressedBuffer.size();
371 }
372
373 SmallVector<char, 0> FinalBuffer;
374 raw_svector_ostream OS(FinalBuffer);
375 OS << MagicNumber;
376 OS.write(reinterpret_cast<const char *>(&Version), sizeof(Version));
377 OS.write(reinterpret_cast<const char *>(&CompressionMethod),
378 sizeof(CompressionMethod));
379
380 // Write size fields according to version.
381 if (Version == 2) {
382 uint32_t TotalFileSize32 = static_cast<uint32_t>(TotalFileSize64);
383 uint32_t UncompressedSize32 = static_cast<uint32_t>(UncompressedSize64);
384 OS.write(reinterpret_cast<const char *>(&TotalFileSize32),
385 sizeof(TotalFileSize32));
386 OS.write(reinterpret_cast<const char *>(&UncompressedSize32),
387 sizeof(UncompressedSize32));
388 } else { // Version 3.
389 OS.write(reinterpret_cast<const char *>(&TotalFileSize64),
390 sizeof(TotalFileSize64));
391 OS.write(reinterpret_cast<const char *>(&UncompressedSize64),
392 sizeof(UncompressedSize64));
393 }
394
395 OS.write(reinterpret_cast<const char *>(&TruncatedHash),
396 sizeof(TruncatedHash));
397 OS.write(reinterpret_cast<const char *>(CompressedBuffer.data()),
398 CompressedBuffer.size());
399
400 if (VerboseStream) {
401 auto MethodUsed = P.format == compression::Format::Zstd ? "zstd" : "zlib";
402 double CompressionRate =
403 static_cast<double>(UncompressedSize64) / CompressedBuffer.size();
404 double CompressionTimeSeconds = CompressTimer.getTotalTime().getWallTime();
405 double CompressionSpeedMBs =
406 (UncompressedSize64 / (1024.0 * 1024.0)) / CompressionTimeSeconds;
407 *VerboseStream << "Compressed bundle format version: " << Version << "\n"
408 << "Total file size (including headers): "
409 << formatWithCommas(TotalFileSize64) << " bytes\n"
410 << "Compression method used: " << MethodUsed << "\n"
411 << "Compression level: " << P.level << "\n"
412 << "Binary size before compression: "
413 << formatWithCommas(UncompressedSize64) << " bytes\n"
414 << "Binary size after compression: "
415 << formatWithCommas(CompressedBuffer.size()) << " bytes\n"
416 << "Compression rate: " << format("%.2lf", CompressionRate)
417 << "\n"
418 << "Compression ratio: "
419 << format("%.2lf%%", 100.0 / CompressionRate) << "\n"
420 << "Compression speed: "
421 << format("%.2lf MB/s", CompressionSpeedMBs) << "\n"
422 << "Truncated MD5 hash: " << format_hex(TruncatedHash, 16)
423 << "\n";
424 }
425
427 StringRef(FinalBuffer.data(), FinalBuffer.size()));
428}
429
430// Use packed structs to avoid padding, such that the structs map the serialized
431// format.
466
467// Helper method to get header size based on version.
468static size_t getHeaderSize(uint16_t Version) {
469 switch (Version) {
470 case 1:
472 case 2:
474 case 3:
476 default:
477 llvm_unreachable("Unsupported version");
478 }
479}
480
481Expected<CompressedOffloadBundle::CompressedBundleHeader>
485
487 std::memcpy(&Header, Blob.data(), std::min(Blob.size(), sizeof(Header)));
488
489 CompressedBundleHeader Normalized;
490 Normalized.Version = Header.Common.Version;
491
492 size_t RequiredSize = getHeaderSize(Normalized.Version);
493
494 if (Blob.size() < RequiredSize)
495 return createStringError("compressed bundle header size too small");
496
497 switch (Normalized.Version) {
498 case 1:
499 Normalized.UncompressedFileSize = Header.V1.UncompressedFileSize;
500 Normalized.Hash = Header.V1.Hash;
501 break;
502 case 2:
503 Normalized.FileSize = Header.V2.FileSize;
504 Normalized.UncompressedFileSize = Header.V2.UncompressedFileSize;
505 Normalized.Hash = Header.V2.Hash;
506 break;
507 case 3:
508 Normalized.FileSize = Header.V3.FileSize;
509 Normalized.UncompressedFileSize = Header.V3.UncompressedFileSize;
510 Normalized.Hash = Header.V3.Hash;
511 break;
512 default:
513 return createStringError("unknown compressed bundle version");
514 }
515
516 // Determine compression format.
517 switch (Header.Common.Method) {
518 case static_cast<uint16_t>(compression::Format::Zlib):
519 case static_cast<uint16_t>(compression::Format::Zstd):
520 Normalized.CompressionFormat =
521 static_cast<compression::Format>(Header.Common.Method);
522 break;
523 default:
524 return createStringError("unknown compressing method");
525 }
526
527 return Normalized;
528}
529
532 raw_ostream *VerboseStream) {
533 StringRef Blob = Input.getBuffer();
534
535 // Check minimum header size (using V1 as it's the smallest).
538
540 if (VerboseStream)
541 *VerboseStream << "Uncompressed bundle\n";
543 }
544
547 if (!HeaderOrErr)
548 return HeaderOrErr.takeError();
549
550 const CompressedBundleHeader &Normalized = *HeaderOrErr;
551 unsigned ThisVersion = Normalized.Version;
552 size_t HeaderSize = getHeaderSize(ThisVersion);
553
554 compression::Format CompressionFormat = Normalized.CompressionFormat;
555
556 size_t TotalFileSize = Normalized.FileSize.value_or(0);
557 size_t UncompressedSize = Normalized.UncompressedFileSize;
558 auto StoredHash = Normalized.Hash;
559
560 Timer DecompressTimer("Decompression Timer", "Decompression time",
562 if (VerboseStream)
563 DecompressTimer.startTimer();
564
565 SmallVector<uint8_t, 0> DecompressedData;
566 StringRef CompressedData =
567 Blob.substr(HeaderSize, TotalFileSize - HeaderSize);
568
569 if (Error DecompressionError = compression::decompress(
570 CompressionFormat, arrayRefFromStringRef(CompressedData),
571 DecompressedData, UncompressedSize))
572 return createStringError("could not decompress embedded file contents: " +
573 toString(std::move(DecompressionError)));
574
575 if (VerboseStream) {
576 DecompressTimer.stopTimer();
577
578 double DecompressionTimeSeconds =
579 DecompressTimer.getTotalTime().getWallTime();
580
581 // Recalculate MD5 hash for integrity check.
582 Timer HashRecalcTimer("Hash Recalculation Timer", "Hash recalculation time",
584 HashRecalcTimer.startTimer();
585 MD5 Hash;
586 MD5::MD5Result Result;
587 Hash.update(ArrayRef<uint8_t>(DecompressedData));
588 Hash.final(Result);
589 uint64_t RecalculatedHash = Result.low();
590 HashRecalcTimer.stopTimer();
591 bool HashMatch = (StoredHash == RecalculatedHash);
592
593 double CompressionRate =
594 static_cast<double>(UncompressedSize) / CompressedData.size();
595 double DecompressionSpeedMBs =
596 (UncompressedSize / (1024.0 * 1024.0)) / DecompressionTimeSeconds;
597
598 *VerboseStream << "Compressed bundle format version: " << ThisVersion
599 << "\n";
600 if (ThisVersion >= 2)
601 *VerboseStream << "Total file size (from header): "
602 << formatWithCommas(TotalFileSize) << " bytes\n";
603 *VerboseStream
604 << "Decompression method: "
605 << (CompressionFormat == compression::Format::Zlib ? "zlib" : "zstd")
606 << "\n"
607 << "Size before decompression: "
608 << formatWithCommas(CompressedData.size()) << " bytes\n"
609 << "Size after decompression: " << formatWithCommas(UncompressedSize)
610 << " bytes\n"
611 << "Compression rate: " << format("%.2lf", CompressionRate) << "\n"
612 << "Compression ratio: " << format("%.2lf%%", 100.0 / CompressionRate)
613 << "\n"
614 << "Decompression speed: "
615 << format("%.2lf MB/s", DecompressionSpeedMBs) << "\n"
616 << "Stored hash: " << format_hex(StoredHash, 16) << "\n"
617 << "Recalculated hash: " << format_hex(RecalculatedHash, 16) << "\n"
618 << "Hashes match: " << (HashMatch ? "Yes" : "No") << "\n";
619 }
620
621 return MemoryBuffer::getMemBufferCopy(toStringRef(DecompressedData));
622}
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:558
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)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
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)