From 168b80f2c0461fded7eb46494e158fa6b71948e4 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Sun, 26 Dec 2010 22:13:16 +0000 Subject: [PATCH] Add support for GNU runtime property set / get structure functions. Minor refactoring of Mac runtime (returns the same function for both, as the Mac runtimes currently only provide a single entry point for setting and getting struct properties, although this will presumably be fixed at some point). llvm-svn: 122569 --- clang/lib/CodeGen/CGObjC.cpp | 8 ++--- clang/lib/CodeGen/CGObjCGNU.cpp | 53 +++++++++++++++++++++++-------- clang/lib/CodeGen/CGObjCMac.cpp | 13 ++++++-- clang/lib/CodeGen/CGObjCRuntime.h | 6 ++-- 4 files changed, 57 insertions(+), 23 deletions(-) diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index 91042dae4b34..456aceda69f1 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -222,11 +222,11 @@ void CodeGenFunction::GenerateObjCGetter(ObjCImplementationDecl *IMP, bool IsStrong = false; if ((IsAtomic || (IsStrong = IvarTypeWithAggrGCObjects(Ivar->getType()))) && CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect - && CGM.getObjCRuntime().GetCopyStructFunction()) { + && CGM.getObjCRuntime().GetGetStructFunction()) { LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), Ivar, 0); llvm::Value *GetCopyStructFn = - CGM.getObjCRuntime().GetCopyStructFunction(); + CGM.getObjCRuntime().GetGetStructFunction(); CodeGenTypes &Types = CGM.getTypes(); // objc_copyStruct (ReturnValue, &structIvar, // sizeof (Type of Ivar), isAtomic, false); @@ -353,11 +353,11 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP, } else if (IsAtomic && hasAggregateLLVMType(Ivar->getType()) && !Ivar->getType()->isAnyComplexType() && IndirectObjCSetterArg(*CurFnInfo) - && CGM.getObjCRuntime().GetCopyStructFunction()) { + && CGM.getObjCRuntime().GetSetStructFunction()) { // objc_copyStruct (&structIvar, &Arg, // sizeof (struct something), true, false); llvm::Value *GetCopyStructFn = - CGM.getObjCRuntime().GetCopyStructFunction(); + CGM.getObjCRuntime().GetSetStructFunction(); CodeGenTypes &Types = CGM.getTypes(); CallArgList Args; LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), Ivar, 0); diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 6551fb90e244..6f8bdc1060e7 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -62,7 +62,10 @@ private: const llvm::IntegerType *IntTy; const llvm::PointerType *PtrTy; const llvm::IntegerType *LongTy; + const llvm::IntegerType *SizeTy; + const llvm::IntegerType *PtrDiffTy; const llvm::PointerType *PtrToIntTy; + const llvm::Type *BoolTy; llvm::GlobalAlias *ClassPtrAlias; llvm::GlobalAlias *MetaClassPtrAlias; std::vector Classes; @@ -179,7 +182,8 @@ public: virtual llvm::Function *ModuleInitFunction(); virtual llvm::Function *GetPropertyGetFunction(); virtual llvm::Function *GetPropertySetFunction(); - virtual llvm::Function *GetCopyStructFunction(); + virtual llvm::Function *GetSetStructFunction(); + virtual llvm::Function *GetGetStructFunction(); virtual llvm::Constant *EnumerationMutationFunction(); virtual void EmitTryStmt(CodeGen::CodeGenFunction &CGF, @@ -273,6 +277,11 @@ CGObjCGNU::CGObjCGNU(CodeGen::CodeGenModule &cgm) CGM.getTypes().ConvertType(CGM.getContext().IntTy)); LongTy = cast( CGM.getTypes().ConvertType(CGM.getContext().LongTy)); + SizeTy = cast( + CGM.getTypes().ConvertType(CGM.getContext().getSizeType())); + PtrDiffTy = cast( + CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType())); + BoolTy = CGM.getTypes().ConvertType(CGM.getContext().BoolTy); Int8Ty = llvm::Type::getInt8Ty(VMContext); // C string type. Used in lots of places. @@ -318,8 +327,7 @@ CGObjCGNU::CGObjCGNU(CodeGen::CodeGenModule &cgm) // id objc_assign_ivar(id, id, ptrdiff_t); std::vector Args(1, IdTy); Args.push_back(PtrToIdTy); - // FIXME: ptrdiff_t - Args.push_back(LongTy); + Args.push_back(PtrDiffTy); llvm::FunctionType *FTy = llvm::FunctionType::get(IdTy, Args, false); IvarAssignFn = CGM.CreateRuntimeFunction(FTy, "objc_assign_ivar"); // id objc_assign_strongCast (id, id*) @@ -342,8 +350,7 @@ CGObjCGNU::CGObjCGNU(CodeGen::CodeGenModule &cgm) Args.clear(); Args.push_back(PtrToInt8Ty); Args.push_back(PtrToInt8Ty); - // FIXME: size_t - Args.push_back(LongTy); + Args.push_back(SizeTy); FTy = llvm::FunctionType::get(IdTy, Args, false); MemMoveFn = CGM.CreateRuntimeFunction(FTy, "objc_memmove_collectable"); } @@ -995,7 +1002,7 @@ llvm::Constant *CGObjCGNU::GenerateProtocolList( Protocols.size()); llvm::StructType *ProtocolListTy = llvm::StructType::get(VMContext, PtrTy, //Should be a recurisve pointer, but it's always NULL here. - LongTy,//FIXME: Should be size_t + SizeTy, ProtocolArrayTy, NULL); std::vector Elements; @@ -1250,7 +1257,7 @@ void CGObjCGNU::GenerateProtocolHolderCategory(void) { ExistingProtocols.size()); llvm::StructType *ProtocolListTy = llvm::StructType::get(VMContext, PtrTy, //Should be a recurisve pointer, but it's always NULL here. - LongTy,//FIXME: Should be size_t + SizeTy, ProtocolArrayTy, NULL); std::vector ProtocolElements; @@ -1821,8 +1828,6 @@ llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD, llvm::Function *CGObjCGNU::GetPropertyGetFunction() { std::vector Params; - const llvm::Type *BoolTy = - CGM.getTypes().ConvertType(CGM.getContext().BoolTy); Params.push_back(IdTy); Params.push_back(SelectorTy); Params.push_back(IntTy); @@ -1836,8 +1841,6 @@ llvm::Function *CGObjCGNU::GetPropertyGetFunction() { llvm::Function *CGObjCGNU::GetPropertySetFunction() { std::vector Params; - const llvm::Type *BoolTy = - CGM.getTypes().ConvertType(CGM.getContext().BoolTy); Params.push_back(IdTy); Params.push_back(SelectorTy); Params.push_back(IntTy); @@ -1851,9 +1854,31 @@ llvm::Function *CGObjCGNU::GetPropertySetFunction() { "objc_setProperty")); } -// FIXME. Implement this. -llvm::Function *CGObjCGNU::GetCopyStructFunction() { - return 0; +llvm::Function *CGObjCGNU::GetGetStructFunction() { + std::vector Params; + Params.push_back(PtrTy); + Params.push_back(PtrTy); + Params.push_back(PtrDiffTy); + Params.push_back(BoolTy); + Params.push_back(BoolTy); + // objc_setPropertyStruct (void*, void*, ptrdiff_t, BOOL, BOOL) + const llvm::FunctionType *FTy = + llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Params, false); + return cast(CGM.CreateRuntimeFunction(FTy, + "objc_getPropertyStruct")); +} +llvm::Function *CGObjCGNU::GetSetStructFunction() { + std::vector Params; + Params.push_back(PtrTy); + Params.push_back(PtrTy); + Params.push_back(PtrDiffTy); + Params.push_back(BoolTy); + Params.push_back(BoolTy); + // objc_setPropertyStruct (void*, void*, ptrdiff_t, BOOL, BOOL) + const llvm::FunctionType *FTy = + llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Params, false); + return cast(CGM.CreateRuntimeFunction(FTy, + "objc_setPropertyStruct")); } llvm::Constant *CGObjCGNU::EnumerationMutationFunction() { diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index a1b029c3206e..66913c8ee28c 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -1157,7 +1157,8 @@ public: virtual llvm::Constant *GetPropertyGetFunction(); virtual llvm::Constant *GetPropertySetFunction(); - virtual llvm::Constant *GetCopyStructFunction(); + virtual llvm::Constant *GetGetStructFunction(); + virtual llvm::Constant *GetSetStructFunction(); virtual llvm::Constant *EnumerationMutationFunction(); virtual void EmitTryStmt(CodeGen::CodeGenFunction &CGF, @@ -1402,7 +1403,10 @@ public: return ObjCTypes.getSetPropertyFn(); } - virtual llvm::Constant *GetCopyStructFunction() { + virtual llvm::Constant *GetSetStructFunction() { + return ObjCTypes.getCopyStructFn(); + } + virtual llvm::Constant *GetGetStructFunction() { return ObjCTypes.getCopyStructFn(); } @@ -2584,7 +2588,10 @@ llvm::Constant *CGObjCMac::GetPropertySetFunction() { return ObjCTypes.getSetPropertyFn(); } -llvm::Constant *CGObjCMac::GetCopyStructFunction() { +llvm::Constant *CGObjCMac::GetGetStructFunction() { + return ObjCTypes.getCopyStructFn(); +} +llvm::Constant *CGObjCMac::GetSetStructFunction() { return ObjCTypes.getCopyStructFn(); } diff --git a/clang/lib/CodeGen/CGObjCRuntime.h b/clang/lib/CodeGen/CGObjCRuntime.h index c9b0c6d10c79..47200402302a 100644 --- a/clang/lib/CodeGen/CGObjCRuntime.h +++ b/clang/lib/CodeGen/CGObjCRuntime.h @@ -176,8 +176,10 @@ public: /// Return the runtime function for setting properties. virtual llvm::Constant *GetPropertySetFunction() = 0; - // API for atomic copying of qualified aggregates in setter/getter. - virtual llvm::Constant *GetCopyStructFunction() = 0; + // API for atomic copying of qualified aggregates in getter. + virtual llvm::Constant *GetGetStructFunction() = 0; + // API for atomic copying of qualified aggregates in setter. + virtual llvm::Constant *GetSetStructFunction() = 0; /// GetClass - Return a reference to the class for the given /// interface decl.