18#define DEBUG_TYPE "cg-data-reader"
27 : FS.getBufferForFile(Filename);
28 if (std::error_code EC = BufferOrErr.getError())
30 return std::move(BufferOrErr.get());
45 if (
Name != CGOutlineName &&
Name != CGMergeName)
49 auto *
Data =
reinterpret_cast<const unsigned char *
>(Contents.data());
50 auto *EndData =
Data + Contents.size();
55 if (
Name == CGOutlineName) {
56 while (
Data != EndData) {
59 GlobalOutlineRecord.
merge(LocalOutlineRecord);
61 }
else if (
Name == CGMergeName) {
62 while (
Data != EndData) {
65 GlobalFunctionMapRecord.
merge(LocalFunctionMapRecord);
70 for (
auto &Section : Obj->
sections()) {
77 processSectionContents(*NameOrErr, *ContentsOrErr);
84 using namespace support;
88 const unsigned MinHeaderSize = 24;
89 if (DataBuffer->getBufferSize() < MinHeaderSize)
93 reinterpret_cast<const unsigned char *
>(DataBuffer->getBufferStart());
95 reinterpret_cast<const unsigned char *
>(DataBuffer->getBufferEnd());
119 if (
Error E = BufferOrError.takeError())
126 if (Buffer->getBufferSize() == 0)
129 std::unique_ptr<CodeGenDataReader> Reader;
132 Reader = std::make_unique<IndexedCodeGenDataReader>(std::move(Buffer));
134 Reader = std::make_unique<TextCodeGenDataReader>(std::move(Buffer));
139 if (
Error E = Reader->read())
142 return std::move(Reader);
146 using namespace support;
150 uint64_t Magic = endian::read<uint64_t, llvm::endianness::little, aligned>(
160 return llvm::all_of(Prefix, [](
char c) {
return isPrint(c) || isSpace(c); });
163 using namespace support;
174 if (Str.equals_insensitive(
"outlined_hash_tree"))
176 else if (Str.equals_insensitive(
"stable_function_map"))
190 const char *Pos = Line->
data();
191 size_t Size =
reinterpret_cast<size_t>(DataBuffer->getBufferEnd()) -
192 reinterpret_cast<size_t>(Pos);
Error success()
Clear the current error and return a successful one.
OutlinedHashTreeRecord HashTreeRecord
The outlined hash tree that has been read.
static Expected< std::unique_ptr< CodeGenDataReader > > create(const Twine &Path, vfs::FileSystem &FS)
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 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...
size_t getBufferSize() const
StringRef getBuffer() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()
Read all of stdin into a file buffer, and return it.
const char * getBufferStart() const
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
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...
bool is_at_eof() const
Return true if we've reached EOF or are an "end" iterator.
This class is the base class for all object file types.
Triple makeTriple() const
Create a triple from the data in this object file.
section_iterator_range sections() const
The virtual file system interface.
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)
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)
std::string getCodeGenDataSectionName(CGDataSectKind CGSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
void deserializeYAML(yaml::Input &YIS)
Deserialize the outlined hash tree from a YAML stream.
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.
void merge(const StableFunctionMapRecord &Other)
Merge the stable function map into this one.
void deserialize(const unsigned char *&Ptr)
Deserialize the stable function map from a raw_ostream.
void deserializeYAML(yaml::Input &YIS)
Deserialize the stable function map from a YAML stream.