From 5b0935f1f05c7aa9d315463c17ff85e7d846d237 Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Sun, 20 Jul 2025 10:59:50 +0200 Subject: [clang][bytecode] Reintroduce Pointer::elem() (#149693) As a way of writing atIndex(I).deref(), which creates an intermediate Pointer, which in turn adds (and removes) that pointer from the pointer list of the Block. This way we can avoid that. --- clang/lib/AST/ByteCode/Program.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'clang/lib/AST/ByteCode/Program.cpp') diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index 5ac0f59f32d4..af6d7c711062 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -74,27 +74,25 @@ unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) { const Pointer Ptr(G->block()); if (CharWidth == 1) { - std::memcpy(&Ptr.atIndex(0).deref(), S->getString().data(), - StringLength); + std::memcpy(&Ptr.elem(0), S->getString().data(), StringLength); } else { // Construct the string in storage. for (unsigned I = 0; I <= StringLength; ++I) { - Pointer Field = Ptr.atIndex(I); const uint32_t CodePoint = I == StringLength ? 0 : S->getCodeUnit(I); switch (CharType) { case PT_Sint8: { using T = PrimConv::T; - Field.deref() = T::from(CodePoint, BitWidth); + Ptr.elem(I) = T::from(CodePoint, BitWidth); break; } case PT_Uint16: { using T = PrimConv::T; - Field.deref() = T::from(CodePoint, BitWidth); + Ptr.elem(I) = T::from(CodePoint, BitWidth); break; } case PT_Uint32: { using T = PrimConv::T; - Field.deref() = T::from(CodePoint, BitWidth); + Ptr.elem(I) = T::from(CodePoint, BitWidth); break; } default: -- cgit v1.2.3 From e39ee62c5bdbe71b9f191bc5da7d47577e2099a9 Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Mon, 21 Jul 2025 17:16:13 +0200 Subject: [clang][bytecode] Use OptPrimType instead of std::optional (#149812) We use this construct a lot. Use something similar to clang's UnsignedOrNone. This results in some slighy compile time improvements: https://llvm-compile-time-tracker.com/compare.php?from=17a4b0399d161a3b89d8f0ce82add1638f23f5d4&to=a251d81ecd0ed45dd190462663155fdb303ef04d&stat=instructions:u --- clang/lib/AST/ByteCode/Program.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'clang/lib/AST/ByteCode/Program.cpp') diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index af6d7c711062..7002724a7a4f 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -169,7 +169,7 @@ unsigned Program::getOrCreateDummy(const DeclTy &D) { assert(!QT.isNull()); Descriptor *Desc; - if (std::optional T = Ctx.classify(QT)) + if (OptPrimType T = Ctx.classify(QT)) Desc = createDescriptor(D, *T, /*SourceTy=*/nullptr, std::nullopt, /*IsConst=*/QT.isConstQualified()); else @@ -248,7 +248,7 @@ std::optional Program::createGlobal(const DeclTy &D, QualType Ty, const bool IsConst = Ty.isConstQualified(); const bool IsTemporary = D.dyn_cast(); const bool IsVolatile = Ty.isVolatileQualified(); - if (std::optional T = Ctx.classify(Ty)) + if (OptPrimType T = Ctx.classify(Ty)) Desc = createDescriptor(D, *T, nullptr, Descriptor::GlobalMD, IsConst, IsTemporary, /*IsMutable=*/false, IsVolatile); else @@ -371,7 +371,7 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) { const bool IsMutable = FD->isMutable(); const bool IsVolatile = FT.isVolatileQualified(); const Descriptor *Desc; - if (std::optional T = Ctx.classify(FT)) { + if (OptPrimType T = Ctx.classify(FT)) { Desc = createDescriptor(FD, *T, nullptr, std::nullopt, IsConst, /*isTemporary=*/false, IsMutable, IsVolatile); } else { @@ -410,7 +410,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty, // Array of well-known bounds. if (const auto *CAT = dyn_cast(ArrayType)) { size_t NumElems = CAT->getZExtSize(); - if (std::optional T = Ctx.classify(ElemTy)) { + if (OptPrimType T = Ctx.classify(ElemTy)) { // Arrays of primitives. unsigned ElemSize = primSize(*T); if (std::numeric_limits::max() / ElemSize <= NumElems) { @@ -437,7 +437,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty, // is forbidden on pointers to such objects. if (isa(ArrayType) || isa(ArrayType)) { - if (std::optional T = Ctx.classify(ElemTy)) { + if (OptPrimType T = Ctx.classify(ElemTy)) { return allocateDescriptor(D, *T, MDSize, IsConst, IsTemporary, Descriptor::UnknownSize{}); } else { @@ -460,7 +460,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty, // Complex types - represented as arrays of elements. if (const auto *CT = Ty->getAs()) { - std::optional ElemTy = Ctx.classify(CT->getElementType()); + OptPrimType ElemTy = Ctx.classify(CT->getElementType()); if (!ElemTy) return nullptr; @@ -470,7 +470,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty, // Same with vector types. if (const auto *VT = Ty->getAs()) { - std::optional ElemTy = Ctx.classify(VT->getElementType()); + OptPrimType ElemTy = Ctx.classify(VT->getElementType()); if (!ElemTy) return nullptr; -- cgit v1.2.3