https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/224893

This saves us yet another BumpPtrAllocator.

>From e4740b8f23b03bf7c4d038056e0497a67daa08e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Sun, 20 Sep 2026 09:26:48 +0200
Subject: [PATCH] shared alloc

---
 clang/lib/AST/ByteCode/DynamicAllocator.h | 6 +++---
 clang/lib/AST/ByteCode/InterpState.h      | 8 +++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ByteCode/DynamicAllocator.h 
b/clang/lib/AST/ByteCode/DynamicAllocator.h
index 2336c3f3316c3..cc6a315083b61 100644
--- a/clang/lib/AST/ByteCode/DynamicAllocator.h
+++ b/clang/lib/AST/ByteCode/DynamicAllocator.h
@@ -62,7 +62,8 @@ class DynamicAllocator final {
   };
 
 public:
-  DynamicAllocator() = default;
+  DynamicAllocator(llvm::BumpPtrAllocator &DescAlloc)
+      : DescAllocator(DescAlloc) {}
   DynamicAllocator(DynamicAllocator &) = delete;
   DynamicAllocator(DynamicAllocator &&) = delete;
   ~DynamicAllocator();
@@ -105,8 +106,7 @@ class DynamicAllocator final {
   // to them.
   llvm::SmallVector<Allocation> DeadAllocations;
 
-  using PoolAllocTy = llvm::BumpPtrAllocator;
-  PoolAllocTy DescAllocator;
+  llvm::BumpPtrAllocator &DescAllocator;
 
   /// Allocates a new descriptor.
   template <typename... Ts> Descriptor *allocateDescriptor(Ts &&...Args) {
diff --git a/clang/lib/AST/ByteCode/InterpState.h 
b/clang/lib/AST/ByteCode/InterpState.h
index 920197d8021c0..91d0c5be2bb0c 100644
--- a/clang/lib/AST/ByteCode/InterpState.h
+++ b/clang/lib/AST/ByteCode/InterpState.h
@@ -80,7 +80,9 @@ class InterpState final : public State {
 
   DynamicAllocator &getAllocator() {
     if (!Alloc) {
-      Alloc = std::make_unique<DynamicAllocator>();
+      if (!Allocator)
+        Allocator.emplace();
+      Alloc = std::make_unique<DynamicAllocator>(*Allocator);
     }
 
     return *Alloc;
@@ -223,10 +225,10 @@ class InterpState final : public State {
   DeadBlock *DeadBlocks = nullptr;
   /// Reference to the offset-source mapping.
   SourceMapper *M;
-  /// Allocator used for dynamic allocations performed via the program.
-  std::unique_ptr<DynamicAllocator> Alloc;
   /// Allocator for everything else, e.g. floating-point values.
   mutable std::optional<llvm::BumpPtrAllocator> Allocator;
+  /// Allocator used for dynamic allocations performed via the program.
+  std::unique_ptr<DynamicAllocator> Alloc;
   /// Diagnose that we've reached the constexpr step limit.
   bool diagnoseStepLimitExceeded(CodePtr OpPC);
 

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

Reply via email to