15#define DEBUG_TYPE "cg-data-writer"
20 using namespace support;
23 case OStreamKind::fd: {
26 for (
const auto &K :
P) {
27 FDOStream.
seek(K.Pos);
28 for (
size_t I = 0;
I < K.D.size(); ++
I)
34 FDOStream.
seek(LastPos);
37 case OStreamKind::string: {
39 std::string &
Data = SOStream.
str();
40 for (
const auto &K :
P) {
41 for (
size_t I = 0;
I < K.D.size(); ++
I) {
43 endian::byte_swap<uint64_t, llvm::endianness::little>(K.D[
I]);
45 reinterpret_cast<const char *
>(&Bytes),
sizeof(
uint64_t));
50 case OStreamKind::svector: {
52 for (
const auto &K :
P) {
53 for (
size_t I = 0;
I < K.D.size(); ++
I) {
55 endian::byte_swap<uint64_t, llvm::endianness::little>(K.D[
I]);
56 VOStream.
pwrite(
reinterpret_cast<const char *
>(&Bytes),
66 assert(
Record.HashTree &&
"empty hash tree in the record");
73 assert(
Record.FunctionMap &&
"empty function map in the record");
81 return writeImpl(COS);
85 using namespace support;
98 Header.OutlinedHashTreeOffset = 0;
99 Header.StableFunctionMapOffset = 0;
103 COS.
write(Header.Magic);
108 OutlinedHashTreeOffset = COS.
tell();
114 StableFunctionMapOffset = COS.
tell();
123 if (
Error E = writeHeader(COS))
126 std::vector<CGDataPatchItem> PatchItems;
136 PatchItems.emplace_back(OutlinedHashTreeOffset, &OutlinedHashTreeFieldStart,
138 PatchItems.emplace_back(StableFunctionMapOffset, &StableFunctionMapFieldStart,
140 COS.
patch(PatchItems);
147 OS <<
"# Outlined stable hash tree\n:outlined_hash_tree\n";
150 OS <<
"# Stable function map\n:stable_function_map\n";
158 if (
Error E = writeHeaderText(
OS))
161 yaml::Output YOS(
OS);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
A wrapper class to abstract writer stream with support of bytes back patching.
LLVM_ABI void patch(ArrayRef< CGDataPatchItem > P)
LLVM_ABI Error writeText(raw_fd_ostream &OS)
Write the codegen data in text format to OS.
LLVM_ABI Error write(raw_fd_ostream &OS)
Write the codegen data to OS.
bool hasOutlinedHashTree() const
Return true if the header indicates the data has an outlined hash tree.
bool hasStableFunctionMap() const
Return true if the header indicates the data has a stable function map.
LLVM_ABI void addRecord(OutlinedHashTreeRecord &Record)
Add the outlined hash tree record. The input hash tree is released.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
A raw_ostream that writes to a file descriptor.
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
uint64_t tell() const
tell - Return the current offset with the file.
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
A raw_ostream that writes to an SmallVector or SmallString.
This is an optimization pass for GlobalISel generic memory operations.
@ StableFunctionMergingMap
@ FunctionOutlinedHashTree
LLVM_ABI void serializeYAML(yaml::Output &YOS) const
Serialize the outlined hash tree to a YAML stream.
LLVM_ABI void serialize(raw_ostream &OS) const
Serialize the outlined hash tree to a raw_ostream.
std::unique_ptr< OutlinedHashTree > HashTree
The structure of the serialized stable function map is as follows:
std::unique_ptr< StableFunctionMap > FunctionMap
static LLVM_ABI void serialize(raw_ostream &OS, const StableFunctionMap *FunctionMap, std::vector< CGDataPatchItem > &PatchItems)
A static helper function to serialize the stable function map without owning the stable function map.
LLVM_ABI void serializeYAML(yaml::Output &YOS) const
Serialize the stable function map to a YAML stream.