Skip to content

Commit f72108e

Browse files
committed
Change PointsToSetTy from std::unordered_set to llvm::DenseSet
1 parent 9305711 commit f72108e

7 files changed

Lines changed: 33 additions & 32 deletions

File tree

include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class OTFResolver : public CHAResolver {
6666
resolveFunctionPointer(const llvm::CallBase *CallSite) override;
6767

6868
static std::set<const llvm::Type *>
69-
getReachableTypes(const std::unordered_set<const llvm::Value *> &Values);
69+
getReachableTypes(const LLVMPointsToInfo::PointsToSetTy &Values);
7070

7171
static std::vector<std::pair<const llvm::Value *, const llvm::Value *>>
7272
getActualFormalPointerPairs(const llvm::CallBase *CallSite,

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEInstInteractionAnalysis.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class IDEInstInteractionAnalysisT
255255
//
256256
struct IIAFlowFunction : FlowFunction<d_t, container_type> {
257257
const llvm::LoadInst *Load;
258-
std::shared_ptr<std::unordered_set<d_t>> PTS;
258+
LLVMPointsToInfo::PointsToSetPtrTy PTS;
259259

260260
IIAFlowFunction(IDEInstInteractionAnalysisT &Problem,
261261
const llvm::LoadInst *Load)
@@ -300,8 +300,8 @@ class IDEInstInteractionAnalysisT
300300
//
301301
struct IIAFlowFunction : FlowFunction<d_t, container_type> {
302302
const llvm::StoreInst *Store;
303-
std::shared_ptr<std::unordered_set<d_t>> ValuePTS;
304-
std::shared_ptr<std::unordered_set<d_t>> PointerPTS;
303+
LLVMPointsToInfo::PointsToSetPtrTy ValuePTS;
304+
LLVMPointsToInfo::PointsToSetPtrTy PointerPTS;
305305

306306
IIAFlowFunction(IDEInstInteractionAnalysisT &Problem,
307307
const llvm::StoreInst *Store)
@@ -311,8 +311,9 @@ class IDEInstInteractionAnalysisT
311311
Store->getValueOperand(),
312312
Problem.OnlyConsiderLocalAliases);
313313
} else {
314-
return std::make_shared<std::unordered_set<d_t>>(
315-
std::unordered_set<d_t>{Store->getValueOperand()});
314+
return std::make_shared<LLVMPointsToInfo::PointsToSetTy>(
315+
LLVMPointsToInfo::PointsToSetTy{
316+
Store->getValueOperand()});
316317
}
317318
}()),
318319
PointerPTS(Problem.PT->getReachableAllocationSites(

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDETypeStateAnalysis.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class IDETypeStateAnalysis
5757

5858
private:
5959
const TypeStateDescription &TSD;
60-
std::map<const llvm::Value *, std::unordered_set<const llvm::Value *>>
61-
PointsToCache;
60+
std::map<const llvm::Value *, LLVMPointsToInfo::PointsToSetTy> PointsToCache;
6261
std::map<const llvm::Value *, std::set<const llvm::Value *>>
6362
RelevantAllocaCache;
6463

include/phasar/PhasarLLVM/Pointer/PointsToInfo.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <memory>
1515
#include <unordered_set>
1616

17+
#include "llvm/ADT/DenseSet.h"
18+
1719
#include "nlohmann/json.hpp"
1820

1921
namespace psr {
@@ -40,7 +42,7 @@ std::ostream &operator<<(std::ostream &os, const PointerAnalysisType &PA);
4042

4143
template <typename V, typename N> class PointsToInfo {
4244
public:
43-
using PointsToSetTy = std::unordered_set<V>;
45+
using PointsToSetTy = llvm::DenseSet<V>;
4446
using PointsToSetPtrTy = std::shared_ptr<PointsToSetTy>;
4547

4648
virtual ~PointsToInfo() = default;

lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ OTFResolver::resolveFunctionPointer(const llvm::CallBase *CallSite) {
218218
return Callees;
219219
}
220220

221-
std::set<const llvm::Type *> OTFResolver::getReachableTypes(
222-
const std::unordered_set<const llvm::Value *> &Values) {
221+
std::set<const llvm::Type *>
222+
OTFResolver::getReachableTypes(const LLVMPointsToInfo::PointsToSetTy &Values) {
223223
std::set<const llvm::Type *> Types;
224224
// an allocation site can either be an AllocaInst or a call to an
225225
// allocating function

lib/PhasarLLVM/Pointer/LLVMPointsToGraph.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@ namespace psr {
3838
struct LLVMPointsToGraph::AllocationSiteDFSVisitor
3939
: boost::default_dfs_visitor {
4040
// collect the allocation sites that are found
41-
std::unordered_set<const llvm::Value *> &AllocationSites;
41+
PointsToSetTy &AllocationSites;
4242
// keeps track of the current path
4343
std::vector<vertex_t> VisitorStack;
4444
// the call stack that can be matched against the visitor stack
4545
const std::vector<const llvm::Instruction *> &CallStack;
4646

47-
AllocationSiteDFSVisitor(
48-
std::unordered_set<const llvm::Value *> &AllocationSizes,
49-
const vector<const llvm::Instruction *> &CallStack)
47+
AllocationSiteDFSVisitor(PointsToSetTy &AllocationSizes,
48+
const vector<const llvm::Instruction *> &CallStack)
5049
: AllocationSites(AllocationSizes), CallStack(CallStack) {}
5150

5251
template <typename Vertex, typename Graph>
@@ -265,12 +264,12 @@ AliasResult LLVMPointsToGraph::alias(const llvm::Value *V1,
265264
return AliasResult::NoAlias;
266265
}
267266

268-
std::shared_ptr<std::unordered_set<const llvm::Value *>>
269-
LLVMPointsToGraph::getReachableAllocationSites(const llvm::Value *V,
270-
bool IntraProcOnly,
271-
const llvm::Instruction *I) {
267+
auto LLVMPointsToGraph::getReachableAllocationSites(const llvm::Value *V,
268+
bool IntraProcOnly,
269+
const llvm::Instruction *I)
270+
-> PointsToSetPtrTy {
272271
computePointsToGraph(V);
273-
auto AllocSites = std::make_shared<std::unordered_set<const llvm::Value *>>();
272+
auto AllocSites = std::make_shared<PointsToSetTy>();
274273
AllocationSiteDFSVisitor AllocVis(*AllocSites, {});
275274
vector<boost::default_color_type> ColorMap(boost::num_vertices(PAG));
276275
boost::depth_first_visit(
@@ -373,9 +372,9 @@ bool LLVMPointsToGraph::containsValue(llvm::Value *V) {
373372
return false;
374373
}
375374

376-
std::shared_ptr<std::unordered_set<const llvm::Value *>>
377-
LLVMPointsToGraph::getPointsToSet(const llvm::Value *V,
378-
const llvm::Instruction *I) {
375+
auto LLVMPointsToGraph::getPointsToSet(const llvm::Value *V,
376+
const llvm::Instruction *I)
377+
-> PointsToSetPtrTy {
379378
PAMM_GET_INSTANCE;
380379
INC_COUNTER("[Calls] getPointsToSet", 1, PAMM_SEVERITY_LEVEL::Full);
381380
START_TIMER("PointsTo-Set Computation", PAMM_SEVERITY_LEVEL::Full);
@@ -389,7 +388,7 @@ LLVMPointsToGraph::getPointsToSet(const llvm::Value *V,
389388
PAG, ValueVertexMap.at(V), Vis,
390389
boost::make_iterator_property_map(
391390
ColorMap.begin(), boost::get(boost::vertex_index, PAG), ColorMap[0]));
392-
auto ResultSet = std::make_shared<std::unordered_set<const llvm::Value *>>();
391+
auto ResultSet = std::make_shared<PointsToSetTy>();
393392
for (auto Vertex : ReachableVertices) {
394393
ResultSet->insert(PAG[Vertex].V);
395394
}

lib/PhasarLLVM/Pointer/LLVMPointsToSet.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,12 @@ auto LLVMPointsToSet::mergePointsToSets(const PointsToSetPtrTy &PTS1,
166166
}
167167

168168
// add smaller set to larger one and get rid of the smaller set
169-
LargerSet->merge(*SmallerSet);
169+
// LargerSet->merge(*SmallerSet);
170+
LargerSet->reserve(LargerSet->size() + SmallerSet->size());
171+
LargerSet->insert(SmallerSet->begin(), SmallerSet->end());
172+
SmallerSet->clear();
170173

171-
assert(SmallerSet->empty() && "Expect the points-to-sets to be disjoint");
174+
// assert(SmallerSet->empty() && "Expect the points-to-sets to be disjoint");
172175

173176
return LargerSet;
174177
}
@@ -470,8 +473,7 @@ LLVMPointsToSet::alias(const llvm::Value *V1, const llvm::Value *V2,
470473
}
471474

472475
auto LLVMPointsToSet::getEmptyPointsToSet() -> PointsToSetPtrTy {
473-
static auto EmptySet =
474-
std::make_shared<std::unordered_set<const llvm::Value *>>();
476+
static auto EmptySet = std::make_shared<PointsToSetTy>();
475477
return EmptySet;
476478
}
477479

@@ -500,7 +502,7 @@ auto LLVMPointsToSet::getReachableAllocationSites(
500502
return getEmptyPointsToSet();
501503
}
502504
computeValuesPointsToSet(V);
503-
auto AllocSites = std::make_shared<std::unordered_set<const llvm::Value *>>();
505+
auto AllocSites = std::make_shared<PointsToSetTy>();
504506
const auto PTS = PointsToSets[V];
505507
// consider the full inter-procedural points-to/alias information
506508
if (!IntraProcOnly) {
@@ -584,9 +586,7 @@ void LLVMPointsToSet::mergeWith(const PointsToInfo &PTI) {
584586
// if none of the pointers of a set of other is known in this, we need to
585587
// perform a copy
586588
if (!FoundElemPtr) {
587-
PointsToSets.insert(
588-
{KeyPtr,
589-
std::make_shared<std::unordered_set<const llvm::Value *>>(*Set)});
589+
PointsToSets.insert({KeyPtr, std::make_shared<PointsToSetTy>(*Set)});
590590
}
591591
}
592592
}

0 commit comments

Comments
 (0)