Skip to content

Commit 55fd57b

Browse files
committed
Revert rL366946 : [Remarks] Add support for serializing metadata for every remark streamer
This allows every serializer format to implement metaSerializer() and return the corresponding meta serializer. ........ Fix windows build bots http://lab.llvm.org:8011/builders/llvm-clang-x86_64-win-fast http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win llvm-svn: 367004
1 parent 1480229 commit 55fd57b

File tree

6 files changed

+135
-166
lines changed

6 files changed

+135
-166
lines changed

llvm/include/llvm/Remarks/RemarkSerializer.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
namespace llvm {
2121
namespace remarks {
2222

23-
struct MetaSerializer;
24-
2523
/// This is the base class for a remark serializer.
2624
/// It includes support for using a string table while emitting.
2725
struct RemarkSerializer {
@@ -35,24 +33,7 @@ struct RemarkSerializer {
3533

3634
/// This is just an interface.
3735
virtual ~RemarkSerializer() = default;
38-
/// Emit a remark to the stream.
3936
virtual void emit(const Remark &Remark) = 0;
40-
/// Return the corresponding metadata serializer.
41-
virtual std::unique_ptr<MetaSerializer>
42-
metaSerializer(raw_ostream &OS,
43-
Optional<StringRef> ExternalFilename = None) = 0;
44-
};
45-
46-
/// This is the base class for a remark metadata serializer.
47-
struct MetaSerializer {
48-
/// The open raw_ostream that the metadata is emitted to.
49-
raw_ostream &OS;
50-
51-
MetaSerializer(raw_ostream &OS) : OS(OS) {}
52-
53-
/// This is just an interface.
54-
virtual ~MetaSerializer() = default;
55-
virtual void emit() = 0;
5637
};
5738

5839
/// Create a remark serializer.

llvm/include/llvm/Remarks/YAMLRemarkSerializer.h

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,8 @@ struct YAMLRemarkSerializer : public RemarkSerializer {
3636

3737
YAMLRemarkSerializer(raw_ostream &OS);
3838

39+
/// Emit a remark to the stream.
3940
void emit(const Remark &Remark) override;
40-
std::unique_ptr<MetaSerializer>
41-
metaSerializer(raw_ostream &OS,
42-
Optional<StringRef> ExternalFilename = None) override;
43-
};
44-
45-
struct YAMLMetaSerializer : public MetaSerializer {
46-
Optional<StringRef> ExternalFilename;
47-
48-
YAMLMetaSerializer(raw_ostream &OS, Optional<StringRef> ExternalFilename)
49-
: MetaSerializer(OS), ExternalFilename(ExternalFilename) {}
50-
51-
void emit() override;
5241
};
5342

5443
/// Serialize the remarks to YAML using a string table. An remark entry looks
@@ -63,21 +52,6 @@ struct YAMLStrTabRemarkSerializer : public YAMLRemarkSerializer {
6352
: YAMLRemarkSerializer(OS) {
6453
StrTab = std::move(StrTabIn);
6554
}
66-
std::unique_ptr<MetaSerializer>
67-
metaSerializer(raw_ostream &OS,
68-
Optional<StringRef> ExternalFilename = None) override;
69-
};
70-
71-
struct YAMLStrTabMetaSerializer : public YAMLMetaSerializer {
72-
/// The string table is part of the metadata.
73-
StringTable StrTab;
74-
75-
YAMLStrTabMetaSerializer(raw_ostream &OS,
76-
Optional<StringRef> ExternalFilename,
77-
StringTable StrTab)
78-
: YAMLMetaSerializer(OS, ExternalFilename), StrTab(std::move(StrTab)) {}
79-
80-
void emit() override;
8155
};
8256

8357
} // end namespace remarks

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,25 +1349,60 @@ void AsmPrinter::emitRemarksSection(Module &M) {
13491349
RemarkStreamer *RS = M.getContext().getRemarkStreamer();
13501350
if (!RS)
13511351
return;
1352-
remarks::RemarkSerializer &RemarkSerializer = RS->getSerializer();
1353-
1354-
StringRef FilenameRef = RS->getFilename();
1355-
SmallString<128> Filename = FilenameRef;
1356-
sys::fs::make_absolute(Filename);
1357-
assert(!Filename.empty() && "The filename can't be empty.");
1358-
1359-
std::string Buf;
1360-
raw_string_ostream OS(Buf);
1361-
std::unique_ptr<remarks::MetaSerializer> MetaSerializer =
1362-
RemarkSerializer.metaSerializer(OS, StringRef(Filename));
1363-
MetaSerializer->emit();
1352+
const remarks::RemarkSerializer &RemarkSerializer = RS->getSerializer();
13641353

13651354
// Switch to the right section: .remarks/__remarks.
13661355
MCSection *RemarksSection =
13671356
OutContext.getObjectFileInfo()->getRemarksSection();
13681357
OutStreamer->SwitchSection(RemarksSection);
13691358

1370-
OutStreamer->EmitBinaryData(OS.str());
1359+
// Emit the magic number.
1360+
OutStreamer->EmitBytes(remarks::Magic);
1361+
// Explicitly emit a '\0'.
1362+
OutStreamer->EmitIntValue(/*Value=*/0, /*Size=*/1);
1363+
1364+
// Emit the version number: little-endian uint64_t.
1365+
// The version number is located at the offset 0x0 in the section.
1366+
std::array<char, 8> Version;
1367+
support::endian::write64le(Version.data(), remarks::Version);
1368+
OutStreamer->EmitBinaryData(StringRef(Version.data(), Version.size()));
1369+
1370+
// Emit the string table in the section.
1371+
// Note: we need to use the streamer here to emit it in the section. We can't
1372+
// just use the serialize function with a raw_ostream because of the way
1373+
// MCStreamers work.
1374+
uint64_t StrTabSize =
1375+
RemarkSerializer.StrTab ? RemarkSerializer.StrTab->SerializedSize : 0;
1376+
// Emit the total size of the string table (the size itself excluded):
1377+
// little-endian uint64_t.
1378+
// The total size is located after the version number.
1379+
// Note: even if no string table is used, emit 0.
1380+
std::array<char, 8> StrTabSizeBuf;
1381+
support::endian::write64le(StrTabSizeBuf.data(), StrTabSize);
1382+
OutStreamer->EmitBinaryData(
1383+
StringRef(StrTabSizeBuf.data(), StrTabSizeBuf.size()));
1384+
1385+
if (const Optional<remarks::StringTable> &StrTab = RemarkSerializer.StrTab) {
1386+
std::vector<StringRef> StrTabStrings = StrTab->serialize();
1387+
// Emit a list of null-terminated strings.
1388+
// Note: the order is important here: the ID used in the remarks corresponds
1389+
// to the position of the string in the section.
1390+
for (StringRef Str : StrTabStrings) {
1391+
OutStreamer->EmitBytes(Str);
1392+
// Explicitly emit a '\0'.
1393+
OutStreamer->EmitIntValue(/*Value=*/0, /*Size=*/1);
1394+
}
1395+
}
1396+
1397+
// Emit the null-terminated absolute path to the remark file.
1398+
// The path is located at the offset 0x4 in the section.
1399+
StringRef FilenameRef = RS->getFilename();
1400+
SmallString<128> Filename = FilenameRef;
1401+
sys::fs::make_absolute(Filename);
1402+
assert(!Filename.empty() && "The filename can't be empty.");
1403+
OutStreamer->EmitBytes(Filename);
1404+
// Explicitly emit a '\0'.
1405+
OutStreamer->EmitIntValue(/*Value=*/0, /*Size=*/1);
13711406
}
13721407

13731408
bool AsmPrinter::doFinalization(Module &M) {

llvm/lib/Remarks/YAMLRemarkSerializer.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -158,68 +158,3 @@ void YAMLRemarkSerializer::emit(const Remark &Remark) {
158158
auto R = const_cast<remarks::Remark *>(&Remark);
159159
YAMLOutput << R;
160160
}
161-
162-
std::unique_ptr<MetaSerializer>
163-
YAMLRemarkSerializer::metaSerializer(raw_ostream &OS,
164-
Optional<StringRef> ExternalFilename) {
165-
return llvm::make_unique<YAMLMetaSerializer>(OS, ExternalFilename);
166-
}
167-
168-
std::unique_ptr<MetaSerializer> YAMLStrTabRemarkSerializer::metaSerializer(
169-
raw_ostream &OS, Optional<StringRef> ExternalFilename) {
170-
assert(StrTab);
171-
return llvm::make_unique<YAMLStrTabMetaSerializer>(OS, ExternalFilename,
172-
std::move(*StrTab));
173-
}
174-
175-
static void emitMagic(raw_ostream &OS) {
176-
// Emit the magic number.
177-
OS << remarks::Magic;
178-
// Explicitly emit a '\0'.
179-
OS.write('\0');
180-
}
181-
182-
static void emitVersion(raw_ostream &OS) {
183-
// Emit the version number: little-endian uint64_t.
184-
std::array<char, 8> Version;
185-
support::endian::write64le(Version.data(), remarks::Version);
186-
OS.write(Version.data(), Version.size());
187-
}
188-
189-
static void emitStrTab(raw_ostream &OS, const Optional<StringTable> &StrTab) {
190-
// Emit the string table in the section.
191-
uint64_t StrTabSize = StrTab ? StrTab->SerializedSize : 0;
192-
// Emit the total size of the string table (the size itself excluded):
193-
// little-endian uint64_t.
194-
// Note: even if no string table is used, emit 0.
195-
std::array<char, 8> StrTabSizeBuf;
196-
support::endian::write64le(StrTabSizeBuf.data(), StrTabSize);
197-
OS.write(StrTabSizeBuf.data(), StrTabSizeBuf.size());
198-
if (StrTab)
199-
StrTab->serialize(OS);
200-
}
201-
202-
static void emitExternalFile(raw_ostream &OS, StringRef Filename) {
203-
// Emit the null-terminated absolute path to the remark file.
204-
SmallString<128> FilenameBuf = Filename;
205-
sys::fs::make_absolute(FilenameBuf);
206-
assert(!FilenameBuf.empty() && "The filename can't be empty.");
207-
OS.write(FilenameBuf.data(), FilenameBuf.size());
208-
OS.write('\0');
209-
}
210-
211-
void YAMLMetaSerializer::emit() {
212-
emitMagic(OS);
213-
emitVersion(OS);
214-
emitStrTab(OS, None);
215-
if (ExternalFilename)
216-
emitExternalFile(OS, *ExternalFilename);
217-
}
218-
219-
void YAMLStrTabMetaSerializer::emit() {
220-
emitMagic(OS);
221-
emitVersion(OS);
222-
emitStrTab(OS, std::move(StrTab));
223-
if (ExternalFilename)
224-
emitExternalFile(OS, *ExternalFilename);
225-
}

llvm/test/CodeGen/X86/remarks-section.ll

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,75 @@
55
; CHECK-LABEL: func1:
66

77
; CHECK: .section .remarks,"e",@progbits
8-
; CHECK-NEXT: .byte
8+
; The magic number:
9+
; CHECK-NEXT: .ascii "REMARKS"
10+
; Null-terminator:
11+
; CHECK-NEXT: .byte 0
12+
; The version:
13+
; CHECK-NEXT: .byte 0x00, 0x00, 0x00, 0x00
14+
; CHECK-NEXT: .byte 0x00, 0x00, 0x00, 0x00
15+
; The string table size:
16+
; CHECK-NEXT: .byte 0x00, 0x00, 0x00, 0x00
17+
; CHECK-NEXT: .byte 0x00, 0x00, 0x00, 0x00
18+
; The string table:
19+
; EMPTY
20+
; The remark file path:
21+
; CHECK-NEXT: .ascii "[[PATH]]"
22+
; Null-terminator:
23+
; CHECK-NEXT: .byte 0
924

1025
; CHECK-DARWIN: .section __LLVM,__remarks,regular,debug
11-
; CHECK-DARWIN-NEXT: .byte
26+
; The magic number:
27+
; CHECK-DARWIN-NEXT: .ascii "REMARKS"
28+
; Null-terminator:
29+
; CHECK-DARWIN-NEXT: .byte 0
30+
; The version:
31+
; CHECK-DARWIN-NEXT: .byte 0x00, 0x00, 0x00, 0x00
32+
; CHECK-DARWIN-NEXT: .byte 0x00, 0x00, 0x00, 0x00
33+
; The string table size:
34+
; CHECK-DARWIN-NEXT: .byte 0x00, 0x00, 0x00, 0x00
35+
; CHECK-DARWIN-NEXT: .byte 0x00, 0x00, 0x00, 0x00
36+
; The string table:
37+
; EMPTY
38+
; The remark file path:
39+
; CHECK-DARWIN-NEXT: .ascii "[[PATH]]"
40+
; Null-terminator:
41+
; CHECK-DARWIN-NEXT: .byte 0
1242

1343
; CHECK-DARWIN-STRTAB: .section __LLVM,__remarks,regular,debug
14-
; CHECK-DARWIN-STRTAB-NEXT: .byte
44+
; The magic number:
45+
; CHECK-DARWIN-STRTAB-NEXT: .ascii "REMARKS"
46+
; Null-terminator:
47+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
48+
; The version:
49+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0x00, 0x00, 0x00, 0x00
50+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0x00, 0x00, 0x00, 0x00
51+
; The size of the string table:
52+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0x71, 0x00, 0x00, 0x00
53+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0x00, 0x00, 0x00, 0x00
54+
; The string table:
55+
; CHECK-DARWIN-STRTAB-NEXT: .ascii "prologepilog"
56+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
57+
; CHECK-DARWIN-STRTAB-NEXT: .ascii "StackSize"
58+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
59+
; CHECK-DARWIN-STRTAB-NEXT: .ascii "func1"
60+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
61+
; CHECK-DARWIN-STRTAB-NEXT: .byte 48
62+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
63+
; CHECK-DARWIN-STRTAB-NEXT: .ascii " stack bytes in function"
64+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
65+
; CHECK-DARWIN-STRTAB-NEXT: .ascii "asm-printer"
66+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
67+
; CHECK-DARWIN-STRTAB-NEXT: .ascii "InstructionCount"
68+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
69+
; CHECK-DARWIN-STRTAB-NEXT: .byte 49
70+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
71+
; CHECK-DARWIN-STRTAB-NEXT: .ascii " instructions in function"
72+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
73+
; The remark file path:
74+
; CHECK-DARWIN-STRTAB-NEXT: .ascii "[[PATH]]"
75+
; Null-terminator:
76+
; CHECK-DARWIN-STRTAB-NEXT: .byte 0
1577
define void @func1() {
1678
ret void
1779
}

llvm/unittests/Remarks/YAMLRemarksSerializerTest.cpp

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
using namespace llvm;
1515

1616
static void check(const remarks::Remark &R, StringRef ExpectedR,
17-
StringRef ExpectedMeta, bool UseStrTab = false,
17+
Optional<StringRef> ExpectedStrTab = None,
1818
Optional<remarks::StringTable> StrTab = None) {
1919
std::string Buf;
2020
raw_string_ostream OS(Buf);
21+
bool UseStrTab = ExpectedStrTab.hasValue();
2122
Expected<std::unique_ptr<remarks::RemarkSerializer>> MaybeS = [&] {
2223
if (UseStrTab) {
2324
if (StrTab)
@@ -33,12 +34,12 @@ static void check(const remarks::Remark &R, StringRef ExpectedR,
3334

3435
S->emit(R);
3536
EXPECT_EQ(OS.str(), ExpectedR);
36-
37-
Buf.clear();
38-
std::unique_ptr<remarks::MetaSerializer> MS =
39-
S->metaSerializer(OS, StringRef("/externalfile"));
40-
MS->emit();
41-
EXPECT_EQ(OS.str(), ExpectedMeta);
37+
if (ExpectedStrTab) {
38+
Buf.clear();
39+
EXPECT_TRUE(S->StrTab);
40+
S->StrTab->serialize(OS);
41+
EXPECT_EQ(OS.str(), *ExpectedStrTab);
42+
}
4243
}
4344

4445
TEST(YAMLRemarks, SerializerRemark) {
@@ -56,23 +57,17 @@ TEST(YAMLRemarks, SerializerRemark) {
5657
R.Args.back().Key = "keydebug";
5758
R.Args.back().Val = "valuedebug";
5859
R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
59-
check(R,
60-
"--- !Missed\n"
61-
"Pass: pass\n"
62-
"Name: name\n"
63-
"DebugLoc: { File: path, Line: 3, Column: 4 }\n"
64-
"Function: func\n"
65-
"Hotness: 5\n"
66-
"Args:\n"
67-
" - key: value\n"
68-
" - keydebug: valuedebug\n"
69-
" DebugLoc: { File: argpath, Line: 6, Column: 7 }\n"
70-
"...\n",
71-
StringRef("REMARKS\0"
72-
"\0\0\0\0\0\0\0\0"
73-
"\0\0\0\0\0\0\0\0"
74-
"/externalfile\0",
75-
38));
60+
check(R, "--- !Missed\n"
61+
"Pass: pass\n"
62+
"Name: name\n"
63+
"DebugLoc: { File: path, Line: 3, Column: 4 }\n"
64+
"Function: func\n"
65+
"Hotness: 5\n"
66+
"Args:\n"
67+
" - key: value\n"
68+
" - keydebug: valuedebug\n"
69+
" DebugLoc: { File: argpath, Line: 6, Column: 7 }\n"
70+
"...\n");
7671
}
7772

7873
TEST(YAMLRemarks, SerializerRemarkStrTab) {
@@ -102,13 +97,7 @@ TEST(YAMLRemarks, SerializerRemarkStrTab) {
10297
" - keydebug: 5\n"
10398
" DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
10499
"...\n",
105-
StringRef("REMARKS\0"
106-
"\0\0\0\0\0\0\0\0"
107-
"\x2d\0\0\0\0\0\0\0"
108-
"pass\0name\0func\0path\0value\0valuedebug\0argpath\0"
109-
"/externalfile\0",
110-
83),
111-
/*UseStrTab=*/true);
100+
StringRef("pass\0name\0func\0path\0value\0valuedebug\0argpath\0", 45));
112101
}
113102

114103
TEST(YAMLRemarks, SerializerRemarkParsedStrTab) {
@@ -139,12 +128,5 @@ TEST(YAMLRemarks, SerializerRemarkParsedStrTab) {
139128
" - keydebug: 5\n"
140129
" DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
141130
"...\n",
142-
StringRef("REMARKS\0"
143-
"\0\0\0\0\0\0\0\0"
144-
"\x2d\0\0\0\0\0\0\0"
145-
"pass\0name\0func\0path\0value\0valuedebug\0argpath\0"
146-
"/externalfile\0",
147-
83),
148-
/*UseStrTab=*/true,
149-
remarks::StringTable(remarks::ParsedStringTable(StrTab)));
131+
StrTab, remarks::StringTable(remarks::ParsedStringTable(StrTab)));
150132
}

0 commit comments

Comments
 (0)