[llvm] d556eb7 - [DebugInfo][InstrRef][NFC] Cache some PHI resolutions
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 2 04:22:03 PST 2022
Author: Jeremy Morse
Date: 2022-02-02T12:21:28Z
New Revision: d556eb7e27c25ae20befb0811bc8a3423241431d
URL: https://github.com/llvm/llvm-project/commit/d556eb7e27c25ae20befb0811bc8a3423241431d
DIFF: https://github.com/llvm/llvm-project/commit/d556eb7e27c25ae20befb0811bc8a3423241431d.diff
LOG: [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
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 2e69a5e437e76..25d764dee2ed8 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
@@ -3122,6 +3122,7 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
DebugPHINumToValue.clear();
OverlapFragments.clear();
SeenFragments.clear();
+ SeenDbgPHIs.clear();
return Changed;
}
@@ -3387,6 +3388,21 @@ Optional<ValueIDNum> InstrRefBasedLDV::resolveDbgPHIs(MachineFunction &MF,
ValueIDNum **MLiveIns,
MachineInstr &Here,
uint64_t InstrNum) {
+ // This function will be called twice per DBG_INSTR_REF, and might end up
+ // computing lots of SSA information: memoize it.
+ auto SeenDbgPHIIt = SeenDbgPHIs.find(&Here);
+ if (SeenDbgPHIIt != SeenDbgPHIs.end())
+ return SeenDbgPHIIt->second;
+
+ Optional<ValueIDNum> Result =
+ resolveDbgPHIsImpl(MF, MLiveOuts, MLiveIns, Here, InstrNum);
+ SeenDbgPHIs.insert({&Here, Result});
+ return Result;
+}
+
+Optional<ValueIDNum> InstrRefBasedLDV::resolveDbgPHIsImpl(
+ MachineFunction &MF, ValueIDNum **MLiveOuts, ValueIDNum **MLiveIns,
+ MachineInstr &Here, uint64_t InstrNum) {
// Pick out records of DBG_PHI instructions that have been observed. If there
// are none, then we cannot compute a value number.
auto RangePair = std::equal_range(DebugPHINumToValue.begin(),
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
index fe1d29260e4da..1e1bb758d3d44 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
@@ -864,6 +864,12 @@ class InstrRefBasedLDV : public LDVImpl {
OverlapMap OverlapFragments;
VarToFragments SeenFragments;
+ /// Mapping of DBG_INSTR_REF instructions to their values, for those
+ /// DBG_INSTR_REFs that call resolveDbgPHIs. These variable references solve
+ /// a mini SSA problem caused by DBG_PHIs being cloned, this collection caches
+ /// the result.
+ DenseMap<MachineInstr *, Optional<ValueIDNum>> SeenDbgPHIs;
+
/// True if we need to examine call instructions for stack clobbers. We
/// normally assume that they don't clobber SP, but stack probes on Windows
/// do.
@@ -944,6 +950,12 @@ class InstrRefBasedLDV : public LDVImpl {
ValueIDNum **MLiveIns, MachineInstr &Here,
uint64_t InstrNum);
+ Optional<ValueIDNum> resolveDbgPHIsImpl(MachineFunction &MF,
+ ValueIDNum **MLiveOuts,
+ ValueIDNum **MLiveIns,
+ MachineInstr &Here,
+ uint64_t InstrNum);
+
/// Step through the function, recording register definitions and movements
/// in an MLocTracker. Convert the observations into a per-block transfer
/// function in \p MLocTransfer, suitable for using with the machine value
More information about the llvm-commits
mailing list