Tweak CGCall functions again:

- Realized these functions will eventually need access to more data,
   moved to CodeGenModule. Eventually they should probably live
   together in some other helper class.

llvm-svn: 56039
This commit is contained in:
Daniel Dunbar 2008-09-10 00:41:16 +00:00
parent 76c8eb75b1
commit c68897d2c3
5 changed files with 28 additions and 21 deletions

View File

@ -14,6 +14,7 @@
#include "CGCall.h" #include "CGCall.h"
#include "CodeGenFunction.h" #include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "clang/AST/ASTContext.h" #include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h" #include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h" #include "clang/AST/DeclObjC.h"
@ -75,11 +76,11 @@ ArgTypeIterator CGCallInfo::argtypes_end() const {
/***/ /***/
bool CodeGenFunction::ReturnTypeUsesSret(QualType RetTy) { bool CodeGenModule::ReturnTypeUsesSret(QualType RetTy) {
return hasAggregateLLVMType(RetTy); return CodeGenFunction::hasAggregateLLVMType(RetTy);
} }
void CodeGenFunction::ConstructParamAttrList(const Decl *TargetDecl, void CodeGenModule::ConstructParamAttrList(const Decl *TargetDecl,
ArgTypeIterator begin, ArgTypeIterator begin,
ArgTypeIterator end, ArgTypeIterator end,
ParamAttrListType &PAL) { ParamAttrListType &PAL) {
@ -94,7 +95,7 @@ void CodeGenFunction::ConstructParamAttrList(const Decl *TargetDecl,
QualType ResTy = *begin; QualType ResTy = *begin;
unsigned Index = 1; unsigned Index = 1;
if (CodeGenFunction::hasAggregateLLVMType(ResTy)) { if (ReturnTypeUsesSret(ResTy)) {
PAL.push_back(llvm::ParamAttrsWithIndex::get(Index, PAL.push_back(llvm::ParamAttrsWithIndex::get(Index,
llvm::ParamAttr::StructRet)); llvm::ParamAttr::StructRet));
++Index; ++Index;
@ -203,8 +204,9 @@ RValue CodeGenFunction::EmitCall(llvm::Value *Callee,
// FIXME: Provide TargetDecl so nounwind, noreturn, etc, etc get set. // FIXME: Provide TargetDecl so nounwind, noreturn, etc, etc get set.
CodeGen::ParamAttrListType ParamAttrList; CodeGen::ParamAttrListType ParamAttrList;
ConstructParamAttrList(0, CallInfo.argtypes_begin(), CallInfo.argtypes_end(), CGM.ConstructParamAttrList(0,
ParamAttrList); CallInfo.argtypes_begin(), CallInfo.argtypes_end(),
ParamAttrList);
CI->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(), CI->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(),
ParamAttrList.size())); ParamAttrList.size()));

View File

@ -531,7 +531,7 @@ CodeGen::RValue CGObjCMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,
llvm::Value *Fn = llvm::Value *Fn =
ObjCTypes.getMessageSendFn(IsSuper, ObjCTypes.getMessageSendFn(IsSuper,
CGF.ReturnTypeUsesSret(ResultType), CGM.ReturnTypeUsesSret(ResultType),
CGM.getTypes().ConvertType(ResultType)); CGM.getTypes().ConvertType(ResultType));
return CGF.EmitCall(Fn, ResultType, ActualArgs); return CGF.EmitCall(Fn, ResultType, ActualArgs);
} }

View File

@ -138,15 +138,6 @@ public:
const FunctionArgList &Args); const FunctionArgList &Args);
void FinishFunction(SourceLocation EndLoc=SourceLocation()); void FinishFunction(SourceLocation EndLoc=SourceLocation());
/// ReturnTypeUsesSret - Return true iff the given type uses 'sret'
/// when used as a return type.
static bool ReturnTypeUsesSret(QualType RetTy);
static void ConstructParamAttrList(const Decl *TargetDecl,
const ArgTypeIterator begin,
const ArgTypeIterator end,
ParamAttrListType &PAL);
/// EmitFunctionProlog - Emit the target specific LLVM code to load /// EmitFunctionProlog - Emit the target specific LLVM code to load
/// the arguments for the given function. This is also responsible /// the arguments for the given function. This is also responsible
/// for naming the LLVM function arguments. /// for naming the LLVM function arguments.

View File

@ -212,12 +212,12 @@ static void SetGlobalValueAttributes(const Decl *D,
} }
} }
static void SetFunctionParamAttrs(const CGFunctionInfo &Info, llvm::Function *F) { void CodeGenModule::SetFunctionParamAttrs(const CGFunctionInfo &Info,
llvm::Function *F) {
ParamAttrListType ParamAttrList; ParamAttrListType ParamAttrList;
CodeGenFunction::ConstructParamAttrList(Info.getDecl(), ConstructParamAttrList(Info.getDecl(),
Info.argtypes_begin(), Info.argtypes_begin(), Info.argtypes_end(),
Info.argtypes_end(), ParamAttrList);
ParamAttrList);
F->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(), F->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(),
ParamAttrList.size())); ParamAttrList.size()));

View File

@ -19,6 +19,8 @@
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringMap.h"
#include "CGCall.h"
namespace llvm { namespace llvm {
class Module; class Module;
class Constant; class Constant;
@ -215,6 +217,18 @@ public:
void SetMethodAttributes(const ObjCMethodDecl *MD, void SetMethodAttributes(const ObjCMethodDecl *MD,
llvm::Function *F); llvm::Function *F);
void SetFunctionParamAttrs(const CGFunctionInfo &Info,
llvm::Function *F);
/// ReturnTypeUsesSret - Return true iff the given type uses 'sret'
/// when used as a return type.
bool ReturnTypeUsesSret(QualType RetTy);
void ConstructParamAttrList(const Decl *TargetDecl,
const ArgTypeIterator begin,
const ArgTypeIterator end,
ParamAttrListType &PAL);
private: private:
/// SetFunctionAttributesForDefinition - Set function attributes /// SetFunctionAttributesForDefinition - Set function attributes
/// specific to a function definition. /// specific to a function definition.