Loop transformations in SUIF + patch for gcc 3

Marc Gonzalez-Sigler <[email protected]> Fri, 24 Sep 2004 15:18:42 +0200
Newsgroups gmane.comp.compilers.suif.bugs
Message-ID <[email protected]>
Hello SUIF users,

I am looking for a source-to-source tool to apply specific 
optimizations (mostly loop optimizations(*) and array padding) to 
specific parts of a C (or Fortran) program.

(*) e.g. unrolling, tiling, interchange, fusion, fission...

For example, imagine I have the following loop nest in my C code:

   ...
   for (i=0; i < N; ++i)
     for (j=0; j < N; ++j)
       for (k=0; k < N; ++k)
         C[i][j] += A[i][k]*B[k][j];
   ...

Imagine I want to interchange loops j and k, then unroll loop j
by a factor of 3.

The tool would output:

   ...
   for (i=0; i < N; ++i)
     for (k=0; k < N; ++k)
       for (j=0; j < N; j+=3)
       {
         C[i][j+0] += A[i][k]*B[k][j+0];
         C[i][j+1] += A[i][k]*B[k][j+1];
         C[i][j+2] += A[i][k]*B[k][j+2];
       }
   ...

(The rest of the program would remain unchanged.)

I was told I might be able to use SUIF 1.x and/or SUIF 2.x

I saw the TRANSFORM library in the SUIF 1.x documentation:
http://suif.stanford.edu/suif/suif1/docs/transform_toc.html

I did not see an equivalent in SUIF 2.x (perhaps I did not look in 
the right place).

Would SUIF 1.x be better suited than SUIF 2.x for my purpose?

I downloaded basesuif-1.3.0.5.tgz

In case someone is interested, here is the patch I applied to 
compile SUIF 1.3.0.5 successfully with gcc version 3.2.2 20030222 
(Red Hat Linux 3.2.2-5)

(Copy the patch above suifhome and use patch -p0 -b)

$ cat basesuif-1.3.0.5.patch
*** suifhome/src/basesuif/suif1/suif1.h Fri Oct 29 05:15:50 1999
--- suifhome/src/basesuif/suif1/suif1.h Tue Sep 21 15:25:57 2004
***************
*** 20,22 ****
   #else
! #define INCLFILE(F) <suif1/ ## F ## >
   #endif
--- 20,22 ----
   #else
! #define INCLFILE(F) <suif1/F>
   #endif
*** suifhome/Makefile.defs      Fri Oct 29 05:15:00 1999
--- suifhome/Makefile.defs      Tue Sep 21 15:29:12 2004
***************
*** 50,52 ****
   DEFAULT_SYSTEM_SPECIFIC_CFLAGS =      -g -Wall
! DEFAULT_SYSTEM_SPECIFIC_CXXFLAGS =    -g -pedantic 
-Wchar-subscripts -Wcomment -Wformat -Wimplicit -Wreturn-type 
-Wswitch -Wtrigraphs -Wreorder -Wpointer-arith -Wstrict-prototypes 
-Wmissing-prototypes -Wnested-externs -DINLINE_ALL_TEMPLATES 
$(USE_SUIF_STRIPPED_HEADERS)
   ifndef CC_OVERRIDE
--- 50,52 ----
   DEFAULT_SYSTEM_SPECIFIC_CFLAGS =      -g -Wall
! DEFAULT_SYSTEM_SPECIFIC_CXXFLAGS =    -g -Wall -pedantic 
-Wno-deprecated -fno-const-strings -fno-operator-names 
-DINLINE_ALL_TEMPLATES $(USE_SUIF_STRIPPED_HEADERS)
   ifndef CC_OVERRIDE

-Wno-deprecated (C++ only)
        Do not warn about usage of deprecated features.

-fno-const-strings
        Give string constants type "char *" instead of type
        "const char *". By default, G++ uses type "const char *"
        as required by the standard.  Even if you use
        -fno-const-strings, you cannot actually modify the value
        of a string constant, unless you also use -fwritable-strings.

-fno-operator-names
        Do not treat the operator name keywords "and", "bitand",
        "bitor", "compl", "not", "or" and "xor" as synonyms as
        keywords. (IMO, this description needs to be rephrased.)

One last comment, why does SUIF generate an incorrect preprocessor 
command line?

$ scc -v toto.c
CPP: /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cpp -D__SCC__ GNU 
-I/local/gonzalez/suif/suifhome/i386-redhat-linux/include -undef 
-U__GNUC__ -U__GNUC_MINOR__ toto.c /tmp/scc09600_0.i
cpp: too many input files
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/cpp -D__SCC__ GNU 
-I/local/gonzalez/suif/suifhome/i386-redhat-linux/include -undef 
-U__GNUC__ -U__GNUC_MINOR__ toto.c /tmp/scc09600_0.i
FAILED (exit status 0x1)

I think the problem comes from the "GNU" token.

In suifhome/src/basesuif/scc/commands.def

   String predefined_path(suif_top);
   predefined_path += '/';
   predefined_path += target_machine;
   predefined_path += "/predefined.txt";
   *p->flags[0] += " ";
   string_from_file(predefined_path.string(), p->flags[0]);

$ cat suifhome/i386-redhat-linux/predefined.txt
GNU

What is the purpose of predefined.txt? Did older versions of cpp 
accept flags without a "-" prefix?

Sorry for the long email and many questions. Thanks to anybody who's 
read this far!

-- 
Regards, Marc
_______________________________________________
To unsubscribe, send mail to [email protected]
or visit http://suif.stanford.edu/mailman/listinfo/suif-bugs