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

The offset we return for them are just indices, so we can use a vector here.

>From e4bcf674619283cd0d7a7d4e613a5621de17ca66 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com>
Date: Sat, 17 May 2025 14:27:43 +0200
Subject: [PATCH] [clang][bytecode] Use a SmallVector for EvalEmitter's locals

The offset we return for them are just indices, so we can use a vector
here.
---
 clang/lib/AST/ByteCode/EvalEmitter.cpp | 4 ++--
 clang/lib/AST/ByteCode/EvalEmitter.h   | 7 +++----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp 
b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 37e8d3788a6fe..5498065657e0a 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -20,7 +20,7 @@ EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State 
&Parent,
     : Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {}
 
 EvalEmitter::~EvalEmitter() {
-  for (auto &[K, V] : Locals) {
+  for (auto &V : Locals) {
     Block *B = reinterpret_cast<Block *>(V.get());
     if (B->isInitialized())
       B->invokeDtor();
@@ -112,7 +112,7 @@ Scope::Local EvalEmitter::createLocal(Descriptor *D) {
 
   // Register the local.
   unsigned Off = Locals.size();
-  Locals.insert({Off, std::move(Memory)});
+  Locals.push_back(std::move(Memory));
   return {Off, D};
 }
 
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.h 
b/clang/lib/AST/ByteCode/EvalEmitter.h
index f9c1ff07625b8..7303adba22af7 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.h
+++ b/clang/lib/AST/ByteCode/EvalEmitter.h
@@ -111,12 +111,11 @@ class EvalEmitter : public SourceMapper {
   std::optional<PtrCallback> PtrCB;
 
   /// Temporaries which require storage.
-  llvm::DenseMap<unsigned, std::unique_ptr<char[]>> Locals;
+  llvm::SmallVector<std::unique_ptr<char[]>> Locals;
 
   Block *getLocal(unsigned Index) const {
-    auto It = Locals.find(Index);
-    assert(It != Locals.end() && "Missing local variable");
-    return reinterpret_cast<Block *>(It->second.get());
+    assert(Index < Locals.size());
+    return reinterpret_cast<Block *>(Locals[Index].get());
   }
 
   void updateGlobalTemporaries();

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to