[LLVMdev] LLVM bytecode simulator/emulator?

Kenneth Hoste kenneth.hoste at elis.ugent.be
Fri Jul 14 09:11:57 PDT 2006


John Criswell wrote:
> Okay.  As Rob has already said, it sounds like you want to write an LLVM 
> pass that adds global variables and instructions to a program.  So, to 
> state it explicitly, you want to:
> 
> 1) Compile the program that you want to instrument to LLVM bytecode 
> using llvm-gcc.
> 2) Use an LLVM pass that you write to instrument the program.
> 3) Use LLVM's llc program to generate C or assembly code of your 
> instrumented program.
> 4) Compile the C/asm code to native code with gcc and link it with any 
> native code libraries that it needs.
> 5) Run the program and gather the information from your instrumentation 
> instructions.
> 

That sounds indeed like what I want to do, but... I want the library 
functions (for example printf), to be counted aswell. I.e., I don't make 
any distinction between program code and library code. This is essential 
for me, because I need the analysis of the program to predict/estimate 
performance, and that's quite hard, if not impossible, without taking 
the library count into account.

Is there a way to statically compile my program (along with the library 
code) into a LLVM bytecode file? That way, I can just instrument that, 
and go on from there with steps 3-5, ignoring the 'link with any native 
code library'. The libraries I need are either pretty standard (i.e. 
glibc), or I have the code for them (so I can compile it along with the 
program).

Maybe it's possible using the lli interpreter (which is a lot slower, I 
know), instead of the analyze tool?

> Since your instrumentation pass will need to add a global variable to 
> the program, a BasicBlockPass is not suitable for what you want to do.  
> I would recommend using a ModulePass.  A ModulePass is given an entire 
> Module (i.e. an entire LLVM bytecode file).  Your pass can add a global 
> counter variable and then iterate over every instruction in the Module, 
> instrumenting it as needed.

Okay, I get that... In ATOM, you're able to iterate over all basic 
blocks, and inside each basic block iterate over all it's instructions, 
and adding instrumentation code after each instruction that way. Hence 
the confusion probably :)

Thanks!

Kenneth

-- 
Statistics are like a bikini. What they reveal is suggestive, but what 
they conceal is vital (Aaron Levenstein)

Kenneth Hoste
ELIS - Ghent University
kenneth.hoste at elis.ugent.be
http://www.elis.ugent.be/~kehoste



More information about the llvm-dev mailing list