CD edges from entry to a function's first node/instruction
https://github.com/mchalupa/dg/blob/bf49092212fbbb0b02f25f8f0f330854dc8d9bbd/lib/llvm/LLVMDependenceGraph.cpp#L771
Can anyone explain the rationale on constructing this CD edge? Or more specifically, why not adding CD edges from a function's entry to each of the function's other nodes? Consider the following example,
void foo(int* a) {
bar(); // perform some operations that are not relevant to the following loop
while (*a <0)
*a++;
}
int main () {
int a = -100;
if (a < 0) {
foo(&a);
}
return 0;
}
The entire foo(int*) is supposed to be control dependent on the if statement, including the while loop, but adding a CD edge from the entry of foo(int*) only to its first node seems unable to catch such dependency, especially when the first node has no control/data dependencies with the function's other nodes (say, calling bar()).
Thanks in advance for helping with my confusion!
Another thing that confuses me a little is the comment in Line 770: https://github.com/mchalupa/dg/blob/bf49092212fbbb0b02f25f8f0f330854dc8d9bbd/lib/llvm/LLVMDependenceGraph.cpp#L770-L771 Isn't it a control dependency edge to be added?
It is hard to remember, this is one of the oldest parts of DG (the comment is not very helpful with this, shame on me...).
I think this edge is there only as a hack so that there is some connection between the entry point of the function and the first instruction while dumping the graph to dot (don't ask me why we just don't dump this edge instead of adding it :). It should not affect slicing the program as the slice() method adds the entry node into the slice whenever some instruction (or basic block) is marked to be in the slice. But to answer your question, to have a proper dependence graph, we should have a dependence edge from entry to bar() and while.
In fact, we're slowly moving from this code to a new code that implements proper SDGs that should not have this problem. We are almost there, but some pieces are still missing.
To the other question: yes, it should be CD, not CFG