This is an archive of the discontinued LLVM Phabricator instance.

Use the frame index side table for byval and inalloca arguments
ClosedPublic

Authored by rnk on May 8 2017, 2:26 PM.

Details

Summary

For inalloca functions, this is a very common code pattern:

%argpack = type <{ i32, i32, i32 }>
define void @f(%argpack* inalloca %args) {
entry:
  %a = getelementptr inbounds %argpack, %argpack* %args, i32 0, i32 0
  %b = getelementptr inbounds %argpack, %argpack* %args, i32 0, i32 1
  %c = getelementptr inbounds %argpack, %argpack* %args, i32 0, i32 2
  tail call void @llvm.dbg.declare(metadata i32* %a, ... "a")
  tail call void @llvm.dbg.declare(metadata i32* %c, ... "b")
  tail call void @llvm.dbg.declare(metadata i32* %b, ... "c")

Even though these GEPs can be simplified to a constant offset from EBP
or RSP, we don't do that at -O0, and each GEP is computed into a
register. Registers used to compute argument addresses are typically
spilled and clobbered very quickly after the initial computation, so
live debug variable tracking loses information very quickly if we use
DBG_VALUE instructions.

This change moves processing of dbg.declare between argument lowering
and basic block isel, so that we can ask if an argument has a frame
index or not. If the argument lives in a register as is the case for
byval arguments on some targets, then we don't put it in the side table
and during ISel we emit DBG_VALUE instructions.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk created this revision.May 8 2017, 2:26 PM
aprantl accepted this revision.May 8 2017, 3:08 PM

This looks generally good (with outstanding comments addressed), thanks!

Is there a testcase for the example that you mention in the description?

Please keep a close eye on the green dragon bots, both the ones in the debuginfo-tests repository that execute as part of each check-clang, as well as the lldb testsuite, after landing this.

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
1183 ↗(On Diff #98208)

else if ?

llvm/test/CodeGen/X86/dbg-baseptr.ll
62 ↗(On Diff #98208)

please add the disassembly as a comment: (such as DW_OP_fbreg +16 )

llvm/test/DebugInfo/X86/dbg-declare-inalloca.ll
105 ↗(On Diff #98208)

We typically delete all unnecessary attributes from testcases.

This revision is now accepted and ready to land.May 8 2017, 3:08 PM
rnk marked 2 inline comments as done.May 8 2017, 4:31 PM

Is there a testcase for the example that you mention in the description?

The dbg-declare-inalloca.ll is a more real-world example of the case in the description. You need a non-trivially copyable argument to trigger inalloca.

Please keep a close eye on the green dragon bots, both the ones in the debuginfo-tests repository that execute as part of each check-clang, as well as the lldb testsuite, after landing this.

Sure!

llvm/test/CodeGen/X86/dbg-baseptr.ll
62 ↗(On Diff #98208)

I understand how this is supposed to work now. I added more CHECKs to ensure that this DWARF is consistent with the asm.

llvm/test/DebugInfo/X86/dbg-declare-inalloca.ll
105 ↗(On Diff #98208)

My intention is that the .ll is verbatim output from clang on the commented C++ at the beginning of the file. Is there any reason to treat reducing away attributes differently from the DI metadata, which is mostly retained below?

This revision was automatically updated to reflect the committed changes.
rnk marked an inline comment as done.
llvm/trunk/test/CodeGen/X86/2010-01-18-DbgValue.ll