[llvm-commits] [llvm] r155761 - /llvm/trunk/include/llvm/Support/type_traits.h
Benjamin Kramer
benny.kra at googlemail.com
Sat Apr 28 09:22:32 PDT 2012
Author: d0k
Date: Sat Apr 28 11:22:31 2012
New Revision: 155761
URL: http://llvm.org/viewvc/llvm-project?rev=155761&view=rev
Log:
If the __is_trivially_copyable type trait is available use it as the baseline for isPodLike.
This way we can enable the POD-like class optimization for a lot more classes,
saving ~120k of code in clang/i386/Release+Asserts when selfhosting.
Modified:
llvm/trunk/include/llvm/Support/type_traits.h
Modified: llvm/trunk/include/llvm/Support/type_traits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/type_traits.h?rev=155761&r1=155760&r2=155761&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/type_traits.h (original)
+++ llvm/trunk/include/llvm/Support/type_traits.h Sat Apr 28 11:22:31 2012
@@ -21,6 +21,11 @@
#include <cstddef>
#include <utility>
+#ifndef __has_feature
+#define LLVM_DEFINED_HAS_FEATURE
+#define __has_feature(x) 0
+#endif
+
// This is actually the conforming implementation which works with abstract
// classes. However, enough compilers have trouble with it that most will use
// the one in boost/type_traits/object_traits.hpp. This implementation actually
@@ -58,9 +63,15 @@
/// type can be copied around with memcpy instead of running ctors etc.
template <typename T>
struct isPodLike {
+#if __has_feature(is_trivially_copyable)
+ // If the compiler supports the is_trivially_copyable trait use it, as it
+ // matches the definition of isPodLike closely.
+ static const bool value = __is_trivially_copyable(T);
+#else
// If we don't know anything else, we can (at least) assume that all non-class
// types are PODs.
static const bool value = !is_class<T>::value;
+#endif
};
// std::pair's are pod-like if their elements are.
@@ -202,4 +213,8 @@
}
+#ifdef LLVM_DEFINED_HAS_FEATURE
+#undef __has_feature
+#endif
+
#endif
More information about the llvm-commits
mailing list