aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-05-19 11:19:35 +0200
committerGitHub <noreply@github.com>2025-05-19 11:19:35 +0200
commit172c2817e5912901f65bd7a43f6df559fb5fcfd3 (patch)
tree6d5ebd03dc6d51b8b0c51aaaec5204d7b87ad514
parent3a86e0bd29f30d9fc9aea91d481372a1f8f69014 (diff)
downloadllvm-172c2817e5912901f65bd7a43f6df559fb5fcfd3.zip
llvm-172c2817e5912901f65bd7a43f6df559fb5fcfd3.tar.gz
llvm-172c2817e5912901f65bd7a43f6df559fb5fcfd3.tar.bz2
[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.
-rw-r--r--clang/lib/AST/ByteCode/EvalEmitter.cpp4
-rw-r--r--clang/lib/AST/ByteCode/EvalEmitter.h7
2 files changed, 5 insertions, 6 deletions
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 37e8d37..5498065 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 f9c1ff0..7303adb 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.h
+++ b/clang/lib/AST/ByteCode/EvalEmitter.h
@@ -111,12 +111,11 @@ private:
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();