-finstrument-functions and C++ exceptions

2005-04-13 Thread Chris Kirby
We are trying to use -finstrument-functions to do some custom profiling on x86 
and ppc.  

For normal code execution, it works fine, calling our entry and exit methods as 
expected.

Unfortunately, we are running into problems related to exceptions.  If we exit 
a function because of an exception, no exit method is called.  This greatly 
diminishes the usefulness of the instrumentation since we are no longer 
guaranteed to get matching entry and exit calls.

It seems to me that if function instrumentation is enabled, then the compiler 
should guarantee that exit (or perhaps a exit_throw?) is called, even if the 
function is exited because of an exception.

I can see where the current instrumentation is added in gcc/function.c.  Is 
there some easy way to add some cleanup code that guarantees exit will be 
called?  Are there any documents on how RTL works?

Another possible place I see to hook it in is unwind.inc, but that does not 
have access to the current function tree, so we can't tell if instrumentation 
is enabled or not.

Thank you,

- Chris Kirby



Re: -finstrument-functions and C++ exceptions

2005-04-13 Thread Chris Kirby
At 10:08 AM 4/13/2005 -0400, Andrew Pinski wrote:

>On Apr 13, 2005, at 10:06 AM, Chris Kirby wrote:
>
>>We are trying to use -finstrument-functions to do some custom profiling on 
>>x86 and ppc.
>>
>>For normal code execution, it works fine, calling our entry and exit methods 
>>as expected.
>>
>>Unfortunately, we are running into problems related to exceptions.  If we 
>>exit a function because of an exception, no exit method is called.  
>>This greatly diminishes the usefulness of the instrumentation since we are no 
>>longer guaranteed to get matching entry and exit calls.
>
>It works the way you want to for the 4.0 release.

Unfortunately our next release will be using gcc 3.4.2.

Looking at the 4.0 code, I can see that the exit instrumentation is done by 
wrapping a try finally around the entire function.  Backporting this to 3.4.2 
isn't as straightforward as I hoped.  I think something similar could be done 
in tree-optimize.c's tree_rest_of_compilation() but it looks like some of the 
tree/RTL methods have changed in 4.0.

Are there any examples of wrapping a method with a try finally clause and 
calling a given method compatible with 3.4.2?

- Chris



rtx/tree calling function syntax

2005-04-15 Thread Chris Kirby
I am trying to backport how -finstrument-functions is handled from gcc 4.0 to 
gcc 3.4.2.

If function instrumentation is enabled, the whole function is wrapped in a try 
finally block, where the exit call is done from the finally block.

So I think the whole function is generated in tree_rest_of_compilation() in 
tree-optimize.c.  I am able to create the try finally node, but I am having 
trouble determining the syntax to call the exit method inside the finally block.

Below is the code I am trying to insert after the function is fully created but 
before the assembly has been generated.  Does anyone have any ideas as to the 
correct syntax for building this call?

if (flag_instrument_function_entry_exit
&& ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl))
  {
tree tf, try, finally;
rtx entry;

try = DECL_SAVED_TREE (fndecl);

/** wrap the current function inside the try finally block *.
tf = build (TRY_FINALLY_EXPR, void_type_node, try, NULL);
TREE_SIDE_EFFECTS (tf) = 1;

/** Following is code that does not work to call the exit function

entry = DECL_RTL(tf);
entry = XEXP(entry,0);

emit_library_call (profile_function_exit_libfunc, LCT_NORMAL, VOIDmode,
 2, entry, Pmode,
 expand_builtin_return_addr 
(BUILT_IN_RETURN_ADDRESS,
   
0,
   
hard_frame_pointer_rtx),
 Pmode);
*/

DECL_SAVED_TREE (fndecl) = tf;
  }

- Chris

At 10:08 AM 4/13/2005 -0400, Andrew Pinski wrote:

>On Apr 13, 2005, at 10:06 AM, Chris Kirby wrote:
>
>>We are trying to use -finstrument-functions to do some custom profiling on 
>>x86 and ppc.
>>
>>For normal code execution, it works fine, calling our entry and exit methods 
>>as expected.
>>
>>Unfortunately, we are running into problems related to exceptions.  If we 
>>exit a function because of an exception, no exit method is called.  
>>This greatly diminishes the usefulness of the instrumentation since we are no 
>>longer guaranteed to get matching entry and exit calls.
>
>It works the way you want to for the 4.0 release.

Unfortunately our next release will be using gcc 3.4.2.

Looking at the 4.0 code, I can see that the exit instrumentation is done by 
wrapping a try finally around the entire function.  Backporting this to 3.4.2 
isn't as straightforward as I hoped.  I think something similar could be done 
in tree-optimize.c's tree_rest_of_compilation() but it looks like some of the 
tree/RTL methods have changed in 4.0.

Are there any examples of wrapping a method with a try finally clause and 
calling a given method compatible with 3.4.2?

- Chris