Subject: f77 -O causes optimizer to blow up (#81) Index: usr.bin/f77/{putdmr.c,dmrdefs} 2.11BSD Description: Use of the -O switch with f77 causes the optimizer (/lib/c2) to die. Repeat-By: Try using "f77 -O foo.f" with foo.f being approximately 400 lines long. Observe the core dump of /lib/c2. The problem is that 'c2' optimizes blocks of code between ".globl" statements and f77 was not generating ".globl" statements between functions. This was causing the generated code for the _entire_ Fortran program to appear as one block to be optimized. Needless to say 'c2' could not handle this except for trivial functions. Fix: The fix is to cause f77 to generate ".globl name" (where "name" is the Fortran routine name being compiled. Large functions will still be able to generate more code than 'c2' can handle (until such time as c2 is rewritten to use a workfile) but it will now be possible to turn on -O for many Fortran programs which previously caused the optimizer to crash. Also, the 'putc()' references were changed to 'fputc()' to save I space. The 'fputc' function is currently implemented in pdp-11 assembly, is almost as fast as the 'putc' macro and generates _far_ less code. Changing just the 5 references to 'putc' saved over 500 bytes of code! A few more space savings like that and the f77 compiler wouldn't have to be overlaid! A side effect of this fix is that after 'c2' optimizes the program the entry point to functions is at the top of the routine which makes debugging via 'adb' easier. Apply the patches below. Recompile and install f77pass1. This and previous updates to 2.11BSD are available via anonymous FTP to FTP.IIPO.GTEGSC.COM in the directory /pub/2.11BSD. ============================================================================= *** /usr/src/usr.bin/f77/putdmr.c.old Mon Feb 16 16:57:40 1987 --- /usr/src/usr.bin/f77/putdmr.c Thu Nov 12 21:57:38 1992 *************** *** 16,25 **** char *s; int class; { if( ! headerdone ) { p2op2(P2SETREG, ARGREG-maxregvar); ! p2op(P2PROG); headerdone = YES; #if TARGET == PDP11 /* fake jump to start the optimizer */ --- 16,40 ---- char *s; int class; { + if( ! headerdone ) { p2op2(P2SETREG, ARGREG-maxregvar); ! p2op(P2PROG); /* .text */ ! /* ! * 11/12/92, sms@192.26.147.1 ! * The optimizer (/lib/c2) works on blocks of code delimited by .globl ! * statements. Without the addition below the fortran program ends up ! * being one huge block which was causing the optimizer to blow up. Large ! * functions may still generate more code than /lib/c2 can handle, but for ! * the most part it is now safe to use "f77 -O". ! */ ! p2op(P2SYMDEF); /* .globl */ ! if (s) ! fprintf(textfile, "_%s", s); ! p2str(""); ! /* end 11/12/92 change */ ! headerdone = YES; #if TARGET == PDP11 /* fake jump to start the optimizer */ *************** *** 1198,1205 **** register char *s; s = &k; ! putc(*s++, textfile); ! putc(*s, textfile); } --- 1213,1220 ---- register char *s; s = &k; ! fputc(*s++, textfile); ! fputc(*s, textfile); } *************** *** 1208,1215 **** p2op(op) int op; { ! putc(op, textfile); ! putc(0376, textfile); /* MAGIC NUMBER */ } --- 1223,1230 ---- p2op(op) int op; { ! fputc(op, textfile); ! fputc(0376, textfile); /* MAGIC NUMBER */ } *************** *** 1219,1225 **** register char *s; { do ! putc(*s, textfile); while(*s++); } --- 1234,1240 ---- register char *s; { do ! fputc(*s, textfile); while(*s++); } *** /usr/src/usr.bin/f77/dmrdefs.old Sun Feb 22 00:46:20 1987 --- /usr/src/usr.bin/f77/dmrdefs Thu Nov 12 20:46:44 1992 *************** *** 55,60 **** --- 55,61 ---- #define P2SETREG 105 #define P2SETSTK 219 #define P2PROG 202 + #define P2SYMDEF 207 #define P2CHAR 1