[PATCH] D158675: [NFC][AsmPrinter] Refactor DbgVariable as a std::variant

Scott Linder via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 15:40:38 PDT 2023


scott.linder created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
scott.linder requested review of this revision.
Herald added subscribers: llvm-commits, wangpc.
Herald added a project: LLVM.

Only a subset of the fields of DbgVariable are meaningful at any time,
and some fields are re-used for multiple purposes (for example
FrameIndexExprs is used with a throw-away frame-index of 0 to hold a
single DIExpression without needing to add another member). The exact
invariants must be reverse-engineered by inspecting the actual use of
the class, its imprecise/outdated doc-comment, and some asserts.

Refactor DbgVariable into a sum type by inheriting from std::variant.
This makes the active fields for any given state explicit and removes
the need to re-use fields in disparate contexts. As a bonus, it seems to
reduce the size on my x86_64 linux box from 144 bytes to 96 bytes.

There is some potential cost to `std::get` as it must check the active
alternative even when context or an assert obviates it. To try to help
ensure the compiler can optimize out the checks the patch also adds a
helper `get` method which uses the noexcept `std::get_if`.

Some of the extra cost would also be avoided more cleanly with a
refactor that exposes the alternative types in the public interface,
which will come in another patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158675

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158675.552906.patch
Type: text/x-patch
Size: 15367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230823/570a858b/attachment.bin>


More information about the llvm-commits mailing list