Author: Timm Bäder Date: 2023-11-10T11:30:38+01:00 New Revision: 7b1a0580216796045b880251e031a1e5e0ecad74
URL: https://github.com/llvm/llvm-project/commit/7b1a0580216796045b880251e031a1e5e0ecad74 DIFF: https://github.com/llvm/llvm-project/commit/7b1a0580216796045b880251e031a1e5e0ecad74.diff LOG: [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. Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index a2cf682b2532bde..15a717089660337 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2119,27 +2119,33 @@ bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) { if (!this->visitVarDecl(VD)) return false; + std::optional<PrimType> VarT = classify(VD->getType()); // Get a pointer to the variable if (Context::shouldBeGloballyIndexed(VD)) { auto GlobalIndex = P.getGlobal(VD); assert(GlobalIndex); // visitVarDecl() didn't return false. - if (!this->emitGetPtrGlobal(*GlobalIndex, VD)) - return false; + if (VarT) { + if (!this->emitGetGlobal(*VarT, *GlobalIndex, VD)) + return false; + } else { + if (!this->emitGetPtrGlobal(*GlobalIndex, VD)) + return false; + } } else { auto Local = Locals.find(VD); assert(Local != Locals.end()); // Same here. - if (!this->emitGetPtrLocal(Local->second.Offset, VD)) - return false; + if (VarT) { + if (!this->emitGetLocal(*VarT, Local->second.Offset, VD)) + return false; + } else { + if (!this->emitGetPtrLocal(Local->second.Offset, VD)) + return false; + } } // Return the value - if (std::optional<PrimType> VarT = classify(VD->getType())) { - if (!this->emitLoadPop(*VarT, VD)) - return false; - + if (VarT) return this->emitRet(*VarT, VD); - } - return this->emitRetValue(VD); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits