Skip to content

Commit 5590a43

Browse files
committed
[DEBUGINFO] Handle restore instructions in LiveDebugValues
The LiveDebugValues pass recognizes spills but not restores, which can cause large gaps in location information for some variables, depending on control flow. This patch make LiveDebugValues recognize restores and generate appropriate DBG_VALUE instructions. Reviewers: aprantl, NicolaPrica Differential Revision: https://reviews.llvm.org/D57271 llvm-svn: 352642
1 parent 92a470e commit 5590a43

File tree

5 files changed

+417
-94
lines changed

5 files changed

+417
-94
lines changed

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,19 @@ class MachineInstr
13991399
/// Return true if all the defs of this instruction are dead.
14001400
bool allDefsAreDead() const;
14011401

1402+
/// Return a valid size if the instruction is a spill instruction.
1403+
Optional<unsigned> getSpillSize(const TargetInstrInfo *TII) const;
1404+
1405+
/// Return a valid size if the instruction is a folded spill instruction.
1406+
Optional<unsigned> getFoldedSpillSize(const TargetInstrInfo *TII) const;
1407+
1408+
/// Return a valid size if the instruction is a restore instruction.
1409+
Optional<unsigned> getRestoreSize(const TargetInstrInfo *TII) const;
1410+
1411+
/// Return a valid size if the instruction is a folded restore instruction.
1412+
Optional<unsigned>
1413+
getFoldedRestoreSize(const TargetInstrInfo *TII) const;
1414+
14021415
/// Copy implicit register operands from specified
14031416
/// instruction to this instruction.
14041417
void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI);

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -754,46 +754,25 @@ static bool emitComments(const MachineInstr &MI, raw_ostream &CommentOS,
754754
const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
755755

756756
// Check for spills and reloads
757-
int FI;
758-
759-
const MachineFrameInfo &MFI = MF->getFrameInfo();
760757
bool Commented = false;
761758

762-
auto getSize =
763-
[&MFI](const SmallVectorImpl<const MachineMemOperand *> &Accesses) {
764-
unsigned Size = 0;
765-
for (auto A : Accesses)
766-
if (MFI.isSpillSlotObjectIndex(
767-
cast<FixedStackPseudoSourceValue>(A->getPseudoValue())
768-
->getFrameIndex()))
769-
Size += A->getSize();
770-
return Size;
771-
};
772-
773759
// We assume a single instruction only has a spill or reload, not
774760
// both.
775-
const MachineMemOperand *MMO;
776-
SmallVector<const MachineMemOperand *, 2> Accesses;
777-
if (TII->isLoadFromStackSlotPostFE(MI, FI)) {
778-
if (MFI.isSpillSlotObjectIndex(FI)) {
779-
MMO = *MI.memoperands_begin();
780-
CommentOS << MMO->getSize() << "-byte Reload";
781-
Commented = true;
782-
}
783-
} else if (TII->hasLoadFromStackSlot(MI, Accesses)) {
784-
if (auto Size = getSize(Accesses)) {
785-
CommentOS << Size << "-byte Folded Reload";
786-
Commented = true;
787-
}
788-
} else if (TII->isStoreToStackSlotPostFE(MI, FI)) {
789-
if (MFI.isSpillSlotObjectIndex(FI)) {
790-
MMO = *MI.memoperands_begin();
791-
CommentOS << MMO->getSize() << "-byte Spill";
761+
Optional<unsigned> Size;
762+
if ((Size = MI.getRestoreSize(TII))) {
763+
CommentOS << *Size << "-byte Reload";
764+
Commented = true;
765+
} else if ((Size = MI.getFoldedRestoreSize(TII))) {
766+
if (*Size) {
767+
CommentOS << *Size << "-byte Folded Reload";
792768
Commented = true;
793769
}
794-
} else if (TII->hasStoreToStackSlot(MI, Accesses)) {
795-
if (auto Size = getSize(Accesses)) {
796-
CommentOS << Size << "-byte Folded Spill";
770+
} else if ((Size = MI.getSpillSize(TII))) {
771+
CommentOS << *Size << "-byte Spill";
772+
Commented = true;
773+
} else if ((Size = MI.getFoldedSpillSize(TII))) {
774+
if (*Size) {
775+
CommentOS << *Size << "-byte Folded Spill";
797776
Commented = true;
798777
}
799778
}

0 commit comments

Comments
 (0)