From 1cf9ff87ee235ad252332a96699abdb32bd6facb Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Thu, 6 Aug 2009 19:12:38 +0000 Subject: [PATCH] Set and use Elidable in elimination of copy ctors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78331 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCXX.cpp | 12 +++--------- lib/Sema/SemaExprCXX.cpp | 6 ++++-- lib/Sema/SemaInit.cpp | 5 +++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 567c58373c..0d51c03bab 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -258,16 +258,10 @@ CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest, // Code gen optimization to eliminate copy constructor and return // its first argument instead. - const CXXConstructorDecl *CDecl = E->getConstructor(); - if (E->getNumArgs() == 1 && - CDecl->isCopyConstructor(getContext())) { + if (E->isElidable()) { CXXConstructExpr::const_arg_iterator i = E->arg_begin(); - const Expr *SubExpr = (*i); - // FIXME. Any other cases can be optimized away? - if (isa(SubExpr) || isa(SubExpr)) { - EmitAggExpr(SubExpr, Dest, false); - return; - } + EmitAggExpr((*i), Dest, false); + return; } // Call the constructor. EmitCXXConstructorCall(E->getConstructor(), Ctor_Complete, Dest, diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 7e0422e432..5b74938191 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -911,8 +911,10 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, assert(!ToType->isReferenceType()); // FIXME: Keep track of whether the copy constructor is elidable or not. - From = BuildCXXConstructExpr(Context, - ToType, SCS.CopyConstructor, false, &From, 1); + bool Elidable = (isa(From) || + isa(From)); + From = BuildCXXConstructExpr(Context, ToType, + SCS.CopyConstructor, Elidable, &From, 1); return false; } diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 445cd691d6..29113822f7 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -176,9 +176,10 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, DirectInit? IK_Direct : IK_Copy); if (!Constructor) return true; - + bool Elidable = (isa(Init) || + isa(Init)); Init = BuildCXXConstructExpr(Context, - DeclType, Constructor, false, &Init, 1); + DeclType, Constructor, Elidable, &Init, 1); Init = MaybeCreateCXXExprWithTemporaries(Init, /*DestroyTemps=*/true); return false; } -- 2.40.0