aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-17 21:15:18 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-17 21:15:18 +0000
commitb372c1114c1eeffbd1a3f6ddc5d33e77564bfee2 (patch)
tree023532e358a24263eeb1eb2677711fb2c6e9f5c5
parent3985728bdefeec6acdcdf4dc78cbe1b9fb7cb72b (diff)
downloadexternal_llvm-b372c1114c1eeffbd1a3f6ddc5d33e77564bfee2.zip
external_llvm-b372c1114c1eeffbd1a3f6ddc5d33e77564bfee2.tar.gz
external_llvm-b372c1114c1eeffbd1a3f6ddc5d33e77564bfee2.tar.bz2
Add BUILTIN_EXPECT Support/Compiler macro.
- Use for exceptional buffer conditions in raw_ostream:write to shave off a cycle or two. - Please rename if you have a better one. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67103 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/Compiler.h6
-rw-r--r--lib/Support/raw_ostream.cpp3
2 files changed, 8 insertions, 1 deletions
diff --git a/include/llvm/Support/Compiler.h b/include/llvm/Support/Compiler.h
index 7186b22..90292df 100644
--- a/include/llvm/Support/Compiler.h
+++ b/include/llvm/Support/Compiler.h
@@ -29,6 +29,12 @@
#define ATTRIBUTE_USED
#endif
+#if (__GNUC__ >= 4)
+#define BUILTIN_EXPECT(EXPR, VALUE) __builtin_expect((EXPR), (VALUE))
+#else
+#define BUILTIN_EXPECT(EXPR, VALUE) (EXPR)
+#endif
+
// C++ doesn't support 'extern template' of template specializations. GCC does,
// but requires __extension__ before it. In the header, use this:
// EXTERN_TEMPLATE_INSTANTIATION(class foo<bar>);
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 639d6fa..f62a31d 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -16,6 +16,7 @@
#include "llvm/System/Program.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Config/config.h"
+#include "llvm/Support/Compiler.h"
#include <ostream>
#if defined(HAVE_UNISTD_H)
@@ -142,7 +143,7 @@ raw_ostream &raw_ostream::write(unsigned char C) {
raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
// Group exceptional cases into a single branch.
- if (OutBufCur+Size > OutBufEnd) {
+ if (BUILTIN_EXPECT(OutBufCur+Size > OutBufEnd, false)) {
if (Unbuffered) {
write_impl(Ptr, Size);
return *this;