[llvm] [llvm-objdump] Optimize live element tracking (PR #158763)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 4 01:51:56 PST 2025
================
@@ -239,57 +302,116 @@ void LiveElementPrinter::addCompileUnit(DWARFDie D) {
void LiveElementPrinter::update(object::SectionedAddress ThisAddr,
object::SectionedAddress NextAddr,
bool IncludeDefinedVars) {
- // Do not create live ranges when debug-inlined-funcs option is provided with
- // line format option.
+ // Exit early if only printing function limits.
if (DbgInlinedFunctions == DFLimitsOnly)
return;
- // First, check variables which have already been assigned a column, so
- // that we don't change their order.
- SmallSet<unsigned, 8> CheckedElementIdxs;
+ // Free columns identified in the previous cycle.
+ for (unsigned ColIdx : ColumnsToFreeNextCycle)
+ freeColumn(ColIdx);
+ ColumnsToFreeNextCycle.clear();
+
+ // Update status of active columns and collect those to free next cycle.
for (unsigned ColIdx = 0, End = ActiveCols.size(); ColIdx < End; ++ColIdx) {
if (!ActiveCols[ColIdx].isActive())
continue;
- CheckedElementIdxs.insert(ActiveCols[ColIdx].ElementIdx);
const std::unique_ptr<LiveElement> &LE =
LiveElements[ActiveCols[ColIdx].ElementIdx];
ActiveCols[ColIdx].LiveIn = LE->liveAtAddress(ThisAddr);
ActiveCols[ColIdx].LiveOut = LE->liveAtAddress(NextAddr);
- std::string Name = Demangle ? demangle(LE->getName()) : LE->getName();
- LLVM_DEBUG(dbgs() << "pass 1, " << ThisAddr.Address << "-"
- << NextAddr.Address << ", " << Name << ", Col " << ColIdx
- << ": LiveIn=" << ActiveCols[ColIdx].LiveIn
- << ", LiveOut=" << ActiveCols[ColIdx].LiveOut << "\n");
- if (!ActiveCols[ColIdx].LiveIn && !ActiveCols[ColIdx].LiveOut)
+ LLVM_DEBUG({
+ std::string Name = Demangle ? demangle(LE->getName()) : LE->getName();
+ dbgs() << "pass 1, " << ThisAddr.Address << "-" << NextAddr.Address
+ << ", " << Name << ", Col " << ColIdx
+ << ": LiveIn=" << ActiveCols[ColIdx].LiveIn
+ << ", LiveOut=" << ActiveCols[ColIdx].LiveOut << "\n";
+ });
+
+ // If element is fully dead, deactivate column immediately.
+ if (!ActiveCols[ColIdx].LiveIn && !ActiveCols[ColIdx].LiveOut) {
ActiveCols[ColIdx].ElementIdx = Column::NullElementIdx;
+ continue;
+ }
+
+ // Mark for cleanup in the next cycle if range ends here.
+ if (ActiveCols[ColIdx].LiveIn && !ActiveCols[ColIdx].LiveOut)
+ ColumnsToFreeNextCycle.push_back(ColIdx);
}
// Next, look for variables which don't already have a column, but which
- // are now live.
+ // are now live (those starting at ThisAddr or NextAddr).
if (IncludeDefinedVars) {
- for (unsigned ElementIdx = 0, End = LiveElements.size(); ElementIdx < End;
- ++ElementIdx) {
- if (CheckedElementIdxs.count(ElementIdx))
+ // Collect all elements starting at ThisAddr and NextAddr.
+ std::vector<std::pair<unsigned, LiveElement *>> NewLiveElements;
+ auto CollectNewElements = [&](const auto &It) {
+ if (It == LiveElementsByAddress.end())
+ return;
+
+ const std::vector<LiveElement *> &ElementList = It->second;
+ // Get the ElementIdx for sorting and column management.
----------------
jh7370 wrote:
Rather than refer to the variable name (which you don't even use until later), just use the real term, i.e. something like "element index".
https://github.com/llvm/llvm-project/pull/158763
More information about the llvm-commits
mailing list