[llvm-commits] [llvm] r68396 - /llvm/trunk/include/llvm/Support/raw_ostream.h

Daniel Dunbar daniel at zuster.org
Fri Apr 3 11:43:18 PDT 2009


Author: ddunbar
Date: Fri Apr  3 13:43:17 2009
New Revision: 68396

URL: http://llvm.org/viewvc/llvm-project?rev=68396&view=rev
Log:
Add fast path for raw_ostream output of strings.
 - Particularly nice for small constant strings, which get optimized
   down nicely. On a synthetic benchmark writing out "hello" in a
   loop, this is about 2x faster with gcc and 3x faster with
   llvm-gcc. llc on insn-attrtab.bc from 403.gcc is about .5% faster.

 - I tried for a fancier solution which wouldn't increase code size as
   much (by trying to match constant arrays), but can't quite make it
   fly.

Modified:
    llvm/trunk/include/llvm/Support/raw_ostream.h

Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=68396&r1=68395&r2=68396&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Fri Apr  3 13:43:17 2009
@@ -119,7 +119,17 @@
   }
 
   raw_ostream &operator<<(const char *Str) {
-    write(Str, strlen(Str));
+    // Inline fast path, particulary for constant strings where a
+    // sufficiently smart compiler will simplify strlen.
+
+    unsigned Size = strlen(Str);
+
+    // Make sure we can use the fast path.
+    if (OutBufCur+Size > OutBufEnd)
+      return write(Str, Size);
+
+    memcpy(OutBufCur, Str, Size);
+    OutBufCur += Size;
     return *this;
   }
 





More information about the llvm-commits mailing list