[cfe-commits] r98138 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp
John McCall
rjmccall at apple.com
Tue Mar 9 22:48:02 PST 2010
Author: rjmccall
Date: Wed Mar 10 00:48:02 2010
New Revision: 98138
URL: http://llvm.org/viewvc/llvm-project?rev=98138&view=rev
Log:
Allow the fast path through ASTContext::getTypeDeclType to be inlined.
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=98138&r1=98137&r2=98138&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Mar 10 00:48:02 2010
@@ -405,6 +405,8 @@
/// getExtQualType - Return a type with extended qualifiers.
QualType getExtQualType(const Type *Base, Qualifiers Quals);
+ QualType getTypeDeclTypeSlow(const TypeDecl *Decl);
+
public:
/// getAddSpaceQualType - Return the uniqued reference to the type for an
/// address space qualified type with the specified type and address space.
@@ -580,7 +582,19 @@
/// getTypeDeclType - Return the unique reference to the type for
/// the specified type declaration.
- QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl* PrevDecl=0);
+ QualType getTypeDeclType(const TypeDecl *Decl,
+ const TypeDecl *PrevDecl = 0) {
+ assert(Decl && "Passed null for Decl param");
+ if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
+
+ if (PrevDecl) {
+ assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
+ Decl->TypeForDecl = PrevDecl->TypeForDecl;
+ return QualType(PrevDecl->TypeForDecl, 0);
+ }
+
+ return getTypeDeclTypeSlow(Decl);
+ }
/// getTypedefType - Return the unique reference to the type for the
/// specified typename decl.
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=98138&r1=98137&r2=98138&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Mar 10 00:48:02 2010
@@ -1957,38 +1957,36 @@
/// getTypeDeclType - Return the unique reference to the type for the
/// specified type declaration.
-QualType ASTContext::getTypeDeclType(const TypeDecl *Decl,
- const TypeDecl* PrevDecl) {
+QualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) {
assert(Decl && "Passed null for Decl param");
- if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
+ assert(!Decl->TypeForDecl && "TypeForDecl present in slow case");
if (const TypedefDecl *Typedef = dyn_cast<TypedefDecl>(Decl))
return getTypedefType(Typedef);
- else if (isa<TemplateTypeParmDecl>(Decl)) {
- assert(false && "Template type parameter types are always available.");
- } else if (const ObjCInterfaceDecl *ObjCInterface
+
+ if (const ObjCInterfaceDecl *ObjCInterface
= dyn_cast<ObjCInterfaceDecl>(Decl))
return getObjCInterfaceType(ObjCInterface);
+ assert(!isa<TemplateTypeParmDecl>(Decl) &&
+ "Template type parameter types are always available.");
+
if (const RecordDecl *Record = dyn_cast<RecordDecl>(Decl)) {
- if (PrevDecl)
- Decl->TypeForDecl = PrevDecl->TypeForDecl;
- else {
- assert(!NeedsInjectedClassNameType(Record));
- Decl->TypeForDecl = new (*this, TypeAlignment) RecordType(Record);
- }
+ assert(!Record->getPreviousDeclaration() &&
+ "struct/union has previous declaration");
+ assert(!NeedsInjectedClassNameType(Record));
+ Decl->TypeForDecl = new (*this, TypeAlignment) RecordType(Record);
} else if (const EnumDecl *Enum = dyn_cast<EnumDecl>(Decl)) {
- if (PrevDecl)
- Decl->TypeForDecl = PrevDecl->TypeForDecl;
- else
- Decl->TypeForDecl = new (*this, TypeAlignment) EnumType(Enum);
+ assert(!Enum->getPreviousDeclaration() &&
+ "enum has previous declaration");
+ Decl->TypeForDecl = new (*this, TypeAlignment) EnumType(Enum);
} else if (const UnresolvedUsingTypenameDecl *Using =
dyn_cast<UnresolvedUsingTypenameDecl>(Decl)) {
Decl->TypeForDecl = new (*this, TypeAlignment) UnresolvedUsingType(Using);
} else
- assert(false && "TypeDecl without a type?");
+ llvm_unreachable("TypeDecl without a type?");
- if (!PrevDecl) Types.push_back(Decl->TypeForDecl);
+ Types.push_back(Decl->TypeForDecl);
return QualType(Decl->TypeForDecl, 0);
}
More information about the cfe-commits
mailing list