diff options
Diffstat (limited to 'clang/lib/AST/ByteCode/Compiler.cpp')
-rw-r--r-- | clang/lib/AST/ByteCode/Compiler.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 6e451ac..5bcac39 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -201,6 +201,28 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { return this->emitInvalidCast(CastKind::Volatile, /*Fatal=*/true, CE); OptPrimType SubExprT = classify(SubExpr->getType()); + // Try to load the value directly. This is purely a performance + // optimization. + if (SubExprT) { + if (const auto *DRE = dyn_cast<DeclRefExpr>(SubExpr)) { + const ValueDecl *D = DRE->getDecl(); + bool IsReference = D->getType()->isReferenceType(); + + if (!IsReference) { + if (Context::shouldBeGloballyIndexed(D)) { + if (auto GlobalIndex = P.getGlobal(D)) + return this->emitGetGlobal(*SubExprT, *GlobalIndex, CE); + } else if (auto It = Locals.find(D); It != Locals.end()) { + return this->emitGetLocal(*SubExprT, It->second.Offset, CE); + } else if (const auto *PVD = dyn_cast<ParmVarDecl>(D)) { + if (auto It = this->Params.find(PVD); It != this->Params.end()) { + return this->emitGetParam(*SubExprT, It->second.Offset, CE); + } + } + } + } + } + // Prepare storage for the result. if (!Initializing && !SubExprT) { std::optional<unsigned> LocalIndex = allocateLocal(SubExpr); @@ -3857,10 +3879,7 @@ template <class Emitter> bool Compiler<Emitter>::VisitAddrLabelExpr(const AddrLabelExpr *E) { assert(E->getType()->isVoidPointerType()); - unsigned Offset = - allocateLocalPrimitive(E->getLabel(), PT_Ptr, /*IsConst=*/true); - - return this->emitGetLocal(PT_Ptr, Offset, E); + return this->emitDummyPtr(E, E); } template <class Emitter> @@ -5895,7 +5914,7 @@ bool Compiler<Emitter>::emitLambdaStaticInvokerBody(const CXXMethodDecl *MD) { const CXXRecordDecl *ClosureClass = MD->getParent(); const CXXMethodDecl *LambdaCallOp = ClosureClass->getLambdaCallOperator(); - assert(ClosureClass->captures_begin() == ClosureClass->captures_end()); + assert(ClosureClass->captures().empty()); const Function *Func = this->getFunction(LambdaCallOp); if (!Func) return false; |