[cfe-dev] Dataflow analysis with LLVM/Clang

Chris Lattner clattner at apple.com
Wed Oct 1 13:12:46 PDT 2008

On Oct 1, 2008, at 6:52 AM, João Paulo Rechi Vita wrote:
> Hello list!

hi :)

Unless you have a very strong reason to do it, I'd suggest doing this  
at the LLVM IR level. Doing transformations and instrumentation there  
is generally easier than dealing with C ASTs.  Dealing with C ASTs  
means you have to deal with a lot of gross stuff that C has, which  
gets lowered away by the time you get to LLVM IR.

Reasons to use Clang ASTs are if you want to do an edit to the  
original user source, or if you need fine grained location info so  
that you can indicate to the user that some subexpression was involved.

You can find several example instrumentations in the llvm/lib/ 
Transforms/Instrumentation directory,


> I'm working on a MSc project and I need detect conflictive actions
> between different threads in a program, through statical analysis. The
> idea is to detect actions like a mutex lock/unlock (besides others),
> and do some code insertion at the program to notify a "manager" about
> the next conflictive action that is going to happen. This insertion
> should be done as early as possible on the program execution flow (so
> the "manager" gets the info as early as possible), but it also has to
> be accurate (so if a conflictive action is performed at one of the
> branches of an if, for example, the insertion has to be made on the
> beggining of the branch, because if that branch is not taken at
> runtime, that action will not be performed).
> I was wondering if it's better to do this on clang, since one of it's
> intended uses is statical code analysis and code transformation, or if
> it's better to do this over the LLVM IR, as an LLVM pass. AFAIK I'll
> need to work over a control-flow graph and call graph in order to make
> the analysis, but I'll also need some line information to make the
> code insertion (maybe this is at the AST?). I very new to LLVM (and
> also new to compilers-related stuff), so I would like to hear some
> opinions on this, so I can make a good decision, and (if applicable)
> contribute with this work to LLVM/Clang. Also, if someone can point me
> a clang or LLVM pass that does similar stuff, it would be great.
> Thanks in advance.
> -- 
> João Paulo Rechi Vita
> MSc Computer Science Student
> Computer Engineer
> IC / Unicamp
> http://jprvita.wordpress.com/
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list