public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Need info on GIMPLE
@ 2011-05-30  6:09 Abdul Wahid Memon
  2011-05-31  6:37 ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: Abdul Wahid Memon @ 2011-05-30  6:09 UTC (permalink / raw)
  To: gcc-help

Hello every one

I am doing some analysis on GIMPLE intermediate representation and I
have some questions.

I need to count the number of labels present in the representation
such as after optimized pass, but
I dont know why I don't encounter label statement in my switch
statement's case clause even though
there are some labels present. I am using iterators over basic blocks
and statement to determine how many
statement are there and which type.

 FOR_EACH_BB(bb)
  {
   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
      {

	switch(gimple_code(stmt))
	  {
	    case GIMPLE_NOP:
	    printf("NOP : ");
	    break;
	  case GIMPLE_COND:
	    printf("COND_STMT / ");
	    break;
	  case GIMPLE_LABEL:
	    printf("LABEL / ");
	    break;
        }
    }
}

Other cases are being matched such as GIMPLE_COND but not
GIMPLE_LABEL. Is there anything I am missing.

Regards

Abdul

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

* Re: Need info on GIMPLE
  2011-05-30  6:09 Need info on GIMPLE Abdul Wahid Memon
@ 2011-05-31  6:37 ` Ian Lance Taylor
  2011-06-07 18:40   ` Abdul Wahid Memon
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2011-05-31  6:37 UTC (permalink / raw)
  To: Abdul Wahid Memon; +Cc: gcc-help

Abdul Wahid Memon <engrwahidmemon@gmail.com> writes:

> I need to count the number of labels present in the representation
> such as after optimized pass, but
> I dont know why I don't encounter label statement in my switch
> statement's case clause even though
> there are some labels present. I am using iterators over basic blocks
> and statement to determine how many
> statement are there and which type.
>
>  FOR_EACH_BB(bb)
>   {
>    for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
>       {
>
> 	switch(gimple_code(stmt))
> 	  {
> 	    case GIMPLE_NOP:
> 	    printf("NOP : ");
> 	    break;
> 	  case GIMPLE_COND:
> 	    printf("COND_STMT / ");
> 	    break;
> 	  case GIMPLE_LABEL:
> 	    printf("LABEL / ");
> 	    break;
>         }
>     }
> }
>
> Other cases are being matched such as GIMPLE_COND but not
> GIMPLE_LABEL. Is there anything I am missing.

Case labels are never GIMPLE_LABEL statements.  Either the switch is
turned into a series of conditionals and the labels are discarded, or
you get a GIMPLE_SWITCH which incorporates CASE_LABEL_EXPR tree nodes
(see GIMPLE_SWITCH in gimple.def).

Ian

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

* Re: Need info on GIMPLE
  2011-05-31  6:37 ` Ian Lance Taylor
@ 2011-06-07 18:40   ` Abdul Wahid Memon
  2011-06-07 19:38     ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: Abdul Wahid Memon @ 2011-06-07 18:40 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Thanks Ian

I am sorry if I posed the question in a different way, but I just want
to count the number of labels (not case labels) but for jump
instructions but I am unable to encounter GIMPLE_LABEL. By the way, if
there is a jump instruction (whether conditional or unconditional)
there must be a label reference. I want to count those label
references.

Regards

Abdul

On Tue, May 31, 2011 at 7:46 AM, Ian Lance Taylor <iant@google.com> wrote:
> Abdul Wahid Memon <engrwahidmemon@gmail.com> writes:
>
>> I need to count the number of labels present in the representation
>> such as after optimized pass, but
>> I dont know why I don't encounter label statement in my switch
>> statement's case clause even though
>> there are some labels present. I am using iterators over basic blocks
>> and statement to determine how many
>> statement are there and which type.
>>
>>  FOR_EACH_BB(bb)
>>   {
>>    for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
>>       {
>>
>>       switch(gimple_code(stmt))
>>         {
>>           case GIMPLE_NOP:
>>           printf("NOP : ");
>>           break;
>>         case GIMPLE_COND:
>>           printf("COND_STMT / ");
>>           break;
>>         case GIMPLE_LABEL:
>>           printf("LABEL / ");
>>           break;
>>         }
>>     }
>> }
>>
>> Other cases are being matched such as GIMPLE_COND but not
>> GIMPLE_LABEL. Is there anything I am missing.
>
> Case labels are never GIMPLE_LABEL statements.  Either the switch is
> turned into a series of conditionals and the labels are discarded, or
> you get a GIMPLE_SWITCH which incorporates CASE_LABEL_EXPR tree nodes
> (see GIMPLE_SWITCH in gimple.def).
>
> Ian
>

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

* Re: Need info on GIMPLE
  2011-06-07 18:40   ` Abdul Wahid Memon
@ 2011-06-07 19:38     ` Ian Lance Taylor
       [not found]       ` <BANLkTi=NGfc9p8LVO+0kv5kzt_RorQPTdQ@mail.gmail.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2011-06-07 19:38 UTC (permalink / raw)
  To: Abdul Wahid Memon; +Cc: gcc-help

Abdul Wahid Memon <engrwahidmemon@gmail.com> writes:

> I am sorry if I posed the question in a different way, but I just want
> to count the number of labels (not case labels) but for jump
> instructions but I am unable to encounter GIMPLE_LABEL. By the way, if
> there is a jump instruction (whether conditional or unconditional)
> there must be a label reference. I want to count those label
> references.

Sorry, I think I misunderstood your question.

I don't know why you are not seeing any GIMPLE_LABEL statements.  Do you
see the labels in the dumps generated by -fdump-tree-all?

Ian

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

* Re: Need info on GIMPLE
       [not found]         ` <mcrei35fmlc.fsf@coign.corp.google.com>
@ 2011-06-07 20:09           ` Abdul Wahid Memon
  2011-06-07 20:15             ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: Abdul Wahid Memon @ 2011-06-07 20:09 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Aah ok. I thought them as labels as in RTL representation. Thanks alot for this.

By the way, if I want to traverse through all the GIMPLE statements,
then from where should I start? I mean what should be the reference
point to capture those labels in the cfg.

Regards

Abdul

On Tue, Jun 7, 2011 at 9:49 PM, Ian Lance Taylor <iant@google.com> wrote:
> Abdul Wahid Memon <engrwahidmemon@gmail.com> writes:
>
>> Lets take the dump at optimized pass.
>>
>> ;; Function main (main)
>>
>> main ()
>> {
>>   int i;
>>   int D.3251;
>>   const char * restrict D.3250;
>>
>> <bb 2>:
>>   i_2 = 0;
>>   goto <bb 4>;
>>
>> <bb 3>:
>>   D.3250_3 = (const char * restrict) &"hello world"[0];
>>   printf (D.3250_3);
>>   i_4 = i_1 + 1;
>>
>> <bb 4>:
>>   # i_1 = PHI <i_2(2), i_4(3)>
>>   if (i_1 <= 100)
>>     goto <bb 3>;
>>   else
>>     goto <bb 5>;
>>
>> <bb 5>:
>>   D.3251_5 = 0;
>>   return D.3251_5;
>>
>> }
>>
>> Here in this case, Can I consider <bb x>: as labels? If yes then I am
>> unable to encounter them in my code.
>
> Please reply to the mailing list, not just to me.  Thanks.
>
> The <bb x> markers just indicate the start of basic blocks.  They are
> not GIMPLE_LABELs.  They aren't represented in GIMPLE at all, they are
> in the CFG.  You will only get a GIMPLE_LABEL for an actual label in
> your source code.
>
> Ian
>

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

* Re: Need info on GIMPLE
  2011-06-07 20:09           ` Abdul Wahid Memon
@ 2011-06-07 20:15             ` Ian Lance Taylor
  2011-06-07 22:34               ` Abdul Wahid Memon
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2011-06-07 20:15 UTC (permalink / raw)
  To: Abdul Wahid Memon; +Cc: gcc-help

Abdul Wahid Memon <engrwahidmemon@gmail.com> writes:

> By the way, if I want to traverse through all the GIMPLE statements,
> then from where should I start? I mean what should be the reference
> point to capture those labels in the cfg.

As far as I know, the way you were traversing GIMPLE was fine.  The
labels you see in the dump, from the CFG, are not GIMPLE statements.
They are basic_block structs connected by edge structs.

Ian

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

* Re: Need info on GIMPLE
  2011-06-07 20:15             ` Ian Lance Taylor
@ 2011-06-07 22:34               ` Abdul Wahid Memon
  2011-06-07 22:54                 ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: Abdul Wahid Memon @ 2011-06-07 22:34 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Does that mean that I have to traverse the control flow graph in order
to capture labels (if there are any) too.

Lets suppose if I want to count the number of gimple statements within
the body of the loop, then definitely I need the reference of that
target label for any conditional goto statement.

Regards

Abdul

On Tue, Jun 7, 2011 at 9:57 PM, Ian Lance Taylor <iant@google.com> wrote:
> Abdul Wahid Memon <engrwahidmemon@gmail.com> writes:
>
>> By the way, if I want to traverse through all the GIMPLE statements,
>> then from where should I start? I mean what should be the reference
>> point to capture those labels in the cfg.
>
> As far as I know, the way you were traversing GIMPLE was fine.  The
> labels you see in the dump, from the CFG, are not GIMPLE statements.
> They are basic_block structs connected by edge structs.
>
> Ian
>

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

* Re: Need info on GIMPLE
  2011-06-07 22:34               ` Abdul Wahid Memon
@ 2011-06-07 22:54                 ` Ian Lance Taylor
  0 siblings, 0 replies; 8+ messages in thread
From: Ian Lance Taylor @ 2011-06-07 22:54 UTC (permalink / raw)
  To: Abdul Wahid Memon; +Cc: gcc-help

Abdul Wahid Memon <engrwahidmemon@gmail.com> writes:

> Does that mean that I have to traverse the control flow graph in order
> to capture labels (if there are any) too.
>
> Lets suppose if I want to count the number of gimple statements within
> the body of the loop, then definitely I need the reference of that
> target label for any conditional goto statement.
>

It really depends on what you mean by labels.  Labels that appear in
user code should appear as GIMPLE_LABEL statements.  Flow control that
does not involve user labels is normally represented by the CFG.  If you
just want to count the number of GIMPLE statements, then you don't have
to worry about the CFG, because it does not include GIMPLE statements.
So what you need to do depends on what you trying to do.

Ian

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

end of thread, other threads:[~2011-06-07 21:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-30  6:09 Need info on GIMPLE Abdul Wahid Memon
2011-05-31  6:37 ` Ian Lance Taylor
2011-06-07 18:40   ` Abdul Wahid Memon
2011-06-07 19:38     ` Ian Lance Taylor
     [not found]       ` <BANLkTi=NGfc9p8LVO+0kv5kzt_RorQPTdQ@mail.gmail.com>
     [not found]         ` <mcrei35fmlc.fsf@coign.corp.google.com>
2011-06-07 20:09           ` Abdul Wahid Memon
2011-06-07 20:15             ` Ian Lance Taylor
2011-06-07 22:34               ` Abdul Wahid Memon
2011-06-07 22:54                 ` Ian Lance Taylor

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