forked from OSchip/llvm-project
Factor out BuildAggrIvarRecordLayout routine.
llvm-svn: 70777
This commit is contained in:
parent
7abf83cc86
commit
15bd88860c
|
@ -826,6 +826,9 @@ protected:
|
||||||
llvm::Constant *BuildIvarLayout(const ObjCImplementationDecl *OI,
|
llvm::Constant *BuildIvarLayout(const ObjCImplementationDecl *OI,
|
||||||
bool ForStrongLayout);
|
bool ForStrongLayout);
|
||||||
|
|
||||||
|
void BuildAggrIvarRecordLayout(const RecordType *RT,
|
||||||
|
unsigned int BytePos, bool ForStrongLayout,
|
||||||
|
bool &HasUnion);
|
||||||
void BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
|
void BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
|
||||||
const llvm::StructLayout *Layout,
|
const llvm::StructLayout *Layout,
|
||||||
const RecordDecl *RD,
|
const RecordDecl *RD,
|
||||||
|
@ -2907,22 +2910,39 @@ llvm::Constant *CGObjCCommonMac::GetIvarLayoutName(IdentifierInfo *Ident,
|
||||||
return llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy);
|
return llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QualType::GCAttrTypes GetGCAttrTypeForType(QualType FQT) {
|
static QualType::GCAttrTypes GetGCAttrTypeForType(ASTContext &Ctx,
|
||||||
|
QualType FQT) {
|
||||||
if (FQT.isObjCGCStrong())
|
if (FQT.isObjCGCStrong())
|
||||||
return QualType::Strong;
|
return QualType::Strong;
|
||||||
|
|
||||||
if (FQT.isObjCGCWeak())
|
if (FQT.isObjCGCWeak())
|
||||||
return QualType::Weak;
|
return QualType::Weak;
|
||||||
|
|
||||||
if (CGM.getContext().isObjCObjectPointerType(FQT))
|
if (Ctx.isObjCObjectPointerType(FQT))
|
||||||
return QualType::Strong;
|
return QualType::Strong;
|
||||||
|
|
||||||
if (const PointerType *PT = FQT->getAsPointerType())
|
if (const PointerType *PT = FQT->getAsPointerType())
|
||||||
return GetGCAttrTypeForType(PT->getPointeeType());
|
return GetGCAttrTypeForType(Ctx, PT->getPointeeType());
|
||||||
|
|
||||||
return QualType::GCNone;
|
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,
|
void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
|
||||||
const llvm::StructLayout *Layout,
|
const llvm::StructLayout *Layout,
|
||||||
const RecordDecl *RD,
|
const RecordDecl *RD,
|
||||||
|
@ -2944,8 +2964,6 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
|
||||||
unsigned WordSizeInBits = CGM.getContext().Target.getPointerWidth(0);
|
unsigned WordSizeInBits = CGM.getContext().Target.getPointerWidth(0);
|
||||||
unsigned ByteSizeInBits = CGM.getContext().Target.getCharWidth();
|
unsigned ByteSizeInBits = CGM.getContext().Target.getCharWidth();
|
||||||
|
|
||||||
llvm::SmallVector<FieldDecl*, 16> TmpRecFields;
|
|
||||||
|
|
||||||
for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
|
for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
|
||||||
FieldDecl *Field = RecFields[i];
|
FieldDecl *Field = RecFields[i];
|
||||||
// Skip over unnamed or bitfields
|
// Skip over unnamed or bitfields
|
||||||
|
@ -2959,19 +2977,9 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
|
||||||
if (FQT->isUnionType())
|
if (FQT->isUnionType())
|
||||||
HasUnion = true;
|
HasUnion = true;
|
||||||
|
|
||||||
const RecordType *RT = FQT->getAsRecordType();
|
BuildAggrIvarRecordLayout(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),
|
BytePos + GetFieldBaseOffset(OI, Layout, Field),
|
||||||
ForStrongLayout, HasUnion);
|
ForStrongLayout, HasUnion);
|
||||||
TmpRecFields.clear();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2994,21 +3002,11 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
|
||||||
int OldIndex = IvarsInfo.size() - 1;
|
int OldIndex = IvarsInfo.size() - 1;
|
||||||
int OldSkIndex = SkipIvars.size() -1;
|
int OldSkIndex = SkipIvars.size() -1;
|
||||||
|
|
||||||
// FIXME - Use a common routine with the above!
|
|
||||||
const RecordType *RT = FQT->getAsRecordType();
|
const RecordType *RT = FQT->getAsRecordType();
|
||||||
const RecordDecl *RD = RT->getDecl();
|
BuildAggrIvarRecordLayout(RT,
|
||||||
// FIXME - Find a more efficient way of passing records down.
|
BytePos + GetFieldBaseOffset(OI, Layout,
|
||||||
TmpRecFields.append(RD->field_begin(CGM.getContext()),
|
Field),
|
||||||
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);
|
ForStrongLayout, HasUnion);
|
||||||
TmpRecFields.clear();
|
|
||||||
|
|
||||||
// Replicate layout information for each array element. Note that
|
// Replicate layout information for each array element. Note that
|
||||||
// one element is already done.
|
// one element is already done.
|
||||||
|
@ -3028,7 +3026,7 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
|
||||||
}
|
}
|
||||||
// At this point, we are done with Record/Union and array there of.
|
// At this point, we are done with Record/Union and array there of.
|
||||||
// For other arrays we are down to its element type.
|
// 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());
|
unsigned FieldSize = CGM.getContext().getTypeSize(Field->getType());
|
||||||
if ((ForStrongLayout && GCAttr == QualType::Strong)
|
if ((ForStrongLayout && GCAttr == QualType::Strong)
|
||||||
|
@ -3063,6 +3061,7 @@ void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LastFieldBitfield) {
|
if (LastFieldBitfield) {
|
||||||
// Last field was a bitfield. Must update skip info.
|
// Last field was a bitfield. Must update skip info.
|
||||||
Expr *BitWidth = LastFieldBitfield->getBitWidth();
|
Expr *BitWidth = LastFieldBitfield->getBitWidth();
|
||||||
|
|
Loading…
Reference in New Issue