Skip to content

Commit 7a9ea8f

Browse files
committed
GlobalISel: put debug info for static allocas in the MachineFunction.
The good reason to do this is that static allocas are pretty simple to handle (especially at -O0) and avoiding tracking DBG_VALUEs throughout the pipeline should give some kind of performance benefit. The bad reason is that the debug pipeline is an unholy mess of implicit contracts, where determining whether "DBG_VALUE %reg, imm" actually implies a load or not involves the services of at least 3 soothsayers and the sacrifice of at least one chicken. And it still gets it wrong if the variable is at SP directly. llvm-svn: 297410
1 parent 7e56366 commit 7a9ea8f

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -598,18 +598,18 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
598598
return true;
599599
}
600600

601-
unsigned Reg = getOrCreateVReg(*Address);
602-
auto RegDef = MRI->def_instr_begin(Reg);
603601
assert(DI.getVariable()->isValidLocationForIntrinsic(
604602
MIRBuilder.getDebugLoc()) &&
605603
"Expected inlined-at fields to agree");
606-
607-
if (RegDef != MRI->def_instr_end() &&
608-
RegDef->getOpcode() == TargetOpcode::G_FRAME_INDEX) {
609-
MIRBuilder.buildFIDbgValue(RegDef->getOperand(1).getIndex(),
610-
DI.getVariable(), DI.getExpression());
604+
auto AI = dyn_cast<AllocaInst>(Address);
605+
if (AI && AI->isStaticAlloca()) {
606+
// Static allocas are tracked at the MF level, no need for DBG_VALUE
607+
// instructions (in fact, they get ignored if they *do* exist).
608+
MF->setVariableDbgInfo(DI.getVariable(), DI.getExpression(),
609+
getOrCreateFrameIndex(*AI), DI.getDebugLoc());
611610
} else
612-
MIRBuilder.buildDirectDbgValue(Reg, DI.getVariable(), DI.getExpression());
611+
MIRBuilder.buildDirectDbgValue(getOrCreateVReg(*Address),
612+
DI.getVariable(), DI.getExpression());
613613
return true;
614614
}
615615
case Intrinsic::vaend:

llvm/lib/CodeGen/MachineFunction.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ void MachineFunction::clear() {
169169
InstructionRecycler.clear(Allocator);
170170
OperandRecycler.clear(Allocator);
171171
BasicBlockRecycler.clear(Allocator);
172+
VariableDbgInfos.clear();
172173
if (RegInfo) {
173174
RegInfo->~MachineRegisterInfo();
174175
Allocator.Deallocate(RegInfo);

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
; RUN: llc -global-isel -mtriple=aarch64 %s -stop-after=irtranslator -o - | FileCheck %s
2-
2+
; RUN: llc -mtriple=aarch64 -global-isel --global-isel-abort=0 -o /dev/null
33

44
; CHECK-LABEL: name: debug_declare
5-
; CHECK: DBG_VALUE %stack.0.in.addr, 0, !11, !12, debug-location !13
5+
; CHECK: stack:
6+
; CHECK: - { id: {{.*}}, name: in.addr, offset: {{.*}}, size: {{.*}}, alignment: {{.*}}, di-variable: '!11',
7+
; CHECK-NEXT: di-expression: '!12', di-location: '!13' }
68
; CHECK: DBG_VALUE debug-use %0(s32), debug-use _, !11, !12, debug-location !13
79
define void @debug_declare(i32 %in) #0 !dbg !7 {
810
entry:
@@ -13,6 +15,15 @@ entry:
1315
ret void, !dbg !14
1416
}
1517

18+
; CHECK-LABEL: name: debug_declare_vla
19+
; CHECK: DBG_VALUE debug-use %{{[0-9]+}}(p0), debug-use _, !11, !12, debug-location !13
20+
define void @debug_declare_vla(i32 %in) #0 !dbg !7 {
21+
entry:
22+
%vla.addr = alloca i32, i32 %in
23+
call void @llvm.dbg.declare(metadata i32* %vla.addr, metadata !11, metadata !12), !dbg !13
24+
ret void, !dbg !14
25+
}
26+
1627
; CHECK-LABEL: name: debug_value
1728
; CHECK: [[IN:%[0-9]+]](s32) = COPY %w0
1829
define void @debug_value(i32 %in) #0 !dbg !7 {

0 commit comments

Comments
 (0)