Skip to content

Commit 3327a4c

Browse files
[Remarks] Move BitstreamRemarkParser helpers to private header (NFC) (llvm#156302)
These helpers are only used in the implementation, and we also don't expose similar details for the YAMLRemarkParser. Pull Request: llvm#156302
1 parent 1c58bc7 commit 3327a4c

File tree

3 files changed

+90
-118
lines changed

3 files changed

+90
-118
lines changed

llvm/include/llvm/Remarks/BitstreamRemarkParser.h

Lines changed: 0 additions & 116 deletions
This file was deleted.

llvm/lib/Remarks/BitstreamRemarkParser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "llvm/Remarks/BitstreamRemarkParser.h"
1514
#include "BitstreamRemarkParser.h"
1615
#include "llvm/Remarks/Remark.h"
1716
#include "llvm/Support/MemoryBuffer.h"

llvm/lib/Remarks/BitstreamRemarkParser.h

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
#ifndef LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
1414
#define LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
1515

16+
#include "llvm/ADT/ArrayRef.h"
17+
#include "llvm/ADT/StringRef.h"
18+
#include "llvm/Bitstream/BitstreamReader.h"
1619
#include "llvm/Remarks/BitstreamRemarkContainer.h"
17-
#include "llvm/Remarks/BitstreamRemarkParser.h"
1820
#include "llvm/Remarks/RemarkFormat.h"
1921
#include "llvm/Remarks/RemarkParser.h"
22+
#include "llvm/Support/Error.h"
23+
#include <array>
2024
#include <cstdint>
2125
#include <memory>
2226
#include <optional>
@@ -26,6 +30,91 @@ namespace remarks {
2630

2731
struct Remark;
2832

33+
/// Helper to parse a META_BLOCK for a bitstream remark container.
34+
struct BitstreamMetaParserHelper {
35+
/// The Bitstream reader.
36+
BitstreamCursor &Stream;
37+
/// Reference to the storage for the block info.
38+
BitstreamBlockInfo &BlockInfo;
39+
/// The parsed content: depending on the container type, some fields might be
40+
/// empty.
41+
std::optional<uint64_t> ContainerVersion;
42+
std::optional<uint8_t> ContainerType;
43+
std::optional<StringRef> StrTabBuf;
44+
std::optional<StringRef> ExternalFilePath;
45+
std::optional<uint64_t> RemarkVersion;
46+
47+
/// Continue parsing with \p Stream. \p Stream is expected to contain a
48+
/// ENTER_SUBBLOCK to the META_BLOCK at the current position.
49+
/// \p Stream is expected to have a BLOCKINFO_BLOCK set.
50+
BitstreamMetaParserHelper(BitstreamCursor &Stream,
51+
BitstreamBlockInfo &BlockInfo);
52+
53+
/// Parse the META_BLOCK and fill the available entries.
54+
/// This helper does not check for the validity of the fields.
55+
Error parse();
56+
};
57+
58+
/// Helper to parse a REMARK_BLOCK for a bitstream remark container.
59+
struct BitstreamRemarkParserHelper {
60+
/// The Bitstream reader.
61+
BitstreamCursor &Stream;
62+
/// The parsed content: depending on the remark, some fields might be empty.
63+
std::optional<uint8_t> Type;
64+
std::optional<uint64_t> RemarkNameIdx;
65+
std::optional<uint64_t> PassNameIdx;
66+
std::optional<uint64_t> FunctionNameIdx;
67+
std::optional<uint64_t> SourceFileNameIdx;
68+
std::optional<uint32_t> SourceLine;
69+
std::optional<uint32_t> SourceColumn;
70+
std::optional<uint64_t> Hotness;
71+
struct Argument {
72+
std::optional<uint64_t> KeyIdx;
73+
std::optional<uint64_t> ValueIdx;
74+
std::optional<uint64_t> SourceFileNameIdx;
75+
std::optional<uint32_t> SourceLine;
76+
std::optional<uint32_t> SourceColumn;
77+
};
78+
std::optional<ArrayRef<Argument>> Args;
79+
/// Avoid re-allocating a vector every time.
80+
SmallVector<Argument, 8> TmpArgs;
81+
82+
/// Continue parsing with \p Stream. \p Stream is expected to contain a
83+
/// ENTER_SUBBLOCK to the REMARK_BLOCK at the current position.
84+
/// \p Stream is expected to have a BLOCKINFO_BLOCK set and to have already
85+
/// parsed the META_BLOCK.
86+
BitstreamRemarkParserHelper(BitstreamCursor &Stream);
87+
88+
/// Parse the REMARK_BLOCK and fill the available entries.
89+
/// This helper does not check for the validity of the fields.
90+
Error parse();
91+
};
92+
93+
/// Helper to parse any bitstream remark container.
94+
struct BitstreamParserHelper {
95+
/// The Bitstream reader.
96+
BitstreamCursor Stream;
97+
/// The block info block.
98+
BitstreamBlockInfo BlockInfo;
99+
/// Start parsing at \p Buffer.
100+
BitstreamParserHelper(StringRef Buffer);
101+
/// Parse the magic number.
102+
Expected<std::array<char, 4>> parseMagic();
103+
/// Parse the block info block containing all the abbrevs.
104+
/// This needs to be called before calling any other parsing function.
105+
Error parseBlockInfoBlock();
106+
/// Return true if the next block is a META_BLOCK. This function does not move
107+
/// the cursor.
108+
Expected<bool> isMetaBlock();
109+
/// Return true if the next block is a REMARK_BLOCK. This function does not
110+
/// move the cursor.
111+
Expected<bool> isRemarkBlock();
112+
/// Return true if the parser reached the end of the stream.
113+
bool atEndOfStream() { return Stream.AtEndOfStream(); }
114+
/// Jump to the end of the stream, skipping everything.
115+
void skipToEnd() { return Stream.skipToEnd(); }
116+
};
117+
29118
/// Parses and holds the state of the latest parsed remark.
30119
struct BitstreamRemarkParser : public RemarkParser {
31120
/// The buffer to parse.

0 commit comments

Comments
 (0)