https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64265
--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Doing it in gimplify_function_tree is pretty straightforward, after all, we already have there code to handle if (flag_instrument_function_entry_exit && !DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl) && !flag_instrument_functions_exclude_p (fndecl)) which does very similar thing - on entry add a call to one function with address of current function and __builtin_return_address (0), on exit (including exit through exceptions) another call with the same arguments. So, the question is just if you want to do it that way...