[cfe-commits] r68101 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/CodeGen/CGObjCMac.cpp
Chris Lattner
sabre at nondot.org
Tue Mar 31 01:48:11 PDT 2009
Author: lattner
Date: Tue Mar 31 03:48:01 2009
New Revision: 68101
URL: http://llvm.org/viewvc/llvm-project?rev=68101&view=rev
Log:
fill in temporary smallvectors instead of vectors for performance.
Fix BuildAggrIvarLayout to not access vectors out of range.
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=68101&r1=68100&r2=68101&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Mar 31 03:48:01 2009
@@ -492,7 +492,7 @@
const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D);
const RecordDecl *addRecordToClass(const ObjCInterfaceDecl *D);
void CollectObjCIvars(const ObjCInterfaceDecl *OI,
- std::vector<FieldDecl*> &Fields) const;
+ llvm::SmallVectorImpl<FieldDecl*> &Fields) const;
const FieldDecl *getFieldDecl(const ObjCIvarRefExpr *MRef) {
llvm::DenseMap<const ObjCIvarRefExpr *, const FieldDecl*>::iterator I
= ASTFieldForIvarRef.find(MRef);
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=68101&r1=68100&r2=68101&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Mar 31 03:48:01 2009
@@ -598,21 +598,20 @@
}
void ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI,
- std::vector<FieldDecl*> &Fields) const {
+ llvm::SmallVectorImpl<FieldDecl*> &Fields) const {
const ObjCInterfaceDecl *SuperClass = OI->getSuperClass();
if (SuperClass)
CollectObjCIvars(SuperClass, Fields);
for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
E = OI->ivar_end(); I != E; ++I) {
- ObjCIvarDecl *IVDecl = (*I);
+ ObjCIvarDecl *IVDecl = *I;
if (!IVDecl->isInvalidDecl())
Fields.push_back(cast<FieldDecl>(IVDecl));
}
// look into properties.
for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(),
E = OI->prop_end(); I != E; ++I) {
- ObjCPropertyDecl *PDecl = (*I);
- if (ObjCIvarDecl *IV = PDecl->getPropertyIvarDecl())
+ if (ObjCIvarDecl *IV = (*I)->getPropertyIvarDecl())
Fields.push_back(cast<FieldDecl>(IV));
}
}
@@ -620,12 +619,12 @@
/// addRecordToClass - produces record info. for the class for its
/// ivars and all those inherited.
///
-const RecordDecl *ASTContext::addRecordToClass(const ObjCInterfaceDecl *D)
-{
+const RecordDecl *ASTContext::addRecordToClass(const ObjCInterfaceDecl *D) {
const RecordDecl *&RD = ASTRecordForInterface[D];
if (RD)
return RD;
- std::vector<FieldDecl*> RecFields;
+
+ llvm::SmallVector<FieldDecl*, 32> RecFields;
CollectObjCIvars(D, RecFields);
RecordDecl *NewRD = RecordDecl::Create(*this, TagDecl::TK_struct, 0,
D->getLocation(),
@@ -633,13 +632,13 @@
/// FIXME! Can do collection of ivars and adding to the record while
/// doing it.
for (unsigned int i = 0; i != RecFields.size(); i++) {
- FieldDecl *Field = FieldDecl::Create(*this, NewRD,
- RecFields[i]->getLocation(),
- RecFields[i]->getIdentifier(),
- RecFields[i]->getType(),
- RecFields[i]->getBitWidth(), false);
- NewRD->addDecl(Field);
+ NewRD->addDecl(FieldDecl::Create(*this, NewRD,
+ RecFields[i]->getLocation(),
+ RecFields[i]->getIdentifier(),
+ RecFields[i]->getType(),
+ RecFields[i]->getBitWidth(), false));
}
+
NewRD->completeDefinition(*this);
RD = NewRD;
return RD;
@@ -2401,9 +2400,9 @@
const IdentifierInfo *II = OI->getIdentifier();
S += II->getName();
S += '=';
- std::vector<FieldDecl*> RecFields;
+ llvm::SmallVector<FieldDecl*, 32> RecFields;
CollectObjCIvars(OI, RecFields);
- for (unsigned int i = 0; i != RecFields.size(); i++) {
+ for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
if (RecFields[i]->isBitField())
getObjCEncodingForTypeImpl(RecFields[i]->getType(), S, false, true,
RecFields[i]);
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=68101&r1=68100&r2=68101&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Mar 31 03:48:01 2009
@@ -430,7 +430,7 @@
void BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
const llvm::StructLayout *Layout,
const RecordDecl *RD,
- const std::vector<FieldDecl*>& RecFields,
+ const llvm::SmallVectorImpl<FieldDecl*> &RecFields,
unsigned int BytePos, bool ForStrongLayout,
int &Index, int &SkIndex, bool &HasUnion);
@@ -2530,7 +2530,7 @@
void CGObjCCommonMac::BuildAggrIvarLayout(const ObjCInterfaceDecl *OI,
const llvm::StructLayout *Layout,
const RecordDecl *RD,
- const std::vector<FieldDecl*>& RecFields,
+ const llvm::SmallVectorImpl<FieldDecl*> &RecFields,
unsigned int BytePos, bool ForStrongLayout,
int &Index, int &SkIndex, bool &HasUnion) {
bool IsUnion = (RD && RD->isUnion());
@@ -2538,23 +2538,23 @@
uint64_t MaxSkippedUnionIvarSize = 0;
FieldDecl *MaxField = 0;
FieldDecl *MaxSkippedField = 0;
- unsigned int base = 0;
+ unsigned base = 0;
if (RecFields.empty())
return;
if (IsUnion)
base = BytePos + GetFieldBaseOffset(OI, Layout, RecFields[0]);
- unsigned WordSizeInBits = CGM.getContext().getTypeSize(
- CGM.getContext().VoidPtrTy);
- unsigned ByteSizeInBits = CGM.getContext().getTypeSize(
- CGM.getContext().CharTy);
- for (unsigned i = 0; i < RecFields.size(); i++) {
+ 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
if (!Field->getIdentifier() || Field->isBitField())
continue;
QualType FQT = Field->getType();
if (FQT->isRecordType() || FQT->isUnionType()) {
- std::vector<FieldDecl*> NestedRecFields;
if (FQT->isUnionType())
HasUnion = true;
else
@@ -2564,18 +2564,17 @@
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);
+ TmpRecFields.append(RD->field_begin(), RD->field_end());
// FIXME - Is Layout correct?
- BuildAggrIvarLayout(OI, Layout, RD, NestedRecFields,
+ BuildAggrIvarLayout(OI, Layout, RD, TmpRecFields,
BytePos + GetFieldBaseOffset(OI, Layout, Field),
ForStrongLayout, Index, SkIndex,
HasUnion);
+ TmpRecFields.clear();
continue;
}
- else if (const ArrayType *Array = CGM.getContext().getAsArrayType(FQT)) {
+
+ if (const ArrayType *Array = CGM.getContext().getAsArrayType(FQT)) {
const ConstantArrayType *CArray =
dyn_cast_or_null<ConstantArrayType>(Array);
assert(CArray && "only array with know element size is supported");
@@ -2593,20 +2592,19 @@
int OldIndex = Index;
int OldSkIndex = SkIndex;
- std::vector<FieldDecl*> ElementRecFields;
// FIXME - Use a common routine with the above!
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)
- ElementRecFields[j++] = (*i);
+ TmpRecFields.append(RD->field_begin(), RD->field_end());
+
BuildAggrIvarLayout(OI, Layout, RD,
- ElementRecFields,
+ TmpRecFields,
BytePos + GetFieldBaseOffset(OI, Layout, Field),
ForStrongLayout, Index, SkIndex,
HasUnion);
+ TmpRecFields.clear();
+
// Replicate layout information for each array element. Note that
// one element is already done.
uint64_t ElIx = 1;
@@ -2621,8 +2619,7 @@
IvarsInfo.push_back(gcivar); ++Index;
}
- for (int i = OldSkIndex+1; i <= FirstSkIndex; ++i)
- {
+ for (int i = OldSkIndex+1; i <= FirstSkIndex; ++i) {
GC_IVAR skivar;
skivar.ivar_bytepos = SkipIvars[i].ivar_bytepos + Size*ElIx;
skivar.ivar_size = SkipIvars[i].ivar_size;
@@ -2651,6 +2648,7 @@
break;
}
} while (true);
+
if ((ForStrongLayout && GCAttr == QualType::Strong)
|| (!ForStrongLayout && GCAttr == QualType::Weak)) {
if (IsUnion)
@@ -2694,26 +2692,24 @@
}
}
}
- if (MaxField)
- {
+ if (MaxField) {
GC_IVAR gcivar;
gcivar.ivar_bytepos = BytePos + GetFieldBaseOffset(OI, Layout, MaxField);
gcivar.ivar_size = MaxUnionIvarSize;
IvarsInfo.push_back(gcivar); ++Index;
}
- if (MaxSkippedField)
- {
+
+ if (MaxSkippedField) {
GC_IVAR skivar;
skivar.ivar_bytepos = BytePos +
GetFieldBaseOffset(OI, Layout, MaxSkippedField);
skivar.ivar_size = MaxSkippedUnionIvarSize;
SkipIvars.push_back(skivar); ++SkIndex;
}
- return;
}
static int
-IvarBytePosCompare (const void *a, const void *b)
+IvarBytePosCompare(const void *a, const void *b)
{
unsigned int sa = ((CGObjCCommonMac::GC_IVAR *)a)->ivar_bytepos;
unsigned int sb = ((CGObjCCommonMac::GC_IVAR *)b)->ivar_bytepos;
@@ -2753,17 +2749,18 @@
if (CGM.getLangOptions().getGCMode() == LangOptions::NonGC)
return llvm::Constant::getNullValue(PtrTy);
- std::vector<FieldDecl*> RecFields;
+ llvm::SmallVector<FieldDecl*, 32> RecFields;
const ObjCInterfaceDecl *OI = OMD->getClassInterface();
CGM.getContext().CollectObjCIvars(OI, RecFields);
if (RecFields.empty())
return llvm::Constant::getNullValue(PtrTy);
+
SkipIvars.clear();
IvarsInfo.clear();
const llvm::StructLayout *Layout = GetInterfaceDeclStructLayout(OI);
- BuildAggrIvarLayout (OI, Layout, 0, RecFields, 0, ForStrongLayout,
- Index, SkIndex, hasUnion);
+ BuildAggrIvarLayout(OI, Layout, 0, RecFields, 0, ForStrongLayout,
+ Index, SkIndex, hasUnion);
if (Index == -1)
return llvm::Constant::getNullValue(PtrTy);
More information about the cfe-commits
mailing list