diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-03-08 20:18:37 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-03-08 20:18:37 +0000 |
commit | b21f07e056b6c9918bf938f19ca561c60f778695 (patch) | |
tree | 8c44e0cda184892d620c7d9404a4e49bd7b73fb9 /lib/CodeGen/CGObjCMac.cpp | |
parent | 4e9990b63518b9ca63d6585dfbd492f452f794c2 (diff) |
Code refactoring. No functional change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66391 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGObjCMac.cpp')
-rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 42 |
1 files changed, 17 insertions, 25 deletions
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<llvm::StructType>(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()) |