From a729c62b81df17a1630de6b8f0709960bee9bc70 Mon Sep 17 00:00:00 2001 From: John McCall Date: Fri, 17 Feb 2012 03:33:10 +0000 Subject: Whether an argument is required (in contrast with being an optional argument passed through the variadic ellipsis) potentially affects how we need to lower it. Propagate this information down to the various getFunctionInfo(...) overloads on CodeGenTypes. Furthermore, rename those overloads to clarify their distinct purposes, and make sure we're calling the right one in the right place. This has a nice side-effect of making it easier to construct a function type, since the 'variadic' bit is no longer separable. This shouldn't really change anything for our existing platforms, with one minor exception --- we should now call variadic ObjC methods with the ... in the "right place" (see the test case), which I guess matters for anyone running GNUStep on MIPS. Mostly it's just a substantial clean-up. llvm-svn: 150788 --- clang/lib/CodeGen/CGObjCGNU.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'clang/lib/CodeGen/CGObjCGNU.cpp') diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 50ab7d2e385..3e8b528c77f 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -103,8 +103,6 @@ class LazyRuntimeFunction { /// GNUstep). class CGObjCGNU : public CGObjCRuntime { protected: - /// The module that is using this class - CodeGenModule &CGM; /// The LLVM module into which output is inserted llvm::Module &TheModule; /// strut objc_super. Used for sending messages to super. This structure @@ -688,9 +686,9 @@ static std::string SymbolNameForMethod(const StringRef &ClassName, CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned runtimeABIVersion, unsigned protocolClassVersion) - : CGM(cgm), TheModule(CGM.getModule()), VMContext(cgm.getLLVMContext()), - ClassPtrAlias(0), MetaClassPtrAlias(0), RuntimeVersion(runtimeABIVersion), - ProtocolVersion(protocolClassVersion) { + : CGObjCRuntime(cgm), TheModule(CGM.getModule()), + VMContext(cgm.getLLVMContext()), ClassPtrAlias(0), MetaClassPtrAlias(0), + RuntimeVersion(runtimeABIVersion), ProtocolVersion(protocolClassVersion) { msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend"); @@ -1037,9 +1035,7 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGenFunction &CGF, ActualArgs.add(RValue::get(cmd), CGF.getContext().getObjCSelType()); ActualArgs.addFrom(CallArgs); - CodeGenTypes &Types = CGM.getTypes(); - const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs, - FunctionType::ExtInfo()); + MessageSendInfo MSI = getMessageSendInfo(Method, ResultType, ActualArgs); llvm::Value *ReceiverClass = 0; if (isCategoryImpl) { @@ -1092,12 +1088,10 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGenFunction &CGF, Builder.CreateStore(ReceiverClass, Builder.CreateStructGEP(ObjCSuper, 1)); ObjCSuper = EnforceType(Builder, ObjCSuper, PtrToObjCSuperTy); - llvm::FunctionType *impType = - Types.GetFunctionType(FnInfo, Method ? Method->isVariadic() : false); // Get the IMP llvm::Value *imp = LookupIMPSuper(CGF, ObjCSuper, cmd); - imp = EnforceType(Builder, imp, llvm::PointerType::getUnqual(impType)); + imp = EnforceType(Builder, imp, MSI.MessengerType); llvm::Value *impMD[] = { llvm::MDString::get(VMContext, Sel.getAsString()), @@ -1107,8 +1101,7 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGenFunction &CGF, llvm::MDNode *node = llvm::MDNode::get(VMContext, impMD); llvm::Instruction *call; - RValue msgRet = CGF.EmitCall(FnInfo, imp, Return, ActualArgs, - 0, &call); + RValue msgRet = CGF.EmitCall(MSI.CallInfo, imp, Return, ActualArgs, 0, &call); call->setMetadata(msgSendMDKind, node); return msgRet; } @@ -1181,13 +1174,13 @@ CGObjCGNU::GenerateMessageSend(CodeGenFunction &CGF, }; llvm::MDNode *node = llvm::MDNode::get(VMContext, impMD); - CodeGenTypes &Types = CGM.getTypes(); CallArgList ActualArgs; ActualArgs.add(RValue::get(Receiver), ASTIdTy); ActualArgs.add(RValue::get(cmd), CGF.getContext().getObjCSelType()); ActualArgs.addFrom(CallArgs); - const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs, - FunctionType::ExtInfo()); + + MessageSendInfo MSI = getMessageSendInfo(Method, ResultType, ActualArgs); + // Get the IMP to call llvm::Value *imp; @@ -1203,7 +1196,7 @@ CGObjCGNU::GenerateMessageSend(CodeGenFunction &CGF, if (CGM.ReturnTypeUsesFPRet(ResultType)) { imp = CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, true), "objc_msgSend_fpret"); - } else if (CGM.ReturnTypeUsesSRet(FnInfo)) { + } else if (CGM.ReturnTypeUsesSRet(MSI.CallInfo)) { // The actual types here don't matter - we're going to bitcast the // function anyway imp = CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, true), @@ -1217,12 +1210,10 @@ CGObjCGNU::GenerateMessageSend(CodeGenFunction &CGF, // Reset the receiver in case the lookup modified it ActualArgs[0] = CallArg(RValue::get(Receiver), ASTIdTy, false); - llvm::FunctionType *impType = - Types.GetFunctionType(FnInfo, Method ? Method->isVariadic() : false); - imp = EnforceType(Builder, imp, llvm::PointerType::getUnqual(impType)); + imp = EnforceType(Builder, imp, MSI.MessengerType); llvm::Instruction *call; - RValue msgRet = CGF.EmitCall(FnInfo, imp, Return, ActualArgs, + RValue msgRet = CGF.EmitCall(MSI.CallInfo, imp, Return, ActualArgs, 0, &call); call->setMetadata(msgSendMDKind, node); @@ -2418,7 +2409,7 @@ llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD, CodeGenTypes &Types = CGM.getTypes(); llvm::FunctionType *MethodTy = - Types.GetFunctionType(Types.getFunctionInfo(OMD), OMD->isVariadic()); + Types.GetFunctionType(Types.arrangeObjCMethodDeclaration(OMD)); std::string FunctionName = SymbolNameForMethod(ClassName, CategoryName, MethodName, isClassMethod); -- cgit v1.2.3