19#define DEBUG_TYPE "cg-data-reader"
29 if (std::error_code EC = BufferOrErr.getError())
31 return std::move(BufferOrErr.get());
38 Triple TT = Obj->makeTriple();
44 auto processSectionContents = [&](
const StringRef &Name,
46 if (Name != CGOutlineName && Name != CGMergeName)
50 auto *
Data =
reinterpret_cast<const unsigned char *
>(Contents.data());
51 auto *EndData =
Data + Contents.size();
56 if (Name == CGOutlineName) {
57 while (
Data != EndData) {
60 GlobalOutlineRecord.
merge(LocalOutlineRecord);
62 }
else if (Name == CGMergeName) {
63 while (
Data != EndData) {
66 GlobalFunctionMapRecord.
merge(LocalFunctionMapRecord);
71 for (
auto &Section : Obj->sections()) {
78 processSectionContents(*NameOrErr, *ContentsOrErr);
89 const unsigned MinHeaderSize = 24;
90 if (DataBuffer->getBufferSize() < MinHeaderSize)
94 reinterpret_cast<const unsigned char *
>(DataBuffer->getBufferStart());
96 reinterpret_cast<const unsigned char *
>(DataBuffer->getBufferEnd());
101 const unsigned char *Ptr = Start + Header.OutlinedHashTreeOffset;
108 std::shared_ptr<MemoryBuffer> SharedDataBuffer = std::move(DataBuffer);
110 const unsigned char *Ptr = Start + Header.StableFunctionMapOffset;
114 CGDataOptions::Global.indexed_codegen_data_read_function_map_names);
117 Header.StableFunctionMapOffset);
130 if (
Error E = BufferOrError.takeError())
138 if (Buffer->getBufferSize() == 0)
141 std::unique_ptr<CodeGenDataReader> Reader;
144 Reader = std::make_unique<IndexedCodeGenDataReader>(std::move(Buffer),
147 Reader = std::make_unique<TextCodeGenDataReader>(std::move(Buffer));
152 if (
Error E = Reader->read())
155 return std::move(Reader);
179 for (; !Line.is_at_eof(); ++Line) {
181 if (Line->trim().empty())
184 if (!Line->starts_with(
":"))
187 if (Str.equals_insensitive(
"outlined_hash_tree"))
189 else if (Str.equals_insensitive(
"stable_function_map"))
196 if (Line.is_at_eof()) {
203 const char *Pos = Line->data();
204 size_t Size =
reinterpret_cast<size_t>(DataBuffer->getBufferEnd()) -
205 reinterpret_cast<size_t>(Pos);
static constexpr StringLiteral Filename
Error success()
Clear the current error and return a successful one.
OutlinedHashTreeRecord HashTreeRecord
The outlined hash tree that has been read.
static LLVM_ABI Expected< std::unique_ptr< CodeGenDataReader > > create(const Twine &Path, vfs::FileSystem &FS, bool LazyLoading=false)
Factory method to create an appropriately typed reader for the given codegen data file path and file ...
StableFunctionMapRecord FunctionMapRecord
The stable function map that has been read. When it's released by.
static LLVM_ABI Error mergeFromObjectFile(const object::ObjectFile *Obj, OutlinedHashTreeRecord &GlobalOutlineRecord, StableFunctionMapRecord &GlobalFunctionMapRecord, stable_hash *CombinedHash=nullptr)
Extract the cgdata embedded in sections from the given object file and merge them into the GlobalOutl...
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 bool hasFormat(const MemoryBuffer &Buffer)
Return true if the given buffer is in binary codegen data format.
Error read() override
Read the contents including the header.
bool hasStableFunctionMap() const override
Return true if the header indicates the data has a stable function map.
bool hasOutlinedHashTree() const override
Return true if the header indicates the data has an outlined hash tree.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
StringRef getBuffer() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
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.
StringRef rtrim(char Char) const
Return string with consecutive Char characters starting from the right removed.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if the given buffer is in text codegen data format.
bool hasStableFunctionMap() const override
Return true if the header indicates the data has a stable function map.
bool hasOutlinedHashTree() const override
Return true if the header indicates the data has an outlined hash tree.
Error read() override
Read the contents including the header.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class is the base class for all object file types.
The virtual file system interface.
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
This is an optimization pass for GlobalISel generic memory operations.
@ StableFunctionMergingMap
@ FunctionOutlinedHashTree
static Expected< std::unique_ptr< MemoryBuffer > > setupMemoryBuffer(const Twine &Filename, vfs::FileSystem &FS)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Inline ArrayRef overloads of the xxhash entry points declared out-of-line in llvm/Support/xxhash....
uint64_t stable_hash
An opaque object representing a stable hash code.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
bool isPrint(char C)
Checks whether character C is printable.
bool isSpace(char C)
Checks whether character C is whitespace in the "C" locale.
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
stable_hash stable_hash_combine(ArrayRef< stable_hash > Buffer)
LLVM_ABI std::string getCodeGenDataSectionName(CGDataSectKind CGSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
LLVM_ABI void deserialize(const unsigned char *&Ptr)
Deserialize the outlined hash tree from a raw_ostream.
void merge(const OutlinedHashTreeRecord &Other)
Merge the other outlined hash tree into this one.
The structure of the serialized stable function map is as follows:
void merge(const StableFunctionMapRecord &Other)
Merge the stable function map into this one.
LLVM_ABI void deserialize(const unsigned char *&Ptr)
Deserialize the stable function map from a raw_ostream.