Application of a path only along the execution path

I have a pass that parses the entire module (using runOnFunction() ). But I want to apply it on every path of execution. Along the way, I mean a sequence of instructions, starting from the point in the program (annotated from the beginning) to the point of completion of the program (annotated with the end).

I assume that I need to divide my module into functions by building CallGraph and then dividing each function into commands for building CFG-s in the nodes of the previous CallGraph mentioned. I assume that the execution paths from node that I select are all paths ending in the output of CallGraph (I should be able to communicate between CFGs). From this node, I see all the paths using the graph search algorithm.

Is it possible to replace the runOnFunction() / runOnModule() method runOnFunction() what is defined by the user, for example runOnExecutionPath() ? And if so, does LLVM have a structure that is suitable for storing execution paths? Another possibility would be to use getAnalysis<CallGraph> or getAnalysis<CFG> ? I'm confused.

Thanks so much for any advice!

+4
source share
1 answer

I am not aware of the full implementation in LLVM for you, which is displayed in the library, because it is a very specific need.

However, all the building blocks are there, and you just need to write code for your specific need. The basic blocks within a function are a graph of control flow in a certain sense, and you can go through it as you see fit. For example, you can create its DFS, which will give you all the paths from entry to exit.

If you want to see sample code that does something similar, look at include/llvm/Analysis/LoopIterator.h

+2
source

Source: https://habr.com/ru/post/1468766/


All Articles