RouteMapper
RouteMapper

Reputation: 2560

Construct in-memory IR CFG of C/C++ program using LLVM

I am interested in analyzing a CFG of a C/C++ program where the CFG's nodes contain LLVM IR instructions. Is there any way to leverage LLVM to extract a persistent in-memory object of this CFG? I do not want to implement a pass in the compiler; I want the CFG to undergo analysis in my own program.

Upvotes: 1

Views: 455

Answers (1)

Eli Bendersky
Eli Bendersky

Reputation: 273736

The LLVM IR in-memory representation is amenable to CFG analysis because all the basic blocks are organized as a graph already. Within a basic block, the instruction sequence is linear. Some interesting in-function CFG-related code in LLVM is: lib/Analysis/CFG.cpp and lib/Analysis/CFGPrinter.cpp

Upvotes: 4

Related Questions