LLVM  6.0.0svn
ilist_node_options.h
Go to the documentation of this file.
1 //===- llvm/ADT/ilist_node_options.h - ilist_node Options -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_ADT_ILIST_NODE_OPTIONS_H
11 #define LLVM_ADT_ILIST_NODE_OPTIONS_H
12 
13 #include "llvm/Config/abi-breaking.h"
14 #include "llvm/Config/llvm-config.h"
15 
16 #include <type_traits>
17 
18 namespace llvm {
19 
20 template <bool EnableSentinelTracking> class ilist_node_base;
21 template <bool EnableSentinelTracking> class ilist_base;
22 
23 /// Option to choose whether to track sentinels.
24 ///
25 /// This option affects the ABI for the nodes. When not specified explicitly,
26 /// the ABI depends on LLVM_ENABLE_ABI_BREAKING_CHECKS. Specify explicitly to
27 /// enable \a ilist_node::isSentinel().
28 template <bool EnableSentinelTracking> struct ilist_sentinel_tracking {};
29 
30 /// Option to specify a tag for the node type.
31 ///
32 /// This option allows a single value type to be inserted in multiple lists
33 /// simultaneously. See \a ilist_node for usage examples.
34 template <class Tag> struct ilist_tag {};
35 
36 namespace ilist_detail {
37 
38 /// Helper trait for recording whether an option is specified explicitly.
39 template <bool IsExplicit> struct explicitness {
40  static const bool is_explicit = IsExplicit;
41 };
44 
45 /// Check whether an option is valid.
46 ///
47 /// The steps for adding and enabling a new ilist option include:
48 /// \li define the option, ilist_foo<Bar>, above;
49 /// \li add new parameters for Bar to \a ilist_detail::node_options;
50 /// \li add an extraction meta-function, ilist_detail::extract_foo;
51 /// \li call extract_foo from \a ilist_detail::compute_node_options and pass it
52 /// into \a ilist_detail::node_options; and
53 /// \li specialize \c is_valid_option<ilist_foo<Bar>> to inherit from \c
54 /// std::true_type to get static assertions passing in \a simple_ilist and \a
55 /// ilist_node.
56 template <class Option> struct is_valid_option : std::false_type {};
57 
58 /// Extract sentinel tracking option.
59 ///
60 /// Look through \p Options for the \a ilist_sentinel_tracking option, with the
61 /// default depending on LLVM_ENABLE_ABI_BREAKING_CHECKS.
62 template <class... Options> struct extract_sentinel_tracking;
63 template <bool EnableSentinelTracking, class... Options>
65  ilist_sentinel_tracking<EnableSentinelTracking>, Options...>
66  : std::integral_constant<bool, EnableSentinelTracking>, is_explicit {};
67 template <class Option1, class... Options>
68 struct extract_sentinel_tracking<Option1, Options...>
69  : extract_sentinel_tracking<Options...> {};
70 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
71 template <> struct extract_sentinel_tracking<> : std::true_type, is_implicit {};
72 #else
73 template <>
74 struct extract_sentinel_tracking<> : std::false_type, is_implicit {};
75 #endif
76 template <bool EnableSentinelTracking>
77 struct is_valid_option<ilist_sentinel_tracking<EnableSentinelTracking>>
78  : std::true_type {};
79 
80 /// Extract custom tag option.
81 ///
82 /// Look through \p Options for the \a ilist_tag option, pulling out the
83 /// custom tag type, using void as a default.
84 template <class... Options> struct extract_tag;
85 template <class Tag, class... Options>
86 struct extract_tag<ilist_tag<Tag>, Options...> {
87  typedef Tag type;
88 };
89 template <class Option1, class... Options>
90 struct extract_tag<Option1, Options...> : extract_tag<Options...> {};
91 template <> struct extract_tag<> { typedef void type; };
92 template <class Tag> struct is_valid_option<ilist_tag<Tag>> : std::true_type {};
93 
94 /// Check whether options are valid.
95 ///
96 /// The conjunction of \a is_valid_option on each individual option.
97 template <class... Options> struct check_options;
98 template <> struct check_options<> : std::true_type {};
99 template <class Option1, class... Options>
100 struct check_options<Option1, Options...>
101  : std::integral_constant<bool, is_valid_option<Option1>::value &&
102  check_options<Options...>::value> {};
103 
104 /// Traits for options for \a ilist_node.
105 ///
106 /// This is usually computed via \a compute_node_options.
107 template <class T, bool EnableSentinelTracking, bool IsSentinelTrackingExplicit,
108  class TagT>
109 struct node_options {
110  typedef T value_type;
111  typedef T *pointer;
112  typedef T &reference;
113  typedef const T *const_pointer;
114  typedef const T &const_reference;
115 
116  static const bool enable_sentinel_tracking = EnableSentinelTracking;
117  static const bool is_sentinel_tracking_explicit = IsSentinelTrackingExplicit;
118  typedef TagT tag;
121 };
122 
123 template <class T, class... Options> struct compute_node_options {
124  typedef node_options<T, extract_sentinel_tracking<Options...>::value,
126  typename extract_tag<Options...>::type>
128 };
129 
130 } // end namespace ilist_detail
131 } // end namespace llvm
132 
133 #endif // LLVM_ADT_ILIST_NODE_OPTIONS_H
Check whether an option is valid.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
explicitness< false > is_implicit
node_options< T, extract_sentinel_tracking< Options... >::value, extract_sentinel_tracking< Options... >::is_explicit, typename extract_tag< Options... >::type > type
explicitness< true > is_explicit
#define T
Extract sentinel tracking option.
Base class for ilist nodes.
Option to choose whether to track sentinels.
ilist_node_base< enable_sentinel_tracking > node_base_type
Check whether options are valid.
Option to specify a tag for the node type.
ilist_base< enable_sentinel_tracking > list_base_type
Helper trait for recording whether an option is specified explicitly.
Implementations of list algorithms using ilist_node_base.
Definition: ilist_base.h:19
Extract custom tag option.
Traits for options for ilist_node.