Skip to content
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

Update LLVMBasedAliasAnalysis #610

Draft
wants to merge 9 commits into
base: development
Choose a base branch
from
1 change: 1 addition & 0 deletions BreakingChanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Development HEAD

- Removed the CLI options `--alias-analysis` and `-P`. PhASAR now only supports the default alias analysis pipeline from LLVM consisting of TBAA, ScopedNoAliasAA and BasicAA.
- Default build mode is no longer `SHARED` but `STATIC`. To build in shared mode, use the cmake option `BUILD_SHARED_LIBS` which we don't recommend anymore. Consider using `PHASAR_BUILD_DYNLIB` instead to build one big libphasar.so.

## v0323
Expand Down
3 changes: 1 addition & 2 deletions include/phasar/PhasarLLVM/HelperAnalyses.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HelperAnalyses { // NOLINT(cppcoreguidelines-special-member-functions)
public:
explicit HelperAnalyses(std::string IRFile,
std::optional<nlohmann::json> PrecomputedPTS,
AliasAnalysisType PTATy, bool AllowLazyPTS,
bool AllowLazyPTS,
std::vector<std::string> EntryPoints,
std::optional<nlohmann::json> PrecomputedCG,
CallGraphAnalysisType CGTy, Soundness SoundnessLevel,
Expand Down Expand Up @@ -66,7 +66,6 @@ class HelperAnalyses { // NOLINT(cppcoreguidelines-special-member-functions)

// PTS
std::optional<nlohmann::json> PrecomputedPTS;
AliasAnalysisType PTATy{};
bool AllowLazyPTS{};

// ICF
Expand Down
2 changes: 0 additions & 2 deletions include/phasar/PhasarLLVM/HelperAnalysisConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define PHASAR_PHASARLLVM_HELPERANALYSISCONFIG_H

#include "phasar/ControlFlow/CallGraphAnalysisType.h"
#include "phasar/Pointer/AliasAnalysisType.h"
#include "phasar/Utils/Soundness.h"

#include "nlohmann/json.hpp"
Expand All @@ -22,7 +21,6 @@ namespace psr {
struct HelperAnalysisConfig {
std::optional<nlohmann::json> PrecomputedPTS = std::nullopt;
std::optional<nlohmann::json> PrecomputedCG = std::nullopt;
AliasAnalysisType PTATy = AliasAnalysisType::CFLAnders;
CallGraphAnalysisType CGTy = CallGraphAnalysisType::OTF;
Soundness SoundnessLevel = Soundness::Soundy;
bool AutoGlobalSupport = true;
Expand Down
6 changes: 1 addition & 5 deletions include/phasar/PhasarLLVM/Pointer/LLVMAliasGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ class LLVMAliasGraph : public AnalysisPropertiesMixin<LLVMAliasGraph>,
* considered. False, if May and Must Aliases should be
* considered.
*/
explicit LLVMAliasGraph(
LLVMProjectIRDB &IRDB, bool UseLazyEvaluation = true,
AliasAnalysisType PATy = AliasAnalysisType::CFLAnders);
explicit LLVMAliasGraph(LLVMProjectIRDB &IRDB, bool UseLazyEvaluation = true);

/**
* @brief Returns true if graph contains 0 nodes.
Expand Down Expand Up @@ -212,8 +210,6 @@ class LLVMAliasGraph : public AnalysisPropertiesMixin<LLVMAliasGraph>,

[[nodiscard]] bool isInterProcedural() const noexcept;

[[nodiscard]] AliasAnalysisType getAliasAnalysisType() const noexcept;

AliasResult alias(const llvm::Value *V1, const llvm::Value *V2,
const llvm::Instruction *I = nullptr);

Expand Down
22 changes: 16 additions & 6 deletions include/phasar/PhasarLLVM/Pointer/LLVMAliasSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Value;
class Instruction;
class GlobalVariable;
class Function;
class GlobalObject;
class DataLayout;
} // namespace llvm

namespace psr {
Expand Down Expand Up @@ -58,8 +60,7 @@ class LLVMAliasSet : public AnalysisPropertiesMixin<LLVMAliasSet>,
* UseLazyEvaluation is true, computes points-to-sets for functions that do
* not use global variables on the fly
*/
explicit LLVMAliasSet(LLVMProjectIRDB *IRDB, bool UseLazyEvaluation = true,
AliasAnalysisType PATy = AliasAnalysisType::CFLAnders);
explicit LLVMAliasSet(LLVMProjectIRDB *IRDB, bool UseLazyEvaluation = true);

explicit LLVMAliasSet(LLVMProjectIRDB *IRDB,
const nlohmann::json &SerializedPTS);
Expand All @@ -68,10 +69,6 @@ class LLVMAliasSet : public AnalysisPropertiesMixin<LLVMAliasSet>,
return false;
};

[[nodiscard]] inline AliasAnalysisType getAliasAnalysisType() const noexcept {
return PTA.getPointerAnalysisType();
};

[[nodiscard]] AliasResult alias(const llvm::Value *V1, const llvm::Value *V2,
const llvm::Instruction *I = nullptr);

Expand Down Expand Up @@ -158,6 +155,19 @@ class LLVMAliasSet : public AnalysisPropertiesMixin<LLVMAliasSet>,
};

static_assert(IsAliasInfo<LLVMAliasSet>);
using TTTT = decltype(detail::testAliasInfo(
std::declval<LLVMAliasSet &>(), std::declval<const LLVMAliasSet &>()));

using TTTT2 = std::void_t<
decltype(std::declval<const LLVMAliasSet>().print(llvm::outs())),
decltype(std::declval<const LLVMAliasSet>().printAsJson(llvm::outs())),
decltype(std::declval<LLVMAliasSet>().mergeWith(
std::declval<LLVMAliasSet>())),
decltype(std::declval<LLVMAliasSet>().introduceAlias(
std::declval<typename AliasInfoTraits<LLVMAliasSet>::v_t>(),
std::declval<typename AliasInfoTraits<LLVMAliasSet>::v_t>(),
std::declval<typename AliasInfoTraits<LLVMAliasSet>::n_t>(),
AliasResult{}))>;

} // namespace psr

Expand Down
20 changes: 6 additions & 14 deletions include/phasar/PhasarLLVM/Pointer/LLVMBasedAliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,34 @@
#ifndef PHASAR_PHASARLLVM_POINTER_LLVMBASEDALIASANALYSIS_H_
#define PHASAR_PHASARLLVM_POINTER_LLVMBASEDALIASANALYSIS_H_

#include "phasar/Pointer/AliasAnalysisType.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/raw_ostream.h"

#include "llvm/Analysis/AliasAnalysis.h"
#include <memory>

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

namespace psr {

class LLVMProjectIRDB;

class LLVMBasedAliasAnalysis {

public:
explicit LLVMBasedAliasAnalysis(
LLVMProjectIRDB &IRDB, bool UseLazyEvaluation,
AliasAnalysisType PATy = AliasAnalysisType::Basic);
LLVMBasedAliasAnalysis(LLVMProjectIRDB &IRDB, bool UseLazyEvaluation = true);

LLVMBasedAliasAnalysis(LLVMBasedAliasAnalysis &&) noexcept = default;
LLVMBasedAliasAnalysis &
operator=(LLVMBasedAliasAnalysis &&) noexcept = default;

LLVMBasedAliasAnalysis(const LLVMBasedAliasAnalysis &) = delete;
LLVMBasedAliasAnalysis &operator=(const LLVMBasedAliasAnalysis &) = delete;
~LLVMBasedAliasAnalysis();

void print(llvm::raw_ostream &OS = llvm::outs()) const;
~LLVMBasedAliasAnalysis();

[[nodiscard]] inline llvm::AAResults *getAAResults(llvm::Function *F) {
if (!hasAliasInfo(*F)) {
Expand All @@ -52,11 +50,6 @@ class LLVMBasedAliasAnalysis {

void clear() noexcept;

[[nodiscard]] inline AliasAnalysisType
getPointerAnalysisType() const noexcept {
return PATy;
};

private:
[[nodiscard]] bool hasAliasInfo(const llvm::Function &Fun) const;

Expand All @@ -66,7 +59,6 @@ class LLVMBasedAliasAnalysis {

struct Impl;
std::unique_ptr<Impl> PImpl;
AliasAnalysisType PATy;
llvm::DenseMap<const llvm::Function *, llvm::AAResults *> AAInfos;
};

Expand Down
8 changes: 4 additions & 4 deletions include/phasar/PhasarLLVM/Utils/BasicBlockOrdering.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ namespace llvm {
class Function;
class BasicBlock;
class Instruction;
class DominatorTree;
} // namespace llvm

namespace psr {

class DefaultDominatorTreeAnalysis {
llvm::DenseMap<const llvm::Function *, std::unique_ptr<llvm::DominatorTree>>
Dom;

public:
llvm::DominatorTree &operator()(const llvm::Function *F);

private:
llvm::DenseMap<const llvm::Function *, std::unique_ptr<llvm::DominatorTree>>
Dom{};
};

/// Provides a simple partial ordering of BasicBlocks based on LLVM's
Expand Down
1 change: 0 additions & 1 deletion include/phasar/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef PHASAR_POINTER_H
#define PHASAR_POINTER_H

#include "phasar/Pointer/AliasAnalysisType.h"
#include "phasar/Pointer/AliasInfo.h"
#include "phasar/Pointer/AliasInfoBase.h"
#include "phasar/Pointer/AliasInfoTraits.h"
Expand Down
19 changes: 0 additions & 19 deletions include/phasar/Pointer/AliasAnalysisType.def

This file was deleted.

23 changes: 0 additions & 23 deletions include/phasar/Pointer/AliasAnalysisType.h

This file was deleted.

9 changes: 0 additions & 9 deletions include/phasar/Pointer/AliasInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class Instruction;
} // namespace llvm

namespace psr {
enum class AliasAnalysisType;

template <typename V, typename N> class AliasInfoRef;
template <typename V, typename N> class AliasInfo;
Expand Down Expand Up @@ -97,10 +96,6 @@ class AliasInfoRef : public AnalysisPropertiesMixin<AliasInfoRef<V, N>> {
assert(VT != nullptr);
return VT->IsInterProcedural(AA);
}
[[nodiscard]] AliasAnalysisType getAliasAnalysisType() const noexcept {
assert(VT != nullptr);
return VT->GetAliasAnalysisType(AA);
}

[[nodiscard]] AliasResult alias(ByConstRef<v_t> Pointer1,
ByConstRef<v_t> Pointer2,
Expand Down Expand Up @@ -189,7 +184,6 @@ class AliasInfoRef : public AnalysisPropertiesMixin<AliasInfoRef<V, N>> {
private:
struct VTable {
bool (*IsInterProcedural)(const void *) noexcept;
AliasAnalysisType (*GetAliasAnalysisType)(const void *) noexcept;
AliasResult (*Alias)(void *, ByConstRef<v_t>, ByConstRef<v_t>,
ByConstRef<n_t>);
AliasSetPtrTy (*GetAliasSet)(void *, ByConstRef<v_t>, ByConstRef<n_t>);
Expand All @@ -215,9 +209,6 @@ class AliasInfoRef : public AnalysisPropertiesMixin<AliasInfoRef<V, N>> {
[](const void *AA) noexcept {
return static_cast<const ConcreteAA *>(AA)->isInterProcedural();
},
[](const void *AA) noexcept {
return static_cast<const ConcreteAA *>(AA)->getAliasAnalysisType();
},
[](void *AA, ByConstRef<v_t> Pointer1, ByConstRef<v_t> Pointer2,
ByConstRef<n_t> AtInstruction) {
return static_cast<ConcreteAA *>(AA)->alias(Pointer1, Pointer2,
Expand Down
7 changes: 3 additions & 4 deletions include/phasar/Pointer/AliasInfoBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Value;

namespace psr {

enum class AliasAnalysisType;
enum class AnalysisProperties;
enum class AliasResult;

Expand All @@ -45,8 +44,8 @@ auto testAliasInfo(
const std::optional<typename AliasInfoTraits<T>::n_t> &NT = {},
const std::optional<typename AliasInfoTraits<T>::v_t> &VT = {})
-> decltype(std::make_tuple(
CAI.isInterProcedural(), CAI.getAliasAnalysisType(),
AI.alias(*VT, *VT, *NT), AI.getAliasSet(*VT, *NT),
CAI.isInterProcedural(), AI.alias(*VT, *VT, *NT),
AI.getAliasSet(*VT, *NT),
AI.getReachableAllocationSites(*VT, true, *NT),
AI.isInReachableAllocationSites(*VT, *VT, true, *NT), CAI.getAsJson(),
CAI.getAnalysisProperties(), CAI.isContextSensitive(),
Expand All @@ -65,7 +64,7 @@ struct IsAliasInfo<
std::declval<typename AliasInfoTraits<T>::n_t>(),
AliasResult{}))>,
std::enable_if_t<std::is_same_v<
std::tuple<bool, AliasAnalysisType, AliasResult,
std::tuple<bool, AliasResult,
typename AliasInfoTraits<T>::AliasSetPtrTy,
typename AliasInfoTraits<T>::AllocationSiteSetPtrTy, bool,
nlohmann::json, AnalysisProperties, bool, bool, bool>,
Expand Down
21 changes: 8 additions & 13 deletions lib/PhasarLLVM/HelperAnalyses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@
#include <string>

namespace psr {
HelperAnalyses::HelperAnalyses(std::string IRFile,
std::optional<nlohmann::json> PrecomputedPTS,
AliasAnalysisType PTATy, bool AllowLazyPTS,
std::vector<std::string> EntryPoints,
std::optional<nlohmann::json> PrecomputedCG,
CallGraphAnalysisType CGTy,
Soundness SoundnessLevel,
bool AutoGlobalSupport) noexcept
HelperAnalyses::HelperAnalyses(
std::string IRFile, std::optional<nlohmann::json> PrecomputedPTS,
bool AllowLazyPTS, std::vector<std::string> EntryPoints,
std::optional<nlohmann::json> PrecomputedCG, CallGraphAnalysisType CGTy,
Soundness SoundnessLevel, bool AutoGlobalSupport) noexcept
: IRFile(std::move(IRFile)), PrecomputedPTS(std::move(PrecomputedPTS)),
PTATy(PTATy), AllowLazyPTS(AllowLazyPTS),
PrecomputedCG(std::move(PrecomputedCG)),
AllowLazyPTS(AllowLazyPTS), PrecomputedCG(std::move(PrecomputedCG)),
EntryPoints(std::move(EntryPoints)), CGTy(CGTy),
SoundnessLevel(SoundnessLevel), AutoGlobalSupport(AutoGlobalSupport) {}

HelperAnalyses::HelperAnalyses(std::string IRFile,
std::vector<std::string> EntryPoints,
HelperAnalysisConfig Config) noexcept
: IRFile(std::move(IRFile)),
PrecomputedPTS(std::move(Config.PrecomputedPTS)), PTATy(Config.PTATy),
PrecomputedPTS(std::move(Config.PrecomputedPTS)),
AllowLazyPTS(Config.AllowLazyPTS),
PrecomputedCG(std::move(Config.PrecomputedCG)),
EntryPoints(std::move(EntryPoints)), CGTy(Config.CGTy),
Expand Down Expand Up @@ -58,8 +54,7 @@ LLVMAliasSet &HelperAnalyses::getAliasInfo() {
if (PrecomputedPTS.has_value()) {
PT = std::make_unique<LLVMAliasSet>(&getProjectIRDB(), *PrecomputedPTS);
} else {
PT = std::make_unique<LLVMAliasSet>(&getProjectIRDB(), AllowLazyPTS,
PTATy);
PT = std::make_unique<LLVMAliasSet>(&getProjectIRDB(), AllowLazyPTS);
}
}
return *PT;
Expand Down
9 changes: 2 additions & 7 deletions lib/PhasarLLVM/Pointer/LLVMAliasGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ std::string LLVMAliasGraph::EdgeProperties::getValueAsString() const {

// points-to graph stuff

LLVMAliasGraph::LLVMAliasGraph(LLVMProjectIRDB &IRDB, bool UseLazyEvaluation,
AliasAnalysisType PATy)
: PTA(IRDB, UseLazyEvaluation, PATy) {}
LLVMAliasGraph::LLVMAliasGraph(LLVMProjectIRDB &IRDB, bool UseLazyEvaluation)
: PTA(IRDB, UseLazyEvaluation) {}

void LLVMAliasGraph::computeAliasGraph(const llvm::Value *V) {
// FIXME when fixed in LLVM
Expand Down Expand Up @@ -244,10 +243,6 @@ void LLVMAliasGraph::computeAliasGraph(llvm::Function *F) {

bool LLVMAliasGraph::isInterProcedural() const noexcept { return false; }

AliasAnalysisType LLVMAliasGraph::getAliasAnalysisType() const noexcept {
return PTA.getPointerAnalysisType();
}

AliasResult LLVMAliasGraph::alias(const llvm::Value *V1, const llvm::Value *V2,
const llvm::Instruction * /*I*/) {
computeAliasGraph(V1);
Expand Down
Loading
Loading