[cfe-commits] [PATCH] Speed up parsing of global declarations.

Manuel Klimek klimek at google.com
Tue Dec 11 01:49:34 PST 2012


klimek added you to the CC list for the revision "Speed up parsing of global declarations.".

+cfe-commits

In effect those are two patches; those two patches interact,
which is why I put them into one.

I ran into this with a synthetic benchmark (100k int i<N>; definitions), and
cross-validated on one of our 25MB preprocessed sources internal test cases.

apply-all: this patch
class-id-cache: only the class-id-caching part applied
diagnostic-level: only the diagnostic-level fix applied
master: the current master's head
gcc: my precise based g++

Benchmarks: (branch / avg - #num runs)

25 MB preprocessed real-world test case:
---
apply-all
13.052 - 10
class-id-cache
13.069 - 10
diagnostic-level
13.681 - 10
master
13.303 - 20

gcc
12.032 - 20

100k int i<N>;
---
apply-all
0.3475 - 20
class-id-cache
0.3945 - 20
diagnostic-level
0.377 - 20
master
0.4015 - 20

gcc
0.293 - 20

The interesting thing to note is that for the real-world test case, the diagnostic-level
shortcut on its own is a ~3% regression, while the class-id-cache is a close to 2% win,
and in the apply-all case you can see that the diagnostic-level shortcut doesn't regress
it.

On the synthetic benchmark side, the diagnostic-level shortcut is roughtly 6% speed-up
with the class-id-cache giving it another boost only when applied on top of the diagnostic
level shortcut (that's as expected, as the first brings the second into the hot path).

In general, the combination of those results makes me pretty confident that those patches
together help parsing times overall. I didn't nice up the patch much (it's probably
better to just use a magic value instead of a bool in the cache), but wanted to get
some feedback first.

(Note: the 'gcc' rows show that those are benchmarks where we parse significantly slower
than gcc).

http://llvm-reviews.chandlerc.com/D197

Files:
  lib/Basic/DiagnosticIDs.cpp
  lib/Sema/SemaDecl.cpp

Index: lib/Basic/DiagnosticIDs.cpp
===================================================================
--- lib/Basic/DiagnosticIDs.cpp
+++ lib/Basic/DiagnosticIDs.cpp
@@ -222,12 +222,21 @@
   return SFINAE_Report;
 }
 
+/// \brief Cache lookup of the DiagID -> ClassInfo ID mapping.
+static std::pair<unsigned, bool>
+DiagnosticClassCache[diag::DIAG_UPPER_LIMIT] = {};
+
 /// getBuiltinDiagClass - Return the class field of the diagnostic.
 ///
 static unsigned getBuiltinDiagClass(unsigned DiagID) {
+  if (DiagnosticClassCache[DiagID].second) {
+    return DiagnosticClassCache[DiagID].first;
+  }
+  unsigned DiagClass = ~0U;
   if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
-    return Info->Class;
-  return ~0U;
+    DiagClass = Info->Class;
+  DiagnosticClassCache[DiagID] = std::make_pair(DiagClass, true);
+  return DiagClass;
 }
 
 //===----------------------------------------------------------------------===//
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -7239,7 +7239,9 @@
     while (prev && prev->isThisDeclarationADefinition())
       prev = prev->getPreviousDecl();
 
-    if (!prev)
+      if (!prev && getDiagnostics().getDiagnosticLevel(
+                       diag::warn_missing_variable_declarations,
+                       var->getLocation()))
       Diag(var->getLocation(), diag::warn_missing_variable_declarations) << var;
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D197.1.patch
Type: text/x-patch
Size: 1477 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121211/e86f9f94/attachment.bin>


More information about the cfe-commits mailing list