Skip to content

Commit a80181a

Browse files
committed
[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
1 parent 73ed118 commit a80181a

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI,
10291029

10301030
// Only handle this instruction when we are building the variable value
10311031
// transfer function.
1032-
if (!VTracker)
1032+
if (!VTracker && !TTracker)
10331033
return false;
10341034

10351035
unsigned InstNo = MI.getOperand(0).getImm();
@@ -1185,7 +1185,8 @@ bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI,
11851185
// for DBG_INSTR_REFs as DBG_VALUEs (just, the former can refer to values that
11861186
// aren't immediately available).
11871187
DbgValueProperties Properties(Expr, false);
1188-
VTracker->defVar(MI, Properties, NewID);
1188+
if (VTracker)
1189+
VTracker->defVar(MI, Properties, NewID);
11891190

11901191
// If we're on the final pass through the function, decompose this INSTR_REF
11911192
// into a plain DBG_VALUE.
@@ -2826,6 +2827,7 @@ void InstrRefBasedLDV::emitLocations(
28262827
const TargetPassConfig &TPC) {
28272828
TTracker = new TransferTracker(TII, MTracker, MF, *TRI, CalleeSavedRegs, TPC);
28282829
unsigned NumLocs = MTracker->getNumLocs();
2830+
VTracker = nullptr;
28292831

28302832
// For each block, load in the machine value locations and variable value
28312833
// live-ins, then step through each instruction in the block. New DBG_VALUEs
@@ -2844,6 +2846,15 @@ void InstrRefBasedLDV::emitLocations(
28442846
TTracker->checkInstForNewValues(CurInst, MI.getIterator());
28452847
++CurInst;
28462848
}
2849+
2850+
// Our block information has now been converted into DBG_VALUEs, to be
2851+
// inserted below. Free the memory we allocated to track variable / register
2852+
// values. If we don't, we needlessy record the same info in memory twice.
2853+
delete[] MInLocs[bbnum];
2854+
delete[] MOutLocs[bbnum];
2855+
MInLocs[bbnum] = nullptr;
2856+
MOutLocs[bbnum] = nullptr;
2857+
SavedLiveIns[bbnum].clear();
28472858
}
28482859

28492860
emitTransfers(AllVarsNumbering);
@@ -3080,6 +3091,12 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
30803091
<< " has " << MaxNumBlocks << " basic blocks and "
30813092
<< VarAssignCount
30823093
<< " variable assignments, exceeding limits.\n");
3094+
3095+
// Perform memory cleanup that emitLocations would do otherwise.
3096+
for (int Idx = 0; Idx < MaxNumBlocks; ++Idx) {
3097+
delete[] MOutLocs[Idx];
3098+
delete[] MInLocs[Idx];
3099+
}
30833100
} else {
30843101
// Compute the extended ranges, iterating over scopes. There might be
30853102
// something to be said for ordering them by size/locality, but that's for
@@ -3091,6 +3108,9 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
30913108
vlocs);
30923109
}
30933110

3111+
// Now that we've analysed variable assignments, free any tracking data.
3112+
vlocs.clear();
3113+
30943114
// Using the computed value locations and variable values for each block,
30953115
// create the DBG_VALUE instructions representing the extended variable
30963116
// locations.
@@ -3100,11 +3120,7 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
31003120
Changed = TTracker->Transfers.size() != 0;
31013121
}
31023122

3103-
// Common clean-up of memory.
3104-
for (int Idx = 0; Idx < MaxNumBlocks; ++Idx) {
3105-
delete[] MOutLocs[Idx];
3106-
delete[] MInLocs[Idx];
3107-
}
3123+
// Elements of these arrays will be deleted by emitLocations.
31083124
delete[] MOutLocs;
31093125
delete[] MInLocs;
31103126

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ class VLocTracker {
680680
/// movement of values between locations inside of a block is handled at a
681681
/// much later stage, in the TransferTracker class.
682682
MapVector<DebugVariable, DbgValue> Vars;
683-
DenseMap<DebugVariable, const DILocation *> Scopes;
683+
SmallDenseMap<DebugVariable, const DILocation *, 8> Scopes;
684684
MachineBasicBlock *MBB = nullptr;
685685
const OverlapMap &OverlappingFragments;
686686
DbgValueProperties EmptyProperties;
@@ -749,6 +749,11 @@ class VLocTracker {
749749
Scopes[Overlapped] = Loc;
750750
}
751751
}
752+
753+
void clear() {
754+
Vars.clear();
755+
Scopes.clear();
756+
}
752757
};
753758

754759
// XXX XXX docs

0 commit comments

Comments
 (0)