Skip to content

Commit 90fafd8

Browse files
committed
resolve merge conflicts
2 parents 1fc1920 + 24e1769 commit 90fafd8

3 files changed

Lines changed: 70 additions & 24 deletions

File tree

include/phasar/PhasarLLVM/Pointer/LLVMPointsToGraph.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ class LLVMPointsToGraph : public LLVMPointsToInfo {
107107
/// Keep track of what has already been merged into this points-to graph.
108108
std::unordered_set<const llvm::Function *> AnalyzedFunctions;
109109
LLVMBasedPointsToAnalysis PTA;
110-
PointsToSetOwner<PointsToSetTy> Owner;
110+
111+
PointsToSetOwner<PointsToSetTy>::memory_resource_type MRes;
112+
PointsToSetOwner<PointsToSetTy> Owner{&MRes};
111113
std::unordered_map<const llvm::Value *, DynamicPointsToSetPtr<PointsToSetTy>>
112114
Cache;
113115

include/phasar/PhasarLLVM/Pointer/LLVMPointsToSet.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,8 @@
77
* Philipp Schubert and others
88
*****************************************************************************/
99

10-
#ifndef PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOSET_H_
11-
#define PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOSET_H_
12-
13-
#include <iostream>
14-
#include <memory_resource>
15-
16-
#include "nlohmann/json.hpp"
17-
18-
#include "llvm/ADT/DenseMap.h"
19-
#include "llvm/ADT/DenseSet.h"
10+
#ifndef PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOSET_H
11+
#define PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOSET_H
2012

2113
#include "phasar/DB/ProjectIRDB.h"
2214
#include "phasar/PhasarLLVM/Pointer/DynamicPointsToSetPtr.h"
@@ -25,6 +17,14 @@
2517
#include "phasar/PhasarLLVM/Pointer/PointsToSetOwner.h"
2618
#include "phasar/Utils/StableVector.h"
2719

20+
#include "llvm/ADT/DenseMap.h"
21+
#include "llvm/ADT/DenseSet.h"
22+
23+
#include "nlohmann/json.hpp"
24+
25+
#include <iostream>
26+
#include <memory_resource>
27+
2828
namespace llvm {
2929
class Value;
3030
class Module;
@@ -45,7 +45,7 @@ class LLVMPointsToSet : public LLVMPointsToInfo {
4545
LLVMBasedPointsToAnalysis PTA;
4646
llvm::DenseSet<const llvm::Function *> AnalyzedFunctions;
4747

48-
std::pmr::unsynchronized_pool_resource MRes;
48+
PointsToSetOwner<PointsToSetTy>::memory_resource_type MRes;
4949
PointsToSetOwner<PointsToSetTy> Owner{&MRes};
5050

5151
PointsToSetMap PointsToSets;

include/phasar/PhasarLLVM/Pointer/PointsToSetOwner.h

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,30 @@
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

2738
namespace llvm {
2839
class Value;
@@ -31,9 +42,27 @@ class Value;
3142
namespace psr {
3243
template <typename PointsToSetTy> class PointsToSetOwner {
3344
public:
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

74118
private:
75-
std::pmr::polymorphic_allocator<PointsToSetTy> Alloc;
119+
allocator_type Alloc{};
76120
llvm::DenseSet<PointsToSetTy *> OwnedPTS;
77121
StableVector<PointsToSetTy *> AllPTS;
78122
};

0 commit comments

Comments
 (0)