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

Make Compose and Join optional in EdgeFunction #736

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
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
74 changes: 53 additions & 21 deletions include/phasar/DataFlow/IfdsIde/EdgeFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "phasar/DataFlow/IfdsIde/EdgeFunctionSingletonCache.h"
#include "phasar/Utils/ByRef.h"
#include "phasar/Utils/ErrorFwd.h"
#include "phasar/Utils/TypeTraits.h"

#include "llvm/ADT/DenseMapInfo.h"
Expand Down Expand Up @@ -41,28 +42,48 @@ template <typename T, typename = void>
struct IsEdgeFunction : std::false_type {};
template <typename T>
struct IsEdgeFunction<
T, std::void_t<
typename T::l_t,
decltype(std::declval<const T &>().computeTarget(
std::declval<typename T::l_t>())),
decltype(T::compose(std::declval<EdgeFunctionRef<T>>(),
std::declval<EdgeFunction<typename T::l_t>>())),
decltype(T::join(std::declval<EdgeFunctionRef<T>>(),
std::declval<EdgeFunction<typename T::l_t>>()))>>
T, std::void_t<typename T::l_t,
decltype(std::declval<const T &>().computeTarget(
std::declval<typename T::l_t>()))>> : std::true_type {};

template <typename T, typename = void> struct HasEFCompose : std::false_type {};
template <typename T>
struct HasEFCompose<T, std::void_t<decltype(T::compose(
std::declval<EdgeFunctionRef<T>>(),
std::declval<EdgeFunction<typename T::l_t>>()))>>
: std::true_type {};

template <typename T, typename = void> struct HasEFJoin : std::false_type {};
template <typename T>
struct HasEFJoin<T, std::void_t<decltype(T::join(
std::declval<EdgeFunctionRef<T>>(),
std::declval<EdgeFunction<typename T::l_t>>()))>>
: std::true_type {};
} // namespace detail
template <typename T>
static constexpr bool IsEdgeFunction = detail::IsEdgeFunction<T>::value;
template <typename T>
static constexpr bool HasEFCompose = detail::HasEFCompose<T>::value;
template <typename T>
static constexpr bool HasEFJoin = detail::HasEFJoin<T>::value;

#else
// clang-format off
template <typename T>
concept IsEdgeFunction = requires(const T &EF, const EdgeFunction<typename T::l_t>& TEEF, EdgeFunctionRef<T> CEF, typename T::l_t Src) {
concept IsEdgeFunction = requires(const T &EF, typename T::l_t Src) {
typename T::l_t;
{EF.computeTarget(Src)} -> std::convertible_to<typename T::l_t>;
{T::compose(CEF, TEEF)} -> std::same_as<EdgeFunction<typename T::l_t>>;
{T::join(CEF, TEEF)} -> std::same_as<EdgeFunction<typename T::l_t>>;
};

template <typename T>
concept HasEFCompose = requires(EdgeFunctionRef<T> EFRef,
const EdgeFunction<typename T::l_t> &EF) {
{ T::compose(EFRef, EF) } -> std::convertible_to<EdgeFunction<T::l_t>>;
};
template <typename T>
concept HasEFJoin = requires(EdgeFunctionRef<T> EFRef,
const EdgeFunction<typename T::l_t> &EF) {
{ T::join(EFRef, EF) } -> std::convertible_to<EdgeFunction<T::l_t>>;
};
// clang-format on

Expand Down Expand Up @@ -700,17 +721,28 @@ class [[clang::trivial_abi]] EdgeFunction final : EdgeFunctionBase {
return getPtr<ConcreteEF>(EF)->computeTarget(Source);
},
[](const void *EF, const EdgeFunction &SecondEF,
AllocationPolicy Policy) {
return ConcreteEF::compose(
EdgeFunctionRef<ConcreteEF>(
EF, Policy == AllocationPolicy::CustomHeapAllocated),
SecondEF);
AllocationPolicy Policy) -> EdgeFunction {
if constexpr (HasEFCompose<ConcreteEF>) {
return ConcreteEF::compose(
EdgeFunctionRef<ConcreteEF>(
EF, Policy == AllocationPolicy::CustomHeapAllocated),
SecondEF);
} else {
composeEFPureVirtualError(llvm::getTypeName<ConcreteEF>(),
llvm::getTypeName<l_t>());
}
},
[](const void *EF, const EdgeFunction &OtherEF, AllocationPolicy Policy) {
return ConcreteEF::join(
EdgeFunctionRef<ConcreteEF>(
EF, Policy == AllocationPolicy::CustomHeapAllocated),
OtherEF);
[](const void *EF, const EdgeFunction &OtherEF,
AllocationPolicy Policy) -> EdgeFunction {
if constexpr (HasEFJoin<ConcreteEF>) {
return ConcreteEF::join(
EdgeFunctionRef<ConcreteEF>(
EF, Policy == AllocationPolicy::CustomHeapAllocated),
OtherEF);
} else {
joinEFPureVirtualError(llvm::getTypeName<ConcreteEF>(),
llvm::getTypeName<l_t>());
}
},
[](const void *EF1, const void *EF2) noexcept {
static_assert(IsEqualityComparable<ConcreteEF> ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,17 +950,6 @@ class IDEInstInteractionAnalysisT

l_t computeTarget(ByConstRef<l_t> /* Src */) const { return Replacement; }

static EdgeFunction<l_t>
compose(EdgeFunctionRef<IIAAKillOrReplaceEF> /*This*/,
const EdgeFunction<l_t> /*SecondFunction*/) {
llvm::report_fatal_error("Implemented in 'extend'");
}

static EdgeFunction<l_t> join(EdgeFunctionRef<IIAAKillOrReplaceEF> /*This*/,
const EdgeFunction<l_t> & /*OtherFunction*/) {
llvm::report_fatal_error("Implemented in 'combine'");
}

bool operator==(const IIAAKillOrReplaceEF &Other) const noexcept {
return Replacement == Other.Replacement;
}
Expand Down Expand Up @@ -1001,17 +990,6 @@ class IDEInstInteractionAnalysisT
return IDEInstInteractionAnalysisT::joinImpl(Src, Data);
}

static EdgeFunction<l_t>
compose(EdgeFunctionRef<IIAAAddLabelsEF> /*This*/,
const EdgeFunction<l_t> & /*SecondFunction*/) {
llvm::report_fatal_error("Implemented in 'extend'");
}

static EdgeFunction<l_t> join(EdgeFunctionRef<IIAAAddLabelsEF> /*This*/,
const EdgeFunction<l_t> & /*OtherFunction*/) {
llvm::report_fatal_error("Implemented in 'combine'");
}

bool operator==(const IIAAAddLabelsEF &Other) const noexcept {
return Data == Other.Data;
}
Expand Down
22 changes: 22 additions & 0 deletions include/phasar/Utils/ErrorFwd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/******************************************************************************
* Copyright (c) 2024 Fabian Schiebel.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of LICENSE.txt.
*
* Contributors:
* Fabian Schiebel and others
*****************************************************************************/

#ifndef PHASAR_UTILS_ERRORFWD_H
#define PHASAR_UTILS_ERRORFWD_H

#include "llvm/ADT/StringRef.h"

namespace psr {
[[noreturn, gnu::cold]] void
composeEFPureVirtualError(llvm::StringRef ConcreteEF, llvm::StringRef L);
[[noreturn, gnu::cold]] void joinEFPureVirtualError(llvm::StringRef ConcreteEF,
llvm::StringRef L);
} // namespace psr

#endif // PHASAR_UTILS_ERRORFWD_H
26 changes: 26 additions & 0 deletions lib/Utils/ErrorFwd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "phasar/Utils/ErrorFwd.h"

#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"

void psr::composeEFPureVirtualError(llvm::StringRef ConcreteEF,
llvm::StringRef L) {
llvm::report_fatal_error(
"EdgeFunction composition is not implemented for " + ConcreteEF +
"; Either implement static EdgeFunction<" + L +
"> compose(const EdgeFunctionRef<" + ConcreteEF +
">, const EdgeFunction<" + L + ">&) in " + ConcreteEF +
", or override EdgeFunction<" + L + "> extend(const EdgeFunction<" + L +
">&, const EdgeFunction<" + L + ">&) in your IDETabulationProblem");
}

void psr::joinEFPureVirtualError(llvm::StringRef ConcreteEF,
llvm::StringRef L) {
llvm::report_fatal_error(
"EdgeFunction join is not implemented for " + ConcreteEF +
"; Either implement static EdgeFunction<" + L +
"> join(const EdgeFunctionRef<" + ConcreteEF + ">, const EdgeFunction<" +
L + ">&) in " + ConcreteEF + ", or override EdgeFunction<" + L +
"> combine(const EdgeFunction<" + L + ">&, const EdgeFunction<" + L +
">&) in your IDETabulationProblem");
}
Loading