From dbe833da54e1b6192991b64fc453cd50b5ee7909 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 26 May 2009 14:40:08 +0000 Subject: [PATCH] Simplify printing of the statistics for types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72415 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 113 +++++++---------------------------------- lib/AST/Stmt.cpp | 1 + 2 files changed, 19 insertions(+), 95 deletions(-) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 32adf3ae73..e85096021b 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -97,107 +97,30 @@ ASTContext::setExternalSource(llvm::OwningPtr &Source) { void ASTContext::PrintStats() const { fprintf(stderr, "*** AST Context Stats:\n"); fprintf(stderr, " %d types total.\n", (int)Types.size()); - unsigned NumBuiltin = 0, NumPointer = 0, NumArray = 0, NumFunctionP = 0; - unsigned NumVector = 0, NumComplex = 0, NumBlockPointer = 0; - unsigned NumFunctionNP = 0, NumTypeName = 0, NumTagged = 0; - unsigned NumLValueReference = 0, NumRValueReference = 0, NumMemberPointer = 0; - unsigned NumTagStruct = 0, NumTagUnion = 0, NumTagEnum = 0, NumTagClass = 0; - unsigned NumObjCInterfaces = 0, NumObjCQualifiedInterfaces = 0; - unsigned NumObjCQualifiedIds = 0; - unsigned NumTypeOfTypes = 0, NumTypeOfExprTypes = 0; - unsigned NumExtQual = 0; + unsigned counts[] = { +#define TYPE(Name, Parent) 0, +#define ABSTRACT_TYPE(Name, Parent) +#include "clang/AST/TypeNodes.def" + 0 // Extra + }; for (unsigned i = 0, e = Types.size(); i != e; ++i) { Type *T = Types[i]; - if (isa(T)) - ++NumBuiltin; - else if (isa(T)) - ++NumPointer; - else if (isa(T)) - ++NumBlockPointer; - else if (isa(T)) - ++NumLValueReference; - else if (isa(T)) - ++NumRValueReference; - else if (isa(T)) - ++NumMemberPointer; - else if (isa(T)) - ++NumComplex; - else if (isa(T)) - ++NumArray; - else if (isa(T)) - ++NumVector; - else if (isa(T)) - ++NumFunctionNP; - else if (isa(T)) - ++NumFunctionP; - else if (isa(T)) - ++NumTypeName; - else if (TagType *TT = dyn_cast(T)) { - ++NumTagged; - switch (TT->getDecl()->getTagKind()) { - default: assert(0 && "Unknown tagged type!"); - case TagDecl::TK_struct: ++NumTagStruct; break; - case TagDecl::TK_union: ++NumTagUnion; break; - case TagDecl::TK_class: ++NumTagClass; break; - case TagDecl::TK_enum: ++NumTagEnum; break; - } - } else if (isa(T)) - ++NumObjCInterfaces; - else if (isa(T)) - ++NumObjCQualifiedInterfaces; - else if (isa(T)) - ++NumObjCQualifiedIds; - else if (isa(T)) - ++NumTypeOfTypes; - else if (isa(T)) - ++NumTypeOfExprTypes; - else if (isa(T)) - ++NumExtQual; - else { - QualType(T, 0).dump(); - assert(0 && "Unknown type!"); - } + counts[(unsigned)T->getTypeClass()]++; } - fprintf(stderr, " %d builtin types\n", NumBuiltin); - fprintf(stderr, " %d pointer types\n", NumPointer); - fprintf(stderr, " %d block pointer types\n", NumBlockPointer); - fprintf(stderr, " %d lvalue reference types\n", NumLValueReference); - fprintf(stderr, " %d rvalue reference types\n", NumRValueReference); - fprintf(stderr, " %d member pointer types\n", NumMemberPointer); - fprintf(stderr, " %d complex types\n", NumComplex); - fprintf(stderr, " %d array types\n", NumArray); - fprintf(stderr, " %d vector types\n", NumVector); - fprintf(stderr, " %d function types with proto\n", NumFunctionP); - fprintf(stderr, " %d function types with no proto\n", NumFunctionNP); - fprintf(stderr, " %d typename (typedef) types\n", NumTypeName); - fprintf(stderr, " %d tagged types\n", NumTagged); - fprintf(stderr, " %d struct types\n", NumTagStruct); - fprintf(stderr, " %d union types\n", NumTagUnion); - fprintf(stderr, " %d class types\n", NumTagClass); - fprintf(stderr, " %d enum types\n", NumTagEnum); - fprintf(stderr, " %d interface types\n", NumObjCInterfaces); - fprintf(stderr, " %d protocol qualified interface types\n", - NumObjCQualifiedInterfaces); - fprintf(stderr, " %d protocol qualified id types\n", - NumObjCQualifiedIds); - fprintf(stderr, " %d typeof types\n", NumTypeOfTypes); - fprintf(stderr, " %d typeof exprs\n", NumTypeOfExprTypes); - fprintf(stderr, " %d attribute-qualified types\n", NumExtQual); - - fprintf(stderr, "Total bytes = %d\n", int(NumBuiltin*sizeof(BuiltinType)+ - NumPointer*sizeof(PointerType)+NumArray*sizeof(ArrayType)+ - NumComplex*sizeof(ComplexType)+NumVector*sizeof(VectorType)+ - NumLValueReference*sizeof(LValueReferenceType)+ - NumRValueReference*sizeof(RValueReferenceType)+ - NumMemberPointer*sizeof(MemberPointerType)+ - NumFunctionP*sizeof(FunctionProtoType)+ - NumFunctionNP*sizeof(FunctionNoProtoType)+ - NumTypeName*sizeof(TypedefType)+NumTagged*sizeof(TagType)+ - NumTypeOfTypes*sizeof(TypeOfType)+NumTypeOfExprTypes*sizeof(TypeOfExprType)+ - NumExtQual*sizeof(ExtQualType))); + unsigned Idx = 0; + unsigned TotalBytes = 0; +#define TYPE(Name, Parent) \ + if (counts[Idx]) \ + fprintf(stderr, " %d %s types\n", (int)counts[Idx], #Name); \ + TotalBytes += counts[Idx] * sizeof(Name##Type); \ + ++Idx; +#define ABSTRACT_TYPE(Name, Parent) +#include "clang/AST/TypeNodes.def" + + fprintf(stderr, "Total bytes = %d\n", int(TotalBytes)); if (ExternalSource.get()) { fprintf(stderr, "\n"); diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index b2fadb1834..17577910d2 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -78,6 +78,7 @@ void Stmt::PrintStats() { sum = 0; for (int i = 0; i != Stmt::lastExprConstant+1; i++) { if (StmtClassInfo[i].Name == 0) continue; + if (StmtClassInfo[i].Counter == 0) continue; fprintf(stderr, " %d %s, %d each (%d bytes)\n", StmtClassInfo[i].Counter, StmtClassInfo[i].Name, StmtClassInfo[i].Size, -- 2.40.0