-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filtered AliasSet #723
Open
fabianbs96
wants to merge
10
commits into
development
Choose a base branch
from
f-FilteredAliasSet
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+595
−18
Open
Filtered AliasSet #723
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d1891f5
Add alias set filter
fabianbs96 52b24a0
Add test
fabianbs96 4e10792
apply review comments from vulder
fabianbs96 e1e8fb5
Add caching for reachable allocation sites
fabianbs96 5ef3331
Bugfix
fabianbs96 f027b39
adding noexcept
fabianbs96 9000760
Rename Context to AliasQueryInst in IFDSTaintAnalysis
fabianbs96 5b31ecd
Merge branch 'development' into f-FilteredAliasSet
fabianbs96 da93441
Merge branch 'development' into f-FilteredAliasSet
fabianbs96 e1ff500
Merge branch 'development' into f-FilteredAliasSet
fabianbs96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
include/phasar/PhasarLLVM/Pointer/FilteredLLVMAliasSet.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2020 Fabian Schiebel. | ||
* All rights reserved. This program and the accompanying materials are made | ||
* available under the terms of LICENSE.txt. | ||
* | ||
* Contributors: | ||
* Fabian Schiebel and others | ||
*****************************************************************************/ | ||
|
||
#ifndef PHASAR_PHASARLLVM_POINTER_FILTEREDLLVMALIASSET_H | ||
#define PHASAR_PHASARLLVM_POINTER_FILTEREDLLVMALIASSET_H | ||
|
||
#include "phasar/Pointer/AliasAnalysisType.h" | ||
#include "phasar/Pointer/AliasInfoTraits.h" | ||
#include "phasar/Pointer/AliasResult.h" | ||
#include "phasar/Pointer/AliasSetOwner.h" | ||
#include "phasar/Utils/AnalysisProperties.h" | ||
#include "phasar/Utils/MaybeUniquePtr.h" | ||
|
||
#include "llvm/ADT/DenseMap.h" | ||
#include "llvm/ADT/DenseMapInfo.h" | ||
#include "llvm/ADT/Hashing.h" | ||
#include "llvm/ADT/PointerIntPair.h" | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/Support/ErrorHandling.h" | ||
|
||
#include "nlohmann/json_fwd.hpp" | ||
|
||
#include <type_traits> | ||
#include <utility> | ||
|
||
namespace llvm { | ||
class Value; | ||
class Instruction; | ||
} // namespace llvm | ||
|
||
namespace psr { | ||
|
||
class LLVMAliasSet; | ||
class FilteredLLVMAliasSet; | ||
|
||
template <> | ||
struct AliasInfoTraits<FilteredLLVMAliasSet> | ||
: DefaultAATraits<const llvm::Value *, const llvm::Instruction *> {}; | ||
|
||
class FilteredLLVMAliasSet { | ||
public: | ||
using alias_traits_t = AliasInfoTraits<FilteredLLVMAliasSet>; | ||
using n_t = alias_traits_t::n_t; | ||
using v_t = alias_traits_t::v_t; | ||
using AliasSetTy = alias_traits_t::AliasSetTy; | ||
using AliasSetPtrTy = alias_traits_t::AliasSetPtrTy; | ||
using AllocationSiteSetPtrTy = alias_traits_t::AllocationSiteSetPtrTy; | ||
|
||
FilteredLLVMAliasSet(LLVMAliasSet *AS) noexcept; | ||
|
||
FilteredLLVMAliasSet(const FilteredLLVMAliasSet &) = delete; | ||
FilteredLLVMAliasSet &operator=(const FilteredLLVMAliasSet &) = delete; | ||
FilteredLLVMAliasSet &operator=(FilteredLLVMAliasSet &&) noexcept = delete; | ||
|
||
FilteredLLVMAliasSet(FilteredLLVMAliasSet &&) noexcept = default; | ||
|
||
~FilteredLLVMAliasSet(); | ||
|
||
template <typename... ArgsT, | ||
typename = std::enable_if_t< | ||
std::is_constructible_v<LLVMAliasSet, ArgsT...>>> | ||
explicit FilteredLLVMAliasSet(ArgsT &&...Args) | ||
: FilteredLLVMAliasSet(std::forward<ArgsT>(Args)...) {} | ||
|
||
// --- API Functions: | ||
|
||
[[nodiscard]] inline bool isInterProcedural() const noexcept { | ||
return false; | ||
}; | ||
|
||
[[nodiscard]] AliasAnalysisType getAliasAnalysisType() const noexcept; | ||
|
||
[[nodiscard]] AliasResult alias(const llvm::Value *V1, const llvm::Value *V2, | ||
const llvm::Instruction *I); | ||
[[nodiscard]] AliasResult alias(const llvm::Value *V1, const llvm::Value *V2, | ||
const llvm::Function *Fun); | ||
|
||
[[nodiscard]] AliasSetPtrTy getAliasSet(const llvm::Value *V, | ||
const llvm::Instruction *I); | ||
[[nodiscard]] AliasSetPtrTy getAliasSet(const llvm::Value *V, | ||
const llvm::Function *Fun); | ||
|
||
[[nodiscard]] AllocationSiteSetPtrTy | ||
getReachableAllocationSites(const llvm::Value *V, bool IntraProcOnly = false, | ||
const llvm::Instruction *I = nullptr); | ||
|
||
// Checks if PotentialValue is in the reachable allocation sites of V. | ||
[[nodiscard]] bool isInReachableAllocationSites( | ||
const llvm::Value *V, const llvm::Value *PotentialValue, | ||
bool IntraProcOnly = false, const llvm::Instruction *I = nullptr); | ||
|
||
void mergeWith(const FilteredLLVMAliasSet & /*OtherPTI*/) { | ||
llvm::report_fatal_error("Not Supported"); | ||
} | ||
|
||
void introduceAlias(const llvm::Value * /*V1*/, const llvm::Value * /*V2*/, | ||
const llvm::Instruction * /*I*/ = nullptr, | ||
AliasResult /*Kind*/ = AliasResult::MustAlias) { | ||
llvm::report_fatal_error("Not Supported"); | ||
} | ||
|
||
void print(llvm::raw_ostream &OS = llvm::outs()) const; | ||
|
||
[[nodiscard]] nlohmann::json getAsJson() const; | ||
|
||
void printAsJson(llvm::raw_ostream &OS = llvm::outs()) const; | ||
|
||
[[nodiscard]] AnalysisProperties getAnalysisProperties() const noexcept { | ||
return AnalysisProperties::None; | ||
} | ||
|
||
private: | ||
struct ReachableAllocationSitesKey { | ||
llvm::PointerIntPair<const llvm::Function *, 1, bool> FunAndIntraProcOnly; | ||
v_t Value{}; | ||
}; | ||
|
||
struct ReachableAllocationSitesKeyDMI { | ||
inline static ReachableAllocationSitesKey getEmptyKey() noexcept { | ||
return {{}, llvm::DenseMapInfo<v_t>::getEmptyKey()}; | ||
} | ||
inline static ReachableAllocationSitesKey getTombstoneKey() noexcept { | ||
return {{}, llvm::DenseMapInfo<v_t>::getTombstoneKey()}; | ||
} | ||
inline static auto getHashValue(ReachableAllocationSitesKey Key) noexcept { | ||
return llvm::hash_combine(Key.FunAndIntraProcOnly.getOpaqueValue(), | ||
Key.Value); | ||
} | ||
inline static bool isEqual(ReachableAllocationSitesKey Key1, | ||
ReachableAllocationSitesKey Key2) noexcept { | ||
return Key1.FunAndIntraProcOnly == Key2.FunAndIntraProcOnly && | ||
Key1.Value == Key2.Value; | ||
} | ||
}; | ||
|
||
FilteredLLVMAliasSet(MaybeUniquePtr<LLVMAliasSet, true> AS) noexcept; | ||
|
||
MaybeUniquePtr<LLVMAliasSet, /*RequireAlignment=*/true> AS; | ||
AliasSetOwner<AliasSetTy> Owner; | ||
llvm::DenseMap<std::pair<const llvm::Function *, v_t>, AliasSetPtrTy> | ||
AliasSetMap; | ||
llvm::DenseMap<ReachableAllocationSitesKey, std::unique_ptr<AliasSetTy>, | ||
ReachableAllocationSitesKeyDMI> | ||
ReachableAllocationSitesMap; | ||
}; | ||
} // namespace psr | ||
|
||
#endif // PHASAR_PHASARLLVM_POINTER_FILTEREDLLVMALIASSET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.