Skip to content

Commit 4943aef

Browse files
committed
Move LDVImpl to LiveDebugVariables
1 parent 1ce5e29 commit 4943aef

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

llvm/include/llvm/CodeGen/LiveDebugVariables.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@
2323
#include "llvm/CodeGen/MachineFunctionPass.h"
2424
#include "llvm/IR/PassManager.h"
2525
#include "llvm/Support/Compiler.h"
26+
#include "llvm/Support/raw_ostream.h"
2627
#include <memory>
2728

2829
namespace llvm {
2930

3031
template <typename T> class ArrayRef;
3132
class LiveIntervals;
3233
class VirtRegMap;
33-
class LDVImpl;
3434

3535
class LiveDebugVariables {
36-
private:
37-
std::unique_ptr<LDVImpl> PImpl;
3836

3937
public:
40-
LiveDebugVariables() = default;
38+
class LDVImpl;
39+
LiveDebugVariables();
40+
~LiveDebugVariables();
41+
LiveDebugVariables(LiveDebugVariables &&);
4142

4243
void analyze(MachineFunction &MF, LiveIntervals *LIS);
4344
/// splitRegister - Move any user variables in OldReg to the live ranges in
@@ -62,6 +63,9 @@ class LiveDebugVariables {
6263

6364
bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA,
6465
MachineFunctionAnalysisManager::Invalidator &Inv);
66+
67+
private:
68+
std::unique_ptr<LDVImpl> PImpl;
6569
};
6670

6771
class LiveDebugVariablesWrapperLegacy : public MachineFunctionPass {
@@ -98,7 +102,11 @@ class LiveDebugVariablesAnalysis
98102

99103
class LiveDebugVariablesPrinterPass
100104
: public PassInfoMixin<LiveDebugVariablesPrinterPass> {
105+
raw_ostream &OS;
106+
101107
public:
108+
LiveDebugVariablesPrinterPass(raw_ostream &OS) : OS(OS) {}
109+
102110
PreservedAnalyses run(MachineFunction &MF,
103111
MachineFunctionAnalysisManager &MFAM);
104112
};

llvm/include/llvm/IR/PassManagerImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/IR/PassInstrumentation.h"
2020
#include "llvm/IR/PassManager.h"
2121
#include "llvm/Support/CommandLine.h"
22+
#include "llvm/Support/Debug.h"
2223
#include "llvm/Support/PrettyStackTrace.h"
2324

2425
extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
@@ -79,7 +80,7 @@ PreservedAnalyses PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...>::run(
7980
continue;
8081

8182
PreservedAnalyses PassPA = Pass->run(IR, AM, ExtraArgs...);
82-
83+
llvm::dbgs() << "Running " << Pass->name() << "\n";
8384
// Update the analysis manager as each pass runs and potentially
8485
// invalidates analyses.
8586
AM.invalidate(IR, PassPA);

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/LiveDebugVariables.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ namespace {
286286
/// user values are related if they are held by the same virtual register. The
287287
/// equivalence class is the transitive closure of that relation.
288288
class UserValue {
289+
using LDVImpl = LiveDebugVariables::LDVImpl;
290+
289291
const DILocalVariable *Variable; ///< The debug info variable we are part of.
290292
/// The part of the variable we describe.
291293
const std::optional<DIExpression::FragmentInfo> Fragment;
@@ -534,7 +536,12 @@ class UserLabel {
534536
namespace llvm {
535537

536538
/// Implementation of the LiveDebugVariables pass.
537-
class LDVImpl {
539+
540+
LiveDebugVariables::LiveDebugVariables() = default;
541+
LiveDebugVariables::~LiveDebugVariables() = default;
542+
LiveDebugVariables::LiveDebugVariables(LiveDebugVariables &&) = default;
543+
544+
class LiveDebugVariables::LDVImpl {
538545
LocMap::Allocator allocator;
539546
MachineFunction *MF = nullptr;
540547
LiveIntervals *LIS;
@@ -756,7 +763,7 @@ void UserLabel::print(raw_ostream &OS, const TargetRegisterInfo *TRI) {
756763
OS << '\n';
757764
}
758765

759-
void LDVImpl::print(raw_ostream &OS) {
766+
void LiveDebugVariables::LDVImpl::print(raw_ostream &OS) {
760767
OS << "********** DEBUG VARIABLES **********\n";
761768
for (auto &userValue : userValues)
762769
userValue->print(OS, TRI);
@@ -765,16 +772,15 @@ void LDVImpl::print(raw_ostream &OS) {
765772
userLabel->print(OS, TRI);
766773
}
767774

768-
void UserValue::mapVirtRegs(LDVImpl *LDV) {
775+
void UserValue::mapVirtRegs(LiveDebugVariables::LDVImpl *LDV) {
769776
for (const MachineOperand &MO : locations)
770777
if (MO.isReg() && MO.getReg().isVirtual())
771778
LDV->mapVirtReg(MO.getReg(), this);
772779
}
773780

774-
UserValue *
775-
LDVImpl::getUserValue(const DILocalVariable *Var,
776-
std::optional<DIExpression::FragmentInfo> Fragment,
777-
const DebugLoc &DL) {
781+
UserValue *LiveDebugVariables::LDVImpl::getUserValue(
782+
const DILocalVariable *Var,
783+
std::optional<DIExpression::FragmentInfo> Fragment, const DebugLoc &DL) {
778784
// FIXME: Handle partially overlapping fragments. See
779785
// https://reviews.llvm.org/D70121#1849741.
780786
DebugVariable ID(Var, Fragment, DL->getInlinedAt());
@@ -787,19 +793,20 @@ LDVImpl::getUserValue(const DILocalVariable *Var,
787793
return UV;
788794
}
789795

790-
void LDVImpl::mapVirtReg(Register VirtReg, UserValue *EC) {
796+
void LiveDebugVariables::LDVImpl::mapVirtReg(Register VirtReg, UserValue *EC) {
791797
assert(VirtReg.isVirtual() && "Only map VirtRegs");
792798
UserValue *&Leader = virtRegToEqClass[VirtReg];
793799
Leader = UserValue::merge(Leader, EC);
794800
}
795801

796-
UserValue *LDVImpl::lookupVirtReg(Register VirtReg) {
802+
UserValue *LiveDebugVariables::LDVImpl::lookupVirtReg(Register VirtReg) {
797803
if (UserValue *UV = virtRegToEqClass.lookup(VirtReg))
798804
return UV->getLeader();
799805
return nullptr;
800806
}
801807

802-
bool LDVImpl::handleDebugValue(MachineInstr &MI, SlotIndex Idx) {
808+
bool LiveDebugVariables::LDVImpl::handleDebugValue(MachineInstr &MI,
809+
SlotIndex Idx) {
803810
// DBG_VALUE loc, offset, variable, expr
804811
// DBG_VALUE_LIST variable, expr, locs...
805812
if (!MI.isDebugValue()) {
@@ -875,8 +882,8 @@ bool LDVImpl::handleDebugValue(MachineInstr &MI, SlotIndex Idx) {
875882
return true;
876883
}
877884

878-
MachineBasicBlock::iterator LDVImpl::handleDebugInstr(MachineInstr &MI,
879-
SlotIndex Idx) {
885+
MachineBasicBlock::iterator
886+
LiveDebugVariables::LDVImpl::handleDebugInstr(MachineInstr &MI, SlotIndex Idx) {
880887
assert(MI.isDebugValueLike() || MI.isDebugPHI());
881888

882889
// In instruction referencing mode, there should be no DBG_VALUE instructions
@@ -896,7 +903,8 @@ MachineBasicBlock::iterator LDVImpl::handleDebugInstr(MachineInstr &MI,
896903
return NextInst;
897904
}
898905

899-
bool LDVImpl::handleDebugLabel(MachineInstr &MI, SlotIndex Idx) {
906+
bool LiveDebugVariables::LDVImpl::handleDebugLabel(MachineInstr &MI,
907+
SlotIndex Idx) {
900908
// DBG_LABEL label
901909
if (MI.getNumOperands() != 1 || !MI.getOperand(0).isMetadata()) {
902910
LLVM_DEBUG(dbgs() << "Can't handle " << MI);
@@ -919,7 +927,8 @@ bool LDVImpl::handleDebugLabel(MachineInstr &MI, SlotIndex Idx) {
919927
return true;
920928
}
921929

922-
bool LDVImpl::collectDebugValues(MachineFunction &mf, bool InstrRef) {
930+
bool LiveDebugVariables::LDVImpl::collectDebugValues(MachineFunction &mf,
931+
bool InstrRef) {
923932
bool Changed = false;
924933
for (MachineBasicBlock &MBB : mf) {
925934
for (MachineBasicBlock::iterator MBBI = MBB.begin(), MBBE = MBB.end();
@@ -1252,7 +1261,7 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI,
12521261
I.setStopUnchecked(PrevEnd);
12531262
}
12541263

1255-
void LDVImpl::computeIntervals() {
1264+
void LiveDebugVariables::LDVImpl::computeIntervals() {
12561265
LexicalScopes LS;
12571266
LS.initialize(*MF);
12581267

@@ -1262,7 +1271,8 @@ void LDVImpl::computeIntervals() {
12621271
}
12631272
}
12641273

1265-
bool LDVImpl::runOnMachineFunction(MachineFunction &mf, bool InstrRef) {
1274+
bool LiveDebugVariables::LDVImpl::runOnMachineFunction(MachineFunction &mf,
1275+
bool InstrRef) {
12661276
clear();
12671277
MF = &mf;
12681278
TRI = mf.getSubtarget().getRegisterInfo();
@@ -1323,7 +1333,7 @@ PreservedAnalyses
13231333
LiveDebugVariablesPrinterPass::run(MachineFunction &MF,
13241334
MachineFunctionAnalysisManager &MFAM) {
13251335
auto &LDV = MFAM.getResult<LiveDebugVariablesAnalysis>(MF);
1326-
LDV.print(dbgs());
1336+
LDV.print(OS);
13271337
return PreservedAnalyses::all();
13281338
}
13291339

@@ -1478,7 +1488,8 @@ UserValue::splitRegister(Register OldReg, ArrayRef<Register> NewRegs,
14781488
return DidChange;
14791489
}
14801490

1481-
void LDVImpl::splitPHIRegister(Register OldReg, ArrayRef<Register> NewRegs) {
1491+
void LiveDebugVariables::LDVImpl::splitPHIRegister(Register OldReg,
1492+
ArrayRef<Register> NewRegs) {
14821493
auto RegIt = RegToPHIIdx.find(OldReg);
14831494
if (RegIt == RegToPHIIdx.end())
14841495
return;
@@ -1516,7 +1527,8 @@ void LDVImpl::splitPHIRegister(Register OldReg, ArrayRef<Register> NewRegs) {
15161527
RegToPHIIdx[RegAndInstr.first].push_back(RegAndInstr.second);
15171528
}
15181529

1519-
void LDVImpl::splitRegister(Register OldReg, ArrayRef<Register> NewRegs) {
1530+
void LiveDebugVariables::LDVImpl::splitRegister(Register OldReg,
1531+
ArrayRef<Register> NewRegs) {
15201532
// Consider whether this split range affects any PHI locations.
15211533
splitPHIRegister(OldReg, NewRegs);
15221534

@@ -1840,7 +1852,7 @@ void UserLabel::emitDebugLabel(LiveIntervals &LIS, const TargetInstrInfo &TII,
18401852
LLVM_DEBUG(dbgs() << '\n');
18411853
}
18421854

1843-
void LDVImpl::emitDebugValues(VirtRegMap *VRM) {
1855+
void LiveDebugVariables::LDVImpl::emitDebugValues(VirtRegMap *VRM) {
18441856
LLVM_DEBUG(dbgs() << "********** EMITTING LIVE DEBUG VARIABLES **********\n");
18451857
if (!MF)
18461858
return;

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
#include "llvm/CodeGen/InterleavedAccess.h"
9999
#include "llvm/CodeGen/InterleavedLoadCombine.h"
100100
#include "llvm/CodeGen/JMCInstrumenter.h"
101+
#include "llvm/CodeGen/LiveDebugVariables.h"
101102
#include "llvm/CodeGen/LiveIntervals.h"
102103
#include "llvm/CodeGen/LiveRegMatrix.h"
103104
#include "llvm/CodeGen/LiveVariables.h"

0 commit comments

Comments
 (0)