Counting instructions


I need to instrument the code in order to generate an event (call a certain function) whenever X instructions have been executed. I’m using MachineFunctionPass to get machine-dependent representation of each LLVM function in the program. However, such pass doesn’t allow to modify such functions. Is there any other class so I can modify MachineFunctions?

Thanks in advance, Raul.

I'm not sure I follow here: you want to insert your instrumentation at the machine code level, but you want to change the llvm ir? Once the instruction selection phase converts from llvm ir to machine code, the LLVM IR is mostly ignored. Changing it won't cause a change in the generated code.


I'm not quite sure Chris. But I think Raul only wanna to execute some
specific instruction about every X instructions. He probably don't
need to modify the instruction generated, but only to count the number
of machine instructions and execute something after. Am I right Raul?
I believe he is trying to do that at the JIT level. These where my two
bits.... :slight_smile:

In time, I don't know the answer for his question.