[cfe-commits] r78267 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/copy-constructor-elim.cpp

Douglas Gregor dgregor at apple.com
Thu Aug 6 11:14:56 PDT 2009


On Aug 6, 2009, at 11:14 AM, Fariborz Jahanian wrote:
> On Aug 6, 2009, at 11:10 AM, Douglas Gregor wrote:
>>
>> On Aug 5, 2009, at 6:03 PM, Fariborz Jahanian wrote:
>>>
>>> +  // 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())) {
>>> +    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;
>>> +    }
>>> +  }
>>
>>
>> The intent of CXXConstructorExpr::isElidable() was to have Sema  
>> compute all of the cases where a copy constructor is elidable  
>> (based on its understanding of the language semantics). Then,  
>> CodeGen would just check isElidable() and elide in those cases.  
>> That way, CodeGen doesn't have to know anything about the language  
>> to do the right thing.
>
> Good to know. Will look into using it (and setting it if not set) to  
> do this optimization.

Thanks!

	- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20090806/c6eb2e47/attachment.html>


More information about the cfe-commits mailing list