1010#ifndef PHASAR_PHASARLLVM_POINTER_POINTSTOSETOWNER_H
1111#define PHASAR_PHASARLLVM_POINTER_POINTSTOSETOWNER_H
1212
13- #include < functional>
14- #include < memory>
15- #include < memory_resource>
16- #include < type_traits>
13+ #include " phasar/PhasarLLVM/Pointer/DynamicPointsToSetPtr.h"
14+ #include " phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h"
15+ #include " phasar/Utils/StableVector.h"
1716
1817#include " llvm/ADT/DenseSet.h"
1918#include " llvm/ADT/STLExtras.h"
2019#include " llvm/ADT/iterator_range.h"
2120#include " llvm/Support/ErrorHandling.h"
2221
23- #include " phasar/PhasarLLVM/Pointer/DynamicPointsToSetPtr.h"
24- #include " phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h"
25- #include " phasar/Utils/StableVector.h"
22+ #include < functional>
23+ #include < memory>
24+ #include < memory_resource>
25+ #include < type_traits>
26+
27+ // / On some MAC systems, <memory_resource> is still not fully implemented, so do
28+ // / a workaround here
29+
30+ #if !defined(__has_include) || __has_include(<memory_resource>)
31+ #define HAS_MEMORY_RESOURCE 1
32+ #include < memory_resource>
33+ #else
34+ #define HAS_MEMORY_RESOURCE 0
35+ #include " llvm/Support/RecyclingAllocator.h"
36+ #endif
2637
2738namespace llvm {
2839class Value ;
@@ -31,9 +42,27 @@ class Value;
3142namespace psr {
3243template <typename PointsToSetTy> class PointsToSetOwner {
3344public:
34- PointsToSetOwner (std::pmr::polymorphic_allocator<PointsToSetTy> Alloc =
35- std::pmr::get_default_resource ()) noexcept
36- : Alloc(Alloc) {}
45+ using allocator_type =
46+ #if HAS_MEMORY_RESOURCE
47+ std::pmr::polymorphic_allocator<PointsToSetTy>
48+ #else
49+ llvm::RecyclingAllocator<llvm::BumpPtrAllocator, PointsToSetTy> *
50+ #endif
51+ ;
52+
53+ using memory_resource_type =
54+ #if HAS_MEMORY_RESOURCE
55+ std::pmr::unsynchronized_pool_resource
56+ #else
57+ llvm::RecyclingAllocator<llvm::BumpPtrAllocator, PointsToSetTy>
58+ #endif
59+ ;
60+
61+ PointsToSetOwner (allocator_type Alloc) noexcept : Alloc(Alloc) {
62+ if constexpr (std::is_pointer_v<allocator_type>) {
63+ assert (Alloc != nullptr );
64+ }
65+ }
3766 PointsToSetOwner (PointsToSetOwner &&) noexcept = default ;
3867
3968 PointsToSetOwner (const PointsToSetOwner &) = delete ;
@@ -43,13 +72,24 @@ template <typename PointsToSetTy> class PointsToSetOwner {
4372 ~PointsToSetOwner () {
4473 for (auto PTS : OwnedPTS) {
4574 std::destroy_at (PTS);
75+ #if HAS_MEMORY_RESOURCE
4676 Alloc.deallocate (PTS, 1 );
77+ #else
78+ Alloc->Deallocate (PTS);
79+ #endif
4780 }
4881 OwnedPTS.clear ();
4982 }
5083
5184 DynamicPointsToSetPtr<PointsToSetTy> acquire () {
52- auto Ptr = new (Alloc.allocate (1 )) PointsToSetTy ();
85+ auto RawMem =
86+ #if HAS_MEMORY_RESOURCE
87+ Alloc.allocate (1 )
88+ #else
89+ Alloc->Allocate ()
90+ #endif
91+ ;
92+ auto Ptr = new (RawMem) PointsToSetTy ();
5393 OwnedPTS.insert (Ptr);
5494 return &AllPTS.emplace_back (Ptr);
5595 }
@@ -61,7 +101,11 @@ template <typename PointsToSetTy> class PointsToSetOwner {
61101 " freed, or never allocated with this PointsToSetOwner!" );
62102 }
63103 std::destroy_at (PTS);
104+ #if HAS_MEMORY_RESOURCE
64105 Alloc.deallocate (PTS, 1 );
106+ #else
107+ Alloc->Deallocate (PTS);
108+ #endif
65109 // / NOTE: Do not delete from AllPTS!
66110 }
67111
@@ -72,7 +116,7 @@ template <typename PointsToSetTy> class PointsToSetOwner {
72116 }
73117
74118private:
75- std::pmr::polymorphic_allocator<PointsToSetTy> Alloc;
119+ allocator_type Alloc{} ;
76120 llvm::DenseSet<PointsToSetTy *> OwnedPTS;
77121 StableVector<PointsToSetTy *> AllPTS;
78122};
0 commit comments