[LLVMdev] LLVM instrumentation overhead

Nipun Arora nipun2512 at gmail.com
Fri Dec 9 11:32:25 PST 2011


Hi John,

Thanks for the detailed answer, this gives me a good starting point to 
look into.

I was also wondering if you could give an idea (in terms of %ge) the 
overhead one can expect with such an instrumentation. I want something 
really lightweight and simple which can possible be applied to 
production systems, so overhead is a concern.

Thanks
Nipun

On 12/09/2011 02:21 PM, John Criswell wrote:
> On 12/7/11 4:51 PM, Nipun Arora wrote:
>> Hi,
>>
>> I need to write a transform pass which instruments the target program to
>> output the name of each function executed, and the rdtsc counter along
>> with it.
>
> Doing this in LLVM is really straightforward.  You simply iterate 
> through all the functions in a module and add instructions to their 
> entry basic blocks to do whatever it is that you want to do.
>
> I believe you already know how to find all the functions and their 
> entry blocks.  Review the Programmer's Guide and the doxygen docs on 
> llvm::Module and llvm::Function if there's something you don't 
> understand.
>
> The only other question is how to insert instructions.  For that, you 
> can take one of two approaches.  First, you can use the IRBuilder 
> class (http://llvm.org/doxygen/classllvm_1_1IRBuilder.html).  Second, 
> you can simply use the appropriate constructor/new methods of the 
> Instruction classes to create and insert the instructions that you 
> want.  I believe IRBuilder is now the preferred way to do things as 
> its API changes less often.
>
> For the instrumentation that you want to do, the easiest thing to do 
> would be to insert a call in every function to a function that you 
> implement in a run-time library that does whatever the instrumentation 
> should do.  This makes the compiler transform very simple.
>>
>> Can anyone give me an idea of how to go about it?(I've worked around
>> with LLVM pass framework and opt to do static analysis, but would like
>> to do a lightweight instrumentation). Also can anyone give an
>> approximate idea of the overhead for such instrumentation?
>
> To make things faster, you could compile your run-time library as a 
> static library linked in using clang's/libLTO's link-time 
> optimization.  Your run-time library can then be inter-procedurally 
> inlined with the program that you are instrumenting.
>
> -- John T.
>
>>
>> Thanks
>> Nipun
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list