[yaml2obj/obj2yaml] - Add support for .stack_sizes sections.
[llvm-complete.git] / include / llvm / Remarks / RemarkStringTable.h
blob4ce27ee884c8c37026c7eb5ae317a8f3369b0680
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.
12 // For parsing a string table, use ParsedStringTable in RemarkParser.h
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_REMARKS_REMARK_STRING_TABLE_H
17 #define LLVM_REMARKS_REMARK_STRING_TABLE_H
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Remarks/Remark.h"
22 #include <vector>
24 namespace llvm {
26 class raw_ostream;
28 namespace remarks {
30 struct ParsedStringTable;
32 /// The string table used for serializing remarks.
33 /// This table can be for example serialized in a section to be consumed after
34 /// the compilation.
35 struct StringTable {
36 /// The string table containing all the unique strings used in the output.
37 /// It maps a string to an unique ID.
38 StringMap<unsigned, BumpPtrAllocator> StrTab;
39 /// Total size of the string table when serialized.
40 size_t SerializedSize = 0;
42 StringTable() = default;
44 /// Disable copy.
45 StringTable(const StringTable &) = delete;
46 StringTable &operator=(const StringTable &) = delete;
47 /// Should be movable.
48 StringTable(StringTable &&) = default;
49 StringTable &operator=(StringTable &&) = default;
51 /// Construct a string table from a ParsedStringTable.
52 StringTable(const ParsedStringTable &Other);
54 /// Add a string to the table. It returns an unique ID of the string.
55 std::pair<unsigned, StringRef> add(StringRef Str);
56 /// Modify \p R to use strings from this string table. If the string table
57 /// does not contain the strings, it adds them.
58 void internalize(Remark &R);
59 /// Serialize the string table to a stream. It is serialized as a little
60 /// endian uint64 (the size of the table in bytes) followed by a sequence of
61 /// NULL-terminated strings, where the N-th string is the string with the ID N
62 /// in the StrTab map.
63 void serialize(raw_ostream &OS) const;
64 /// Serialize the string table to a vector. This allows users to do the actual
65 /// writing to file/memory/other.
66 /// The string with the ID == N should be the N-th element in the vector.
67 std::vector<StringRef> serialize() const;
70 } // end namespace remarks
71 } // end namespace llvm
73 #endif /* LLVM_REMARKS_REMARK_STRING_TABLE_H */