Index: llvm/lib/CodeGen/LiveDebugValues.cpp =================================================================== --- llvm/lib/CodeGen/LiveDebugValues.cpp +++ llvm/lib/CodeGen/LiveDebugValues.cpp @@ -1285,15 +1285,6 @@ std::greater> Pending; - // Besides parameter's modification, check whether a DBG_VALUE is inlined - // in order to deduce whether the variable that it tracks comes from - // a different function. If that is the case we can't track its entry value. - auto IsUnmodifiedFuncParam = [&](const MachineInstr &MI) { - auto *DIVar = MI.getDebugVariable(); - return DIVar->isParameter() && DIVar->isNotModified() && - !MI.getDebugLoc()->getInlinedAt(); - }; - const TargetLowering *TLI = MF.getSubtarget().getTargetLowering(); unsigned SP = TLI->getStackPointerRegisterToSaveRestore(); Register FP = TRI->getFrameRegister(MF); @@ -1305,21 +1296,51 @@ // representing candidates for production of debug entry values. DebugParamMap DebugEntryVals; - MachineBasicBlock &First_MBB = *(MF.begin()); // Only in the case of entry MBB collect DBG_VALUEs representing // function parameters in order to generate debug entry values for them. + // // Currently, we generate debug entry values only for parameters that are // unmodified throughout the function and located in a register. - // TODO: Add support for parameters that are described as fragments. - // TODO: Add support for modified arguments that can be expressed - // by using its entry value. - // TODO: Add support for local variables that are expressed in terms of - // parameters entry values. + auto IsEntryValueCandidate = [&](const MachineInstr &MI) { + if (!MI.isDebugValue()) + return false; + + // TODO: Add support for local variables that are expressed in terms of + // parameters entry values. + // TODO: Add support for modified arguments that can be expressed + // by using its entry value. + auto *DIVar = MI.getDebugVariable(); + if (!DIVar->isParameter() || !DIVar->isNotModified()) + return false; + + // Do not consider parameters that belong to an inlined function. + if (MI.getDebugLoc()->getInlinedAt()) + return false; + + // Do not consider indirect debug values (TODO: explain why). + if (MI.isIndirectDebugValue()) + return false; + + // Only consider parameters that are described using registers. Parameters + // that are passed on the stack are not yet supported, so ignore debug + // values that are described by the frame or stack pointer. + if (!IsRegOtherThanSPAndFP(MI.getOperand(0))) + return false; + + // Do not consider parameters that we have already handled. + if (DebugEntryVals.count(MI.getDebugVariable())) + return false; + + // TODO: Add support for parameters that are described as fragments. + if (MI.getDebugExpression()->isFragment()) + return false; + + return true; + }; + + MachineBasicBlock &First_MBB = *(MF.begin()); for (auto &MI : First_MBB) - if (MI.isDebugValue() && IsUnmodifiedFuncParam(MI) && - !MI.isIndirectDebugValue() && IsRegOtherThanSPAndFP(MI.getOperand(0)) && - !DebugEntryVals.count(MI.getDebugVariable()) && - !MI.getDebugExpression()->isFragment()) + if (IsEntryValueCandidate(MI)) DebugEntryVals[MI.getDebugVariable()] = &MI; // Initialize per-block structures and scan for fragment overlaps.