[cfe-commits] r39485 - in /cfe/cfe/trunk: AST/ASTContext.cpp AST/Decl.cpp AST/Stmt.cpp Driver/clang.cpp INPUTS/carbon_h.c Sema/SemaDecl.cpp include/clang/AST/Decl.h include/clang/AST/Stmt.h

Steve Naroff snaroff at apple.com
Wed Jul 11 09:44:53 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:44:53 2007
New Revision: 39485

URL: http://llvm.org/viewvc/llvm-project?rev=39485&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Added "global" statistics gathering for Decls/Stmts/Exprs.
Very useful for working with a single file. When we start compiling
multiple files, will need to enhance this to collect stats on a per-module
basis.

Modified:
    cfe/cfe/trunk/AST/ASTContext.cpp
    cfe/cfe/trunk/AST/Decl.cpp
    cfe/cfe/trunk/AST/Stmt.cpp
    cfe/cfe/trunk/Driver/clang.cpp
    cfe/cfe/trunk/INPUTS/carbon_h.c
    cfe/cfe/trunk/Sema/SemaDecl.cpp
    cfe/cfe/trunk/include/clang/AST/Decl.h
    cfe/cfe/trunk/include/clang/AST/Stmt.h

Modified: cfe/cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/ASTContext.cpp?rev=39485&r1=39484&r2=39485&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/cfe/trunk/AST/ASTContext.cpp Wed Jul 11 11:44:53 2007
@@ -85,6 +85,10 @@
   fprintf(stderr, "      %d union types\n", NumTagUnion);
   fprintf(stderr, "      %d class types\n", NumTagClass);
   fprintf(stderr, "      %d enum types\n", NumTagEnum);
+  fprintf(stderr, "Total bytes = %d\n", NumBuiltin*sizeof(BuiltinType)+
+    NumPointer*sizeof(PointerType)+NumArray*sizeof(ArrayType)+
+    NumFunctionP*sizeof(FunctionTypeProto)+NumFunctionNP*sizeof(FunctionTypeNoProto)+
+    NumTypeName*sizeof(TypedefType)+NumTagged*sizeof(TagType));
 }
 
 

Modified: cfe/cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Decl.cpp?rev=39485&r1=39484&r2=39485&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Decl.cpp (original)
+++ cfe/cfe/trunk/AST/Decl.cpp Wed Jul 11 11:44:53 2007
@@ -16,6 +16,87 @@
 using namespace llvm;
 using namespace clang;
 
+// temporary statistics gathering
+static unsigned nFuncs = 0;
+static unsigned nBlockVars = 0;
+static unsigned nFileVars = 0;
+static unsigned nParmVars = 0;
+static unsigned nSUE = 0;
+static unsigned nEnumConst = 0;
+static unsigned nEnumDecls = 0;
+static unsigned nTypedef = 0;
+static unsigned nFieldDecls = 0;
+static bool StatSwitch = false;
+
+bool Decl::CollectingStats(bool enable) {
+  if (enable) StatSwitch = true;
+	return StatSwitch;
+}
+
+void Decl::PrintStats() {
+    fprintf(stderr, "*** Decl Stats:\n");
+		fprintf(stderr, "  %d decls total.\n", 
+		  nFuncs+nBlockVars+nFileVars+nParmVars+nFieldDecls+nSUE+nEnumDecls+nEnumConst+nTypedef);
+    fprintf(stderr, "    %d function decls, %d each (%d bytes)\n", 
+		  nFuncs, sizeof(FunctionDecl), nFuncs*sizeof(FunctionDecl));
+    fprintf(stderr, "    %d block variable decls, %d each (%d bytes)\n", 
+		  nBlockVars, sizeof(BlockVarDecl), nBlockVars*sizeof(BlockVarDecl));
+    fprintf(stderr, "    %d file variable decls, %d each (%d bytes)\n", 
+		  nFileVars, sizeof(FileVarDecl), nFileVars*sizeof(FileVarDecl));
+    fprintf(stderr, "    %d parameter variable decls, %d each (%d bytes)\n", 
+		  nParmVars, sizeof(ParmVarDecl), nParmVars*sizeof(ParmVarDecl));
+    fprintf(stderr, "    %d field decls, %d each (%d bytes)\n", 
+		  nFieldDecls, sizeof(FieldDecl), nFieldDecls*sizeof(FieldDecl));
+    fprintf(stderr, "    %d struct/union/enum decls, %d each (%d bytes)\n", 
+		  nSUE, sizeof(RecordDecl), nSUE*sizeof(RecordDecl));
+    fprintf(stderr, "    %d enum decls, %d each (%d bytes)\n", 
+		  nEnumDecls, sizeof(EnumDecl), nEnumDecls*sizeof(EnumDecl));
+    fprintf(stderr, "    %d enum constant decls, %d each (%d bytes)\n", 
+		  nEnumConst, sizeof(EnumConstantDecl), nEnumConst*sizeof(EnumConstantDecl));
+    fprintf(stderr, "    %d typedef decls, %d each (%d bytes)\n", 
+		  nTypedef, sizeof(TypedefDecl), nTypedef*sizeof(TypedefDecl));
+		fprintf(stderr, "Total bytes = %d\n", 
+		  nFuncs*sizeof(FunctionDecl)+nBlockVars*sizeof(BlockVarDecl)+
+      nFileVars*sizeof(FileVarDecl)+nParmVars*sizeof(ParmVarDecl)+
+      nFieldDecls*sizeof(FieldDecl)+nSUE*sizeof(RecordDecl)+
+      nEnumDecls*sizeof(EnumDecl)+nEnumConst*sizeof(EnumConstantDecl)+
+			nTypedef*sizeof(TypedefDecl));
+}
+
+void Decl::addDeclKind(const Kind k) {
+	switch (k) {
+	case Typedef:
+		nTypedef++;
+		break;
+	case Function:
+		nFuncs++;
+		break;
+	case BlockVariable:
+		nBlockVars++;
+		break;
+	case FileVariable:
+		nFileVars++;
+		break;
+	case ParmVariable:
+		nParmVars++;
+		break;
+	case EnumConstant:
+		nEnumConst++;
+		break;
+	case Field:
+		nFieldDecls++;
+		break;
+	case Struct:
+	case Union:
+	case Class:
+		nSUE++;
+		break;
+	case Enum:
+		nEnumDecls++;
+		break;
+	}
+}
+
 // Out-of-line virtual method providing a home for Decl.
 Decl::~Decl() {
 }

Modified: cfe/cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Stmt.cpp?rev=39485&r1=39484&r2=39485&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/cfe/trunk/AST/Stmt.cpp Wed Jul 11 11:44:53 2007
@@ -24,13 +24,15 @@
 STMT(0, Stmt, )
 #include "clang/AST/StmtNodes.def"
 
-static const struct StmtClassNameTable {
+static struct StmtClassNameTable {
   int enumValue;
   const char *className;
+  unsigned counter;
+  unsigned size;
 } sNames[] = {
-#define STMT(N, CLASS, PARENT) { N, #CLASS },
+#define STMT(N, CLASS, PARENT) { N, #CLASS, 0, sizeof(CLASS) },
 #include "clang/AST/StmtNodes.def"
-  { 0, 0 }
+  { 0, 0, 0, 0 }
 };
   
 const char *Stmt::getStmtClassName() const {
@@ -40,4 +42,35 @@
   }
   return 0; // should never happen....
 }
-  
+
+void Stmt::PrintStats() {
+  unsigned sum = 0;
+  fprintf(stderr, "*** Stmt/Expr Stats:\n");
+  for (int i = 0; sNames[i].className; i++) {
+    sum += sNames[i].counter;
+  }
+  fprintf(stderr, "  %d stmts/exprs total.\n", sum);
+  sum = 0;
+  for (int i = 0; sNames[i].className; i++) {
+    fprintf(stderr, "    %d %s, %d each (%d bytes)\n", 
+      sNames[i].counter, sNames[i].className, sNames[i].size, sNames[i].counter*sNames[i].size);
+    sum += sNames[i].counter*sNames[i].size;
+  }
+  fprintf(stderr, "Total bytes = %d\n", sum);
+}
+
+void Stmt::addStmtClass(StmtClass s) {
+  for (int i = 0; sNames[i].className; i++) {
+    if (s == sNames[i].enumValue)
+      sNames[i].counter++;
+  }
+}
+
+static bool StatSwitch = false;
+
+bool Stmt::CollectingStats(bool enable) {
+  if (enable) StatSwitch = true;
+	return StatSwitch;
+}
+
+

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39485&r1=39484&r2=39485&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:44:53 2007
@@ -944,6 +944,11 @@
 //===----------------------------------------------------------------------===//
 
 static void BuildASTs(Preprocessor &PP, unsigned MainFileID) {
+  // collect global stats on Decls/Stmts (until we have a module streamer)
+  if (Stats) {
+    Decl::CollectingStats(true);
+    Stmt::CollectingStats(true);
+  }
   ASTContext Context(PP.getTargetInfo(), PP.getIdentifierTable());
   ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
   while (ASTStreamer_ReadTopLevelDecl(Streamer))
@@ -953,6 +958,8 @@
     std::cerr << "\nSTATISTICS:\n";
     ASTStreamer_PrintStats(Streamer);
     Context.PrintStats();
+    Decl::PrintStats();
+    Stmt::PrintStats();
   }
   
   ASTStreamer_Terminate(Streamer);

Modified: cfe/cfe/trunk/INPUTS/carbon_h.c
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/INPUTS/carbon_h.c?rev=39485&r1=39484&r2=39485&view=diff

==============================================================================
--- cfe/cfe/trunk/INPUTS/carbon_h.c (original)
+++ cfe/cfe/trunk/INPUTS/carbon_h.c Wed Jul 11 11:44:53 2007
@@ -1,4 +1,4 @@
 
-#import <Carbon/Carbon.h>
+#include <Carbon/Carbon.h>
 
 //#import<vecLib/vecLib.h>

Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39485&r1=39484&r2=39485&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:44:53 2007
@@ -627,7 +627,7 @@
   
   if (BitWidth) {
     // TODO: Validate.
-    printf("WARNING: BITFIELDS IGNORED!\n");
+    //printf("WARNING: BITFIELDS IGNORED!\n");
     
     // 6.7.2.1p3
     // 6.7.2.1p4

Modified: cfe/cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Decl.h?rev=39485&r1=39484&r2=39485&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Decl.h Wed Jul 11 11:44:53 2007
@@ -23,7 +23,8 @@
 class Expr;
 class Stmt;
 class FunctionDecl;
-  
+
+
 /// Decl - This represents one declaration (or definition), e.g. a variable, 
 /// typedef, function, struct, etc.  
 ///
@@ -62,10 +63,12 @@
   /// Decls are relinked onto a containing decl object.
   ///
   Decl *Next;
-  
+
 protected:
   Decl(Kind DK, SourceLocation L, IdentifierInfo *Id)
-    : DeclKind(DK), Loc(L), Identifier(Id), Next(0) {}
+    : DeclKind(DK), Loc(L), Identifier(Id), Next(0) {
+    if (Decl::CollectingStats()) addDeclKind(DK);
+  }
   virtual ~Decl();
   
 public:
@@ -95,7 +98,11 @@
       return IDNS_Tag;
     }
   }
-  
+  // global temp stats (until we have a per-module visitor)
+  static void addDeclKind(const Kind k);
+  static bool CollectingStats(bool enable=false);
+  static void PrintStats();
+    
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *) { return true; }
 };

Modified: cfe/cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Stmt.h?rev=39485&r1=39484&r2=39485&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Stmt.h Wed Jul 11 11:44:53 2007
@@ -39,12 +39,19 @@
 private:
   const StmtClass sClass;
 public:
-  Stmt(StmtClass SC) : sClass(SC) {}
+  Stmt(StmtClass SC) : sClass(SC) { 
+    if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
+  }
   virtual ~Stmt() {}
 
   StmtClass getStmtClass() const { return sClass; }
   const char *getStmtClassName() const;
 
+  // global temp stats (until we have a per-module visitor)
+  static void addStmtClass(const StmtClass s);
+  static bool CollectingStats(bool enable=false);
+  static void PrintStats();
+  
   void dump() const;
   void print(std::ostream &OS) const;
   





More information about the cfe-commits mailing list