Skip to content

Commit 7b1a058

Browse files
committed
[clang][Interp][NFC] Use direct Get{Local,Global} when possible
When returning variable declaration values, try to get the value directly instead of always going through a Pointer.
1 parent 86ef9d3 commit 7b1a058

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,27 +2119,33 @@ bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) {
21192119
if (!this->visitVarDecl(VD))
21202120
return false;
21212121

2122+
std::optional<PrimType> VarT = classify(VD->getType());
21222123
// Get a pointer to the variable
21232124
if (Context::shouldBeGloballyIndexed(VD)) {
21242125
auto GlobalIndex = P.getGlobal(VD);
21252126
assert(GlobalIndex); // visitVarDecl() didn't return false.
2126-
if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
2127-
return false;
2127+
if (VarT) {
2128+
if (!this->emitGetGlobal(*VarT, *GlobalIndex, VD))
2129+
return false;
2130+
} else {
2131+
if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
2132+
return false;
2133+
}
21282134
} else {
21292135
auto Local = Locals.find(VD);
21302136
assert(Local != Locals.end()); // Same here.
2131-
if (!this->emitGetPtrLocal(Local->second.Offset, VD))
2132-
return false;
2137+
if (VarT) {
2138+
if (!this->emitGetLocal(*VarT, Local->second.Offset, VD))
2139+
return false;
2140+
} else {
2141+
if (!this->emitGetPtrLocal(Local->second.Offset, VD))
2142+
return false;
2143+
}
21332144
}
21342145

21352146
// Return the value
2136-
if (std::optional<PrimType> VarT = classify(VD->getType())) {
2137-
if (!this->emitLoadPop(*VarT, VD))
2138-
return false;
2139-
2147+
if (VarT)
21402148
return this->emitRet(*VarT, VD);
2141-
}
2142-
21432149
return this->emitRetValue(VD);
21442150
}
21452151

0 commit comments

Comments
 (0)