Add MIR-level debugify with only locations support for now
authorDaniel Sanders <daniel_l_sanders@apple.com>
Fri, 3 Apr 2020 23:18:45 +0000 (16:18 -0700)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Tue, 7 Apr 2020 23:25:13 +0000 (16:25 -0700)
commit1adeeabb79afbe966a45050f07e0bd6f446f8aa6
treef94637cb4e80d29d6e09ba71a7f9e2184af03b15
parent624654fd647057dd6c1cdf8799a7605b69716a02
Add MIR-level debugify with only locations support for now

Summary:
Re-used the IR-level debugify for the most part. The MIR-level code then
adds locations to the MachineInstrs afterwards based on the LLVM-IR debug
info.

It's worth mentioning that the resulting locations make little sense as
the range of line numbers used in a Function at the MIR level exceeds that
of the equivelent IR level function. As such, MachineInstrs can appear to
originate from outside the subprogram scope (and from other subprogram
scopes). However, it doesn't seem worth worrying about as the source is
imaginary anyway.

There's a few high level goals this pass works towards:
* We should be able to debugify our .ll/.mir in the lit tests without
  changing the checks and still pass them. I.e. Debug info should not change
  codegen. Combining this with a strip-debug pass should enable this. The
  main issue I ran into without the strip-debug pass was instructions with MMO's and
  checks on both the instruction and the MMO as the debug-location is
  between them. I currently have a simple hack in the MIRPrinter to
  resolve that but the more general solution is a proper strip-debug pass.
* We should be able to test that GlobalISel does not lose debug info. I
  recently found that the legalizer can be unexpectedly lossy in seemingly
  simple cases (e.g. expanding one instr into many). I have a verifier
  (will be posted separately) that can be integrated with passes that use
  the observer interface and will catch location loss (it does not verify
  correctness, just that there's zero lossage). It is a little conservative
  as the line-0 locations that arise from conflicts do not track the
  conflicting locations but it can still catch a fair bit.

Depends on D77439, D77438

Reviewers: aprantl, bogner, vsk

Subscribers: mgorny, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77446
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/Transforms/Utils/Debugify.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/MachineDebugify.cpp [new file with mode: 0644]
llvm/lib/Transforms/Utils/Debugify.cpp
llvm/test/CodeGen/Generic/MIRDebugify/locations.mir [new file with mode: 0644]