Better solution for intersection of multiple sets? #2396
-
Hi, I want to implement Available Expression Analysis in doop at Basic Block level, which requires to calculate the intersection of multiple branches.
at stmt both branches have met and a+b is available since the expression is computed on all incoming paths. What I want is an approach how to (better) implement IntersectionOfPred(), which is used to find common expressions if there is more than one Predecessor.
One difficulty is that any amount of branches can join at a program point, so I need a solution that finds the intersection of all incoming branches. First Approach: Find all expressions that are not in ALL Predecessors, and then negate the set:
Second approach: Counting the number of equivalent expressions & compare it to the number of predecessors
Third approach: pairwise intersection with help of string concatenation to keep track which predecessor expression were joined already:
This approach works but it feels clumsy and I am wondering if you can suggest a better way. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The simple way to achieve this in your case would be to enforce that each node has at most Another solution would be to use user-defined aggregates (#2282). The semantics checkers is currently not very strict about them and you might be able to call user-defined aggregates in a recursive relation. Last solution, not available yet, would be recursive aggregates (#2263). |
Beta Was this translation helpful? Give feedback.
-
With the recent introduction of See #2438 |
Beta Was this translation helpful? Give feedback.
The simple way to achieve this in your case would be to enforce that each node has at most
N
predecessors, then write the intersection rules to mergeN
branches,N-1
branches ...1
branch. WithN=2
being a good choice, you only need a rule for2
branches intersection and1
branch intersection (trivial).Another solution would be to use user-defined aggregates (#2282). The semantics checkers is currently not very strict about them and you might be able to call user-defined aggregates in a recursive relation.
Last solution, not available yet, would be recursive aggregates (#2263).