Skip to content

[clang][bytecode][NFC] Cache more integer type sizes #142720

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

Merged
merged 1 commit into from
Jun 4, 2025

Conversation

tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Jun 4, 2025

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Jun 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 4, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/142720.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Context.cpp (+12)
  • (modified) clang/lib/AST/ByteCode/Context.h (+2)
diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp
index 6b8f4e31e4ff9..d73705b6126fe 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -22,8 +22,10 @@ using namespace clang;
 using namespace clang::interp;
 
 Context::Context(ASTContext &Ctx) : Ctx(Ctx), P(new Program(*this)) {
+  this->ShortWidth = Ctx.getTargetInfo().getShortWidth();
   this->IntWidth = Ctx.getTargetInfo().getIntWidth();
   this->LongWidth = Ctx.getTargetInfo().getLongWidth();
+  this->LongLongWidth = Ctx.getTargetInfo().getLongLongWidth();
   assert(Ctx.getTargetInfo().getCharWidth() == 8 &&
          "We're assuming 8 bit chars");
 }
@@ -265,6 +267,11 @@ std::optional<PrimType> Context::classify(QualType T) const {
       return PT_MemberPtr;
 
     // Just trying to avoid the ASTContext::getIntWidth call below.
+    if (Kind == BuiltinType::Short)
+      return integralTypeToPrimTypeS(this->ShortWidth);
+    if (Kind == BuiltinType::UShort)
+      return integralTypeToPrimTypeU(this->ShortWidth);
+
     if (Kind == BuiltinType::Int)
       return integralTypeToPrimTypeS(this->IntWidth);
     if (Kind == BuiltinType::UInt)
@@ -273,6 +280,11 @@ std::optional<PrimType> Context::classify(QualType T) const {
       return integralTypeToPrimTypeS(this->LongWidth);
     if (Kind == BuiltinType::ULong)
       return integralTypeToPrimTypeU(this->LongWidth);
+    if (Kind == BuiltinType::LongLong)
+      return integralTypeToPrimTypeS(this->LongLongWidth);
+    if (Kind == BuiltinType::ULongLong)
+      return integralTypeToPrimTypeU(this->LongLongWidth);
+
     if (Kind == BuiltinType::SChar || Kind == BuiltinType::Char_S)
       return integralTypeToPrimTypeS(8);
     if (Kind == BuiltinType::UChar || Kind == BuiltinType::Char_U ||
diff --git a/clang/lib/AST/ByteCode/Context.h b/clang/lib/AST/ByteCode/Context.h
index 9a604ce8ebbe9..5898ab5e54599 100644
--- a/clang/lib/AST/ByteCode/Context.h
+++ b/clang/lib/AST/ByteCode/Context.h
@@ -138,8 +138,10 @@ class Context final {
   /// ID identifying an evaluation.
   unsigned EvalID = 0;
   /// Cached widths (in bits) of common types, for a faster classify().
+  unsigned ShortWidth;
   unsigned IntWidth;
   unsigned LongWidth;
+  unsigned LongLongWidth;
 };
 
 } // namespace interp

@tbaederr tbaederr merged commit b36e161 into llvm:main Jun 4, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants