public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [question] replacing called function by gimple_call_set_fndecl doesn't actually take effect
@ 2018-01-05  4:57 Tong Zhou
  2018-01-05  9:38 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Tong Zhou @ 2018-01-05  4:57 UTC (permalink / raw)
  To: gcc

Hi,

I am new to gcc and was trying to implement a gimple pass today. One thing
I tried to do was to make a call_stat that originally calls malloc call
another function like new_malloc. I used gimple_call_set_fndecl and also
did update_stmt (although I don't know exactly what it does). But the final
assembly code still calls the old function. The relevant code is as follows:

------------------------------------
  tree malloc_fn_type
      = build_function_type_list (void_type_node, size_type_node,
NULL_TREE);
  tree new_malloc = build_fn_decl("new_malloc", malloc_fn_type);

  struct cgraph_node *alloc_node = my_get_malloc_node();
  struct cgraph_edge *edge = NULL;
  struct cgraph_node *caller = NULL;

  for (edge = alloc_node->callers; edge; edge = edge->next_caller)
  {
    gimple callStmt = edge->call_stmt;
    gimple_call_set_fndecl(callStmt, new_malloc);
    update_stmt (callStmt);
  }
------------------------------------

The callee was indeed the new_malloc when I use debug_gimple_stmt to print
the call_stmt out, but the generated assembly code or dumped gimble file
still use the old malloc. Thanks in advance!

Thanks,
Tong

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [question] replacing called function by gimple_call_set_fndecl doesn't actually take effect
  2018-01-05  4:57 [question] replacing called function by gimple_call_set_fndecl doesn't actually take effect Tong Zhou
@ 2018-01-05  9:38 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2018-01-05  9:38 UTC (permalink / raw)
  To: Tong Zhou; +Cc: GCC Development

On Fri, Jan 5, 2018 at 5:57 AM, Tong Zhou <zt9465@gmail.com> wrote:
> Hi,
>
> I am new to gcc and was trying to implement a gimple pass today. One thing
> I tried to do was to make a call_stat that originally calls malloc call
> another function like new_malloc. I used gimple_call_set_fndecl and also
> did update_stmt (although I don't know exactly what it does). But the final
> assembly code still calls the old function. The relevant code is as follows:
>
> ------------------------------------
>   tree malloc_fn_type
>       = build_function_type_list (void_type_node, size_type_node,
> NULL_TREE);
>   tree new_malloc = build_fn_decl("new_malloc", malloc_fn_type);
>
>   struct cgraph_node *alloc_node = my_get_malloc_node();
>   struct cgraph_edge *edge = NULL;
>   struct cgraph_node *caller = NULL;
>
>   for (edge = alloc_node->callers; edge; edge = edge->next_caller)
>   {
>     gimple callStmt = edge->call_stmt;
>     gimple_call_set_fndecl(callStmt, new_malloc);
>     update_stmt (callStmt);
>   }
> ------------------------------------
>
> The callee was indeed the new_malloc when I use debug_gimple_stmt to print
> the call_stmt out, but the generated assembly code or dumped gimble file
> still use the old malloc. Thanks in advance!

I would guess the cgraph is stale at the point you modify it (the
edge->call_stmt).
This part of the callgraph isn't really kept up-to-date.

Richard.

> Thanks,
> Tong

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-05  9:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-05  4:57 [question] replacing called function by gimple_call_set_fndecl doesn't actually take effect Tong Zhou
2018-01-05  9:38 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).