Author: Timm Baeder Date: 2025-08-28T08:46:06+02:00 New Revision: 02ade22aa824597b31c1eaaa041830ff54e5b71c
URL: https://github.com/llvm/llvm-project/commit/02ade22aa824597b31c1eaaa041830ff54e5b71c DIFF: https://github.com/llvm/llvm-project/commit/02ade22aa824597b31c1eaaa041830ff54e5b71c.diff LOG: [clang][bytecode] Avoid copying APValue into EvaluationResult (#155757) Move the `APValue` into `EvaluationResult` instead. For a large primitive array (`#embed` of the sqlite3 amalgamation), this improves compile times by around 25%. Added: Modified: clang/lib/AST/ByteCode/EvalEmitter.cpp clang/lib/AST/ByteCode/EvaluationResult.h Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index 1ebadae811bdf..2860a09ae6e2d 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -184,7 +184,7 @@ template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) { return true; using T = typename PrimConv<OpType>::T; - EvalResult.setValue(S.Stk.pop<T>().toAPValue(Ctx.getASTContext())); + EvalResult.takeValue(S.Stk.pop<T>().toAPValue(Ctx.getASTContext())); return true; } @@ -195,7 +195,7 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) { const Pointer &Ptr = S.Stk.pop<Pointer>(); if (Ptr.isFunctionPointer()) { - EvalResult.setValue(Ptr.toAPValue(Ctx.getASTContext())); + EvalResult.takeValue(Ptr.toAPValue(Ctx.getASTContext())); return true; } @@ -224,7 +224,7 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) { if (std::optional<APValue> V = Ptr.toRValue(Ctx, EvalResult.getSourceType())) { - EvalResult.setValue(*V); + EvalResult.takeValue(std::move(*V)); } else { return false; } @@ -233,14 +233,14 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) { // the result, even if the pointer is dead. // This will later be diagnosed by CheckLValueConstantExpression. if (Ptr.isBlockPointer() && !Ptr.block()->isStatic()) { - EvalResult.setValue(Ptr.toAPValue(Ctx.getASTContext())); + EvalResult.takeValue(Ptr.toAPValue(Ctx.getASTContext())); return true; } if (!Ptr.isLive() && !Ptr.isTemporary()) return false; - EvalResult.setValue(Ptr.toAPValue(Ctx.getASTContext())); + EvalResult.takeValue(Ptr.toAPValue(Ctx.getASTContext())); } return true; @@ -261,7 +261,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) { if (std::optional<APValue> APV = Ptr.toRValue(S.getASTContext(), EvalResult.getSourceType())) { - EvalResult.setValue(*APV); + EvalResult.takeValue(std::move(*APV)); return true; } diff --git a/clang/lib/AST/ByteCode/EvaluationResult.h b/clang/lib/AST/ByteCode/EvaluationResult.h index 3b6c65eff1ef8..49a3e5c00eea3 100644 --- a/clang/lib/AST/ByteCode/EvaluationResult.h +++ b/clang/lib/AST/ByteCode/EvaluationResult.h @@ -55,7 +55,7 @@ class EvaluationResult final { void setSource(DeclTy D) { Source = D; } - void setValue(const APValue &V) { + void takeValue(APValue &&V) { // V could still be an LValue. assert(empty()); Value = std::move(V); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
