Skip to content

Commit 429c6ec

Browse files
committed
Revert "[DebugInfo] Add DWARF emission for DBG_VALUE_LIST"
This reverts commit 0da27ba. This revision was causing an error on the sanitizer-x86_64-linux-autoconf build.
1 parent 6e92f46 commit 429c6ec

File tree

10 files changed

+206
-622
lines changed

10 files changed

+206
-622
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,9 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
918918
OS << V->getName();
919919
OS << " <- ";
920920

921+
// The second operand is only an offset if it's an immediate.
922+
bool MemLoc = MI->isIndirectDebugValue();
923+
auto Offset = StackOffset::getFixed(MemLoc ? MI->getOperand(1).getImm() : 0);
921924
const DIExpression *Expr = MI->getDebugExpression();
922925
if (Expr->getNumElements()) {
923926
OS << '[';
@@ -931,71 +934,56 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
931934
}
932935

933936
// Register or immediate value. Register 0 means undef.
934-
for (const MachineOperand &Op : MI->debug_operands()) {
935-
if (&Op != MI->debug_operands().begin())
936-
OS << ", ";
937-
switch (Op.getType()) {
938-
case MachineOperand::MO_FPImmediate: {
939-
APFloat APF = APFloat(Op.getFPImm()->getValueAPF());
940-
if (Op.getFPImm()->getType()->isFloatTy()) {
941-
OS << (double)APF.convertToFloat();
942-
} else if (Op.getFPImm()->getType()->isDoubleTy()) {
943-
OS << APF.convertToDouble();
944-
} else {
945-
// There is no good way to print long double. Convert a copy to
946-
// double. Ah well, it's only a comment.
947-
bool ignored;
948-
APF.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
949-
&ignored);
950-
OS << "(long double) " << APF.convertToDouble();
951-
}
952-
break;
953-
}
954-
case MachineOperand::MO_Immediate: {
955-
OS << Op.getImm();
956-
break;
937+
if (MI->getDebugOperand(0).isFPImm()) {
938+
APFloat APF = APFloat(MI->getDebugOperand(0).getFPImm()->getValueAPF());
939+
if (MI->getDebugOperand(0).getFPImm()->getType()->isFloatTy()) {
940+
OS << (double)APF.convertToFloat();
941+
} else if (MI->getDebugOperand(0).getFPImm()->getType()->isDoubleTy()) {
942+
OS << APF.convertToDouble();
943+
} else {
944+
// There is no good way to print long double. Convert a copy to
945+
// double. Ah well, it's only a comment.
946+
bool ignored;
947+
APF.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
948+
&ignored);
949+
OS << "(long double) " << APF.convertToDouble();
957950
}
958-
case MachineOperand::MO_CImmediate: {
959-
Op.getCImm()->getValue().print(OS, false /*isSigned*/);
960-
break;
951+
} else if (MI->getDebugOperand(0).isImm()) {
952+
OS << MI->getDebugOperand(0).getImm();
953+
} else if (MI->getDebugOperand(0).isCImm()) {
954+
MI->getDebugOperand(0).getCImm()->getValue().print(OS, false /*isSigned*/);
955+
} else if (MI->getDebugOperand(0).isTargetIndex()) {
956+
auto Op = MI->getDebugOperand(0);
957+
OS << "!target-index(" << Op.getIndex() << "," << Op.getOffset() << ")";
958+
// NOTE: Want this comment at start of line, don't emit with AddComment.
959+
AP.OutStreamer->emitRawComment(OS.str());
960+
return true;
961+
} else {
962+
Register Reg;
963+
if (MI->getDebugOperand(0).isReg()) {
964+
Reg = MI->getDebugOperand(0).getReg();
965+
} else {
966+
assert(MI->getDebugOperand(0).isFI() && "Unknown operand type");
967+
const TargetFrameLowering *TFI = AP.MF->getSubtarget().getFrameLowering();
968+
Offset += TFI->getFrameIndexReference(
969+
*AP.MF, MI->getDebugOperand(0).getIndex(), Reg);
970+
MemLoc = true;
961971
}
962-
case MachineOperand::MO_TargetIndex: {
963-
OS << "!target-index(" << Op.getIndex() << "," << Op.getOffset() << ")";
972+
if (Reg == 0) {
973+
// Suppress offset, it is not meaningful here.
974+
OS << "undef";
964975
// NOTE: Want this comment at start of line, don't emit with AddComment.
965976
AP.OutStreamer->emitRawComment(OS.str());
966-
break;
967-
}
968-
case MachineOperand::MO_Register:
969-
case MachineOperand::MO_FrameIndex: {
970-
Register Reg;
971-
Optional<StackOffset> Offset;
972-
if (Op.isReg()) {
973-
Reg = Op.getReg();
974-
} else {
975-
const TargetFrameLowering *TFI =
976-
AP.MF->getSubtarget().getFrameLowering();
977-
Offset = TFI->getFrameIndexReference(*AP.MF, Op.getIndex(), Reg);
978-
}
979-
if (!Reg) {
980-
// Suppress offset, it is not meaningful here.
981-
OS << "undef";
982-
break;
983-
}
984-
// The second operand is only an offset if it's an immediate.
985-
if (MI->isIndirectDebugValue())
986-
Offset = StackOffset::getFixed(MI->getDebugOffset().getImm());
987-
if (Offset)
988-
OS << '[';
989-
OS << printReg(Reg, AP.MF->getSubtarget().getRegisterInfo());
990-
if (Offset)
991-
OS << '+' << Offset->getFixed() << ']';
992-
break;
993-
}
994-
default:
995-
llvm_unreachable("Unknown operand type");
977+
return true;
996978
}
979+
if (MemLoc)
980+
OS << '[';
981+
OS << printReg(Reg, AP.MF->getSubtarget().getRegisterInfo());
997982
}
998983

984+
if (MemLoc)
985+
OS << '+' << Offset.getFixed() << ']';
986+
999987
// NOTE: Want this comment at start of line, don't emit with AddComment.
1000988
AP.OutStreamer->emitRawComment(OS.str());
1001989
return true;

llvm/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ namespace {
3737
using EntryIndex = DbgValueHistoryMap::EntryIndex;
3838
}
3939

40+
// If @MI is a DBG_VALUE with debug value described by a
41+
// defined register, returns the number of this register.
42+
// In the other case, returns 0.
43+
static Register isDescribedByReg(const MachineInstr &MI) {
44+
assert(MI.isDebugValue());
45+
assert(MI.getNumOperands() == 4);
46+
// If the location of variable is an entry value (DW_OP_LLVM_entry_value)
47+
// do not consider it as a register location.
48+
if (MI.getDebugExpression()->isEntryValue())
49+
return 0;
50+
// If location of variable is described using a register (directly or
51+
// indirectly), this register is always a first operand.
52+
return MI.getDebugOperand(0).isReg() ? MI.getDebugOperand(0).getReg()
53+
: Register();
54+
}
55+
4056
void InstructionOrdering::initialize(const MachineFunction &MF) {
4157
// We give meta instructions the same ordinal as the preceding instruction
4258
// because this class is written for the task of comparing positions of
@@ -317,44 +333,24 @@ static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
317333
}
318334

319335
/// Create a clobbering entry and end all open debug value entries
320-
/// for \p Var that are described by \p RegNo using that entry. Inserts into \p
321-
/// FellowRegisters the set of Registers that were also used to describe \p Var
322-
/// alongside \p RegNo.
336+
/// for \p Var that are described by \p RegNo using that entry.
323337
static void clobberRegEntries(InlinedEntity Var, unsigned RegNo,
324338
const MachineInstr &ClobberingInstr,
325339
DbgValueEntriesMap &LiveEntries,
326-
DbgValueHistoryMap &HistMap,
327-
SmallVectorImpl<Register> &FellowRegisters) {
340+
DbgValueHistoryMap &HistMap) {
328341
EntryIndex ClobberIndex = HistMap.startClobber(Var, ClobberingInstr);
342+
329343
// Close all entries whose values are described by the register.
330344
SmallVector<EntryIndex, 4> IndicesToErase;
331-
// If a given register appears in a live DBG_VALUE_LIST for Var alongside the
332-
// clobbered register, and never appears in a live DBG_VALUE* for Var without
333-
// the clobbered register, then it is no longer linked to the variable.
334-
SmallSet<Register, 4> MaybeRemovedRegisters;
335-
SmallSet<Register, 4> KeepRegisters;
336345
for (auto Index : LiveEntries[Var]) {
337346
auto &Entry = HistMap.getEntry(Var, Index);
338347
assert(Entry.isDbgValue() && "Not a DBG_VALUE in LiveEntries");
339-
if (Entry.getInstr()->isDebugEntryValue())
340-
continue;
341-
if (Entry.getInstr()->hasDebugOperandForReg(RegNo)) {
348+
if (isDescribedByReg(*Entry.getInstr()) == RegNo) {
342349
IndicesToErase.push_back(Index);
343350
Entry.endEntry(ClobberIndex);
344-
for (auto &MO : Entry.getInstr()->debug_operands())
345-
if (MO.isReg() && MO.getReg() && MO.getReg() != RegNo)
346-
MaybeRemovedRegisters.insert(MO.getReg());
347-
} else {
348-
for (auto &MO : Entry.getInstr()->debug_operands())
349-
if (MO.isReg() && MO.getReg())
350-
KeepRegisters.insert(MO.getReg());
351351
}
352352
}
353353

354-
for (Register Reg : MaybeRemovedRegisters)
355-
if (!KeepRegisters.contains(Reg))
356-
FellowRegisters.push_back(Reg);
357-
358354
// Drop all entries that have ended.
359355
for (auto Index : IndicesToErase)
360356
LiveEntries[Var].erase(Index);
@@ -382,24 +378,17 @@ static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV,
382378
IndicesToErase.push_back(Index);
383379
Entry.endEntry(NewIndex);
384380
}
385-
if (!DV.isDebugEntryValue())
386-
for (const MachineOperand &Op : DV.debug_operands())
387-
if (Op.isReg() && Op.getReg())
388-
TrackedRegs[Op.getReg()] |= !Overlaps;
381+
if (Register Reg = isDescribedByReg(DV))
382+
TrackedRegs[Reg] |= !Overlaps;
389383
}
390384

391385
// If the new debug value is described by a register, add tracking of
392386
// that register if it is not already tracked.
393-
if (!DV.isDebugEntryValue()) {
394-
for (const MachineOperand &Op : DV.debug_operands()) {
395-
if (Op.isReg() && Op.getReg()) {
396-
Register NewReg = Op.getReg();
397-
if (!TrackedRegs.count(NewReg))
398-
addRegDescribedVar(RegVars, NewReg, Var);
399-
LiveEntries[Var].insert(NewIndex);
400-
TrackedRegs[NewReg] = true;
401-
}
402-
}
387+
if (Register NewReg = isDescribedByReg(DV)) {
388+
if (!TrackedRegs.count(NewReg))
389+
addRegDescribedVar(RegVars, NewReg, Var);
390+
LiveEntries[Var].insert(NewIndex);
391+
TrackedRegs[NewReg] = true;
403392
}
404393

405394
// Drop tracking of registers that are no longer used.
@@ -422,16 +411,9 @@ static void clobberRegisterUses(RegDescribedVarsMap &RegVars,
422411
DbgValueEntriesMap &LiveEntries,
423412
const MachineInstr &ClobberingInstr) {
424413
// Iterate over all variables described by this register and add this
425-
// instruction to their history, clobbering it. All registers that also
426-
// describe the clobbered variables (i.e. in variadic debug values) will have
427-
// those Variables removed from their DescribedVars.
428-
for (const auto &Var : I->second) {
429-
SmallVector<Register, 4> FellowRegisters;
430-
clobberRegEntries(Var, I->first, ClobberingInstr, LiveEntries, HistMap,
431-
FellowRegisters);
432-
for (Register RegNo : FellowRegisters)
433-
dropRegDescribedVar(RegVars, RegNo, Var);
434-
}
414+
// instruction to their history, clobbering it.
415+
for (const auto &Var : I->second)
416+
clobberRegEntries(Var, I->first, ClobberingInstr, LiveEntries, HistMap);
435417
RegVars.erase(I);
436418
}
437419

llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ Optional<DbgVariableLocation>
3535
DbgVariableLocation::extractFromMachineInstruction(
3636
const MachineInstr &Instruction) {
3737
DbgVariableLocation Location;
38-
// Variables calculated from multiple locations can't be represented here.
39-
if (Instruction.getNumDebugOperands() != 1)
38+
if (!Instruction.isDebugValue())
4039
return None;
4140
if (!Instruction.getDebugOperand(0).isReg())
4241
return None;
@@ -47,15 +46,6 @@ DbgVariableLocation::extractFromMachineInstruction(
4746
int64_t Offset = 0;
4847
const DIExpression *DIExpr = Instruction.getDebugExpression();
4948
auto Op = DIExpr->expr_op_begin();
50-
// We can handle a DBG_VALUE_LIST iff it has exactly one location operand that
51-
// appears exactly once at the start of the expression.
52-
if (Instruction.isDebugValueList()) {
53-
if (Instruction.getNumDebugOperands() == 1 &&
54-
Op->getOp() == dwarf::DW_OP_LLVM_arg)
55-
++Op;
56-
else
57-
return None;
58-
}
5949
while (Op != DIExpr->expr_op_end()) {
6050
switch (Op->getOp()) {
6151
case dwarf::DW_OP_constu: {
@@ -271,8 +261,7 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
271261
continue;
272262

273263
auto IsDescribedByReg = [](const MachineInstr *MI) {
274-
return any_of(MI->debug_operands(),
275-
[](auto &MO) { return MO.isReg() && MO.getReg(); });
264+
return MI->getDebugOperand(0).isReg() && MI->getDebugOperand(0).getReg();
276265
};
277266

278267
// The first mention of a function argument gets the CurrentFnBegin label,

0 commit comments

Comments
 (0)