From 3913f184c84135fb4612743f1faa6c1edd2dd055 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 9 Sep 2008 23:48:28 +0000 Subject: [PATCH] Add CodeGenFunction::ReturnTypeUsesSret - Hook so NeXT runtime doesn't depend on ABI. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56034 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 4 ++++ lib/CodeGen/CGObjCMac.cpp | 18 +++++++++--------- lib/CodeGen/CodeGenFunction.h | 4 ++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 89004325c1..8b7400af56 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -117,6 +117,10 @@ void CGCallInfo::constructParamAttrList(ParamAttrListType &PAL) const { /***/ +bool CodeGenFunction::ReturnTypeUsesSret(QualType RetTy) { + return hasAggregateLLVMType(RetTy); +} + void CodeGenFunction::EmitFunctionProlog(llvm::Function *Fn, QualType RetTy, const FunctionArgList &Args) { diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index a64b16041a..ff7717dad3 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -158,7 +158,8 @@ public: ObjCTypesHelper(CodeGen::CodeGenModule &cgm); ~ObjCTypesHelper(); - llvm::Value *getMessageSendFn(bool IsSuper, const llvm::Type *ReturnTy); + llvm::Value *getMessageSendFn(bool IsSuper, bool isStret, + const llvm::Type *ReturnTy); }; class CGObjCMac : public CodeGen::CGObjCRuntime { @@ -528,13 +529,11 @@ CodeGen::RValue CGObjCMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF, CGF.getContext().getObjCSelType())); ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end()); - // FIXME: This is a hack, we are implicitly coordinating with - // EmitCall, which will move the return type to the first parameter - // and set the structure return flag. See getMessageSendFn(). - - const llvm::Type *ReturnTy = CGM.getTypes().ConvertType(ResultType); - return CGF.EmitCall(ObjCTypes.getMessageSendFn(IsSuper, ReturnTy), - ResultType, ActualArgs); + llvm::Value *Fn = + ObjCTypes.getMessageSendFn(IsSuper, + CGF.ReturnTypeUsesSret(ResultType), + CGM.getTypes().ConvertType(ResultType)); + return CGF.EmitCall(Fn, ResultType, ActualArgs); } llvm::Value *CGObjCMac::GenerateProtocolRef(llvm::IRBuilder<> &Builder, @@ -2249,12 +2248,13 @@ ObjCTypesHelper::~ObjCTypesHelper() { } llvm::Value *ObjCTypesHelper::getMessageSendFn(bool IsSuper, + bool IsStret, const llvm::Type *ReturnTy) { llvm::Function *F; llvm::FunctionType *CallFTy; // FIXME: Should we be caching any of this? - if (!ReturnTy->isSingleValueType()) { + if (IsStret) { F = IsSuper ? MessageSendSuperStretFn : MessageSendStretFn; std::vector Params(3); Params[0] = llvm::PointerType::getUnqual(ReturnTy); diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 5054b56d21..f5eba15a24 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -138,6 +138,10 @@ public: const FunctionArgList &Args); void FinishFunction(SourceLocation EndLoc=SourceLocation()); + /// ReturnTypeUsesSret - Return true iff the given type uses 'sret' + /// when used as a return type. + bool ReturnTypeUsesSret(QualType RetTy); + /// 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. -- 2.40.0