Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/phasar/PhasarLLVM/ControlFlow/SparseLLVMBasedICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SparseLLVMBasedICFG

~SparseLLVMBasedICFG();

[[nodiscard]] n_t advanceToNextUser(n_t Succ, const auto &Fact) {
[[nodiscard]] n_t advanceToNextUser(n_t Succ, const auto &Fact) const {
using psr::valueOf;
return advanceToNextUserImpl(Succ, valueOf(Fact));
}
Expand All @@ -65,7 +65,7 @@ class SparseLLVMBasedICFG
[[nodiscard]] const SparseLLVMBasedCFG &
getSparseCFGImpl(const llvm::Function *Fun, const llvm::Value *Val) const;

[[nodiscard]] n_t advanceToNextUserImpl(n_t Succ, v_t Fact);
[[nodiscard]] n_t advanceToNextUserImpl(n_t Succ, v_t Fact) const;

std::unique_ptr<SVFGCache> SparseCFGCache;
LLVMAliasInfoRef AliasAnalysis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SparseLLVMBasedICFGView
// To make the IDESolver happy...
operator const LLVMBasedICFG &() const noexcept { return *ICF; }

[[nodiscard]] n_t advanceToNextUser(n_t Succ, const auto &Fact) {
[[nodiscard]] n_t advanceToNextUser(n_t Succ, const auto &Fact) const {
using psr::valueOf;
return advanceToNextUserImpl(Succ, valueOf(Fact));
}
Expand All @@ -77,7 +77,9 @@ class SparseLLVMBasedICFGView
[[nodiscard]] const SparseLLVMBasedCFG &
getSparseCFGImpl(const llvm::Function *Fun, const llvm::Value *Val) const;

[[nodiscard]] n_t advanceToNextUserImpl(n_t Succ, v_t Fact);
[[nodiscard]] n_t advanceToNextUserImpl(n_t Succ, v_t Fact) const;

[[nodiscard]] size_t getNumCallSitesImpl() const noexcept;

const LLVMBasedICFG *ICF{};
std::unique_ptr<SVFGCache> SparseCFGCache;
Expand Down
18 changes: 7 additions & 11 deletions lib/PhasarLLVM/ControlFlow/SVFGCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,16 @@ struct SVFGCache {
getOrCreate(const LLVMBasedCFG &CFG, const llvm::Function *Fun,
const llvm::Value *Val, LLVMAliasInfoRef AliasAnalysis);

[[nodiscard]] n_t advanceToNextUser(n_t Succ, const auto &Fact,
LLVMAliasInfoRef AliasAnalysis) {
[[nodiscard]] static n_t advanceToNextUser(n_t Succ, const auto &Fact,
LLVMAliasInfoRef AliasAnalysis) {
using psr::valueOf;

// XXX: Measure, whether caching actually helps here...
// XXX: Make thread-safe:
// Not memoized: the forward scan skips only very few instructions on
// average, which is cheaper than a lookup in a multi-million-entry map.
// On a small coreutils benchmark, it was about ~11% *faster* to skip the
// cache.

auto [It, Inserted] =
SameOrNextUserCache.try_emplace(std::pair{Succ, valueOf(Fact)});
if (Inserted) {
It->second =
SparseLLVMControlFlow::advanceToNextUser(Succ, Fact, AliasAnalysis);
}
return It->second;
return SparseLLVMControlFlow::advanceToNextUser(Succ, Fact, AliasAnalysis);
}
};

Expand Down
6 changes: 3 additions & 3 deletions lib/PhasarLLVM/ControlFlow/SparseLLVMBasedICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SparseLLVMBasedICFG::getSparseCFGImpl(const llvm::Function *Fun,
return SparseCFGCache->getOrCreate(*this, Fun, Val, AliasAnalysis);
}

auto SparseLLVMBasedICFG::advanceToNextUserImpl(n_t Succ, v_t Fact) -> n_t {
assert(SparseCFGCache != nullptr);
return SparseCFGCache->advanceToNextUser(Succ, Fact, AliasAnalysis);
auto SparseLLVMBasedICFG::advanceToNextUserImpl(n_t Succ, v_t Fact) const
-> n_t {
return SVFGCache::advanceToNextUser(Succ, Fact, AliasAnalysis);
}
10 changes: 7 additions & 3 deletions lib/PhasarLLVM/ControlFlow/SparseLLVMBasedICFGView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ SparseLLVMBasedICFGView::getSparseCFGImpl(const llvm::Function *Fun,
return SparseCFGCache->getOrCreate(*this, Fun, Val, AliasAnalysis);
}

auto SparseLLVMBasedICFGView::advanceToNextUserImpl(n_t Succ, v_t Fact) -> n_t {
assert(SparseCFGCache != nullptr);
return SparseCFGCache->advanceToNextUser(Succ, Fact, AliasAnalysis);
auto SparseLLVMBasedICFGView::advanceToNextUserImpl(n_t Succ, v_t Fact) const
-> n_t {
return SVFGCache::advanceToNextUser(Succ, Fact, AliasAnalysis);
}

size_t SparseLLVMBasedICFGView::getNumCallSitesImpl() const noexcept {
return ICF->getNumCallSites();
}
Loading