This is an archive of the discontinued LLVM Phabricator instance.

DwarfDebug: Reduce duplication in addAccel*** methods
ClosedPublic

Authored by labath on Jul 19 2018, 5:49 AM.

Details

Summary

Each of the four methods had a dozen lines and was doing almost exactly
the same thing: get the appropriate accelerator table kind and insert an
entry into it. I move this common logic to a helper function and make
these methods delegate to it.

This came up in the context of D49493, where I've needed to make adding
a string to a string pool slightly more complicated, and it seemed to
make sense to do it in one place instead of five.

To make this work I've needed to unify the interface of the AccelTable
data types, as some used to store DIE& and others DIE*. I chose to unify
to a reference as that's what the caller uses.

This technically isn't NFC, because it changes the StringPool used for
apple tables in the DWO case (now it uses the main file like DWARF v5
instead of the DWO file). However, that shouldn't matter, as DWO is not
a thing on apple targets (clang frontend simply ignores -gsplit-dwarf).

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Jul 19 2018, 5:49 AM

This technically isn't NFC, because it changes the StringPool used for
apple tables in the DWO case (now it uses the main file like DWARF v5
instead of the DWO file). However, that shouldn't matter, as DWO is not
a thing on apple targets (clang frontend simply ignores -gsplit-dwarf).

In fact I would go as far as to say this makes things more correct. Back when apple tables were hooked up to -glldb, I tried to use them on linux with -gsplit-dwarf. The compilation broke because we couldn't perform the split step (it wanted to keep the apple tables in the main file, but they were linked to the debug_str.dwo section).

JDevlieghere accepted this revision.Jul 19 2018, 6:54 AM

LGTM. This is definitely much better!

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
2418 ↗(On Diff #156250)

I think I slightly prefer a switch here with an unreachable, so we have a NO-OP in case the default hasn't been resolved yet (instead or arbitrarily defaulting to DWARF).

This revision is now accepted and ready to land.Jul 19 2018, 6:54 AM
labath added inline comments.Jul 20 2018, 8:29 AM
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
2418 ↗(On Diff #156250)

I've changed this to a switch statement, but I wouldn't recommend relying on llvm_unreachable being a noop (compilers like to turn it into a trap instruction).

This revision was automatically updated to reflect the committed changes.