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());
40 for (
auto &Section : Obj->
sections()) {
47 auto *
Data =
reinterpret_cast<const unsigned char *
>(ContentsOrErr->data());
48 auto *EndData =
Data + ContentsOrErr->size();
50 if (*NameOrErr == CGOutLineName) {
54 while (
Data != EndData) {
57 GlobalOutlineRecord.
merge(LocalOutlineRecord);
67 using namespace support;
70 const unsigned MinHeaderSize = 24;
71 if (DataBuffer->getBufferSize() < MinHeaderSize)
75 reinterpret_cast<const unsigned char *
>(DataBuffer->getBufferStart());
77 reinterpret_cast<const unsigned char *
>(DataBuffer->getBufferEnd());
95 if (
Error E = BufferOrError.takeError())
102 if (Buffer->getBufferSize() == 0)
105 std::unique_ptr<CodeGenDataReader> Reader;
108 Reader = std::make_unique<IndexedCodeGenDataReader>(std::move(Buffer));
110 Reader = std::make_unique<TextCodeGenDataReader>(std::move(Buffer));
115 if (
Error E = Reader->read())
118 return std::move(Reader);
122 using namespace support;
126 uint64_t Magic = endian::read<uint64_t, llvm::endianness::little, aligned>(
136 return llvm::all_of(Prefix, [](
char c) {
return isPrint(c) || isSpace(c); });
139 using namespace support;
150 if (Str.equals_insensitive(
"outlined_hash_tree"))
164 const char *Pos = Line->
data();
165 size_t Size =
reinterpret_cast<size_t>(DataBuffer->getBufferEnd()) -
166 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 ...
static Error mergeFromObjectFile(const object::ObjectFile *Obj, OutlinedHashTreeRecord &GlobalOutlineRecord)
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 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 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.
@ 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.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
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.