Convert types over to placement new() that takes an ASTContext.

Also changed FunctionTypeProto to be allocated with 8-byte alignment (noticed by Doug). I couldn't think of any reason to allocate on 16-byte boundaries. If anyone remembers why we were doing this, let me know!

llvm-svn: 63137
This commit is contained in:
Steve Naroff 2009-01-27 22:08:43 +00:00
parent f041127bda
commit 096bab711e
1 changed files with 30 additions and 57 deletions

View File

@ -177,8 +177,7 @@ void ASTContext::PrintStats() const {
void ASTContext::InitBuiltinType(QualType &R, BuiltinType::Kind K) {
void *Mem = Allocator.Allocate(sizeof(BuiltinType), 8);
Types.push_back((R = QualType(new (Mem) BuiltinType(K),0)).getTypePtr());
Types.push_back((R = QualType(new (*this,8) BuiltinType(K),0)).getTypePtr());
}
void ASTContext::InitBuiltinTypes() {
@ -733,8 +732,8 @@ QualType ASTContext::getASQualType(QualType T, unsigned AddressSpace) {
ASQualType *NewIP = ASQualTypes.FindNodeOrInsertPos(ID, InsertPos);
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(ASQualType), 8);
ASQualType *New = new (Mem) ASQualType(T.getTypePtr(), Canonical, AddressSpace);
ASQualType *New = new (*this, 8) ASQualType(T.getTypePtr(), Canonical,
AddressSpace);
ASQualTypes.InsertNode(New, InsertPos);
Types.push_back(New);
return QualType(New, T.getCVRQualifiers());
@ -763,8 +762,7 @@ QualType ASTContext::getComplexType(QualType T) {
ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos);
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(ComplexType), 8);
ComplexType *New = new (Mem) ComplexType(T, Canonical);
ComplexType *New = new (*this,8) ComplexType(T, Canonical);
Types.push_back(New);
ComplexTypes.InsertNode(New, InsertPos);
return QualType(New, 0);
@ -793,8 +791,7 @@ QualType ASTContext::getPointerType(QualType T) {
PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos);
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(PointerType), 8);
PointerType *New = new (Mem) PointerType(T, Canonical);
PointerType *New = new (*this,8) PointerType(T, Canonical);
Types.push_back(New);
PointerTypes.InsertNode(New, InsertPos);
return QualType(New, 0);
@ -825,8 +822,7 @@ QualType ASTContext::getBlockPointerType(QualType T) {
BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(BlockPointerType), 8);
BlockPointerType *New = new (Mem) BlockPointerType(T, Canonical);
BlockPointerType *New = new (*this,8) BlockPointerType(T, Canonical);
Types.push_back(New);
BlockPointerTypes.InsertNode(New, InsertPos);
return QualType(New, 0);
@ -855,8 +851,7 @@ QualType ASTContext::getReferenceType(QualType T) {
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(ReferenceType), 8);
ReferenceType *New = new (Mem) ReferenceType(T, Canonical);
ReferenceType *New = new (*this,8) ReferenceType(T, Canonical);
Types.push_back(New);
ReferenceTypes.InsertNode(New, InsertPos);
return QualType(New, 0);
@ -887,8 +882,7 @@ QualType ASTContext::getMemberPointerType(QualType T, const Type *Cls)
MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(MemberPointerType), 8);
MemberPointerType *New = new (Mem) MemberPointerType(T, Cls, Canonical);
MemberPointerType *New = new (*this,8) MemberPointerType(T, Cls, Canonical);
Types.push_back(New);
MemberPointerTypes.InsertNode(New, InsertPos);
return QualType(New, 0);
@ -920,9 +914,8 @@ QualType ASTContext::getConstantArrayType(QualType EltTy,
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(ConstantArrayType), 8);
ConstantArrayType *New =
new (Mem) ConstantArrayType(EltTy, Canonical, ArySize, ASM, EltTypeQuals);
new(*this,8)ConstantArrayType(EltTy, Canonical, ArySize, ASM, EltTypeQuals);
ConstantArrayTypes.InsertNode(New, InsertPos);
Types.push_back(New);
return QualType(New, 0);
@ -936,9 +929,8 @@ QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts,
// Since we don't unique expressions, it isn't possible to unique VLA's
// that have an expression provided for their size.
void *Mem = Allocator.Allocate(sizeof(VariableArrayType), 8);
VariableArrayType *New =
new (Mem) VariableArrayType(EltTy, QualType(), NumElts, ASM, EltTypeQuals);
new(*this,8)VariableArrayType(EltTy,QualType(), NumElts, ASM, EltTypeQuals);
VariableArrayTypes.push_back(New);
Types.push_back(New);
@ -958,10 +950,9 @@ QualType ASTContext::getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
// Since we don't unique expressions, it isn't possible to unique
// dependently-sized array types.
void *Mem = Allocator.Allocate(sizeof(DependentSizedArrayType), 8);
DependentSizedArrayType *New =
new (Mem) DependentSizedArrayType(EltTy, QualType(), NumElts,
ASM, EltTypeQuals);
new (*this,8) DependentSizedArrayType(EltTy, QualType(), NumElts,
ASM, EltTypeQuals);
DependentSizedArrayTypes.push_back(New);
Types.push_back(New);
@ -993,8 +984,7 @@ QualType ASTContext::getIncompleteArrayType(QualType EltTy,
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(IncompleteArrayType), 8);
IncompleteArrayType *New = new (Mem) IncompleteArrayType(EltTy, Canonical,
IncompleteArrayType *New = new (*this,8) IncompleteArrayType(EltTy, Canonical,
ASM, EltTypeQuals);
IncompleteArrayTypes.InsertNode(New, InsertPos);
@ -1027,8 +1017,7 @@ QualType ASTContext::getVectorType(QualType vecType, unsigned NumElts) {
VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos);
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(VectorType), 8);
VectorType *New = new (Mem) VectorType(vecType, NumElts, Canonical);
VectorType *New = new (*this,8) VectorType(vecType, NumElts, Canonical);
VectorTypes.InsertNode(New, InsertPos);
Types.push_back(New);
return QualType(New, 0);
@ -1059,8 +1048,7 @@ QualType ASTContext::getExtVectorType(QualType vecType, unsigned NumElts) {
VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos);
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(ExtVectorType), 8);
ExtVectorType *New = new (Mem) ExtVectorType(vecType, NumElts, Canonical);
ExtVectorType *New = new (*this,8) ExtVectorType(vecType, NumElts, Canonical);
VectorTypes.InsertNode(New, InsertPos);
Types.push_back(New);
return QualType(New, 0);
@ -1089,8 +1077,7 @@ QualType ASTContext::getFunctionTypeNoProto(QualType ResultTy) {
assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP;
}
void *Mem = Allocator.Allocate(sizeof(FunctionTypeNoProto), 8);
FunctionTypeNoProto *New = new (Mem) FunctionTypeNoProto(ResultTy, Canonical);
FunctionTypeNoProto *New =new(*this,8)FunctionTypeNoProto(ResultTy,Canonical);
Types.push_back(New);
FunctionTypeNoProtos.InsertNode(New, InsertPos);
return QualType(New, 0);
@ -1138,10 +1125,9 @@ QualType ASTContext::getFunctionType(QualType ResultTy,const QualType *ArgArray,
// FunctionTypeProto objects are allocated with extra bytes after them
// for a variable size array (for parameter types) at the end of them.
// FIXME: Can we do better than forcing a 16-byte alignment?
FunctionTypeProto *FTP =
(FunctionTypeProto*)Allocator.Allocate(sizeof(FunctionTypeProto) +
NumArgs*sizeof(QualType), 16);
NumArgs*sizeof(QualType), 8);
new (FTP) FunctionTypeProto(ResultTy, ArgArray, NumArgs, isVariadic,
TypeQuals, Canonical);
Types.push_back(FTP);
@ -1165,26 +1151,20 @@ QualType ASTContext::getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl) {
if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(Decl)) {
if (PrevDecl)
Decl->TypeForDecl = PrevDecl->TypeForDecl;
else {
void *Mem = Allocator.Allocate(sizeof(CXXRecordType), 8);
Decl->TypeForDecl = new (Mem) CXXRecordType(CXXRecord);
}
else
Decl->TypeForDecl = new (*this,8) CXXRecordType(CXXRecord);
}
else if (RecordDecl *Record = dyn_cast<RecordDecl>(Decl)) {
if (PrevDecl)
Decl->TypeForDecl = PrevDecl->TypeForDecl;
else {
void *Mem = Allocator.Allocate(sizeof(RecordType), 8);
Decl->TypeForDecl = new (Mem) RecordType(Record);
}
else
Decl->TypeForDecl = new (*this,8) RecordType(Record);
}
else if (EnumDecl *Enum = dyn_cast<EnumDecl>(Decl)) {
if (PrevDecl)
Decl->TypeForDecl = PrevDecl->TypeForDecl;
else {
void *Mem = Allocator.Allocate(sizeof(EnumType), 8);
Decl->TypeForDecl = new (Mem) EnumType(Enum);
}
else
Decl->TypeForDecl = new (*this,8) EnumType(Enum);
}
else
assert(false && "TypeDecl without a type?");
@ -1199,8 +1179,7 @@ QualType ASTContext::getTypedefType(TypedefDecl *Decl) {
if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
QualType Canonical = getCanonicalType(Decl->getUnderlyingType());
void *Mem = Allocator.Allocate(sizeof(TypedefType), 8);
Decl->TypeForDecl = new (Mem) TypedefType(Type::TypeName, Decl, Canonical);
Decl->TypeForDecl = new(*this,8) TypedefType(Type::TypeName, Decl, Canonical);
Types.push_back(Decl->TypeForDecl);
return QualType(Decl->TypeForDecl, 0);
}
@ -1209,8 +1188,7 @@ QualType ASTContext::getTypedefType(TypedefDecl *Decl) {
/// for the specified template type parameter declaration.
QualType ASTContext::getTemplateTypeParmType(TemplateTypeParmDecl *Decl) {
if (!Decl->TypeForDecl) {
void *Mem = Allocator.Allocate(sizeof(TemplateTypeParmType), 8);
Decl->TypeForDecl = new (Mem) TemplateTypeParmType(Decl);
Decl->TypeForDecl = new (*this,8) TemplateTypeParmType(Decl);
Types.push_back(Decl->TypeForDecl);
}
return QualType(Decl->TypeForDecl, 0);
@ -1221,8 +1199,7 @@ QualType ASTContext::getTemplateTypeParmType(TemplateTypeParmDecl *Decl) {
QualType ASTContext::getObjCInterfaceType(ObjCInterfaceDecl *Decl) {
if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
void *Mem = Allocator.Allocate(sizeof(ObjCInterfaceType), 8);
Decl->TypeForDecl = new (Mem) ObjCInterfaceType(Type::ObjCInterface, Decl);
Decl->TypeForDecl = new(*this,8) ObjCInterfaceType(Type::ObjCInterface, Decl);
Types.push_back(Decl->TypeForDecl);
return QualType(Decl->TypeForDecl, 0);
}
@ -1263,9 +1240,8 @@ QualType ASTContext::getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl,
return QualType(QT, 0);
// No Match;
void *Mem = Allocator.Allocate(sizeof(ObjCQualifiedInterfaceType), 8);
ObjCQualifiedInterfaceType *QType =
new (Mem) ObjCQualifiedInterfaceType(Decl, Protocols, NumProtocols);
new (*this,8) ObjCQualifiedInterfaceType(Decl, Protocols, NumProtocols);
Types.push_back(QType);
ObjCQualifiedInterfaceTypes.InsertNode(QType, InsertPos);
@ -1288,9 +1264,8 @@ QualType ASTContext::getObjCQualifiedIdType(ObjCProtocolDecl **Protocols,
return QualType(QT, 0);
// No Match;
void *Mem = Allocator.Allocate(sizeof(ObjCQualifiedIdType), 8);
ObjCQualifiedIdType *QType =
new (Mem) ObjCQualifiedIdType(Protocols, NumProtocols);
new (*this,8) ObjCQualifiedIdType(Protocols, NumProtocols);
Types.push_back(QType);
ObjCQualifiedIdTypes.InsertNode(QType, InsertPos);
return QualType(QType, 0);
@ -1303,8 +1278,7 @@ QualType ASTContext::getObjCQualifiedIdType(ObjCProtocolDecl **Protocols,
/// on canonical type's (which are always unique).
QualType ASTContext::getTypeOfExpr(Expr *tofExpr) {
QualType Canonical = getCanonicalType(tofExpr->getType());
void *Mem = Allocator.Allocate(sizeof(TypeOfExpr), 8);
TypeOfExpr *toe = new (Mem) TypeOfExpr(tofExpr, Canonical);
TypeOfExpr *toe = new (*this,8) TypeOfExpr(tofExpr, Canonical);
Types.push_back(toe);
return QualType(toe, 0);
}
@ -1316,8 +1290,7 @@ QualType ASTContext::getTypeOfExpr(Expr *tofExpr) {
/// on canonical type's (which are always unique).
QualType ASTContext::getTypeOfType(QualType tofType) {
QualType Canonical = getCanonicalType(tofType);
void *Mem = Allocator.Allocate(sizeof(TypeOfType), 8);
TypeOfType *tot = new (Mem) TypeOfType(tofType, Canonical);
TypeOfType *tot = new (*this,8) TypeOfType(tofType, Canonical);
Types.push_back(tot);
return QualType(tot, 0);
}