Given $n$ inputs and $k$ outputs and $j$ identical binary function calls to $g$, how many possible distinct single-assignment forms are there?
The only assumption made about $g$ is that if $a = c \wedge b = d$ then $g(a, b) = g(c,d)$.
Each SSA form consists of two parts. The first is a temporary assignment part:
t1 = g(_, _)
...
tj = g(_, _)
Where each _ can be any of the inputs $i_1$ through $i_n$ or a previously calculated $t_x$. After that follows an output assignment part:
o1 = _
...
ok = _
where _ can be $i_1$ through $i_n$ or $t_1$ through $t_j$, but not another $o_x$. The output of the SSA form is $(o_1, o_2, \dots, o_k)$.
Trivial counting doesn't work, because the following two SSA forms seem different, but are equivalent (with $n = 4$, $k = 1$, $j = 3$):
t1 = g(i1, i2) t1 = g(i3, i4)
t2 = g(i3, i4) t2 = g(i1, i2)
t3 = g(t1, t2) t3 = g(t2, t1)
o = t3 o = t3
Also this doesn't account for irrelevant changes that are still equivalent (with $n = 3, k = j = 1$):
t1 = g(i1, i2) t1 = g(i1, i3)
o = i1 o = i1
Questions:
What is $f(n, k, j)$, giving the number of distinct SSA forms?
Does there exist an efficient way of iterating over these SSA forms?
What if we also assume $g(a, b) = g(b, a)$?