aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Compiler.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-05-13 11:01:59 +0200
committerGitHub <noreply@github.com>2025-05-13 11:01:59 +0200
commit3de2fa91e17287c0bc45f8080064fc327e803314 (patch)
treef9bbf1930feab191c0cbf7f40b9c0b4995d94963 /clang/lib/AST/ByteCode/Compiler.cpp
parentfd3fecfc0936703f2715fe6fea890e81b0b3c2ac (diff)
downloadllvm-3de2fa91e17287c0bc45f8080064fc327e803314.zip
llvm-3de2fa91e17287c0bc45f8080064fc327e803314.tar.gz
llvm-3de2fa91e17287c0bc45f8080064fc327e803314.tar.bz2
[clang][bytecode] Avoid classifying in visitArrayElemInit() (#139674)
We usually call this more than once, but the type of the initializer never changes. Let's classify only once and pass that to visitArrayElemInit().
Diffstat (limited to 'clang/lib/AST/ByteCode/Compiler.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Compiler.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 51bfa8e..07e8712 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -570,11 +570,11 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
return false;
}
+ PrimType T = classifyPrim(SubExpr->getType());
// Init the complex value to {SubExpr, 0}.
- if (!this->visitArrayElemInit(0, SubExpr))
+ if (!this->visitArrayElemInit(0, SubExpr, T))
return false;
// Zero-init the second element.
- PrimType T = classifyPrim(SubExpr->getType());
if (!this->visitZeroInitializer(T, SubExpr->getType(), SubExpr))
return false;
return this->emitInitElem(T, 1, SubExpr);
@@ -772,7 +772,7 @@ bool Compiler<Emitter>::VisitImaginaryLiteral(const ImaginaryLiteral *E) {
return false;
if (!this->emitInitElem(SubExprT, 0, SubExpr))
return false;
- return this->visitArrayElemInit(1, SubExpr);
+ return this->visitArrayElemInit(1, SubExpr, SubExprT);
}
template <class Emitter>
@@ -1886,6 +1886,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
if (!this->emitCheckArraySize(NumElems, E))
return false;
+ std::optional<PrimType> InitT = classify(CAT->getElementType());
unsigned ElementIndex = 0;
for (const Expr *Init : Inits) {
if (const auto *EmbedS =
@@ -1905,7 +1906,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
return false;
} else {
- if (!this->visitArrayElemInit(ElementIndex, Init))
+ if (!this->visitArrayElemInit(ElementIndex, Init, InitT))
return false;
++ElementIndex;
}
@@ -1915,7 +1916,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
// FIXME: This should go away.
if (ArrayFiller) {
for (; ElementIndex != NumElems; ++ElementIndex) {
- if (!this->visitArrayElemInit(ElementIndex, ArrayFiller))
+ if (!this->visitArrayElemInit(ElementIndex, ArrayFiller, InitT))
return false;
}
}
@@ -1998,13 +1999,13 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
/// Pointer to the array(not the element!) must be on the stack when calling
/// this.
template <class Emitter>
-bool Compiler<Emitter>::visitArrayElemInit(unsigned ElemIndex,
- const Expr *Init) {
- if (std::optional<PrimType> T = classify(Init->getType())) {
+bool Compiler<Emitter>::visitArrayElemInit(unsigned ElemIndex, const Expr *Init,
+ std::optional<PrimType> InitT) {
+ if (InitT) {
// Visit the primitive element like normal.
if (!this->visit(Init))
return false;
- return this->emitInitElem(*T, ElemIndex, Init);
+ return this->emitInitElem(*InitT, ElemIndex, Init);
}
InitLinkScope<Emitter> ILS(this, InitLink::Elem(ElemIndex));
@@ -2298,6 +2299,7 @@ bool Compiler<Emitter>::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
// Investigate compiling this to a loop.
const Expr *SubExpr = E->getSubExpr();
size_t Size = E->getArraySize().getZExtValue();
+ std::optional<PrimType> SubExprT = classify(SubExpr);
// So, every iteration, we execute an assignment here
// where the LHS is on the stack (the target array)
@@ -2306,7 +2308,7 @@ bool Compiler<Emitter>::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
ArrayIndexScope<Emitter> IndexScope(this, I);
BlockScope<Emitter> BS(this);
- if (!this->visitArrayElemInit(I, SubExpr))
+ if (!this->visitArrayElemInit(I, SubExpr, SubExprT))
return false;
if (!BS.destroyLocals())
return false;