LLVM 20.0.0git
Classes | Namespaces
TrailingObjects.h File Reference

This header defines support for implementing classes that have some trailing object (or arrays of objects) appended to them. More...

#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/type_traits.h"
#include <new>
#include <type_traits>

Go to the source code of this file.

Classes

class  llvm::trailing_objects_internal::AlignmentCalcHelper< First, Rest >
 Helper template to calculate the max alignment requirement for a set of objects. More...
 
class  llvm::trailing_objects_internal::AlignmentCalcHelper< First >
 
class  llvm::trailing_objects_internal::TrailingObjectsBase
 The base class for TrailingObjects* classes. More...
 
struct  llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken< T >
 OverloadToken's purpose is to allow specifying function overloads for different types, without actually taking the types as parameters. More...
 
struct  llvm::trailing_objects_internal::ExtractSecondType< Ty1, Ty2 >
 
class  llvm::trailing_objects_internal::TrailingObjectsImpl< Align, BaseTy, TopTrailingObj, PrevTy, MoreTys >
 
class  llvm::trailing_objects_internal::TrailingObjectsImpl< Align, BaseTy, TopTrailingObj, PrevTy, NextTy, MoreTys... >
 
class  llvm::trailing_objects_internal::TrailingObjectsImpl< Align, BaseTy, TopTrailingObj, PrevTy >
 
class  llvm::TrailingObjects< BaseTy, TrailingTys >
 See the file comment for details on the usage of the TrailingObjects type. More...
 
struct  llvm::TrailingObjects< BaseTy, TrailingTys >::FixedSizeStorage< Tys >
 A type where its ::with_counts template member has a ::type member suitable for use as uninitialized storage for an object with the given trailing object counts. More...
 
struct  llvm::TrailingObjects< BaseTy, TrailingTys >::FixedSizeStorage< Tys >::with_counts< Counts >
 
struct  llvm::TrailingObjects< BaseTy, TrailingTys >::FixedSizeStorage< Tys >::with_counts< Counts >::type
 
class  llvm::TrailingObjects< BaseTy, TrailingTys >::FixedSizeStorageOwner
 A type that acts as the owner for an object placed into fixed storage. More...
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 
namespace  llvm::trailing_objects_internal
 

Detailed Description

This header defines support for implementing classes that have some trailing object (or arrays of objects) appended to them.

The main purpose is to make it obvious where this idiom is being used, and to make the usage more idiomatic and more difficult to get wrong.

The TrailingObject template abstracts away the reinterpret_cast, pointer arithmetic, and size calculations used for the allocation and access of appended arrays of objects, and takes care that they are all allocated at their required alignment. Additionally, it ensures that the base type is final – deriving from a class that expects data appended immediately after it is typically not safe.

Users are expected to derive from this template, and provide numTrailingObjects implementations for each trailing type except the last, e.g. like this sample:

class VarLengthObj : private TrailingObjects<VarLengthObj, int, double> {
friend TrailingObjects;
unsigned NumInts, NumDoubles;
size_t numTrailingObjects(OverloadToken<int>) const { return NumInts; }
};

You can access the appended arrays via 'getTrailingObjects', and determine the size needed for allocation via 'additionalSizeToAlloc' and 'totalSizeToAlloc'.

All the methods implemented by this class are intended for use by the implementation of the class, not as part of its interface (thus, private inheritance is suggested).

Definition in file TrailingObjects.h.