forked from OSchip/llvm-project
Use __builtin_operator_new/__builtin_operator_delete when available. This
allows allocations and deallocations to be optimized out. llvm-svn: 210211
This commit is contained in:
parent
58a0a70fb2
commit
ff0aff3caf
|
@ -550,12 +550,20 @@ template <unsigned> struct __static_assert_check {};
|
||||||
#define __has_feature(__x) 0
|
#define __has_feature(__x) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __has_builtin
|
||||||
|
#define __has_builtin(__x) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__)
|
#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__)
|
||||||
# define _LIBCPP_EXPLICIT explicit
|
# define _LIBCPP_EXPLICIT explicit
|
||||||
#else
|
#else
|
||||||
# define _LIBCPP_EXPLICIT
|
# define _LIBCPP_EXPLICIT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete)
|
||||||
|
# define _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
|
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
|
||||||
#define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
|
#define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
|
||||||
#define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
|
#define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
|
||||||
|
|
|
@ -55,14 +55,14 @@ public:
|
||||||
__allocated_ = true;
|
__allocated_ = true;
|
||||||
return (pointer)&buf_;
|
return (pointer)&buf_;
|
||||||
}
|
}
|
||||||
return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));
|
return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
|
||||||
}
|
}
|
||||||
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type)
|
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type)
|
||||||
{
|
{
|
||||||
if (__p == (pointer)&buf_)
|
if (__p == (pointer)&buf_)
|
||||||
__allocated_ = false;
|
__allocated_ = false;
|
||||||
else
|
else
|
||||||
::operator delete(__p);
|
_VSTD::__deallocate(__p);
|
||||||
}
|
}
|
||||||
_LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
|
_LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
|
||||||
|
|
||||||
|
|
|
@ -147,12 +147,12 @@ private:
|
||||||
assert(!"dynarray::allocation");
|
assert(!"dynarray::allocation");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return static_cast<value_type *> (::operator new (sizeof(value_type) * count));
|
return static_cast<value_type *> (_VSTD::__allocate (sizeof(value_type) * count));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline _LIBCPP_INLINE_VISIBILITY void __deallocate ( value_type* __ptr ) noexcept
|
static inline _LIBCPP_INLINE_VISIBILITY void __deallocate ( value_type* __ptr ) noexcept
|
||||||
{
|
{
|
||||||
::operator delete (static_cast<void *> (__ptr));
|
_VSTD::__deallocate (static_cast<void *> (__ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1631,9 +1631,9 @@ public:
|
||||||
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
|
||||||
{return _VSTD::addressof(__x);}
|
{return _VSTD::addressof(__x);}
|
||||||
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
|
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
|
||||||
{return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
|
{return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
|
||||||
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
|
||||||
{::operator delete((void*)__p);}
|
{_VSTD::__deallocate((void*)__p);}
|
||||||
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
|
||||||
{return size_type(~0) / sizeof(_Tp);}
|
{return size_type(~0) / sizeof(_Tp);}
|
||||||
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
||||||
|
@ -1721,9 +1721,9 @@ public:
|
||||||
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
|
||||||
{return _VSTD::addressof(__x);}
|
{return _VSTD::addressof(__x);}
|
||||||
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
|
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
|
||||||
{return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
|
{return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
|
||||||
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
|
||||||
{::operator delete((void*)__p);}
|
{_VSTD::__deallocate((void*)__p);}
|
||||||
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
|
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
|
||||||
{return size_type(~0) / sizeof(_Tp);}
|
{return size_type(~0) / sizeof(_Tp);}
|
||||||
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
||||||
|
|
|
@ -147,4 +147,24 @@ inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _N
|
||||||
inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {}
|
inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {}
|
||||||
inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {}
|
inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {}
|
||||||
|
|
||||||
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY void *__allocate(size_t __size) {
|
||||||
|
#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
|
||||||
|
return ::operator new(__size);
|
||||||
|
#else
|
||||||
|
return __builtin_operator_new(__size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY void __deallocate(void *__ptr) {
|
||||||
|
#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
|
||||||
|
::operator delete(__ptr);
|
||||||
|
#else
|
||||||
|
__builtin_operator_delete(__ptr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
_LIBCPP_END_NAMESPACE_STD
|
||||||
|
|
||||||
#endif // _LIBCPP_NEW
|
#endif // _LIBCPP_NEW
|
||||||
|
|
|
@ -345,6 +345,7 @@ template <class T> unspecified2 end(const valarray<T>& v);
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
#include <__undef_min_max>
|
#include <__undef_min_max>
|
||||||
|
|
||||||
|
@ -2636,7 +2637,7 @@ __val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
|
||||||
{
|
{
|
||||||
__r.__begin_ =
|
__r.__begin_ =
|
||||||
__r.__end_ =
|
__r.__end_ =
|
||||||
static_cast<result_type*>(::operator new(__n * sizeof(result_type)));
|
static_cast<result_type*>(_VSTD::__allocate(__n * sizeof(result_type)));
|
||||||
for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
|
for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
|
||||||
::new (__r.__end_) result_type(__expr_[__i]);
|
::new (__r.__end_) result_type(__expr_[__i]);
|
||||||
}
|
}
|
||||||
|
@ -2670,7 +2671,7 @@ valarray<_Tp>::valarray(const value_type* __p, size_t __n)
|
||||||
{
|
{
|
||||||
if (__n)
|
if (__n)
|
||||||
{
|
{
|
||||||
__begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
__begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -2695,7 +2696,7 @@ valarray<_Tp>::valarray(const valarray& __v)
|
||||||
{
|
{
|
||||||
if (__v.size())
|
if (__v.size())
|
||||||
{
|
{
|
||||||
__begin_ = __end_ = static_cast<value_type*>(::operator new(__v.size() * sizeof(value_type)));
|
__begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__v.size() * sizeof(value_type)));
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -2736,7 +2737,7 @@ valarray<_Tp>::valarray(initializer_list<value_type> __il)
|
||||||
size_t __n = __il.size();
|
size_t __n = __il.size();
|
||||||
if (__n)
|
if (__n)
|
||||||
{
|
{
|
||||||
__begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
__begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -2764,7 +2765,7 @@ valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
|
||||||
size_t __n = __sa.__size_;
|
size_t __n = __sa.__size_;
|
||||||
if (__n)
|
if (__n)
|
||||||
{
|
{
|
||||||
__begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
__begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -2790,7 +2791,7 @@ valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
|
||||||
size_t __n = __ga.__1d_.size();
|
size_t __n = __ga.__1d_.size();
|
||||||
if (__n)
|
if (__n)
|
||||||
{
|
{
|
||||||
__begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
__begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -2819,7 +2820,7 @@ valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
|
||||||
size_t __n = __ma.__1d_.size();
|
size_t __n = __ma.__1d_.size();
|
||||||
if (__n)
|
if (__n)
|
||||||
{
|
{
|
||||||
__begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
__begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -2848,7 +2849,7 @@ valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
|
||||||
size_t __n = __ia.__1d_.size();
|
size_t __n = __ia.__1d_.size();
|
||||||
if (__n)
|
if (__n)
|
||||||
{
|
{
|
||||||
__begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
__begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -3133,7 +3134,7 @@ valarray<_Tp>::operator+() const
|
||||||
{
|
{
|
||||||
__r.__begin_ =
|
__r.__begin_ =
|
||||||
__r.__end_ =
|
__r.__end_ =
|
||||||
static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
||||||
::new (__r.__end_) value_type(+*__p);
|
::new (__r.__end_) value_type(+*__p);
|
||||||
}
|
}
|
||||||
|
@ -3150,7 +3151,7 @@ valarray<_Tp>::operator-() const
|
||||||
{
|
{
|
||||||
__r.__begin_ =
|
__r.__begin_ =
|
||||||
__r.__end_ =
|
__r.__end_ =
|
||||||
static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
||||||
::new (__r.__end_) value_type(-*__p);
|
::new (__r.__end_) value_type(-*__p);
|
||||||
}
|
}
|
||||||
|
@ -3167,7 +3168,7 @@ valarray<_Tp>::operator~() const
|
||||||
{
|
{
|
||||||
__r.__begin_ =
|
__r.__begin_ =
|
||||||
__r.__end_ =
|
__r.__end_ =
|
||||||
static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
||||||
::new (__r.__end_) value_type(~*__p);
|
::new (__r.__end_) value_type(~*__p);
|
||||||
}
|
}
|
||||||
|
@ -3184,7 +3185,7 @@ valarray<_Tp>::operator!() const
|
||||||
{
|
{
|
||||||
__r.__begin_ =
|
__r.__begin_ =
|
||||||
__r.__end_ =
|
__r.__end_ =
|
||||||
static_cast<bool*>(::operator new(__n * sizeof(bool)));
|
static_cast<bool*>(_VSTD::__allocate(__n * sizeof(bool)));
|
||||||
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
||||||
::new (__r.__end_) bool(!*__p);
|
::new (__r.__end_) bool(!*__p);
|
||||||
}
|
}
|
||||||
|
@ -3504,7 +3505,7 @@ valarray<_Tp>::shift(int __i) const
|
||||||
{
|
{
|
||||||
__r.__begin_ =
|
__r.__begin_ =
|
||||||
__r.__end_ =
|
__r.__end_ =
|
||||||
static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
const value_type* __sb;
|
const value_type* __sb;
|
||||||
value_type* __tb;
|
value_type* __tb;
|
||||||
value_type* __te;
|
value_type* __te;
|
||||||
|
@ -3542,7 +3543,7 @@ valarray<_Tp>::cshift(int __i) const
|
||||||
{
|
{
|
||||||
__r.__begin_ =
|
__r.__begin_ =
|
||||||
__r.__end_ =
|
__r.__end_ =
|
||||||
static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
__i %= static_cast<int>(__n);
|
__i %= static_cast<int>(__n);
|
||||||
const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
|
const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
|
||||||
for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
|
for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
|
||||||
|
@ -3563,7 +3564,7 @@ valarray<_Tp>::apply(value_type __f(value_type)) const
|
||||||
{
|
{
|
||||||
__r.__begin_ =
|
__r.__begin_ =
|
||||||
__r.__end_ =
|
__r.__end_ =
|
||||||
static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
||||||
::new (__r.__end_) value_type(__f(*__p));
|
::new (__r.__end_) value_type(__f(*__p));
|
||||||
}
|
}
|
||||||
|
@ -3580,7 +3581,7 @@ valarray<_Tp>::apply(value_type __f(const value_type&)) const
|
||||||
{
|
{
|
||||||
__r.__begin_ =
|
__r.__begin_ =
|
||||||
__r.__end_ =
|
__r.__end_ =
|
||||||
static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
|
||||||
::new (__r.__end_) value_type(__f(*__p));
|
::new (__r.__end_) value_type(__f(*__p));
|
||||||
}
|
}
|
||||||
|
@ -3595,12 +3596,12 @@ valarray<_Tp>::resize(size_t __n, value_type __x)
|
||||||
{
|
{
|
||||||
while (__end_ != __begin_)
|
while (__end_ != __begin_)
|
||||||
(--__end_)->~value_type();
|
(--__end_)->~value_type();
|
||||||
::operator delete(__begin_);
|
_VSTD::__deallocate(__begin_);
|
||||||
__begin_ = __end_ = nullptr;
|
__begin_ = __end_ = nullptr;
|
||||||
}
|
}
|
||||||
if (__n)
|
if (__n)
|
||||||
{
|
{
|
||||||
__begin_ = __end_ = static_cast<value_type*>(::operator new(__n * sizeof(value_type)));
|
__begin_ = __end_ = static_cast<value_type*>(_VSTD::__allocate(__n * sizeof(value_type)));
|
||||||
#ifndef _LIBCPP_NO_EXCEPTIONS
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue