Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:06

0001 //===- llvm/ADT/ilist_node_options.h - ilist_node Options -------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_ADT_ILIST_NODE_OPTIONS_H
0010 #define LLVM_ADT_ILIST_NODE_OPTIONS_H
0011 
0012 #include "llvm/Config/abi-breaking.h"
0013 
0014 #include <type_traits>
0015 
0016 namespace llvm {
0017 
0018 template <bool EnableSentinelTracking, class ParentTy> class ilist_node_base;
0019 template <bool EnableSentinelTracking, class ParentTy> class ilist_base;
0020 
0021 /// Option to choose whether to track sentinels.
0022 ///
0023 /// This option affects the ABI for the nodes.  When not specified explicitly,
0024 /// the ABI depends on LLVM_ENABLE_ABI_BREAKING_CHECKS.  Specify explicitly to
0025 /// enable \a ilist_node::isSentinel().
0026 template <bool EnableSentinelTracking> struct ilist_sentinel_tracking {};
0027 
0028 /// Option to specify a tag for the node type.
0029 ///
0030 /// This option allows a single value type to be inserted in multiple lists
0031 /// simultaneously.  See \a ilist_node for usage examples.
0032 template <class Tag> struct ilist_tag {};
0033 
0034 /// Option to add extra bits to the ilist_iterator.
0035 ///
0036 /// Some use-cases (debug-info) need to know whether a position is intended
0037 /// to be half-open or fully open, i.e. whether to include any immediately
0038 /// adjacent debug-info in an operation. This option adds two bits to the
0039 /// iterator class to store that information.
0040 template <bool ExtraIteratorBits> struct ilist_iterator_bits {};
0041 
0042 /// Option to add a pointer to this list's owner in every node.
0043 ///
0044 /// This option causes the \a ilist_base_node for this list to contain a pointer
0045 /// ParentTy *Parent, returned by \a ilist_base_node::getNodeBaseParent() and
0046 /// set by \a ilist_base_node::setNodeBaseParent(ParentTy *Parent). The parent
0047 /// value is not set automatically; the ilist owner should set itself as the
0048 /// parent of the list sentinel, and the parent should be set on each node
0049 /// inserted into the list. This value is also not used by
0050 /// \a ilist_node_with_parent::getNodeParent(), but is used by \a
0051 /// ilist_iterator::getNodeParent(), which allows the parent to be fetched from
0052 /// any valid (non-null) iterator to this list, including the sentinel.
0053 template <class ParentTy> struct ilist_parent {};
0054 
0055 namespace ilist_detail {
0056 
0057 /// Helper trait for recording whether an option is specified explicitly.
0058 template <bool IsExplicit> struct explicitness {
0059   static const bool is_explicit = IsExplicit;
0060 };
0061 typedef explicitness<true> is_explicit;
0062 typedef explicitness<false> is_implicit;
0063 
0064 /// Check whether an option is valid.
0065 ///
0066 /// The steps for adding and enabling a new ilist option include:
0067 /// \li define the option, ilist_foo<Bar>, above;
0068 /// \li add new parameters for Bar to \a ilist_detail::node_options;
0069 /// \li add an extraction meta-function, ilist_detail::extract_foo;
0070 /// \li call extract_foo from \a ilist_detail::compute_node_options and pass it
0071 /// into \a ilist_detail::node_options; and
0072 /// \li specialize \c is_valid_option<ilist_foo<Bar>> to inherit from \c
0073 /// std::true_type to get static assertions passing in \a simple_ilist and \a
0074 /// ilist_node.
0075 template <class Option> struct is_valid_option : std::false_type {};
0076 
0077 /// Extract sentinel tracking option.
0078 ///
0079 /// Look through \p Options for the \a ilist_sentinel_tracking option, with the
0080 /// default depending on LLVM_ENABLE_ABI_BREAKING_CHECKS.
0081 template <class... Options> struct extract_sentinel_tracking;
0082 template <bool EnableSentinelTracking, class... Options>
0083 struct extract_sentinel_tracking<
0084     ilist_sentinel_tracking<EnableSentinelTracking>, Options...>
0085     : std::integral_constant<bool, EnableSentinelTracking>, is_explicit {};
0086 template <class Option1, class... Options>
0087 struct extract_sentinel_tracking<Option1, Options...>
0088     : extract_sentinel_tracking<Options...> {};
0089 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
0090 template <> struct extract_sentinel_tracking<> : std::true_type, is_implicit {};
0091 #else
0092 template <>
0093 struct extract_sentinel_tracking<> : std::false_type, is_implicit {};
0094 #endif
0095 template <bool EnableSentinelTracking>
0096 struct is_valid_option<ilist_sentinel_tracking<EnableSentinelTracking>>
0097     : std::true_type {};
0098 
0099 /// Extract custom tag option.
0100 ///
0101 /// Look through \p Options for the \a ilist_tag option, pulling out the
0102 /// custom tag type, using void as a default.
0103 template <class... Options> struct extract_tag;
0104 template <class Tag, class... Options>
0105 struct extract_tag<ilist_tag<Tag>, Options...> {
0106   typedef Tag type;
0107 };
0108 template <class Option1, class... Options>
0109 struct extract_tag<Option1, Options...> : extract_tag<Options...> {};
0110 template <> struct extract_tag<> {
0111   typedef void type;
0112 };
0113 template <class Tag> struct is_valid_option<ilist_tag<Tag>> : std::true_type {};
0114 
0115 /// Extract iterator bits option.
0116 ///
0117 /// Look through \p Options for the \a ilist_iterator_bits option. Defaults
0118 /// to false.
0119 template <class... Options> struct extract_iterator_bits;
0120 template <bool IteratorBits, class... Options>
0121 struct extract_iterator_bits<ilist_iterator_bits<IteratorBits>, Options...>
0122     : std::integral_constant<bool, IteratorBits> {};
0123 template <class Option1, class... Options>
0124 struct extract_iterator_bits<Option1, Options...>
0125     : extract_iterator_bits<Options...> {};
0126 template <> struct extract_iterator_bits<> : std::false_type, is_implicit {};
0127 template <bool IteratorBits>
0128 struct is_valid_option<ilist_iterator_bits<IteratorBits>> : std::true_type {};
0129 
0130 /// Extract node parent option.
0131 ///
0132 /// Look through \p Options for the \a ilist_parent option, pulling out the
0133 /// custom parent type, using void as a default.
0134 template <class... Options> struct extract_parent;
0135 template <class ParentTy, class... Options>
0136 struct extract_parent<ilist_parent<ParentTy>, Options...> {
0137   typedef ParentTy type;
0138 };
0139 template <class Option1, class... Options>
0140 struct extract_parent<Option1, Options...> : extract_parent<Options...> {};
0141 template <> struct extract_parent<> { typedef void type; };
0142 template <class ParentTy>
0143 struct is_valid_option<ilist_parent<ParentTy>> : std::true_type {};
0144 
0145 /// Check whether options are valid.
0146 ///
0147 /// The conjunction of \a is_valid_option on each individual option.
0148 template <class... Options> struct check_options;
0149 template <> struct check_options<> : std::true_type {};
0150 template <class Option1, class... Options>
0151 struct check_options<Option1, Options...>
0152     : std::integral_constant<bool, is_valid_option<Option1>::value &&
0153                                        check_options<Options...>::value> {};
0154 
0155 /// Traits for options for \a ilist_node.
0156 ///
0157 /// This is usually computed via \a compute_node_options.
0158 template <class T, bool EnableSentinelTracking, bool IsSentinelTrackingExplicit,
0159           class TagT, bool HasIteratorBits, class ParentTy>
0160 struct node_options {
0161   typedef T value_type;
0162   typedef T *pointer;
0163   typedef T &reference;
0164   typedef const T *const_pointer;
0165   typedef const T &const_reference;
0166 
0167   static const bool enable_sentinel_tracking = EnableSentinelTracking;
0168   static const bool is_sentinel_tracking_explicit = IsSentinelTrackingExplicit;
0169   static const bool has_iterator_bits = HasIteratorBits;
0170   typedef TagT tag;
0171   typedef ParentTy parent_ty;
0172   typedef ilist_node_base<enable_sentinel_tracking, parent_ty> node_base_type;
0173   typedef ilist_base<enable_sentinel_tracking, parent_ty> list_base_type;
0174 };
0175 
0176 template <class T, class... Options> struct compute_node_options {
0177   typedef node_options<T, extract_sentinel_tracking<Options...>::value,
0178                        extract_sentinel_tracking<Options...>::is_explicit,
0179                        typename extract_tag<Options...>::type,
0180                        extract_iterator_bits<Options...>::value,
0181                        typename extract_parent<Options...>::type>
0182       type;
0183 };
0184 
0185 } // end namespace ilist_detail
0186 } // end namespace llvm
0187 
0188 #endif // LLVM_ADT_ILIST_NODE_OPTIONS_H