[PATCH] D143184: [MemProf] Add helper to access the back (last) call stack id

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 3 07:51:46 PST 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6827c4f0dea1: [MemProf] Add helper to access the back (last) call stack id (authored by tejohnson).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143184/new/

https://reviews.llvm.org/D143184

Files:
  llvm/include/llvm/Analysis/MemoryProfileInfo.h
  llvm/lib/Analysis/MemoryProfileInfo.cpp
  llvm/unittests/Analysis/MemoryProfileInfoTest.cpp


Index: llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
===================================================================
--- llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
+++ llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
@@ -401,6 +401,8 @@
     auto *MIBMD = cast<const MDNode>(MIBOp);
     MDNode *StackNode = getMIBStackNode(MIBMD);
     CallStack<MDNode, MDNode::op_iterator> StackContext(StackNode);
+    uint64_t ExpectedBack = First ? 4 : 5;
+    EXPECT_EQ(StackContext.back(), ExpectedBack);
     std::vector<uint64_t> StackIds;
     for (auto ContextIter = StackContext.beginAfterSharedPrefix(InstCallsite);
          ContextIter != StackContext.end(); ++ContextIter)
@@ -450,6 +452,8 @@
     for (auto &MIB : AI.MIBs) {
       CallStack<MIBInfo, SmallVector<unsigned>::const_iterator> StackContext(
           &MIB);
+      uint64_t ExpectedBack = First ? 4 : 5;
+      EXPECT_EQ(Index->getStackIdAtIndex(StackContext.back()), ExpectedBack);
       std::vector<uint64_t> StackIds;
       for (auto StackIdIndex : StackContext)
         StackIds.push_back(Index->getStackIdAtIndex(StackIdIndex));
Index: llvm/lib/Analysis/MemoryProfileInfo.cpp
===================================================================
--- llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -242,3 +242,9 @@
   assert(StackIdCInt);
   return StackIdCInt->getZExtValue();
 }
+
+template <> uint64_t CallStack<MDNode, MDNode::op_iterator>::back() const {
+  assert(N);
+  return mdconst::dyn_extract<ConstantInt>(N->operands().back())
+      ->getZExtValue();
+}
Index: llvm/include/llvm/Analysis/MemoryProfileInfo.h
===================================================================
--- llvm/include/llvm/Analysis/MemoryProfileInfo.h
+++ llvm/include/llvm/Analysis/MemoryProfileInfo.h
@@ -128,6 +128,7 @@
   CallStackIterator begin() const;
   CallStackIterator end() const { return CallStackIterator(N, /*End*/ true); }
   CallStackIterator beginAfterSharedPrefix(CallStack &Other);
+  uint64_t back() const;
 
 private:
   const NodeT *N = nullptr;
@@ -137,8 +138,10 @@
 CallStack<NodeT, IteratorT>::CallStackIterator::CallStackIterator(
     const NodeT *N, bool End)
     : N(N) {
-  if (!N)
+  if (!N) {
+    Iter = nullptr;
     return;
+  }
   Iter = End ? N->StackIdIndices.end() : N->StackIdIndices.begin();
 }
 
@@ -148,6 +151,12 @@
   return *Iter;
 }
 
+template <class NodeT, class IteratorT>
+uint64_t CallStack<NodeT, IteratorT>::back() const {
+  assert(N);
+  return N->StackIdIndices.back();
+}
+
 template <class NodeT, class IteratorT>
 typename CallStack<NodeT, IteratorT>::CallStackIterator
 CallStack<NodeT, IteratorT>::begin() const {
@@ -170,6 +179,7 @@
     const MDNode *N, bool End);
 template <>
 uint64_t CallStack<MDNode, MDNode::op_iterator>::CallStackIterator::operator*();
+template <> uint64_t CallStack<MDNode, MDNode::op_iterator>::back() const;
 
 } // end namespace memprof
 } // end namespace llvm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143184.494641.patch
Type: text/x-patch
Size: 2971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230203/bf48f0cc/attachment.bin>


More information about the llvm-commits mailing list