[Prev][Next][Index]

What is the innermost loop: bug or feature?



I've writting some very simple code on top of Sage++ to look at
loops. The way in which the innermostLoop loop is calcuated either has a
bug or the definition is different than I expected. 

First a qualifier as to what I'm using Sage++ for. I need an object
representation of a C++/C file. The "derived" things such as
innermostLoop() I will of course have to write my own flavor of in the
future, but thought I should let you know what I have found in the
off-the-shelf stuff.

Here is a function from my simple Sage++ program:

****************************************
void
dump_if_loop(SgStatement *f)
{
  if (f = isSgForStmt(s)) {
      printf("Found loop, variant %s, id %d :\n", 
	     tag[f->variant()], f->id());
      SgStatement *next = f->getNextLoop();
      SgStatement *prev = f->getPreviousLoop();
      SgStatement *inner = f->getInnermostLoop();
      
      if (next) {
	  printf("\tnext loop  : %d, Variant %s\n", 
		 next->id(), tag[next->variant()]);
      }
      if (prev) {
	  printf("\tprev loop  : %d, Variant %s\n", 
		 prev->id(), tag[prev->variant()]);
      }
      if (inner) {
	  printf("\tinner loop : %d, Variant %s\n",
		 inner->id(), tag[inner->variant()]);
      }
      f->unparsestdout();
  }
}
****************************************

Given a .dep file generated from this input:

****************************************
main()
{
    int x, y, z;
    int w, q, j;

    for (w = 0; w < 3; w++) {
	for (y = 0; y < 3; y++) {
	    for (z = 0; z < 3; z++) {
		printf("%d,%d,%d", x, y, z);
	    }
	    printf("z\n");
	}
	printf("y\n");
    }
}
****************************************

my program outputs:

****************************************
Found loop, variant FOR_NODE, id 5 :
        next loop  : 6, Variant FOR_NODE
        inner loop : 6, Variant FOR_NODE
for (w = 0 ; w < 3 ; (w)++)
{
       for (y = 0 ; y < 3 ; (y)++)
       {
          for (z = 0 ; z < 3 ; (z)++)
          {
             printf("%d,%d,%d", x, y, z);
           }
          printf("z\n");
        }
       printf("y\n");
 }
Found loop, variant FOR_NODE, id 6 :
        next loop  : 7, Variant FOR_NODE
        prev loop  : 5, Variant FOR_NODE
        inner loop : 7, Variant FOR_NODE
for (y = 0 ; y < 3 ; (y)++)
{
       for (z = 0 ; z < 3 ; (z)++)
       {
          printf("%d,%d,%d", x, y, z);
        }
       printf("z\n");
 }
Found loop, variant FOR_NODE, id 7 :
        prev loop  : 6, Variant FOR_NODE
        inner loop : 7, Variant FOR_NODE
for (z = 0 ; z < 3 ; (z)++)
{
       printf("%d,%d,%d", x, y, z);
 }
****************************************

I would have expected node 7 to have been the innermost loop of node
5. If printf("y\n); is removed then the output is what I expected.

Bug or feature? 

Jack Greenbaum       | Ricoh California Research Center
jackg@crc.ricoh.com  | 2882 Sand Hill Rd. Suite 115
(415) 496-5711 voice | Menlo Parck, CA 94025-7002
(415) 854-8740 fax   |