From: Fariborz Jahanian Date: Sun, 8 Mar 2009 20:18:37 +0000 (+0000) Subject: Code refactoring. No functional change. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b21f07e056b6c9918bf938f19ca561c60f778695;p=clang Code refactoring. No functional change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66391 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index ece675f0c8..44d56b5a60 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -425,6 +425,10 @@ protected: /// description, creating an empty one if it has not been /// defined. The return value has type ProtocolPtrTy. llvm::Constant *GetProtocolRef(const ObjCProtocolDecl *PD); + + /// GetIvarBaseOffset - returns ivars byte offset. + uint64_t GetIvarBaseOffset(const llvm::StructLayout *Layout, + FieldDecl *Field); public: CGObjCCommonMac(CodeGen::CodeGenModule &cgm) : CGM(cgm) @@ -1706,13 +1710,7 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID, const RecordDecl *RD = GetFirstIvarInRecord(OID, ifield, pfield); for (RecordDecl::field_iterator e = RD->field_end(); ifield != e; ++ifield) { FieldDecl *Field = *ifield; - unsigned Offset; - if (Field->isBitField()) - // Bit field staring offset is cached in FieldInfo[Field]. - Offset = CGM.getTypes().getLLVMFieldNo(Field); - else - Offset = Layout->getElementOffset(CGM.getTypes(). - getLLVMFieldNo(Field)); + uint64_t Offset = GetIvarBaseOffset(Layout, Field); if (Field->getIdentifier()) Ivar[0] = GetMethodVarName(Field->getIdentifier()); else @@ -1830,6 +1828,14 @@ llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD, return Method; } +uint64_t CGObjCCommonMac::GetIvarBaseOffset(const llvm::StructLayout *Layout, + FieldDecl *Field) { + return Field->isBitField() + ? CGM.getTypes().getLLVMFieldNo(Field) + : Layout->getElementOffset( + CGM.getTypes().getLLVMFieldNo(Field)); +} + llvm::Function *CGObjCMac::ModuleInitFunction() { // Abuse this interface function as a place to finalize. FinishModule(); @@ -2272,10 +2278,7 @@ llvm::Value *CGObjCMac::EmitIvarOffset(CodeGen::CodeGenFunction &CGF, const llvm::StructLayout *Layout = CGM.getTargetData().getStructLayout(cast(InterfaceLTy)); FieldDecl *Field = Interface->lookupFieldDeclForIvar(CGM.getContext(), Ivar); - uint64_t Offset = - Field->isBitField() ? CGM.getTypes().getLLVMFieldNo(Field) : - Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field)); - + uint64_t Offset = GetIvarBaseOffset(Layout, Field); return llvm::ConstantInt::get( CGM.getTypes().ConvertType(CGM.getContext().LongTy), Offset); @@ -3847,17 +3850,12 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { const llvm::Type *FieldTy = CGM.getTypes().ConvertTypeForMem(Field->getType()); unsigned Size = CGM.getTargetData().getTypePaddedSize(FieldTy); - uint64_t Offset = - Field->isBitField() ? CGM.getTypes().getLLVMFieldNo(Field) : - Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field)); - InstanceSize = Offset + Size; + InstanceSize = GetIvarBaseOffset(Layout, Field) + Size; if (firstField == RD->field_end()) InstanceStart = InstanceSize; else { Field = *firstField; - InstanceStart = - Field->isBitField() ? CGM.getTypes().getLLVMFieldNo(Field) : - Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field)); + InstanceStart = GetIvarBaseOffset(Layout, Field); } } } @@ -4160,13 +4158,7 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList( for (RecordDecl::field_iterator e = RD->field_end(); i != e; ++i) { FieldDecl *Field = *i; - unsigned long offset; - if (Field->isBitField()) - // Bit field starting offset is cached in FieldInfo[Field]. - offset = CGM.getTypes().getLLVMFieldNo(Field); - else - offset = Layout->getElementOffset(CGM.getTypes(). - getLLVMFieldNo(Field)); + uint64_t offset = GetIvarBaseOffset(Layout, Field); const ObjCIvarDecl *ivarDecl = *I++; Ivar[0] = EmitIvarOffsetVar(ID->getClassInterface(), ivarDecl, offset); if (Field->getIdentifier())