[llvm] r288611 - TableGen: Optimize common string concatenation with SmallString

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 3 21:48:06 PST 2016


Author: matze
Date: Sat Dec  3 23:48:06 2016
New Revision: 288611

URL: http://llvm.org/viewvc/llvm-project?rev=288611&view=rev
Log:
TableGen: Optimize common string concatenation with SmallString

Modified:
    llvm/trunk/lib/TableGen/Record.cpp

Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=288611&r1=288610&r2=288611&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Sat Dec  3 23:48:06 2016
@@ -15,6 +15,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -839,8 +840,12 @@ Init *BinOpInit::Fold(Record *CurRec, Mu
   case STRCONCAT: {
     StringInit *LHSs = dyn_cast<StringInit>(LHS);
     StringInit *RHSs = dyn_cast<StringInit>(RHS);
-    if (LHSs && RHSs)
-      return StringInit::get(LHSs->getValue() + RHSs->getValue());
+    if (LHSs && RHSs) {
+      // STRCONCAT is common; Use a SmallString to avoid most heap allocations.
+      SmallString<80> Concat(LHSs->getValue());
+      Concat.append(RHSs->getValue());
+      return StringInit::get(Concat);
+    }
     break;
   }
   case EQ: {




More information about the llvm-commits mailing list