diff options
author | David Stenberg <david.stenberg@ericsson.com> | 2019-02-12 10:51:27 +0000 |
---|---|---|
committer | David Stenberg <david.stenberg@ericsson.com> | 2019-02-12 10:51:27 +0000 |
commit | bbd2f972930e4ae99d5fff68122b5b7cec6aace7 (patch) | |
tree | a537eb94da141fc7c9ed5206724fd6a3d54c278f /llvm/lib | |
parent | 905438a4b556ec0844fb82fd21aba81c25d18d60 (diff) | |
download | bcm5719-llvm-bbd2f972930e4ae99d5fff68122b5b7cec6aace7.tar.gz bcm5719-llvm-bbd2f972930e4ae99d5fff68122b5b7cec6aace7.zip |
[DebugInfo] Keep parameter DBG_VALUEs before prologue code
Summary:
This is a preparatory change for removing the code from
DebugHandlerBase::beginFunction() which changes the starting label for
the first non-overlapping DBG_VALUEs of parameters to the beginning of
the function. It does that to be able to show parameters when entering a
function. However, that code does not consider what defines the values,
which can result in the ranges for the debug values starting before
their defining instructions. That code is removed in a follow-up patch.
When prologue code is inserted, it leads to DBG_VALUEs that start
directly in the entry block being moved down after the prologue
instructions. This patch fixes that by stashing away DBG_VALUEs for
parameters before emitting the prologue, and then reinserts them at the
start of the block. This assumes that there is no target that somehow
clobbers parameter registers in the frame setup; there is no such case
in the lit tests at least.
See PR40188 for more information.
Reviewers: aprantl, dblaikie, rnk, jmorse
Reviewed By: aprantl
Subscribers: bjope, llvm-commits
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D57510
llvm-svn: 353823
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/PrologEpilogInserter.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index 5c7f3d49de6..f2b1802fff2 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -168,6 +168,46 @@ void PEI::getAnalysisUsage(AnalysisUsage &AU) const { /// StackObjSet - A set of stack object indexes using StackObjSet = SmallSetVector<int, 8>; +using SavedDbgValuesMap = + SmallDenseMap<MachineBasicBlock *, SmallVector<MachineInstr *, 4>, 4>; + +/// Stash DBG_VALUEs that describe parameters and which are placed at the start +/// of the block. Later on, after the prologue code has been emitted, the +/// stashed DBG_VALUEs will be reinserted at the start of the block. +static void stashEntryDbgValues(MachineBasicBlock &MBB, + SavedDbgValuesMap &EntryDbgValues) { + SmallVector<const MachineInstr *, 4> FrameIndexValues; + + for (auto &MI : MBB) { + if (!MI.isDebugInstr()) + break; + if (!MI.isDebugValue() || !MI.getDebugVariable()->isParameter()) + continue; + if (MI.getOperand(0).isFI()) { + // We can only emit valid locations for frame indices after the frame + // setup, so do not stash away them. + FrameIndexValues.push_back(&MI); + continue; + } + const DILocalVariable *Var = MI.getDebugVariable(); + const DIExpression *Expr = MI.getDebugExpression(); + auto Overlaps = [Var, Expr](const MachineInstr *DV) { + return Var == DV->getDebugVariable() && + Expr->fragmentsOverlap(DV->getDebugExpression()); + }; + // See if the debug value overlaps with any preceding debug value that will + // not be stashed. If that is the case, then we can't stash this value, as + // we would then reorder the values at reinsertion. + if (llvm::none_of(FrameIndexValues, Overlaps)) + EntryDbgValues[&MBB].push_back(&MI); + } + + // Remove stashed debug values from the block. + if (EntryDbgValues.count(&MBB)) + for (auto *MI : EntryDbgValues[&MBB]) + MI->removeFromParent(); +} + /// runOnMachineFunction - Insert prolog/epilog code and replace abstract /// frame indexes with appropriate references. bool PEI::runOnMachineFunction(MachineFunction &MF) { @@ -191,6 +231,11 @@ bool PEI::runOnMachineFunction(MachineFunction &MF) { // place all spills in the entry block, all restores in return blocks. calculateSaveRestoreBlocks(MF); + // Stash away DBG_VALUEs that should not be moved by insertion of prolog code. + SavedDbgValuesMap EntryDbgValues; + for (MachineBasicBlock *SaveBlock : SaveBlocks) + stashEntryDbgValues(*SaveBlock, EntryDbgValues); + // Handle CSR spilling and restoring, for targets that need it. if (MF.getTarget().usesPhysRegsForPEI()) spillCalleeSavedRegs(MF); @@ -210,6 +255,10 @@ bool PEI::runOnMachineFunction(MachineFunction &MF) { if (!F.hasFnAttribute(Attribute::Naked)) insertPrologEpilogCode(MF); + // Reinsert stashed debug values at the start of the entry blocks. + for (auto &I : EntryDbgValues) + I.first->insert(I.first->begin(), I.second.begin(), I.second.end()); + // Replace all MO_FrameIndex operands with physical register references // and actual offsets. // |