Skip to content

Commit d9b4bdb

Browse files
authored
[CodeGen][NewPM] Port LiveDebugVariables to NPM (#115468)
The existing analysis was already a pimpl wrapper. I have extracted legacy pass logic to a LDVImpl wrapper named `LiveDebugVariables` which is the analysis::Result now. This controls whether to activate the LDV (depending on `-live-debug-variables` and DIsubprogram) itself. The legacy and new analysis only construct the LiveDebugVariables. VirtRegRewriter will test this.
1 parent 3b0cb89 commit d9b4bdb

14 files changed

+195
-85
lines changed

llvm/include/llvm/CodeGen/LiveDebugVariables.h

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,26 @@
2121
#define LLVM_CODEGEN_LIVEDEBUGVARIABLES_H
2222

2323
#include "llvm/CodeGen/MachineFunctionPass.h"
24+
#include "llvm/IR/PassManager.h"
2425
#include "llvm/Support/Compiler.h"
26+
#include "llvm/Support/raw_ostream.h"
27+
#include <memory>
2528

2629
namespace llvm {
2730

2831
template <typename T> class ArrayRef;
2932
class LiveIntervals;
3033
class VirtRegMap;
3134

32-
class LiveDebugVariables : public MachineFunctionPass {
33-
void *pImpl = nullptr;
35+
class LiveDebugVariables {
3436

3537
public:
36-
static char ID; // Pass identification, replacement for typeid
37-
38+
class LDVImpl;
3839
LiveDebugVariables();
39-
~LiveDebugVariables() override;
40+
~LiveDebugVariables();
41+
LiveDebugVariables(LiveDebugVariables &&);
4042

43+
void analyze(MachineFunction &MF, LiveIntervals *LIS);
4144
/// splitRegister - Move any user variables in OldReg to the live ranges in
4245
/// NewRegs where they are live. Mark the values as unavailable where no new
4346
/// register is live.
@@ -49,12 +52,39 @@ class LiveDebugVariables : public MachineFunctionPass {
4952
/// @param VRM Rename virtual registers according to map.
5053
void emitDebugValues(VirtRegMap *VRM);
5154

55+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
5256
/// dump - Print data structures to dbgs().
5357
void dump() const;
58+
#endif
59+
60+
void print(raw_ostream &OS) const;
61+
62+
void releaseMemory();
63+
64+
bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA,
65+
MachineFunctionAnalysisManager::Invalidator &Inv);
5466

5567
private:
68+
std::unique_ptr<LDVImpl> PImpl;
69+
};
70+
71+
class LiveDebugVariablesWrapperLegacy : public MachineFunctionPass {
72+
std::unique_ptr<LiveDebugVariables> Impl;
73+
74+
public:
75+
static char ID; // Pass identification, replacement for typeid
76+
77+
LiveDebugVariablesWrapperLegacy();
78+
5679
bool runOnMachineFunction(MachineFunction &) override;
57-
void releaseMemory() override;
80+
81+
LiveDebugVariables &getLDV() { return *Impl; }
82+
const LiveDebugVariables &getLDV() const { return *Impl; }
83+
84+
void releaseMemory() override {
85+
if (Impl)
86+
Impl->releaseMemory();
87+
}
5888
void getAnalysisUsage(AnalysisUsage &) const override;
5989

6090
MachineFunctionProperties getSetProperties() const override {
@@ -63,6 +93,32 @@ class LiveDebugVariables : public MachineFunctionPass {
6393
}
6494
};
6595

96+
class LiveDebugVariablesAnalysis
97+
: public AnalysisInfoMixin<LiveDebugVariablesAnalysis> {
98+
friend AnalysisInfoMixin<LiveDebugVariablesAnalysis>;
99+
static AnalysisKey Key;
100+
101+
public:
102+
using Result = LiveDebugVariables;
103+
104+
MachineFunctionProperties getSetProperties() const {
105+
return MachineFunctionProperties().set(
106+
MachineFunctionProperties::Property::TracksDebugUserValues);
107+
}
108+
109+
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
110+
};
111+
112+
class LiveDebugVariablesPrinterPass
113+
: public PassInfoMixin<LiveDebugVariablesPrinterPass> {
114+
raw_ostream &OS;
115+
116+
public:
117+
LiveDebugVariablesPrinterPass(raw_ostream &OS) : OS(OS) {}
118+
119+
PreservedAnalyses run(MachineFunction &MF,
120+
MachineFunctionAnalysisManager &MFAM);
121+
};
66122
} // end namespace llvm
67123

68124
#endif // LLVM_CODEGEN_LIVEDEBUGVARIABLES_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void initializeLegalizerPass(PassRegistry &);
154154
void initializeGISelCSEAnalysisWrapperPassPass(PassRegistry &);
155155
void initializeGISelKnownBitsAnalysisPass(PassRegistry &);
156156
void initializeLiveDebugValuesPass(PassRegistry &);
157-
void initializeLiveDebugVariablesPass(PassRegistry &);
157+
void initializeLiveDebugVariablesWrapperLegacyPass(PassRegistry &);
158158
void initializeLiveIntervalsWrapperPassPass(PassRegistry &);
159159
void initializeLiveRangeShrinkPass(PassRegistry &);
160160
void initializeLiveRegMatrixWrapperLegacyPass(PassRegistry &);

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ LOOP_PASS("loop-term-fold", LoopTermFoldPass())
9898
// computed. (We still either need to regenerate kill flags after regalloc, or
9999
// preferably fix the scavenger to not depend on them).
100100
MACHINE_FUNCTION_ANALYSIS("edge-bundles", EdgeBundlesAnalysis())
101+
MACHINE_FUNCTION_ANALYSIS("livedebugvars", LiveDebugVariablesAnalysis())
101102
MACHINE_FUNCTION_ANALYSIS("live-intervals", LiveIntervalsAnalysis())
102103
MACHINE_FUNCTION_ANALYSIS("live-reg-matrix", LiveRegMatrixAnalysis())
103104
MACHINE_FUNCTION_ANALYSIS("live-vars", LiveVariablesAnalysis())
@@ -146,6 +147,7 @@ MACHINE_FUNCTION_PASS("opt-phis", OptimizePHIsPass())
146147
MACHINE_FUNCTION_PASS("peephole-opt", PeepholeOptimizerPass())
147148
MACHINE_FUNCTION_PASS("phi-node-elimination", PHIEliminationPass())
148149
MACHINE_FUNCTION_PASS("print", PrintMIRPass())
150+
MACHINE_FUNCTION_PASS("print<livedebugvars>", LiveDebugVariablesPrinterPass(errs()))
149151
MACHINE_FUNCTION_PASS("print<live-intervals>", LiveIntervalsPrinterPass(errs()))
150152
MACHINE_FUNCTION_PASS("print<live-vars>", LiveVariablesPrinterPass(errs()))
151153
MACHINE_FUNCTION_PASS("print<machine-block-freq>",

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
5959
initializeInterleavedAccessPass(Registry);
6060
initializeJMCInstrumenterPass(Registry);
6161
initializeLiveDebugValuesPass(Registry);
62-
initializeLiveDebugVariablesPass(Registry);
62+
initializeLiveDebugVariablesWrapperLegacyPass(Registry);
6363
initializeLiveIntervalsWrapperPassPass(Registry);
6464
initializeLiveRangeShrinkPass(Registry);
6565
initializeLiveStacksPass(Registry);

0 commit comments

Comments
 (0)