This is an archive of the discontinued LLVM Phabricator instance.

[AST] Pack BinaryOperator
ClosedPublic

Authored by riccibruno on Nov 14 2018, 6:25 AM.

Details

Summary

Use the newly available space in the bit-fields of Stmt.
This saves 8 bytes per BinaryOperator.

Diff Detail

Repository
rC Clang

Event Timeline

riccibruno created this revision.Nov 14 2018, 6:25 AM
dblaikie accepted this revision.Nov 14 2018, 12:49 PM

Looks good - thanks! just a few things that could be cleaned up.

include/clang/AST/Expr.h
3220–3222

Lost LLVM_READONLY somewhere along the way? Should it be added back in?

3256–3261

I probably wouldn't add a new public member function here - I take it you added that to avoid calling getOpcode() twice? (either for performance or textual/source tersity?)

Calling it twice probably is OK for both performance and readability - but if you prefer otherwise, I guess you could do it with a temporary:

bool isPetrMemOp() const {
  auto Opc = getOpcode();
  return Opc == ... ;
}
3369–3375

Could do these two (& some of the other "refactor to use a common accessor, because the accessor is getting a bit more interesting") changes as NFC cleanup before this - but no big deal, just mention it in case in other/future changes that makes sense for you.

This revision is now accepted and ready to land.Nov 14 2018, 12:49 PM
dblaikie added inline comments.Nov 14 2018, 12:51 PM
include/clang/AST/Stmt.h
572

Oh, just a thought - wonder if we could/should have an assert that this anonymous union doesn't grow beyond a certain intended size? (can we have such an assert? I'm not sure how to test the size of an anonymous union - I guess we could static_assert the size of the whole Stmt class, though that'd be a bit brittle)

riccibruno marked an inline comment as done.Nov 14 2018, 1:55 PM

Added some inline comments.

include/clang/AST/Expr.h
3220–3222

On purpose. LLVM_READONLY on a simple getter seems pointless,
since the compiler is just going to inline it.

3259

I added it for consistency with the other similar function below.
isPtrMemOp is the only one without the pattern of having
a static member function and a member function calling it.
I would not expect this to matter for performance since the compiler
is just going to see right through the getOpcode call.

include/clang/AST/Stmt.h
572

Already done in line 657 below. And yes it is a valid concern !
When I did the same thing for the types hierarchy I spotted
that the bit-field class FunctionTypeBitfields was taking more
than 32 bits accidentally. (fixed since) Oops.

riccibruno marked 6 inline comments as done.Nov 15 2018, 5:41 AM

Marked the inline comments as done since I believe I
answered each of them. If not I can fix it in a subsequent commit.

This revision was automatically updated to reflect the committed changes.