LLVM 22.0.0git
CodeGenDataWriter.h
Go to the documentation of this file.
1//===- CodeGenDataWriter.h --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains support for writing codegen data.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CGDATA_CODEGENDATAWRITER_H
14#define LLVM_CGDATA_CODEGENDATAWRITER_H
15
22#include "llvm/Support/Error.h"
23
24namespace llvm {
25
26/// A wrapper class to abstract writer stream with support of bytes
27/// back patching.
29 enum class OStreamKind {
30 fd,
31 string,
32 svector,
33 };
34
35public:
37 : Kind(OStreamKind::fd), OS(FD), LE(FD, llvm::endianness::little) {}
39 : Kind(OStreamKind::string), OS(STR), LE(STR, llvm::endianness::little) {}
41 : Kind(OStreamKind::svector), OS(SVEC),
42 LE(SVEC, llvm::endianness::little) {}
43
44 uint64_t tell() { return OS.tell(); }
45 void write(uint64_t V) { LE.write<uint64_t>(V); }
46 void write32(uint32_t V) { LE.write<uint32_t>(V); }
47 void write8(uint8_t V) { LE.write<uint8_t>(V); }
48
49 // \c patch can only be called when all data is written and flushed.
50 // For raw_string_ostream, the patch is done on the target string
51 // directly and it won't be reflected in the stream's internal buffer.
53
54 OStreamKind Kind;
57};
58
60 /// The outlined hash tree to be written.
61 OutlinedHashTreeRecord HashTreeRecord;
62
63 /// The stable function map to be written.
64 StableFunctionMapRecord FunctionMapRecord;
65
66 /// A bit mask describing the kind of the codegen data.
68
69public:
70 CodeGenDataWriter() = default;
71 ~CodeGenDataWriter() = default;
72
73 /// Add the outlined hash tree record. The input hash tree is released.
75
76 /// Add the stable function map record. The input function map is released.
78
79 /// Write the codegen data to \c OS
81
82 /// Write the codegen data in text format to \c OS
84
85 /// Return the attributes of the current CGData.
86 CGDataKind getCGDataKind() const { return DataKind; }
87
88 /// Return true if the header indicates the data has an outlined hash tree.
89 bool hasOutlinedHashTree() const {
90 return static_cast<uint32_t>(DataKind) &
92 }
93 /// Return true if the header indicates the data has a stable function map.
94 bool hasStableFunctionMap() const {
95 return static_cast<uint32_t>(DataKind) &
97 }
98
99private:
100 /// The offset of the outlined hash tree in the file.
101 uint64_t OutlinedHashTreeOffset;
102
103 /// The offset of the stable function map in the file.
104 uint64_t StableFunctionMapOffset;
105
106 /// Write the codegen data header to \c COS
107 Error writeHeader(CGDataOStream &COS);
108
109 /// Write the codegen data header in text to \c OS
110 Error writeHeaderText(raw_fd_ostream &OS);
111
112 Error writeImpl(CGDataOStream &COS);
113};
114
115} // end namespace llvm
116
117#endif // LLVM_CGDATA_CODEGENDATAWRITER_H
#define LLVM_ABI
Definition Compiler.h:213
#define P(N)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
A wrapper class to abstract writer stream with support of bytes back patching.
LLVM_ABI void patch(ArrayRef< CGDataPatchItem > P)
CGDataOStream(raw_string_ostream &STR)
void write8(uint8_t V)
void write32(uint32_t V)
CGDataOStream(raw_fd_ostream &FD)
CGDataOStream(raw_svector_ostream &SVEC)
support::endian::Writer LE
void write(uint64_t V)
CGDataKind getCGDataKind() const
Return the attributes of the current CGData.
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.
Definition Error.h:159
A raw_ostream that writes to a file descriptor.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
This is an optimization pass for GlobalISel generic memory operations.
endianness
Definition bit.h:71
The structure of the serialized stable function map is as follows:
Adapter to write values to a stream in a particular byte order.