summaryrefslogtreecommitdiff
path: root/llvm/lib/Remarks/YAMLRemarkSerializer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Remarks/YAMLRemarkSerializer.cpp')
-rw-r--r--llvm/lib/Remarks/YAMLRemarkSerializer.cpp103
1 files changed, 19 insertions, 84 deletions
diff --git a/llvm/lib/Remarks/YAMLRemarkSerializer.cpp b/llvm/lib/Remarks/YAMLRemarkSerializer.cpp
index 68285c3dde1b..846a72182d8f 100644
--- a/llvm/lib/Remarks/YAMLRemarkSerializer.cpp
+++ b/llvm/lib/Remarks/YAMLRemarkSerializer.cpp
@@ -21,11 +21,10 @@ using namespace llvm::remarks;
// Use the same keys whether we use a string table or not (respectively, T is an
// unsigned or a StringRef).
-template <typename T>
-static void mapRemarkHeader(yaml::IO &io, T PassName, T RemarkName,
- std::optional<RemarkLocation> RL, T FunctionName,
- std::optional<uint64_t> Hotness,
- ArrayRef<Argument> Args) {
+static void
+mapRemarkHeader(yaml::IO &io, StringRef PassName, StringRef RemarkName,
+ std::optional<RemarkLocation> RL, StringRef FunctionName,
+ std::optional<uint64_t> Hotness, ArrayRef<Argument> Args) {
io.mapRequired("Pass", PassName);
io.mapRequired("Name", RemarkName);
io.mapOptional("DebugLoc", RL);
@@ -58,19 +57,8 @@ template <> struct MappingTraits<remarks::Remark *> {
else
llvm_unreachable("Unknown remark type");
- if (auto *Serializer = dyn_cast<YAMLStrTabRemarkSerializer>(
- reinterpret_cast<RemarkSerializer *>(io.getContext()))) {
- assert(Serializer->StrTab && "YAMLStrTabSerializer with no StrTab.");
- StringTable &StrTab = *Serializer->StrTab;
- unsigned PassID = StrTab.add(Remark->PassName).first;
- unsigned NameID = StrTab.add(Remark->RemarkName).first;
- unsigned FunctionID = StrTab.add(Remark->FunctionName).first;
- mapRemarkHeader(io, PassID, NameID, Remark->Loc, FunctionID,
- Remark->Hotness, Remark->Args);
- } else {
- mapRemarkHeader(io, Remark->PassName, Remark->RemarkName, Remark->Loc,
- Remark->FunctionName, Remark->Hotness, Remark->Args);
- }
+ mapRemarkHeader(io, Remark->PassName, Remark->RemarkName, Remark->Loc,
+ Remark->FunctionName, Remark->Hotness, Remark->Args);
}
};
@@ -82,15 +70,7 @@ template <> struct MappingTraits<RemarkLocation> {
unsigned Line = RL.SourceLine;
unsigned Col = RL.SourceColumn;
- if (auto *Serializer = dyn_cast<YAMLStrTabRemarkSerializer>(
- reinterpret_cast<RemarkSerializer *>(io.getContext()))) {
- assert(Serializer->StrTab && "YAMLStrTabSerializer with no StrTab.");
- StringTable &StrTab = *Serializer->StrTab;
- unsigned FileID = StrTab.add(File).first;
- io.mapRequired("File", FileID);
- } else {
- io.mapRequired("File", File);
- }
+ io.mapRequired("File", File);
io.mapRequired("Line", Line);
io.mapRequired("Column", Col);
@@ -136,13 +116,7 @@ template <> struct MappingTraits<Argument> {
static void mapping(IO &io, Argument &A) {
assert(io.outputting() && "input not yet implemented");
- if (auto *Serializer = dyn_cast<YAMLStrTabRemarkSerializer>(
- reinterpret_cast<RemarkSerializer *>(io.getContext()))) {
- assert(Serializer->StrTab && "YAMLStrTabSerializer with no StrTab.");
- StringTable &StrTab = *Serializer->StrTab;
- auto ValueID = StrTab.add(A.Val).first;
- io.mapRequired(A.Key.data(), ValueID);
- } else if (StringRef(A.Val).count('\n') > 1) {
+ if (StringRef(A.Val).count('\n') > 1) {
StringBlockVal S(A.Val);
io.mapRequired(A.Key.data(), S);
} else {
@@ -159,12 +133,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(Argument)
YAMLRemarkSerializer::YAMLRemarkSerializer(raw_ostream &OS, SerializerMode Mode,
std::optional<StringTable> StrTabIn)
- : YAMLRemarkSerializer(Format::YAML, OS, Mode, std::move(StrTabIn)) {}
-
-YAMLRemarkSerializer::YAMLRemarkSerializer(Format SerializerFormat,
- raw_ostream &OS, SerializerMode Mode,
- std::optional<StringTable> StrTabIn)
- : RemarkSerializer(SerializerFormat, OS, Mode),
+ : RemarkSerializer(Format::YAML, OS, Mode),
YAMLOutput(OS, reinterpret_cast<void *>(this)) {
StrTab = std::move(StrTabIn);
}
@@ -172,7 +141,7 @@ YAMLRemarkSerializer::YAMLRemarkSerializer(Format SerializerFormat,
void YAMLRemarkSerializer::emit(const Remark &Remark) {
// Again, YAMLTraits expect a non-const object for inputting, but we're not
// using that here.
- auto R = const_cast<remarks::Remark *>(&Remark);
+ auto *R = const_cast<remarks::Remark *>(&Remark);
YAMLOutput << R;
}
@@ -181,27 +150,6 @@ std::unique_ptr<MetaSerializer> YAMLRemarkSerializer::metaSerializer(
return std::make_unique<YAMLMetaSerializer>(OS, ExternalFilename);
}
-void YAMLStrTabRemarkSerializer::emit(const Remark &Remark) {
- // In standalone mode, for the serializer with a string table, emit the
- // metadata first and set DidEmitMeta to avoid emitting it again.
- if (Mode == SerializerMode::Standalone && !DidEmitMeta) {
- std::unique_ptr<MetaSerializer> MetaSerializer =
- metaSerializer(OS, /*ExternalFilename=*/std::nullopt);
- MetaSerializer->emit();
- DidEmitMeta = true;
- }
-
- // Then do the usual remark emission.
- YAMLRemarkSerializer::emit(Remark);
-}
-
-std::unique_ptr<MetaSerializer> YAMLStrTabRemarkSerializer::metaSerializer(
- raw_ostream &OS, std::optional<StringRef> ExternalFilename) {
- assert(StrTab);
- return std::make_unique<YAMLStrTabMetaSerializer>(OS, ExternalFilename,
- *StrTab);
-}
-
static void emitMagic(raw_ostream &OS) {
// Emit the magic number.
OS << remarks::Magic;
@@ -216,20 +164,6 @@ static void emitVersion(raw_ostream &OS) {
OS.write(Version.data(), Version.size());
}
-static void emitStrTab(raw_ostream &OS,
- std::optional<const StringTable *> StrTab) {
- // Emit the string table in the section.
- uint64_t StrTabSize = StrTab ? (*StrTab)->SerializedSize : 0;
- // Emit the total size of the string table (the size itself excluded):
- // little-endian uint64_t.
- // Note: even if no string table is used, emit 0.
- std::array<char, 8> StrTabSizeBuf;
- support::endian::write64le(StrTabSizeBuf.data(), StrTabSize);
- OS.write(StrTabSizeBuf.data(), StrTabSizeBuf.size());
- if (StrTab)
- (*StrTab)->serialize(OS);
-}
-
static void emitExternalFile(raw_ostream &OS, StringRef Filename) {
// Emit the null-terminated absolute path to the remark file.
SmallString<128> FilenameBuf = Filename;
@@ -242,15 +176,16 @@ static void emitExternalFile(raw_ostream &OS, StringRef Filename) {
void YAMLMetaSerializer::emit() {
emitMagic(OS);
emitVersion(OS);
- emitStrTab(OS, std::nullopt);
- if (ExternalFilename)
- emitExternalFile(OS, *ExternalFilename);
-}
-void YAMLStrTabMetaSerializer::emit() {
- emitMagic(OS);
- emitVersion(OS);
- emitStrTab(OS, &StrTab);
+ // Emit StringTable with size 0. This is left over after removing StringTable
+ // support from the YAML format. For now, don't unnecessarily change how the
+ // the metadata is serialized. When changing the format, we should think about
+ // just reusing the bitstream remark meta for this.
+ uint64_t StrTabSize = 0;
+ std::array<char, 8> StrTabSizeBuf;
+ support::endian::write64le(StrTabSizeBuf.data(), StrTabSize);
+
+ OS.write(StrTabSizeBuf.data(), StrTabSizeBuf.size());
if (ExternalFilename)
emitExternalFile(OS, *ExternalFilename);
}