[clang] [clang][bytecode][NFC] Cache more integer type sizes (PR #142720)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 3 22:49:07 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/142720
More information about the cfe-commits
mailing list