Skip to content

Commit 1f34d68

Browse files
[Remarks] Remove yaml-strtab format (#144527)
Background: The yaml-strtab format looks just like the yaml format, except that the values in the key/value pairs of the remarks are deduplicated and replaced by indices into a string table (see removed test cases for examples). The motivation behind this format was to reduce size of the remarks files. However, it was quickly superseded by the bitstream format. Therefore, remove the yaml-strtab format, as it doesn't have a good usecase anymore: - It isn't particularly efficient - It isn't human-readable - It isn't straightforward to parse in external tools that can't use the remarks library. We don't even support it in opt-viewer. llvm-remarkutil is also missing options to parse/convert yaml-strtab, so the chance that anyone is actually using this format is low.
1 parent c4d9970 commit 1f34d68

19 files changed

+64
-618
lines changed

llvm/docs/CommandGuide/llvm-opt-report.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ be sent to standard output.
9494
The Argument is one of the following:
9595

9696
- yaml
97-
- yaml-strtab
9897
- bitstream
9998

10099
.. option:: --no-demangle

llvm/docs/Remarks.rst

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ following options:
112112
Supported formats:
113113

114114
* :ref:`yaml <yamlremarks>` (default)
115-
* :ref:`yaml-strtab <yamlstrtabremarks>`
116115
* :ref:`bitstream <bitstreamremarks>`
117116

118117
``Content configuration``
@@ -213,30 +212,6 @@ fields are required:
213212
* ``<arg-line>``
214213
* ``<arg-column>``
215214

216-
.. _yamlstrtabremarks:
217-
218-
YAML with a string table
219-
------------------------
220-
221-
The YAML serialization supports the usage of a string table by using the
222-
``yaml-strtab`` format.
223-
224-
This format replaces strings in the YAML output with integers representing the
225-
index in the string table that can be provided separately through metadata.
226-
227-
The following entries can take advantage of the string table while respecting
228-
YAML rules:
229-
230-
* ``<pass>``
231-
* ``<name>``
232-
* ``<function>``
233-
* ``<file>``
234-
* ``<value>``
235-
* ``<arg-file>``
236-
237-
Currently, none of the tools in :ref:`the opt-viewer directory <optviewer>`
238-
support this format.
239-
240215
.. _optviewer:
241216

242217
YAML metadata
@@ -246,9 +221,9 @@ The metadata used together with the YAML format is:
246221

247222
* a magic number: "REMARKS\\0"
248223
* the version number: a little-endian uint64_t
249-
* the total size of the string table (the size itself excluded):
250-
little-endian uint64_t
251-
* a list of null-terminated strings
224+
* 8 zero bytes. This space was previously used to encode the size of a string
225+
table. String table support for YAML remarks has been removed, use the
226+
bitstream format instead.
252227

253228
Optional:
254229

@@ -584,7 +559,6 @@ Emitting remark diagnostics in the object file
584559
A section containing metadata on remark diagnostics will be emitted for the
585560
following formats:
586561

587-
* ``yaml-strtab``
588562
* ``bitstream``
589563

590564
This can be overridden by using the flag ``-remarks-section=<bool>``.

llvm/include/llvm/Remarks/RemarkFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace remarks {
2323
constexpr StringLiteral Magic("REMARKS");
2424

2525
/// The format used for serializing/deserializing remarks.
26-
enum class Format { Unknown, YAML, YAMLStrTab, Bitstream };
26+
enum class Format { Unknown, YAML, Bitstream };
2727

2828
/// Parse and validate a string for the remark format.
2929
LLVM_ABI Expected<Format> parseFormat(StringRef FormatStr);

llvm/include/llvm/Remarks/RemarkParser.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,8 @@ struct ParsedStringTable {
8080
LLVM_ABI Expected<std::unique_ptr<RemarkParser>>
8181
createRemarkParser(Format ParserFormat, StringRef Buf);
8282

83-
LLVM_ABI Expected<std::unique_ptr<RemarkParser>>
84-
createRemarkParser(Format ParserFormat, StringRef Buf,
85-
ParsedStringTable StrTab);
86-
8783
LLVM_ABI Expected<std::unique_ptr<RemarkParser>> createRemarkParserFromMeta(
8884
Format ParserFormat, StringRef Buf,
89-
std::optional<ParsedStringTable> StrTab = std::nullopt,
9085
std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
9186

9287
} // end namespace remarks

llvm/include/llvm/Remarks/YAMLRemarkSerializer.h

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -63,47 +63,6 @@ struct LLVM_ABI YAMLMetaSerializer : public MetaSerializer {
6363
void emit() override;
6464
};
6565

66-
/// Serialize the remarks to YAML using a string table. An remark entry looks
67-
/// like the regular YAML remark but instead of string entries it's using
68-
/// numbers that map to an index in the string table.
69-
struct LLVM_ABI YAMLStrTabRemarkSerializer : public YAMLRemarkSerializer {
70-
/// Wether we already emitted the metadata in standalone mode.
71-
/// This should be set to true after the first invocation of `emit`.
72-
bool DidEmitMeta = false;
73-
74-
YAMLStrTabRemarkSerializer(raw_ostream &OS, SerializerMode Mode)
75-
: YAMLRemarkSerializer(Format::YAMLStrTab, OS, Mode) {
76-
// We always need a string table for this type of serializer.
77-
StrTab.emplace();
78-
}
79-
YAMLStrTabRemarkSerializer(raw_ostream &OS, SerializerMode Mode,
80-
StringTable StrTab)
81-
: YAMLRemarkSerializer(Format::YAMLStrTab, OS, Mode, std::move(StrTab)) {}
82-
83-
/// Override to emit the metadata if necessary.
84-
void emit(const Remark &Remark) override;
85-
86-
std::unique_ptr<MetaSerializer> metaSerializer(
87-
raw_ostream &OS,
88-
std::optional<StringRef> ExternalFilename = std::nullopt) override;
89-
90-
static bool classof(const RemarkSerializer *S) {
91-
return S->SerializerFormat == Format::YAMLStrTab;
92-
}
93-
};
94-
95-
struct LLVM_ABI YAMLStrTabMetaSerializer : public YAMLMetaSerializer {
96-
/// The string table is part of the metadata.
97-
const StringTable &StrTab;
98-
99-
YAMLStrTabMetaSerializer(raw_ostream &OS,
100-
std::optional<StringRef> ExternalFilename,
101-
const StringTable &StrTab)
102-
: YAMLMetaSerializer(OS, ExternalFilename), StrTab(StrTab) {}
103-
104-
void emit() override;
105-
};
106-
10766
} // end namespace remarks
10867
} // end namespace llvm
10968

llvm/lib/Remarks/BitstreamRemarkParser.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ static Error advanceToMetaBlock(BitstreamParserHelper &Helper) {
308308

309309
Expected<std::unique_ptr<BitstreamRemarkParser>>
310310
remarks::createBitstreamParserFromMeta(
311-
StringRef Buf, std::optional<ParsedStringTable> StrTab,
312-
std::optional<StringRef> ExternalFilePrependPath) {
311+
StringRef Buf, std::optional<StringRef> ExternalFilePrependPath) {
313312
BitstreamParserHelper Helper(Buf);
314313
Expected<std::array<char, 4>> MagicNumber = Helper.parseMagic();
315314
if (!MagicNumber)
@@ -319,9 +318,7 @@ remarks::createBitstreamParserFromMeta(
319318
StringRef(MagicNumber->data(), MagicNumber->size())))
320319
return std::move(E);
321320

322-
auto Parser =
323-
StrTab ? std::make_unique<BitstreamRemarkParser>(Buf, std::move(*StrTab))
324-
: std::make_unique<BitstreamRemarkParser>(Buf);
321+
auto Parser = std::make_unique<BitstreamRemarkParser>(Buf);
325322

326323
if (ExternalFilePrependPath)
327324
Parser->ExternalFilePrependPath = std::string(*ExternalFilePrependPath);

llvm/lib/Remarks/BitstreamRemarkParser.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ struct BitstreamRemarkParser : public RemarkParser {
4848
explicit BitstreamRemarkParser(StringRef Buf)
4949
: RemarkParser(Format::Bitstream), ParserHelper(Buf) {}
5050

51-
/// Create a parser that uses a pre-parsed string table.
52-
BitstreamRemarkParser(StringRef Buf, ParsedStringTable StrTab)
53-
: RemarkParser(Format::Bitstream), ParserHelper(Buf),
54-
StrTab(std::move(StrTab)) {}
55-
5651
Expected<std::unique_ptr<Remark>> next() override;
5752

5853
static bool classof(const RemarkParser *P) {
@@ -77,7 +72,7 @@ struct BitstreamRemarkParser : public RemarkParser {
7772
};
7873

7974
Expected<std::unique_ptr<BitstreamRemarkParser>> createBitstreamParserFromMeta(
80-
StringRef Buf, std::optional<ParsedStringTable> StrTab = std::nullopt,
75+
StringRef Buf,
8176
std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
8277

8378
} // end namespace remarks

llvm/lib/Remarks/RemarkFormat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ using namespace llvm::remarks;
2020
Expected<Format> llvm::remarks::parseFormat(StringRef FormatStr) {
2121
auto Result = StringSwitch<Format>(FormatStr)
2222
.Cases("", "yaml", Format::YAML)
23-
.Case("yaml-strtab", Format::YAMLStrTab)
2423
.Case("bitstream", Format::Bitstream)
2524
.Default(Format::Unknown);
2625

@@ -36,7 +35,8 @@ Expected<Format> llvm::remarks::magicToFormat(StringRef MagicStr) {
3635
auto Result =
3736
StringSwitch<Format>(MagicStr)
3837
.StartsWith("--- ", Format::YAML) // This is only an assumption.
39-
.StartsWith(remarks::Magic, Format::YAMLStrTab)
38+
.StartsWith(remarks::Magic,
39+
Format::YAML) // Needed for remark meta section
4040
.StartsWith(remarks::ContainerMagic, Format::Bitstream)
4141
.Default(Format::Unknown);
4242

llvm/lib/Remarks/RemarkLinker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Error RemarkLinker::link(StringRef Buffer, std::optional<Format> RemarkFormat) {
7676

7777
Expected<std::unique_ptr<RemarkParser>> MaybeParser =
7878
createRemarkParserFromMeta(
79-
*RemarkFormat, Buffer, /*StrTab=*/std::nullopt,
79+
*RemarkFormat, Buffer,
8080
PrependPath ? std::optional<StringRef>(StringRef(*PrependPath))
8181
: std::optional<StringRef>());
8282
if (!MaybeParser)

llvm/lib/Remarks/RemarkParser.cpp

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ llvm::remarks::createRemarkParser(Format ParserFormat, StringRef Buf) {
5353
switch (ParserFormat) {
5454
case Format::YAML:
5555
return std::make_unique<YAMLRemarkParser>(Buf);
56-
case Format::YAMLStrTab:
57-
return createStringError(
58-
std::make_error_code(std::errc::invalid_argument),
59-
"The YAML with string table format requires a parsed string table.");
6056
case Format::Bitstream:
6157
return std::make_unique<BitstreamRemarkParser>(Buf);
6258
case Format::Unknown:
@@ -66,38 +62,15 @@ llvm::remarks::createRemarkParser(Format ParserFormat, StringRef Buf) {
6662
llvm_unreachable("unhandled ParseFormat");
6763
}
6864

69-
Expected<std::unique_ptr<RemarkParser>>
70-
llvm::remarks::createRemarkParser(Format ParserFormat, StringRef Buf,
71-
ParsedStringTable StrTab) {
72-
switch (ParserFormat) {
73-
case Format::YAML:
74-
return createStringError(std::make_error_code(std::errc::invalid_argument),
75-
"The YAML format can't be used with a string "
76-
"table. Use yaml-strtab instead.");
77-
case Format::YAMLStrTab:
78-
return std::make_unique<YAMLStrTabRemarkParser>(Buf, std::move(StrTab));
79-
case Format::Bitstream:
80-
return std::make_unique<BitstreamRemarkParser>(Buf, std::move(StrTab));
81-
case Format::Unknown:
82-
return createStringError(std::make_error_code(std::errc::invalid_argument),
83-
"Unknown remark parser format.");
84-
}
85-
llvm_unreachable("unhandled ParseFormat");
86-
}
87-
8865
Expected<std::unique_ptr<RemarkParser>>
8966
llvm::remarks::createRemarkParserFromMeta(
90-
Format ParserFormat, StringRef Buf, std::optional<ParsedStringTable> StrTab,
67+
Format ParserFormat, StringRef Buf,
9168
std::optional<StringRef> ExternalFilePrependPath) {
9269
switch (ParserFormat) {
93-
// Depending on the metadata, the format can be either yaml or yaml-strtab,
94-
// regardless of the input argument.
9570
case Format::YAML:
96-
case Format::YAMLStrTab:
97-
return createYAMLParserFromMeta(Buf, std::move(StrTab),
98-
std::move(ExternalFilePrependPath));
71+
return createYAMLParserFromMeta(Buf, std::move(ExternalFilePrependPath));
9972
case Format::Bitstream:
100-
return createBitstreamParserFromMeta(Buf, std::move(StrTab),
73+
return createBitstreamParserFromMeta(Buf,
10174
std::move(ExternalFilePrependPath));
10275
case Format::Unknown:
10376
return createStringError(std::make_error_code(std::errc::invalid_argument),
@@ -112,11 +85,8 @@ struct CParser {
11285
std::unique_ptr<RemarkParser> TheParser;
11386
std::optional<std::string> Err;
11487

115-
CParser(Format ParserFormat, StringRef Buf,
116-
std::optional<ParsedStringTable> StrTab = std::nullopt)
117-
: TheParser(cantFail(
118-
StrTab ? createRemarkParser(ParserFormat, Buf, std::move(*StrTab))
119-
: createRemarkParser(ParserFormat, Buf))) {}
88+
CParser(Format ParserFormat, StringRef Buf)
89+
: TheParser(cantFail(createRemarkParser(ParserFormat, Buf))) {}
12090

12191
void handleError(Error E) { Err.emplace(toString(std::move(E))); }
12292
bool hasError() const { return Err.has_value(); }

llvm/lib/Remarks/RemarkSerializer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode,
2626
"Unknown remark serializer format.");
2727
case Format::YAML:
2828
return std::make_unique<YAMLRemarkSerializer>(OS, Mode);
29-
case Format::YAMLStrTab:
30-
return std::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode);
3129
case Format::Bitstream:
3230
return std::make_unique<BitstreamRemarkSerializer>(OS, Mode);
3331
}
@@ -43,9 +41,6 @@ remarks::createRemarkSerializer(Format RemarksFormat, SerializerMode Mode,
4341
"Unknown remark serializer format.");
4442
case Format::YAML:
4543
return std::make_unique<YAMLRemarkSerializer>(OS, Mode, std::move(StrTab));
46-
case Format::YAMLStrTab:
47-
return std::make_unique<YAMLStrTabRemarkSerializer>(OS, Mode,
48-
std::move(StrTab));
4944
case Format::Bitstream:
5045
return std::make_unique<BitstreamRemarkSerializer>(OS, Mode,
5146
std::move(StrTab));

llvm/lib/Remarks/RemarkStreamer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static cl::opt<cl::boolOrDefault> EnableRemarksSection(
2121
"remarks-section",
2222
cl::desc(
2323
"Emit a section containing remark diagnostics metadata. By default, "
24-
"this is enabled for the following formats: yaml-strtab, bitstream."),
24+
"this is enabled for the following formats: bitstream."),
2525
cl::init(cl::BOU_UNSET), cl::Hidden);
2626

2727
RemarkStreamer::RemarkStreamer(
@@ -63,9 +63,7 @@ bool RemarkStreamer::needsSection() const {
6363

6464
// Only some formats need a section:
6565
// * bitstream
66-
// * yaml-strtab
6766
switch (RemarkSerializer->SerializerFormat) {
68-
case remarks::Format::YAMLStrTab:
6967
case remarks::Format::Bitstream:
7068
return true;
7169
default:

0 commit comments

Comments
 (0)