[clang] 9b8cb3d - [clang][bytecode] Divide `noteStep()` in hot and cold paths (#219760)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 30 00:38:30 PDT 2026
Author: Timm Baeder
Date: 2026-08-30T09:38:25+02:00
New Revision: 9b8cb3dc5f9847cd1039c7e6b4df2f18cbec72be
URL: https://github.com/llvm/llvm-project/commit/9b8cb3dc5f9847cd1039c7e6b4df2f18cbec72be
DIFF: https://github.com/llvm/llvm-project/commit/9b8cb3dc5f9847cd1039c7e6b4df2f18cbec72be.diff
LOG: [clang][bytecode] Divide `noteStep()` in hot and cold paths (#219760)
Move the hot success path into the header file to encourage inlining.
Also add a likeliness-hint since the steps check should _almost_ never
hit.
Added:
Modified:
clang/lib/AST/ByteCode/InterpState.cpp
clang/lib/AST/ByteCode/InterpState.h
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpState.cpp b/clang/lib/AST/ByteCode/InterpState.cpp
index 6ac1b2610dd09..4143a39dac83f 100644
--- a/clang/lib/AST/ByteCode/InterpState.cpp
+++ b/clang/lib/AST/ByteCode/InterpState.cpp
@@ -157,14 +157,7 @@ StdAllocatorCaller InterpState::getStdAllocatorCaller(StringRef Name) const {
return {};
}
-bool InterpState::noteStep(CodePtr OpPC) {
- if (InfiniteSteps)
- return true;
-
- --StepsLeft;
- if (StepsLeft != 0)
- return true;
-
+bool InterpState::diagnoseStepLimitExceeded(CodePtr OpPC) {
FFDiag(Current->getSource(OpPC), diag::note_constexpr_step_limit_exceeded, 1)
<< getLangOpts().ConstexprStepLimit;
Note(Current->getSource(OpPC), diag::note_constexpr_steps);
diff --git a/clang/lib/AST/ByteCode/InterpState.h b/clang/lib/AST/ByteCode/InterpState.h
index 9eb94faf813ef..5977162df445c 100644
--- a/clang/lib/AST/ByteCode/InterpState.h
+++ b/clang/lib/AST/ByteCode/InterpState.h
@@ -124,7 +124,16 @@ class InterpState final : public State {
/// Note that a step has been executed. If there are no more steps remaining,
/// diagnoses and returns \c false.
- bool noteStep(CodePtr OpPC);
+ bool noteStep(CodePtr OpPC) {
+ if (InfiniteSteps)
+ return true;
+
+ --StepsLeft;
+ if (LLVM_LIKELY(StepsLeft != 0))
+ return true;
+
+ return diagnoseStepLimitExceeded(OpPC);
+ }
bool initializingBlock(const Block *B) const {
for (PtrView V : InitializingPtrs)
@@ -171,6 +180,8 @@ class InterpState final : public State {
std::unique_ptr<DynamicAllocator> Alloc;
/// Allocator for everything else, e.g. floating-point values.
mutable std::optional<llvm::BumpPtrAllocator> Allocator;
+ /// Diagnose that we've reached the constexpr step limit.
+ bool diagnoseStepLimitExceeded(CodePtr OpPC);
public:
CodePtr PC;
More information about the cfe-commits
mailing list