From ca6408c3176783f0b29da4679a08512aa05f0c73 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sat, 12 Sep 2009 00:59:20 +0000 Subject: [PATCH] Change CodeGenModule::ConstructTypeAttributes to return the calling convention to use, and allow the ABI implementation to override the calling convention. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81593 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 15 +++++++++------ lib/CodeGen/CGCall.h | 18 +++++++++++++++++- lib/CodeGen/CodeGenModule.cpp | 13 +++++-------- lib/CodeGen/CodeGenModule.h | 12 +++++++++++- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index fcaa49e129..c63dab16a1 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -156,7 +156,8 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy, CGFunctionInfo::CGFunctionInfo(unsigned _CallingConvention, QualType ResTy, const llvm::SmallVector &ArgTys) - : CallingConvention(_CallingConvention) + : CallingConvention(_CallingConvention), + EffectiveCallingConvention(_CallingConvention) { NumArgs = ArgTys.size(); Args = new ArgInfo[1 + NumArgs]; @@ -404,10 +405,13 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI, bool IsVariadic) { void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, const Decl *TargetDecl, - AttributeListType &PAL) { + AttributeListType &PAL, + unsigned &CallingConv) { unsigned FuncAttrs = 0; unsigned RetAttrs = 0; + CallingConv = FI.getEffectiveCallingConvention(); + // FIXME: handle sseregparm someday... if (TargetDecl) { if (TargetDecl->hasAttr()) @@ -835,8 +839,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, llvm::BasicBlock *InvokeDest = getInvokeDest(); + unsigned CallingConv; CodeGen::AttributeListType AttributeList; - CGM.ConstructAttributeList(CallInfo, TargetDecl, AttributeList); + CGM.ConstructAttributeList(CallInfo, TargetDecl, AttributeList, CallingConv); llvm::AttrListPtr Attrs = llvm::AttrListPtr::get(AttributeList.begin(), AttributeList.end()); @@ -851,9 +856,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, } CS.setAttributes(Attrs); - llvm::CallingConv::ID CC = - static_cast(CallInfo.getCallingConvention()); - CS.setCallingConv(CC); + CS.setCallingConv(static_cast(CallingConv)); // If the call doesn't return, finish the basic block and clear the // insertion point; this allows the rest of IRgen to discard diff --git a/lib/CodeGen/CGCall.h b/lib/CodeGen/CGCall.h index 53432a2a9e..ebf801dcaa 100644 --- a/lib/CodeGen/CGCall.h +++ b/lib/CodeGen/CGCall.h @@ -60,9 +60,14 @@ namespace CodeGen { ABIArgInfo info; }; - /// The LLVM::CallingConv to use for this function. + /// The LLVM::CallingConv to use for this function (as specified by the + /// user). unsigned CallingConvention; + /// The LLVM::CallingConv to actually use for this function, which may + /// depend on the ABI. + unsigned EffectiveCallingConvention; + unsigned NumArgs; ArgInfo *Args; @@ -82,8 +87,19 @@ namespace CodeGen { unsigned arg_size() const { return NumArgs; } + /// getCallingConvention - Return the user specified calling + /// convention. unsigned getCallingConvention() const { return CallingConvention; } + /// getEffectiveCallingConvention - Return the actual calling convention to + /// use, which may depend on the ABI. + unsigned getEffectiveCallingConvention() const { + return EffectiveCallingConvention; + } + void setEffectiveCallingConvention(unsigned Value) { + EffectiveCallingConvention = Value; + } + QualType getReturnType() const { return Args[0].type; } ABIArgInfo &getReturnInfo() { return Args[0].info; } diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index ae7a8b1dcb..5dfc4bc1b9 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -337,15 +337,12 @@ void CodeGenModule::SetFunctionDefinitionAttributes(const FunctionDecl *D, void CodeGenModule::SetLLVMFunctionAttributes(const Decl *D, const CGFunctionInfo &Info, llvm::Function *F) { + unsigned CallingConv; AttributeListType AttributeList; - ConstructAttributeList(Info, D, AttributeList); - + ConstructAttributeList(Info, D, AttributeList, CallingConv); F->setAttributes(llvm::AttrListPtr::get(AttributeList.begin(), - AttributeList.size())); - - llvm::CallingConv::ID CC = - static_cast(Info.getCallingConvention()); - F->setCallingConv(CC); + AttributeList.size())); + F->setCallingConv(static_cast(CallingConv)); } void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, @@ -1101,8 +1098,8 @@ static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old, ArgList.clear(); if (NewCall->getType() != llvm::Type::getVoidTy(Old->getContext())) NewCall->takeName(CI); - NewCall->setCallingConv(CI->getCallingConv()); NewCall->setAttributes(CI->getAttributes()); + NewCall->setCallingConv(CI->getCallingConv()); // Finally, remove the old call, replacing any uses with the new one. if (!CI->use_empty()) diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index aa92269406..fa32aaf7ef 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -384,9 +384,19 @@ public: /// as a return type. bool ReturnTypeUsesSret(const CGFunctionInfo &FI); + /// ConstructAttributeList - Get the LLVM attributes and calling convention to + /// use for a particular function type. + /// + /// \param Info - The function type information. + /// \param TargetDecl - The decl these attributes are being constructed + /// for. If supplied the attributes applied to this decl may contribute to the + /// function attributes and calling convention. + /// \param PAL [out] - On return, the attribute list to use. + /// \param CallingConv [out] - On return, the LLVM calling convention to use. void ConstructAttributeList(const CGFunctionInfo &Info, const Decl *TargetDecl, - AttributeListType &PAL); + AttributeListType &PAL, + unsigned &CallingConv); const char *getMangledName(const GlobalDecl &D); -- 2.40.0