-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang][NFC] Increase NumStmtBits by 2 as we are approaching the limit #120341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Ziqing Luo (ziqingluo-90) ChangesWe have already hit the limit of NumStmtBits downstream after 010d011, which adds 4 new StmtNodes. Full diff: https://github.com/llvm/llvm-project/pull/120341.diff 1 Files Affected:
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 83fafbabb1d460..4d02b122c5e858 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -109,6 +109,18 @@ class alignas(void *) Stmt {
//===--- Statement bitfields classes ---===//
+ enum { NumStmtBits = 10 };
+
+#define STMT(CLASS, PARENT)
+#define STMT_RANGE(BASE, FIRST, LAST)
+#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
+ static_assert( \
+ StmtClass::LAST##Class < (1 << NumStmtBits), \
+ "The number of 'StmtClass'es is strictly bounded under two to " \
+ "the power of 'NumStmtBits'");
+#define ABSTRACT_STMT(STMT)
+#include "clang/AST/StmtNodes.inc"
+
class StmtBitfields {
friend class ASTStmtReader;
friend class ASTStmtWriter;
@@ -116,9 +128,8 @@ class alignas(void *) Stmt {
/// The statement class.
LLVM_PREFERRED_TYPE(StmtClass)
- unsigned sClass : 8;
+ unsigned sClass : NumStmtBits;
};
- enum { NumStmtBits = 8 };
class NullStmtBitfields {
friend class ASTStmtReader;
@@ -564,8 +575,8 @@ class alignas(void *) Stmt {
/// True if the call expression is a must-elide call to a coroutine.
unsigned IsCoroElideSafe : 1;
- /// Padding used to align OffsetToTrailingObjects to a byte multiple.
- unsigned : 24 - 4 - NumExprBits;
+ static_assert(NumExprBits == 20,
+ "No extra padding needed when NumExprBits is exactly 20.");
/// The offset in bytes from the this pointer to the start of the
/// trailing objects belonging to CallExpr. Intentionally byte sized
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just increase to 9 bits.
Have you checked whether the size of Stmt
or Expr
changes when you do this?
I have these concerns as well, this ends up affecting the size of a lot of things.... That said, StmtNodes.td already has 267 items in it (as far as I can tell, just a wc -l on appearances of 'def'). So I don't know how we're getting away with this already. Can you confirm how many are present currently? I also think 9 should be plenty, 512 should cover us for many many years. |
I THINK I just tracked down that our current max is ~249, and I intend to add a few more for OpenACC, so this would cause us to exceed the limit, even without a downstream. Additionally, Reflection is likely to add a few, as will contracts, so even without OpenACC, we'd continue to exceed the limit. I'd like to see some level of analysis of what we're paying for this increase, and whether we can 'get it back' elsewhere (some of our bitfields have padding we could perhaps steal, or some too-large-but-nothing-better-needs-the-bits fields), so we should make sure we minimize the sizeof our important things. Perhaps some level of "print sizeof every AST node before and after" could be done, and compared? |
quick way to find those cases:
|
We have already hit the limit of NumStmtBits downstream after 010d011, which adds 4 new StmtNodes. (rdar://141555357)
6cb8ccb
to
6947710
Compare
@rjmccall I've changed it to 9 bits and checked that |
I think checking just those two isn't sufficient, as this is used as a 'base' type for a few other types. We probably need to ensure that other types that use bitfields don't have this problem as well. Basically any of the other bitfield types here that implicitly use |
The way this works is that all of these class-specific bitfields are union'ed into a single field in |
OH! I see! I misremembered how this works. Disregard the above then. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wait a little while to give the others a chance to approve this version before committing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but yeah, please give some time for the other early reviewers to sign off as well.
FYI it looks like this has a fairly large impact on compile-time, esp at I wonder whether this is due to some increase in structure sizes, or because the choice of a non power of two bitwidth makes the accesses to the field inefficient. |
"The number of 'StmtClass'es is strictly bounded under two to " \ | ||
"the power of 'NumStmtBits'"); | ||
#define ABSTRACT_STMT(STMT) | ||
#include "clang/AST/StmtNodes.inc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how much of the (clang bootstrap) build time overhead comes from this, but this seems like the kind of assertion that should be in a source file, not a header.
It probably is the bit-width not matching a native integer size. If we want to get that back, we'll need to Huffman-encode Computing the actual auto kind = node->basicKind; // 8-bit load
if (kind == 255)
kind += node->extendedKind; // 8-bit load But We should be able to make |
…urce A follow-up change to PR #120341 & #120643. Address @nikic's concern: #120341 (comment)
…eader to source A follow-up change to PR #120341 & #120643. Address @nikic's concern: llvm/llvm-project#120341 (comment)
We have already hit the limit of NumStmtBits downstream after 010d011, which adds 4 new StmtNodes.