[GlobalISel] Improve stack slot tracking in dbg.values
authorFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Tue, 4 Apr 2023 13:35:23 +0000 (09:35 -0400)
committerFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Wed, 5 Apr 2023 12:21:00 +0000 (08:21 -0400)
commit79a1e32915631469b4ea50c0e00ccd7ecc828d00
tree9e8550b56a317e3b484ba8ddca8271071e635c26
parent0d022e7d1ff94aaf51e8ac1cea9ce0b827c92814
[GlobalISel] Improve stack slot tracking in dbg.values

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.

Differential Revision: https://reviews.llvm.org/D147536
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
llvm/test/CodeGen/AArch64/GlobalISel/debug-insts.ll