This is an archive of the discontinued LLVM Phabricator instance.

[DWARF] - Cleanup relocation handling.
AbandonedPublic

Authored by grimar on May 25 2017, 5:51 AM.

Details

Summary

Current version of Dwarf parser uses object::RelocVisitor for applying relocations.
And do that in a bit wierd way. It creates object::RelocVisitor object
for each relocation, though could do it once for file and reduce amount of checks, which
now happens because of visit() function that still check file type on each call and then
chooses which arch to use in a huge single method with use of lots helper function.

I was interested would it be any benefit if we change code to select proper architecture
and file type once during visitor creation. And implemented it for ELF x86_64 in this patch.

Numbers for me are 16,5909 ( +- 0,16% ) vs 16,3406 ( +- 0,19% ) for 25 runs of linking
llc binary with lld and -gdb-index. Difference is not much: 1,015, or up to 1% it seems for total link time.

Though this approach helps to split huge method and cleanup implementation.
Interesting what other thinks about that.

Diff Detail

Event Timeline

grimar created this revision.May 25 2017, 5:51 AM
grimar edited the summary of this revision. (Show Details)May 25 2017, 6:05 AM
dblaikie added inline comments.May 25 2017, 10:47 AM
include/llvm/Object/RelocVisitor.h
53

Have you/could you try keeping the selection here, but using a switch over ObjToVisit.getType() rather than the if/else chain? (maybe that'll be easy enough to optimize & tidy things up rather than having to have the indirection through a function pointer.

ruiu added a subscriber: ruiu.May 25 2017, 4:46 PM

I think what we should do to tidy this class up is to remove a lot of visitELF_<ARCH> functions and inline them. Splitting into small function is usually good, but in this case it went too far.

grimar updated this revision to Diff 100417.May 26 2017, 8:43 AM
  • Addressed review comments.
  • Rebased.
include/llvm/Object/RelocVisitor.h
53

Rui did a great cleenup here and it is looks much easier to avoid check of file type and target type on each relocation.
It just looks a bit wierd as obviously a useless job.

ruiu added inline comments.May 26 2017, 8:48 AM
include/llvm/Object/RelocVisitor.h
62

Why don't you use std::function?

grimar added inline comments.May 26 2017, 8:53 AM
include/llvm/Object/RelocVisitor.h
62

I am pretty sure I was asked by somebody to use poiner in one of reviews earlier, do not really remember why, so
I supposed it is preferred in LLVM before your comment, though it looks std::function is used widely. So I can switch to it.

ruiu added inline comments.May 26 2017, 8:56 AM
include/llvm/Object/RelocVisitor.h
62

Well, maybe a bare pointer is smaller and faster than std::function, I guess? I'd guess David Blaikie knows more than me about that.

grimar abandoned this revision.Aug 3 2017, 4:38 AM

Irrelevant.