DebugInfo: Do not emit empty CUs
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 26 May 2017 18:52:56 +0000 (18:52 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 26 May 2017 18:52:56 +0000 (18:52 +0000)
commit07963bd1d194af32a3065b170084da94ae8ec090
treef546d1cd26cb9419ab49ef0a4f22af74d0e07481
parent7730b244480c4a2b12dc3bff9892bb989f8b3e9c
DebugInfo: Do not emit empty CUs

Consistent with GCC and addresses a shortcoming with ThinLTO where many
imported CUs may end up being empty (because the functions imported from
them either ended up not being used (and were then discarded, since
they're imported as available_externally) or optimized away entirely).

Test cases previously testing empty CUs (either intentionally, or
because they didn't need anything more complicated) had a trivial 'int'
or similar basic type added to their retained types list.

This is a first order approximation - a deeper implementation could do
things like:

1) Be more lazy about construction of the CU - for example if two CUs
containing a single identical retained type are linked together, with
this change one of the two CUs will be produced but empty (since a
duplicate type won't be produced).

2) Go further and invert all the CU links the same way the subprogram
link is inverted - keep named CU lists of retained types, macros, etc,
and have those link back to the CU. Then if they're emitted, the CU is
emitted, but never otherwise - this would allow the metadata itself to
be dropped earlier too, though it seems unlikely that's an important
optimization as there shouldn't be many CUs relative to the number of
other entities.

llvm-svn: 304020
14 files changed:
llvm/include/llvm/IR/Metadata.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/test/DebugInfo/Generic/empty.ll
llvm/test/DebugInfo/Generic/nodebug.ll
llvm/test/DebugInfo/Generic/skeletoncu.ll
llvm/test/DebugInfo/X86/debug-loc-offset.ll
llvm/test/DebugInfo/X86/debug-macro.ll
llvm/test/DebugInfo/X86/empty.ll
llvm/test/DebugInfo/X86/fission-hash.ll
llvm/test/DebugInfo/X86/gnu-public-names-empty.ll
llvm/test/DebugInfo/dwo.ll
llvm/test/DebugInfo/omit-empty.ll [new file with mode: 0644]
llvm/test/DebugInfo/skeletoncu.ll