Skip to content

Commit

Permalink
Revert "Reapply D124184, [DebugInfo][InstrRef] Add a size operand to …
Browse files Browse the repository at this point in the history
…DBG_PHI"

This reverts commit 5db9250.

Further to the early revert, the sanitizers have found something wrong with
this.
  • Loading branch information
jmorse committed Apr 25, 2022
1 parent 8fbf9ac commit 987cd7c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 482 deletions.
53 changes: 32 additions & 21 deletions llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
Expand Up @@ -722,20 +722,6 @@ MLocTracker::MLocTracker(MachineFunction &MF, const TargetInstrInfo &TII,
StackSlotIdxes.insert({{Size, Offs}, Idx});
}

// There may also be strange register class sizes (think x86 fp80s).
for (const TargetRegisterClass *RC : TRI.regclasses()) {
unsigned Size = TRI.getRegSizeInBits(*RC);

// We might see special reserved values as sizes, and classes for other
// stuff the machine tries to model. If it's more than 512 bits, then it
// is very unlikely to be a register than can be spilt.
if (Size > 512)
continue;

unsigned Idx = StackSlotIdxes.size();
StackSlotIdxes.insert({{Size, 0}, Idx});
}

for (auto &Idx : StackSlotIdxes)
StackIdxesToPos[Idx.second] = Idx.first;

Expand Down Expand Up @@ -1307,16 +1293,41 @@ bool InstrRefBasedLDV::transferDebugPHI(MachineInstr &MI) {
if (!SpillNo)
return EmitBadPHI();

// Any stack location DBG_PHI should have an associate bit-size.
assert(MI.getNumOperands() == 3 && "Stack DBG_PHI with no size?");
unsigned slotBitSize = MI.getOperand(2).getImm();
// Problem: what value should we extract from the stack? LLVM does not
// record what size the last store to the slot was, and it would become
// sketchy after stack slot colouring anyway. Take a look at what values
// are stored on the stack, and pick the largest one that wasn't def'd
// by a spill (i.e., the value most likely to have been def'd in a register
// and then spilt.
std::array<unsigned, 4> CandidateSizes = {64, 32, 16, 8};
Optional<ValueIDNum> Result = None;
Optional<LocIdx> SpillLoc = None;
for (unsigned CS : CandidateSizes) {
unsigned SpillID = MTracker->getLocID(*SpillNo, {CS, 0});
SpillLoc = MTracker->getSpillMLoc(SpillID);
ValueIDNum Val = MTracker->readMLoc(*SpillLoc);
// If this value was defined in it's own position, then it was probably
// an aliasing index of a small value that was spilt.
if (Val.getLoc() != SpillLoc->asU64()) {
Result = Val;
break;
}
}

unsigned SpillID = MTracker->getLocID(*SpillNo, {slotBitSize, 0});
LocIdx SpillLoc = MTracker->getSpillMLoc(SpillID);
ValueIDNum Result = MTracker->readMLoc(SpillLoc);
// If we didn't find anything, we're probably looking at a PHI, or a memory
// store folded into an instruction. FIXME: Take a guess that's it's 64
// bits. This isn't ideal, but tracking the size that the spill is
// "supposed" to be is more complex, and benefits a small number of
// locations.
if (!Result) {
unsigned SpillID = MTracker->getLocID(*SpillNo, {64, 0});
SpillLoc = MTracker->getSpillMLoc(SpillID);
Result = MTracker->readMLoc(*SpillLoc);
}

// Record this DBG_PHI for later analysis.
auto DbgPHI = DebugPHIRecord({InstrNum, MI.getParent(), Result, SpillLoc});
auto DbgPHI =
DebugPHIRecord({InstrNum, MI.getParent(), *Result, *SpillLoc});
DebugPHINumToValue.push_back(DbgPHI);
} else {
// Else: if the operand is neither a legal register or a stack slot, then
Expand Down
21 changes: 2 additions & 19 deletions llvm/lib/CodeGen/LiveDebugVariables.cpp
Expand Up @@ -1850,33 +1850,16 @@ void LDVImpl::emitDebugValues(VirtRegMap *VRM) {
const TargetRegisterClass *TRC = MRI.getRegClass(Reg);
unsigned SpillSize, SpillOffset;

unsigned regSizeInBits = TRI->getRegSizeInBits(*TRC);
if (SubReg)
regSizeInBits = TRI->getSubRegIdxSize(SubReg);

// Test whether this location is legal with the given subreg. If the
// subregister has a nonzero offset, drop this location, it's too complex
// to describe. (TODO: future work).
// Test whether this location is legal with the given subreg.
bool Success =
TII->getStackSlotRange(TRC, SubReg, SpillSize, SpillOffset, *MF);

if (Success && SpillOffset == 0) {
if (Success) {
auto Builder = BuildMI(*OrigMBB, OrigMBB->begin(), DebugLoc(),
TII->get(TargetOpcode::DBG_PHI));
Builder.addFrameIndex(VRM->getStackSlot(Reg));
Builder.addImm(InstNum);
// Record how large the original value is. The stack slot might be
// merged and altered during optimisation, but we will want to know how
// large the value is, at this DBG_PHI.
Builder.addImm(regSizeInBits);
}

LLVM_DEBUG(
if (SpillOffset != 0) {
dbgs() << "DBG_PHI for Vreg " << Reg << " subreg " << SubReg <<
" has nonzero offset\n";
}
);
}
// If there was no mapping for a value ID, it's optimized out. Create no
// DBG_PHI, and any variables using this value will become optimized out.
Expand Down
128 changes: 0 additions & 128 deletions llvm/test/DebugInfo/MIR/InstrRef/dbg-phis-in-ldv2.mir

This file was deleted.

156 changes: 0 additions & 156 deletions llvm/test/DebugInfo/MIR/InstrRef/phi-on-stack-coalesced.mir

This file was deleted.

0 comments on commit 987cd7c

Please sign in to comment.