Skip to content

Commit 02ade22

Browse files
authored
[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%.
1 parent 5d774ec commit 02ade22

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

clang/lib/AST/ByteCode/EvalEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) {
184184
return true;
185185

186186
using T = typename PrimConv<OpType>::T;
187-
EvalResult.setValue(S.Stk.pop<T>().toAPValue(Ctx.getASTContext()));
187+
EvalResult.takeValue(S.Stk.pop<T>().toAPValue(Ctx.getASTContext()));
188188
return true;
189189
}
190190

@@ -195,7 +195,7 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
195195
const Pointer &Ptr = S.Stk.pop<Pointer>();
196196

197197
if (Ptr.isFunctionPointer()) {
198-
EvalResult.setValue(Ptr.toAPValue(Ctx.getASTContext()));
198+
EvalResult.takeValue(Ptr.toAPValue(Ctx.getASTContext()));
199199
return true;
200200
}
201201

@@ -224,7 +224,7 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
224224

225225
if (std::optional<APValue> V =
226226
Ptr.toRValue(Ctx, EvalResult.getSourceType())) {
227-
EvalResult.setValue(*V);
227+
EvalResult.takeValue(std::move(*V));
228228
} else {
229229
return false;
230230
}
@@ -233,14 +233,14 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
233233
// the result, even if the pointer is dead.
234234
// This will later be diagnosed by CheckLValueConstantExpression.
235235
if (Ptr.isBlockPointer() && !Ptr.block()->isStatic()) {
236-
EvalResult.setValue(Ptr.toAPValue(Ctx.getASTContext()));
236+
EvalResult.takeValue(Ptr.toAPValue(Ctx.getASTContext()));
237237
return true;
238238
}
239239

240240
if (!Ptr.isLive() && !Ptr.isTemporary())
241241
return false;
242242

243-
EvalResult.setValue(Ptr.toAPValue(Ctx.getASTContext()));
243+
EvalResult.takeValue(Ptr.toAPValue(Ctx.getASTContext()));
244244
}
245245

246246
return true;
@@ -261,7 +261,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
261261

262262
if (std::optional<APValue> APV =
263263
Ptr.toRValue(S.getASTContext(), EvalResult.getSourceType())) {
264-
EvalResult.setValue(*APV);
264+
EvalResult.takeValue(std::move(*APV));
265265
return true;
266266
}
267267

clang/lib/AST/ByteCode/EvaluationResult.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class EvaluationResult final {
5555

5656
void setSource(DeclTy D) { Source = D; }
5757

58-
void setValue(const APValue &V) {
58+
void takeValue(APValue &&V) {
5959
// V could still be an LValue.
6060
assert(empty());
6161
Value = std::move(V);

0 commit comments

Comments
 (0)