32#ifndef LLVM_ADT_FUNCTIONEXTRAS_H
33#define LLVM_ADT_FUNCTIONEXTRAS_H
61template <
typename CallableT,
typename ThisT>
63 std::enable_if_t<!std::is_same<remove_cvref_t<CallableT>, ThisT>
::value>;
64template <
typename CallableT,
typename Ret,
typename... Params>
67 std::is_same<decltype(std::declval<CallableT>()(std::declval<Params>()...)),
69 std::is_same<
const decltype(std::declval<CallableT>()(
70 std::declval<Params>()...)),
72 std::is_convertible<
decltype(std::declval<CallableT>()(
73 std::declval<Params>()...)),
91 static_assert(!std::is_reference<T>::value,
92 "references should be handled by template specialization");
94 sizeof(
T) <= 2 *
sizeof(
void *);
96 std::conditional_t<std::is_trivially_copy_constructible<T>::value &&
97 std::is_trivially_move_constructible<T>::value &&
108 template <
typename T>
115 using MovePtrT = void (*)(
void *LHSCallableAddr,
void *RHSCallableAddr);
150 "Should always use all of the out-of-line storage for inline storage!");
209 template <
typename CalledAsT>
212 auto &Func = *
reinterpret_cast<CalledAsT *
>(CallableAddr);
213 return Func(std::forward<ParamTs>(Params)...);
216 template <
typename CallableT>
217 static void MoveImpl(
void *LHSCallableAddr,
void *RHSCallableAddr)
noexcept {
218 new (LHSCallableAddr)
219 CallableT(std::move(*
reinterpret_cast<CallableT *
>(RHSCallableAddr)));
222 template <
typename CallableT>
224 reinterpret_cast<CallableT *
>(CallableAddr)->~CallableT();
238 if constexpr (std::is_trivially_move_constructible_v<CallableT> &&
239 std::is_trivially_destructible_v<CallableT>)
253 template <
typename CallableT,
typename CalledAsT>
255 bool IsInlineStorage =
true;
259 IsInlineStorage =
false;
262 auto Size =
sizeof(CallableT);
263 auto Alignment =
alignof(CallableT);
269 new (CallableAddr) CallableT(std::move(Callable));
285 if (!IsInlineStorage)
307 RHS.getInlineStorage());
312 RHS.CallbackAndInlineFlag = {};
314#if !defined(NDEBUG) && !LLVM_ADDRESS_SANITIZER_BUILD
337 explicit operator bool()
const {
344template <
typename R,
typename...
P>
356 template <
typename CallableT>
361 : Base(
std::forward<CallableT>(Callable),
362 typename Base::template CalledAs<CallableT>{}) {}
369template <
typename R,
typename...
P>
382 template <
typename CallableT>
387 : Base(
std::forward<CallableT>(Callable),
388 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[]
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
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 && IsSizeLessThanThreshold, T, T & > type
static constexpr bool IsSizeLessThanThreshold
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]