Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __memory_resource / unsynchronized_pool_resource.h
blob81d5f9ec4da87d9944bdba5465556821f2f6ed6b
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H
10 #define _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H
12 #include <__availability>
13 #include <__config>
14 #include <__memory_resource/memory_resource.h>
15 #include <__memory_resource/pool_options.h>
16 #include <cstddef>
17 #include <cstdint>
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 # pragma GCC system_header
21 #endif
23 #if _LIBCPP_STD_VER >= 17
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 namespace pmr {
29 // [mem.res.pool.overview]
31 class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI unsynchronized_pool_resource : public memory_resource {
32 class __fixed_pool;
34 class __adhoc_pool {
35 struct __chunk_footer;
36 __chunk_footer* __first_;
38 public:
39 _LIBCPP_HIDE_FROM_ABI explicit __adhoc_pool() : __first_(nullptr) {}
41 void __release_ptr(memory_resource* __upstream);
42 void* __do_allocate(memory_resource* __upstream, size_t __bytes, size_t __align);
43 void __do_deallocate(memory_resource* __upstream, void* __p, size_t __bytes, size_t __align);
46 static const size_t __min_blocks_per_chunk = 16;
47 static const size_t __min_bytes_per_chunk = 1024;
48 static const size_t __max_blocks_per_chunk = (size_t(1) << 20);
49 static const size_t __max_bytes_per_chunk = (size_t(1) << 30);
51 static const int __log2_smallest_block_size = 3;
52 static const size_t __smallest_block_size = 8;
53 static const size_t __default_largest_block_size = (size_t(1) << 20);
54 static const size_t __max_largest_block_size = (size_t(1) << 30);
56 size_t __pool_block_size(int __i) const;
57 int __log2_pool_block_size(int __i) const;
58 int __pool_index(size_t __bytes, size_t __align) const;
60 public:
61 unsynchronized_pool_resource(const pool_options& __opts, memory_resource* __upstream);
63 _LIBCPP_HIDE_FROM_ABI unsynchronized_pool_resource()
64 : unsynchronized_pool_resource(pool_options(), get_default_resource()) {}
66 _LIBCPP_HIDE_FROM_ABI explicit unsynchronized_pool_resource(memory_resource* __upstream)
67 : unsynchronized_pool_resource(pool_options(), __upstream) {}
69 _LIBCPP_HIDE_FROM_ABI explicit unsynchronized_pool_resource(const pool_options& __opts)
70 : unsynchronized_pool_resource(__opts, get_default_resource()) {}
72 unsynchronized_pool_resource(const unsynchronized_pool_resource&) = delete;
74 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~unsynchronized_pool_resource() override { release(); }
76 unsynchronized_pool_resource& operator=(const unsynchronized_pool_resource&) = delete;
78 void release();
80 _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
82 [[__gnu__::__pure__]] pool_options options() const;
84 protected:
85 void* do_allocate(size_t __bytes, size_t __align) override; // key function
87 void do_deallocate(void* __p, size_t __bytes, size_t __align) override;
89 _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
90 return &__other == this;
93 private:
94 memory_resource* __res_;
95 __adhoc_pool __adhoc_pool_;
96 __fixed_pool* __fixed_pools_;
97 int __num_fixed_pools_;
98 uint32_t __options_max_blocks_per_chunk_;
101 } // namespace pmr
103 _LIBCPP_END_NAMESPACE_STD
105 #endif // _LIBCPP_STD_VER >= 17
107 #endif // _LIBCPP___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H