Index: lib/CodeGen/LiveDebugValues.cpp =================================================================== --- lib/CodeGen/LiveDebugValues.cpp +++ lib/CodeGen/LiveDebugValues.cpp @@ -37,6 +37,10 @@ #define DEBUG_TYPE "live-debug-values" +static cl::opt +EnableLDV("live-debug-values", cl::init(true), + cl::desc("Enable the live debug values pass"), cl::Hidden); + STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted"); namespace { @@ -360,9 +364,16 @@ transfer(MI, OpenRanges, OutLocs); DEBUG(printVarLocInMBB(OutLocs, "OutLocs after initialization", dbgs())); - // Construct a worklist of MBBs. - for (auto &MBB : MF) + // Convergence takes really long time on certain programs with huge number of + // basic blocks. Stop converging after few iterations for every mbb. + const unsigned MAX_ITERS_TO_CONVERGE = 10; + DenseMap StopConvergence; + + // Construct a worklist of MBBs. Also initialze StopConvergence for every mbb. + for (auto &MBB : MF) { BBWorklist.push_back(&MBB); + StopConvergence.insert(std::make_pair(&MBB, 1)); + } // Perform join() and transfer() using the worklist until the ranges converge // Ranges have converged when the worklist is empty. @@ -379,7 +390,7 @@ DEBUG(printVarLocInMBB(OutLocs, "OutLocs after propagating", dbgs())); DEBUG(printVarLocInMBB(InLocs, "InLocs after propagating", dbgs())); - if (OLChanged) { + if (OLChanged && (++StopConvergence[MBB] < MAX_ITERS_TO_CONVERGE)) { OLChanged = false; for (auto s : MBB->successors()) if (std::find(BBWorklist.begin(), BBWorklist.end(), s) == @@ -394,6 +405,9 @@ } bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) { + if (!EnableLDV) + return false; + TRI = MF.getSubtarget().getRegisterInfo(); TII = MF.getSubtarget().getInstrInfo();