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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121489 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index a42f009..2fe360b 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -63,7 +63,7 @@
}
static CXTypeKind GetTypeKind(QualType T) {
- Type *TP = T.getTypePtr();
+ Type *TP = T.getTypePtrOrNull();
if (!TP)
return CXType_Invalid;
@@ -186,7 +186,7 @@
CXType clang_getPointeeType(CXType CT) {
QualType T = GetQualType(CT);
- Type *TP = T.getTypePtr();
+ Type *TP = T.getTypePtrOrNull();
if (!TP)
return MakeCXType(QualType(), GetTU(CT));
@@ -217,7 +217,7 @@
return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
QualType T = GetQualType(CT);
- Type *TP = T.getTypePtr();
+ Type *TP = T.getTypePtrOrNull();
if (!TP)
return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
@@ -254,7 +254,7 @@
// FIXME: Template type parameters!
case Type::Elaborated:
- TP = cast<ElaboratedType>(TP)->getNamedType().getTypePtr();
+ TP = cast<ElaboratedType>(TP)->getNamedType().getTypePtrOrNull();
goto try_again;
default:
@@ -324,7 +324,7 @@
CXType clang_getResultType(CXType X) {
QualType T = GetQualType(X);
- if (!T.getTypePtr())
+ if (!T.getTypePtrOrNull())
return MakeCXType(QualType(), GetTU(X));
if (const FunctionType *FD = T->getAs<FunctionType>())
@@ -347,7 +347,7 @@
unsigned clang_isPODType(CXType X) {
QualType T = GetQualType(X);
- if (!T.getTypePtr())
+ if (!T.getTypePtrOrNull())
return 0;
return T->isPODType() ? 1 : 0;
}