[llvm] [memprof] Add Version2 of the indexed MemProf format (PR #89100)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 17 15:15:11 PDT 2024
================
@@ -633,6 +633,96 @@ class FrameLookupTrait {
}
};
+// Trait for writing call stacks to the on-disk hash table.
+class CallStackWriterTrait {
+public:
+ using key_type = CallStackId;
+ using key_type_ref = CallStackId;
+
+ using data_type = llvm::SmallVector<FrameId>;
+ using data_type_ref = llvm::SmallVector<FrameId> &;
+
+ using hash_value_type = CallStackId;
+ using offset_type = uint64_t;
+
+ static hash_value_type ComputeHash(key_type_ref K) { return K; }
+
+ static std::pair<offset_type, offset_type>
+ EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) {
+ using namespace support;
+ endian::Writer LE(Out, llvm::endianness::little);
+ offset_type N = sizeof(K);
+ LE.write<offset_type>(N);
+ offset_type M = sizeof(CallStackId) * V.size();
+ LE.write<offset_type>(M);
+ return std::make_pair(N, M);
+ }
+
+ void EmitKey(raw_ostream &Out, key_type_ref K, offset_type /*Unused*/) {
+ using namespace support;
+ endian::Writer LE(Out, llvm::endianness::little);
+ LE.write<key_type>(K);
+ }
+
+ void EmitData(raw_ostream &Out, key_type_ref /*Unused*/, data_type_ref V,
+ offset_type /*Unused*/) {
+ using namespace support;
+ endian::Writer LE(Out, llvm::endianness::little);
+ // Emit the frames. We do not explicitly emit the length of the vector
+ // because it can be inferred from the data length.
+ for (FrameId F : V)
+ LE.write<FrameId>(F);
+ }
+};
+
+// Trait for reading call stack mappings from the on-disk hash table.
+class CallStackLookupTrait {
+public:
+ using data_type = const llvm::SmallVector<FrameId>;
+ using internal_key_type = CallStackId;
+ using external_key_type = CallStackId;
+ using hash_value_type = CallStackId;
+ using offset_type = uint64_t;
+
+ static bool EqualKey(internal_key_type A, internal_key_type B) {
+ return A == B;
+ }
+ static uint64_t GetInternalKey(internal_key_type K) { return K; }
+ static uint64_t GetExternalKey(external_key_type K) { return K; }
+
+ hash_value_type ComputeHash(internal_key_type K) { return K; }
+
+ static std::pair<offset_type, offset_type>
+ ReadKeyDataLength(const unsigned char *&D) {
+ using namespace support;
+
+ offset_type KeyLen =
+ endian::readNext<offset_type, llvm::endianness::little>(D);
+ offset_type DataLen =
+ endian::readNext<offset_type, llvm::endianness::little>(D);
+ return std::make_pair(KeyLen, DataLen);
+ }
+
+ uint64_t ReadKey(const unsigned char *D, offset_type /*Unused*/) {
+ using namespace support;
+ return endian::readNext<external_key_type, llvm::endianness::little>(D);
+ }
+
+ data_type ReadData(uint64_t K, const unsigned char *D, offset_type Length) {
+ using namespace support;
+ llvm::SmallVector<FrameId> CS;
+ // Derive the number of frames from the data length.
+ uint64_t NumFrames = Length / sizeof(CallStackId);
----------------
kazutakahirata wrote:
Thank you for catching this! Fixed.
https://github.com/llvm/llvm-project/pull/89100
More information about the llvm-commits
mailing list