[llvm] [memprof] Add IndexedMemProfReader::getMemProfCallerCalleePairs (PR #115807)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 14 08:36:40 PST 2024
================
@@ -931,6 +931,83 @@ struct LinearCallStackIdConverter {
}
};
+struct LineLocation {
+ LineLocation(uint32_t L, uint32_t D) : LineOffset(L), Column(D) {}
+
+ bool operator<(const LineLocation &O) const {
+ return LineOffset < O.LineOffset ||
+ (LineOffset == O.LineOffset && Column < O.Column);
+ }
+
+ bool operator==(const LineLocation &O) const {
+ return LineOffset == O.LineOffset && Column == O.Column;
+ }
+
+ bool operator!=(const LineLocation &O) const {
+ return LineOffset != O.LineOffset || Column != O.Column;
+ }
+
+ uint64_t getHashCode() const { return ((uint64_t)Column << 32) | LineOffset; }
+
+ uint32_t LineOffset;
+ uint32_t Column;
+};
+
+// A pair of a call site location and its corresponding callee GUID.
+using CallEdgeTy = std::pair<LineLocation, uint64_t>;
+
+// Used to extract caller-callee pairs from the call stack array. The leaf
+// frame is assumed to call a heap allocation function with GUID 0. The
+// resulting pairs are accumulated in CallerCalleePairs. Users can take it
+// with:
+//
+// auto Pairs = std::move(Extractor.CallerCalleePairs);
+struct CallerCalleePairExtractor {
+ // The base address of the radix tree array.
+ const unsigned char *CallStackBase;
+ // A functor to convert a linear FrameId to a Frame.
+ std::function<Frame(LinearFrameId)> FrameIdToFrame;
----------------
snehasish wrote:
Can this be a llvm::function_ref to avoid a copy of the frame converter? We've seen subtle bugs when copying a functor if there is state to be preserved for error handling in the callstack id converter.
https://github.com/llvm/llvm-project/pull/115807
More information about the llvm-commits
mailing list