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
This commit is contained in:
David Chisnall 2010-12-26 22:13:16 +00:00
parent 9ae2d05d45
commit 168b80f2c0
4 changed files with 57 additions and 23 deletions

View File

@ -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);

View File

@ -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<llvm::Constant*> 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<llvm::IntegerType>(
CGM.getTypes().ConvertType(CGM.getContext().LongTy));
SizeTy = cast<llvm::IntegerType>(
CGM.getTypes().ConvertType(CGM.getContext().getSizeType()));
PtrDiffTy = cast<llvm::IntegerType>(
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<const llvm::Type*> 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<llvm::Constant*> 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<llvm::Constant*> ProtocolElements;
@ -1821,8 +1828,6 @@ llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD,
llvm::Function *CGObjCGNU::GetPropertyGetFunction() {
std::vector<const llvm::Type*> 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<const llvm::Type*> 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<const llvm::Type*> 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<llvm::Function>(CGM.CreateRuntimeFunction(FTy,
"objc_getPropertyStruct"));
}
llvm::Function *CGObjCGNU::GetSetStructFunction() {
std::vector<const llvm::Type*> 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<llvm::Function>(CGM.CreateRuntimeFunction(FTy,
"objc_setPropertyStruct"));
}
llvm::Constant *CGObjCGNU::EnumerationMutationFunction() {

View File

@ -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();
}

View File

@ -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.