Question about Built-in DDG(data dependency graph) implementation

Hi All,

I appreciate any help in advance.

I am new to LLVM, and I have been trying to use the built-in implementation of DDG in LLVM to analyze programs better.

I tried the example shown on the official website. It worked smoothly, and I got a perfect DDG dot file, but it didn’t work for another program, an example used in WIKI to illustrate flow dependency, seeing the details below.

the example showing in the official website:
for(int i = 1; i < n; i++){
        b[i] = c[i] + b[i-1];
}

the example  about flow dependency
int main(){
        int a = 3;
        int b = a;
        int c = b;
        return 0;
}

clang -c -03 -emit-llvm test.c -o test.bc
opt -passes=dot-ddg test.bc

Nothing showed up after executing the above commands, but they did work for the example 1.

I am looking forward to your help.

Hi,

I think as you have used -O3 with clang the whole code should have been optimized away

Regards,
Raghesh

Hi Raghesh,

I am confused about the flag, “-O3” because if I don’t compile my program with it, the built-in pass DDG-dot won’t work.

Thanks,
Zsh

Hi Zsh,

When we don’t use -O3, I think clang would choose -O0 by default and it would attach the ‘optnone’ attribute in the resulting IR. Then -dot-ddg won’t be invoked. I guess this is happening in your case. You may edit the resulting IR and remove all the ‘optnone’ attributes and give a try.

An alternative is to use the following combination of flags along with clang.

clang -O2 -Xclang -disable-llvm-passes -emit-llvm test.c -o test.bc

This avoids generation of ‘optnone’. Though O2 is mentioned, its passes are suppressed by ‘disable-llvm-passes’.

Please note the following too. Your second example does not have a loop. Following is the description of -dot-ddg from the source.

//===----------------------------------------------------------------------===//
//
// This file defines the -dot-ddg analysis pass, which emits DDG in DOT format
// in a file named ddg.<graph-name>.dot for each loop in a function.
//===----------------------------------------------------------------------===//

So dot graph won’t be printed if you do not have a loop.

Regards,
Raghesh