Skip to content

Commit e24f534

Browse files
committed
[debug-info] As an NFC commit, refactor EmitFuncArgumentDbgValue so that it can be extended to support llvm.dbg.addr.
The reason why I am making this change is that before this commit, EmitFuncArgumentDbgValue relied on a boolean flag IsDbgDeclare both to signal that a DBG_VALUE should be made to be indirect /and/ that the original intrinsic was a dbg.declare. This is no longer always true if we add support for handling dbg.addr since we will have an indirect DBG_VALUE that is a different intrinsic from dbg.declare. With that in mind, in this NFC patch, we prepare for future fixes by introducing a 3 case-enum argument to EmitFuncArgumentDbgValue that allows the caller to explicitly specify how the argument's DBG_VALUE should be emitted. This then allows us to turn the indirect checks into a != FuncArgumentDbgValueKind::Value and prepare us for a future where we add support here for llvm.dbg.addr directly. rdar://83957028 Reviewed By: aprantl Differential Revision: https://reviews.llvm.org/D122945
1 parent 9262d03 commit e24f534

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,8 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
12281228
// in the first place we should not be more successful here). Unless we
12291229
// have some test case that prove this to be correct we should avoid
12301230
// calling EmitFuncArgumentDbgValue here.
1231-
if (!EmitFuncArgumentDbgValue(V, Variable, Expr, dl, false, Val)) {
1231+
if (!EmitFuncArgumentDbgValue(V, Variable, Expr, dl,
1232+
FuncArgumentDbgValueKind::Value, Val)) {
12321233
LLVM_DEBUG(dbgs() << "Resolve dangling debug info [order="
12331234
<< DbgSDNodeOrder << "] for:\n " << *DI << "\n");
12341235
LLVM_DEBUG(dbgs() << " By mapping to:\n "; Val.dump());
@@ -1359,7 +1360,9 @@ bool SelectionDAGBuilder::handleDebugValue(ArrayRef<const Value *> Values,
13591360
N = UnusedArgNodeMap[V];
13601361
if (N.getNode()) {
13611362
// Only emit func arg dbg value for non-variadic dbg.values for now.
1362-
if (!IsVariadic && EmitFuncArgumentDbgValue(V, Var, Expr, dl, false, N))
1363+
if (!IsVariadic &&
1364+
EmitFuncArgumentDbgValue(V, Var, Expr, dl,
1365+
FuncArgumentDbgValueKind::Value, N))
13631366
return true;
13641367
if (auto *FISDN = dyn_cast<FrameIndexSDNode>(N.getNode())) {
13651368
// Construct a FrameIndexDbgValue for FrameIndexSDNodes so we can
@@ -5486,7 +5489,7 @@ getUnderlyingArgRegs(SmallVectorImpl<std::pair<unsigned, TypeSize>> &Regs,
54865489
/// appear for function arguments or in the prologue.
54875490
bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
54885491
const Value *V, DILocalVariable *Variable, DIExpression *Expr,
5489-
DILocation *DL, bool IsDbgDeclare, const SDValue &N) {
5492+
DILocation *DL, FuncArgumentDbgValueKind Kind, const SDValue &N) {
54905493
const Argument *Arg = dyn_cast<Argument>(V);
54915494
if (!Arg)
54925495
return false;
@@ -5520,7 +5523,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
55205523
}
55215524
};
55225525

5523-
if (!IsDbgDeclare) {
5526+
if (Kind == FuncArgumentDbgValueKind::Value) {
55245527
// ArgDbgValues are hoisted to the beginning of the entry block. So we
55255528
// should only emit as ArgDbgValue if the dbg.value intrinsic is found in
55265529
// the entry block.
@@ -5607,7 +5610,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
56075610
}
56085611
if (Reg) {
56095612
Op = MachineOperand::CreateReg(Reg, false);
5610-
IsIndirect = IsDbgDeclare;
5613+
IsIndirect = Kind != FuncArgumentDbgValueKind::Value;
56115614
}
56125615
}
56135616

@@ -5655,7 +5658,8 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
56555658
continue;
56565659
}
56575660
MachineInstr *NewMI =
5658-
MakeVRegDbgValue(RegAndSize.first, *FragmentExpr, IsDbgDeclare);
5661+
MakeVRegDbgValue(RegAndSize.first, *FragmentExpr,
5662+
Kind != FuncArgumentDbgValueKind::Value);
56595663
FuncInfo.ArgDbgValues.push_back(NewMI);
56605664
}
56615665
};
@@ -5673,7 +5677,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
56735677
}
56745678

56755679
Op = MachineOperand::CreateReg(VMI->second, false);
5676-
IsIndirect = IsDbgDeclare;
5680+
IsIndirect = Kind != FuncArgumentDbgValueKind::Value;
56775681
} else if (ArgRegsAndSizes.size() > 1) {
56785682
// This was split due to the calling convention, and no virtual register
56795683
// mapping exists for the value.
@@ -5695,6 +5699,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
56955699
NewMI = BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), true, *Op,
56965700
Variable, Expr);
56975701

5702+
// Otherwise, use ArgDbgValues.
56985703
FuncInfo.ArgDbgValues.push_back(NewMI);
56995704
return true;
57005705
}
@@ -6070,7 +6075,8 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
60706075
} else if (isa<Argument>(Address)) {
60716076
// Address is an argument, so try to emit its dbg value using
60726077
// virtual register info from the FuncInfo.ValueMap.
6073-
EmitFuncArgumentDbgValue(Address, Variable, Expression, dl, true, N);
6078+
EmitFuncArgumentDbgValue(Address, Variable, Expression, dl,
6079+
FuncArgumentDbgValueKind::Declare, N);
60746080
return;
60756081
} else {
60766082
SDV = DAG.getDbgValue(Variable, Expression, N.getNode(), N.getResNo(),
@@ -6080,8 +6086,8 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
60806086
} else {
60816087
// If Address is an argument then try to emit its dbg value using
60826088
// virtual register info from the FuncInfo.ValueMap.
6083-
if (!EmitFuncArgumentDbgValue(Address, Variable, Expression, dl, true,
6084-
N)) {
6089+
if (!EmitFuncArgumentDbgValue(Address, Variable, Expression, dl,
6090+
FuncArgumentDbgValueKind::Declare, N)) {
60856091
LLVM_DEBUG(dbgs() << "Dropping debug info for " << DI
60866092
<< " (could not emit func-arg dbg_value)\n");
60876093
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,22 @@ class SelectionDAGBuilder {
607607

608608
void emitInlineAsmError(const CallBase &Call, const Twine &Message);
609609

610+
/// An enum that states to emit func argument dbg value the kind of intrinsic
611+
/// it originally had. This controls the internal behavior of
612+
/// EmitFuncArgumentDbgValue.
613+
enum class FuncArgumentDbgValueKind {
614+
Value, // This was originally a llvm.dbg.value.
615+
Addr, // This was originally a llvm.dbg.addr.
616+
Declare, // This was originally a llvm.dbg.declare.
617+
};
618+
610619
/// If V is an function argument then create corresponding DBG_VALUE machine
611620
/// instruction for it now. At the end of instruction selection, they will be
612621
/// inserted to the entry BB.
613622
bool EmitFuncArgumentDbgValue(const Value *V, DILocalVariable *Variable,
614623
DIExpression *Expr, DILocation *DL,
615-
bool IsDbgDeclare, const SDValue &N);
624+
FuncArgumentDbgValueKind Kind,
625+
const SDValue &N);
616626

617627
/// Return the next block after MBB, or nullptr if there is none.
618628
MachineBasicBlock *NextBlock(MachineBasicBlock *MBB);

0 commit comments

Comments
 (0)