[cfe-commits] r78331 - in /cfe/trunk/lib: CodeGen/CGCXX.cpp Sema/SemaExprCXX.cpp Sema/SemaInit.cpp
Fariborz Jahanian
fjahanian at apple.com
Thu Aug 6 12:12:38 PDT 2009
Author: fjahanian
Date: Thu Aug 6 14:12:38 2009
New Revision: 78331
URL: http://llvm.org/viewvc/llvm-project?rev=78331&view=rev
Log:
Set and use Elidable in elimination of copy ctors.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=78331&r1=78330&r2=78331&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Thu Aug 6 14:12:38 2009
@@ -258,16 +258,10 @@
// 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<CallExpr>(SubExpr) || isa<CXXTemporaryObjectExpr>(SubExpr)) {
- EmitAggExpr(SubExpr, Dest, false);
- return;
- }
+ EmitAggExpr((*i), Dest, false);
+ return;
}
// Call the constructor.
EmitCXXConstructorCall(E->getConstructor(), Ctor_Complete, Dest,
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=78331&r1=78330&r2=78331&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Aug 6 14:12:38 2009
@@ -911,8 +911,10 @@
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<CallExpr>(From) ||
+ isa<CXXTemporaryObjectExpr>(From));
+ From = BuildCXXConstructExpr(Context, ToType,
+ SCS.CopyConstructor, Elidable, &From, 1);
return false;
}
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=78331&r1=78330&r2=78331&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Aug 6 14:12:38 2009
@@ -176,9 +176,10 @@
DirectInit? IK_Direct : IK_Copy);
if (!Constructor)
return true;
-
+ bool Elidable = (isa<CallExpr>(Init) ||
+ isa<CXXTemporaryObjectExpr>(Init));
Init = BuildCXXConstructExpr(Context,
- DeclType, Constructor, false, &Init, 1);
+ DeclType, Constructor, Elidable, &Init, 1);
Init = MaybeCreateCXXExprWithTemporaries(Init, /*DestroyTemps=*/true);
return false;
}
More information about the cfe-commits
mailing list