[llvm] [memprof] Add extractCallsFromIR (PR #115218)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 6 15:44:36 PST 2024
================
@@ -57,6 +57,41 @@ class MemProfUsePass : public PassInfoMixin<MemProfUsePass> {
IntrusiveRefCntPtr<vfs::FileSystem> FS;
};
+namespace memprof {
+
+struct LineLocation {
+ LineLocation(uint32_t L, uint32_t D) : LineOffset(L), Column(D) {}
+
+ void print(raw_ostream &OS) const;
+ void dump() const;
+
+ 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>;
+
+// Extract all calls from the IR. Arrange them in a map from caller GUIDs to a
+// list of call sites, each of the form {LineLocation, CalleeGUID}.
+DenseMap<uint64_t, SmallVector<CallEdgeTy, 0>> extractCallsFromIR(Module &M);
----------------
kazutakahirata wrote:
I'm using `SmallVector<CallEdgeTy, 0>` as a memory-efficient version of `std::vector`. Note that `sizeof(SmallVector<T, 0>) == 16` while `sizeof(std::vector<T>) == 24`.
I'd like to avoid using inline elements when we have many instances of vectors like a vector of vectors or a map of vectors (at least until we run some numbers) because we could either underutilize those inline elements or waste them when we have more elements, and the effect gets magnified. (For something like a work list in an optimization pass, inline elements would be perfect because we would have just one instance of the vector.)
https://github.com/llvm/llvm-project/pull/115218
More information about the llvm-commits
mailing list