diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-05-03 14:10:34 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-05-03 14:10:34 +0000 |
commit | d58edcb49140b4e82f8b1e2f2e6ab35b9d401c99 (patch) | |
tree | bb12be23a2b82cfc8295192546a0c6f6f9bf407d /lib/CodeGen/CGObjCMac.cpp | |
parent | 5e563dd38d6ec9f367cfd4b55d3efaf88a97cc09 (diff) |
Factor out BuildAggrIvarRecordLayout routine.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70777 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGObjCMac.cpp')
-rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 4d84c775d3..13864d7265 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -826,6 +826,9 @@ protected: llvm::Constant *BuildIvarLayout(const ObjCImplementationDecl *OI, bool ForStrongLayout); + void BuildAggrIvarRecordLayout(const RecordType *RT, + unsigned int BytePos, bool ForStrongLayout, + bool &HasUnion); void BuildAggrIvarLayout(const ObjCInterfaceDecl *OI, const llvm::StructLayout *Layout, const RecordDecl *RD, @@ -2907,22 +2910,39 @@ llvm::Constant *CGObjCCommonMac::GetIvarLayoutName(IdentifierInfo *Ident, return llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy); } -static QualType::GCAttrTypes GetGCAttrTypeForType(QualType FQT) { +static QualType::GCAttrTypes GetGCAttrTypeForType(ASTContext &Ctx, + QualType FQT) { if (FQT.isObjCGCStrong()) return QualType::Strong; if (FQT.isObjCGCWeak()) return QualType::Weak; - if (CGM.getContext().isObjCObjectPointerType(FQT)) + if (Ctx.isObjCObjectPointerType(FQT)) return QualType::Strong; if (const PointerType *PT = FQT->getAsPointerType()) - return GetGCAttrTypeForType(PT->getPointeeType()); + return GetGCAttrTypeForType(Ctx, PT->getPointeeType()); return QualType::GCNone; } +void CGObjCCommonMac::BuildAggrIvarRecordLayout(const RecordType *RT, + unsigned int BytePos, + bool ForStrongLayout, + bool &HasUnion) { + const RecordDecl *RD = RT->getDecl(); + // FIXME - Use iterator. + llvm::SmallVector<FieldDecl*, 16> Fields(RD->field_begin(CGM.getContext()), + RD->field_end(CGM.getContext())); + const llvm::Type *Ty = CGM.getTypes().ConvertType(QualType(RT, 0)); + const llvm::StructLayout *RecLayout = + CGM.getTargetData().getStructLayout(cast<llvm::StructType>(Ty)); + + BuildAggrIvarLayout(0, RecLayout, RD, Fields, BytePos, + ForStrongLayout, HasUnion); +} + void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI, const llvm::StructLayout *Layout, const RecordDecl *RD, @@ -2944,8 +2964,6 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI, unsigned WordSizeInBits = CGM.getContext().Target.getPointerWidth(0); unsigned ByteSizeInBits = CGM.getContext().Target.getCharWidth(); - llvm::SmallVector<FieldDecl*, 16> TmpRecFields; - for (unsigned i = 0, e = RecFields.size(); i != e; ++i) { FieldDecl *Field = RecFields[i]; // Skip over unnamed or bitfields @@ -2959,19 +2977,9 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI, if (FQT->isUnionType()) HasUnion = true; - const RecordType *RT = FQT->getAsRecordType(); - const RecordDecl *RD = RT->getDecl(); - // FIXME - Find a more efficient way of passing records down. - TmpRecFields.append(RD->field_begin(CGM.getContext()), - RD->field_end(CGM.getContext())); - const llvm::Type *Ty = CGM.getTypes().ConvertType(FQT); - const llvm::StructLayout *RecLayout = - CGM.getTargetData().getStructLayout(cast<llvm::StructType>(Ty)); - - BuildAggrIvarLayout(0, RecLayout, RD, TmpRecFields, - BytePos + GetFieldBaseOffset(OI, Layout, Field), - ForStrongLayout, HasUnion); - TmpRecFields.clear(); + BuildAggrIvarRecordLayout(FQT->getAsRecordType(), + BytePos + GetFieldBaseOffset(OI, Layout, Field), + ForStrongLayout, HasUnion); continue; } @@ -2994,22 +3002,12 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI, int OldIndex = IvarsInfo.size() - 1; int OldSkIndex = SkipIvars.size() -1; - // FIXME - Use a common routine with the above! const RecordType *RT = FQT->getAsRecordType(); - const RecordDecl *RD = RT->getDecl(); - // FIXME - Find a more efficient way of passing records down. - TmpRecFields.append(RD->field_begin(CGM.getContext()), - RD->field_end(CGM.getContext())); - const llvm::Type *Ty = CGM.getTypes().ConvertType(FQT); - const llvm::StructLayout *RecLayout = - CGM.getTargetData().getStructLayout(cast<llvm::StructType>(Ty)); - - BuildAggrIvarLayout(0, RecLayout, RD, - TmpRecFields, - BytePos + GetFieldBaseOffset(OI, Layout, Field), - ForStrongLayout, HasUnion); - TmpRecFields.clear(); - + BuildAggrIvarRecordLayout(RT, + BytePos + GetFieldBaseOffset(OI, Layout, + Field), + ForStrongLayout, HasUnion); + // Replicate layout information for each array element. Note that // one element is already done. uint64_t ElIx = 1; @@ -3028,7 +3026,7 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI, } // At this point, we are done with Record/Union and array there of. // For other arrays we are down to its element type. - QualType::GCAttrTypes GCAttr = GetGCAttrTypeForType(FQT): + QualType::GCAttrTypes GCAttr = GetGCAttrTypeForType(CGM.getContext(), FQT); unsigned FieldSize = CGM.getContext().getTypeSize(Field->getType()); if ((ForStrongLayout && GCAttr == QualType::Strong) @@ -3063,6 +3061,7 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI, } } } + if (LastFieldBitfield) { // Last field was a bitfield. Must update skip info. Expr *BitWidth = LastFieldBitfield->getBitWidth(); |