Skip to content

Commit b36e161

Browse files
authored
[clang][bytecode][NFC] Cache more integer type sizes (#142720)
1 parent 4e4273c commit b36e161

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/AST/ByteCode/Context.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ using namespace clang;
2222
using namespace clang::interp;
2323

2424
Context::Context(ASTContext &Ctx) : Ctx(Ctx), P(new Program(*this)) {
25+
this->ShortWidth = Ctx.getTargetInfo().getShortWidth();
2526
this->IntWidth = Ctx.getTargetInfo().getIntWidth();
2627
this->LongWidth = Ctx.getTargetInfo().getLongWidth();
28+
this->LongLongWidth = Ctx.getTargetInfo().getLongLongWidth();
2729
assert(Ctx.getTargetInfo().getCharWidth() == 8 &&
2830
"We're assuming 8 bit chars");
2931
}
@@ -265,6 +267,11 @@ std::optional<PrimType> Context::classify(QualType T) const {
265267
return PT_MemberPtr;
266268

267269
// Just trying to avoid the ASTContext::getIntWidth call below.
270+
if (Kind == BuiltinType::Short)
271+
return integralTypeToPrimTypeS(this->ShortWidth);
272+
if (Kind == BuiltinType::UShort)
273+
return integralTypeToPrimTypeU(this->ShortWidth);
274+
268275
if (Kind == BuiltinType::Int)
269276
return integralTypeToPrimTypeS(this->IntWidth);
270277
if (Kind == BuiltinType::UInt)
@@ -273,6 +280,11 @@ std::optional<PrimType> Context::classify(QualType T) const {
273280
return integralTypeToPrimTypeS(this->LongWidth);
274281
if (Kind == BuiltinType::ULong)
275282
return integralTypeToPrimTypeU(this->LongWidth);
283+
if (Kind == BuiltinType::LongLong)
284+
return integralTypeToPrimTypeS(this->LongLongWidth);
285+
if (Kind == BuiltinType::ULongLong)
286+
return integralTypeToPrimTypeU(this->LongLongWidth);
287+
276288
if (Kind == BuiltinType::SChar || Kind == BuiltinType::Char_S)
277289
return integralTypeToPrimTypeS(8);
278290
if (Kind == BuiltinType::UChar || Kind == BuiltinType::Char_U ||

clang/lib/AST/ByteCode/Context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ class Context final {
138138
/// ID identifying an evaluation.
139139
unsigned EvalID = 0;
140140
/// Cached widths (in bits) of common types, for a faster classify().
141+
unsigned ShortWidth;
141142
unsigned IntWidth;
142143
unsigned LongWidth;
144+
unsigned LongLongWidth;
143145
};
144146

145147
} // namespace interp

0 commit comments

Comments
 (0)