[cfe-commits] r143763 - /cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp

Ted Kremenek kremenek at apple.com
Fri Nov 4 17:10:04 PDT 2011


Author: kremenek
Date: Fri Nov  4 19:10:04 2011
New Revision: 143763

URL: http://llvm.org/viewvc/llvm-project?rev=143763&view=rev
Log:
Serialized diagnostics: pull category name serialization into diagnostic blocks.  The goal is to remove BLOCK_STRINGS so that the bitcode file can potentially be streamed.

Modified:
    cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp

Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp?rev=143763&r1=143762&r2=143763&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp Fri Nov  4 19:10:04 2011
@@ -94,6 +94,9 @@
   /// \brief Emit a record for a CharSourceRange.
   void EmitCharSourceRange(CharSourceRange R);
   
+  /// \brief Emit the string information for a category.
+  void EmitCategory(unsigned CatID);
+  
   /// \brief The version of the diagnostics file.
   enum { Version = 1 };
 
@@ -238,6 +241,7 @@
   EmitBlockID(BLOCK_DIAG, "Diag", Stream, Record);
   EmitRecordID(RECORD_DIAG, "DiagInfo", Stream, Record);
   EmitRecordID(RECORD_SOURCE_RANGE, "SrcRange", Stream, Record);
+  EmitRecordID(RECORD_CATEGORY, "CatName", Stream, Record);
   
   // Emit Abbrevs.
   using namespace llvm;
@@ -253,6 +257,14 @@
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Diagnostc text.
   Abbrevs.set(RECORD_DIAG, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
   
+  // Emit abbrevation for RECORD_CATEGORY.
+  Abbrev = new BitCodeAbbrev();
+  Abbrev->Add(BitCodeAbbrevOp(RECORD_CATEGORY));
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Category ID.
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));  // Text size.
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));      // Category text.
+  Abbrevs.set(RECORD_CATEGORY, Stream.EmitBlockInfoAbbrev(BLOCK_DIAG, Abbrev));
+
   // Emit abbrevation for RECORD_SOURCE_RANGE.
   Abbrev = new BitCodeAbbrev();
   Abbrev->Add(BitCodeAbbrevOp(RECORD_SOURCE_RANGE));
@@ -266,18 +278,10 @@
   // ==---------------------------------------------------------------------==//
 
   EmitBlockID(BLOCK_STRINGS, "Strings", Stream, Record);
-  EmitRecordID(RECORD_CATEGORY, "CatName", Stream, Record);
   EmitRecordID(RECORD_FILENAME, "FileName", Stream, Record);
   EmitRecordID(RECORD_DIAG_FLAG, "DiagFlag", Stream, Record);
 
   Abbrev = new BitCodeAbbrev();
-  Abbrev->Add(BitCodeAbbrevOp(RECORD_CATEGORY));
-  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); // Text size.
-  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Category text.
-  Abbrevs.set(RECORD_CATEGORY, Stream.EmitBlockInfoAbbrev(BLOCK_STRINGS,
-                                                          Abbrev));
-  
-  Abbrev = new BitCodeAbbrev();
   Abbrev->Add(BitCodeAbbrevOp(RECORD_FILENAME));
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 64)); // Size.
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 64)); // Modifcation time.  
@@ -298,6 +302,22 @@
   Stream.ExitBlock();
 }
 
+void SDiagsWriter::EmitCategory(unsigned int CatID) {
+  if (Categories.count(CatID))
+    return;
+  
+  Categories.insert(CatID);
+  
+  // We use a local version of 'Record' so that we can be generating
+  // another record when we lazily generate one for the category entry.
+  RecordData Record;
+  Record.push_back(RECORD_CATEGORY);
+  Record.push_back(CatID);
+  StringRef catName = DiagnosticIDs::getCategoryNameFromID(CatID);
+  Record.push_back(catName.size());
+  Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_CATEGORY), Record, catName);
+}
+
 void SDiagsWriter::EmitRawStringContents(llvm::StringRef str) {
   for (StringRef::const_iterator I = str.begin(), E = str.end(); I!=E; ++I)
     Stream.Emit(*I, 8);
@@ -324,6 +344,10 @@
   AddLocToRecord(Diags.getSourceManager(), Info.getLocation(), Record);  
   unsigned category = DiagnosticIDs::getCategoryNumberForDiag(Info.getID());
   Record.push_back(category);
+  
+  // Emit the category string lazily if we haven't already.
+  EmitCategory(category);
+
   Categories.insert(category);
   if (DiagLevel == DiagnosticsEngine::Note)
     Record.push_back(0); // No flag for notes.
@@ -379,25 +403,10 @@
 }
 
 void SDiagsWriter::EmitCategoriesAndFileNames() {
-
   if (Categories.empty() && Files.empty())
     return;
-  
+
   BlockEnterExit BlockEnter(Stream, BLOCK_STRINGS);
-  
-  // Emit the category names.
-  {
-    std::vector<unsigned> scribble;
-    populateAndSort(scribble, Categories);
-    for (std::vector<unsigned>::iterator it = scribble.begin(), 
-          ei = scribble.end(); it != ei ; ++it) {
-      Record.clear();
-      Record.push_back(RECORD_CATEGORY);
-      StringRef catName = DiagnosticIDs::getCategoryNameFromID(*it);
-      Record.push_back(catName.size());
-      Stream.EmitRecordWithBlob(Abbrevs.get(RECORD_CATEGORY), Record, catName);
-    }
-  }
 
   // Emit the file names.
   {





More information about the cfe-commits mailing list