[cfe-commits] r57643 - in /cfe/trunk: Driver/clang.cpp include/clang/Sema/ParseAST.h lib/Sema/ParseAST.cpp

Daniel Dunbar daniel at zuster.org
Thu Oct 16 09:54:20 PDT 2008


Author: ddunbar
Date: Thu Oct 16 11:54:18 2008
New Revision: 57643

URL: http://llvm.org/viewvc/llvm-project?rev=57643&view=rev
Log:
Add --disable-free flag to clang.
 - Disables the freeing of the ASTContext and the TranslationUnit
   after parsing & sema.
 - Primarily for timing the impact on -fsyntax-only timings.

Modified:
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/include/clang/Sema/ParseAST.h
    cfe/trunk/lib/Sema/ParseAST.cpp

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

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Thu Oct 16 11:54:18 2008
@@ -54,13 +54,17 @@
 // Global options.
 //===----------------------------------------------------------------------===//
 
-bool HadErrors = false;
+static bool HadErrors = false;
 
 static llvm::cl::opt<bool>
 Verbose("v", llvm::cl::desc("Enable verbose output"));
 static llvm::cl::opt<bool>
 Stats("print-stats", 
       llvm::cl::desc("Print performance metrics and statistics"));
+static llvm::cl::opt<bool>
+DisableFree("disable-free",
+           llvm::cl::desc("Disable freeing of memory on exit"),
+           llvm::cl::init(false));
 
 enum ProgActions {
   RewriteObjC,                  // ObjC->C Rewriter.
@@ -1187,7 +1191,7 @@
     if (VerifyDiagnostics)
       exit(CheckASTConsumer(PP, Consumer.get()));
     
-    ParseAST(PP, Consumer.get(), Stats);
+    ParseAST(PP, Consumer.get(), Stats, !DisableFree);
   } else {
     if (VerifyDiagnostics)
       exit(CheckDiagnostics(PP));

Modified: cfe/trunk/include/clang/Sema/ParseAST.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ParseAST.h?rev=57643&r1=57642&r2=57643&view=diff

==============================================================================
--- cfe/trunk/include/clang/Sema/ParseAST.h (original)
+++ cfe/trunk/include/clang/Sema/ParseAST.h Thu Oct 16 11:54:18 2008
@@ -21,7 +21,11 @@
   /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
   /// the file is parsed.  This takes ownership of the ASTConsumer and
   /// ultimately deletes it.
-  void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false);
+  ///
+  /// \param FreeMemory If false, the memory used for AST elements is
+  /// not released.
+  void ParseAST(Preprocessor &pp, ASTConsumer *C, 
+                bool PrintStats = false, bool FreeMemory = true);
 
 }  // end namespace clang
 

Modified: cfe/trunk/lib/Sema/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ParseAST.cpp?rev=57643&r1=57642&r2=57643&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/ParseAST.cpp (original)
+++ cfe/trunk/lib/Sema/ParseAST.cpp Thu Oct 16 11:54:18 2008
@@ -26,26 +26,30 @@
 /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
 /// the file is parsed.  This takes ownership of the ASTConsumer and
 /// ultimately deletes it.
-void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
+///
+/// \param FreeMemory If false, the memory used for AST elements is
+/// not released.
+void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, 
+                     bool PrintStats, bool FreeMemory) {
   // Collect global stats on Decls/Stmts (until we have a module streamer).
   if (PrintStats) {
     Decl::CollectingStats(true);
     Stmt::CollectingStats(true);
   }
   
-  ASTContext Context(PP.getLangOptions(), PP.getSourceManager(),
-                     PP.getTargetInfo(),
-                     PP.getIdentifierTable(), PP.getSelectorTable());
-  
-  TranslationUnit TU(Context);
-  Sema S(PP, Context, *Consumer);
+  ASTContext *Context = 
+    new ASTContext(PP.getLangOptions(), PP.getSourceManager(),
+                   PP.getTargetInfo(),
+                   PP.getIdentifierTable(), PP.getSelectorTable());
+  TranslationUnit *TU = new TranslationUnit(*Context);
+  Sema S(PP, *Context, *Consumer);
   Parser P(PP, S);
   PP.EnterMainSourceFile();
     
   // Initialize the parser.
   P.Initialize();
   
-  Consumer->InitializeTU(TU);
+  Consumer->InitializeTU(*TU);
   
   Parser::DeclTy *ADecl;
   
@@ -55,17 +59,17 @@
     // skipping something.
     if (ADecl) {
       Decl* D = static_cast<Decl*>(ADecl);      
-      TU.AddTopLevelDecl(D); // TranslationUnit now owns the Decl.
+      TU->AddTopLevelDecl(D); // TranslationUnit now owns the Decl.
       Consumer->HandleTopLevelDecl(D);
     }
   };
   
-  Consumer->HandleTranslationUnit(TU);
+  Consumer->HandleTranslationUnit(*TU);
 
   if (PrintStats) {
     fprintf(stderr, "\nSTATISTICS:\n");
     P.getActions().PrintStats();
-    Context.PrintStats();
+    Context->PrintStats();
     Decl::PrintStats();
     Stmt::PrintStats();
     Consumer->PrintStats();
@@ -73,4 +77,9 @@
     Decl::CollectingStats(false);
     Stmt::CollectingStats(false);
   }
+
+  if (FreeMemory) {
+    delete TU;
+    delete Context;      
+  }
 }





More information about the cfe-commits mailing list