[clang] 0a6c8c1 - [clang][Interp][NFC] Add a helper function for local variables
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 25 08:02:18 PST 2023
Author: Timm Bäder
Date: 2023-01-25T16:57:59+01:00
New Revision: 0a6c8c1b2570e3fc9c652989afed5de1aee0c0be
URL: https://github.com/llvm/llvm-project/commit/0a6c8c1b2570e3fc9c652989afed5de1aee0c0be
DIFF: https://github.com/llvm/llvm-project/commit/0a6c8c1b2570e3fc9c652989afed5de1aee0c0be.diff
LOG: [clang][Interp][NFC] Add a helper function for local variables
... in EvalEmitter.
Added:
Modified:
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/EvalEmitter.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp
index 72fd3b45254b..6d89bc407aad 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -208,9 +208,7 @@ bool EvalEmitter::emitGetPtrLocal(uint32_t I, const SourceInfo &Info) {
if (!isActive())
return true;
- auto It = Locals.find(I);
- assert(It != Locals.end() && "Missing local variable");
- Block *B = reinterpret_cast<Block *>(It->second.get());
+ Block *B = getLocal(I);
S.Stk.push<Pointer>(B, sizeof(InlineDescriptor));
return true;
}
@@ -222,9 +220,7 @@ bool EvalEmitter::emitGetLocal(uint32_t I, const SourceInfo &Info) {
using T = typename PrimConv<OpType>::T;
- auto It = Locals.find(I);
- assert(It != Locals.end() && "Missing local variable");
- auto *B = reinterpret_cast<Block *>(It->second.get());
+ Block *B = getLocal(I);
S.Stk.push<T>(*reinterpret_cast<T *>(B->data()));
return true;
}
@@ -236,9 +232,7 @@ bool EvalEmitter::emitSetLocal(uint32_t I, const SourceInfo &Info) {
using T = typename PrimConv<OpType>::T;
- auto It = Locals.find(I);
- assert(It != Locals.end() && "Missing local variable");
- auto *B = reinterpret_cast<Block *>(It->second.get());
+ Block *B = getLocal(I);
*reinterpret_cast<T *>(B->data()) = S.Stk.pop<T>();
InlineDescriptor &Desc = *reinterpret_cast<InlineDescriptor *>(B->rawData());
Desc.IsInitialized = true;
@@ -251,9 +245,8 @@ bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo &Info) {
return true;
for (auto &Local : Descriptors[I]) {
- auto It = Locals.find(Local.Offset);
- assert(It != Locals.end() && "Missing local variable");
- S.deallocate(reinterpret_cast<Block *>(It->second.get()));
+ Block *B = getLocal(Local.Offset);
+ S.deallocate(B);
}
return true;
diff --git a/clang/lib/AST/Interp/EvalEmitter.h b/clang/lib/AST/Interp/EvalEmitter.h
index 6b6d0d621901..22d7b7c68d10 100644
--- a/clang/lib/AST/Interp/EvalEmitter.h
+++ b/clang/lib/AST/Interp/EvalEmitter.h
@@ -92,6 +92,12 @@ class EvalEmitter : public SourceMapper {
/// Temporaries which require storage.
llvm::DenseMap<unsigned, 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());
+ }
+
// The emitter always tracks the current instruction and sets OpPC to a token
// value which is mapped to the location of the opcode being evaluated.
CodePtr OpPC;
More information about the cfe-commits
mailing list