[clang] 172c281 - [clang][bytecode] Use a SmallVector for EvalEmitter's locals (#140513)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 19 02:19:39 PDT 2025
Author: Timm Baeder
Date: 2025-05-19T11:19:35+02:00
New Revision: 172c2817e5912901f65bd7a43f6df559fb5fcfd3
URL: https://github.com/llvm/llvm-project/commit/172c2817e5912901f65bd7a43f6df559fb5fcfd3
DIFF: https://github.com/llvm/llvm-project/commit/172c2817e5912901f65bd7a43f6df559fb5fcfd3.diff
LOG: [clang][bytecode] Use a SmallVector for EvalEmitter's locals (#140513)
The offset we return for them are just indices, so we can use a vector
here.
Added:
Modified:
clang/lib/AST/ByteCode/EvalEmitter.cpp
clang/lib/AST/ByteCode/EvalEmitter.h
Removed:
################################################################################
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();
More information about the cfe-commits
mailing list