LLVM 19.0.0git
RemarkStringTable.h
Go to the documentation of this file.
1//===-- RemarkStringTable.h - Serializing string table ----------*- 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 class is used to deduplicate and serialize a string table used for
10// generating remarks.
11//
12// For parsing a string table, use ParsedStringTable in RemarkParser.h
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_REMARKS_REMARKSTRINGTABLE_H
17#define LLVM_REMARKS_REMARKSTRINGTABLE_H
18
19#include "llvm/ADT/StringMap.h"
21#include <vector>
22
23namespace llvm {
24
25class raw_ostream;
26class StringRef;
27
28namespace remarks {
29
30struct ParsedStringTable;
31struct Remark;
32
33/// The string table used for serializing remarks.
34/// This table can be for example serialized in a section to be consumed after
35/// the compilation.
37 /// The string table containing all the unique strings used in the output.
38 /// It maps a string to an unique ID.
40 /// Total size of the string table when serialized.
41 size_t SerializedSize = 0;
42
43 StringTable() = default;
44
45 /// Disable copy.
46 StringTable(const StringTable &) = delete;
47 StringTable &operator=(const StringTable &) = delete;
48 /// Should be movable.
49 StringTable(StringTable &&) = default;
51
52 /// Construct a string table from a ParsedStringTable.
54
55 /// Add a string to the table. It returns an unique ID of the string.
56 std::pair<unsigned, StringRef> add(StringRef Str);
57 /// Modify \p R to use strings from this string table. If the string table
58 /// does not contain the strings, it adds them.
59 void internalize(Remark &R);
60 /// Serialize the string table to a stream. It is serialized as a little
61 /// endian uint64 (the size of the table in bytes) followed by a sequence of
62 /// NULL-terminated strings, where the N-th string is the string with the ID N
63 /// in the StrTab map.
64 void serialize(raw_ostream &OS) const;
65 /// Serialize the string table to a vector. This allows users to do the actual
66 /// writing to file/memory/other.
67 /// The string with the ID == N should be the N-th element in the vector.
68 std::vector<StringRef> serialize() const;
69};
70
71} // end namespace remarks
72} // end namespace llvm
73
74#endif // LLVM_REMARKS_REMARKSTRINGTABLE_H
This file defines the StringMap class.
This file defines the BumpPtrAllocator interface.
raw_pwrite_stream & OS
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Other
Any other memory.
In-memory representation of the string table parsed from a buffer (e.g.
Definition: RemarkParser.h:60
A remark type used for both emission and parsing.
Definition: Remark.h:97
The string table used for serializing remarks.
StringTable & operator=(StringTable &&)=default
std::vector< StringRef > serialize() const
Serialize the string table to a vector.
size_t SerializedSize
Total size of the string table when serialized.
void internalize(Remark &R)
Modify R to use strings from this string table.
StringMap< unsigned, BumpPtrAllocator > StrTab
The string table containing all the unique strings used in the output.
StringTable(StringTable &&)=default
Should be movable.
StringTable & operator=(const StringTable &)=delete
StringTable(const StringTable &)=delete
Disable copy.
std::pair< unsigned, StringRef > add(StringRef Str)
Add a string to the table. It returns an unique ID of the string.