[PATCH] D76293: [WIP][DebugInfo] refactor DIE classes. Remove dependency on AsmPrinter.

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 17 09:38:10 PDT 2020


avl created this revision.
avl added reviewers: JDevlieghere, clayborg, dblaikie, aprantl.
avl added projects: LLVM, debug-info.
Herald added a subscriber: hiraditya.

Remove dependency of DWARF generation code on AsmPrinter.

This patch is not for integration. I want to consult whether it is going
in the right direction. It demonstrates the possible variant of refactoring.
Not all cases/problems are resolved in this patch currently.

During work on "Remove obsolete debug info in lld" I need to generate
DWARF without using AsmPrinter(To not to add extra libraries to lld).
The current implementation of DWARF generation is heavily depends on
using AsmPrinter. F.e. CodeGen/DIE.h

class DIEInteger {

  void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const;
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;

}

I think it would be a bad idea to write a new set of DWARF generating
classes, not depending on AsmPrinter. Instead, it would be better
to reduce dependence on AsmPrinter for current structures.
It would allow for reusing existed implementation.

There is already a place which implements such separation :

AsmPrinter/ByteStreamer.h:ByteStreamer
AsmPrinter/DwarfDebug.h:DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer)

But it is used locally. I think the same idea could be implemented
in a more general way:

There should be a class that allows writing byte data in the dwarf section: DwarfDebugSection.
DwarfDebugSection would have two descendands: DwarfDebugSectionAsm, DwarfDebugSectionBin.
There should be a class that allows writing DWARF constructions(units, line tables,
address ranges) to DwarfDebugSection: DwarfDebugFile.
DIE* classes from CodeGen/DIE.h should be moved into DebugInfoDWARF library.
DwarfDebugSection & DwarfDebugFile should be put into DebugInfoDWARF library.
In a far perspective: DwarfDebugFile could replace AsmPrinter/DwarfFile,
other classes would be moved into DebugInfoDWARF library(DwarfStringPool...).
The above changes would allow generating DWARF without AsmPrinter.
Also, this implementation could probably be reused by debug info tools(dsymutil,
llvm-gsymutil, llvm-dwp...).

This patch presents some changes which show the direction of the refactoring.

What do you think? Would this refactoring be useful?
Is it OK to do things in this manner?

If that idea is OK, then changes could be done incrementally,
moving code(currently located in AsmPrinter) into DebugInfoDWARF library.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76293

Files:
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/CodeGen/DIE.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFile.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFDebugSection.h
  llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
  llvm/lib/CodeGen/AsmPrinter/DIE.cpp
  llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76293.250796.patch
Type: text/x-patch
Size: 53753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200317/c15a9431/attachment.bin>


More information about the llvm-commits mailing list