[cfe-commits] r39305 - in /cfe/cfe/trunk: AST/ASTContext.cpp AST/ASTStreamer.cpp Driver/clang.cpp Sema/ASTStreamer.cpp include/clang/AST/ASTContext.h include/clang/AST/ASTStreamer.h include/clang/Sema/ASTStreamer.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:42:48 PDT 2007
Author: sabre
Date: Wed Jul 11 11:42:47 2007
New Revision: 39305
URL: http://llvm.org/viewvc/llvm-project?rev=39305&view=rev
Log:
start gather stats on types processed. carbon.h currently yields:
*** AST Context Stats:
30594 types total.
19 builtin types
3929 pointer types
308 array types
18883 function types with proto
8 function types with no proto
2988 typename (typedef) types
4459 tagged types
1476 struct types
80 union types
0 class types
2903 enum types
83298 slow type lookups
Next up, making type canonicalization not trivially silly.
Modified:
cfe/cfe/trunk/AST/ASTContext.cpp
cfe/cfe/trunk/AST/ASTStreamer.cpp
cfe/cfe/trunk/Driver/clang.cpp
cfe/cfe/trunk/Sema/ASTStreamer.cpp
cfe/cfe/trunk/include/clang/AST/ASTContext.h
cfe/cfe/trunk/include/clang/AST/ASTStreamer.h
cfe/cfe/trunk/include/clang/Sema/ASTStreamer.h
Modified: cfe/cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/ASTContext.cpp?rev=39305&r1=39304&r2=39305&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/cfe/trunk/AST/ASTContext.cpp Wed Jul 11 11:42:47 2007
@@ -20,6 +20,7 @@
ASTContext::ASTContext(Preprocessor &pp)
: PP(pp), Target(pp.getTargetInfo()) {
+ NumSlowLookups = 0;
InitBuiltinTypes();
}
@@ -37,6 +38,57 @@
}
}
+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 NumFunctionNP = 0, NumTypeName = 0, NumTagged = 0;
+
+ unsigned NumTagStruct = 0, NumTagUnion = 0, NumTagEnum = 0, NumTagClass = 0;
+
+ for (unsigned i = 0, e = Types.size(); i != e; ++i) {
+ Type *T = Types[i];
+ if (isa<BuiltinType>(T))
+ ++NumBuiltin;
+ else if (isa<PointerType>(T))
+ ++NumPointer;
+ else if (isa<ArrayType>(T))
+ ++NumArray;
+ else if (isa<FunctionTypeNoProto>(T))
+ ++NumFunctionNP;
+ else if (isa<FunctionTypeProto>(T))
+ ++NumFunctionP;
+ else if (isa<TypeNameType>(T))
+ ++NumTypeName;
+ else if (TaggedType *TT = dyn_cast<TaggedType>(T)) {
+ ++NumTagged;
+ switch (TT->getDecl()->getKind()) {
+ default: assert(0 && "Unknown tagged type!");
+ case Decl::Struct: ++NumTagStruct; break;
+ case Decl::Union: ++NumTagUnion; break;
+ case Decl::Class: ++NumTagClass; break;
+ case Decl::Enum: ++NumTagEnum; break;
+ }
+ } else {
+ assert(0 && "Unknown type!");
+ }
+ }
+
+ fprintf(stderr, " %d builtin types\n", NumBuiltin);
+ fprintf(stderr, " %d pointer types\n", NumPointer);
+ fprintf(stderr, " %d array types\n", NumArray);
+ 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 slow type lookups\n", NumSlowLookups);
+}
+
+
void ASTContext::InitBuiltinType(TypeRef &R, BuiltinType::Kind K) {
Types.push_back((R = new BuiltinType(K)).getTypePtr());
}
@@ -83,6 +135,7 @@
// FIXME: This is obviously braindead!
// Unique pointers, to guarantee there is only one pointer of a particular
// structure.
+ ++NumSlowLookups;
for (unsigned i = 0, e = Types.size(); i != e; ++i)
if (PointerType *PTy = dyn_cast<PointerType>(Types[i]))
if (PTy->getPointeeType() == T)
@@ -107,6 +160,7 @@
// FIXME: This is obviously braindead!
// Unique array, to guarantee there is only one array of a particular
// structure.
+ ++NumSlowLookups;
for (unsigned i = 0, e = Types.size(); i != e; ++i)
if (ArrayType *ATy = dyn_cast<ArrayType>(Types[i]))
if (ATy->getElementType() == EltTy &&
@@ -131,6 +185,7 @@
// FIXME: This is obviously braindead!
// Unique functions, to guarantee there is only one function of a particular
// structure.
+ ++NumSlowLookups;
for (unsigned i = 0, e = Types.size(); i != e; ++i)
if (FunctionTypeNoProto *FTy = dyn_cast<FunctionTypeNoProto>(Types[i]))
if (FTy->getResultType() == ResultTy)
@@ -151,6 +206,7 @@
// FIXME: This is obviously braindead!
// Unique functions, to guarantee there is only one function of a particular
// structure.
+ ++NumSlowLookups;
for (unsigned i = 0, e = Types.size(); i != e; ++i) {
if (FunctionTypeProto *FTy = dyn_cast<FunctionTypeProto>(Types[i]))
if (FTy->getResultType() == ResultTy &&
@@ -204,6 +260,7 @@
TypeRef ASTContext::getTypeDeclType(TypeDecl *Decl) {
// FIXME: This is obviously braindead!
// Unique TypeDecl, to guarantee there is only one TypeDeclType.
+ ++NumSlowLookups;
for (unsigned i = 0, e = Types.size(); i != e; ++i)
if (TypeNameType *Ty = dyn_cast<TypeNameType>(Types[i]))
if (Ty->getDecl() == Decl)
@@ -221,6 +278,7 @@
TypeRef ASTContext::getTagDeclType(TagDecl *Decl) {
// FIXME: This is obviously braindead!
// Unique TypeDecl, to guarantee there is only one TaggedType.
+ ++NumSlowLookups;
for (unsigned i = 0, e = Types.size(); i != e; ++i)
if (TaggedType *Ty = dyn_cast<TaggedType>(Types[i]))
if (Ty->getDecl() == Decl)
Modified: cfe/cfe/trunk/AST/ASTStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/ASTStreamer.cpp?rev=39305&r1=39304&r2=39305&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/ASTStreamer.cpp (original)
+++ cfe/cfe/trunk/AST/ASTStreamer.cpp Wed Jul 11 11:42:47 2007
@@ -33,38 +33,10 @@
}
/// ReadTopLevelDecl - Parse and return the next top-level declaration.
- Decl *ReadTopLevelDecl() {
- Parser::DeclTy *Result;
-
- /// If the previous time through we read something like 'int X, Y', return
- /// the next declarator.
- if (!LastInGroupList.empty()) {
- Result = LastInGroupList.back();
- LastInGroupList.pop_back();
- return (Decl*)Result;
- }
-
- do {
- if (P.ParseTopLevelDecl(Result))
- return 0; // End of file.
-
- // If we got a null return and something *was* parsed, try again. This
- // is due to a top-level semicolon, an action override, or a parse error
- // skipping something.
- } while (Result == 0);
-
- // If we parsed a declspec with multiple declarators, reverse the list and
- // return the first one.
- if (!LastInGroupList.empty()) {
- LastInGroupList.push_back((Decl*)Result);
- std::reverse(LastInGroupList.begin(), LastInGroupList.end());
- Result = LastInGroupList.back();
- LastInGroupList.pop_back();
- }
-
- return (Decl*)Result;
- }
+ Decl *ReadTopLevelDecl();
+ void PrintStats() const;
+
~ASTStreamer() {
P.Finalize();
delete &P.getActions();
@@ -72,7 +44,43 @@
};
}
+/// ReadTopLevelDecl - Parse and return the next top-level declaration.
+///
+Decl *ASTStreamer::ReadTopLevelDecl() {
+ Parser::DeclTy *Result;
+
+ /// If the previous time through we read something like 'int X, Y', return
+ /// the next declarator.
+ if (!LastInGroupList.empty()) {
+ Result = LastInGroupList.back();
+ LastInGroupList.pop_back();
+ return static_cast<Decl*>(Result);
+ }
+
+ do {
+ if (P.ParseTopLevelDecl(Result))
+ return 0; // End of file.
+
+ // If we got a null return and something *was* parsed, try again. This
+ // is due to a top-level semicolon, an action override, or a parse error
+ // skipping something.
+ } while (Result == 0);
+
+ // If we parsed a declspec with multiple declarators, reverse the list and
+ // return the first one.
+ if (!LastInGroupList.empty()) {
+ LastInGroupList.push_back((Decl*)Result);
+ std::reverse(LastInGroupList.begin(), LastInGroupList.end());
+ Result = LastInGroupList.back();
+ LastInGroupList.pop_back();
+ }
+
+ return static_cast<Decl*>(Result);
+}
+void ASTStreamer::PrintStats() const {
+
+}
//===----------------------------------------------------------------------===//
// Public interface to the file
@@ -91,6 +99,13 @@
return static_cast<ASTStreamer*>(Streamer)->ReadTopLevelDecl();
}
+
+/// ASTStreamer_PrintStats - Emit statistic information to stderr.
+///
+void llvm::clang::ASTStreamer_PrintStats(ASTStreamerTy *Streamer) {
+ return static_cast<ASTStreamer*>(Streamer)->PrintStats();
+}
+
/// ASTStreamer_Terminate - Gracefully shut down the streamer.
///
void llvm::clang::ASTStreamer_Terminate(ASTStreamerTy *Streamer) {
Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39305&r1=39304&r2=39305&view=diff
==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:42:47 2007
@@ -808,6 +808,12 @@
ASTStreamerTy *Streamer = ASTStreamer_Init(Context, MainFileID);
while (ASTStreamer_ReadTopLevelDecl(Streamer))
/* keep reading */;
+
+ if (Stats) {
+ std::cerr << "\nSTATISTICS:\n";
+ ASTStreamer_PrintStats(Streamer);
+ Context.PrintStats();
+ }
ASTStreamer_Terminate(Streamer);
}
@@ -866,6 +872,12 @@
}
}
+ if (Stats) {
+ std::cerr << "\nSTATISTICS:\n";
+ ASTStreamer_PrintStats(Streamer);
+ Context.PrintStats();
+ }
+
ASTStreamer_Terminate(Streamer);
}
Modified: cfe/cfe/trunk/Sema/ASTStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/ASTStreamer.cpp?rev=39305&r1=39304&r2=39305&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/ASTStreamer.cpp (original)
+++ cfe/cfe/trunk/Sema/ASTStreamer.cpp Wed Jul 11 11:42:47 2007
@@ -33,38 +33,10 @@
}
/// ReadTopLevelDecl - Parse and return the next top-level declaration.
- Decl *ReadTopLevelDecl() {
- Parser::DeclTy *Result;
-
- /// If the previous time through we read something like 'int X, Y', return
- /// the next declarator.
- if (!LastInGroupList.empty()) {
- Result = LastInGroupList.back();
- LastInGroupList.pop_back();
- return (Decl*)Result;
- }
-
- do {
- if (P.ParseTopLevelDecl(Result))
- return 0; // End of file.
-
- // If we got a null return and something *was* parsed, try again. This
- // is due to a top-level semicolon, an action override, or a parse error
- // skipping something.
- } while (Result == 0);
-
- // If we parsed a declspec with multiple declarators, reverse the list and
- // return the first one.
- if (!LastInGroupList.empty()) {
- LastInGroupList.push_back((Decl*)Result);
- std::reverse(LastInGroupList.begin(), LastInGroupList.end());
- Result = LastInGroupList.back();
- LastInGroupList.pop_back();
- }
-
- return (Decl*)Result;
- }
+ Decl *ReadTopLevelDecl();
+ void PrintStats() const;
+
~ASTStreamer() {
P.Finalize();
delete &P.getActions();
@@ -72,7 +44,43 @@
};
}
+/// ReadTopLevelDecl - Parse and return the next top-level declaration.
+///
+Decl *ASTStreamer::ReadTopLevelDecl() {
+ Parser::DeclTy *Result;
+
+ /// If the previous time through we read something like 'int X, Y', return
+ /// the next declarator.
+ if (!LastInGroupList.empty()) {
+ Result = LastInGroupList.back();
+ LastInGroupList.pop_back();
+ return static_cast<Decl*>(Result);
+ }
+
+ do {
+ if (P.ParseTopLevelDecl(Result))
+ return 0; // End of file.
+
+ // If we got a null return and something *was* parsed, try again. This
+ // is due to a top-level semicolon, an action override, or a parse error
+ // skipping something.
+ } while (Result == 0);
+
+ // If we parsed a declspec with multiple declarators, reverse the list and
+ // return the first one.
+ if (!LastInGroupList.empty()) {
+ LastInGroupList.push_back((Decl*)Result);
+ std::reverse(LastInGroupList.begin(), LastInGroupList.end());
+ Result = LastInGroupList.back();
+ LastInGroupList.pop_back();
+ }
+
+ return static_cast<Decl*>(Result);
+}
+void ASTStreamer::PrintStats() const {
+
+}
//===----------------------------------------------------------------------===//
// Public interface to the file
@@ -91,6 +99,13 @@
return static_cast<ASTStreamer*>(Streamer)->ReadTopLevelDecl();
}
+
+/// ASTStreamer_PrintStats - Emit statistic information to stderr.
+///
+void llvm::clang::ASTStreamer_PrintStats(ASTStreamerTy *Streamer) {
+ return static_cast<ASTStreamer*>(Streamer)->PrintStats();
+}
+
/// ASTStreamer_Terminate - Gracefully shut down the streamer.
///
void llvm::clang::ASTStreamer_Terminate(ASTStreamerTy *Streamer) {
Modified: cfe/cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/ASTContext.h?rev=39305&r1=39304&r2=39305&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ASTContext.h Wed Jul 11 11:42:47 2007
@@ -27,6 +27,7 @@
class ASTContext {
// FIXME: This is a stupid data structure.
std::vector<Type*> Types;
+ unsigned NumSlowLookups;
public:
Preprocessor &PP;
TargetInfo &Target;
@@ -44,6 +45,8 @@
ASTContext(Preprocessor &pp);
~ASTContext();
+ void PrintStats() const;
+
/// getPointerType - Return the uniqued reference to the type for a pointer to
/// the specified type.
Modified: cfe/cfe/trunk/include/clang/AST/ASTStreamer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/ASTStreamer.h?rev=39305&r1=39304&r2=39305&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ASTStreamer.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ASTStreamer.h Wed Jul 11 11:42:47 2007
@@ -31,6 +31,10 @@
/// This returns null at end of file.
Decl *ASTStreamer_ReadTopLevelDecl(ASTStreamerTy *Streamer);
+ /// ASTStreamer_PrintStats - Emit statistic information to stderr.
+ ///
+ void ASTStreamer_PrintStats(ASTStreamerTy *Streamer);
+
/// ASTStreamer_Terminate - Gracefully shut down the streamer.
///
void ASTStreamer_Terminate(ASTStreamerTy *Streamer);
Modified: cfe/cfe/trunk/include/clang/Sema/ASTStreamer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Sema/ASTStreamer.h?rev=39305&r1=39304&r2=39305&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Sema/ASTStreamer.h (original)
+++ cfe/cfe/trunk/include/clang/Sema/ASTStreamer.h Wed Jul 11 11:42:47 2007
@@ -31,6 +31,10 @@
/// This returns null at end of file.
Decl *ASTStreamer_ReadTopLevelDecl(ASTStreamerTy *Streamer);
+ /// ASTStreamer_PrintStats - Emit statistic information to stderr.
+ ///
+ void ASTStreamer_PrintStats(ASTStreamerTy *Streamer);
+
/// ASTStreamer_Terminate - Gracefully shut down the streamer.
///
void ASTStreamer_Terminate(ASTStreamerTy *Streamer);
More information about the cfe-commits
mailing list