Move ABI specific code for functions / calls to CGCall.cpp:
 - Factor out EmitFunction{Pro,Epi}log


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56031 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index a934e43..8b3dd84 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -86,21 +86,9 @@
   assert(BreakContinueStack.empty() &&
          "mismatched push/pop in break/continue stack!");
 
-  // Emit code to actually return.
+  // Emit function epilog (to return).
   Builder.SetInsertPoint(ReturnBlock);
-  if (!ReturnValue) {
-    Builder.CreateRetVoid();
-  } else { 
-    if (!hasAggregateLLVMType(FnRetTy)) {
-      Builder.CreateRet(Builder.CreateLoad(ReturnValue));
-    } else if (FnRetTy->isAnyComplexType()) {
-      EmitAggregateCopy(CurFn->arg_begin(), ReturnValue, FnRetTy);
-      Builder.CreateRetVoid();
-    } else {
-      EmitAggregateCopy(CurFn->arg_begin(), ReturnValue, FnRetTy);
-      Builder.CreateRetVoid();
-    }
-  }
+  EmitFunctionEpilog(FnRetTy, ReturnValue);
 
   // Remove the AllocaInsertPt instruction, which is just a convenience for us.
   AllocaInsertPt->eraseFromParent();
@@ -146,29 +134,7 @@
     }
   }
 
-  // Emit allocs for param decls.  Give the LLVM Argument nodes names.
-  llvm::Function::arg_iterator AI = CurFn->arg_begin();
-  
-  // Name the struct return argument.
-  if (hasAggregateLLVMType(FnRetTy)) {
-    AI->setName("agg.result");
-    ++AI;
-  }
-     
-  for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
-       i != e; ++i, ++AI) {
-    const VarDecl *Arg = i->first;
-    QualType T = i->second;
-    assert(AI != CurFn->arg_end() && "Argument mismatch!");
-    llvm::Value* V = AI;
-    if (!getContext().typesAreCompatible(T, Arg->getType())) {
-      // This must be a promotion, for something like
-      // "void a(x) short x; {..."
-      V = EmitScalarConversion(V, T, Arg->getType());
-      }
-    EmitParmDecl(*Arg, V);
-  }
-  assert(AI == CurFn->arg_end() && "Argument mismatch!");
+  EmitFunctionProlog(CurFn, FnRetTy, Args);
 }
 
 void CodeGenFunction::GenerateCode(const FunctionDecl *FD,