Does LLVM dynamically run the program to obtain profiling information like branch weight? if so, can we access the information regarding this run like the number of instructions that have been executed dynamically between two specific points of the program?
depending on your specific use case you could have a look at the Sulong project (https://github.com/graalvm/sulong/). Sulong can execute LLVM IR programs and gathers profiling information during the program’s execution. For example, Sulong profiles the frequency of successor blocks in the interpreter, to then communicate it to the dynamic compiler for better optimization . Similarly, you could implement a node that counts the number of executed instructions between two points in the program and instantiate it in the parser .
Does LLVM dynamically run the program to obtain profiling information like branch weight?
No, the profile information is either collected via instrumentation of the program or via external sampling profilers. It is then read back into the IR by the frontend or an optimization pass.
if so, can we access the information regarding this run like the number of instructions that have been executed dynamically between two specific points of the program?
If Manuel Rigger’s suggestion doesn’t work, maybe try Valgrind which can get these kinds of instruction counts?
Thank you for your reply.