<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 6, 2009, at 11:14 AM, Fariborz Jahanian wrote:</div><blockquote type="cite"><div>On Aug 6, 2009, at 11:10 AM, Douglas Gregor wrote:<blockquote type="cite">On Aug 5, 2009, at 6:03 PM, Fariborz Jahanian wrote:<br></blockquote><blockquote type="cite"><blockquote type="cite"><font class="Apple-style-span" color="#006312"><br></font></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+  // Code gen optimization to eliminate copy constructor and return<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+  // its first argument instead.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+  const CXXConstructorDecl *CDecl = E->getConstructor();<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+  if (E->getNumArgs() == 1 &&<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+      CDecl->isCopyConstructor(getContext())) {<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+    CXXConstructExpr::const_arg_iterator i = E->arg_begin();<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+    const Expr *SubExpr = (*i);<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+    // FIXME. Any other cases can be optimized away?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+    if (isa<CallExpr>(SubExpr) || isa<CXXTemporaryObjectExpr>(SubExpr)) {<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+      EmitAggExpr(SubExpr, Dest, false);<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+      return;<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+    }<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">+  }<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">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.<br></blockquote><br>Good to know. Will look into using it (and setting it if not set) to do this optimization.<br></div></blockquote></div><br><div>Thanks!</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div></body></html>