]> granicus.if.org Git - clang/commitdiff
Modules: Optimize bitcode encoding of diagnostic state
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 14 Mar 2017 19:31:27 +0000 (19:31 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 14 Mar 2017 19:31:27 +0000 (19:31 +0000)
Since bitcode uses VBR encoding, large numbers are more expensive than
small ones.  Instead of emitting a UINT_MAX sentinel after each sequence
of state-change pairs, emit the size of the sequence as a prefix.

This should have no functionality change besides saving bits from the
encoding.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297770 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp

index be0cc9ab1a8f399d9ed71d944584c9b74fabd2c7..e4eddaef9897823a07b77f65ff495b4b9ae5912c 100644 (file)
@@ -5463,16 +5463,16 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) {
       Diag.DiagStates.push_back(BasedOn);
       DiagState *NewState = &Diag.DiagStates.back();
       DiagStates.push_back(NewState);
-      while (Idx + 1 < Record.size() && Record[Idx] != unsigned(-1)) {
+      unsigned Size = Record[Idx++];
+      assert(Idx + Size * 2 <= Record.size() &&
+             "Invalid data, not enough diag/map pairs");
+      while (Size--) {
         unsigned DiagID = Record[Idx++];
         diag::Severity Map = (diag::Severity)Record[Idx++];
         DiagnosticMapping Mapping = Diag.makeUserMapping(Map, Loc);
         if (Mapping.isPragma() || IncludeNonPragmaStates)
           NewState->setMapping(DiagID, Mapping);
       }
-      assert(Idx != Record.size() && Record[Idx] == unsigned(-1) &&
-             "Invalid data, didn't find '-1' marking end of diag/map pairs");
-      ++Idx;
       return NewState;
     };
 
index b13a4e1ff4bdccd6341c0011b6fed6b951e4dd49..e9e64c2a66f82fe0ab551921d6efeadf202fd39f 100644 (file)
@@ -2871,14 +2871,18 @@ void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
   
     if (DiagStateID == 0) {
       DiagStateID = ++CurrID;
+
+      // Add a placeholder for the number of mappings.
+      auto SizeIdx = Record.size();
+      Record.emplace_back();
       for (const auto &I : *State) {
         if (I.second.isPragma() || IncludeNonPragmaStates) {
           Record.push_back(I.first);
           Record.push_back((unsigned)I.second.getSeverity());
         }
       }
-      // Add a sentinel to mark the end of the diag IDs.
-      Record.push_back(unsigned(-1));
+      // Update the placeholder.
+      Record[SizeIdx] = (Record.size() - SizeIdx) / 2;
     }
   };