OSDN Git Service

Add -mabi=n32 support.
[pf3gnuchains/gcc-fork.git] / gcc / final.c
index b046d78..47d4644 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert RTL to assembler code and output it, for GNU compiler.
-   Copyright (C) 1987, 88, 89, 92, 93, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1987, 88, 89, 92-5, 1996 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
 /* This is the final pass of the compiler.
@@ -121,6 +122,12 @@ static rtx debug_insn = 0;
 /* Line number of last NOTE.  */
 static int last_linenum;
 
+/* Highest line number in current block.  */
+static int high_block_linenum;
+
+/* Likewise for function.  */
+static int high_function_linenum;
+
 /* Filename of last NOTE.  */
 static char *last_filename;
 
@@ -270,6 +277,7 @@ static int add_bb_string    PROTO((char *, int));
 static void output_source_line PROTO((FILE *, rtx));
 static rtx walk_alter_subreg   PROTO((rtx));
 static int alter_cond          PROTO((rtx));
+static void output_asm_name    PROTO((void));
 static void output_operand     PROTO((rtx, int));
 static void leaf_renumber_regs PROTO((rtx));
 
@@ -316,8 +324,8 @@ end_final (filename)
 
       data_section ();
 
-      /* Output the main header, of 10 words:
-        0:  1 if this file's initialized, else 0.
+      /* Output the main header, of 11 words:
+        0:  1 if this file is initialized, else 0.
         1:  address of file name (LPBX1).
         2:  address of table of counts (LPBX2).
         3:  number of counts in the table.
@@ -329,7 +337,8 @@ end_final (filename)
         6:  Number of bytes in this header.
         7:  address of table of function names (LPBX4).
         8:  address of table of line numbers (LPBX5) or 0.
-        9:  address of table of file names (LPBX6) or 0.  */
+        9:  address of table of file names (LPBX6) or 0.
+       10:  space reserved for basic block profiling. */
 
       ASM_OUTPUT_ALIGN (asm_out_file, align);
 
@@ -356,7 +365,7 @@ end_final (filename)
       assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
 
       /* byte count for extended structure.  */
-      assemble_integer (GEN_INT (10 * UNITS_PER_WORD), UNITS_PER_WORD, 1);
+      assemble_integer (GEN_INT (11 * UNITS_PER_WORD), UNITS_PER_WORD, 1);
 
       /* address of function name table */
       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
@@ -376,6 +385,9 @@ end_final (filename)
          assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
        }
 
+      /* space for extension ptr (link field) */
+      assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
+
       /* Output the file name changing the suffix to .d for Sun tcov
         compatibility.  */
       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
@@ -393,7 +405,7 @@ end_final (filename)
       }
 
       /* Make space for the table of counts.  */
-      if (flag_no_common || size == 0)
+      if (size == 0)
        {
          /* Realign data section.  */
          ASM_OUTPUT_ALIGN (asm_out_file, align);
@@ -808,6 +820,9 @@ shorten_branches (first)
              something_changed = 1;
            }
        }
+      /* For a non-optimizing compile, do only a single pass.  */
+      if (!optimize)
+       break;
     }
 #endif /* HAVE_ATTR_length */
 }
@@ -876,24 +891,27 @@ final_start_function (first, file, optimize)
      so that the function's address will not appear to be
      in the last statement of the preceding function.  */
   if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
-    {
-      if (write_symbols == SDB_DEBUG)
-       /* For sdb, let's not, but say we did.
-          We need to set last_linenum for sdbout_function_begin,
-          but we can't have an actual line number before the .bf symbol.
-          (sdb_begin_function_line is not set,
-          and other compilers don't do it.)  */
-       last_linenum = NOTE_LINE_NUMBER (first);
+    last_linenum = high_block_linenum = high_function_linenum
+      = NOTE_LINE_NUMBER (first);
+
+  /* For SDB and XCOFF, the function beginning must be marked between
+     the function label and the prologue.  We always need this, even when
+     -g1 was used.  Defer on MIPS systems so that parameter descriptions
+     follow function entry. */
+#if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
+  if (write_symbols == SDB_DEBUG)
+    sdbout_begin_function (last_linenum);
+  else
+#endif
 #ifdef XCOFF_DEBUGGING_INFO
-      else if (write_symbols == XCOFF_DEBUG)
-       {
-         last_linenum = NOTE_LINE_NUMBER (first);
-         xcoffout_output_first_source_line (file, last_linenum);
-       }
+    if (write_symbols == XCOFF_DEBUG)
+      xcoffout_begin_function (file, last_linenum);
+    else
 #endif   
-      else
+      /* But only output line number for other debug info types if -g2
+        or better.  */
+      if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
        output_source_line (file, first);
-    }
 
 #ifdef LEAF_REG_REMAP
   if (leaf_function)
@@ -943,7 +961,7 @@ profile_after_prologue (file)
 #ifdef FUNCTION_BLOCK_PROFILER
   if (profile_block_flag)
     {
-      FUNCTION_BLOCK_PROFILER (file, profile_label_no);
+      FUNCTION_BLOCK_PROFILER (file, count_basic_blocks);
     }
 #endif /* FUNCTION_BLOCK_PROFILER */
 
@@ -1033,7 +1051,7 @@ final_end_function (first, file, optimize)
 
 #ifdef SDB_DEBUGGING_INFO
   if (write_symbols == SDB_DEBUG)
-    sdbout_end_function (last_linenum);
+    sdbout_end_function (high_function_linenum);
 #endif
 
 #ifdef DWARF_DEBUGGING_INFO
@@ -1043,7 +1061,7 @@ final_end_function (first, file, optimize)
 
 #ifdef XCOFF_DEBUGGING_INFO
   if (write_symbols == XCOFF_DEBUG)
-    xcoffout_end_function (file, last_linenum);
+    xcoffout_end_function (file, high_function_linenum);
 #endif
 
 #ifdef FUNCTION_EPILOGUE
@@ -1301,15 +1319,16 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
        break;
       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
        {
-#ifdef SDB_DEBUGGING_INFO
+#if defined(SDB_DEBUGGING_INFO) && defined(MIPS_DEBUGGING_INFO)
+         /* MIPS stabs require the parameter descriptions to be after the
+            function entry point rather than before. */
          if (write_symbols == SDB_DEBUG)
            sdbout_begin_function (last_linenum);
-#endif
-#ifdef XCOFF_DEBUGGING_INFO
-         if (write_symbols == XCOFF_DEBUG)
-           xcoffout_begin_function (file, last_linenum);
+         else
 #endif
 #ifdef DWARF_DEBUGGING_INFO
+         /* This outputs a marker where the function body starts, so it
+            must be after the prologue.  */
          if (write_symbols == DWARF_DEBUG)
            dwarfout_begin_function ();
 #endif
@@ -1344,6 +1363,8 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
            }
          pending_blocks[block_depth++] = next_block_index;
 
+         high_block_linenum = last_linenum;
+
          /* Output debugging info about the symbol-block beginning.  */
 
 #ifdef SDB_DEBUGGING_INFO
@@ -1381,7 +1402,8 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
 
 #ifdef XCOFF_DEBUGGING_INFO
          if (write_symbols == XCOFF_DEBUG && block_depth >= 0)
-           xcoffout_end_block (file, last_linenum, pending_blocks[block_depth]);
+           xcoffout_end_block (file, high_block_linenum,
+                               pending_blocks[block_depth]);
 #endif
 #ifdef DBX_DEBUGGING_INFO
          if (write_symbols == DBX_DEBUG && block_depth >= 0)
@@ -1390,7 +1412,8 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
 #endif
 #ifdef SDB_DEBUGGING_INFO
          if (write_symbols == SDB_DEBUG && block_depth >= 0)
-           sdbout_end_block (file, last_linenum, pending_blocks[block_depth]);
+           sdbout_end_block (file, high_block_linenum,
+                             pending_blocks[block_depth]);
 #endif
 #ifdef DWARF_DEBUGGING_INFO
          if (write_symbols == DWARF_DEBUG && block_depth >= 1)
@@ -1468,6 +1491,11 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
       if (prescan > 0)
        break;
       new_block = 1;
+
+#ifdef FINAL_PRESCAN_LABEL
+      FINAL_PRESCAN_INSN (insn, NULL_PTR, 0);
+#endif
+
 #ifdef SDB_DEBUGGING_INFO
       if (write_symbols == SDB_DEBUG && LABEL_NAME (insn))
        sdbout_label (insn);
@@ -1501,7 +1529,7 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
                                            / BITS_PER_UNIT));
 #endif /* READONLY_DATA_SECTION */
 #else /* JUMP_TABLES_IN_TEXT_SECTION */
-             text_section ();
+             function_section (current_function_decl);
 #endif /* JUMP_TABLES_IN_TEXT_SECTION */
 #ifdef ASM_OUTPUT_CASE_LABEL
              ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
@@ -1590,7 +1618,7 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
                                 insn);
 #endif
 
-           text_section ();
+           function_section (current_function_decl);
 
            break;
          }
@@ -1675,7 +1703,15 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
              }
 
            for (i = 1; i < XVECLEN (body, 0); i++)
-             final_scan_insn (XVECEXP (body, 0, i), file, 0, prescan, 1);
+             {
+               rtx insn = XVECEXP (body, 0, i);
+               rtx next = NEXT_INSN (insn);
+               /* We loop in case any instruction in a delay slot gets
+                  split.  */
+               do
+                 insn = final_scan_insn (insn, file, 0, prescan, 1);
+               while (insn != next);
+             }
 #ifdef DBR_OUTPUT_SEQEND
            DBR_OUTPUT_SEQEND (file);
 #endif
@@ -1720,35 +1756,39 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
           and the next statement should reexamine the variable
           to compute the condition codes.  */
 
-       if (optimize
-           && GET_CODE (body) == SET
-           && GET_CODE (SET_DEST (body)) == CC0
-           && insn != last_ignored_compare)
+       if (optimize)
          {
-           if (GET_CODE (SET_SRC (body)) == SUBREG)
-             SET_SRC (body) = alter_subreg (SET_SRC (body));
-           else if (GET_CODE (SET_SRC (body)) == COMPARE)
-             {
-               if (GET_CODE (XEXP (SET_SRC (body), 0)) == SUBREG)
-                 XEXP (SET_SRC (body), 0)
-                   = alter_subreg (XEXP (SET_SRC (body), 0));
-               if (GET_CODE (XEXP (SET_SRC (body), 1)) == SUBREG)
-                 XEXP (SET_SRC (body), 1)
-                   = alter_subreg (XEXP (SET_SRC (body), 1));
-             }
-           if ((cc_status.value1 != 0
-                && rtx_equal_p (SET_SRC (body), cc_status.value1))
-               || (cc_status.value2 != 0
-                   && rtx_equal_p (SET_SRC (body), cc_status.value2)))
+           rtx set = single_set(insn);
+
+           if (set
+               && GET_CODE (SET_DEST (set)) == CC0
+               && insn != last_ignored_compare)
              {
-               /* Don't delete insn if it has an addressing side-effect.  */
-               if (! FIND_REG_INC_NOTE (insn, 0)
-                   /* or if anything in it is volatile.  */
-                   && ! volatile_refs_p (PATTERN (insn)))
+               if (GET_CODE (SET_SRC (set)) == SUBREG)
+                 SET_SRC (set) = alter_subreg (SET_SRC (set));
+               else if (GET_CODE (SET_SRC (set)) == COMPARE)
                  {
-                   /* We don't really delete the insn; just ignore it.  */
-                   last_ignored_compare = insn;
-                   break;
+                   if (GET_CODE (XEXP (SET_SRC (set), 0)) == SUBREG)
+                     XEXP (SET_SRC (set), 0)
+                       = alter_subreg (XEXP (SET_SRC (set), 0));
+                   if (GET_CODE (XEXP (SET_SRC (set), 1)) == SUBREG)
+                     XEXP (SET_SRC (set), 1)
+                       = alter_subreg (XEXP (SET_SRC (set), 1));
+                 }
+               if ((cc_status.value1 != 0
+                    && rtx_equal_p (SET_SRC (set), cc_status.value1))
+                   || (cc_status.value2 != 0
+                       && rtx_equal_p (SET_SRC (set), cc_status.value2)))
+                 {
+                   /* Don't delete insn if it has an addressing side-effect.  */
+                   if (! FIND_REG_INC_NOTE (insn, 0)
+                       /* or if anything in it is volatile.  */
+                       && ! volatile_refs_p (PATTERN (insn)))
+                     {
+                       /* We don't really delete the insn; just ignore it.  */
+                       last_ignored_compare = insn;
+                       break;
+                     }
                  }
              }
          }
@@ -1790,6 +1830,8 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
            && GET_CODE (body) == SET
            && SET_DEST (body) == pc_rtx
            && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
+           && GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (body), 0))) == '<'
+           && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx
            /* This is done during prescan; it is not done again
               in final scan when prescan has been done.  */
            && prescan >= 0)
@@ -1827,12 +1869,29 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
          }
 
        /* Make same adjustments to instructions that examine the
-          condition codes without jumping (if this machine has them).  */
+          condition codes without jumping and instructions that
+          handle conditional moves (if this machine has either one).  */
 
        if (cc_status.flags != 0
            && GET_CODE (body) == SET)
          {
-           switch (GET_CODE (SET_SRC (body)))
+           rtx cond_rtx, then_rtx, else_rtx;
+           
+           if (GET_CODE (insn) != JUMP_INSN
+               && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE)
+             {
+               cond_rtx = XEXP (SET_SRC (body), 0);
+               then_rtx = XEXP (SET_SRC (body), 1);
+               else_rtx = XEXP (SET_SRC (body), 2);
+             }
+           else
+             {
+               cond_rtx = SET_SRC (body);
+               then_rtx = const_true_rtx;
+               else_rtx = const0_rtx;
+             }
+           
+           switch (GET_CODE (cond_rtx))
              {
              case GTU:
              case GT:
@@ -1846,18 +1905,26 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
              case NE:
                {
                  register int result;
-                 if (XEXP (SET_SRC (body), 0) != cc0_rtx)
+                 if (XEXP (cond_rtx, 0) != cc0_rtx)
                    break;
-                 result = alter_cond (SET_SRC (body));
+                 result = alter_cond (cond_rtx);
                  if (result == 1)
-                   validate_change (insn, &SET_SRC (body), const_true_rtx, 0);
+                   validate_change (insn, &SET_SRC (body), then_rtx, 0);
                  else if (result == -1)
-                   validate_change (insn, &SET_SRC (body), const0_rtx, 0);
+                   validate_change (insn, &SET_SRC (body), else_rtx, 0);
                  else if (result == 2)
                    INSN_CODE (insn) = -1;
+                 if (SET_DEST (body) == SET_SRC (body))
+                   {
+                     PUT_CODE (insn, NOTE);
+                     NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
+                     NOTE_SOURCE_FILE (insn) = 0;
+                     break;
+                   }
                }
              }
          }
+
 #endif
 
        /* Do machine-specific peephole optimizations if desired.  */
@@ -2018,6 +2085,8 @@ output_source_line (file, insn)
 
   last_filename = filename;
   last_linenum = NOTE_LINE_NUMBER (insn);
+  high_block_linenum = MAX (last_linenum, high_block_linenum);
+  high_function_linenum = MAX (last_linenum, high_function_linenum);
 
   if (write_symbols != NO_DEBUG)
     {
@@ -2301,6 +2370,28 @@ output_operand_lossage (str)
       and print a constant expression for minus the value
       of the operand, with no other punctuation.  */
 
+static void
+output_asm_name ()
+{
+  if (flag_print_asm_name)
+    {
+      /* Annotate the assembly with a comment describing the pattern and
+        alternative used.  */
+      if (debug_insn)
+       {
+         register int num = INSN_CODE (debug_insn);
+         fprintf (asm_out_file, " %s %d %s", 
+                  ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
+         if (insn_n_alternatives[num] > 1)
+           fprintf (asm_out_file, "/%d", which_alternative + 1);
+
+         /* Clear this so only the first assembler insn
+            of any rtl insn will get the special comment for -dp.  */
+         debug_insn = 0;
+       }
+    }
+}
+
 void
 output_asm_insn (template, operands)
      char *template;
@@ -2324,17 +2415,18 @@ output_asm_insn (template, operands)
   while (c = *p++)
     switch (c)
       {
-#ifdef ASM_OUTPUT_OPCODE
       case '\n':
+       output_asm_name ();
        putc (c, asm_out_file);
+#ifdef ASM_OUTPUT_OPCODE
        while ((c = *p) == '\t')
          {
            putc (c, asm_out_file);
            p++;
          }
        ASM_OUTPUT_OPCODE (asm_out_file, p);
-       break;
 #endif
+       break;
 
 #ifdef ASSEMBLER_DIALECT
       case '{':
@@ -2447,23 +2539,7 @@ output_asm_insn (template, operands)
        putc (c, asm_out_file);
       }
 
-  if (flag_print_asm_name)
-    {
-      /* Annotate the assembly with a comment describing the pattern and
-        alternative used.  */
-      if (debug_insn)
-       {
-         register int num = INSN_CODE (debug_insn);
-         fprintf (asm_out_file, " %s %d %s", 
-                  ASM_COMMENT_START, INSN_UID (debug_insn), insn_name[num]);
-         if (insn_n_alternatives[num] > 1)
-           fprintf (asm_out_file, "/%d", which_alternative + 1);
-
-         /* Clear this so only the first assembler insn
-            of any rtl insn will get the special comment for -dp.  */
-         debug_insn = 0;
-       }
-    }
+  output_asm_name ();
 
   putc ('\n', asm_out_file);
 }
@@ -2834,19 +2910,46 @@ split_double (value, first, second)
 {
   if (GET_CODE (value) == CONST_INT)
     {
-      /* The rule for using CONST_INT for a wider mode
-        is that we regard the value as signed.
-        So sign-extend it.  */
-      rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
-      if (WORDS_BIG_ENDIAN)
+      if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
        {
-         *first = high;
-         *second = value;
+         /* In this case the CONST_INT holds both target words.
+            Extract the bits from it into two word-sized pieces.  */
+         rtx low, high;
+         HOST_WIDE_INT word_mask;
+         /* Avoid warnings for shift count >= BITS_PER_WORD.  */
+         int shift_count = BITS_PER_WORD - 1;
+
+         word_mask = (HOST_WIDE_INT) 1 << shift_count;
+         word_mask |= word_mask - 1;
+         low = GEN_INT (INTVAL (value) & word_mask);
+         high = GEN_INT ((INTVAL (value) >> (shift_count + 1)) & word_mask);
+         if (WORDS_BIG_ENDIAN)
+           {
+             *first = high;
+             *second = low;
+           }
+         else
+           {
+             *first = low;
+             *second = high;
+           }
        }
       else
        {
-         *first = value;
-         *second = high;
+         /* The rule for using CONST_INT for a wider mode
+            is that we regard the value as signed.
+            So sign-extend it.  */
+         rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
+         if (WORDS_BIG_ENDIAN)
+           {
+             *first = high;
+             *second = value;
+           }
+         else
+           {
+             *first = value;
+             *second = high;
+           }
        }
     }
   else if (GET_CODE (value) != CONST_DOUBLE)