Could I do some control-flow and dataflow analysis cross files and functions via IR

As mentioned in the title, I want to do some control-flow and dataflow analysis. I can only find the assignment statement in a function, but the assigned variable is just a parameter of this function.

For example,

Hi Shulin,

It seems to me what you’ll need is your own inter-procedural analysis to deal with data-flow between functions. That is, you’ll need to figure out the callgraph between all the functions and the dataflow inside all the functions. In this case, you’ll need to find where foo is called (probably multiple places), what are the use cases for all this callsites in the dataflow in foo’s parent function, and all the functions where the pointer a’s content could be modified. If there’re other pointers pointing to the same address a’s pointing to, you may also need pointer analysis, where things could get really tricky.

To deal with different IR files, you’ll either have to implement an LTO pass, or use llvm-link to link multiple IRs to a combined IR for analysis run it through your OPT pass like a regular IR.


Just note on this last aspect of the problem: I don’t see any fundamental reason a custom interprocedural-analysis can’t run over a call graph involving functions defined in multiple modules without linking them in a single IR. This is admittedly more involved though.