From: Daniel Dunbar Date: Sun, 3 May 2009 23:31:46 +0000 (+0000) Subject: Avoid recomputing field offsets. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=900c1980de73d17cdc11b108cde7f9b68be1e5bd;p=clang Avoid recomputing field offsets. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70812 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 3731411367..e7733d9786 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -2947,6 +2947,9 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI, FieldDecl *MaxField = 0; FieldDecl *MaxSkippedField = 0; FieldDecl *LastFieldBitfield = 0; + uint64_t MaxFieldOffset = 0; + uint64_t MaxSkippedFieldOffset = 0; + uint64_t LastBitfieldOffset = 0; if (RecFields.empty()) return; @@ -2955,15 +2958,15 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI, for (unsigned i = 0, e = RecFields.size(); i != e; ++i) { FieldDecl *Field = RecFields[i]; + unsigned FieldOffset = GetFieldBaseOffset(OI, Layout, Field); // Skip over unnamed or bitfields if (!Field->getIdentifier() || Field->isBitField()) { LastFieldBitfield = Field; + LastBitfieldOffset = FieldOffset; continue; } - unsigned FieldOffset = GetFieldBaseOffset(OI, Layout, Field); - LastFieldBitfield = 0; QualType FQT = Field->getType(); if (FQT->isRecordType() || FQT->isUnionType()) { @@ -3027,6 +3030,7 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI, if (UnionIvarSize > MaxUnionIvarSize) { MaxUnionIvarSize = UnionIvarSize; MaxField = Field; + MaxFieldOffset = FieldOffset; } } else { IvarsInfo.push_back(GC_IVAR(BytePos + FieldOffset, @@ -3042,6 +3046,7 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI, if (UnionIvarSize > MaxSkippedUnionIvarSize) { MaxSkippedUnionIvarSize = UnionIvarSize; MaxSkippedField = Field; + MaxSkippedFieldOffset = FieldOffset; } } else { // FIXME: Why the asymmetry, we divide by byte size in bits here? @@ -3057,20 +3062,17 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCImplementationDecl *OI, uint64_t BitFieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); GC_IVAR skivar; - skivar.ivar_bytepos = BytePos + GetFieldBaseOffset(OI, Layout, - LastFieldBitfield); + skivar.ivar_bytepos = BytePos + LastBitfieldOffset; skivar.ivar_size = (BitFieldSize / ByteSizeInBits) + ((BitFieldSize % ByteSizeInBits) != 0); SkipIvars.push_back(skivar); } if (MaxField) - IvarsInfo.push_back(GC_IVAR(BytePos + GetFieldBaseOffset(OI, Layout, - MaxField), + IvarsInfo.push_back(GC_IVAR(BytePos + MaxFieldOffset, MaxUnionIvarSize)); if (MaxSkippedField) - SkipIvars.push_back(GC_IVAR(BytePos + GetFieldBaseOffset(OI, Layout, - MaxSkippedField), + SkipIvars.push_back(GC_IVAR(BytePos + MaxSkippedFieldOffset, MaxSkippedUnionIvarSize)); }