This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Improve stack slot tracking in dbg.values
ClosedPublic

Authored by fdeazeve on Apr 4 2023, 7:42 AM.

Details

Summary

For IR like:

%alloca = alloca ...
dbg.value(%alloca, !myvar, OP_deref(<other_ops>))

GlobalISel lowers it to MIR:

%some_reg = G_FRAME_INDEX <stack_slot>
DBG_VALUE %some_reg, !myvar, OP_deref(<other_ops>)

In other words, if the value of !myvar can be obtained by
dereferencing an alloca, in MIR we say that the _location_ of a variable
is obtained by dereferencing register %some_reg (plus some
<other_ops>).

We can instead remove the use of %some_reg: the location of !myvar
_is_ <stack_slot> (plus some <other_ops>). This patch implements
this transformation, which improves debug information handling in O0, as
these registers hardly ever survive register allocation.

A note about testing: similar to what was done in D76934
(f24e2e9eebde4b7a1d), this patch exposed a bug in the Builder class when
using -debug, where we tried to print an incomplete instruction. The
changes in MachineIRBuilder.cpp address that.

Diff Detail

Event Timeline

fdeazeve created this revision.Apr 4 2023, 7:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 7:42 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
fdeazeve requested review of this revision.Apr 4 2023, 7:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2023, 7:42 AM
fdeazeve added inline comments.
llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll
41

what is this meaning of this dbg.value with 4 arguments? I can't find it anywhere in the docs

aprantl accepted this revision.Apr 4 2023, 10:23 AM
This revision is now accepted and ready to land.Apr 4 2023, 10:23 AM
aprantl added inline comments.Apr 4 2023, 10:24 AM
llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll
40

Can you update the test to not hardcode !17, !18?

41

This is an old form of dbg.value with an offset field. Let's update this to the 3 argument form by dropping it.

This revision was automatically updated to reflect the committed changes.

I'll submit a separate patch for the test cleanup