Index: llvm/lib/CodeGen/VirtRegMap.cpp =================================================================== --- llvm/lib/CodeGen/VirtRegMap.cpp +++ llvm/lib/CodeGen/VirtRegMap.cpp @@ -181,6 +181,7 @@ SlotIndexes *Indexes; LiveIntervals *LIS; VirtRegMap *VRM; + LiveDebugVariables *DebugVars; DenseSet RewriteRegs; bool ClearVirtRegs; @@ -238,6 +239,10 @@ AU.addRequired(); AU.addPreserved(); AU.addRequired(); + + if (!ClearVirtRegs) + AU.addPreserved(); + MachineFunctionPass::getAnalysisUsage(AU); } @@ -249,6 +254,7 @@ Indexes = &getAnalysis(); LIS = &getAnalysis(); VRM = &getAnalysis(); + DebugVars = getAnalysisIfAvailable(); LLVM_DEBUG(dbgs() << "********** REWRITE VIRTUAL REGISTERS **********\n" << "********** Function: " << MF->getName() << '\n'); LLVM_DEBUG(VRM->dump()); @@ -262,10 +268,10 @@ // Rewrite virtual registers. rewrite(); - // Write out new DBG_VALUE instructions. - getAnalysis().emitDebugValues(VRM); + if (DebugVars && ClearVirtRegs) { + // Write out new DBG_VALUE instructions. + DebugVars->emitDebugValues(VRM); - if (ClearVirtRegs) { // All machine operands and other references to virtual registers have been // replaced. Remove the virtual registers and release all the transient data. VRM->clearAllVirt();