[llvm] [llvm-objdump] Optimize live element tracking (PR #158763)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 19:50:28 PDT 2025
================
@@ -97,11 +98,22 @@ class LiveElementPrinter {
std::numeric_limits<unsigned>::max();
};
- // All live elements we know about in the object/image file.
+ // Vector that owns all LiveElement objects for memory management.
std::vector<std::unique_ptr<LiveElement>> LiveElements;
-
- // The columns we are currently drawing.
- IndexedMap<Column> ActiveCols;
+ // Map for fast lookup of live elements by their starting address (LowPC).
+ std::unordered_multimap<uint64_t, LiveElement *> LiveElementsByAddress;
+ // Map for fast lookup of live elements by their ending address (HighPC).
+ std::unordered_multimap<uint64_t, LiveElement *> LiveElementsByEndAddress;
+ // Map from a LiveElement pointer to its index in the LiveElements vector.
+ std::unordered_map<LiveElement *, unsigned> ElementPtrToIndex;
+ // Map from a live element index to column index for efficient lookup.
+ std::unordered_map<unsigned, unsigned> ElementToColumn;
+ // Vector of columns currently used for printing live ranges.
+ std::vector<Column> ActiveCols;
+ // Set of available column indices kept sorted for efficient reuse.
+ std::set<unsigned> FreeCols;
----------------
gulfemsavrun wrote:
The purpose of using `std::set` is to ensure that `*FreeCols.begin()` always retrieves the smallest available column index (ColIdx=1 before ColIdx=3) for deterministic output ordering.
When `ActiveCols` has space (e.g., size 4, with indices 1 and 3 inactive), the column assignment needs to be deterministic and visually sequential.
With `std::set<unsigned> FreeCols`, the process is:
1) `*FreeCols.begin()` returns 1 (the smallest index), as the set is sorted.
2) The next variable is assigned Column 1.
Since `llvm::SmallSet` is unsorted, it doesn't guarantee this behavior. We need to ensure the display always looks clean and columns are reused sequentially (0, 1, 2, 3,..) when `--debug-vars` option is enabled.
https://github.com/llvm/llvm-project/pull/158763
More information about the llvm-commits
mailing list