File indexing completed on 2026-05-10 08:43:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CGDATA_CODEGENDATAWRITER_H
0014 #define LLVM_CGDATA_CODEGENDATAWRITER_H
0015
0016 #include "llvm/CGData/CodeGenData.h"
0017 #include "llvm/CGData/OutlinedHashTreeRecord.h"
0018 #include "llvm/CGData/StableFunctionMapRecord.h"
0019 #include "llvm/Support/EndianStream.h"
0020 #include "llvm/Support/Error.h"
0021
0022 namespace llvm {
0023
0024
0025 struct CGDataPatchItem {
0026 uint64_t Pos;
0027 uint64_t *D;
0028 int N;
0029 };
0030
0031
0032
0033 class CGDataOStream {
0034 public:
0035 CGDataOStream(raw_fd_ostream &FD)
0036 : IsFDOStream(true), OS(FD), LE(FD, llvm::endianness::little) {}
0037 CGDataOStream(raw_string_ostream &STR)
0038 : IsFDOStream(false), OS(STR), LE(STR, llvm::endianness::little) {}
0039
0040 uint64_t tell() { return OS.tell(); }
0041 void write(uint64_t V) { LE.write<uint64_t>(V); }
0042 void write32(uint32_t V) { LE.write<uint32_t>(V); }
0043 void write8(uint8_t V) { LE.write<uint8_t>(V); }
0044
0045
0046
0047
0048 void patch(ArrayRef<CGDataPatchItem> P);
0049
0050
0051
0052 bool IsFDOStream;
0053 raw_ostream &OS;
0054 support::endian::Writer LE;
0055 };
0056
0057 class CodeGenDataWriter {
0058
0059 OutlinedHashTreeRecord HashTreeRecord;
0060
0061
0062 StableFunctionMapRecord FunctionMapRecord;
0063
0064
0065 CGDataKind DataKind = CGDataKind::Unknown;
0066
0067 public:
0068 CodeGenDataWriter() = default;
0069 ~CodeGenDataWriter() = default;
0070
0071
0072 void addRecord(OutlinedHashTreeRecord &Record);
0073
0074
0075 void addRecord(StableFunctionMapRecord &Record);
0076
0077
0078 Error write(raw_fd_ostream &OS);
0079
0080
0081 Error writeText(raw_fd_ostream &OS);
0082
0083
0084 CGDataKind getCGDataKind() const { return DataKind; }
0085
0086
0087 bool hasOutlinedHashTree() const {
0088 return static_cast<uint32_t>(DataKind) &
0089 static_cast<uint32_t>(CGDataKind::FunctionOutlinedHashTree);
0090 }
0091
0092 bool hasStableFunctionMap() const {
0093 return static_cast<uint32_t>(DataKind) &
0094 static_cast<uint32_t>(CGDataKind::StableFunctionMergingMap);
0095 }
0096
0097 private:
0098
0099 uint64_t OutlinedHashTreeOffset;
0100
0101
0102 uint64_t StableFunctionMapOffset;
0103
0104
0105 Error writeHeader(CGDataOStream &COS);
0106
0107
0108 Error writeHeaderText(raw_fd_ostream &OS);
0109
0110 Error writeImpl(CGDataOStream &COS);
0111 };
0112
0113 }
0114
0115 #endif