From 21e6f176015f8ffa0f162618c03f6d63746361ef Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 11 Mar 2009 21:42:00 +0000 Subject: [PATCH] Code refactoring. No change in functionality. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66710 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCMac.cpp | 46 +++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 48ea99ef7d..045cde248c 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -416,11 +416,15 @@ protected: /// name. The return value has type char *. llvm::Constant *GetClassName(IdentifierInfo *Ident); + /// GetInterfaceDeclStructLayout - Get layout for ivars of given + /// interface declaration. + const llvm::StructLayout *GetInterfaceDeclStructLayout( + const ObjCInterfaceDecl *ID) const; + /// BuildIvarLayout - Builds ivar layout bitmap for the class /// implementation for the __strong or __weak case. /// - llvm::Constant *BuildIvarLayout(const llvm::StructLayout *Layout, - ObjCImplementationDecl *OI, + llvm::Constant *BuildIvarLayout(ObjCImplementationDecl *OI, bool ForStrongLayout, const ObjCCommonTypesHelper &ObjCTypes); @@ -1706,10 +1710,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID, ObjCInterfaceDecl *OID = const_cast(ID->getClassInterface()); - const llvm::Type *InterfaceTy = - CGM.getTypes().ConvertType(CGM.getContext().getObjCInterfaceType(OID)); - const llvm::StructLayout *Layout = - CGM.getTargetData().getStructLayout(cast(InterfaceTy)); + const llvm::StructLayout *Layout = GetInterfaceDeclStructLayout(OID); RecordDecl::field_iterator ifield, pfield; const RecordDecl *RD = GetFirstIvarInRecord(OID, ifield, pfield); @@ -2292,10 +2293,7 @@ LValue CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, llvm::Value *CGObjCMac::EmitIvarOffset(CodeGen::CodeGenFunction &CGF, ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar) { - const llvm::Type *InterfaceLTy = - CGM.getTypes().ConvertType(CGM.getContext().getObjCInterfaceType(Interface)); - const llvm::StructLayout *Layout = - CGM.getTargetData().getStructLayout(cast(InterfaceLTy)); + const llvm::StructLayout *Layout = GetInterfaceDeclStructLayout(Interface); FieldDecl *Field = Interface->lookupFieldDeclForIvar(CGM.getContext(), Ivar); uint64_t Offset = GetIvarBaseOffset(Layout, Field); return llvm::ConstantInt::get( @@ -2462,6 +2460,19 @@ llvm::Constant *CGObjCCommonMac::GetClassName(IdentifierInfo *Ident) { return getConstantGEP(Entry, 0, 0); } +/// GetInterfaceDeclStructLayout - Get layout for ivars of given +/// interface declaration. +const llvm::StructLayout *CGObjCCommonMac::GetInterfaceDeclStructLayout( + const ObjCInterfaceDecl *OID) const { + const llvm::Type *InterfaceTy = + CGM.getTypes().ConvertType( + CGM.getContext().getObjCInterfaceType( + const_cast(OID))); + const llvm::StructLayout *Layout = + CGM.getTargetData().getStructLayout(cast(InterfaceTy)); + return Layout; +} + /// GetIvarLayoutName - Returns a unique constant for the given /// ivar layout bitmap. llvm::Constant *CGObjCCommonMac::GetIvarLayoutName(IdentifierInfo *Ident, @@ -2666,7 +2677,6 @@ IvarBytePosCompare (const void *a, const void *b) /// - __weak anything /// llvm::Constant *CGObjCCommonMac::BuildIvarLayout( - const llvm::StructLayout *Layout, ObjCImplementationDecl *OMD, bool ForStrongLayout, const ObjCCommonTypesHelper &ObjCTypes) { @@ -2681,7 +2691,8 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout( CGM.getContext().CollectObjCIvars(OI, RecFields); if (RecFields.empty()) return llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy); - + + const llvm::StructLayout *Layout = GetInterfaceDeclStructLayout(OI); BuildAggrIvarLayout (Layout, 0, RecFields, 0, ForStrongLayout, Index, SkIndex, hasUnion); if (Index == -1) @@ -4129,10 +4140,7 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { if (ObjCInterfaceDecl *OID = const_cast(ID->getClassInterface())) { // FIXME. Share this with the one in EmitIvarList. - const llvm::Type *InterfaceTy = - CGM.getTypes().ConvertType(CGM.getContext().buildObjCInterfaceType(OID)); - const llvm::StructLayout *Layout = - CGM.getTargetData().getStructLayout(cast(InterfaceTy)); + const llvm::StructLayout *Layout = GetInterfaceDeclStructLayout(OID); RecordDecl::field_iterator firstField, lastField; const RecordDecl *RD = GetFirstIvarInRecord(OID, firstField, lastField); @@ -4442,11 +4450,7 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList( assert(OID && "CGObjCNonFragileABIMac::EmitIvarList - null interface"); // FIXME. Consolidate this with similar code in GenerateClass. - const llvm::Type *InterfaceTy = - CGM.getTypes().ConvertType(CGM.getContext().getObjCInterfaceType( - const_cast(OID))); - const llvm::StructLayout *Layout = - CGM.getTargetData().getStructLayout(cast(InterfaceTy)); + const llvm::StructLayout *Layout = GetInterfaceDeclStructLayout(OID); RecordDecl::field_iterator i,p; const RecordDecl *RD = GetFirstIvarInRecord(OID, i,p); -- 2.40.0