[llvm] a80181a - [DebugInfo][InstrRef][NFC] Free resources at an earlier stage
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 2 04:58:35 PST 2022
Author: Jeremy Morse
Date: 2022-02-02T12:58:15Z
New Revision: a80181a81ea44215e49e5da1457614ec0bd44111
URL: https://github.com/llvm/llvm-project/commit/a80181a81ea44215e49e5da1457614ec0bd44111
DIFF: https://github.com/llvm/llvm-project/commit/a80181a81ea44215e49e5da1457614ec0bd44111.diff
LOG: [DebugInfo][InstrRef][NFC] Free resources at an earlier stage
This patch releases some memory from InstrRefBasedLDV earlier that it would
otherwise. The underlying problem is:
* We store a big table of "live in values for each block",
* We translate that into DBG_VALUE instructions in each block,
And both exist in memory at the same time, which needlessly doubles that
information. The most of what this patch does is: as we progressively
translate live-in information into DBG_VALUEs, we free the variable-value /
machine-value tracking information as we go, which significantly reduces
peak memory.
While I'm here, also add a clear method to wipe variable assignments that
have been accumulated into VLocTracker objects, and turn a DenseMap into
a SmallDenseMap to avoid an initial allocation.
Differential Revision: https://reviews.llvm.org/D118453
Added:
Modified:
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
index 25d764dee2ed..7b06bc9b0c39 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -1029,7 +1029,7 @@ bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI,
// Only handle this instruction when we are building the variable value
// transfer function.
- if (!VTracker)
+ if (!VTracker && !TTracker)
return false;
unsigned InstNo = MI.getOperand(0).getImm();
@@ -1185,7 +1185,8 @@ bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI,
// for DBG_INSTR_REFs as DBG_VALUEs (just, the former can refer to values that
// aren't immediately available).
DbgValueProperties Properties(Expr, false);
- VTracker->defVar(MI, Properties, NewID);
+ if (VTracker)
+ VTracker->defVar(MI, Properties, NewID);
// If we're on the final pass through the function, decompose this INSTR_REF
// into a plain DBG_VALUE.
@@ -2826,6 +2827,7 @@ void InstrRefBasedLDV::emitLocations(
const TargetPassConfig &TPC) {
TTracker = new TransferTracker(TII, MTracker, MF, *TRI, CalleeSavedRegs, TPC);
unsigned NumLocs = MTracker->getNumLocs();
+ VTracker = nullptr;
// For each block, load in the machine value locations and variable value
// live-ins, then step through each instruction in the block. New DBG_VALUEs
@@ -2844,6 +2846,15 @@ void InstrRefBasedLDV::emitLocations(
TTracker->checkInstForNewValues(CurInst, MI.getIterator());
++CurInst;
}
+
+ // Our block information has now been converted into DBG_VALUEs, to be
+ // inserted below. Free the memory we allocated to track variable / register
+ // values. If we don't, we needlessy record the same info in memory twice.
+ delete[] MInLocs[bbnum];
+ delete[] MOutLocs[bbnum];
+ MInLocs[bbnum] = nullptr;
+ MOutLocs[bbnum] = nullptr;
+ SavedLiveIns[bbnum].clear();
}
emitTransfers(AllVarsNumbering);
@@ -3080,6 +3091,12 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
<< " has " << MaxNumBlocks << " basic blocks and "
<< VarAssignCount
<< " variable assignments, exceeding limits.\n");
+
+ // Perform memory cleanup that emitLocations would do otherwise.
+ for (int Idx = 0; Idx < MaxNumBlocks; ++Idx) {
+ delete[] MOutLocs[Idx];
+ delete[] MInLocs[Idx];
+ }
} else {
// Compute the extended ranges, iterating over scopes. There might be
// something to be said for ordering them by size/locality, but that's for
@@ -3091,6 +3108,9 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
vlocs);
}
+ // Now that we've analysed variable assignments, free any tracking data.
+ vlocs.clear();
+
// Using the computed value locations and variable values for each block,
// create the DBG_VALUE instructions representing the extended variable
// locations.
@@ -3100,11 +3120,7 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
Changed = TTracker->Transfers.size() != 0;
}
- // Common clean-up of memory.
- for (int Idx = 0; Idx < MaxNumBlocks; ++Idx) {
- delete[] MOutLocs[Idx];
- delete[] MInLocs[Idx];
- }
+ // Elements of these arrays will be deleted by emitLocations.
delete[] MOutLocs;
delete[] MInLocs;
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
index 1e1bb758d3d4..9ae0d4dd087c 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
@@ -680,7 +680,7 @@ class VLocTracker {
/// movement of values between locations inside of a block is handled at a
/// much later stage, in the TransferTracker class.
MapVector<DebugVariable, DbgValue> Vars;
- DenseMap<DebugVariable, const DILocation *> Scopes;
+ SmallDenseMap<DebugVariable, const DILocation *, 8> Scopes;
MachineBasicBlock *MBB = nullptr;
const OverlapMap &OverlappingFragments;
DbgValueProperties EmptyProperties;
@@ -749,6 +749,11 @@ class VLocTracker {
Scopes[Overlapped] = Loc;
}
}
+
+ void clear() {
+ Vars.clear();
+ Scopes.clear();
+ }
};
// XXX XXX docs
More information about the llvm-commits
mailing list