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
This commit is contained in:
Fariborz Jahanian 2009-08-06 19:12:38 +00:00
Родитель 70101ce87f
Коммит 1cf9ff87ee
3 изменённых файлов: 10 добавлений и 13 удалений

Просмотреть файл

@ -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<CallExpr>(SubExpr) || isa<CXXTemporaryObjectExpr>(SubExpr)) {
EmitAggExpr(SubExpr, Dest, false);
return;
}
EmitAggExpr((*i), Dest, false);
return;
}
// Call the constructor.
EmitCXXConstructorCall(E->getConstructor(), Ctor_Complete, Dest,

Просмотреть файл

@ -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<CallExpr>(From) ||
isa<CXXTemporaryObjectExpr>(From));
From = BuildCXXConstructExpr(Context, ToType,
SCS.CopyConstructor, Elidable, &From, 1);
return false;
}

Просмотреть файл

@ -176,9 +176,10 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
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;
}