mchalupa / dg

[LLVM Static Slicer] Various program analyses, construction of dependence graphs and program slicing of LLVM bitcode.
MIT License
474 stars 131 forks source link

Is data-dependence analysis driven by self-defined pointer analysis or SVF? #451

Open for-just-we opened 1 year ago

for-just-we commented 1 year ago

Hi, author. I try to integrate dg into other project and when I use data-dependence analysis. I found not like llvm-cda-dump.cpp, in llvm-dda-dump, there seems to be no code for leveraging SVF pointer analysis. So is there support for SVF in data-dependence analysis?

mchalupa commented 1 year ago

DG can use SVF for points-to analysis and this then propagates to data dependence analysis. If you want to use the value-flow analysis from SVF, you must do that directly via SVF API.

mchalupa commented 1 year ago

To answer the question from the title: both, depends on the options you pass on the command line (and if you compile DG with SVF support).

for-just-we commented 1 year ago

data

DG can use SVF for points-to analysis and this then propagates to data dependence analysis. If you want to use the value-flow analysis from SVF, you must do that directly via SVF API.

So I just simply need to replace DGLLVMPointerAnalysis with SVFPointerAnalysis?

mchalupa commented 1 year ago

Yes, that should do the trick, check this code: https://github.com/mchalupa/dg/blob/master/tools/llvm-pta-dump.cpp#L816

for-just-we commented 1 year ago

Yes, that should do the trick, check this code: https://github.com/mchalupa/dg/blob/master/tools/llvm-pta-dump.cpp#L816

ok, and I want to map instructions in a bc file to the instructions they depend on. So the code for data dependence analysis is

LLVMDataDependenceAnalysis DDA(M.get(), &PTA, options.dgOptions.DDAOptions);
DDA.run();
auto *SSA = static_cast<MemorySSATransformation *>(
                DDA->getDDA()->getImpl());
SSA->computeAllDefinitions();

right?

mchalupa commented 1 year ago

This part is important:

LLVMDataDependenceAnalysis DDA(M.get(), &PTA, options.dgOptions.DDAOptions);
DDA.run();

Then you can query directly the DDA object for the definitions.

for-just-we commented 1 year ago

This part is important:

LLVMDataDependenceAnalysis DDA(M.get(), &PTA, options.dgOptions.DDAOptions);
DDA.run();

Then you can query directly the DDA object for the definitions.

So, this part

auto *SSA = static_cast<MemorySSATransformation *>(
                DDA->getDDA()->getImpl());
SSA->computeAllDefinitions();

is only optional? If I don't run SSA, would there be differences in the data dependence results?

mchalupa commented 1 year ago

SSA is run either way, but this code makes it to compute all the results immediately (otherwise they are computed on-demand upon querying DDA object) so that llvm-dda-dump can show dump all the results including some internal information obtained from the SSA object.

There should be no differences in the results if you omit this code.