Skip to content

Commit

Permalink
Merge branch 'f-AdvancedIIATesting' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
pdschubert committed May 6, 2021
2 parents a0bbc5e + 429cd62 commit 983d713
Show file tree
Hide file tree
Showing 10 changed files with 959 additions and 420 deletions.
95 changes: 67 additions & 28 deletions include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/FlowFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,8 @@ class Kill : public FlowFunction<D, Container> {
D killValue;
};

/**
* @brief Kills all facts for which the given predicate evaluates to true.
* @tparam D The type of data-flow facts to be killed.
*/
/// \brief Kills all facts for which the given predicate evaluates to true.
/// \tparam D The type of data-flow facts to be killed.
template <typename D, typename Container = std::set<D>>
class KillIf : public FlowFunction<D, Container> {
public:
Expand Down Expand Up @@ -302,6 +300,54 @@ class KillAll : public FlowFunction<D, Container> {
KillAll() = default;
};

//===----------------------------------------------------------------------===//
// Gen-and-kill flow functions

template <typename D, typename Container = std::set<D>>
class GenAndKillAllOthers : public FlowFunction<D, Container> {
public:
using typename FlowFunction<D, Container>::container_type;

GenAndKillAllOthers(D genValue, D zeroValue)
: genValue(genValue), zeroValue(zeroValue) {}
virtual ~GenAndKillAllOthers() = default;
container_type computeTargets(D source) override {
if (source == zeroValue) {
return {zeroValue, genValue};
}
return {};
}

private:
D genValue;
D zeroValue;
};

template <typename D, typename Container = std::set<D>>
class GenAllAndKillAllOthers : public FlowFunction<D, Container> {
public:
using typename FlowFunction<D, Container>::container_type;

GenAllAndKillAllOthers(container_type genValues, D zeroValue)
: genValues(genValues), zeroValue(zeroValue) {}
virtual ~GenAllAndKillAllOthers() = default;
container_type computeTargets(D source) override {
if (source == zeroValue) {
genValues.insert(source);
return genValues;
} else {
return {};
}
}

protected:
container_type genValues;
D zeroValue;
};

//===----------------------------------------------------------------------===//
// Miscellaneous flow functions

template <typename D, typename Container = std::set<D>>
class Transfer : public FlowFunction<D, Container> {
public:
Expand All @@ -327,38 +373,31 @@ class Transfer : public FlowFunction<D, Container> {
template <typename D, typename Container = std::set<D>>
class Union : public FlowFunction<D, Container> {
public:
using typename FlowFunction<D, Container>::container_type;
using typename FlowFunction<D, Container>::FlowFunctionType;
using typename FlowFunction<D, Container>::FlowFunctionPtrType;

using typename FlowFunction<D, Container>::container_type;

Union(const std::vector<FlowFunctionType> &funcs) : funcs(funcs) {}
Union(const std::vector<FlowFunctionPtrType> &FlowFuncs)
: FlowFuncs([&FlowFuncs]() {
if (FlowFuncs.empty()) {
return std::vector<FlowFunctionPtrType>(
{Identity<D, Container>::getInstance()});
} else {
return FlowFuncs;
}
}()) {}
virtual ~Union() = default;
container_type computeTargets(const D &source) override {
container_type result;
for (const FlowFunctionType &func : funcs) {
container_type target = func.computeTarget(source);
result.insert(target.begin(), target.end());
}
return result;
}
static FlowFunctionType setunion(const std::vector<FlowFunctionType> &funcs) {
std::vector<FlowFunctionType> vec;
for (const FlowFunctionType &func : funcs) {
if (func != Identity<D, Container>::getInstance()) {
vec.add(func);
}
}
if (vec.size() == 1) {
return vec[0];
} else if (vec.empty()) {
return Identity<D, Container>::getInstance();
container_type computeTargets(D source) override {
container_type Result;
for (const auto &FlowFunc : FlowFuncs) {
container_type target = FlowFunc->computeTargets(source);
Result.insert(target.begin(), target.end());
}
return Union(vec);
return Result;
}

protected:
const std::vector<FlowFunctionType> funcs;
const std::vector<FlowFunctionPtrType> FlowFuncs;
};

template <typename D, typename Container = std::set<D>>
Expand Down
Loading

0 comments on commit 983d713

Please sign in to comment.