[cfe-commits] r152669 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp

Daniel Dunbar daniel at zuster.org
Tue Mar 13 14:02:15 PDT 2012


Author: ddunbar
Date: Tue Mar 13 16:02:14 2012
New Revision: 152669

URL: http://llvm.org/viewvc/llvm-project?rev=152669&view=rev
Log:
[Basic] Fix up DiagnosticBuilder::{FlushCounts,Emit} to be inline.

 - This is much more important than it appears at first glance...

The intended design of DiagnosticBuilder was that it never escape and that all
its members would get lowered to registers by the compiler. By fixing Emit here,
the compiler can completely eliminate the DiagnosticBuilder object and never
need to push those registers back into it.

Unfortunately, Sema has broken DiagnosticBuilder in other ways (by introducing
SemaDiagnosticBuilder), so we don't get the fill impact of this, but it is still
good for 30k reduction in code size. I'll work on fixing the
SemaDiagnosticBuilder problems next.

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/Basic/Diagnostic.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=152669&r1=152668&r2=152669&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Tue Mar 13 16:02:14 2012
@@ -700,6 +700,9 @@
     return Diags->ProcessDiag(*this);
   }
 
+  /// \brief Emit the current diagnostic and clear the diagnostic state.
+  bool EmitCurrentDiagnostic();
+
   friend class ASTReader;
   friend class ASTWriter;
 };
@@ -764,7 +767,11 @@
   friend class PartialDiagnostic;
 
 protected:
-  void FlushCounts();
+  void FlushCounts() {
+    DiagObj->NumDiagArgs = NumArgs;
+    DiagObj->NumDiagRanges = NumRanges;
+    DiagObj->NumDiagFixItHints = NumFixits;
+  }
 
   /// \brief Clear out the current diagnostic.
   void Clear() { DiagObj = 0; }
@@ -792,7 +799,24 @@
   ///
   /// \returns true if a diagnostic was emitted, false if the
   /// diagnostic was suppressed.
-  bool Emit();
+  bool Emit() {
+    // If DiagObj is null, then its soul was stolen by the copy ctor
+    // or the user called Emit().
+    if (DiagObj == 0) return false;
+
+    // When emitting diagnostics, we set the final argument count into
+    // the DiagnosticsEngine object.
+    FlushCounts();
+
+    // Process the diagnostic.
+    bool Result = DiagObj->EmitCurrentDiagnostic();
+
+    // This diagnostic is dead.
+    DiagObj = 0;
+
+    return Result;
+  }
+
   
 public:
   /// Copy constructor.  When copied, this "takes" the diagnostic info from the
@@ -808,8 +832,7 @@
   /// Destructor - The dtor emits the diagnostic if it hasn't already
   /// been emitted.
   ~DiagnosticBuilder() {
-    if (DiagObj)
-      Emit();
+    Emit();
   }
   
   /// Operator bool: conversion of DiagnosticBuilder to bool always returns

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=152669&r1=152668&r2=152669&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Tue Mar 13 16:02:14 2012
@@ -385,35 +385,18 @@
   CurDiagID = ~0U;
 }
 
-void DiagnosticBuilder::FlushCounts() {
-  DiagObj->NumDiagArgs = NumArgs;
-  DiagObj->NumDiagRanges = NumRanges;
-  DiagObj->NumDiagFixItHints = NumFixits;
-}
-
-bool DiagnosticBuilder::Emit() {
-  // If DiagObj is null, then its soul was stolen by the copy ctor
-  // or the user called Emit().
-  if (DiagObj == 0) return false;
-
-  // When emitting diagnostics, we set the final argument count into
-  // the DiagnosticsEngine object.
-  FlushCounts();
-
+bool DiagnosticsEngine::EmitCurrentDiagnostic() {
   // Process the diagnostic, sending the accumulated information to the
   // DiagnosticConsumer.
-  bool Emitted = DiagObj->ProcessDiag();
+  bool Emitted = ProcessDiag();
 
   // Clear out the current diagnostic object.
-  unsigned DiagID = DiagObj->CurDiagID;
-  DiagObj->Clear();
+  unsigned DiagID = CurDiagID;
+  Clear();
 
   // If there was a delayed diagnostic, emit it now.
-  if (DiagObj->DelayedDiagID && DiagObj->DelayedDiagID != DiagID)
-    DiagObj->ReportDelayed();
-
-  // This diagnostic is dead.
-  DiagObj = 0;
+  if (DelayedDiagID && DelayedDiagID != DiagID)
+    ReportDelayed();
 
   return Emitted;
 }





More information about the cfe-commits mailing list