Skip to content
Merged
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 @@ -18,11 +18,11 @@ namespace psr {
struct AllBot {
using type = AllBottom<IDEGeneralizedLCA::l_t>;
static std::shared_ptr<type> getInstance();
static bool isBot(const EdgeFunction<IDEGeneralizedLCA::l_t> *edgeFn,
bool nonRec = false);
static bool isBot(const EdgeFunction<IDEGeneralizedLCA::l_t> *EdgeFn,
bool NonRec = false);
static bool
isBot(const std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> &edgeFn,
bool nonRec = false);
isBot(const std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> &EdgeFn,
bool NonRec = false);
};

} // namespace psr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ namespace psr {
class BinaryEdgeFunction
: public EdgeFunction<IDEGeneralizedLCA::l_t>,
public std::enable_shared_from_this<BinaryEdgeFunction> {
llvm::BinaryOperator::BinaryOps op;
const IDEGeneralizedLCA::l_t cnst;
bool leftConst;
size_t maxSize;
llvm::BinaryOperator::BinaryOps Op;
const IDEGeneralizedLCA::l_t Const;
bool LeftConst;
size_t MaxSize;

public:
BinaryEdgeFunction(llvm::BinaryOperator::BinaryOps op,
const IDEGeneralizedLCA::l_t &cnst, bool leftConst,
size_t maxSize)
: op(op), cnst(cnst), leftConst(leftConst), maxSize(maxSize) {}
BinaryEdgeFunction(llvm::BinaryOperator::BinaryOps Op,
const IDEGeneralizedLCA::l_t &Const, bool LeftConst,
size_t MaxSize)
: Op(Op), Const(Const), LeftConst(LeftConst), MaxSize(MaxSize) {}

IDEGeneralizedLCA::l_t computeTarget(IDEGeneralizedLCA::l_t source) override;
IDEGeneralizedLCA::l_t computeTarget(IDEGeneralizedLCA::l_t Source) override;

std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> composeWith(
std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> secondFunction)
std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> SecondFunction)
override;

std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>>
joinWith(std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> otherFunction)
joinWith(std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> OtherFunction)
override;

bool equal_to(std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> other)
bool equal_to(std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> Other)
const override;

void print(std::ostream &OS, bool isForDebug = false) const override;
void print(std::ostream &OS, bool IsForDebug = false) const override;
};

} // namespace psr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,122 +1,125 @@
/******************************************************************************
* 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, Alexander Meinhold and others
*****************************************************************************/

#ifndef PHASAR_PHASARLLVM_DATAFLOWSOLVER_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H
#define PHASAR_PHASARLLVM_DATAFLOWSOLVER_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H

#include <iostream>
#include <memory>
#include <unordered_set>
#include <variant>

#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Instructions.h"

namespace psr {

enum class Ordering { Less, Greater, Equal, Incomparable };

class EdgeValue {
public:
enum Type { Top, Integer, String, FloatingPoint };

private:
std::variant<llvm::APInt, llvm::APFloat, std::string, std::nullptr_t> value =
nullptr;
Type type;

public:
EdgeValue(const llvm::Value *val);
EdgeValue(const EdgeValue &ev);
EdgeValue(llvm::APInt &&vi);
EdgeValue(const llvm::APInt &vi);
EdgeValue(llvm::APFloat &&vf);
EdgeValue(long long vi);
EdgeValue(int vi);
EdgeValue(double d);
EdgeValue(float d);
EdgeValue(std::string &&vs);
EdgeValue(std::nullptr_t);
~EdgeValue();
const static EdgeValue top;
[[nodiscard]] bool tryGetInt(uint64_t &Res) const;
[[nodiscard]] bool tryGetFP(double &Res) const;
[[nodiscard]] bool tryGetString(std::string &Res) const;
[[nodiscard]] bool isTop() const;
[[nodiscard]] bool isNumeric() const;
[[nodiscard]] bool isString() const;
[[nodiscard]] Type getKind() const;
// std::unique_ptr<ObjectLLVM> asObjLLVM(llvm::LLVMContext &ctx) const;
bool sqSubsetEq(const EdgeValue &other) const;
EdgeValue performBinOp(llvm::BinaryOperator::BinaryOps op,
const EdgeValue &other) const;
EdgeValue typecast(Type dest, unsigned bits) const;
EdgeValue &operator=(const EdgeValue &ev);

operator bool();
friend bool operator==(const EdgeValue &v1, const EdgeValue &v2);

// binary operators
friend EdgeValue operator+(const EdgeValue &v1, const EdgeValue &v2);
friend EdgeValue operator-(const EdgeValue &v1, const EdgeValue &v2);
friend EdgeValue operator*(const EdgeValue &v1, const EdgeValue &v2);
friend EdgeValue operator/(const EdgeValue &v1, const EdgeValue &v2);
friend EdgeValue operator%(const EdgeValue &v1, const EdgeValue &v2);
friend EdgeValue operator&(const EdgeValue &v1, const EdgeValue &v2);
friend EdgeValue operator|(const EdgeValue &v1, const EdgeValue &v2);
friend EdgeValue operator^(const EdgeValue &v1, const EdgeValue &v2);
friend EdgeValue operator<<(const EdgeValue &v1, const EdgeValue &v2);
friend EdgeValue operator>>(const EdgeValue &v1, const EdgeValue &v2);
static int compare(const EdgeValue &v1, const EdgeValue &v2);

// unary operators
EdgeValue operator-() const;
EdgeValue operator~() const;
friend std::ostream &operator<<(std::ostream &os, const EdgeValue &ev);
static std::string typeToString(Type ty);
};
class EdgeValueSet;
using ev_t = EdgeValueSet;

ev_t performBinOp(llvm::BinaryOperator::BinaryOps op, const ev_t &v1,
const ev_t &v2, size_t maxSize);
ev_t performTypecast(const ev_t &ev, EdgeValue::Type dest, unsigned bits);
Ordering compare(const ev_t &v1, const ev_t &v2);
ev_t join(const ev_t &v1, const ev_t &v2, size_t maxSize);
/// \brief implements square subset equal
bool operator<(const ev_t &v1, const ev_t &v2);
bool isTopValue(const ev_t &v);
std::ostream &operator<<(std::ostream &os, const ev_t &v);

} // namespace psr

namespace std {

template <> struct hash<psr::EdgeValue> {
hash() {}
size_t operator()(const psr::EdgeValue &val) const {
auto hc = hash<int>()(val.getKind());
uint64_t asInt;
double asFloat;
string asString;
if (val.tryGetInt(asInt))
return hash<uint64_t>()(asInt) * 31 + hc;
else if (val.tryGetFP(asFloat))
return hash<double>()(round(asFloat)) * 31 + hc;
else if (val.tryGetString(asString))
return hash<string>()(asString) * 31 + hc;
return hc;
}
};

} // namespace std

#endif
/******************************************************************************
* 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, Alexander Meinhold and others
*****************************************************************************/

#ifndef PHASAR_PHASARLLVM_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H_
#define PHASAR_PHASARLLVM_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H_

#include <iostream>
#include <memory>
#include <unordered_set>
#include <variant>

#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Instructions.h"

namespace psr {

enum class Ordering { Less, Greater, Equal, Incomparable };

class EdgeValue {
public:
enum Type { Top, Integer, String, FloatingPoint };

private:
std::variant<llvm::APInt, llvm::APFloat, std::string, std::nullptr_t>
Comment thread
vulder marked this conversation as resolved.
ValVariant = nullptr;
Type VariantType;

public:
EdgeValue(const llvm::Value *Val);
EdgeValue(const EdgeValue &EV);
EdgeValue(llvm::APInt &&VI);
EdgeValue(const llvm::APInt &VI);
EdgeValue(llvm::APFloat &&VF);
EdgeValue(long long VI);
EdgeValue(int VI);
EdgeValue(double Double);
EdgeValue(float Float);
EdgeValue(std::string &&VS);
EdgeValue(std::nullptr_t);
~EdgeValue();
const static EdgeValue TopValue;
[[nodiscard]] bool tryGetInt(uint64_t &Res) const;
[[nodiscard]] bool tryGetFP(double &Res) const;
[[nodiscard]] bool tryGetString(std::string &Res) const;
[[nodiscard]] bool isTop() const;
[[nodiscard]] bool isNumeric() const;
[[nodiscard]] bool isString() const;
[[nodiscard]] Type getKind() const;
// std::unique_ptr<ObjectLLVM> asObjLLVM(llvm::LLVMContext &ctx) const;
[[nodiscard]] bool sqSubsetEq(const EdgeValue &Other) const;
[[nodiscard]] EdgeValue performBinOp(llvm::BinaryOperator::BinaryOps Op,
Comment thread
vulder marked this conversation as resolved.
const EdgeValue &Other) const;
[[nodiscard]] EdgeValue typecast(Type Dest, unsigned Bits) const;
EdgeValue &operator=(const EdgeValue &EV);

operator bool();
friend bool operator==(const EdgeValue &Lhs, const EdgeValue &Rhs);

// binary operators
friend EdgeValue operator+(const EdgeValue &Lhs, const EdgeValue &Rhs);
friend EdgeValue operator-(const EdgeValue &Lhs, const EdgeValue &Rhs);
friend EdgeValue operator*(const EdgeValue &Lhs, const EdgeValue &Rhs);
friend EdgeValue operator/(const EdgeValue &Lhs, const EdgeValue &Rhs);
friend EdgeValue operator%(const EdgeValue &Lhs, const EdgeValue &Rhs);
friend EdgeValue operator&(const EdgeValue &Lhs, const EdgeValue &Rhs);
friend EdgeValue operator|(const EdgeValue &Lhs, const EdgeValue &Rhs);
friend EdgeValue operator^(const EdgeValue &Lhs, const EdgeValue &Rhs);
friend EdgeValue operator<<(const EdgeValue &Lhs, const EdgeValue &Rhs);
friend EdgeValue operator>>(const EdgeValue &Lhs, const EdgeValue &Rhs);
static int compare(const EdgeValue &Lhs, const EdgeValue &Rhs);

// unary operators
EdgeValue operator-() const;
EdgeValue operator~() const;
friend std::ostream &operator<<(std::ostream &Os, const EdgeValue &EV);
static std::string typeToString(Type Ty);
};
class EdgeValueSet;
typedef EdgeValueSet ev_t;

ev_t performBinOp(llvm::BinaryOperator::BinaryOps Op, const ev_t &Lhs,
const ev_t &Rhs, size_t MaxSize);
ev_t performTypecast(const ev_t &Ev, EdgeValue::Type Dest, unsigned Bits);
Ordering compare(const ev_t &Lhs, const ev_t &Rhs);
Comment thread
vulder marked this conversation as resolved.
ev_t join(const ev_t &Lhs, const ev_t &Rhs, size_t MaxSize);
/// \brief implements square subset equal
bool operator<(const ev_t &Lhs, const ev_t &Rhs);
bool isTopValue(const ev_t &Val);
std::ostream &operator<<(std::ostream &Os, const ev_t &Val);

} // namespace psr

namespace std {

template <> struct hash<psr::EdgeValue> {
hash() = default;
size_t operator()(const psr::EdgeValue &Val) const {
auto Hash = hash<int>()(Val.getKind());
uint64_t AsInt;
double AsFloat;
string AsString;
if (Val.tryGetInt(AsInt)) {
return hash<uint64_t>()(AsInt) * 31 + Hash;
}
Comment thread
vulder marked this conversation as resolved.
if (Val.tryGetFP(AsFloat)) {
return hash<double>()(round(AsFloat)) * 31 + Hash;
}
if (Val.tryGetString(AsString)) {
return hash<string>()(AsString) * 31 + Hash;
Comment thread
vulder marked this conversation as resolved.
}
return Hash;
}
};

} // namespace std

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@
namespace psr {

class EdgeValueSet {
std::unordered_set<EdgeValue> underlying;
std::unordered_set<EdgeValue> Underlying;

public:
EdgeValueSet();
template <typename Iter>
EdgeValueSet(Iter beg, Iter ed) : underlying(beg, ed) {}
EdgeValueSet(std::initializer_list<EdgeValue> ilist);
auto begin() -> decltype(underlying.begin());
auto end() -> decltype(underlying.end());
auto begin() const -> decltype(underlying.begin());
auto end() const -> decltype(underlying.end());
int count(const EdgeValue &ev) const;
auto find(const EdgeValue &ev) -> decltype(underlying.find(ev));
auto find(const EdgeValue &ev) const -> decltype(underlying.find(ev));
EdgeValueSet(Iter Begin, Iter End) : Underlying(Begin, End) {}
EdgeValueSet(std::initializer_list<EdgeValue> IList);
auto begin() -> decltype(Underlying.begin());
auto end() -> decltype(Underlying.end());
auto begin() const -> decltype(Underlying.begin());
auto end() const -> decltype(Underlying.end());
int count(const EdgeValue &EV) const;
auto find(const EdgeValue &EV) -> decltype(Underlying.find(EV));
auto find(const EdgeValue &EV) const -> decltype(Underlying.find(EV));

size_t size() const;
auto insert(const EdgeValue &ev) -> decltype(underlying.insert(ev));
auto insert(EdgeValue &&ev) -> decltype(underlying.insert(ev));
auto insert(const EdgeValue &EV) -> decltype(Underlying.insert(EV));
auto insert(EdgeValue &&EV) -> decltype(Underlying.insert(EV));
bool empty() const;
bool operator==(const EdgeValueSet &other) const;
bool operator!=(const EdgeValueSet &other) const;
bool operator==(const EdgeValueSet &Other) const;
bool operator!=(const EdgeValueSet &Other) const;
};

} // namespace psr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ namespace psr {

class GenConstant : public EdgeFunction<IDEGeneralizedLCA::l_t>,
public std::enable_shared_from_this<GenConstant> {
IDEGeneralizedLCA::l_t val;
size_t maxSize;
IDEGeneralizedLCA::l_t Val;
size_t MaxSize;

public:
GenConstant(const IDEGeneralizedLCA::l_t &val, size_t maxSize);
IDEGeneralizedLCA::l_t computeTarget(IDEGeneralizedLCA::l_t source) override;
GenConstant(const IDEGeneralizedLCA::l_t &Val, size_t MaxSize);
IDEGeneralizedLCA::l_t computeTarget(IDEGeneralizedLCA::l_t Source) override;

std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> composeWith(
std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> secondFunction)
std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> SecondFunction)
override;

std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>>
joinWith(std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> otherFunction)
joinWith(std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> OtherFunction)
override;

bool equal_to(std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> other)
bool equal_to(std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> Other)
const override;
void print(std::ostream &OS, bool isForDebug = false) const override;
void print(std::ostream &OS, bool IsForDebug = false) const override;
};

} // namespace psr
Expand Down
Loading