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

EF SemiRing in Problem #722

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open

Conversation

fabianbs96
Copy link
Member

@fabianbs96 fabianbs96 commented May 5, 2024

Edge functions model a bounded idempotent semi-ring.
Thereby, the extend-operation is represented as composeWith and the combine-operation as joinWith.
The fixed interface of these functions makes handling dependent resources hard, especially caching edge functions.

This PR creates the option to implement extend and combine on the IDETabulationProblem instead, making it easy to access members of the problem instance.
The PR also applies this concept to the inst-interation analysis, to show how EF caching can look like.

@fabianbs96 fabianbs96 self-assigned this May 5, 2024
@fabianbs96 fabianbs96 added the enhancement New feature or request label May 5, 2024
Copy link
Collaborator

@vulder vulder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

Did you run a test benchmark how this impact the analysis time?

#include "phasar/DataFlow/IfdsIde/EdgeFunction.h"

namespace psr {
template <typename AnalysisDomainTy> class SemiRing {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, as the IDESolver is already specialized on the AnalysisDomainTy, could it make sense to implement the SemiRing structure as a trait and not on the ide/ifds problem itself.

Question: Is the implementation of combine/extend usually/always problem specific or is it in general specific for a given AnalysisDomainTy.

Why do I ask? Well, one would model the interface around a trait, the IDESolver would get around the virtual function call to extend/combine.

Example:

...
template<>
class SemiRing<MyAnalysisDomain> {
  static EdgeFunction<l_t> extend(const EdgeFunction<l_t> &L,
                                                       const EdgeFunction<l_t> &R) {
    ...
  }
}

class IDESolver {
  void foo() {
    ...
    auto res = SemiRing<AnalysisDomainTy>::extend(L, R);
    ...
  }
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't benchmarked the new implementation, but I like your idea with separating the semi ring from the problem.
However, we cannot implement the trait functions as static as the main reason for this PR is to make the integration of edge-function caching easier. Still, we can get rid of the additional virtual call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one problem, though: The edge-function factories within the IDE problem need the edge-function cache, as well as the extend and combine functions need it.
So, it is actually easier to have these both functions as members within the IDE problem; or do you have an idea, how to workaround this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can the function not be static for the cache? The cache state could be part of the IDE solver and in case of a miss call the static impl. but in the end, solve it as you like it best^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, the edge functions should be specific to the problem. Two problems might accidentially have the same domain, but want to handle edge functions differently.

The idea of having the cache in the solver sounds interesting, but probably too much for this PR.

include/phasar/Utils/BitVectorSet.h Outdated Show resolved Hide resolved
static EdgeFunction<l_t>
compose(EdgeFunctionRef<IIAAAddLabelsEF> /*This*/,
const EdgeFunction<l_t> & /*SecondFunction*/) {
llvm::report_fatal_error("Implemented in 'extend'");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this left for legacy reasons?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the EdgeFunction interface requires compose and join to be implemented. The default implementation of the semi-ring methods also assumes these functions to be implemented. We may want to make them optional at some point

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they not strictly required, disabling them would be a option, otherwise this could crash at some point.

@fabianbs96
Copy link
Member Author

Small update: I have run the IIA on some smaller coreutils and at least there I could not detect any performance impact

#include "phasar/DataFlow/IfdsIde/EdgeFunction.h"

namespace psr {
template <typename AnalysisDomainTy> class SemiRing {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, the edge functions should be specific to the problem. Two problems might accidentially have the same domain, but want to handle edge functions differently.

The idea of having the cache in the solver sounds interesting, but probably too much for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants