Skip to content

Commit b59b14e

Browse files
[spr] initial version
Created using spr 1.3.7-wip
2 parents 260ee97 + b90092c commit b59b14e

File tree

4 files changed

+101
-130
lines changed

4 files changed

+101
-130
lines changed

llvm/include/llvm/Remarks/BitstreamRemarkContainer.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ enum BlockIDs {
6767
REMARK_BLOCK_ID
6868
};
6969

70-
constexpr StringRef MetaBlockName = StringRef("Meta", 4);
71-
constexpr StringRef RemarkBlockName = StringRef("Remark", 6);
70+
constexpr StringLiteral MetaBlockName("Meta");
71+
constexpr StringLiteral RemarkBlockName("Remark");
7272

7373
/// The possible records that can be encountered in the previously described
7474
/// blocks.
@@ -89,16 +89,15 @@ enum RecordIDs {
8989
RECORD_LAST = RECORD_REMARK_ARG_WITHOUT_DEBUGLOC
9090
};
9191

92-
constexpr StringRef MetaContainerInfoName = StringRef("Container info", 14);
93-
constexpr StringRef MetaRemarkVersionName = StringRef("Remark version", 14);
94-
constexpr StringRef MetaStrTabName = StringRef("String table", 12);
95-
constexpr StringRef MetaExternalFileName = StringRef("External File", 13);
96-
constexpr StringRef RemarkHeaderName = StringRef("Remark header", 13);
97-
constexpr StringRef RemarkDebugLocName = StringRef("Remark debug location", 21);
98-
constexpr StringRef RemarkHotnessName = StringRef("Remark hotness", 14);
99-
constexpr StringRef RemarkArgWithDebugLocName =
100-
StringRef("Argument with debug location", 28);
101-
constexpr StringRef RemarkArgWithoutDebugLocName = StringRef("Argument", 8);
92+
constexpr StringLiteral MetaContainerInfoName("Container info");
93+
constexpr StringLiteral MetaRemarkVersionName("Remark version");
94+
constexpr StringLiteral MetaStrTabName("String table");
95+
constexpr StringLiteral MetaExternalFileName("External File");
96+
constexpr StringLiteral RemarkHeaderName("Remark header");
97+
constexpr StringLiteral RemarkDebugLocName("Remark debug location");
98+
constexpr StringLiteral RemarkHotnessName("Remark hotness");
99+
constexpr StringLiteral RemarkArgWithDebugLocName("Argument with debug location");
100+
constexpr StringLiteral RemarkArgWithoutDebugLocName("Argument");
102101

103102
} // end namespace remarks
104103
} // end namespace llvm

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)