[cfe-dev] Newbie question : instrumenting code
Douglas Gregor
dgregor at apple.com
Tue Dec 22 15:54:03 PST 2009
On Dec 13, 2009, at 9:28 AM, Rahul Garg wrote:
> 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?
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
More information about the cfe-dev
mailing list