[PATCH] D138115: [clang] Short-circuit evaluation in ::EvaluateAsConstantExpr
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 16 03:56:13 PST 2022
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This adds another case to `FastEvaluateAsRValue()` for boolean expressions as well as calls `FastEvaluateAsRValue()` in `Expr::EvaluateAsConstantExpr()` as well.
This way we can short-circuit evaluating simple integer and boolean literals here.
I don't have before/after numbers for compilation times, since my local builds have asan enabled (so valgrind doesn't work) and I lost access to the my asan-less build. But it shouldn't be worse than before... right?
Sorry, can't find better reviewers to add.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138115
Files:
clang/lib/AST/ExprConstant.cpp
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15056,6 +15056,12 @@
return true;
}
+ if (const auto *L = dyn_cast<CXXBoolLiteralExpr>(Exp)) {
+ Result.Val = APValue(APSInt(APInt(1, L->getValue())));
+ IsConst = true;
+ return true;
+ }
+
// This case should be rare, but we need to check it before we check on
// the type below.
if (Exp->getType().isNull()) {
@@ -15240,6 +15246,9 @@
ConstantExprKind Kind) const {
assert(!isValueDependent() &&
"Expression evaluator can't be called on a dependent expression.");
+ bool IsConst;
+ if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+ return true;
ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
EvalInfo::EvaluationMode EM = EvalInfo::EM_ConstantExpression;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138115.475762.patch
Type: text/x-patch
Size: 954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221116/1c383d49/attachment-0001.bin>
More information about the cfe-commits
mailing list