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
19#include "llvm/Support/Error.h"
20
21namespace llvm {
22
23/// A struct to define how the data stream should be patched.
25 uint64_t Pos; // Where to patch.
26 uint64_t *D; // Pointer to an array of source data.
27 int N; // Number of elements in \c D array.
28};
29
30/// A wrapper class to abstract writer stream with support of bytes
31/// back patching.
33public:
35 : IsFDOStream(true), OS(FD), LE(FD, llvm::endianness::little) {}
37 : IsFDOStream(false), OS(STR), LE(STR, llvm::endianness::little) {}
38
39 uint64_t tell() { return OS.tell(); }
40 void write(uint64_t V) { LE.write<uint64_t>(V); }
41 void write32(uint32_t V) { LE.write<uint32_t>(V); }
42 void write8(uint8_t V) { LE.write<uint8_t>(V); }
43
44 // \c patch can only be called when all data is written and flushed.
45 // For raw_string_ostream, the patch is done on the target string
46 // directly and it won't be reflected in the stream's internal buffer.
48
49 // If \c OS is an instance of \c raw_fd_ostream, this field will be
50 // true. Otherwise, \c OS will be an raw_string_ostream.
54};
55
57 /// The outlined hash tree to be written.
58 OutlinedHashTreeRecord HashTreeRecord;
59
60 /// A bit mask describing the kind of the codegen data.
62
63public:
64 CodeGenDataWriter() = default;
65 ~CodeGenDataWriter() = default;
66
67 /// Add the outlined hash tree record. The input Record is released.
69
70 /// Write the codegen data to \c OS
72
73 /// Write the codegen data in text format to \c OS
75
76 /// Return the attributes of the current CGData.
77 CGDataKind getCGDataKind() const { return DataKind; }
78
79 /// Return true if the header indicates the data has an outlined hash tree.
80 bool hasOutlinedHashTree() const {
81 return static_cast<uint32_t>(DataKind) &
83 }
84
85private:
86 /// The offset of the outlined hash tree in the file.
87 uint64_t OutlinedHashTreeOffset;
88
89 /// Write the codegen data header to \c COS
90 Error writeHeader(CGDataOStream &COS);
91
92 /// Write the codegen data header in text to \c OS
93 Error writeHeaderText(raw_fd_ostream &OS);
94
95 Error writeImpl(CGDataOStream &COS);
96};
97
98} // end namespace llvm
99
100#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.
void addRecord(OutlinedHashTreeRecord &Record)
Add the outlined hash tree record. The input Record 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:38
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