public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Finding all CALL_EXPR tree nodes during GENERIC
@ 2017-11-18 16:38 Katsunori Kumatani
  2017-11-18 16:49 ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Katsunori Kumatani @ 2017-11-18 16:38 UTC (permalink / raw)
  To: gcc

Hello, I'm doing some testing with a gcc plugin (also helped me
understand a lot of how GCC works) but I've hit a roadblock.

I want to find all of a function body's CALL_EXPR nodes (i.e. what
calls it has) early during GENERIC, so I assume the
PLUGIN_PRE_GENERICIZE hook is what I should use right?

Anyway, my problem is I don't know how to find all the CALL_EXPR nodes
from the DECL_SAVED_TREE of the function's decl. So what's the
simplest way to do that? The routines in tree-iterator.h don't help
much, they only iterate through a statement list. Do I have to go
through every expr manually? Is there no API available? (walk_tree
doesn't seem to handle it, or maybe I don't know how to use it)


This is obviously trivial to do in GIMPLE form (iterating through all
statements and finding GIMPLE_CALL) but I need it as early as
possible, so that would be in the tree representation (GENERIC?). I
hope I'm just missing something obvious.

Thanks.

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

* Re: Finding all CALL_EXPR tree nodes during GENERIC
  2017-11-18 16:38 Finding all CALL_EXPR tree nodes during GENERIC Katsunori Kumatani
@ 2017-11-18 16:49 ` Richard Biener
  2017-11-19 20:27   ` Katsunori Kumatani
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2017-11-18 16:49 UTC (permalink / raw)
  To: gcc, Katsunori Kumatani

On November 18, 2017 5:38:35 PM GMT+01:00, Katsunori Kumatani <katsunori.kumatani@gmail.com> wrote:
>Hello, I'm doing some testing with a gcc plugin (also helped me
>understand a lot of how GCC works) but I've hit a roadblock.
>
>I want to find all of a function body's CALL_EXPR nodes (i.e. what
>calls it has) early during GENERIC, so I assume the
>PLUGIN_PRE_GENERICIZE hook is what I should use right?
>
>Anyway, my problem is I don't know how to find all the CALL_EXPR nodes
>from the DECL_SAVED_TREE of the function's decl. So what's the
>simplest way to do that? The routines in tree-iterator.h don't help
>much, they only iterate through a statement list. Do I have to go
>through every expr manually? Is there no API available? (walk_tree
>doesn't seem to handle it, or maybe I don't know how to use it)

Walk_tree should do it. 

Richard. 

>
>This is obviously trivial to do in GIMPLE form (iterating through all
>statements and finding GIMPLE_CALL) but I need it as early as
>possible, so that would be in the tree representation (GENERIC?). I
>hope I'm just missing something obvious.
>
>Thanks.

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

* Re: Finding all CALL_EXPR tree nodes during GENERIC
  2017-11-18 16:49 ` Richard Biener
@ 2017-11-19 20:27   ` Katsunori Kumatani
  2017-11-20 10:32     ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Katsunori Kumatani @ 2017-11-19 20:27 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc

Yes, it seems walk_tree does the job, I was probably doing something
wrong before. Thank you.

I have a question about it. Am I correct in assuming I only have to
check the subtrees of nodes that satisfy EXPR_P? So for nodes that
aren't EXPR_P, can I just set *walkSubtrees to 0, or will that miss
some CALL_EXPRs? In my tests, none were missed, but I don't know if
this is all-encompassing for C/C++ generated AST.

Oh and another thing, is it possible to change the node (or create a
new one and modify the source that points to it)? I assume that's why
the first parameter to walk_tree_fn is a tree* right? That would be
useful to know too.

On Sat, Nov 18, 2017 at 6:49 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On November 18, 2017 5:38:35 PM GMT+01:00, Katsunori Kumatani <katsunori.kumatani@gmail.com> wrote:
>>Hello, I'm doing some testing with a gcc plugin (also helped me
>>understand a lot of how GCC works) but I've hit a roadblock.
>>
>>I want to find all of a function body's CALL_EXPR nodes (i.e. what
>>calls it has) early during GENERIC, so I assume the
>>PLUGIN_PRE_GENERICIZE hook is what I should use right?
>>
>>Anyway, my problem is I don't know how to find all the CALL_EXPR nodes
>>from the DECL_SAVED_TREE of the function's decl. So what's the
>>simplest way to do that? The routines in tree-iterator.h don't help
>>much, they only iterate through a statement list. Do I have to go
>>through every expr manually? Is there no API available? (walk_tree
>>doesn't seem to handle it, or maybe I don't know how to use it)
>
> Walk_tree should do it.
>
> Richard.
>
>>
>>This is obviously trivial to do in GIMPLE form (iterating through all
>>statements and finding GIMPLE_CALL) but I need it as early as
>>possible, so that would be in the tree representation (GENERIC?). I
>>hope I'm just missing something obvious.
>>
>>Thanks.
>

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

* Re: Finding all CALL_EXPR tree nodes during GENERIC
  2017-11-19 20:27   ` Katsunori Kumatani
@ 2017-11-20 10:32     ` Richard Biener
  2017-11-21 12:41       ` Katsunori Kumatani
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2017-11-20 10:32 UTC (permalink / raw)
  To: Katsunori Kumatani; +Cc: GCC Development

On Sun, Nov 19, 2017 at 9:27 PM, Katsunori Kumatani
<katsunori.kumatani@gmail.com> wrote:
> Yes, it seems walk_tree does the job, I was probably doing something
> wrong before. Thank you.
>
> I have a question about it. Am I correct in assuming I only have to
> check the subtrees of nodes that satisfy EXPR_P? So for nodes that
> aren't EXPR_P, can I just set *walkSubtrees to 0, or will that miss
> some CALL_EXPRs? In my tests, none were missed, but I don't know if
> this is all-encompassing for C/C++ generated AST.

You'd have to experiment, it depends on the C/C++ AST.  You should be
able to skip TYPE_P though.

> Oh and another thing, is it possible to change the node (or create a
> new one and modify the source that points to it)? I assume that's why
> the first parameter to walk_tree_fn is a tree* right? That would be
> useful to know too.

Yes, you can change things.

Richard.

> On Sat, Nov 18, 2017 at 6:49 PM, Richard Biener
> <richard.guenther@gmail.com> wrote:
>> On November 18, 2017 5:38:35 PM GMT+01:00, Katsunori Kumatani <katsunori.kumatani@gmail.com> wrote:
>>>Hello, I'm doing some testing with a gcc plugin (also helped me
>>>understand a lot of how GCC works) but I've hit a roadblock.
>>>
>>>I want to find all of a function body's CALL_EXPR nodes (i.e. what
>>>calls it has) early during GENERIC, so I assume the
>>>PLUGIN_PRE_GENERICIZE hook is what I should use right?
>>>
>>>Anyway, my problem is I don't know how to find all the CALL_EXPR nodes
>>>from the DECL_SAVED_TREE of the function's decl. So what's the
>>>simplest way to do that? The routines in tree-iterator.h don't help
>>>much, they only iterate through a statement list. Do I have to go
>>>through every expr manually? Is there no API available? (walk_tree
>>>doesn't seem to handle it, or maybe I don't know how to use it)
>>
>> Walk_tree should do it.
>>
>> Richard.
>>
>>>
>>>This is obviously trivial to do in GIMPLE form (iterating through all
>>>statements and finding GIMPLE_CALL) but I need it as early as
>>>possible, so that would be in the tree representation (GENERIC?). I
>>>hope I'm just missing something obvious.
>>>
>>>Thanks.
>>

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

* Re: Finding all CALL_EXPR tree nodes during GENERIC
  2017-11-20 10:32     ` Richard Biener
@ 2017-11-21 12:41       ` Katsunori Kumatani
  0 siblings, 0 replies; 5+ messages in thread
From: Katsunori Kumatani @ 2017-11-21 12:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Development

On Mon, Nov 20, 2017 at 12:32 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Sun, Nov 19, 2017 at 9:27 PM, Katsunori Kumatani
> <katsunori.kumatani@gmail.com> wrote:
>> Yes, it seems walk_tree does the job, I was probably doing something
>> wrong before. Thank you.
>>
>> I have a question about it. Am I correct in assuming I only have to
>> check the subtrees of nodes that satisfy EXPR_P? So for nodes that
>> aren't EXPR_P, can I just set *walkSubtrees to 0, or will that miss
>> some CALL_EXPRs? In my tests, none were missed, but I don't know if
>> this is all-encompassing for C/C++ generated AST.
>
> You'd have to experiment, it depends on the C/C++ AST.  You should be
> able to skip TYPE_P though.
>

You're right, one example would be variable initialization. I realized
the exprs are found within its DECL_INITIAL, which is part of a
VAR_DECL (and so not an expr). I'll stick to TYPE_P then, thanks.

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

end of thread, other threads:[~2017-11-21 12:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-18 16:38 Finding all CALL_EXPR tree nodes during GENERIC Katsunori Kumatani
2017-11-18 16:49 ` Richard Biener
2017-11-19 20:27   ` Katsunori Kumatani
2017-11-20 10:32     ` Richard Biener
2017-11-21 12:41       ` Katsunori Kumatani

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).