@@ -74,24 +74,25 @@ EnableLDV("live-debug-variables", cl::init(true),
7474STATISTIC (NumInsertedDebugValues, " Number of DBG_VALUEs inserted" );
7575STATISTIC (NumInsertedDebugLabels, " Number of DBG_LABELs inserted" );
7676
77- char LiveDebugVariables ::ID = 0 ;
77+ char LiveDebugVariablesWrapperPass ::ID = 0 ;
7878
79- INITIALIZE_PASS_BEGIN (LiveDebugVariables , DEBUG_TYPE,
80- " Debug Variable Analysis" , false , false )
79+ INITIALIZE_PASS_BEGIN (LiveDebugVariablesWrapperPass , DEBUG_TYPE,
80+ " Debug Variable Analysis" , false , false )
8181INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
8282INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
83- INITIALIZE_PASS_END(LiveDebugVariables , DEBUG_TYPE,
84- " Debug Variable Analysis" , false , false )
83+ INITIALIZE_PASS_END(LiveDebugVariablesWrapperPass , DEBUG_TYPE,
84+ " Debug Variable Analysis" , false , false )
8585
86- void LiveDebugVariables ::getAnalysisUsage(AnalysisUsage &AU) const {
86+ void LiveDebugVariablesWrapperPass ::getAnalysisUsage(AnalysisUsage &AU) const {
8787 AU.addRequired <MachineDominatorTreeWrapperPass>();
8888 AU.addRequiredTransitive <LiveIntervalsWrapperPass>();
8989 AU.setPreservesAll ();
9090 MachineFunctionPass::getAnalysisUsage (AU);
9191}
9292
93- LiveDebugVariables::LiveDebugVariables () : MachineFunctionPass(ID) {
94- initializeLiveDebugVariablesPass (*PassRegistry::getPassRegistry ());
93+ LiveDebugVariablesWrapperPass::LiveDebugVariablesWrapperPass ()
94+ : MachineFunctionPass(ID) {
95+ initializeLiveDebugVariablesWrapperPassPass (*PassRegistry::getPassRegistry ());
9596}
9697
9798enum : unsigned { UndefLocNo = ~0U };
@@ -530,7 +531,6 @@ class UserLabel {
530531
531532// / Implementation of the LiveDebugVariables pass.
532533class LDVImpl {
533- LiveDebugVariables &pass;
534534 LocMap::Allocator allocator;
535535 MachineFunction *MF = nullptr ;
536536 LiveIntervals *LIS;
@@ -634,7 +634,7 @@ class LDVImpl {
634634 void computeIntervals ();
635635
636636public:
637- LDVImpl (LiveDebugVariables *ps ) : pass(*ps ) {}
637+ LDVImpl (LiveIntervals *LIS ) : LIS(LIS ) {}
638638
639639 bool runOnMachineFunction (MachineFunction &mf, bool InstrRef);
640640
@@ -1263,7 +1263,6 @@ void LDVImpl::computeIntervals() {
12631263bool LDVImpl::runOnMachineFunction (MachineFunction &mf, bool InstrRef) {
12641264 clear ();
12651265 MF = &mf;
1266- LIS = &pass.getAnalysis <LiveIntervalsWrapperPass>().getLIS ();
12671266 TRI = mf.getSubtarget ().getRegisterInfo ();
12681267 LLVM_DEBUG (dbgs () << " ********** COMPUTING LIVE DEBUG VARIABLES: "
12691268 << mf.getName () << " **********\n " );
@@ -1298,31 +1297,50 @@ static void removeDebugInstrs(MachineFunction &mf) {
12981297 }
12991298}
13001299
1301- bool LiveDebugVariables::runOnMachineFunction (MachineFunction &mf) {
1302- if (!EnableLDV)
1303- return false ;
1304- if (!mf.getFunction ().getSubprogram ()) {
1305- removeDebugInstrs (mf);
1306- return false ;
1307- }
1300+ bool LiveDebugVariablesWrapperPass::runOnMachineFunction (MachineFunction &mf) {
1301+ auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS ();
13081302
1309- // Have we been asked to track variable locations using instruction
1310- // referencing?
1311- bool InstrRef = mf.useDebugInstrRef ();
1303+ Impl = std::make_unique<LiveDebugVariables>();
1304+ Impl->analyze (mf, LIS);
1305+ return false ;
1306+ }
1307+
1308+ AnalysisKey LiveDebugVariablesAnalysis::Key;
1309+
1310+ LiveDebugVariables
1311+ LiveDebugVariablesAnalysis::run (MachineFunction &MF,
1312+ MachineFunctionAnalysisManager &MFAM) {
1313+ auto *LIS = &MFAM.getResult <LiveIntervalsAnalysis>(MF);
1314+ LiveDebugVariables LDV;
1315+ LDV.analyze (MF, LIS);
1316+ return LDV;
1317+ }
13121318
1313- if (!pImpl)
1314- pImpl = new LDVImpl ( this );
1315- return static_cast <LDVImpl *>(pImpl)-> runOnMachineFunction (mf, InstrRef );
1319+ LiveDebugVariables::~LiveDebugVariables () {
1320+ if (PImpl)
1321+ delete static_cast <LDVImpl *>(PImpl );
13161322}
13171323
13181324void LiveDebugVariables::releaseMemory () {
1319- if (pImpl )
1320- static_cast <LDVImpl*>(pImpl )->clear ();
1325+ if (PImpl )
1326+ static_cast <LDVImpl *>(PImpl )->clear ();
13211327}
13221328
1323- LiveDebugVariables::~LiveDebugVariables () {
1324- if (pImpl)
1325- delete static_cast <LDVImpl*>(pImpl);
1329+ void LiveDebugVariables::analyze (MachineFunction &MF, LiveIntervals *LIS) {
1330+ if (!EnableLDV)
1331+ return ;
1332+ if (!MF.getFunction ().getSubprogram ()) {
1333+ removeDebugInstrs (MF);
1334+ return ;
1335+ }
1336+
1337+ if (!PImpl)
1338+ PImpl = new LDVImpl (LIS); // reuse same object across analysis runs
1339+
1340+ // Have we been asked to track variable locations using instruction
1341+ // referencing?
1342+ bool InstrRef = MF.useDebugInstrRef ();
1343+ static_cast <LDVImpl *>(PImpl)->runOnMachineFunction (MF, InstrRef);
13261344}
13271345
13281346// ===----------------------------------------------------------------------===//
@@ -1504,8 +1522,8 @@ void LDVImpl::splitRegister(Register OldReg, ArrayRef<Register> NewRegs) {
15041522
15051523void LiveDebugVariables::
15061524splitRegister (Register OldReg, ArrayRef<Register> NewRegs, LiveIntervals &LIS) {
1507- if (pImpl )
1508- static_cast <LDVImpl*>(pImpl )->splitRegister (OldReg, NewRegs);
1525+ if (PImpl )
1526+ static_cast <LDVImpl *>(PImpl )->splitRegister (OldReg, NewRegs);
15091527}
15101528
15111529void UserValue::rewriteLocations (VirtRegMap &VRM, const MachineFunction &MF,
@@ -1956,13 +1974,13 @@ void LDVImpl::emitDebugValues(VirtRegMap *VRM) {
19561974}
19571975
19581976void LiveDebugVariables::emitDebugValues (VirtRegMap *VRM) {
1959- if (pImpl )
1960- static_cast <LDVImpl*>(pImpl )->emitDebugValues (VRM);
1977+ if (PImpl )
1978+ static_cast <LDVImpl *>(PImpl )->emitDebugValues (VRM);
19611979}
19621980
19631981#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
19641982LLVM_DUMP_METHOD void LiveDebugVariables::dump () const {
1965- if (pImpl )
1966- static_cast <LDVImpl*>(pImpl )->print (dbgs ());
1983+ if (PImpl )
1984+ static_cast <LDVImpl *>(PImpl )->print (dbgs ());
19671985}
19681986#endif
0 commit comments