File: allocator_config_wrapper.h

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (128 lines) | stat: -rw-r--r-- 6,026 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//===-- allocator_config_wrapper.h ------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef SCUDO_ALLOCATOR_CONFIG_WRAPPER_H_
#define SCUDO_ALLOCATOR_CONFIG_WRAPPER_H_

#include "condition_variable.h"
#include "internal_defs.h"
#include "secondary.h"
#include "type_traits.h"

namespace scudo {

#define OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT, MEMBER)                         \
  template <typename Config, typename = TYPE> struct NAME##State {             \
    static constexpr removeConst<TYPE>::type getValue() { return DEFAULT; }    \
  };                                                                           \
  template <typename Config>                                                   \
  struct NAME##State<                                                          \
      Config, typename assertSameType<decltype(Config::MEMBER), TYPE>::type> { \
    static constexpr removeConst<TYPE>::type getValue() {                      \
      return Config::MEMBER;                                                   \
    }                                                                          \
  };

#define OPTIONAL_TYPE_TEMPLATE(NAME, DEFAULT, MEMBER)                          \
  template <typename Config, typename Void = void> struct NAME##Type {         \
    static constexpr bool enabled() { return false; }                          \
    using NAME = DEFAULT;                                                      \
  };                                                                           \
  template <typename Config>                                                   \
  struct NAME##Type<Config,                                                    \
                    typename voidAdaptor<typename Config::MEMBER>::type> {     \
    static constexpr bool enabled() { return true; }                           \
    using NAME = typename Config::MEMBER;                                      \
  };

template <typename AllocatorConfig> struct BaseConfig {
#define BASE_REQUIRED_TEMPLATE_TYPE(NAME)                                      \
  template <typename T> using NAME = typename AllocatorConfig::template NAME<T>;

#define BASE_OPTIONAL(TYPE, NAME, DEFAULT)                                     \
  OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT, NAME)                                 \
  static constexpr removeConst<TYPE>::type get##NAME() {                       \
    return NAME##State<AllocatorConfig>::getValue();                           \
  }

#include "allocator_config.def"
}; // BaseConfig

template <typename AllocatorConfig> struct PrimaryConfig {
  // TODO: Pass this flag through template argument to remove this hard-coded
  //       function.
  static constexpr bool getMaySupportMemoryTagging() {
    return BaseConfig<AllocatorConfig>::getMaySupportMemoryTagging();
  }

#define PRIMARY_REQUIRED_TYPE(NAME)                                            \
  using NAME = typename AllocatorConfig::Primary::NAME;

#define PRIMARY_REQUIRED(TYPE, NAME)                                           \
  static constexpr removeConst<TYPE>::type get##NAME() {                       \
    return AllocatorConfig::Primary::NAME;                                     \
  }

#define PRIMARY_OPTIONAL(TYPE, NAME, DEFAULT)                                  \
  OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT, NAME)                                 \
  static constexpr removeConst<TYPE>::type get##NAME() {                       \
    return NAME##State<typename AllocatorConfig::Primary>::getValue();         \
  }

#define PRIMARY_OPTIONAL_TYPE(NAME, DEFAULT)                                   \
  OPTIONAL_TYPE_TEMPLATE(NAME, DEFAULT, NAME)                                  \
  static constexpr bool has##NAME() {                                          \
    return NAME##Type<typename AllocatorConfig::Primary>::enabled();           \
  }                                                                            \
  using NAME = typename NAME##Type<typename AllocatorConfig::Primary>::NAME;

#include "allocator_config.def"

}; // PrimaryConfig

template <typename AllocatorConfig> struct SecondaryConfig {
  // TODO: Pass this flag through template argument to remove this hard-coded
  //       function.
  static constexpr bool getMaySupportMemoryTagging() {
    return BaseConfig<AllocatorConfig>::getMaySupportMemoryTagging();
  }

#define SECONDARY_REQUIRED_TEMPLATE_TYPE(NAME)                                 \
  template <typename T>                                                        \
  using NAME = typename AllocatorConfig::Secondary::template NAME<T>;

#define SECONDARY_OPTIONAL(TYPE, NAME, DEFAULT)                                \
  OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT, NAME)                                 \
  static constexpr removeConst<TYPE>::type get##NAME() {                       \
    return NAME##State<typename AllocatorConfig::Secondary>::getValue();       \
  }

#include "allocator_config.def"

  struct CacheConfig {
    // TODO: Pass this flag through template argument to remove this hard-coded
    //       function.
    static constexpr bool getMaySupportMemoryTagging() {
      return BaseConfig<AllocatorConfig>::getMaySupportMemoryTagging();
    }

#define SECONDARY_CACHE_OPTIONAL(TYPE, NAME, DEFAULT)                          \
  OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT, Cache::NAME)                          \
  static constexpr removeConst<TYPE>::type get##NAME() {                       \
    return NAME##State<typename AllocatorConfig::Secondary>::getValue();       \
  }
#include "allocator_config.def"
  }; // CacheConfig
};   // SecondaryConfig

#undef OPTIONAL_TEMPLATE
#undef OPTIONAL_TEMPLATE_TYPE

} // namespace scudo

#endif // SCUDO_ALLOCATOR_CONFIG_WRAPPER_H_