Skip to content

Commit

Permalink
save intermediate state
Browse files Browse the repository at this point in the history
  • Loading branch information
pdschubert committed Jan 2, 2020
1 parent b0644ee commit d27f060
Show file tree
Hide file tree
Showing 54 changed files with 1,779 additions and 1,292 deletions.
13 changes: 11 additions & 2 deletions include/phasar/Controller/AnalysisController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@
#include <iosfwd>
#include <set>
#include <string>
#include <vector>

#include <phasar/DB/ProjectIRDB.h>
#include <phasar/PhasarLLVM/AnalysisStrategy/Strategies.h>
#include <phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h>
#include <phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h>
#include <phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h>
#include <phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h>

namespace psr {

class AnalysisController {
private:
ProjectIRDB IRDB;
ProjectIRDB &IRDB;
LLVMTypeHierarchy TH;
LLVMPointsToInfo PT;
LLVMBasedICFG ICF;
std::vector<DataFlowAnalysisType> DataFlowAnalyses;
std::vector<std::string> AnalysisConfigs;
std::set<std::string> EntryPoints;
AnalysisStrategy Strategy;

void executeDemandDriven();
void executeIncremental();
Expand All @@ -37,7 +42,11 @@ class AnalysisController {
void executeWholeProgram();

public:
AnalysisController();
AnalysisController(ProjectIRDB &IRDB,
std::vector<DataFlowAnalysisType> DataFlowAnalyses,
std::vector<std::string> AnalysisConfigs,
std::set<std::string> EntryPoints,
AnalysisStrategy Strategy);
~AnalysisController() = default;
AnalysisController(const AnalysisController &) = delete;
AnalysisController(AnalysisController &&) = delete;
Expand Down
3 changes: 2 additions & 1 deletion include/phasar/DB/ProjectIRDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <llvm/IR/Module.h>

#include <phasar/PhasarLLVM/Pointer/LLVMPointsToGraph.h>
#include <phasar/Utils/EnumFlags.h>

namespace llvm {
class Value;
Expand Down Expand Up @@ -69,7 +70,7 @@ class ProjectIRDB {
ProjectIRDB(IRDBOptions Options);
/// Constructs a ProjectIRDB from a bunch of LLVM IR files
ProjectIRDB(const std::vector<std::string> &IRFiles,
IRDBOptions Options = IRDBOptions::WPA);
IRDBOptions Options = (IRDBOptions::WPA | IRDBOptions::OWNS));
/// Constructs a ProjecIRDB from a bunch of LLVM Modules
ProjectIRDB(const std::vector<llvm::Module *> &Modules,
IRDBOptions Options = IRDBOptions::WPA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,49 @@

namespace psr {

template <typename V> class EdgeIdentity;
template <typename V> class AllTop;
template <typename L> class EdgeIdentity;
template <typename L> class AllTop;

template <typename V>
class AllBottom : public EdgeFunction<V>,
public std::enable_shared_from_this<AllBottom<V>> {
template <typename L>
class AllBottom : public EdgeFunction<L>,
public std::enable_shared_from_this<AllBottom<L>> {
private:
const V bottomElement;
const L bottomElement;

public:
AllBottom(V bottomElement) : bottomElement(bottomElement) {}
AllBottom(L bottomElement) : bottomElement(bottomElement) {}

~AllBottom() override = default;

V computeTarget(V source) override { return bottomElement; }
L computeTarget(L source) override { return bottomElement; }

std::shared_ptr<EdgeFunction<V>>
composeWith(std::shared_ptr<EdgeFunction<V>> secondFunction) override {
if (AllBottom<V> *ab = dynamic_cast<AllBottom<V> *>(secondFunction.get())) {
std::shared_ptr<EdgeFunction<L>>
composeWith(std::shared_ptr<EdgeFunction<L>> secondFunction) override {
if (AllBottom<L> *ab = dynamic_cast<AllBottom<L> *>(secondFunction.get())) {
return this->shared_from_this();
}
if (EdgeIdentity<V> *ei =
dynamic_cast<EdgeIdentity<V> *>(secondFunction.get())) {
if (EdgeIdentity<L> *ei =
dynamic_cast<EdgeIdentity<L> *>(secondFunction.get())) {
return this->shared_from_this();
}
return secondFunction->composeWith(this->shared_from_this());
}

std::shared_ptr<EdgeFunction<V>>
joinWith(std::shared_ptr<EdgeFunction<V>> otherFunction) override {
std::shared_ptr<EdgeFunction<L>>
joinWith(std::shared_ptr<EdgeFunction<L>> otherFunction) override {
if (otherFunction.get() == this ||
otherFunction->equal_to(this->shared_from_this()))
return this->shared_from_this();
if (AllTop<V> *alltop = dynamic_cast<AllTop<V> *>(otherFunction.get()))
if (AllTop<L> *alltop = dynamic_cast<AllTop<L> *>(otherFunction.get()))
return this->shared_from_this();
if (EdgeIdentity<V> *ei =
dynamic_cast<EdgeIdentity<V> *>(otherFunction.get()))
if (EdgeIdentity<L> *ei =
dynamic_cast<EdgeIdentity<L> *>(otherFunction.get()))
return this->shared_from_this();
return this->shared_from_this();
}

bool equal_to(std::shared_ptr<EdgeFunction<V>> other) const override {
if (AllBottom<V> *allbottom = dynamic_cast<AllBottom<V> *>(other.get())) {
bool equal_to(std::shared_ptr<EdgeFunction<L>> other) const override {
if (AllBottom<L> *allbottom = dynamic_cast<AllBottom<L> *>(other.get())) {
return (allbottom->bottomElement == bottomElement);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@

namespace psr {

template <typename V>
class AllTop : public EdgeFunction<V>,
public std::enable_shared_from_this<AllTop<V>> {
template <typename L>
class AllTop : public EdgeFunction<L>,
public std::enable_shared_from_this<AllTop<L>> {
private:
const V topElement;
const L topElement;

public:
AllTop(V topElement) : topElement(topElement) {}
AllTop(L topElement) : topElement(topElement) {}

~AllTop() override = default;

V computeTarget(V source) override { return topElement; }
L computeTarget(L source) override { return topElement; }

std::shared_ptr<EdgeFunction<V>>
composeWith(std::shared_ptr<EdgeFunction<V>> secondFunction) override {
std::shared_ptr<EdgeFunction<L>>
composeWith(std::shared_ptr<EdgeFunction<L>> secondFunction) override {
return this->shared_from_this();
}

std::shared_ptr<EdgeFunction<V>>
joinWith(std::shared_ptr<EdgeFunction<V>> otherFunction) override {
std::shared_ptr<EdgeFunction<L>>
joinWith(std::shared_ptr<EdgeFunction<L>> otherFunction) override {
return otherFunction;
}

bool equal_to(std::shared_ptr<EdgeFunction<V>> other) const override {
if (AllTop<V> *alltop = dynamic_cast<AllTop<V> *>(other.get()))
bool equal_to(std::shared_ptr<EdgeFunction<L>> other) const override {
if (AllTop<L> *alltop = dynamic_cast<AllTop<L> *>(other.get()))
return (alltop->topElement == topElement);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

namespace psr {

template <typename V> class EdgeFunction;
template <typename L> class EdgeFunction;

template <typename V>
class EdgeIdentity : public EdgeFunction<V>,
public std::enable_shared_from_this<EdgeIdentity<V>> {
template <typename L>
class EdgeIdentity : public EdgeFunction<L>,
public std::enable_shared_from_this<EdgeIdentity<L>> {
private:
EdgeIdentity() = default;

Expand All @@ -42,33 +42,33 @@ class EdgeIdentity : public EdgeFunction<V>,

~EdgeIdentity() override = default;

V computeTarget(V source) override { return source; }
L computeTarget(L source) override { return source; }

std::shared_ptr<EdgeFunction<V>>
composeWith(std::shared_ptr<EdgeFunction<V>> secondFunction) override {
std::shared_ptr<EdgeFunction<L>>
composeWith(std::shared_ptr<EdgeFunction<L>> secondFunction) override {
return secondFunction;
}

std::shared_ptr<EdgeFunction<V>>
joinWith(std::shared_ptr<EdgeFunction<V>> otherFunction) override {
std::shared_ptr<EdgeFunction<L>>
joinWith(std::shared_ptr<EdgeFunction<L>> otherFunction) override {
if ((otherFunction.get() == this) ||
otherFunction->equal_to(this->shared_from_this()))
return this->shared_from_this();
if (AllBottom<V> *ab = dynamic_cast<AllBottom<V> *>(otherFunction.get()))
if (AllBottom<L> *ab = dynamic_cast<AllBottom<L> *>(otherFunction.get()))
return otherFunction;
if (AllTop<V> *at = dynamic_cast<AllTop<V> *>(otherFunction.get()))
if (AllTop<L> *at = dynamic_cast<AllTop<L> *>(otherFunction.get()))
return this->shared_from_this();
// do not know how to join; hence ask other function to decide on this
return otherFunction->joinWith(this->shared_from_this());
}

bool equal_to(std::shared_ptr<EdgeFunction<V>> other) const override {
bool equal_to(std::shared_ptr<EdgeFunction<L>> other) const override {
return this == other.get();
}

static std::shared_ptr<EdgeIdentity<V>> getInstance() {
static std::shared_ptr<EdgeIdentity<L>> getInstance() {
// implement singleton C++11 thread-safe (see Scott Meyers)
static std::shared_ptr<EdgeIdentity<V>> instance(new EdgeIdentity<V>());
static std::shared_ptr<EdgeIdentity<L>> instance(new EdgeIdentity<L>());
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/******************************************************************************
* Copyright (c) 2019 Philipp Schubert, Richard Leer, and Florian Sattler.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of LICENSE.txt.
*
* Contributors:
* Philipp Schubert and others
*****************************************************************************/

#ifndef PHASAR_PHASARLLVM_IFDSIDE_PROBLEMS_IDEINSTINTERACTIONALYSIS_H_
#define PHASAR_PHASARLLVM_IFDSIDE_PROBLEMS_IDEINSTINTERACTIONALYSIS_H_

#include <functional>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>

#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IDETabulationProblem.h>
#include <phasar/Utils/BitVectorSet.h>

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

namespace psr {

class LLVMBasedICFG;
class LLVMTypeHierarchy;
class LLVMPointsToInfo;

class IDEInstInteractionAnalysis
: public IDETabulationProblem<const llvm::Instruction *,
const llvm::Value *, const llvm::Function *,
const llvm::StructType *, const llvm::Value *,
BitVectorSet<std::string>, LLVMBasedICFG> {
public:
typedef const llvm::Value *d_t;
typedef const llvm::Instruction *n_t;
typedef const llvm::Function *m_t;
typedef const llvm::StructType *t_t;
typedef const llvm::Value *v_t;
typedef BitVectorSet<std::string> l_t;
typedef LLVMBasedICFG i_t;

private:
std::function<std::set<d_t>(n_t)> FactGen;

public:
IDEInstInteractionAnalysis(const ProjectIRDB *IRDB,
const LLVMTypeHierarchy *TH,
const LLVMBasedICFG *ICF,
const LLVMPointsToInfo *PT,
std::set<std::string> EntryPoints = {"main"});

virtual ~IDEInstInteractionAnalysis() = default;

// offer a special hook to the usr that allows to generate facts on-the-fly

void
registerFlowFactGenerator(std::function<std::set<d_t>(n_t)> FactGenerator);

// start formulating our analysis by specifying the parts required for IFDS

std::shared_ptr<FlowFunction<d_t>> getNormalFlowFunction(n_t curr,
n_t succ) override;

std::shared_ptr<FlowFunction<d_t>> getCallFlowFunction(n_t callStmt,
m_t destMthd) override;

std::shared_ptr<FlowFunction<d_t>> getRetFlowFunction(n_t callSite,
m_t calleeMthd,
n_t exitStmt,
n_t retSite) override;

std::shared_ptr<FlowFunction<d_t>>
getCallToRetFlowFunction(n_t callSite, n_t retSite,
std::set<m_t> callees) override;

std::shared_ptr<FlowFunction<d_t>>
getSummaryFlowFunction(n_t callStmt, m_t destMthd) override;

std::map<n_t, std::set<d_t>> initialSeeds() override;

d_t createZeroValue() const override;

bool isZeroValue(d_t d) const override;

// in addition provide specifications for the IDE parts

std::shared_ptr<EdgeFunction<l_t>>
getNormalEdgeFunction(n_t curr, d_t currNode, n_t succ,
d_t succNode) override;

std::shared_ptr<EdgeFunction<l_t>> getCallEdgeFunction(n_t callStmt,
d_t srcNode,
m_t destinationMethod,
d_t destNode) override;

std::shared_ptr<EdgeFunction<l_t>>
getReturnEdgeFunction(n_t callSite, m_t calleeMethod, n_t exitStmt,
d_t exitNode, n_t reSite, d_t retNode) override;

std::shared_ptr<EdgeFunction<l_t>>
getCallToRetEdgeFunction(n_t callSite, d_t callNode, n_t retSite,
d_t retSiteNode, std::set<m_t> callees) override;

std::shared_ptr<EdgeFunction<l_t>>
getSummaryEdgeFunction(n_t callSite, d_t callNode, n_t retSite,
d_t retSiteNode) override;

l_t topElement() override;

l_t bottomElement() override;

l_t join(l_t lhs, l_t rhs) override;

std::shared_ptr<EdgeFunction<l_t>> allTopFunction() override;

void printNode(std::ostream &os, n_t n) const override;

void printDataFlowFact(std::ostream &os, d_t d) const override;

void printMethod(std::ostream &os, m_t m) const override;

void printEdgeFact(std::ostream &os, l_t l) const override;
};

} // namespace psr

#endif
Loading

0 comments on commit d27f060

Please sign in to comment.