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>()...)),
95 static_assert(!std::is_reference<T>::value,
96 "references should be handled by template specialization");
99 std::bool_constant<
sizeof(U) <= 2 *
sizeof(
void *)>;
101 std::conditional_t<std::is_trivially_copy_constructible<T>::value &&
102 std::is_trivially_move_constructible<T>::value &&
113 template <
typename T>
120 using MovePtrT = void (*)(
void *LHSCallableAddr,
void *RHSCallableAddr);
155 "Should always use all of the out-of-line storage for inline storage!");
214 template <
typename CalledAsT>
217 auto &Func = *
reinterpret_cast<CalledAsT *
>(CallableAddr);
218 return Func(std::forward<ParamTs>(Params)...);
221 template <
typename CallableT>
222 static void MoveImpl(
void *LHSCallableAddr,
void *RHSCallableAddr)
noexcept {
223 new (LHSCallableAddr)
224 CallableT(std::move(*
reinterpret_cast<CallableT *
>(RHSCallableAddr)));
227 template <
typename CallableT>
229 reinterpret_cast<CallableT *
>(CallableAddr)->~CallableT();
240 template <
typename CallableT,
typename CalledAs,
typename Enable =
void>
247 template <
typename CallableT,
typename CalledAs>
258 template <
typename CallableT,
typename CalledAsT>
260 bool IsInlineStorage =
true;
264 IsInlineStorage =
false;
267 auto Size =
sizeof(CallableT);
268 auto Alignment =
alignof(CallableT);
274 new (CallableAddr) CallableT(std::move(Callable));
290 if (!IsInlineStorage)
312 RHS.getInlineStorage());
317 RHS.CallbackAndInlineFlag = {};
319#if !defined(NDEBUG) && !LLVM_ADDRESS_SANITIZER_BUILD
342 explicit operator bool()
const {
347template <
typename R,
typename...
P>
348template <
typename CallableT,
typename CalledAsT,
typename Enable>
349typename UniqueFunctionBase<R,
P...>::NonTrivialCallbacks UniqueFunctionBase<
350 R,
P...>::CallbacksHolder<CallableT, CalledAsT, Enable>::Callbacks = {
351 &CallImpl<CalledAsT>, &MoveImpl<CallableT>, &DestroyImpl<CallableT>};
353template <
typename R,
typename...
P>
354template <
typename CallableT,
typename CalledAsT>
355typename UniqueFunctionBase<R,
P...>::TrivialCallback
356 UniqueFunctionBase<R,
P...>::CallbacksHolder<
358 &CallImpl<CalledAsT>};
362template <
typename R,
typename...
P>
374 template <
typename CallableT>
379 : Base(
std::forward<CallableT>(Callable),
380 typename Base::template CalledAs<CallableT>{}) {}
387template <
typename R,
typename...
P>
400 template <
typename CallableT>
405 : Base(
std::forward<CallableT>(Callable),
406 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::bool_constant< sizeof(U)<=2 *sizeof(void *)> IsSizeLessThanThresholdT
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]