[cfe-commits] r56031 - in /cfe/trunk/lib/CodeGen: CGCall.cpp CGExpr.cpp CodeGenFunction.cpp CodeGenFunction.h

Daniel Dunbar daniel at zuster.org
Tue Sep 9 16:27:19 PDT 2008


Author: ddunbar
Date: Tue Sep  9 18:27:19 2008
New Revision: 56031

URL: http://llvm.org/viewvc/llvm-project?rev=56031&view=rev
Log:
Move ABI specific code for functions / calls to CGCall.cpp:
 - Factor out EmitFunction{Pro,Epi}log

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=56031&r1=56030&r2=56031&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Sep  9 18:27:19 2008
@@ -114,3 +114,105 @@
   // FIXME: Provide TargetDecl so nounwind, noreturn, etc, etc get set.
   constructParamAttrListInternal(0, ArgTypes, PAL);
 }
+
+/***/
+
+void CodeGenFunction::EmitFunctionProlog(llvm::Function *Fn,
+                                         QualType RetTy, 
+                                         const FunctionArgList &Args) {
+  // Emit allocs for param decls.  Give the LLVM Argument nodes names.
+  llvm::Function::arg_iterator AI = Fn->arg_begin();
+  
+  // Name the struct return argument.
+  if (hasAggregateLLVMType(RetTy)) {
+    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 != Fn->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 == Fn->arg_end() && "Argument mismatch!");
+}
+
+void CodeGenFunction::EmitFunctionEpilog(QualType RetTy, 
+                                         llvm::Value *ReturnValue) {
+  if (!ReturnValue) {
+    Builder.CreateRetVoid();
+  } else { 
+    if (!hasAggregateLLVMType(RetTy)) {
+      Builder.CreateRet(Builder.CreateLoad(ReturnValue));
+    } else if (RetTy->isAnyComplexType()) {
+      EmitAggregateCopy(CurFn->arg_begin(), ReturnValue, RetTy);
+      Builder.CreateRetVoid();
+    } else {
+      EmitAggregateCopy(CurFn->arg_begin(), ReturnValue, RetTy);
+      Builder.CreateRetVoid();
+    }
+  }
+}
+
+RValue CodeGenFunction::EmitCall(llvm::Value *Callee, 
+                                 QualType ResultType, 
+                                 const CallArgList &CallArgs) {
+  // FIXME: Factor out code to load from args into locals into target.
+  llvm::SmallVector<llvm::Value*, 16> Args;
+  llvm::Value *TempArg0 = 0;
+
+  // Handle struct-return functions by passing a pointer to the
+  // location that we would like to return into.
+  if (hasAggregateLLVMType(ResultType)) {
+    // Create a temporary alloca to hold the result of the call. :(
+    TempArg0 = CreateTempAlloca(ConvertType(ResultType));
+    Args.push_back(TempArg0);
+  }
+  
+  for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end(); 
+       I != E; ++I) {
+    RValue RV = I->first;
+    if (RV.isScalar()) {
+      Args.push_back(RV.getScalarVal());
+    } else if (RV.isComplex()) {
+      // Make a temporary alloca to pass the argument.
+      Args.push_back(CreateTempAlloca(ConvertType(I->second)));
+      StoreComplexToAddr(RV.getComplexVal(), Args.back(), false); 
+    } else {
+      Args.push_back(RV.getAggregateAddr());
+    }
+  }
+  
+  llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size());
+  CGCallInfo CallInfo(ResultType, CallArgs);
+
+  CodeGen::ParamAttrListType ParamAttrList;
+  CallInfo.constructParamAttrList(ParamAttrList);
+  CI->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(), 
+                                         ParamAttrList.size()));  
+
+  if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee))
+    CI->setCallingConv(F->getCallingConv());
+  if (CI->getType() != llvm::Type::VoidTy)
+    CI->setName("call");
+  else if (ResultType->isAnyComplexType())
+    return RValue::getComplex(LoadComplexFromAddr(TempArg0, false));
+  else if (hasAggregateLLVMType(ResultType))
+    // Struct return.
+    return RValue::getAggregate(TempArg0);
+  else {
+    // void return.
+    assert(ResultType->isVoidType() && "Should only have a void expr here");
+    CI = 0;
+  }
+      
+  return RValue::get(CI);  
+}

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=56031&r1=56030&r2=56031&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Sep  9 18:27:19 2008
@@ -856,58 +856,3 @@
 
   return EmitCall(Callee, ResultType, Args);
 }
-
-RValue CodeGenFunction::EmitCall(llvm::Value *Callee, 
-                                 QualType ResultType, 
-                                 const CallArgList &CallArgs) {
-  // FIXME: Factor out code to load from args into locals into target.
-  llvm::SmallVector<llvm::Value*, 16> Args;
-  llvm::Value *TempArg0 = 0;
-
-  // Handle struct-return functions by passing a pointer to the
-  // location that we would like to return into.
-  if (hasAggregateLLVMType(ResultType)) {
-    // Create a temporary alloca to hold the result of the call. :(
-    TempArg0 = CreateTempAlloca(ConvertType(ResultType));
-    Args.push_back(TempArg0);
-  }
-  
-  for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end(); 
-       I != E; ++I) {
-    RValue RV = I->first;
-    if (RV.isScalar()) {
-      Args.push_back(RV.getScalarVal());
-    } else if (RV.isComplex()) {
-      // Make a temporary alloca to pass the argument.
-      Args.push_back(CreateTempAlloca(ConvertType(I->second)));
-      StoreComplexToAddr(RV.getComplexVal(), Args.back(), false); 
-    } else {
-      Args.push_back(RV.getAggregateAddr());
-    }
-  }
-  
-  llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size());
-  CGCallInfo CallInfo(ResultType, CallArgs);
-
-  CodeGen::ParamAttrListType ParamAttrList;
-  CallInfo.constructParamAttrList(ParamAttrList);
-  CI->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(), 
-                                         ParamAttrList.size()));  
-
-  if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee))
-    CI->setCallingConv(F->getCallingConv());
-  if (CI->getType() != llvm::Type::VoidTy)
-    CI->setName("call");
-  else if (ResultType->isAnyComplexType())
-    return RValue::getComplex(LoadComplexFromAddr(TempArg0, false));
-  else if (hasAggregateLLVMType(ResultType))
-    // Struct return.
-    return RValue::getAggregate(TempArg0);
-  else {
-    // void return.
-    assert(ResultType->isVoidType() && "Should only have a void expr here");
-    CI = 0;
-  }
-      
-  return RValue::get(CI);  
-}

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=56031&r1=56030&r2=56031&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Sep  9 18:27:19 2008
@@ -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,

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=56031&r1=56030&r2=56031&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Sep  9 18:27:19 2008
@@ -137,7 +137,18 @@
                      llvm::Function *Fn,
                      const FunctionArgList &Args);
   void FinishFunction(SourceLocation EndLoc=SourceLocation());
-  
+
+  /// EmitFunctionProlog - Emit the target specific LLVM code to load
+  /// the arguments for the given function. This is also responsible
+  /// for naming the LLVM function arguments.
+  void EmitFunctionProlog(llvm::Function *Fn, QualType RetTy, 
+                          const FunctionArgList &Args);
+
+  /// EmitFunctionEpilog - Emit the target specific LLVM code to
+  /// return the given temporary.
+  void EmitFunctionEpilog(QualType RetTy, 
+                          llvm::Value *ReturnValue);
+
   const llvm::Type *ConvertType(QualType T);
 
   /// LoadObjCSelf - Load the value of self. This function is only





More information about the cfe-commits mailing list