Skip to content

[clang][bytecode] Use a SmallVector for EvalEmitter's locals #140513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025

Conversation

tbaederr
Copy link
Contributor

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

The offset we return for them are just indices, so we can use a vector
here.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels May 19, 2025
@llvmbot
Copy link
Member

llvmbot commented May 19, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/140513.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+2-2)
  • (modified) clang/lib/AST/ByteCode/EvalEmitter.h (+3-4)
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();

@tbaederr tbaederr merged commit 172c281 into llvm:main May 19, 2025
15 checks passed
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 6, 2025
…0513)

The offset we return for them are just indices, so we can use a vector
here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants