[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / include / llvm / Remarks / RemarkStringTable.h
blobbe2596d42c886f0da4adc78466bf035f3341e933
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/RemarkParser.h"
22 #include <vector>
24 namespace llvm {
26 class raw_ostream;
28 namespace remarks {
30 /// The string table used for serializing remarks.
31 /// This table can be for example serialized in a section to be consumed after
32 /// the compilation.
33 struct StringTable {
34 /// The string table containing all the unique strings used in the output.
35 /// It maps a string to an unique ID.
36 StringMap<unsigned, BumpPtrAllocator> StrTab;
37 /// Total size of the string table when serialized.
38 size_t SerializedSize = 0;
40 StringTable() = default;
42 /// Disable copy.
43 StringTable(const StringTable &) = delete;
44 StringTable &operator=(const StringTable &) = delete;
45 /// Should be movable.
46 StringTable(StringTable &&) = default;
47 StringTable &operator=(StringTable &&) = default;
49 /// Construct a string table from a ParsedStringTable.
50 StringTable(const ParsedStringTable &Other);
52 /// Add a string to the table. It returns an unique ID of the string.
53 std::pair<unsigned, StringRef> add(StringRef Str);
54 /// Serialize the string table to a stream. It is serialized as a little
55 /// endian uint64 (the size of the table in bytes) followed by a sequence of
56 /// NULL-terminated strings, where the N-th string is the string with the ID N
57 /// in the StrTab map.
58 void serialize(raw_ostream &OS) const;
59 /// Serialize the string table to a vector. This allows users to do the actual
60 /// writing to file/memory/other.
61 /// The string with the ID == N should be the N-th element in the vector.
62 std::vector<StringRef> serialize() const;
65 } // end namespace remarks
66 } // end namespace llvm
68 #endif /* LLVM_REMARKS_REMARK_STRING_TABLE_H */