r297770 - Modules: Optimize bitcode encoding of diagnostic state

Duncan P. N. Exon Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 14 12:31:27 PDT 2017


Author: dexonsmith
Date: Tue Mar 14 14:31:27 2017
New Revision: 297770

URL: http://llvm.org/viewvc/llvm-project?rev=297770&view=rev
Log:
Modules: Optimize bitcode encoding of diagnostic state

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.

Modified:
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=297770&r1=297769&r2=297770&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Mar 14 14:31:27 2017
@@ -5463,16 +5463,16 @@ void ASTReader::ReadPragmaDiagnosticMapp
       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;
     };
 

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=297770&r1=297769&r2=297770&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Mar 14 14:31:27 2017
@@ -2871,14 +2871,18 @@ void ASTWriter::WritePragmaDiagnosticMap
   
     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;
     }
   };
 




More information about the cfe-commits mailing list