On Thu, Jun 4, 2020 at 10:24 PM Gary Oblock via Gcc <gcc@gcc.gnu.org> wrote:
>
> ________________________________
>
>
>
> I'm trying to determine during LTO optimization (with one partition)
> whether of not a function call is to a function in the partition.
>
> Here is the routine I've written. Note, I'm willing to admit up front
> that the comparison below ( ) is probably dicey.

I think you should simply lookup the callgraph edge for the call_stmt
in the caller via caller_graph_node->get_edge (call_stmt).

> ---------------------------
> static bool
> is_user_function ( gimple *call_stmt)
> {
>   tree fndecl = gimple_call_fndecl ( call_stmt);
>
>   DEBUG_L("is_user_function: decl in: %p,", fndecl);
>   DEBUG_F( print_generic_decl, stderr, fndecl, (dump_flags_t)-1);
>   DEBUG("\n");
>   INDENT(2);
>
>   cgraph_node* node;
>   bool ret_val = false;
>   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY ( node)
>   {
>     DEBUG_L("decl %p,", node->decl);
>     DEBUG_F( print_generic_decl, stderr, node->decl, (dump_flags_t)-1);
>     DEBUG("\n");
>
>     if ( node->decl == fndecl )
>       {
>     ret_val = true;
>     break;
>       }
>   }
>
>   INDENT(-2);
>   return ret_val;
> }
> ---------------------------
>
> Here's the test program I was compiling.
>
> -- aux.h ------------------
> #include "stdlib.h"
> typedef struct type type_t;
> struct type {
>   int i;
>   double x;
> };
>
> #define MAX(x,y) ((x)>(y) ? (x) : (y))
>
> extern int max1( type_t *, size_t);
> extern double max2( type_t *, size_t);
> extern type_t *setup( size_t);
> -- aux.c ------------------
> #include "aux.h"
> #include "stdlib.h"
>
> type_t *
> setup( size_t size)
> {
>   type_t *data = (type_t *)malloc( size * sizeof(type_t));
>   size_t i;
>   for( i = 0; i < size; i++ ) {
>     data[i].i = rand();
>     data[i].x = drand48();
>   }
>   return data;
> }
>
> int
> max1( type_t *array, size_t len)
> {
>   size_t i;
>   int result = array[0].i;
>   for( i = 1; i < len; i++  ) {
>     result = MAX( array[i].i, result);
>   }
>   return result;
> }
>
> double
> max2( type_t *array, size_t len)
> {
>   size_t i;
>   double result = array[0].x;
>   for( i = 1; i < len; i++  ) {
>     result = MAX( array[i].x, result);
>   }
>   return result;
> }
> -- main.c -----------------
> #include "aux.h"
> #include "stdio.h"
>
> type_t *data1;
>
> int
> main(void)
> {
>   type_t *data2 = setup(200);
>   data1 = setup(100);
>
>   printf("First %d\n" , max1(data1,100));
>   printf("Second %e\n", max2(data2,200));
> }
> ---------------------------
>
> The output follows:
>
> ---------------------------
> L# 1211: is_user_function: decl in: 0x7f078461be00,  static intD.xxxx 
> max1D.xxxx (struct type_t *, size_t);
> L# 1222:   decl 0x7f0784620000,  static struct type_t * setupD.xxxx (size_t);
> L# 1222:   decl 0x7f078461bf00,  static intD.xxxx max1.constprop.0D.xxxx 
> (struct type_t *);
> L# 1222:   decl 0x7f078461bd00,  static doubleD.xxxx max2.constprop.0D.xxxx 
> (struct type_t *);
> L# 1222:   decl 0x7f078461bb00,  static intD.xxxx mainD.xxxx (void);
> ---------------------------
>
> Now it's pretty obvious that constant propagation decided the size_t
> len arguments to max1 and max2 were no longer needed. However, the
> function declaration information on the calls to them weren't updated
> so they'll never match. Now if there is another way to see if the
> function is in the partition or if there is some other way to compare
> the functions in a partition, please let me know.
>
> Thanks,
>
> Gary Oblock
> Ampere Computing
>
> PS. The body of the message is attached in a file because my email program
> (Outlook) mangled the above.
>
>
>
> CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is 
> for the sole use of the intended recipient(s) and contains information that 
> is confidential and proprietary to Ampere Computing or its subsidiaries. It 
> is to be used solely for the purpose of furthering the parties' business 
> relationship. Any review, copying, or distribution of this email (or any 
> attachments thereto) is strictly prohibited. If you are not the intended 
> recipient, please contact the sender immediately and permanently delete the 
> original and any copies of this email and any attachments thereto.

Reply via email to