LLVM: lib/CGData/CodeGenDataWriter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
14
15#define DEBUG_TYPE "cg-data-writer"
16
17using namespace llvm;
18
21
22 switch (Kind) {
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)
30 }
31
32
33
34 FDOStream.seek(LastPos);
35 break;
36 }
37 case OStreamKind:🧵 {
39 std::string &Data = SOStream.str();
40 for (const auto &K : P) {
41 for (size_t I = 0; I < K.D.size(); ++I) {
45 reinterpret_cast<const char *>(&Bytes), sizeof(uint64_t));
46 }
47 }
48 break;
49 }
50 case OStreamKind::svector: {
52 for (const auto &K : P) {
53 for (size_t I = 0; I < K.D.size(); ++I) {
56 VOStream.pwrite(reinterpret_cast<const char *>(&Bytes),
58 }
59 }
60 break;
61 }
62 }
63}
64
66 assert(Record.HashTree && "empty hash tree in the record");
67 HashTreeRecord.HashTree = std::move(Record.HashTree);
68
70}
71
73 assert(Record.FunctionMap && "empty function map in the record");
74 FunctionMapRecord.FunctionMap = std::move(Record.FunctionMap);
75
77}
78
81 return writeImpl(COS);
82}
83
89
90
91 Header.DataKind = 0;
93 Header.DataKind |=
96 Header.DataKind |=
98 Header.OutlinedHashTreeOffset = 0;
99 Header.StableFunctionMapOffset = 0;
100
101
102
103 COS.write(Header.Magic);
104 COS.write32(Header.Version);
105 COS.write32(Header.DataKind);
106
107
108 OutlinedHashTreeOffset = COS.tell();
109
110
112
113
114 StableFunctionMapOffset = COS.tell();
115
116
118
120}
121
123 if (Error E = writeHeader(COS))
124 return E;
125
126 std::vector PatchItems;
127
128 uint64_t OutlinedHashTreeFieldStart = COS.tell();
131 uint64_t StableFunctionMapFieldStart = COS.tell();
133 FunctionMapRecord.serialize(COS.OS, PatchItems);
134
135
136 PatchItems.emplace_back(OutlinedHashTreeOffset, &OutlinedHashTreeFieldStart,
137 1);
138 PatchItems.emplace_back(StableFunctionMapOffset, &StableFunctionMapFieldStart,
139 1);
140 COS.patch(PatchItems);
141
143}
144
147 OS << "# Outlined stable hash tree\n:outlined_hash_tree\n";
148
150 OS << "# Stable function map\n:stable_function_map\n";
151
152
153
155}
156
158 if (Error E = writeHeaderText(OS))
159 return E;
160
163 HashTreeRecord.serializeYAML(YOS);
164
166 FunctionMapRecord.serializeYAML(YOS);
167
168
169
171}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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)
Definition CodeGenDataWriter.cpp:19
LLVM_ABI Error writeText(raw_fd_ostream &OS)
Write the codegen data in text format to OS.
Definition CodeGenDataWriter.cpp:157
LLVM_ABI Error write(raw_fd_ostream &OS)
Write the codegen data to OS.
Definition CodeGenDataWriter.cpp:79
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.
Definition CodeGenDataWriter.cpp:65
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.
The Output class is used to generate a yaml document from in-memory structs and vectors.
value_type byte_swap(value_type value, endianness endian)
This is an optimization pass for GlobalISel generic memory operations.
@ StableFunctionMergingMap
@ FunctionOutlinedHashTree
FunctionAddr VTableAddr uintptr_t uintptr_t Data
LLVM_ABI void serialize(raw_ostream &OS) const
Serialize the outlined hash tree to a raw_ostream.
The structure of the serialized stable function map is as follows:
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.