[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / include / llvm / Remarks / YAMLRemarkSerializer.h
blob77b78380c07251f5ba21b509f1907821fe6efe5f
1 //===-- YAMLRemarkSerializer.h - YAML Remark serialization ---*- 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 interface for serializing remarks to YAML.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_REMARKS_YAML_REMARK_SERIALIZER_H
14 #define LLVM_REMARKS_YAML_REMARK_SERIALIZER_H
16 #include "llvm/Remarks/RemarkSerializer.h"
17 #include "llvm/Support/YAMLTraits.h"
19 namespace llvm {
20 namespace remarks {
22 /// Serialize the remarks to YAML. One remark entry looks like this:
23 /// --- !<TYPE>
24 /// Pass: <PASSNAME>
25 /// Name: <REMARKNAME>
26 /// DebugLoc: { File: <SOURCEFILENAME>, Line: <SOURCELINE>,
27 /// Column: <SOURCECOLUMN> }
28 /// Function: <FUNCTIONNAME>
29 /// Args:
30 /// - <KEY>: <VALUE>
31 /// DebugLoc: { File: <FILE>, Line: <LINE>, Column: <COL> }
32 /// ...
33 struct YAMLRemarkSerializer : public RemarkSerializer {
34 /// The YAML streamer.
35 yaml::Output YAMLOutput;
37 YAMLRemarkSerializer(raw_ostream &OS, SerializerMode Mode);
39 void emit(const Remark &Remark) override;
40 std::unique_ptr<MetaSerializer>
41 metaSerializer(raw_ostream &OS,
42 Optional<StringRef> ExternalFilename = None) override;
45 struct YAMLMetaSerializer : public MetaSerializer {
46 Optional<StringRef> ExternalFilename;
48 YAMLMetaSerializer(raw_ostream &OS, Optional<StringRef> ExternalFilename)
49 : MetaSerializer(OS), ExternalFilename(ExternalFilename) {}
51 void emit() override;
54 /// Serialize the remarks to YAML using a string table. An remark entry looks
55 /// like the regular YAML remark but instead of string entries it's using
56 /// numbers that map to an index in the string table.
57 struct YAMLStrTabRemarkSerializer : public YAMLRemarkSerializer {
58 /// Wether we already emitted the metadata in standalone mode.
59 /// This should be set to true after the first invocation of `emit`.
60 bool DidEmitMeta = false;
62 YAMLStrTabRemarkSerializer(raw_ostream &OS, SerializerMode Mode)
63 : YAMLRemarkSerializer(OS, Mode) {
64 // Having a string table set up enables the serializer to use it.
65 StrTab.emplace();
67 YAMLStrTabRemarkSerializer(raw_ostream &OS, SerializerMode Mode,
68 StringTable StrTabIn)
69 : YAMLRemarkSerializer(OS, Mode) {
70 StrTab = std::move(StrTabIn);
73 /// Override to emit the metadata if necessary.
74 void emit(const Remark &Remark) override;
76 std::unique_ptr<MetaSerializer>
77 metaSerializer(raw_ostream &OS,
78 Optional<StringRef> ExternalFilename = None) override;
81 struct YAMLStrTabMetaSerializer : public YAMLMetaSerializer {
82 /// The string table is part of the metadata.
83 StringTable StrTab;
85 YAMLStrTabMetaSerializer(raw_ostream &OS,
86 Optional<StringRef> ExternalFilename,
87 StringTable StrTab)
88 : YAMLMetaSerializer(OS, ExternalFilename), StrTab(std::move(StrTab)) {}
90 void emit() override;
93 } // end namespace remarks
94 } // end namespace llvm
96 #endif /* LLVM_REMARKS_REMARK_SERIALIZER_H */