32#ifndef LLVM_ADT_FUNCTIONEXTRAS_H
33#define LLVM_ADT_FUNCTIONEXTRAS_H
63 std::enable_if_t<std::is_trivially_move_constructible<T>::value &&
64 std::is_trivially_destructible<T>::value>;
65template <
typename CallableT,
typename ThisT>
67 std::enable_if_t<!std::is_same<remove_cvref_t<CallableT>, ThisT>
::value>;
68template <
typename CallableT,
typename Ret,
typename... Params>
71 std::is_same<decltype(std::declval<CallableT>()(std::declval<Params>()...)),
73 std::is_same<
const decltype(std::declval<CallableT>()(
74 std::declval<Params>()...)),
76 std::is_convertible<
decltype(std::declval<CallableT>()(
77 std::declval<Params>()...)),
85 template <
typename T,
class =
void>
90 T,
std::enable_if_t<sizeof(T) <= 2 * sizeof(void *)>> : std::true_type {};
102 static_assert(!std::is_reference<T>::value,
103 "references should be handled by template specialization");
105 std::conditional_t<std::is_trivially_copy_constructible<T>::value &&
106 std::is_trivially_move_constructible<T>::value &&
117 template <
typename T>
124 using MovePtrT = void (*)(
void *LHSCallableAddr,
void *RHSCallableAddr);
159 "Should always use all of the out-of-line storage for inline storage!");
218 template <
typename CalledAsT>
221 auto &Func = *
reinterpret_cast<CalledAsT *
>(CallableAddr);
222 return Func(std::forward<ParamTs>(Params)...);
225 template <
typename CallableT>
226 static void MoveImpl(
void *LHSCallableAddr,
void *RHSCallableAddr)
noexcept {
227 new (LHSCallableAddr)
228 CallableT(std::move(*
reinterpret_cast<CallableT *
>(RHSCallableAddr)));
231 template <
typename CallableT>
233 reinterpret_cast<CallableT *
>(CallableAddr)->~CallableT();
244 template <
typename CallableT,
typename CalledAs,
typename Enable =
void>
251 template <
typename CallableT,
typename CalledAs>
262 template <
typename CallableT,
typename CalledAsT>
264 bool IsInlineStorage =
true;
268 IsInlineStorage =
false;
271 auto Size =
sizeof(CallableT);
272 auto Alignment =
alignof(CallableT);
278 new (CallableAddr) CallableT(std::move(Callable));
294 if (!IsInlineStorage)
316 RHS.getInlineStorage());
321 RHS.CallbackAndInlineFlag = {};
323#if !defined(NDEBUG) && !LLVM_ADDRESS_SANITIZER_BUILD
346 explicit operator bool()
const {
351template <
typename R,
typename...
P>
352template <
typename CallableT,
typename CalledAsT,
typename Enable>
353typename UniqueFunctionBase<R,
P...>::NonTrivialCallbacks UniqueFunctionBase<
354 R,
P...>::CallbacksHolder<CallableT, CalledAsT, Enable>::Callbacks = {
355 &CallImpl<CalledAsT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
357template <
typename R,
typename...
P>
358template <
typename CallableT,
typename CalledAsT>
359typename UniqueFunctionBase<R,
P...>::TrivialCallback
360 UniqueFunctionBase<R,
P...>::CallbacksHolder<
362 &CallImpl<CalledAsT>};
366template <
typename R,
typename...
P>
378 template <
typename CallableT>
383 : Base(
std::forward<CallableT>(Callable),
384 typename Base::template CalledAs<CallableT>{}) {}
391template <
typename R,
typename...
P>
404 template <
typename CallableT>
409 : Base(
std::forward<CallableT>(Callable),
410 typename Base::template CalledAs<
const CallableT>{}) {}
This file defines counterparts of C library allocation functions defined in the namespace 'std'.
This file defines the PointerIntPair class.
This file defines the PointerUnion class, which is a discriminated union of pointer types.
This file contains library features backported from future STL versions.
PointerIntPair - This class implements a pair of a pointer and small integer.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
CallPtrT getCallPtr() const
void(*)(void *LHSCallableAddr, void *RHSCallableAddr) MovePtrT
void * getInlineStorage() const
CallPtrT getTrivialCallback() const
PointerIntPair< CallbackPointerUnionT, 1, bool > CallbackAndInlineFlag
UniqueFunctionBase()=default
void * getOutOfLineStorage() const
void setOutOfLineStorage(void *Ptr, size_t Size, size_t Alignment)
UniqueFunctionBase & operator=(UniqueFunctionBase &&RHS) noexcept
typename AdjustedParamTBase< T >::type AdjustedParamT
NonTrivialCallbacks * getNonTrivialCallbacks() const
PointerUnion< TrivialCallback *, NonTrivialCallbacks * > CallbackPointerUnionT
UniqueFunctionBase(CallableT Callable, CalledAs< CalledAsT >)
static void MoveImpl(void *LHSCallableAddr, void *RHSCallableAddr) noexcept
static void DestroyImpl(void *CallableAddr) noexcept
bool isInlineStorage() const
size_t getOutOfLineStorageSize() const
static ReturnT CallImpl(void *CallableAddr, AdjustedParamT< ParamTs >... Params)
void * getCalleePtr() const
static constexpr size_t InlineStorageAlign
size_t getOutOfLineStorageAlignment() const
union llvm::detail::UniqueFunctionBase::StorageUnionT StorageUnion
void(*)(void *CallableAddr) DestroyPtrT
ReturnT(*)(void *CallableAddr, AdjustedParamT< ParamTs >... Params) CallPtrT
UniqueFunctionBase(UniqueFunctionBase &&RHS) noexcept
bool isTrivialCallback() const
static constexpr size_t InlineStorageSize
unique_function(std::nullptr_t)
unique_function()=default
unique_function(const unique_function &)=delete
unique_function(unique_function &&)=default
unique_function & operator=(const unique_function &)=delete
unique_function & operator=(unique_function &&)=default
R operator()(P... Params) const
unique_function(CallableT Callable, detail::EnableUnlessSameType< CallableT, unique_function > *=nullptr, detail::EnableIfCallable< const CallableT, R, P... > *=nullptr)
unique_function(unique_function &&)=default
unique_function & operator=(const unique_function &)=delete
unique_function(CallableT Callable, detail::EnableUnlessSameType< CallableT, unique_function > *=nullptr, detail::EnableIfCallable< CallableT, R, P... > *=nullptr)
unique_function & operator=(unique_function &&)=default
R operator()(P... Params)
unique_function()=default
unique_function(std::nullptr_t)
unique_function(const unique_function &)=delete
unique_function is a type-erasing functor similar to std::function.
std::enable_if_t<!std::is_same< remove_cvref_t< CallableT >, ThisT >::value > EnableUnlessSameType
const char unit< Period >::value[]
UniqueFunctionBase< R, P... >::NonTrivialCallbacks UniqueFunctionBase< R, P... >::CallbacksHolder< CallableT, CalledAsT, Enable >::Callbacks
std::enable_if_t< std::disjunction< std::is_void< Ret >, std::is_same< decltype(std::declval< CallableT >()(std::declval< Params >()...)), Ret >, std::is_same< const decltype(std::declval< CallableT >()( std::declval< Params >()...)), Ret >, std::is_convertible< decltype(std::declval< CallableT >()( std::declval< Params >()...)), Ret > >::value > EnableIfCallable
std::enable_if_t< std::is_trivially_move_constructible< T >::value && std::is_trivially_destructible< T >::value > EnableIfTrivial
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * allocate_buffer(size_t Size, size_t Alignment)
Allocate a buffer of memory with the given size and alignment.
LLVM_ABI void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment)
Deallocate a buffer of memory with the given size and alignment.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Implement std::hash so that hash_code can be used in STL containers.
std::conditional_t< std::is_trivially_copy_constructible< T >::value && std::is_trivially_move_constructible< T >::value && IsSizeLessThanThresholdT< T >::value, T, T & > type
static TrivialCallback Callbacks
static NonTrivialCallbacks Callbacks
A struct we use to aggregate three callbacks when we need full set of operations.
A struct to hold a single trivial callback with sufficient alignment for our bitpacking.
struct llvm::detail::UniqueFunctionBase::StorageUnionT::OutOfLineStorageT OutOfLineStorage
std::byte InlineStorage[InlineStorageSize]