Skip to content

Alias Iterator #783

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

Open
wants to merge 12 commits into
base: development
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ class IDEAliasAwareDefaultFlowFunctionsImpl

using IDENoAliasDefaultFlowFunctionsImpl::isFunctionModeled;

[[nodiscard]] constexpr LLVMAliasInfoRef getAliasInfo() const noexcept {
[[nodiscard]] constexpr LLVMAliasIteratorRef getAliasInfo() const noexcept {
return AS;
}

constexpr IDEAliasAwareDefaultFlowFunctionsImpl(LLVMAliasInfoRef AS) noexcept
: AS(AS) {
assert(AS && "You must provide an alias information handle!");
}
constexpr IDEAliasAwareDefaultFlowFunctionsImpl(
LLVMAliasIteratorRef AS) noexcept
: AS(AS) {}

[[nodiscard]] FlowFunctionPtrType getNormalFlowFunctionImpl(n_t Curr,
n_t /*Succ*/);
Expand All @@ -54,8 +53,8 @@ class IDEAliasAwareDefaultFlowFunctionsImpl
using IDENoAliasDefaultFlowFunctionsImpl::getCallFlowFunctionImpl;
using IDENoAliasDefaultFlowFunctionsImpl::getCallToRetFlowFunctionImpl;

protected:
LLVMAliasInfoRef AS;
private:
LLVMAliasIteratorRef AS;
};
} // namespace detail

Expand All @@ -72,7 +71,7 @@ class DefaultAliasAwareIDEProblem
/// \note It is useful to use an instance of FilteredAliasSet for the alias
/// information to lower suprious aliases
explicit DefaultAliasAwareIDEProblem(
const ProjectIRDBBase<db_t> *IRDB, LLVMAliasInfoRef AS,
const ProjectIRDBBase<db_t> *IRDB, LLVMAliasIteratorRef AS,
std::vector<std::string> EntryPoints,
std::optional<d_t>
ZeroValue) noexcept(std::is_nothrow_move_constructible_v<d_t>)
Expand Down Expand Up @@ -116,7 +115,7 @@ class DefaultAliasAwareIFDSProblem
/// \note It is useful to use an instance of FilteredAliasSet for the alias
/// information to lower suprious aliases
explicit DefaultAliasAwareIFDSProblem(
const ProjectIRDBBase<db_t> *IRDB, LLVMAliasInfoRef AS,
const ProjectIRDBBase<db_t> *IRDB, LLVMAliasIteratorRef AS,
std::vector<std::string> EntryPoints,
d_t ZeroValue) noexcept(std::is_nothrow_move_constructible_v<d_t>)
: IFDSTabulationProblem(IRDB, std::move(EntryPoints), ZeroValue),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "phasar/PhasarLLVM/DataFlow/IfdsIde/DefaultNoAliasIDEProblem.h"
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
#include "phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h"

// Forward declaration of types for which we only use its pointer or ref type
namespace llvm {
Expand All @@ -34,15 +35,14 @@ class IDEReachableAllocationSitesDefaultFlowFunctionsImpl

using IDENoAliasDefaultFlowFunctionsImpl::isFunctionModeled;

[[nodiscard]] constexpr LLVMAliasInfoRef getAliasInfo() const noexcept {
[[nodiscard]] constexpr LLVMPointsToIteratorRef
getPointsToInfo() const noexcept {
return AS;
}

constexpr IDEReachableAllocationSitesDefaultFlowFunctionsImpl(
LLVMAliasInfoRef AS) noexcept
: AS(AS) {
assert(AS && "You must provide an alias information handle!");
}
LLVMPointsToIteratorRef AS) noexcept
: AS(AS) {}

[[nodiscard]] FlowFunctionPtrType getNormalFlowFunctionImpl(n_t Curr,
n_t /*Succ*/);
Expand All @@ -56,7 +56,7 @@ class IDEReachableAllocationSitesDefaultFlowFunctionsImpl
using IDENoAliasDefaultFlowFunctionsImpl::getCallToRetFlowFunctionImpl;

protected:
LLVMAliasInfoRef AS;
LLVMPointsToIteratorRef AS;
};
} // namespace detail

Expand All @@ -73,7 +73,7 @@ class DefaultReachableAllocationSitesIDEProblem
/// \note It is useful to use an instance of FilteredAliasSet for the alias
/// information to lower suprious aliases
explicit DefaultReachableAllocationSitesIDEProblem(
const ProjectIRDBBase<db_t> *IRDB, LLVMAliasInfoRef AS,
const ProjectIRDBBase<db_t> *IRDB, LLVMPointsToIteratorRef AS,
std::vector<std::string> EntryPoints,
std::optional<d_t>
ZeroValue) noexcept(std::is_nothrow_move_constructible_v<d_t>)
Expand Down Expand Up @@ -115,7 +115,7 @@ class DefaultReachableAllocationSitesIFDSProblem
/// \note It is useful to use an instance of FilteredAliasSet for the alias
/// information to lower suprious aliases
explicit DefaultReachableAllocationSitesIFDSProblem(
const ProjectIRDBBase<db_t> *IRDB, LLVMAliasInfoRef AS,
const ProjectIRDBBase<db_t> *IRDB, LLVMPointsToIteratorRef AS,
std::vector<std::string> EntryPoints,
d_t ZeroValue) noexcept(std::is_nothrow_move_constructible_v<d_t>)
: IFDSTabulationProblem(IRDB, std::move(EntryPoints), ZeroValue),
Expand Down
5 changes: 5 additions & 0 deletions include/phasar/PhasarLLVM/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
#ifndef PHASAR_PHASARLLVM_POINTER_H
#define PHASAR_PHASARLLVM_POINTER_H

#include "phasar/Config/phasar-config.h" // for PHASAR_USE_SVF
#include "phasar/PhasarLLVM/Pointer/AliasAnalysisView.h"
#include "phasar/PhasarLLVM/Pointer/FilteredLLVMAliasSet.h"
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
#include "phasar/PhasarLLVM/Pointer/LLVMAliasSet.h"
#include "phasar/PhasarLLVM/Pointer/LLVMPointsToUtils.h"

#ifdef PHASAR_USE_SVF
#include "phasar/PhasarLLVM/Pointer/SVF/SVFPointsToSet.h"
#endif

#endif // PHASAR_PHASARLLVM_POINTER_H
4 changes: 4 additions & 0 deletions include/phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define PHASAR_PHASARLLVM_POINTER_LLVMALIASINFO_H_

#include "phasar/Pointer/AliasInfo.h"
#include "phasar/Pointer/AliasIterator.h"

namespace llvm {
class Function;
Expand All @@ -20,6 +21,9 @@ class Value;

namespace psr {

using LLVMAliasIteratorRef =
AliasIteratorRef<const llvm::Value *, const llvm::Instruction *>;

using LLVMAliasInfoRef =
AliasInfoRef<const llvm::Value *, const llvm::Instruction *>;

Expand Down
21 changes: 13 additions & 8 deletions include/phasar/PhasarLLVM/Pointer/LLVMAliasSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ template <>
struct AliasInfoTraits<LLVMAliasSet>
: DefaultAATraits<const llvm::Value *, const llvm::Instruction *> {};

/// Utility function to check whether PotentialValue may be in the reachable
/// allocation-sites of V, if V and PotentialValue alias.
[[nodiscard]] bool isInReachableAllocationSitesTy(
const llvm::Value *V, const llvm::Value *PotentialValue, bool IntraProcOnly,
const llvm::Function *VFun = nullptr,
const llvm::GlobalObject *VG = nullptr);

class LLVMAliasSet : public AnalysisPropertiesMixin<LLVMAliasSet>,
public AliasInfoBaseUtils {
// For int*IsReachableAllocationSiteTy:
Expand Down Expand Up @@ -120,6 +127,12 @@ class LLVMAliasSet : public AnalysisPropertiesMixin<LLVMAliasSet>,

[[nodiscard]] inline bool empty() const { return AnalyzedFunctions.empty(); }

friend bool isInReachableAllocationSitesTy(const llvm::Value *V,
const llvm::Value *PotentialValue,
bool IntraProcOnly,
const llvm::Function *VFun,
const llvm::GlobalObject *VG);

private:
void computeValuesAliasSet(const llvm::Value *V);

Expand All @@ -131,14 +144,6 @@ class LLVMAliasSet : public AnalysisPropertiesMixin<LLVMAliasSet>,

void mergeAliasSets(BoxedPtr<AliasSetTy> PTS1, BoxedPtr<AliasSetTy> PTS2);

bool interIsReachableAllocationSiteTy(const llvm::Value *V,
const llvm::Value *P) const;

bool intraIsReachableAllocationSiteTy(const llvm::Value *V,
const llvm::Value *P,
const llvm::Function *VFun,
const llvm::GlobalObject *VG) const;

/// Utility function used by computeFunctionsAliasSet(...)
void addPointer(FunctionAliasView AA, const llvm::DataLayout &DL,
const llvm::Value *V, std::vector<const llvm::Value *> &Reps);
Expand Down
31 changes: 31 additions & 0 deletions include/phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/******************************************************************************
* Copyright (c) 2025 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_LLVMPOINTSTOINFO_H
#define PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOINFO_H

#include "phasar/Pointer/PointsToIterator.h"

namespace llvm {
class Instruction;
class Value;
} // namespace llvm

namespace psr {

using LLVMPointsToIteratorRef =
PointsToIteratorRef<const llvm::Value *, const llvm::Value *,
const llvm::Instruction *>;

using LLVMPointsToIterator =
PointsToIterator<const llvm::Value *, const llvm::Value *,
const llvm::Instruction *>;
} // namespace psr

#endif // PHASAR_PHASARLLVM_POINTER_LLVMPOINTSTOINFO_H
34 changes: 34 additions & 0 deletions include/phasar/PhasarLLVM/Pointer/SVF/SVFPointsToSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
#define PHASAR_PHASARLLVM_POINTER_SVF_SVFPOINTSTOSET_H

#include "phasar/Config/phasar-config.h"
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
#include "phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h"
#include "phasar/Pointer/AliasAnalysisType.h"
#include "phasar/Pointer/PointsToInfo.h"
#include "phasar/Pointer/PointsToIterator.h"

#include "llvm/ADT/DenseSet.h"
#include "llvm/IR/Value.h"

#include <cstdint>

#ifndef PHASAR_USE_SVF
#error \
"Don't include SVFPointsToSet.h when PhASAR is not configured to include SVF. Set the cmake variable PHASAR_USE_SVF and retry."
Expand All @@ -37,8 +43,18 @@ struct SVFPointsToInfoTraits {
using PointsToSetPtrTy = PointsToSetTy;
};

enum class SVFPointsToAnalysisType {
DDA = int(AliasAnalysisType::SVFDDA),
VFS = int(AliasAnalysisType::SVFVFS),
};

using SVFBasedPointsToInfo = PointsToInfo<SVFPointsToInfoTraits>;
using SVFBasedPointsToInfoRef = PointsToInfoRef<SVFPointsToInfoTraits>;
using SVFBasedPointsToIterator =
PointsToIterator<const llvm::Value *, uint32_t, const llvm::Instruction *>;
using SVFBasedPointsToIteratorRef =
PointsToIteratorRef<const llvm::Value *, uint32_t,
const llvm::Instruction *>;

/// Use SVF to perform a VersionedFlowSensitive pointer analysis and return the
/// results compatible to psr::PointsToInfo and psr::PointsToInfoRef
Expand All @@ -50,6 +66,24 @@ createSVFVFSPointsToInfo(LLVMProjectIRDB &IRDB);
[[nodiscard]] SVFBasedPointsToInfo
createSVFDDAPointsToInfo(LLVMProjectIRDB &IRDB);

/// Use SVF to perform the specified pointer analysis and return the results
/// compatible to psr::PointsToInfo and psr::PointsToInfoRef
[[nodiscard]] SVFBasedPointsToInfo
createSVFPointsToInfo(LLVMProjectIRDB &IRDB, SVFPointsToAnalysisType PTATy);

/// Use SVF to perform the specified pointer analysis and return the results
/// compatible to psr::LLVMPointsToIterator, converting the points-to sets to
/// LLVM allocation-sites
[[nodiscard]] LLVMPointsToIterator
createLLVMSVFPointsToIterator(LLVMProjectIRDB &IRDB,
SVFPointsToAnalysisType PTATy);

/// Use SVF to perform a ContextDDA pointer analysis and return the results
/// compatible to psr::LLVMAliasInfo and psr::LLVMAliasInfoRef
///
/// \note Only support DDA for now, as VFS seems to not support getRevPts().
[[nodiscard]] LLVMAliasInfo createLLVMSVFDDAAliasInfo(LLVMProjectIRDB &IRDB);

} // namespace psr

#endif // PHASAR_PHASARLLVM_POINTER_SVF_SVFPOINTSTOSET_H
2 changes: 2 additions & 0 deletions include/phasar/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#include "phasar/Pointer/AliasInfo.h"
#include "phasar/Pointer/AliasInfoBase.h"
#include "phasar/Pointer/AliasInfoTraits.h"
#include "phasar/Pointer/AliasIterator.h"
#include "phasar/Pointer/AliasResult.h"
#include "phasar/Pointer/AliasSetOwner.h"
#include "phasar/Pointer/PointsToInfo.h"
#include "phasar/Pointer/PointsToInfoBase.h"
#include "phasar/Pointer/PointsToIterator.h"

#endif // PHASAR_POINTER_H
3 changes: 3 additions & 0 deletions include/phasar/Pointer/AliasAnalysisType.def
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ ALIAS_ANALYSIS_TYPE(Basic, "basic", "Basic LLVM alias resolving based on simple,
ALIAS_ANALYSIS_TYPE(CFLSteens, "cflsteens", "Steensgaard-style alias analysis (equality-based)")
ALIAS_ANALYSIS_TYPE(CFLAnders, "cflanders", "Andersen-style alias analysis (subset-based) (default)")
ALIAS_ANALYSIS_TYPE(PointsTo, "points-to", "Alias-information based on (external) points-to information")

#ifdef PHASAR_USE_SVF
ALIAS_ANALYSIS_TYPE(SVFDDA, "svf-dda", "Alias-information based on SVF's ContextDDA analysis. Requires SVF.")
ALIAS_ANALYSIS_TYPE(SVFVFS, "svf-vfs", "Alias-information based on SVF's VersionedFlowSensitive analysis. Requires SVF.")
#endif

#undef ALIAS_ANALYSIS_TYPE
3 changes: 3 additions & 0 deletions include/phasar/Pointer/AliasAnalysisType.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#ifndef PHASAR_POINTER_ALIASANALYSISTYPE_H
#define PHASAR_POINTER_ALIASANALYSISTYPE_H

#include "phasar/Config/phasar-config.h" // For PHASAR_USE_SVF in AliasAnalysisType.def

#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"

#include <string>

namespace psr {

enum class AliasAnalysisType {
#define ALIAS_ANALYSIS_TYPE(NAME, CMDFLAG, TYPE) NAME,
#include "phasar/Pointer/AliasAnalysisType.def"
Expand Down
Loading
Loading