Skip to content

Commit d556eb7

Browse files
committed
[DebugInfo][InstrRef][NFC] Cache some PHI resolutions
Install a cache of DBG_INSTR_REF -> ValueIDNum resolutions, for scenarios where the value has to be reconstructed from several DBG_PHIs. Whenever this happens, it's because branch folding + tail duplication has messed with the SSA form of the program, and we have to solve a mini SSA problem to find the variable value. This is always called twice, so it makes sense to cache the value. This gives a ~0.5% geomean compile-time-performance improvement on CTMark. Differential Revision: https://reviews.llvm.org/D118455
1 parent 81d3144 commit d556eb7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,7 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
31223122
DebugPHINumToValue.clear();
31233123
OverlapFragments.clear();
31243124
SeenFragments.clear();
3125+
SeenDbgPHIs.clear();
31253126

31263127
return Changed;
31273128
}
@@ -3387,6 +3388,21 @@ Optional<ValueIDNum> InstrRefBasedLDV::resolveDbgPHIs(MachineFunction &MF,
33873388
ValueIDNum **MLiveIns,
33883389
MachineInstr &Here,
33893390
uint64_t InstrNum) {
3391+
// This function will be called twice per DBG_INSTR_REF, and might end up
3392+
// computing lots of SSA information: memoize it.
3393+
auto SeenDbgPHIIt = SeenDbgPHIs.find(&Here);
3394+
if (SeenDbgPHIIt != SeenDbgPHIs.end())
3395+
return SeenDbgPHIIt->second;
3396+
3397+
Optional<ValueIDNum> Result =
3398+
resolveDbgPHIsImpl(MF, MLiveOuts, MLiveIns, Here, InstrNum);
3399+
SeenDbgPHIs.insert({&Here, Result});
3400+
return Result;
3401+
}
3402+
3403+
Optional<ValueIDNum> InstrRefBasedLDV::resolveDbgPHIsImpl(
3404+
MachineFunction &MF, ValueIDNum **MLiveOuts, ValueIDNum **MLiveIns,
3405+
MachineInstr &Here, uint64_t InstrNum) {
33903406
// Pick out records of DBG_PHI instructions that have been observed. If there
33913407
// are none, then we cannot compute a value number.
33923408
auto RangePair = std::equal_range(DebugPHINumToValue.begin(),

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,12 @@ class InstrRefBasedLDV : public LDVImpl {
864864
OverlapMap OverlapFragments;
865865
VarToFragments SeenFragments;
866866

867+
/// Mapping of DBG_INSTR_REF instructions to their values, for those
868+
/// DBG_INSTR_REFs that call resolveDbgPHIs. These variable references solve
869+
/// a mini SSA problem caused by DBG_PHIs being cloned, this collection caches
870+
/// the result.
871+
DenseMap<MachineInstr *, Optional<ValueIDNum>> SeenDbgPHIs;
872+
867873
/// True if we need to examine call instructions for stack clobbers. We
868874
/// normally assume that they don't clobber SP, but stack probes on Windows
869875
/// do.
@@ -944,6 +950,12 @@ class InstrRefBasedLDV : public LDVImpl {
944950
ValueIDNum **MLiveIns, MachineInstr &Here,
945951
uint64_t InstrNum);
946952

953+
Optional<ValueIDNum> resolveDbgPHIsImpl(MachineFunction &MF,
954+
ValueIDNum **MLiveOuts,
955+
ValueIDNum **MLiveIns,
956+
MachineInstr &Here,
957+
uint64_t InstrNum);
958+
947959
/// Step through the function, recording register definitions and movements
948960
/// in an MLocTracker. Convert the observations into a per-block transfer
949961
/// function in \p MLocTransfer, suitable for using with the machine value

0 commit comments

Comments
 (0)