Skip to content

[memprof] Remove inline call stacks #117833

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 1 commit into from
Nov 27, 2024

Conversation

kazutakahirata
Copy link
Contributor

Now that MemProf format version 1 has been removed, nobody uses:

  • IndexedAllocationInfo::CallStack
  • IndexedMemProfRecord::CallSites

This patch removed the dead struct fields.

You might notice that IndexedMemProfRecord::{clear,merge} do not
mention CallSiteIds at all. I think it's an oversight. clear doesn't
matter at the moment because we call it during serialization to reduce
memory footprint. merge is simply not as well tested as it should be.
I'll follow up with a separate patch to address these issues.

Now that MemProf format version 1 has been removed, nobody uses:

- IndexedAllocationInfo::CallStack
- IndexedMemProfRecord::CallSites

This patch removed the dead struct fields.

You might notice that IndexedMemProfRecord::{clear,merge} do not
mention CallSiteIds at all.  I think it's an oversight.  clear doesn't
matter at the moment because we call it during serialization to reduce
memory footprint.  merge is simply not as well tested as it should be.
I'll follow up with a separate patch to address these issues.
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Nov 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2024

@llvm/pr-subscribers-pgo

Author: Kazu Hirata (kazutakahirata)

Changes

Now that MemProf format version 1 has been removed, nobody uses:

  • IndexedAllocationInfo::CallStack
  • IndexedMemProfRecord::CallSites

This patch removed the dead struct fields.

You might notice that IndexedMemProfRecord::{clear,merge} do not
mention CallSiteIds at all. I think it's an oversight. clear doesn't
matter at the moment because we call it during serialization to reduce
memory footprint. merge is simply not as well tested as it should be.
I'll follow up with a separate patch to address these issues.


Full diff: https://github.com/llvm/llvm-project/pull/117833.diff

2 Files Affected:

  • (modified) llvm/include/llvm/ProfileData/MemProf.h (+1-18)
  • (modified) llvm/lib/ProfileData/MemProfReader.cpp (+1-2)
diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h
index d64addcfe3ed06..5a29df8e97e20c 100644
--- a/llvm/include/llvm/ProfileData/MemProf.h
+++ b/llvm/include/llvm/ProfileData/MemProf.h
@@ -344,21 +344,11 @@ using LinearCallStackId = uint32_t;
 struct IndexedAllocationInfo {
   // The dynamic calling context for the allocation in bottom-up (leaf-to-root)
   // order. Frame contents are stored out-of-line.
-  // TODO: Remove once we fully transition to CSId.
-  llvm::SmallVector<FrameId> CallStack;
-  // Conceptually the same as above.  We are going to keep both CallStack and
-  // CallStackId while we are transitioning from CallStack to CallStackId.
   CallStackId CSId = 0;
   // The statistics obtained from the runtime for the allocation.
   PortableMemInfoBlock Info;
 
   IndexedAllocationInfo() = default;
-  // This constructor is soft deprecated.  It will be removed once we remove all
-  // users of the CallStack field.
-  IndexedAllocationInfo(ArrayRef<FrameId> CS, CallStackId CSId,
-                        const MemInfoBlock &MB,
-                        const MemProfSchema &Schema = getFullSchema())
-      : CallStack(CS), CSId(CSId), Info(MB, Schema) {}
   IndexedAllocationInfo(CallStackId CSId, const MemInfoBlock &MB,
                         const MemProfSchema &Schema = getFullSchema())
       : CSId(CSId), Info(MB, Schema) {}
@@ -415,21 +405,14 @@ struct IndexedMemProfRecord {
   // list of inline locations in bottom-up order i.e. from leaf to root. The
   // inline location list may include additional entries, users should pick
   // the last entry in the list with the same function GUID.
-  llvm::SmallVector<llvm::SmallVector<FrameId>> CallSites;
-  // Conceptually the same as above.  We are going to keep both CallSites and
-  // CallSiteIds while we are transitioning from CallSites to CallSiteIds.
   llvm::SmallVector<CallStackId> CallSiteIds;
 
-  void clear() {
-    AllocSites.clear();
-    CallSites.clear();
-  }
+  void clear() { AllocSites.clear(); }
 
   void merge(const IndexedMemProfRecord &Other) {
     // TODO: Filter out duplicates which may occur if multiple memprof
     // profiles are merged together using llvm-profdata.
     AllocSites.append(Other.AllocSites);
-    CallSites.append(Other.CallSites);
   }
 
   size_t serializedSize(const MemProfSchema &Schema,
diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp
index 921ff3429fed74..2a7681feccede7 100644
--- a/llvm/lib/ProfileData/MemProfReader.cpp
+++ b/llvm/lib/ProfileData/MemProfReader.cpp
@@ -507,7 +507,7 @@ Error RawMemProfReader::mapRawProfileToRecords() {
     for (size_t I = 0; /*Break out using the condition below*/; I++) {
       const Frame &F = idToFrame(Callstack[I]);
       IndexedMemProfRecord &Record = MemProfData.Records[F.Function];
-      Record.AllocSites.emplace_back(Callstack, CSId, MIB);
+      Record.AllocSites.emplace_back(CSId, MIB);
 
       if (!F.IsInlineFrame)
         break;
@@ -522,7 +522,6 @@ Error RawMemProfReader::mapRawProfileToRecords() {
     for (LocationPtr Loc : Locs) {
       CallStackId CSId = hashCallStack(*Loc);
       MemProfData.CallStacks.insert({CSId, *Loc});
-      Record.CallSites.push_back(*Loc);
       Record.CallSiteIds.push_back(CSId);
     }
   }

Copy link
Contributor

@snehasish snehasish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@kazutakahirata kazutakahirata merged commit 3ce8b7d into llvm:main Nov 27, 2024
10 checks passed
@kazutakahirata kazutakahirata deleted the memprof_remove_dead_fields branch November 27, 2024 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants