Newbie question : instrumenting code

Hi.

I am new to Clang and somewhat new to LLVM. I am doing a project where I need to instrument C code to add some profiling information such as timers and iteration counts of loops to some of the functions and then it will be compiled using clang+llvm. The transformation need not be source to source. All I am looking for is the ability to add instrumentation at some point during the compilation process. Is it reasonable to attempt to modify Clang so that it adds timers and logging calls at the places I need? Or should I be looking at some other part of the LLVM stack?

thanks,
rahul

You will probably want to extend Clang's CodeGen to create LLVM IR for the timers/instrumentation directly. That will make it easy to tie that instrumentation to specific AST elements, which might be useful if you decide that you also want to add instrumentation pragmas or attributes that show up in the source code.

If you're interesting in perform more low-level instrumentation, you could consider adding an LLVM pass.

  - Doug