[clang] [clang][bytecode] Divide `noteStep()` in hot and cold paths (PR #219760)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 29 22:10:04 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/219760.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/InterpState.cpp (+1-8)
- (modified) clang/lib/AST/ByteCode/InterpState.h (+12-1)
``````````diff
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 8b3c2a0e7dd5a..16cb0ac415ff5 100644
--- a/clang/lib/AST/ByteCode/InterpState.h
+++ b/clang/lib/AST/ByteCode/InterpState.h
@@ -129,7 +129,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)
@@ -176,6 +185,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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/219760
More information about the cfe-commits
mailing list