-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[memprof] Move YAML traits to MemProf.h (NFC) #118668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This patch moves the MemProf YAML traits to MemProf.h so that the YAML writer can access them from outside MemProfReader.cpp in the future.
@llvm/pr-subscribers-pgo Author: Kazu Hirata (kazutakahirata) ChangesThis patch moves the MemProf YAML traits to MemProf.h so that the YAML Full diff: https://github.com/llvm/llvm-project/pull/118668.diff 2 Files Affected:
diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index 6ffead4f13aebc..fe017913f6de24 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -12,6 +12,7 @@
#include "llvm/Support/Endian.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/HashBuilder.h"
+#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include <bitset>
@@ -1145,6 +1146,95 @@ template <typename FrameIdTy> class CallStackRadixTreeBuilder {
}
};
} // namespace memprof
+
+namespace yaml {
+template <> struct MappingTraits<memprof::Frame> {
+ static void mapping(IO &Io, memprof::Frame &F) {
+ Io.mapRequired("Function", F.Function);
+ Io.mapRequired("LineOffset", F.LineOffset);
+ Io.mapRequired("Column", F.Column);
+ Io.mapRequired("Inline", F.IsInlineFrame);
+
+ // Assert that the definition of Frame matches what we expect. The
+ // structured bindings below detect changes to the number of fields.
+ // static_assert checks the type of each field.
+ const auto &[Function, SymbolName, LineOffset, Column, IsInlineFrame] = F;
+ static_assert(
+ std::is_same_v<remove_cvref_t<decltype(Function)>, GlobalValue::GUID>);
+ static_assert(std::is_same_v<remove_cvref_t<decltype(SymbolName)>,
+ std::unique_ptr<std::string>>);
+ static_assert(
+ std::is_same_v<remove_cvref_t<decltype(LineOffset)>, uint32_t>);
+ static_assert(std::is_same_v<remove_cvref_t<decltype(Column)>, uint32_t>);
+ static_assert(
+ std::is_same_v<remove_cvref_t<decltype(IsInlineFrame)>, bool>);
+
+ // MSVC issues unused variable warnings despite the uses in static_assert
+ // above.
+ (void)Function;
+ (void)SymbolName;
+ (void)LineOffset;
+ (void)Column;
+ (void)IsInlineFrame;
+ }
+};
+
+template <> struct CustomMappingTraits<memprof::PortableMemInfoBlock> {
+ static void inputOne(IO &Io, StringRef KeyStr,
+ memprof::PortableMemInfoBlock &MIB) {
+ // PortableMemInfoBlock keeps track of the set of fields that actually have
+ // values. We update the set here as we receive a key-value pair from the
+ // YAML document.
+ //
+ // We set MIB.Name via a temporary variable because ScalarTraits<uintptr_t>
+ // isn't available on macOS.
+#define MIBEntryDef(NameTag, Name, Type) \
+ if (KeyStr == #Name) { \
+ uint64_t Value; \
+ Io.mapRequired(KeyStr.str().c_str(), Value); \
+ MIB.Name = static_cast<Type>(Value); \
+ MIB.Schema.set(llvm::to_underlying(memprof::Meta::Name)); \
+ return; \
+ }
+#include "llvm/ProfileData/MIBEntryDef.inc"
+#undef MIBEntryDef
+ Io.setError("Key is not a valid validation event");
+ }
+
+ static void output(IO &Io, memprof::PortableMemInfoBlock &VI) {
+ llvm_unreachable("To be implemented");
+ }
+};
+
+template <> struct MappingTraits<memprof::AllocationInfo> {
+ static void mapping(IO &Io, memprof::AllocationInfo &AI) {
+ Io.mapRequired("Callstack", AI.CallStack);
+ Io.mapRequired("MemInfoBlock", AI.Info);
+ }
+};
+
+// In YAML, we use GUIDMemProfRecordPair instead of MemProfRecord so that we can
+// treat the GUID and the fields within MemProfRecord at the same level as if
+// the GUID were part of MemProfRecord.
+template <> struct MappingTraits<memprof::GUIDMemProfRecordPair> {
+ static void mapping(IO &Io, memprof::GUIDMemProfRecordPair &Pair) {
+ Io.mapRequired("GUID", Pair.GUID);
+ Io.mapRequired("AllocSites", Pair.Record.AllocSites);
+ Io.mapRequired("CallSites", Pair.Record.CallSites);
+ }
+};
+
+template <> struct MappingTraits<memprof::AllMemProfData> {
+ static void mapping(IO &Io, memprof::AllMemProfData &Data) {
+ Io.mapRequired("HeapProfileRecords", Data.HeapProfileRecords);
+ }
+};
+} // namespace yaml
} // namespace llvm
+LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::Frame)
+LLVM_YAML_IS_SEQUENCE_VECTOR(std::vector<memprof::Frame>)
+LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::AllocationInfo)
+LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::GUIDMemProfRecordPair)
+
#endif // LLVM_PROFILEDATA_MEMPROF_H_
diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp
index 1b8a9d3b7cb1de..fdb8e596b0dd3e 100644
--- a/llvm/lib/ProfileData/MemProfReader.cpp
+++ b/llvm/lib/ProfileData/MemProfReader.cpp
@@ -41,97 +41,6 @@
#define DEBUG_TYPE "memprof"
-namespace llvm {
-namespace yaml {
-template <> struct MappingTraits<memprof::Frame> {
- static void mapping(IO &Io, memprof::Frame &F) {
- Io.mapRequired("Function", F.Function);
- Io.mapRequired("LineOffset", F.LineOffset);
- Io.mapRequired("Column", F.Column);
- Io.mapRequired("Inline", F.IsInlineFrame);
-
- // Assert that the definition of Frame matches what we expect. The
- // structured bindings below detect changes to the number of fields.
- // static_assert checks the type of each field.
- const auto &[Function, SymbolName, LineOffset, Column, IsInlineFrame] = F;
- static_assert(
- std::is_same_v<remove_cvref_t<decltype(Function)>, GlobalValue::GUID>);
- static_assert(std::is_same_v<remove_cvref_t<decltype(SymbolName)>,
- std::unique_ptr<std::string>>);
- static_assert(
- std::is_same_v<remove_cvref_t<decltype(LineOffset)>, uint32_t>);
- static_assert(std::is_same_v<remove_cvref_t<decltype(Column)>, uint32_t>);
- static_assert(
- std::is_same_v<remove_cvref_t<decltype(IsInlineFrame)>, bool>);
-
- // MSVC issues unused variable warnings despite the uses in static_assert
- // above.
- (void)Function;
- (void)SymbolName;
- (void)LineOffset;
- (void)Column;
- (void)IsInlineFrame;
- }
-};
-
-template <> struct CustomMappingTraits<memprof::PortableMemInfoBlock> {
- static void inputOne(IO &Io, StringRef KeyStr,
- memprof::PortableMemInfoBlock &MIB) {
- // PortableMemInfoBlock keeps track of the set of fields that actually have
- // values. We update the set here as we receive a key-value pair from the
- // YAML document.
- //
- // We set MIB.Name via a temporary variable because ScalarTraits<uintptr_t>
- // isn't available on macOS.
-#define MIBEntryDef(NameTag, Name, Type) \
- if (KeyStr == #Name) { \
- uint64_t Value; \
- Io.mapRequired(KeyStr.str().c_str(), Value); \
- MIB.Name = static_cast<Type>(Value); \
- MIB.Schema.set(llvm::to_underlying(memprof::Meta::Name)); \
- return; \
- }
-#include "llvm/ProfileData/MIBEntryDef.inc"
-#undef MIBEntryDef
- Io.setError("Key is not a valid validation event");
- }
-
- static void output(IO &Io, memprof::PortableMemInfoBlock &VI) {
- llvm_unreachable("To be implemented");
- }
-};
-
-template <> struct MappingTraits<memprof::AllocationInfo> {
- static void mapping(IO &Io, memprof::AllocationInfo &AI) {
- Io.mapRequired("Callstack", AI.CallStack);
- Io.mapRequired("MemInfoBlock", AI.Info);
- }
-};
-
-// In YAML, we use GUIDMemProfRecordPair instead of MemProfRecord so that we can
-// treat the GUID and the fields within MemProfRecord at the same level as if
-// the GUID were part of MemProfRecord.
-template <> struct MappingTraits<memprof::GUIDMemProfRecordPair> {
- static void mapping(IO &Io, memprof::GUIDMemProfRecordPair &Pair) {
- Io.mapRequired("GUID", Pair.GUID);
- Io.mapRequired("AllocSites", Pair.Record.AllocSites);
- Io.mapRequired("CallSites", Pair.Record.CallSites);
- }
-};
-
-template <> struct MappingTraits<memprof::AllMemProfData> {
- static void mapping(IO &Io, memprof::AllMemProfData &Data) {
- Io.mapRequired("HeapProfileRecords", Data.HeapProfileRecords);
- }
-};
-} // namespace yaml
-} // namespace llvm
-
-LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::Frame)
-LLVM_YAML_IS_SEQUENCE_VECTOR(std::vector<memprof::Frame>)
-LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::AllocationInfo)
-LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::GUIDMemProfRecordPair)
-
namespace llvm {
namespace memprof {
namespace {
|
teresajohnson
approved these changes
Dec 4, 2024
snehasish
reviewed
Dec 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch moves the MemProf YAML traits to MemProf.h so that the YAML
writer can access them from outside MemProfReader.cpp in the future.