[cfe-commits] r40383 - in /cfe/trunk: Driver/clang.cpp include/clang/Basic/SourceManager.h

Chris Lattner sabre at nondot.org
Sat Jul 21 23:05:44 PDT 2007


Author: lattner
Date: Sun Jul 22 01:05:44 2007
New Revision: 40383

URL: http://llvm.org/viewvc/llvm-project?rev=40383&view=rev
Log:
when running in -E mode on multiple files, there is no reason to accumulate 
fileid's and macroid's across files.  Clearing between files keeps the tables
smaller and slightly speeds up compilation.

Modified:
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/include/clang/Basic/SourceManager.h

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

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Sun Jul 22 01:05:44 2007
@@ -770,6 +770,7 @@
                              TextDiagnostics &OurDiagnosticClient,
                              HeaderSearch &HeaderInfo,
                              const LangOptions &LangInfo) {
+  bool ClearSourceMgr = false;
   switch (ProgAction) {
   default:
     fprintf(stderr, "Unexpected program action!\n");
@@ -783,6 +784,7 @@
       PP.DumpToken(Tok, true);
       fprintf(stderr, "\n");
     } while (Tok.getKind() != tok::eof);
+    ClearSourceMgr = true;
     break;
   }
   case RunPreprocessorOnly: {        // Just lex as fast as we can, no output.
@@ -792,19 +794,23 @@
     do {
       PP.Lex(Tok);
     } while (Tok.getKind() != tok::eof);
+    ClearSourceMgr = true;
     break;
   }
     
   case PrintPreprocessedInput:       // -E mode.
     DoPrintPreprocessedInput(MainFileID, PP, LangInfo);
+    ClearSourceMgr = true;
     break;
     
   case ParseNoop:                    // -parse-noop
     ParseFile(PP, new MinimalAction(), MainFileID);
+    ClearSourceMgr = true;
     break;
     
   case ParsePrintCallbacks:
     ParseFile(PP, CreatePrintParserActionsAction(), MainFileID);
+    ClearSourceMgr = true;
     break;
   case ParseSyntaxOnly:              // -fsyntax-only
   case ParseAST:
@@ -826,8 +832,17 @@
     PP.PrintStats();
     PP.getIdentifierTable().PrintStats();
     HeaderInfo.PrintStats();
+    if (ClearSourceMgr)
+      SourceMgr.PrintStats();
     fprintf(stderr, "\n");
   }
+
+  // For a multi-file compilation, some things are ok with nuking the source 
+  // manager tables, other require stable fileid/macroid's across multiple
+  // files.
+  if (ClearSourceMgr) {
+    SourceMgr.clearIDTables();
+  }
 }
 
 static llvm::cl::list<std::string>

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=40383&r1=40382&r2=40383&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Sun Jul 22 01:05:44 2007
@@ -158,6 +158,11 @@
   SourceManager() {}
   ~SourceManager();
   
+  void clearIDTables() {
+    FileIDs.clear();
+    MacroIDs.clear();
+  }
+  
   /// createFileID - Create a new FileID that represents the specified file
   /// being #included from the specified IncludePosition.  This returns 0 on
   /// error and translates NULL into standard input.





More information about the cfe-commits mailing list