CodeGen: Have 'this'-returning constructors and destructors to take advantage of the new backend 'returned' attribute.

The backend will now use the generic 'returned' attribute to form tail calls where possible, as well as avoid save-restores of 'this' in some cases (specifically the cases that matter for the ARM C++ ABI).

This patch also reverts a prior front-end only partial implementation of these optimizations, since it's no longer required.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184205 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 824d2a0..d76fee5 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -717,6 +717,14 @@
   if (!IsIncompleteFunction)
     SetLLVMFunctionAttributes(FD, getTypes().arrangeGlobalDeclaration(GD), F);
 
+  if (getCXXABI().HasThisReturn(GD)) {
+    llvm::Type *RetTy = F->getReturnType();
+    assert(!F->arg_empty() &&
+           F->arg_begin()->getType()->canLosslesslyBitCastTo(RetTy) &&
+           "unexpected this return");
+    F->addAttribute(1, llvm::Attribute::Returned);
+  }
+
   // Only a few attributes are set on declarations; these may later be
   // overridden by a definition.