Search code examples
clangllvmllvm-clangllvm-ir

Counting the number of LLVM instructions executed dynamically using LLI


I wanted to count the number of LLVM instruction executed dynamically in any program, using lli 3.4.

I checked this link, but it's not giving any information related to instruction count.


Solution

  • There's no built-in way in LLVM to do this, AFAIK. However, you have a number of simple options:

    1. You can hack the interpreter (which lli can run) to count how many instructions it executed.
    2. You can instrument the IR before running it by incrementing a counter on entry to each basic block. Then you can run the instrumented IR through either the interpreter or JIT.