Skip to content

Commit ed29dba

Browse files
committed
[DebugInfo] Remove some users of DBG_VALUEs IsIndirect field
This patch kills off a significant user of the "IsIndirect" field of DBG_VALUE machine insts. Brought up in in PR41675, IsIndirect is techncally redundant as it can be expressed by the DIExpression of a DBG_VALUE inst, and it isn't helpful to have two ways of expressing things. Rather than setting IsIndirect, have DBG_VALUE creators add an extra deref to the insts DIExpression. There should now be no appearences of IsIndirect=True from isel down to LiveDebugVariables / VirtRegRewriter, which is ensured by an assertion in LDVImpl::handleDebugValue. This means we also get to delete the IsIndirect handling in LiveDebugVariables. Tests can be upgraded by for example swapping the following IsIndirect=True DBG_VALUE: DBG_VALUE $somereg, 0, !123, !DIExpression(DW_OP_foo) With one where the indirection is in the DIExpression, by _appending_ a deref: DBG_VALUE $somereg, $noreg, !123, !DIExpression(DW_OP_foo, DW_OP_deref) Which both mean the same thing. Most of the test changes in this patch are updates of that form; also some changes in how the textual assembly printer handles these insts. Differential Revision: https://reviews.llvm.org/D68945 llvm-svn: 374877
1 parent 4706f3b commit ed29dba

22 files changed

+115
-91
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
13781378
if (!V) {
13791379
// Currently the optimizer can produce this; insert an undef to
13801380
// help debugging. Probably the optimizer should not do this.
1381-
MIRBuilder.buildIndirectDbgValue(0, DI.getVariable(), DI.getExpression());
1381+
MIRBuilder.buildDirectDbgValue(0, DI.getVariable(), DI.getExpression());
13821382
} else if (const auto *CI = dyn_cast<Constant>(V)) {
13831383
MIRBuilder.buildConstDbgValue(*CI, DI.getVariable(), DI.getExpression());
13841384
} else {

llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,13 @@ MachineIRBuilder::buildIndirectDbgValue(Register Reg, const MDNode *Variable,
107107
assert(
108108
cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(getDL()) &&
109109
"Expected inlined-at fields to agree");
110+
// DBG_VALUE insts now carry IR-level indirection in their DIExpression
111+
// rather than encoding it in the instruction itself.
112+
const DIExpression *DIExpr = cast<DIExpression>(Expr);
113+
DIExpr = DIExpression::append(DIExpr, {dwarf::DW_OP_deref});
110114
return insertInstr(BuildMI(getMF(), getDL(),
111115
getTII().get(TargetOpcode::DBG_VALUE),
112-
/*IsIndirect*/ true, Reg, Variable, Expr));
116+
/*IsIndirect*/ false, Reg, Variable, DIExpr));
113117
}
114118

115119
MachineInstrBuilder MachineIRBuilder::buildFIDbgValue(int FI,
@@ -120,11 +124,15 @@ MachineInstrBuilder MachineIRBuilder::buildFIDbgValue(int FI,
120124
assert(
121125
cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(getDL()) &&
122126
"Expected inlined-at fields to agree");
127+
// DBG_VALUE insts now carry IR-level indirection in their DIExpression
128+
// rather than encoding it in the instruction itself.
129+
const DIExpression *DIExpr = cast<DIExpression>(Expr);
130+
DIExpr = DIExpression::append(DIExpr, {dwarf::DW_OP_deref});
123131
return buildInstr(TargetOpcode::DBG_VALUE)
124132
.addFrameIndex(FI)
125-
.addImm(0)
133+
.addReg(0)
126134
.addMetadata(Variable)
127-
.addMetadata(Expr);
135+
.addMetadata(DIExpr);
128136
}
129137

130138
MachineInstrBuilder MachineIRBuilder::buildConstDbgValue(const Constant &C,
@@ -148,7 +156,7 @@ MachineInstrBuilder MachineIRBuilder::buildConstDbgValue(const Constant &C,
148156
MIB.addReg(0U);
149157
}
150158

151-
return MIB.addImm(0).addMetadata(Variable).addMetadata(Expr);
159+
return MIB.addReg(0).addMetadata(Variable).addMetadata(Expr);
152160
}
153161

154162
MachineInstrBuilder MachineIRBuilder::buildDbgLabel(const MDNode *Label) {

llvm/lib/CodeGen/LiveDebugVariables.cpp

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,27 @@ enum : unsigned { UndefLocNo = ~0U };
9999
/// usage of the location.
100100
class DbgValueLocation {
101101
public:
102-
DbgValueLocation(unsigned LocNo, bool WasIndirect)
103-
: LocNo(LocNo), WasIndirect(WasIndirect) {
102+
DbgValueLocation(unsigned LocNo)
103+
: LocNo(LocNo) {
104104
static_assert(sizeof(*this) == sizeof(unsigned), "bad bitfield packing");
105105
assert(locNo() == LocNo && "location truncation");
106106
}
107107

108-
DbgValueLocation() : LocNo(0), WasIndirect(0) {}
108+
DbgValueLocation() : LocNo(0) {}
109109

110110
unsigned locNo() const {
111111
// Fix up the undef location number, which gets truncated.
112112
return LocNo == INT_MAX ? UndefLocNo : LocNo;
113113
}
114-
bool wasIndirect() const { return WasIndirect; }
115114
bool isUndef() const { return locNo() == UndefLocNo; }
116115

117116
DbgValueLocation changeLocNo(unsigned NewLocNo) const {
118-
return DbgValueLocation(NewLocNo, WasIndirect);
117+
return DbgValueLocation(NewLocNo);
119118
}
120119

121120
friend inline bool operator==(const DbgValueLocation &LHS,
122121
const DbgValueLocation &RHS) {
123-
return LHS.LocNo == RHS.LocNo && LHS.WasIndirect == RHS.WasIndirect;
122+
return LHS.LocNo == RHS.LocNo;
124123
}
125124

126125
friend inline bool operator!=(const DbgValueLocation &LHS,
@@ -129,8 +128,7 @@ class DbgValueLocation {
129128
}
130129

131130
private:
132-
unsigned LocNo : 31;
133-
unsigned WasIndirect : 1;
131+
unsigned LocNo;
134132
};
135133

136134
/// Map of where a user value is live, and its location.
@@ -261,8 +259,8 @@ class UserValue {
261259
void mapVirtRegs(LDVImpl *LDV);
262260

263261
/// Add a definition point to this value.
264-
void addDef(SlotIndex Idx, const MachineOperand &LocMO, bool IsIndirect) {
265-
DbgValueLocation Loc(getLocationNo(LocMO), IsIndirect);
262+
void addDef(SlotIndex Idx, const MachineOperand &LocMO) {
263+
DbgValueLocation Loc(getLocationNo(LocMO));
266264
// Add a singular (Idx,Idx) -> Loc mapping.
267265
LocMap::iterator I = locInts.find(Idx);
268266
if (!I.valid() || I.start() != Idx)
@@ -297,11 +295,10 @@ class UserValue {
297295
///
298296
/// \param LI Scan for copies of the value in LI->reg.
299297
/// \param LocNo Location number of LI->reg.
300-
/// \param WasIndirect Indicates if the original use of LI->reg was indirect
301298
/// \param Kills Points where the range of LocNo could be extended.
302299
/// \param [in,out] NewDefs Append (Idx, LocNo) of inserted defs here.
303300
void addDefsFromCopies(
304-
LiveInterval *LI, unsigned LocNo, bool WasIndirect,
301+
LiveInterval *LI, unsigned LocNo,
305302
const SmallVectorImpl<SlotIndex> &Kills,
306303
SmallVectorImpl<std::pair<SlotIndex, DbgValueLocation>> &NewDefs,
307304
MachineRegisterInfo &MRI, LiveIntervals &LIS);
@@ -521,8 +518,6 @@ void UserValue::print(raw_ostream &OS, const TargetRegisterInfo *TRI) {
521518
OS << "undef";
522519
else {
523520
OS << I.value().locNo();
524-
if (I.value().wasIndirect())
525-
OS << " ind";
526521
}
527522
}
528523
for (unsigned i = 0, e = locations.size(); i != e; ++i) {
@@ -631,19 +626,18 @@ bool LDVImpl::handleDebugValue(MachineInstr &MI, SlotIndex Idx) {
631626
}
632627

633628
// Get or create the UserValue for (variable,offset) here.
634-
bool IsIndirect = MI.getOperand(1).isImm();
635-
if (IsIndirect)
636-
assert(MI.getOperand(1).getImm() == 0 && "DBG_VALUE with nonzero offset");
629+
assert(!MI.getOperand(1).isImm() && "DBG_VALUE with indirect flag before "
630+
"LiveDebugVariables");
637631
const DILocalVariable *Var = MI.getDebugVariable();
638632
const DIExpression *Expr = MI.getDebugExpression();
639633
UserValue *UV =
640634
getUserValue(Var, Expr, MI.getDebugLoc());
641635
if (!Discard)
642-
UV->addDef(Idx, MI.getOperand(0), IsIndirect);
636+
UV->addDef(Idx, MI.getOperand(0));
643637
else {
644638
MachineOperand MO = MachineOperand::CreateReg(0U, false);
645639
MO.setIsDebug();
646-
UV->addDef(Idx, MO, false);
640+
UV->addDef(Idx, MO);
647641
}
648642
return true;
649643
}
@@ -751,7 +745,7 @@ void UserValue::extendDef(SlotIndex Idx, DbgValueLocation Loc, LiveRange *LR,
751745
}
752746

753747
void UserValue::addDefsFromCopies(
754-
LiveInterval *LI, unsigned LocNo, bool WasIndirect,
748+
LiveInterval *LI, unsigned LocNo,
755749
const SmallVectorImpl<SlotIndex> &Kills,
756750
SmallVectorImpl<std::pair<SlotIndex, DbgValueLocation>> &NewDefs,
757751
MachineRegisterInfo &MRI, LiveIntervals &LIS) {
@@ -815,7 +809,7 @@ void UserValue::addDefsFromCopies(
815809
MachineInstr *CopyMI = LIS.getInstructionFromIndex(DstVNI->def);
816810
assert(CopyMI && CopyMI->isCopy() && "Bad copy value");
817811
unsigned LocNo = getLocationNo(CopyMI->getOperand(0));
818-
DbgValueLocation NewLoc(LocNo, WasIndirect);
812+
DbgValueLocation NewLoc(LocNo);
819813
I.insert(Idx, Idx.getNextSlot(), NewLoc);
820814
NewDefs.push_back(std::make_pair(Idx, NewLoc));
821815
break;
@@ -863,8 +857,7 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI,
863857
// sub-register in that regclass). For now, simply skip handling copies if
864858
// a sub-register is involved.
865859
if (LI && !LocMO.getSubReg())
866-
addDefsFromCopies(LI, Loc.locNo(), Loc.wasIndirect(), Kills, Defs, MRI,
867-
LIS);
860+
addDefsFromCopies(LI, Loc.locNo(), Kills, Defs, MRI, LIS);
868861
continue;
869862
}
870863

@@ -1302,21 +1295,14 @@ void UserValue::insertDebugValue(MachineBasicBlock *MBB, SlotIndex StartIdx,
13021295
// that the original virtual register was a pointer. Also, add the stack slot
13031296
// offset for the spilled register to the expression.
13041297
const DIExpression *Expr = Expression;
1305-
uint8_t DIExprFlags = DIExpression::ApplyOffset;
1306-
bool IsIndirect = Loc.wasIndirect();
1307-
if (Spilled) {
1308-
if (IsIndirect)
1309-
DIExprFlags |= DIExpression::DerefAfter;
1310-
Expr =
1311-
DIExpression::prepend(Expr, DIExprFlags, SpillOffset);
1312-
IsIndirect = true;
1313-
}
1298+
if (Spilled)
1299+
Expr = DIExpression::prepend(Expr, DIExpression::ApplyOffset, SpillOffset);
13141300

13151301
assert((!Spilled || MO.isFI()) && "a spilled location must be a frame index");
13161302

13171303
do {
13181304
BuildMI(*MBB, I, getDebugLoc(), TII.get(TargetOpcode::DBG_VALUE),
1319-
IsIndirect, MO, Variable, Expr);
1305+
Spilled, MO, Variable, Expr);
13201306

13211307
// Continue and insert DBG_VALUES after every redefinition of register
13221308
// associated with the debug value within the range

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,9 +1389,11 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
13891389
"Expected inlined-at fields to agree");
13901390
// A dbg.declare describes the address of a source variable, so lower it
13911391
// into an indirect DBG_VALUE.
1392+
auto *Expr = DI->getExpression();
1393+
Expr = DIExpression::append(Expr, {dwarf::DW_OP_deref});
13921394
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1393-
TII.get(TargetOpcode::DBG_VALUE), /*IsIndirect*/ true,
1394-
*Op, DI->getVariable(), DI->getExpression());
1395+
TII.get(TargetOpcode::DBG_VALUE), /*IsIndirect*/ false,
1396+
*Op, DI->getVariable(), Expr);
13951397
} else {
13961398
// We can't yet handle anything else here because it would require
13971399
// generating code, thus altering codegen because of debug info.
@@ -1415,19 +1417,19 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
14151417
if (CI->getBitWidth() > 64)
14161418
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
14171419
.addCImm(CI)
1418-
.addImm(0U)
1420+
.addReg(0U)
14191421
.addMetadata(DI->getVariable())
14201422
.addMetadata(DI->getExpression());
14211423
else
14221424
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
14231425
.addImm(CI->getZExtValue())
1424-
.addImm(0U)
1426+
.addReg(0U)
14251427
.addMetadata(DI->getVariable())
14261428
.addMetadata(DI->getExpression());
14271429
} else if (const auto *CF = dyn_cast<ConstantFP>(V)) {
14281430
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
14291431
.addFPImm(CF)
1430-
.addImm(0U)
1432+
.addReg(0U)
14311433
.addMetadata(DI->getVariable())
14321434
.addMetadata(DI->getExpression());
14331435
} else if (unsigned Reg = lookUpRegForValue(V)) {

llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ MachineInstr *
677677
InstrEmitter::EmitDbgValue(SDDbgValue *SD,
678678
DenseMap<SDValue, unsigned> &VRBaseMap) {
679679
MDNode *Var = SD->getVariable();
680-
MDNode *Expr = SD->getExpression();
680+
const DIExpression *Expr = SD->getExpression();
681681
DebugLoc DL = SD->getDebugLoc();
682682
assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
683683
"Expected inlined-at fields to agree");
@@ -701,12 +701,11 @@ InstrEmitter::EmitDbgValue(SDDbgValue *SD,
701701
// EmitTargetCodeForFrameDebugValue is responsible for allocation.
702702
auto FrameMI = BuildMI(*MF, DL, TII->get(TargetOpcode::DBG_VALUE))
703703
.addFrameIndex(SD->getFrameIx());
704+
704705
if (SD->isIndirect())
705-
// Push [fi + 0] onto the DIExpression stack.
706-
FrameMI.addImm(0);
707-
else
708-
// Push fi onto the DIExpression stack.
709-
FrameMI.addReg(0);
706+
Expr = DIExpression::append(Expr, {dwarf::DW_OP_deref});
707+
708+
FrameMI.addReg(0);
710709
return FrameMI.addMetadata(Var).addMetadata(Expr);
711710
}
712711
// Otherwise, we're going to create an instruction here.
@@ -752,9 +751,9 @@ InstrEmitter::EmitDbgValue(SDDbgValue *SD,
752751

753752
// Indirect addressing is indicated by an Imm as the second parameter.
754753
if (SD->isIndirect())
755-
MIB.addImm(0U);
756-
else
757-
MIB.addReg(0U, RegState::Debug);
754+
Expr = DIExpression::append(Expr, {dwarf::DW_OP_deref});
755+
756+
MIB.addReg(0U, RegState::Debug);
758757

759758
MIB.addMetadata(Var);
760759
MIB.addMetadata(Expr);

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5519,8 +5519,9 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
55195519
Expr, Offset, RegAndSize.second);
55205520
if (!FragmentExpr)
55215521
continue;
5522+
assert(!IsDbgDeclare && "DbgDeclare operand is not in memory?");
55225523
FuncInfo.ArgDbgValues.push_back(
5523-
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsDbgDeclare,
5524+
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), false,
55245525
RegAndSize.first, Variable, *FragmentExpr));
55255526
Offset += RegAndSize.second;
55265527
}
@@ -5554,8 +5555,10 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
55545555
assert(Variable->isValidLocationForIntrinsic(DL) &&
55555556
"Expected inlined-at fields to agree");
55565557
IsIndirect = (Op->isReg()) ? IsIndirect : true;
5558+
if (IsIndirect)
5559+
Expr = DIExpression::append(Expr, {dwarf::DW_OP_deref});
55575560
FuncInfo.ArgDbgValues.push_back(
5558-
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsIndirect,
5561+
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), false,
55595562
*Op, Variable, Expr));
55605563

55615564
return true;

llvm/test/CodeGen/AArch64/GlobalISel/debug-cpp.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ target triple = "aarch64-unknown-linux-gnu"
1818
%struct.NTCopy = type { i32 }
1919

2020
; CHECK-LABEL: name: _Z3foo6NTCopy
21-
; CHECK: DBG_VALUE %{{[0-9]+}}(p0), 0, !23, !DIExpression(), debug-location !24
21+
; CHECK: DBG_VALUE %{{[0-9]+}}(p0), $noreg, !23, !DIExpression(DW_OP_deref), debug-location !24
2222
; Function Attrs: noinline nounwind optnone
2323
define dso_local i32 @_Z3foo6NTCopy(%struct.NTCopy* %o) #0 !dbg !7 {
2424
entry:

llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ entry:
1515
}
1616

1717
; CHECK-LABEL: name: debug_declare_vla
18-
; CHECK: DBG_VALUE %{{[0-9]+}}(p0), 0, !14, !DIExpression(), debug-location !15
18+
; CHECK: DBG_VALUE %{{[0-9]+}}(p0), $noreg, !14, !DIExpression(DW_OP_deref), debug-location !15
1919
define void @debug_declare_vla(i32 %in) #0 !dbg !13 {
2020
entry:
2121
%vla.addr = alloca i32, i32 %in
@@ -32,11 +32,11 @@ define void @debug_value(i32 %in) #0 !dbg !16 {
3232
store i32 %in, i32* %addr
3333
; CHECK: DBG_VALUE %1(p0), $noreg, !17, !DIExpression(DW_OP_deref), debug-location !18
3434
call void @llvm.dbg.value(metadata i32* %addr, i64 0, metadata !17, metadata !DIExpression(DW_OP_deref)), !dbg !18
35-
; CHECK: DBG_VALUE 123, 0, !17, !DIExpression(), debug-location !18
35+
; CHECK: DBG_VALUE 123, $noreg, !17, !DIExpression(), debug-location !18
3636
call void @llvm.dbg.value(metadata i32 123, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
37-
; CHECK: DBG_VALUE float 1.000000e+00, 0, !17, !DIExpression(), debug-location !18
37+
; CHECK: DBG_VALUE float 1.000000e+00, $noreg, !17, !DIExpression(), debug-location !18
3838
call void @llvm.dbg.value(metadata float 1.000000e+00, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
39-
; CHECK: DBG_VALUE $noreg, 0, !17, !DIExpression(), debug-location !18
39+
; CHECK: DBG_VALUE $noreg, $noreg, !17, !DIExpression(), debug-location !18
4040
call void @llvm.dbg.value(metadata i32* null, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
4141
ret void
4242
}

llvm/test/CodeGen/ARM/debug-info-arg.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define void @foo(%struct.tag_s* nocapture %this, %struct.tag_s* %c, i64 %x, i64
1111
tail call void @llvm.dbg.value(metadata %struct.tag_s* %c, metadata !13, metadata !DIExpression()), !dbg !21
1212
tail call void @llvm.dbg.value(metadata i64 %x, metadata !14, metadata !DIExpression()), !dbg !22
1313
tail call void @llvm.dbg.value(metadata i64 %y, metadata !17, metadata !DIExpression()), !dbg !23
14-
;CHECK: @DEBUG_VALUE: foo:y <- [DW_OP_plus_uconst 8] [$r7+0]
14+
;CHECK: @DEBUG_VALUE: foo:y <- [DW_OP_plus_uconst 8, DW_OP_deref] $r7
1515
tail call void @llvm.dbg.value(metadata %struct.tag_s* %ptr1, metadata !18, metadata !DIExpression()), !dbg !24
1616
tail call void @llvm.dbg.value(metadata %struct.tag_s* %ptr2, metadata !19, metadata !DIExpression()), !dbg !25
1717
%1 = icmp eq %struct.tag_s* %c, null, !dbg !26

llvm/test/CodeGen/PowerPC/debuginfo-stackarg.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ define i64 @foo(i64 %bar1, i64 %bar2, i64 %bar3, i64 %bar4, i64 %bar5) local_unn
3434
; We expect to find a DBG_VALUE refering to the metadata id for bar5, using the lowest
3535
; of the two fixed stack offsets found earlier.
3636
; CHECK-LABEL: body:
37-
; CHECK: DBG_VALUE $r1, 0, !17, !DIExpression(DW_OP_plus_uconst, 8)
37+
; CHECK: DBG_VALUE $r1, $noreg, !17, !DIExpression(DW_OP_plus_uconst, 8, DW_OP_deref)
3838
entry:
3939
tail call void @llvm.dbg.value(metadata i64 %bar1, metadata !13, metadata !DIExpression()), !dbg !18
4040
tail call void @llvm.dbg.value(metadata i64 %bar2, metadata !14, metadata !DIExpression()), !dbg !19

0 commit comments

Comments
 (0)