This is an archive of the discontinued LLVM Phabricator instance.

Refactor VariantMatcher::MatcherOps to reduce the amount of generated code.
ClosedPublic

Authored by sbenza on Aug 29 2014, 9:47 AM.

Details

Summary

Refactor VariantMatcher::MatcherOps to reduce the amount of generated code.

  • Make some code type agnostic and move it to the cpp file.
  • Return a DynTypedMatcher instead of storing the object in MatcherOps.

This change reduces the number of symbols generated in Registry.cpp by
~19%, the object byte size by ~17% and the compilation time (in non-release mode) by ~20%.

Diff Detail

Repository
rL LLVM

Event Timeline

sbenza updated this revision to Diff 13095.Aug 29 2014, 9:47 AM
sbenza retitled this revision from to Refactor VariantMatcher::MatcherOps to reduce the amount of generated code..
sbenza updated this object.
sbenza edited the test plan for this revision. (Show Details)
sbenza added a reviewer: klimek.
sbenza added a subscriber: Unknown Object (MLST).
sbenza updated this object.Aug 29 2014, 9:52 AM
klimek edited edge metadata.Aug 29 2014, 11:49 AM
  1. Using /bigobj doesn't seem to be controversial
  2. Can we make the compiler faster on this code?

I'm still not sure this is worth it. It seems to make the code harder to maintain.

"Needlessly". I don't think making code more complex is worth it. If we can
make the code simpler, I'd be all into it...

What is exactly the objection?
If it is the manual vtable, I can revert that part and still get most of the benefit. The big savings are from moving a bunch of code to the .cpp and making some methods non-virtual by using ASTNodeKind.

Yes, the manual vtable is the biggest issue.
Just for my curiosity - wouldn't it be much simpler to split up the registration into multiple files?

Simpler? I don't know.
What metric do we use for splitting them?

I'll update the diff without the vtable.

Split it up into 5 files should make each file 1/5th the size and 1/5th compile time? Split up more whenever we need? Generate the split TUs? That seems a better long term strategy than poking at the code (that is already borderline complex for my taste ;)

sbenza updated this revision to Diff 13108.Aug 29 2014, 2:14 PM
sbenza edited edge metadata.

Bring back the virtual functions.

sbenza updated this object.Aug 29 2014, 2:15 PM

Updated the numbers also.

klimek accepted this revision.Aug 31 2014, 5:51 AM
klimek edited edge metadata.

If you really think this is the right change, by all means, check it in. I'd just be excited if we found a different way to address the problem.

include/clang/ASTMatchers/Dynamic/VariantValue.h
126 ↗(On Diff #13108)

Is there a chance to get something out of this without handing around void*'s?

Have you tried splitting the registration up into multiple TUs, and what effect that has?

This revision is now accepted and ready to land.Aug 31 2014, 5:51 AM
sbenza added a comment.Sep 2 2014, 8:34 AM

I did try splitting it up. It doesn't scale much.
Each part contains duplicate template instantiations, so splitting in N pieces will not make each one 1/Nth of the total.
Tried 1-5 pieces. These are the results:

parts | # symbols | total

    |  per part | symbols
1   |    ~19k   |  ~19k
2   |    ~13k   |  ~26k
3   |    ~10k   |  ~30k
4   |    ~9k    |  ~36k
5   |    ~8k    |  ~40k

Note that I did not try to group similar matchers together (which would be a maintenance nightmare), so each part ends up instantiating most of the common templates for a lot (most?) of the node types.

+chandler

19k sounds like so little; why does it take so much time =[
Can we fix the compiler to make this fast then?

sbenza updated this revision to Diff 13172.Sep 2 2014, 10:50 AM
sbenza updated this object.
sbenza edited edge metadata.

Get rid of the void* arguments/return values. Use DynTypedMatcher instead.

sbenza updated this object.Sep 2 2014, 10:50 AM

Replaced the void* with DynTypedMatcher and it simplified the interface even more (and improved the numbers).
Updated the numbers in the description.

include/clang/ASTMatchers/Dynamic/VariantValue.h
126 ↗(On Diff #13108)

Removed the void* passing. Moved a little more logic to DynTypedMatcher instead.

klimek added a comment.Sep 3 2014, 7:01 AM

... and I still think we should fix the compiler...

lib/ASTMatchers/ASTMatchersInternal.cpp
29–37 ↗(On Diff #13172)

This needs a comment or two :)

sbenza updated this revision to Diff 13214.Sep 3 2014, 9:17 AM
sbenza updated this object.

Added comment and fixed up the variable names.

rnk added a subscriber: rnk.Sep 3 2014, 10:15 AM
In D5124#20, @klimek wrote:

+chandler

19k sounds like so little; why does it take so much time =[
Can we fix the compiler to make this fast then?

We can make it fast in release mode by optimizing away lots of cruft, but probably not in debug mode. You've asked the compiler to make many thousands of functions, and that's fundamentally really expensive.

I am not opposed to making the compiler faster, but I am not in a position to do that.

lib/ASTMatchers/ASTMatchersInternal.cpp
29–37 ↗(On Diff #13172)

Done.

sbenza closed this revision.Sep 4 2014, 7:23 AM
sbenza updated this revision to Diff 13263.

Closed by commit rL217152 (authored by @sbenza).