[llvm-dev] How to add custom instrumentation?

Alex Denisov via llvm-dev llvm-dev at lists.llvm.org
Thu Jul 13 13:45:46 PDT 2017

Thanks for the hint, I didn’t know about this option. That’s a great reference!

However, I am trying to be a compiler/language agnostic.
Also (for whatever reasons) I need a numeric ID of a function rather then its address.
So the question is still opened.

May I assume that the following always holds:
The first basic block in a function is an entry point and the last basic block in a function is an exit point

> On 13. Jul 2017, at 10:57, ORiordan, Martin <martin.oriordan at intel.com> wrote:
> The '-finstrument-functions' option may already be sufficient for your needs.
> When selected this inserts the following two calls on entry-to and exit-from a function:
>  __cyg_profile_func_enter(void* this_fn, void* call_site)
>  __cyg_profile_func_exit(void* this_fn, void* call_site)
> You can then provide a custom implementation of these calls to perform the analysis tasks that you require.
> The two parameters are the address of the function into which the instrumentation is inserted, and the address of the call site to the instrumentation function.
> There is an "Execution Trace" implementation of these instrumentation hooks on GitHub called 'eTrace' that may guide you, though I can't recall the link.
> All the best,
>  MartinO
> -----Original Message-----
> From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Alex Denisov via llvm-dev
> Sent: Thursday, July 13, 2017 8:57 AM
> To: llvm-dev <llvm-dev at lists.llvm.org>
> Subject: [llvm-dev] How to add custom instrumentation?
> Hi everyone,
> I run some functions using ORC JIT, now I need to add custom instrumentation.
> I want to add two callbacks to each function: ‘enterFunction' at the beginning and ‘leaveFunction' at the end.
> Intuition says that I could ‘just' insert CallInst's to the first and the last basic blocks in the function.
> Am I correct? Are there any other/better way to do this? Is there anything special I need to be aware of?
> Thank you.
> --
> AlexDenisov
> Software Engineer, https://lowlevelbits.org
> --------------------------------------------------------------
> Intel Research and Development Ireland Limited
> Registered in Ireland
> Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
> Registered Number: 308263
> This e-mail and any attachments may contain confidential material for the sole
> use of the intended recipient(s). Any review or distribution by others is
> strictly prohibited. If you are not the intended recipient, please contact the
> sender and delete all copies.

Software Engineer, https://lowlevelbits.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170713/e23cf1df/attachment.sig>

More information about the llvm-dev mailing list