46#ifndef LLVM_SUPPORT_TRAILINGOBJECTS_H
47#define LLVM_SUPPORT_TRAILINGOBJECTS_H
59namespace trailing_objects_internal {
65 FirstAlignment =
alignof(
First),
71 Alignment = FirstAlignment > RestAlignment ? FirstAlignment : RestAlignment
77 enum { Alignment =
alignof(
First) };
106template <
int Align,
typename BaseTy,
typename TopTrailingObj,
typename PrevTy,
113template <
int Align,
typename BaseTy,
typename TopTrailingObj,
typename PrevTy,
114 typename NextTy,
typename... MoreTys>
123 struct RequiresRealignment {
124 static const bool value =
alignof(PrevTy) <
alignof(NextTy);
127 static constexpr bool requiresRealignment() {
128 return RequiresRealignment::value;
133 using ParentType::getTrailingObjectsImpl;
144 static const NextTy *
147 auto *
Ptr = TopTrailingObj::getTrailingObjectsImpl(
149 TopTrailingObj::callNumTrailingObjects(
152 if (requiresRealignment())
153 return reinterpret_cast<const NextTy *
>(
156 return reinterpret_cast<const NextTy *
>(
Ptr);
162 auto *
Ptr = TopTrailingObj::getTrailingObjectsImpl(
164 TopTrailingObj::callNumTrailingObjects(
167 if (requiresRealignment())
168 return reinterpret_cast<NextTy *
>(
alignAddr(
Ptr, Align::Of<NextTy>()));
170 return reinterpret_cast<NextTy *
>(
Ptr);
177 size_t SizeSoFar,
size_t Count1,
179 return ParentType::additionalSizeToAllocImpl(
180 (requiresRealignment() ?
llvm::alignTo<
alignof(NextTy)>(SizeSoFar)
182 sizeof(NextTy) * Count1,
189template <
int Align,
typename BaseTy,
typename TopTrailingObj,
typename PrevTy>
211template <
typename BaseTy,
typename... TrailingTys>
213 trailing_objects_internal::AlignmentCalcHelper<
214 TrailingTys...>::Alignment,
215 BaseTy, TrailingObjects<BaseTy, TrailingTys...>,
216 BaseTy, TrailingTys...> {
218 template <
int A,
typename B,
typename T,
typename P,
typename... M>
221 template <
typename... Tys>
class Foo {};
229 using ParentType::getTrailingObjectsImpl;
231 template <
bool Strict>
static void verifyTrailingObjectsAssertions() {
235 static_assert(std::is_final<BaseTy>(),
"BaseTy must be final.");
240 static_assert(!Strict ||
sizeof...(TrailingTys) > 1,
241 "Use templated getTrailingObjects() only when there are "
242 "multiple trailing types");
247 getTrailingObjectsImpl(
const BaseTy *Obj,
248 TrailingObjectsBase::OverloadToken<BaseTy>) {
253 getTrailingObjectsImpl(
BaseTy *Obj,
254 TrailingObjectsBase::OverloadToken<BaseTy>) {
266 callNumTrailingObjects(
const BaseTy *Obj,
267 TrailingObjectsBase::OverloadToken<BaseTy>) {
271 template <
typename T>
272 static size_t callNumTrailingObjects(
const BaseTy *Obj,
273 TrailingObjectsBase::OverloadToken<T>) {
274 return Obj->numTrailingObjects(TrailingObjectsBase::OverloadToken<T>());
280 using ParentType::OverloadToken;
284 template <
typename T>
285 using OverloadToken =
typename ParentType::template OverloadToken<T>;
292 verifyTrailingObjectsAssertions<true>();
295 return this->getTrailingObjectsImpl(
296 static_cast<const BaseTy *
>(
this),
304 verifyTrailingObjectsAssertions<true>();
307 return this->getTrailingObjectsImpl(
313 typename std::tuple_element_t<0, std::tuple<TrailingTys...>>;
316 static_assert(
sizeof...(TrailingTys) == 1,
317 "Can use non-templated getTrailingObjects() only when there "
318 "is a single trailing type");
319 verifyTrailingObjectsAssertions<false>();
320 return this->getTrailingObjectsImpl(
321 static_cast<const BaseTy *
>(
this),
326 static_assert(
sizeof...(TrailingTys) == 1,
327 "Can use non-templated getTrailingObjects() only when there "
328 "is a single trailing type");
329 verifyTrailingObjectsAssertions<false>();
330 return this->getTrailingObjectsImpl(
331 static_cast<BaseTy *
>(
this),
341 return ArrayRef(getTrailingObjects<T>(),
N);
349 return ArrayRef(getTrailingObjects(),
N);
355 verifyTrailingObjectsAssertions<false>();
356 return this->getTrailingObjectsImpl(
357 static_cast<const BaseTy *
>(
this),
362 verifyTrailingObjectsAssertions<false>();
363 return this->getTrailingObjectsImpl(
367 template <
typename T>
372 template <
typename T>
374 return ArrayRef(getTrailingObjectsNonStrict<T>(),
N);
383 template <
typename... Tys>
384 static constexpr std::enable_if_t<
385 std::is_same_v<Foo<TrailingTys...>, Foo<Tys...>>,
size_t>
387 TrailingTys,
size_t>::type... Counts) {
388 return ParentType::additionalSizeToAllocImpl(0, Counts...);
395 template <
typename... Tys>
396 static constexpr std::enable_if_t<
397 std::is_same_v<Foo<TrailingTys...>, Foo<Tys...>>,
size_t>
399 TrailingTys,
size_t>::type... Counts) {
400 return sizeof(
BaseTy) + ParentType::additionalSizeToAllocImpl(0, Counts...);
426 enum {
Size = totalSizeToAlloc<Tys...>(Counts...) };
438 assert(p &&
"FixedSizeStorageOwner owns null?");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Given that RA is a live value
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
A type that acts as the owner for an object placed into fixed storage.
FixedSizeStorageOwner(BaseTy *p)
const BaseTy * get() const
See the file comment for details on the usage of the TrailingObjects type.
TrailingObjects & operator=(TrailingObjects &&)=delete
const FirstTrailingType * getTrailingObjects() const
MutableArrayRef< T > getTrailingObjects(size_t N)
const T * getTrailingObjectsNonStrict() const
static constexpr std::enable_if_t< std::is_same_v< Foo< TrailingTys... >, Foo< Tys... > >, size_t > totalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType< TrailingTys, size_t >::type... Counts)
Returns the total size of an object if it were allocated with the given trailing object counts.
T * getTrailingObjectsNonStrict()
TrailingObjects & operator=(const TrailingObjects &)=delete
FirstTrailingType * getTrailingObjects()
ArrayRef< FirstTrailingType > getTrailingObjects(size_t N) const
typename std::tuple_element_t< 0, std::tuple< TrailingTys... > > FirstTrailingType
ArrayRef< T > getTrailingObjectsNonStrict(size_t N) const
static constexpr std::enable_if_t< std::is_same_v< Foo< TrailingTys... >, Foo< Tys... > >, size_t > additionalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType< TrailingTys, size_t >::type... Counts)
Returns the size of the trailing data, if an object were allocated with the given counts (The counts ...
TrailingObjects(TrailingObjects &&)=delete
MutableArrayRef< T > getTrailingObjectsNonStrict(size_t N)
T * getTrailingObjects()
Returns a pointer to the trailing object array of the given type (which must be one of those specifie...
MutableArrayRef< FirstTrailingType > getTrailingObjects(size_t N)
const T * getTrailingObjects() const
Returns a pointer to the trailing object array of the given type (which must be one of those specifie...
ArrayRef< T > getTrailingObjects(size_t N) const
TrailingObjects()=default
TrailingObjects(const TrailingObjects &)=delete
Helper template to calculate the max alignment requirement for a set of objects.
The base class for TrailingObjects* classes.
static const NextTy * getTrailingObjectsImpl(const BaseTy *Obj, TrailingObjectsBase::OverloadToken< NextTy >)
static constexpr size_t additionalSizeToAllocImpl(size_t SizeSoFar, size_t Count1, typename ExtractSecondType< MoreTys, size_t >::type... MoreCounts)
static NextTy * getTrailingObjectsImpl(BaseTy *Obj, TrailingObjectsBase::OverloadToken< NextTy >)
static void getTrailingObjectsImpl()
static constexpr size_t additionalSizeToAllocImpl(size_t SizeSoFar)
static void verifyTrailingObjectsAlignment()
This is an optimization pass for GlobalISel generic memory operations.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
uintptr_t alignAddr(const void *Addr, Align Alignment)
Aligns Addr to Alignment bytes, rounding up.
This struct is a compact representation of a valid (non-zero power of two) alignment.
A type where its ::with_counts template member has a ::type member suitable for use as uninitialized ...
OverloadToken's purpose is to allow specifying function overloads for different types,...