This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Simplify COMDAT handling.
ClosedPublic

Authored by ruiu on Mar 1 2018, 1:24 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu created this revision.Mar 1 2018, 1:24 PM
ruiu updated this revision to Diff 136593.Mar 1 2018, 1:27 PM
  • simplify addComdat's return type
sbc100 added a subscriber: ncw.Mar 1 2018, 1:42 PM

Interesting.. I guess it works. Adding @ncw who wrote this code.

sbc100 added a reviewer: ncw.Mar 1 2018, 1:42 PM
ruiu added a comment.Mar 1 2018, 1:51 PM

If I understand the existing code correctly, the new code should do exactly the same as before, with less number of hash table lookups.

ncw accepted this revision.Mar 1 2018, 2:08 PM

In my queue of about ~20 patches still to submit, I have got one similar to this! In fact it was discussed a while back in some comments on another issue; I've just built up a big backlog while the symbol table stuff was being worked on.

It's actually possible to optimise it even more; my patch involves editing the BinaryFormat/Wasm.h structures to go from struct Function { ... StringRef Comdat } to struct Function { int Comdat; }.

Then change the loop to for (Comdat : File->Comdats()) { if (add(Comdat)) markComdatIndex(Comdat); }. Then, you only do a hashtable lookup once per Comdat, rather than (in your case) once per symbol, which should be a bit of a saving for a typical inline function comdat that might have some strings or other data in the comdat as well.

I'm happy for this to go in, it's in the right direction I think.

This revision is now accepted and ready to land.Mar 1 2018, 2:08 PM
ruiu added a comment.Mar 1 2018, 2:18 PM

I think that's a right direction, though that should be done as a separate patch after this.

Your change needs to change llvm/lib/Object/WasmObjectFile.cpp right? One thing I noticed there is that WasmObjectFile::parseLinkingSectionComdat does an expensive test using a set. I don't think that's we want check for name uniqueness in WasmObjectFile.cpp, as it should be a lightweight wrapper to read object files as quickly as possible.

This revision was automatically updated to reflect the committed changes.
ncw added a comment.Mar 2 2018, 1:35 AM

I think that's a right direction, though that should be done as a separate patch after this.

Your change needs to change llvm/lib/Object/WasmObjectFile.cpp right? One thing I noticed there is that WasmObjectFile::parseLinkingSectionComdat does an expensive test using a set. I don't think that's we want check for name uniqueness in WasmObjectFile.cpp, as it should be a lightweight wrapper to read object files as quickly as possible.

Good point, I can look into getting rid of that at the same time, when I get to submitting that patch.

By the way, I didn't mean to be rude, my last comment might have sounded like "I've done this already and my way's better". I just meant to say what I was working on, for comparison. I think it's great by the way you're working on Wasm-LLD; when Wasm came along was it maybe someone else's idea/initiative? It's good of you to make time in your schedule to work on the Wasm toolchain if you're not using it yourself!