Skip to content

Revert IsIndirect DBG_VALUE changes, take an entry values bugfix #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
if (!V) {
// Currently the optimizer can produce this; insert an undef to
// help debugging. Probably the optimizer should not do this.
MIRBuilder.buildDirectDbgValue(0, DI.getVariable(), DI.getExpression());
MIRBuilder.buildIndirectDbgValue(0, DI.getVariable(), DI.getExpression());
} else if (const auto *CI = dyn_cast<Constant>(V)) {
MIRBuilder.buildConstDbgValue(*CI, DI.getVariable(), DI.getExpression());
} else {
Expand Down
16 changes: 4 additions & 12 deletions llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,9 @@ MachineIRBuilder::buildIndirectDbgValue(Register Reg, const MDNode *Variable,
assert(
cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(getDL()) &&
"Expected inlined-at fields to agree");
// DBG_VALUE insts now carry IR-level indirection in their DIExpression
// rather than encoding it in the instruction itself.
const DIExpression *DIExpr = cast<DIExpression>(Expr);
DIExpr = DIExpression::append(DIExpr, {dwarf::DW_OP_deref});
return insertInstr(BuildMI(getMF(), getDL(),
getTII().get(TargetOpcode::DBG_VALUE),
/*IsIndirect*/ false, Reg, Variable, DIExpr));
/*IsIndirect*/ true, Reg, Variable, Expr));
}

MachineInstrBuilder MachineIRBuilder::buildFIDbgValue(int FI,
Expand All @@ -124,15 +120,11 @@ MachineInstrBuilder MachineIRBuilder::buildFIDbgValue(int FI,
assert(
cast<DILocalVariable>(Variable)->isValidLocationForIntrinsic(getDL()) &&
"Expected inlined-at fields to agree");
// DBG_VALUE insts now carry IR-level indirection in their DIExpression
// rather than encoding it in the instruction itself.
const DIExpression *DIExpr = cast<DIExpression>(Expr);
DIExpr = DIExpression::append(DIExpr, {dwarf::DW_OP_deref});
return buildInstr(TargetOpcode::DBG_VALUE)
.addFrameIndex(FI)
.addReg(0)
.addImm(0)
.addMetadata(Variable)
.addMetadata(DIExpr);
.addMetadata(Expr);
}

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

return MIB.addReg(0).addMetadata(Variable).addMetadata(Expr);
return MIB.addImm(0).addMetadata(Variable).addMetadata(Expr);
}

MachineInstrBuilder MachineIRBuilder::buildDbgLabel(const MDNode *Label) {
Expand Down
52 changes: 33 additions & 19 deletions llvm/lib/CodeGen/LiveDebugVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,28 @@ enum : unsigned { UndefLocNo = ~0U };
/// usage of the location.
class DbgValueLocation {
public:
DbgValueLocation(unsigned LocNo)
: LocNo(LocNo) {
DbgValueLocation(unsigned LocNo, bool WasIndirect)
: LocNo(LocNo), WasIndirect(WasIndirect) {
static_assert(sizeof(*this) == sizeof(unsigned), "bad bitfield packing");
assert(locNo() == LocNo && "location truncation");
}

DbgValueLocation() : LocNo(0) {}
DbgValueLocation() : LocNo(0), WasIndirect(0) {}

unsigned locNo() const {
// Fix up the undef location number, which gets truncated.
return LocNo == INT_MAX ? UndefLocNo : LocNo;
}
bool wasIndirect() const { return WasIndirect; }
bool isUndef() const { return locNo() == UndefLocNo; }

DbgValueLocation changeLocNo(unsigned NewLocNo) const {
return DbgValueLocation(NewLocNo);
return DbgValueLocation(NewLocNo, WasIndirect);
}

friend inline bool operator==(const DbgValueLocation &LHS,
const DbgValueLocation &RHS) {
return LHS.LocNo == RHS.LocNo;
return LHS.LocNo == RHS.LocNo && LHS.WasIndirect == RHS.WasIndirect;
}

friend inline bool operator!=(const DbgValueLocation &LHS,
Expand All @@ -129,7 +130,8 @@ class DbgValueLocation {
}

private:
unsigned LocNo;
unsigned LocNo : 31;
unsigned WasIndirect : 1;
};

/// Map of where a user value is live, and its location.
Expand Down Expand Up @@ -283,8 +285,8 @@ class UserValue {
void mapVirtRegs(LDVImpl *LDV);

/// Add a definition point to this value.
void addDef(SlotIndex Idx, const MachineOperand &LocMO) {
DbgValueLocation Loc(getLocationNo(LocMO));
void addDef(SlotIndex Idx, const MachineOperand &LocMO, bool IsIndirect) {
DbgValueLocation Loc(getLocationNo(LocMO), IsIndirect);
// Add a singular (Idx,Idx) -> Loc mapping.
LocMap::iterator I = locInts.find(Idx);
if (!I.valid() || I.start() != Idx)
Expand Down Expand Up @@ -319,10 +321,11 @@ class UserValue {
///
/// \param LI Scan for copies of the value in LI->reg.
/// \param LocNo Location number of LI->reg.
/// \param WasIndirect Indicates if the original use of LI->reg was indirect
/// \param Kills Points where the range of LocNo could be extended.
/// \param [in,out] NewDefs Append (Idx, LocNo) of inserted defs here.
void addDefsFromCopies(
LiveInterval *LI, unsigned LocNo,
LiveInterval *LI, unsigned LocNo, bool WasIndirect,
const SmallVectorImpl<SlotIndex> &Kills,
SmallVectorImpl<std::pair<SlotIndex, DbgValueLocation>> &NewDefs,
MachineRegisterInfo &MRI, LiveIntervals &LIS);
Expand Down Expand Up @@ -542,6 +545,8 @@ void UserValue::print(raw_ostream &OS, const TargetRegisterInfo *TRI) {
OS << "undef";
else {
OS << I.value().locNo();
if (I.value().wasIndirect())
OS << " ind";
}
}
for (unsigned i = 0, e = locations.size(); i != e; ++i) {
Expand Down Expand Up @@ -650,18 +655,19 @@ bool LDVImpl::handleDebugValue(MachineInstr &MI, SlotIndex Idx) {
}

// Get or create the UserValue for (variable,offset) here.
assert(!MI.getOperand(1).isImm() && "DBG_VALUE with indirect flag before "
"LiveDebugVariables");
bool IsIndirect = MI.getOperand(1).isImm();
if (IsIndirect)
assert(MI.getOperand(1).getImm() == 0 && "DBG_VALUE with nonzero offset");
const DILocalVariable *Var = MI.getDebugVariable();
const DIExpression *Expr = MI.getDebugExpression();
UserValue *UV =
getUserValue(Var, Expr, MI.getDebugLoc());
if (!Discard)
UV->addDef(Idx, MI.getOperand(0));
UV->addDef(Idx, MI.getOperand(0), IsIndirect);
else {
MachineOperand MO = MachineOperand::CreateReg(0U, false);
MO.setIsDebug();
UV->addDef(Idx, MO);
UV->addDef(Idx, MO, false);
}
return true;
}
Expand Down Expand Up @@ -769,7 +775,7 @@ void UserValue::extendDef(SlotIndex Idx, DbgValueLocation Loc, LiveRange *LR,
}

void UserValue::addDefsFromCopies(
LiveInterval *LI, unsigned LocNo,
LiveInterval *LI, unsigned LocNo, bool WasIndirect,
const SmallVectorImpl<SlotIndex> &Kills,
SmallVectorImpl<std::pair<SlotIndex, DbgValueLocation>> &NewDefs,
MachineRegisterInfo &MRI, LiveIntervals &LIS) {
Expand Down Expand Up @@ -833,7 +839,7 @@ void UserValue::addDefsFromCopies(
MachineInstr *CopyMI = LIS.getInstructionFromIndex(DstVNI->def);
assert(CopyMI && CopyMI->isCopy() && "Bad copy value");
unsigned LocNo = getLocationNo(CopyMI->getOperand(0));
DbgValueLocation NewLoc(LocNo);
DbgValueLocation NewLoc(LocNo, WasIndirect);
I.insert(Idx, Idx.getNextSlot(), NewLoc);
NewDefs.push_back(std::make_pair(Idx, NewLoc));
break;
Expand Down Expand Up @@ -881,7 +887,8 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI,
// sub-register in that regclass). For now, simply skip handling copies if
// a sub-register is involved.
if (LI && !LocMO.getSubReg())
addDefsFromCopies(LI, Loc.locNo(), Kills, Defs, MRI, LIS);
addDefsFromCopies(LI, Loc.locNo(), Loc.wasIndirect(), Kills, Defs, MRI,
LIS);
continue;
}

Expand Down Expand Up @@ -1323,14 +1330,21 @@ void UserValue::insertDebugValue(MachineBasicBlock *MBB, SlotIndex StartIdx,
// that the original virtual register was a pointer. Also, add the stack slot
// offset for the spilled register to the expression.
const DIExpression *Expr = Expression;
if (Spilled)
Expr = DIExpression::prepend(Expr, DIExpression::ApplyOffset, SpillOffset);
uint8_t DIExprFlags = DIExpression::ApplyOffset;
bool IsIndirect = Loc.wasIndirect();
if (Spilled) {
if (IsIndirect)
DIExprFlags |= DIExpression::DerefAfter;
Expr =
DIExpression::prepend(Expr, DIExprFlags, SpillOffset);
IsIndirect = true;
}

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

do {
BuildMI(*MBB, I, getDebugLoc(), TII.get(TargetOpcode::DBG_VALUE),
Spilled, MO, Variable, Expr);
IsIndirect, MO, Variable, Expr);

// Continue and insert DBG_VALUES after every redefinition of register
// associated with the debug value within the range
Expand Down
12 changes: 5 additions & 7 deletions llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,11 +1393,9 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
"Expected inlined-at fields to agree");
// A dbg.declare describes the address of a source variable, so lower it
// into an indirect DBG_VALUE.
auto *Expr = DI->getExpression();
Expr = DIExpression::append(Expr, {dwarf::DW_OP_deref});
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
TII.get(TargetOpcode::DBG_VALUE), /*IsIndirect*/ false,
*Op, DI->getVariable(), Expr);
TII.get(TargetOpcode::DBG_VALUE), /*IsIndirect*/ true,
*Op, DI->getVariable(), DI->getExpression());
} else {
// We can't yet handle anything else here because it would require
// generating code, thus altering codegen because of debug info.
Expand All @@ -1421,19 +1419,19 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
if (CI->getBitWidth() > 64)
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
.addCImm(CI)
.addReg(0U)
.addImm(0U)
.addMetadata(DI->getVariable())
.addMetadata(DI->getExpression());
else
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
.addImm(CI->getZExtValue())
.addReg(0U)
.addImm(0U)
.addMetadata(DI->getVariable())
.addMetadata(DI->getExpression());
} else if (const auto *CF = dyn_cast<ConstantFP>(V)) {
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II)
.addFPImm(CF)
.addReg(0U)
.addImm(0U)
.addMetadata(DI->getVariable())
.addMetadata(DI->getExpression());
} else if (unsigned Reg = lookUpRegForValue(V)) {
Expand Down
17 changes: 9 additions & 8 deletions llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ MachineInstr *
InstrEmitter::EmitDbgValue(SDDbgValue *SD,
DenseMap<SDValue, unsigned> &VRBaseMap) {
MDNode *Var = SD->getVariable();
const DIExpression *Expr = SD->getExpression();
MDNode *Expr = SD->getExpression();
DebugLoc DL = SD->getDebugLoc();
assert(cast<DILocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
Expand All @@ -701,11 +701,12 @@ InstrEmitter::EmitDbgValue(SDDbgValue *SD,
// EmitTargetCodeForFrameDebugValue is responsible for allocation.
auto FrameMI = BuildMI(*MF, DL, TII->get(TargetOpcode::DBG_VALUE))
.addFrameIndex(SD->getFrameIx());

if (SD->isIndirect())
Expr = DIExpression::append(Expr, {dwarf::DW_OP_deref});

FrameMI.addReg(0);
// Push [fi + 0] onto the DIExpression stack.
FrameMI.addImm(0);
else
// Push fi onto the DIExpression stack.
FrameMI.addReg(0);
return FrameMI.addMetadata(Var).addMetadata(Expr);
}
// Otherwise, we're going to create an instruction here.
Expand Down Expand Up @@ -751,9 +752,9 @@ InstrEmitter::EmitDbgValue(SDDbgValue *SD,

// Indirect addressing is indicated by an Imm as the second parameter.
if (SD->isIndirect())
Expr = DIExpression::append(Expr, {dwarf::DW_OP_deref});

MIB.addReg(0U, RegState::Debug);
MIB.addImm(0U);
else
MIB.addReg(0U, RegState::Debug);

MIB.addMetadata(Var);
MIB.addMetadata(Expr);
Expand Down
28 changes: 6 additions & 22 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5565,6 +5565,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
MachineFunction &MF = DAG.getMachineFunction();
const TargetInstrInfo *TII = DAG.getSubtarget().getInstrInfo();

bool IsIndirect = false;
Optional<MachineOperand> Op;
// Some arguments' frame index is recorded during argument lowering.
int FI = FuncInfo.getArgumentFrameIndex(Arg);
Expand All @@ -5586,6 +5587,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
}
if (Reg) {
Op = MachineOperand::CreateReg(Reg, false);
IsIndirect = IsDbgDeclare;
}
}

Expand Down Expand Up @@ -5634,7 +5636,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
}
assert(!IsDbgDeclare && "DbgDeclare operand is not in memory?");
FuncInfo.ArgDbgValues.push_back(
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), false,
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsDbgDeclare,
RegAndSize.first, Variable, *FragmentExpr));
}
};
Expand All @@ -5652,6 +5654,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
}

Op = MachineOperand::CreateReg(VMI->second, false);
IsIndirect = IsDbgDeclare;
} else if (ArgRegsAndSizes.size() > 1) {
// This was split due to the calling convention, and no virtual register
// mapping exists for the value.
Expand All @@ -5665,28 +5668,9 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(

assert(Variable->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");

// If the argument arrives in a stack slot, then what the IR thought was a
// normal Value is actually in memory, and we must add a deref to load it.
if (Op->isFI()) {
int FI = Op->getIndex();
unsigned Size = DAG.getMachineFunction().getFrameInfo().getObjectSize(FI);
if (Expr->isImplicit()) {
SmallVector<uint64_t, 2> Ops = {dwarf::DW_OP_deref_size, Size};
Expr = DIExpression::prependOpcodes(Expr, Ops);
} else {
Expr = DIExpression::prepend(Expr, DIExpression::DerefBefore);
}
}

// If this location was specified with a dbg.declare, then it and its
// expression calculate the address of the variable. Append a deref to
// force it to be a memory location.
if (IsDbgDeclare)
Expr = DIExpression::append(Expr, {dwarf::DW_OP_deref});

IsIndirect = (Op->isReg()) ? IsIndirect : true;
FuncInfo.ArgDbgValues.push_back(
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), false,
BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsIndirect,
*Op, Variable, Expr));

return true;
Expand Down
10 changes: 8 additions & 2 deletions llvm/lib/CodeGen/TargetInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,14 @@ TargetInstrInfo::describeLoadedValue(const MachineInstr &MI,
if (!TII->getMemOperandWithOffset(MI, BaseOp, Offset, TRI))
return None;

assert(MI.getNumExplicitDefs() == 1 &&
"Can currently only handle mem instructions with a single define");
// TODO: Can currently only handle mem instructions with a single define.
// An example from the x86 target:
// ...
// DIV64m $rsp, 1, $noreg, 24, $noreg, implicit-def dead $rax, implicit-def $rdx
// ...
//
if (MI.getNumExplicitDefs() != 1)
return None;

// TODO: In what way do we need to take Reg into consideration here?

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/AArch64/GlobalISel/debug-cpp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ target triple = "aarch64-unknown-linux-gnu"
%struct.NTCopy = type { i32 }

; CHECK-LABEL: name: _Z3foo6NTCopy
; CHECK: DBG_VALUE %{{[0-9]+}}(p0), $noreg, !23, !DIExpression(DW_OP_deref), debug-location !24
; CHECK: DBG_VALUE %{{[0-9]+}}(p0), 0, !23, !DIExpression(), debug-location !24
; Function Attrs: noinline nounwind optnone
define dso_local i32 @_Z3foo6NTCopy(%struct.NTCopy* %o) #0 !dbg !7 {
entry:
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ entry:
}

; CHECK-LABEL: name: debug_declare_vla
; CHECK: DBG_VALUE %{{[0-9]+}}(p0), $noreg, !14, !DIExpression(DW_OP_deref), debug-location !15
; CHECK: DBG_VALUE %{{[0-9]+}}(p0), 0, !14, !DIExpression(), debug-location !15
define void @debug_declare_vla(i32 %in) #0 !dbg !13 {
entry:
%vla.addr = alloca i32, i32 %in
Expand All @@ -32,11 +32,11 @@ define void @debug_value(i32 %in) #0 !dbg !16 {
store i32 %in, i32* %addr
; CHECK: DBG_VALUE %1(p0), $noreg, !17, !DIExpression(DW_OP_deref), debug-location !18
call void @llvm.dbg.value(metadata i32* %addr, i64 0, metadata !17, metadata !DIExpression(DW_OP_deref)), !dbg !18
; CHECK: DBG_VALUE 123, $noreg, !17, !DIExpression(), debug-location !18
; CHECK: DBG_VALUE 123, 0, !17, !DIExpression(), debug-location !18
call void @llvm.dbg.value(metadata i32 123, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
; CHECK: DBG_VALUE float 1.000000e+00, $noreg, !17, !DIExpression(), debug-location !18
; CHECK: DBG_VALUE float 1.000000e+00, 0, !17, !DIExpression(), debug-location !18
call void @llvm.dbg.value(metadata float 1.000000e+00, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
; CHECK: DBG_VALUE $noreg, $noreg, !17, !DIExpression(), debug-location !18
; CHECK: DBG_VALUE $noreg, 0, !17, !DIExpression(), debug-location !18
call void @llvm.dbg.value(metadata i32* null, i64 0, metadata !17, metadata !DIExpression()), !dbg !18
ret void
}
Expand Down
Loading