[llvm] f367eaa - [memprof] Add accessors to Frame::SymbolName (#94085)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 2 22:59:23 PDT 2024


Author: Kazu Hirata
Date: 2024-06-02T22:59:19-07:00
New Revision: f367eaa4647404414ab256d2ac3c4d4f6c6d1363

URL: https://github.com/llvm/llvm-project/commit/f367eaa4647404414ab256d2ac3c4d4f6c6d1363
DIFF: https://github.com/llvm/llvm-project/commit/f367eaa4647404414ab256d2ac3c4d4f6c6d1363.diff

LOG: [memprof] Add accessors to Frame::SymbolName (#94085)

This patch adds accessors to Frame::SymbolName so that we can change
the underlying type of SymbolName without affecting downstream users
once they switch to the new accessors.

Note that SymbolName is only used for debugging.  Changing the type of
SymbolName from std::optional<std::string> to
std::unique_ptr<std::string> cuts down sizeof(Frame) by half -- from
64 bytes to 32 bytes.  (std::optional<T> sets aside the storage in
case T is instantiated.)

During deserialization, the memory usage is dominated by Frames.
Shrinking the type cuts down the memory usage and deserialization time
nearly by half.

Added: 
    

Modified: 
    llvm/include/llvm/ProfileData/MemProf.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index 0e00b243c1575..406144d9db1e8 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -237,6 +237,17 @@ struct Frame {
 
   bool operator!=(const Frame &Other) const { return !operator==(Other); }
 
+  bool hasSymbolName() const { return SymbolName.has_value(); }
+
+  StringRef getSymbolName() const {
+    assert(SymbolName.has_value());
+    return *SymbolName;
+  }
+
+  std::string getSymbolNameOr(StringRef Alt) const {
+    return std::string(hasSymbolName() ? getSymbolName() : Alt);
+  }
+
   // Write the contents of the frame to the ostream \p OS.
   void serialize(raw_ostream &OS) const {
     using namespace support;
@@ -279,7 +290,7 @@ struct Frame {
   void printYAML(raw_ostream &OS) const {
     OS << "      -\n"
        << "        Function: " << Function << "\n"
-       << "        SymbolName: " << SymbolName.value_or("<None>") << "\n"
+       << "        SymbolName: " << getSymbolNameOr("<None>") << "\n"
        << "        LineOffset: " << LineOffset << "\n"
        << "        Column: " << Column << "\n"
        << "        Inline: " << IsInlineFrame << "\n";


        


More information about the llvm-commits mailing list