[clang] [clang][bytecode][NFC] Avoid re-evaluating APValue base expressions (PR #237133)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 30 00:56:42 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
If we already have a global variable created for the apvalue lvalue base expression, just get the pointer to the existing global instead of evaluating the expression again.
---
Full diff: https://github.com/llvm/llvm-project/pull/237133.diff
1 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+9-2)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 164dd155debd4..079c24344f21a 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5994,8 +5994,15 @@ bool Compiler<Emitter>::visitAPValue(const APValue &Val, PrimType ValType,
APValue::LValueBase Base = Val.getLValueBase();
QualType EntryType;
if (const Expr *BaseExpr = Base.dyn_cast<const Expr *>()) {
- if (!this->visit(BaseExpr))
- return false;
+ // Try to avoid evaluating the BaseExpr multiple times.
+ if (UnsignedOrNone GlobalIndex = P.getGlobal(BaseExpr);
+ GlobalIndex && P.isGlobalInitialized(*GlobalIndex)) {
+ if (!this->emitGetPtrGlobal(*GlobalIndex, Info))
+ return false;
+ } else {
+ if (!this->visit(BaseExpr))
+ return false;
+ }
EntryType = BaseExpr->getType();
} else if (const auto *VD = Base.dyn_cast<const ValueDecl *>()) {
if (!this->visitDeclRef(VD, Info.asExpr()))
``````````
</details>
https://github.com/llvm/llvm-project/pull/237133
More information about the cfe-commits
mailing list