diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-12-10 17:03:06 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-12-10 17:03:06 +0000 |
commit | 0cdc8320779058553b48b3c14875ad44632091d3 (patch) | |
tree | c076465ab9fe88e1cd0aad377137216cfd9e4994 /clang/lib/Serialization | |
parent | 924a8f3573a64797a7080061a586e3b4de8a41ae (diff) | |
download | bcm5719-llvm-0cdc8320779058553b48b3c14875ad44632091d3.tar.gz bcm5719-llvm-0cdc8320779058553b48b3c14875ad44632091d3.zip |
Eliminate the branching in QualType::getTypePtr() by providing a
common base for ExtQuals and Type that stores the underlying type
pointer. This results in a 2% performance win for -emit-llvm on a
typical C file, with 1% memory growth in the AST.
Note that there is an API change in this optimization:
QualType::getTypePtr() can no longer be invoked on a NULL
QualType. If the QualType might be NULL, use
QualType::getTypePtrOrNull(). I've audited all uses of getTypePtr() in
the code base and changed the appropriate uses over to
getTypePtrOrNull().
A future optimization opportunity would be to distinguish between
cast/dyn_cast and cast_or_null/dyn_cast_or_null; for the former, we
could use getTypePtr() rather than getTypePtrOrNull(), to take another
branch out of the cast/dyn_cast implementation.
llvm-svn: 121489
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 4e0a7b783b4..5fe95bfed46 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2772,6 +2772,9 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { } QualType PointeeType = GetType(Record[0]); QualType ClassType = GetType(Record[1]); + if (PointeeType.isNull() || ClassType.isNull()) + return QualType(); + return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); } @@ -4368,7 +4371,10 @@ ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { case NestedNameSpecifier::TypeSpec: case NestedNameSpecifier::TypeSpecWithTemplate: { - Type *T = GetType(Record[Idx++]).getTypePtr(); + Type *T = GetType(Record[Idx++]).getTypePtrOrNull(); + if (!T) + return 0; + bool Template = Record[Idx++]; NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); break; diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 8506f0bdd61..6100d65757c 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -167,7 +167,7 @@ void ASTDeclReader::Visit(Decl *D) { if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) { // if we have a fully initialized TypeDecl, we can safely read its type now. - TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr()); + TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull()); } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { // FunctionDecl's body was written last after all other Stmts/Exprs. if (Record[Idx++]) @@ -443,7 +443,7 @@ void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { VisitObjCContainerDecl(ID); - ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr()); + ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtrOrNull()); ID->setSuperClass(cast_or_null<ObjCInterfaceDecl> (Reader.GetDecl(Record[Idx++]))); |