https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/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.

>From b1d1de0f19813806b23479a2173bed1e45bcd4b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Sat, 29 Aug 2026 19:46:37 +0200
Subject: [PATCH] noteStep

---
 clang/lib/AST/ByteCode/InterpState.cpp |  9 +--------
 clang/lib/AST/ByteCode/InterpState.h   | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 9 deletions(-)

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;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to