I've been beginning to work with LLVM and I'm interested to know if there is a programmatic way to extract the control flow graph and/or basic blocks from LLVM/clang in order to do some analysis on them. Is there a way to hook into the tool chain and pull out this information instead of doing a straight compilation? If not, what are the alternatives?
Extracting Basic Blocks/CFG from LLVM/clang on the Backend
1.9k views Asked by thegravian At
2
There are 2 answers
0
On
The CFG (Control Flow Graph) is purely part of CLang.
The CFG supports Visitors (see CFG.h) but you might want to ask on CLang dev list if there is a code sample available.
LLVM supports plugin passes. It would be straight-forward to write a pass to emit whatever data you want in whatever format you want.
However, LLVM has a large suite of analysis and transform passes already. You may be able to use the existing LLVM framework to extract the data you want after running the analysis passes you want.
Take a look at the docs, the code, and then ask more specific questions on the LLVMdev list to get the best answers.