LLVM 22.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"
22#include <vector>
23
24namespace llvm {
25
26class raw_ostream;
27class StringRef;
28
29namespace remarks {
30
31struct ParsedStringTable;
32struct Remark;
33
34/// The string table used for serializing remarks.
35/// This table can be for example serialized in a section to be consumed after
36/// the compilation.
38 /// The string table containing all the unique strings used in the output.
39 /// It maps a string to an unique ID.
41 /// Total size of the string table when serialized.
42 size_t SerializedSize = 0;
43
44 StringTable() = default;
45
46 /// Disable copy.
47 StringTable(const StringTable &) = delete;
48 StringTable &operator=(const StringTable &) = delete;
49 /// Should be movable.
50 StringTable(StringTable &&) = default;
52
53 /// Construct a string table from a ParsedStringTable.
55
56 /// Add a string to the table. It returns an unique ID of the string.
57 LLVM_ABI std::pair<unsigned, StringRef> add(StringRef Str);
58 /// Modify \p R to use strings from this string table. If the string table
59 /// does not contain the strings, it adds them.
61 /// Serialize the string table to a stream. It is serialized as a little
62 /// endian uint64 (the size of the table in bytes) followed by a sequence of
63 /// NULL-terminated strings, where the N-th string is the string with the ID N
64 /// in the StrTab map.
65 LLVM_ABI void serialize(raw_ostream &OS) const;
66 /// Serialize the string table to a vector. This allows users to do the actual
67 /// writing to file/memory/other.
68 /// The string with the ID == N should be the N-th element in the vector.
69 LLVM_ABI std::vector<StringRef> serialize() const;
70};
71
72} // end namespace remarks
73} // end namespace llvm
74
75#endif // LLVM_REMARKS_REMARKSTRINGTABLE_H
This file defines the StringMap class.
This file defines the BumpPtrAllocator interface.
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
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:61
A remark type used for both emission and parsing.
Definition: Remark.h:98
The string table used for serializing remarks.
StringTable & operator=(StringTable &&)=default
LLVM_ABI std::vector< StringRef > serialize() const
Serialize the string table to a vector.
size_t SerializedSize
Total size of the string table when serialized.
LLVM_ABI 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.
LLVM_ABI std::pair< unsigned, StringRef > add(StringRef Str)
Add a string to the table. It returns an unique ID of the string.