LLVM 20.0.0git
BitstreamRemarkParser.h
Go to the documentation of this file.
1//===-- BitstreamRemarkParser.h - Bitstream parser --------------*- 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 file provides an implementation of the remark parser using the LLVM
10// Bitstream format.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_REMARKS_BITSTREAMREMARKPARSER_H
15#define LLVM_REMARKS_BITSTREAMREMARKPARSER_H
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/Error.h"
21#include <array>
22#include <cstdint>
23#include <optional>
24
25namespace llvm {
26namespace remarks {
27
28/// Helper to parse a META_BLOCK for a bitstream remark container.
30 /// The Bitstream reader.
32 /// Reference to the storage for the block info.
34 /// The parsed content: depending on the container type, some fields might be
35 /// empty.
36 std::optional<uint64_t> ContainerVersion;
37 std::optional<uint8_t> ContainerType;
38 std::optional<StringRef> StrTabBuf;
39 std::optional<StringRef> ExternalFilePath;
40 std::optional<uint64_t> RemarkVersion;
41
42 /// Continue parsing with \p Stream. \p Stream is expected to contain a
43 /// ENTER_SUBBLOCK to the META_BLOCK at the current position.
44 /// \p Stream is expected to have a BLOCKINFO_BLOCK set.
47
48 /// Parse the META_BLOCK and fill the available entries.
49 /// This helper does not check for the validity of the fields.
50 Error parse();
51};
52
53/// Helper to parse a REMARK_BLOCK for a bitstream remark container.
55 /// The Bitstream reader.
57 /// The parsed content: depending on the remark, some fields might be empty.
58 std::optional<uint8_t> Type;
59 std::optional<uint64_t> RemarkNameIdx;
60 std::optional<uint64_t> PassNameIdx;
61 std::optional<uint64_t> FunctionNameIdx;
62 std::optional<uint64_t> SourceFileNameIdx;
63 std::optional<uint32_t> SourceLine;
64 std::optional<uint32_t> SourceColumn;
65 std::optional<uint64_t> Hotness;
66 struct Argument {
67 std::optional<uint64_t> KeyIdx;
68 std::optional<uint64_t> ValueIdx;
69 std::optional<uint64_t> SourceFileNameIdx;
70 std::optional<uint32_t> SourceLine;
71 std::optional<uint32_t> SourceColumn;
72 };
73 std::optional<ArrayRef<Argument>> Args;
74 /// Avoid re-allocating a vector every time.
76
77 /// Continue parsing with \p Stream. \p Stream is expected to contain a
78 /// ENTER_SUBBLOCK to the REMARK_BLOCK at the current position.
79 /// \p Stream is expected to have a BLOCKINFO_BLOCK set and to have already
80 /// parsed the META_BLOCK.
82
83 /// Parse the REMARK_BLOCK and fill the available entries.
84 /// This helper does not check for the validity of the fields.
85 Error parse();
86};
87
88/// Helper to parse any bitstream remark container.
90 /// The Bitstream reader.
92 /// The block info block.
94 /// Start parsing at \p Buffer.
96 /// Parse the magic number.
98 /// Parse the block info block containing all the abbrevs.
99 /// This needs to be called before calling any other parsing function.
101 /// Return true if the next block is a META_BLOCK. This function does not move
102 /// the cursor.
104 /// Return true if the next block is a REMARK_BLOCK. This function does not
105 /// move the cursor.
107 /// Return true if the parser reached the end of the stream.
108 bool atEndOfStream() { return Stream.AtEndOfStream(); }
109 /// Jump to the end of the stream, skipping everything.
110 void skipToEnd() { return Stream.skipToEnd(); }
111};
112
113} // end namespace remarks
114} // end namespace llvm
115
116#endif // LLVM_REMARKS_BITSTREAMREMARKPARSER_H
This class maintains the abbreviations read from a block info block.
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
void skipToEnd()
Skip to the end of the file.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Helper to parse a META_BLOCK for a bitstream remark container.
std::optional< uint64_t > ContainerVersion
The parsed content: depending on the container type, some fields might be empty.
BitstreamCursor & Stream
The Bitstream reader.
Error parse()
Parse the META_BLOCK and fill the available entries.
BitstreamBlockInfo & BlockInfo
Reference to the storage for the block info.
Helper to parse any bitstream remark container.
Expected< bool > isRemarkBlock()
Return true if the next block is a REMARK_BLOCK.
bool atEndOfStream()
Return true if the parser reached the end of the stream.
void skipToEnd()
Jump to the end of the stream, skipping everything.
Expected< std::array< char, 4 > > parseMagic()
Parse the magic number.
BitstreamBlockInfo BlockInfo
The block info block.
BitstreamCursor Stream
The Bitstream reader.
Expected< bool > isMetaBlock()
Return true if the next block is a META_BLOCK.
Error parseBlockInfoBlock()
Parse the block info block containing all the abbrevs.
Helper to parse a REMARK_BLOCK for a bitstream remark container.
std::optional< uint8_t > Type
The parsed content: depending on the remark, some fields might be empty.
std::optional< ArrayRef< Argument > > Args
BitstreamCursor & Stream
The Bitstream reader.
SmallVector< Argument, 8 > TmpArgs
Avoid re-allocating a vector every time.
Error parse()
Parse the REMARK_BLOCK and fill the available entries.