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

Fix Backward ICFG #660

Merged
merged 8 commits into from
Sep 21, 2023
16 changes: 5 additions & 11 deletions include/phasar/ControlFlow/ICFGBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,7 @@ template <typename Derived> class ICFGBase {
n_t>);
return self().getReturnSitesOfCallAtImpl(Inst);
}
/// Returns an iterable range of all global initializer functions
[[nodiscard]] decltype(auto)
getGlobalInitializers(ByConstRef<f_t> Fun) const {
static_assert(
is_iterable_over_v<decltype(self().getGlobalInitializersImpl(Fun)),
f_t>);
return self().getGlobalInitializersImpl(Fun);
}

/// Prints the underlying call-graph as DOT to the given output-stream
void print(llvm::raw_ostream &OS = llvm::outs()) const {
self().printImpl(OS);
Expand All @@ -128,9 +121,10 @@ template <typename Derived> class ICFGBase {
/// from the given analysis-Domain
template <typename ICF, typename Domain>
// NOLINTNEXTLINE(readability-identifier-naming)
constexpr bool is_icfg_v = is_crtp_base_of_v<ICFGBase, ICF>
&&std::is_same_v<typename ICF::n_t, typename Domain::n_t>
&&std::is_same_v<typename ICF::f_t, typename Domain::f_t>;
constexpr bool is_icfg_v =
is_crtp_base_of_v<ICFGBase, ICF> &&
std::is_same_v<typename ICF::n_t, typename Domain::n_t> &&
std::is_same_v<typename ICF::f_t, typename Domain::f_t>;
fabianbs96 marked this conversation as resolved.
Show resolved Hide resolved

} // namespace psr

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
namespace psr {

class LLVMBasedICFG;
class LLVMBasedBackwardICFG;
template <typename N, typename F> class CallGraph;

template <>
struct CFGTraits<LLVMBasedBackwardICFG> : CFGTraits<LLVMBasedBackwardCFG> {};

class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG,
public ICFGBase<LLVMBasedBackwardCFG> {
public ICFGBase<LLVMBasedBackwardICFG> {
friend ICFGBase;

class LLVMBackwardRet {
Expand Down Expand Up @@ -60,6 +65,7 @@ class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG,
getReturnSitesOfCallAtImpl(n_t Inst) const;
void printImpl(llvm::raw_ostream &OS) const;
[[nodiscard]] nlohmann::json getAsJsonImpl() const;
[[nodiscard]] const CallGraph<n_t, f_t> &getCallGraphImpl() const noexcept;

llvm::LLVMContext BackwardRetsCtx;
llvm::DenseMap<const llvm::Function *, LLVMBackwardRet> BackwardRets;
Expand All @@ -68,6 +74,8 @@ class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG,

LLVMBasedICFG *ForwardICFG{};
};

extern template class ICFGBase<LLVMBasedBackwardICFG>;
} // namespace psr

#endif
2 changes: 2 additions & 0 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
LLVMProjectIRDB *IRDB = nullptr;
MaybeUniquePtr<LLVMTypeHierarchy, true> TH;
};

extern template class ICFGBase<LLVMBasedICFG>;
} // namespace psr

#endif
9 changes: 8 additions & 1 deletion lib/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h"

#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h"
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"

namespace psr {
Expand Down Expand Up @@ -68,4 +67,12 @@ void LLVMBasedBackwardICFG::printImpl(llvm::raw_ostream &OS) const {
nlohmann::json LLVMBasedBackwardICFG::getAsJsonImpl() const {
return ForwardICFG->getAsJson();
}

auto LLVMBasedBackwardICFG::getCallGraphImpl() const noexcept
-> const CallGraph<n_t, f_t> & {
return ForwardICFG->getCallGraph();
}

template class ICFGBase<LLVMBasedBackwardICFG>;

} // namespace psr
2 changes: 2 additions & 0 deletions lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,6 @@ void LLVMBasedICFG::printImpl(llvm::raw_ostream &OS) const {
[this](n_t Inst) { return IRDB->getInstructionId(Inst); });
}

template class ICFGBase<LLVMBasedICFG>;

} // namespace psr
Loading