From: Fariborz Jahanian Date: Tue, 10 Mar 2009 16:22:08 +0000 (+0000) Subject: More objc2's gc meta-data work related to ivar layout bitmap. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5a10c37a02ac65f88624a29d1f7ad1d196fc7ea;p=clang More objc2's gc meta-data work related to ivar layout bitmap. Work in progress. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66546 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index d33005ef0c..9f3e3035d3 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -307,11 +307,20 @@ public: }; class CGObjCCommonMac : public CodeGen::CGObjCRuntime { + class GC_IVAR { + unsigned int ivar_bytepos; + unsigned int ivar_size; + GC_IVAR() : ivar_bytepos(0), ivar_size(0) {} + }; + protected: CodeGen::CodeGenModule &CGM; // FIXME! May not be needing this after all. unsigned ObjCABI; + llvm::SmallVector SkipIvars; + llvm::SmallVector IvarsInfo; + /// LazySymbols - Symbols to generate a lazy reference for. See /// DefinedSymbols and FinishModule(). std::set LazySymbols; @@ -398,10 +407,12 @@ protected: /// BuildIvarLayout - Builds ivar layout bitmap for the class /// implementation for the __strong or __weak case. /// - llvm::Constant *BuildIvarLayout(ObjCImplementationDecl *OI, + llvm::Constant *BuildIvarLayout(const llvm::StructLayout *Layout, + ObjCImplementationDecl *OI, bool ForStrongLayout); - void BuildAggrIvarLayout(RecordDecl *RD, + void BuildAggrIvarLayout(const llvm::StructLayout *Layout, + const RecordDecl *RD, const std::vector& RecFields, unsigned int BytePos, bool ForStrongLayout, int &Index, int &SkIndex, bool &HasUnion); @@ -2445,10 +2456,46 @@ llvm::Constant *CGObjCCommonMac::GetIvarLayoutName(IdentifierInfo *Ident, return llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy); } -void CGObjCCommonMac::BuildAggrIvarLayout(RecordDecl *RD, +void CGObjCCommonMac::BuildAggrIvarLayout(const llvm::StructLayout *Layout, + const RecordDecl *RD, const std::vector& RecFields, unsigned int BytePos, bool ForStrongLayout, int &Index, int &SkIndex, bool &HasUnion) { + bool is_union = (RD && RD->isUnion()); + unsigned int base = 0; + if (RecFields.empty()) + return; + if (is_union) + base = BytePos + GetIvarBaseOffset(Layout, RecFields[0]); + + for (unsigned i = 0; i < RecFields.size(); i++) { + FieldDecl *Field = RecFields[i]; + // Skip over unnamed or bitfields + if (!Field->getIdentifier() || Field->isBitField()) + continue; + QualType FQT = Field->getType(); + if (FQT->isAggregateType()) { + std::vector NestedRecFields; + if (FQT->isUnionType()) + HasUnion = true; + const RecordType *RT = FQT->getAsRecordType(); + const RecordDecl *RD = RT->getDecl(); + // FIXME - Find a more efficiant way of passing records down. + unsigned j = 0; + for (RecordDecl::field_iterator i = RD->field_begin(), + e = RD->field_end(); i != e; ++i) + NestedRecFields[j++] = (*i); + // FIXME - Is Layout correct? + BuildAggrIvarLayout(Layout, RD, NestedRecFields, + BytePos + GetIvarBaseOffset(Layout, Field), + ForStrongLayout, Index, SkIndex, + HasUnion); + continue; + } + else if (const ArrayType *Array = CGM.getContext().getAsArrayType(FQT)) { + FQT = Array->getElementType(); + } + } return; } @@ -2468,8 +2515,10 @@ void CGObjCCommonMac::BuildAggrIvarLayout(RecordDecl *RD, /// 2. When ForStrongLayout is false, following ivars are scanned: /// - __weak anything /// -llvm::Constant *CGObjCCommonMac::BuildIvarLayout(ObjCImplementationDecl *OMD, - bool ForStrongLayout) { +llvm::Constant *CGObjCCommonMac::BuildIvarLayout( + const llvm::StructLayout *Layout, + ObjCImplementationDecl *OMD, + bool ForStrongLayout) { int iIndex = -1; int iSkIndex = -1; bool hasUnion = false; @@ -2479,7 +2528,7 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout(ObjCImplementationDecl *OMD, CGM.getContext().CollectObjCIvars(OI, RecFields); if (RecFields.empty()) return 0; - BuildAggrIvarLayout (0, RecFields, 0, ForStrongLayout, + BuildAggrIvarLayout (Layout, 0, RecFields, 0, ForStrongLayout, iIndex, iSkIndex, hasUnion); return 0; }