LLVM 20.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
20#include "llvm/Support/Error.h"
21
22namespace llvm {
23
24/// A struct to define how the data stream should be patched.
26 uint64_t Pos; // Where to patch.
27 uint64_t *D; // Pointer to an array of source data.
28 int N; // Number of elements in \c D array.
29};
30
31/// A wrapper class to abstract writer stream with support of bytes
32/// back patching.
34public:
36 : IsFDOStream(true), OS(FD), LE(FD, llvm::endianness::little) {}
38 : IsFDOStream(false), OS(STR), LE(STR, llvm::endianness::little) {}
39
40 uint64_t tell() { return OS.tell(); }
41 void write(uint64_t V) { LE.write<uint64_t>(V); }
42 void write32(uint32_t V) { LE.write<uint32_t>(V); }
43 void write8(uint8_t V) { LE.write<uint8_t>(V); }
44
45 // \c patch can only be called when all data is written and flushed.
46 // For raw_string_ostream, the patch is done on the target string
47 // directly and it won't be reflected in the stream's internal buffer.
49
50 // If \c OS is an instance of \c raw_fd_ostream, this field will be
51 // true. Otherwise, \c OS will be an raw_string_ostream.
55};
56
58 /// The outlined hash tree to be written.
59 OutlinedHashTreeRecord HashTreeRecord;
60
61 /// The stable function map to be written.
62 StableFunctionMapRecord FunctionMapRecord;
63
64 /// A bit mask describing the kind of the codegen data.
66
67public:
68 CodeGenDataWriter() = default;
69 ~CodeGenDataWriter() = default;
70
71 /// Add the outlined hash tree record. The input hash tree is released.
73
74 /// Add the stable function map record. The input function map is released.
76
77 /// Write the codegen data to \c OS
79
80 /// Write the codegen data in text format to \c OS
82
83 /// Return the attributes of the current CGData.
84 CGDataKind getCGDataKind() const { return DataKind; }
85
86 /// Return true if the header indicates the data has an outlined hash tree.
87 bool hasOutlinedHashTree() const {
88 return static_cast<uint32_t>(DataKind) &
90 }
91 /// Return true if the header indicates the data has a stable function map.
92 bool hasStableFunctionMap() const {
93 return static_cast<uint32_t>(DataKind) &
95 }
96
97private:
98 /// The offset of the outlined hash tree in the file.
99 uint64_t OutlinedHashTreeOffset;
100
101 /// The offset of the stable function map in the file.
102 uint64_t StableFunctionMapOffset;
103
104 /// Write the codegen data header to \c COS
105 Error writeHeader(CGDataOStream &COS);
106
107 /// Write the codegen data header in text to \c OS
108 Error writeHeaderText(raw_fd_ostream &OS);
109
110 Error writeImpl(CGDataOStream &COS);
111};
112
113} // end namespace llvm
114
115#endif // LLVM_CGDATA_CODEGENDATAWRITER_H
basic Basic Alias true
#define P(N)
raw_pwrite_stream & OS
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.
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)
support::endian::Writer LE
void write(uint64_t V)
CGDataKind getCGDataKind() const
Return the attributes of the current CGData.
Error writeText(raw_fd_ostream &OS)
Write the codegen data in text format to OS.
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.
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:160
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:460
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:147
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
CGDataKind
Definition: CodeGenData.h:41
endianness
Definition: bit.h:70
A struct to define how the data stream should be patched.
Adapter to write values to a stream in a particular byte order.
Definition: EndianStream.h:67
void write(ArrayRef< value_type > Val)
Definition: EndianStream.h:71