[cfe-commits] r92203 - /cfe/trunk/lib/Lex/MacroArgs.cpp

Chris Lattner sabre at nondot.org
Sun Dec 27 22:36:47 PST 2009


Author: lattner
Date: Mon Dec 28 00:36:46 2009
New Revision: 92203

URL: http://llvm.org/viewvc/llvm-project?rev=92203&view=rev
Log:
use best-fit instead of first-fit when reusing a MacroArgs object,
this speeds up Eonly on the testcase in PR5888 from 30.5s to 0.85s

Modified:
    cfe/trunk/lib/Lex/MacroArgs.cpp

Modified: cfe/trunk/lib/Lex/MacroArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroArgs.cpp?rev=92203&r1=92202&r2=92203&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/MacroArgs.cpp (original)
+++ cfe/trunk/lib/Lex/MacroArgs.cpp Mon Dec 28 00:36:46 2009
@@ -24,25 +24,34 @@
                              Preprocessor &PP) {
   assert(MI->isFunctionLike() &&
          "Can't have args for an object-like macro!");
-  MacroArgs *Result = 0;
+  MacroArgs **ResultEnt = 0;
+  unsigned ClosestMatch = ~0U;
   
   // See if we have an entry with a big enough argument list to reuse on the
   // free list.  If so, reuse it.
   for (MacroArgs **Entry = &PP.MacroArgCache; *Entry;
        Entry = &(*Entry)->ArgCache)
-    if ((*Entry)->NumUnexpArgTokens >= NumToks) {
-      Result = *Entry;
-      // Unlink this node from the preprocessors singly linked list.
-      *Entry = Result->ArgCache;
-      break;
+    if ((*Entry)->NumUnexpArgTokens >= NumToks &&
+        (*Entry)->NumUnexpArgTokens < ClosestMatch) {
+      ResultEnt = Entry;
+      
+      // If we have an exact match, use it.
+      if ((*Entry)->NumUnexpArgTokens == NumToks)
+        break;
+      // Otherwise, use the best fit.
+      ClosestMatch = (*Entry)->NumUnexpArgTokens;
     }
   
-  if (Result == 0) {
+  MacroArgs *Result;
+  if (ResultEnt == 0) {
     // Allocate memory for a MacroArgs object with the lexer tokens at the end.
     Result = (MacroArgs*)malloc(sizeof(MacroArgs) + NumToks*sizeof(Token));
     // Construct the MacroArgs object.
     new (Result) MacroArgs(NumToks, VarargsElided);
   } else {
+    Result = *ResultEnt;
+    // Unlink this node from the preprocessors singly linked list.
+    *ResultEnt = Result->ArgCache;
     Result->NumUnexpArgTokens = NumToks;
     Result->VarargsElided = VarargsElided;
   }





More information about the cfe-commits mailing list