OSDN Git Service

* tree.c (unsave_expr_now): Avoid recursing into the parts of
[pf3gnuchains/gcc-fork.git] / gcc / final.c
index 4de4e12..91ad498 100644 (file)
@@ -1,5 +1,5 @@
 /* Convert RTL to assembler code and output it, for GNU compiler.
-   Copyright (C) 1987, 88, 89, 92-5, 1996 Free Software Foundation, Inc.
+   Copyright (C) 1987, 88, 89, 92-6, 1997 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -67,6 +67,7 @@ Boston, MA 02111-1307, USA.  */
 #include "hard-reg-set.h"
 #include "defaults.h"
 #include "output.h"
+#include "except.h"
 
 /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist.  */
 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
@@ -95,6 +96,10 @@ Boston, MA 02111-1307, USA.  */
 #define INT_TYPE_SIZE BITS_PER_WORD
 #endif
 
+#ifndef LONG_TYPE_SIZE
+#define LONG_TYPE_SIZE BITS_PER_WORD
+#endif
+
 /* If we aren't using cc0, CC_STATUS_INIT shouldn't exist.  So define a
    null default for it to save conditionalization later.  */
 #ifndef CC_STATUS_INIT
@@ -135,6 +140,9 @@ static char *last_filename;
    used if profile_block_flag is set.  */
 static int count_basic_blocks;
 
+/* Number of instrumented arcs when profile_arc_flag is set.  */
+extern int count_instrumented_arcs;
+
 /* Nonzero while outputting an `asm' with operands.
    This means that inconsistencies are the user's fault, so don't abort.
    The precise value is the insn being output, to pass to error_for_asm.  */
@@ -309,14 +317,21 @@ end_final (filename)
 {
   int i;
 
-  if (profile_block_flag)
+  if (profile_block_flag || profile_arc_flag)
     {
       char name[20];
       int align = exact_log2 (BIGGEST_ALIGNMENT / BITS_PER_UNIT);
-      int size = (POINTER_SIZE / BITS_PER_UNIT) * count_basic_blocks;
-      int rounded = size;
+      int size, rounded;
       struct bb_list *ptr;
       struct bb_str *sptr;
+      int long_bytes = LONG_TYPE_SIZE / BITS_PER_UNIT;
+      int pointer_bytes = POINTER_SIZE / BITS_PER_UNIT;
+
+      if (profile_block_flag)
+       size = long_bytes * count_basic_blocks;
+      else
+       size = long_bytes * count_instrumented_arcs;
+      rounded = size;
 
       rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
       rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
@@ -338,51 +353,67 @@ end_final (filename)
         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.
-       10:  space reserved for basic block profiling. */
+       10:  space reserved for basic block profiling.  */
 
       ASM_OUTPUT_ALIGN (asm_out_file, align);
 
       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
       /* zero word */
-      assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
+      assemble_integer (const0_rtx, long_bytes, 1);
 
       /* address of filename */
       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
-      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
+      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), pointer_bytes, 1);
 
       /* address of count table */
       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
-      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
+      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), pointer_bytes, 1);
 
-      /* count of the # of basic blocks */
-      assemble_integer (GEN_INT (count_basic_blocks), UNITS_PER_WORD, 1);
+      /* count of the # of basic blocks or # of instrumented arcs */
+      if (profile_block_flag)
+       assemble_integer (GEN_INT (count_basic_blocks), long_bytes, 1);
+      else
+       assemble_integer (GEN_INT (count_instrumented_arcs), long_bytes,
+                         1);
 
       /* zero word (link field) */
-      assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
+      assemble_integer (const0_rtx, pointer_bytes, 1);
 
       /* address of basic block start address table */
-      ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
-      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
+      if (profile_block_flag)
+       {
+         ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
+         assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), pointer_bytes,
+                           1);
+       }
+      else
+       assemble_integer (const0_rtx, pointer_bytes, 1);
 
       /* byte count for extended structure.  */
-      assemble_integer (GEN_INT (11 * UNITS_PER_WORD), UNITS_PER_WORD, 1);
+      assemble_integer (GEN_INT (10 * UNITS_PER_WORD), long_bytes, 1);
 
       /* address of function name table */
-      ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
-      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
+      if (profile_block_flag)
+       {
+         ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 4);
+         assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), pointer_bytes,
+                           1);
+       }
+      else
+       assemble_integer (const0_rtx, pointer_bytes, 1);
 
       /* address of line number and filename tables if debugging.  */
-      if (write_symbols != NO_DEBUG)
+      if (write_symbols != NO_DEBUG && profile_block_flag)
        {
          ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 5);
-         assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
+         assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), pointer_bytes, 1);
          ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 6);
-         assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
+         assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), pointer_bytes, 1);
        }
       else
        {
-         assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
-         assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
+         assemble_integer (const0_rtx, pointer_bytes, 1);
+         assemble_integer (const0_rtx, pointer_bytes, 1);
        }
 
       /* space for extension ptr (link field) */
@@ -400,7 +431,10 @@ end_final (filename)
        strcat (data_file, "/");
        strcat (data_file, filename);
        strip_off_ending (data_file, len);
-       strcat (data_file, ".d");
+       if (profile_block_flag)
+         strcat (data_file, ".d");
+       else
+         strcat (data_file, ".da");
        assemble_string (data_file, strlen (data_file) + 1);
       }
 
@@ -430,54 +464,65 @@ end_final (filename)
        }
 
       /* Output any basic block strings */
-      readonly_data_section ();
-      if (sbb_head)
+      if (profile_block_flag)
        {
-         ASM_OUTPUT_ALIGN (asm_out_file, align);
-         for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
+         readonly_data_section ();
+         if (sbb_head)
            {
-             ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC", sptr->label_num);
-             assemble_string (sptr->string, sptr->length);
+             ASM_OUTPUT_ALIGN (asm_out_file, align);
+             for (sptr = sbb_head; sptr != 0; sptr = sptr->next)
+               {
+                 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBC",
+                                            sptr->label_num);
+                 assemble_string (sptr->string, sptr->length);
+               }
            }
        }
 
       /* Output the table of addresses.  */
-      /* Realign in new section */
-      ASM_OUTPUT_ALIGN (asm_out_file, align);
-      ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
-      for (i = 0; i < count_basic_blocks; i++)
+      if (profile_block_flag)
        {
-         ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
-         assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
-                           UNITS_PER_WORD, 1);
+         /* Realign in new section */
+         ASM_OUTPUT_ALIGN (asm_out_file, align);
+         ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
+         for (i = 0; i < count_basic_blocks; i++)
+           {
+             ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
+             assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
+                               pointer_bytes, 1);
+           }
        }
 
       /* Output the table of function names.  */
-      ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
-      for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
+      if (profile_block_flag)
        {
-         if (ptr->func_label_num >= 0)
+         ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 4);
+         for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
            {
-             ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->func_label_num);
-             assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
-                               UNITS_PER_WORD, 1);
+             if (ptr->func_label_num >= 0)
+               {
+                 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
+                                              ptr->func_label_num);
+                 assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
+                                   pointer_bytes, 1);
+               }
+             else
+               assemble_integer (const0_rtx, pointer_bytes, 1);
            }
-         else
-           assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
-       }
 
-      for ( ; i < count_basic_blocks; i++)
-       assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
+         for ( ; i < count_basic_blocks; i++)
+           assemble_integer (const0_rtx, pointer_bytes, 1);
+       }
 
-      if (write_symbols != NO_DEBUG)
+      if (write_symbols != NO_DEBUG && profile_block_flag)
        {
          /* Output the table of line numbers.  */
          ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 5);
          for ((ptr = bb_head), (i = 0); ptr != 0; (ptr = ptr->next), i++)
-           assemble_integer (GEN_INT (ptr->line_num), UNITS_PER_WORD, 1);
+           assemble_integer (GEN_INT (ptr->line_num), long_bytes, 1);
 
          for ( ; i < count_basic_blocks; i++)
-           assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
+           assemble_integer (const0_rtx, long_bytes, 1);
 
          /* Output the table of file names.  */
          ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 6);
@@ -485,22 +530,27 @@ end_final (filename)
            {
              if (ptr->file_label_num >= 0)
                {
-                 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC", ptr->file_label_num);
+                 ASM_GENERATE_INTERNAL_LABEL (name, "LPBC",
+                                              ptr->file_label_num);
                  assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name),
-                                   UNITS_PER_WORD, 1);
+                                   pointer_bytes, 1);
                }
              else
-               assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
+               assemble_integer (const0_rtx, pointer_bytes, 1);
            }
 
          for ( ; i < count_basic_blocks; i++)
-           assemble_integer (const0_rtx, UNITS_PER_WORD, 1);
+           assemble_integer (const0_rtx, pointer_bytes, 1);
        }
 
       /* End with the address of the table of addresses,
         so we can find it easily, as the last word in the file's text.  */
-      ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
-      assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), UNITS_PER_WORD, 1);
+      if (profile_block_flag)
+       {
+         ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
+         assemble_integer (gen_rtx (SYMBOL_REF, Pmode, name), pointer_bytes,
+                           1);
+       }
     }
 }
 
@@ -654,6 +704,13 @@ shorten_branches (first)
   rtx body;
   int uid;
 
+  /* In order to make sure that all instructions have valid length info,
+     we must split them before we compute the address/length info.  */
+
+  for (insn = NEXT_INSN (first); insn; insn = NEXT_INSN (insn))
+    if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
+      insn = try_split (PATTERN (insn), insn, 1);
+
   /* Compute maximum UID and allocate arrays.  */
   for (insn = first; insn; insn = NEXT_INSN (insn))
     if (INSN_UID (insn) > max_uid)
@@ -709,7 +766,7 @@ shorten_branches (first)
 #endif
          /* Inside a delay slot sequence, we do not do any branch shortening
             if the shortening could change the number of delay slots
-            of the branch. */
+            of the branch.  */
          for (i = 0; i < XVECLEN (body, 0); i++)
            {
              rtx inner_insn = XVECEXP (body, 0, i);
@@ -894,10 +951,16 @@ final_start_function (first, file, optimize)
     last_linenum = high_block_linenum = high_function_linenum
       = NOTE_LINE_NUMBER (first);
 
+#ifdef DWARF2_DEBUGGING_INFO
+  /* Output DWARF definition of the function.  */
+  if (write_symbols == DWARF2_DEBUG)
+    dwarf2out_begin_prologue ();
+#endif
+
   /* 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. */
+     follow function entry.  */
 #if defined(SDB_DEBUGGING_INFO) && !defined(MIPS_DEBUGGING_INFO)
   if (write_symbols == SDB_DEBUG)
     sdbout_begin_function (last_linenum);
@@ -948,9 +1011,8 @@ final_start_function (first, file, optimize)
      of the function name.  */
   if (profile_block_flag)
     {
-      char *junk = "function";
-      bb_func_label_num =
-       add_bb_string ((*decl_printable_name) (current_function_decl, &junk), FALSE);
+      bb_func_label_num
+       = add_bb_string ((*decl_printable_name) (current_function_decl, 2), FALSE);
     }
 }
 
@@ -975,58 +1037,54 @@ static void
 profile_function (file)
      FILE *file;
 {
-  int align = MIN (BIGGEST_ALIGNMENT, POINTER_SIZE);
+  int align = MIN (BIGGEST_ALIGNMENT, LONG_TYPE_SIZE);
   int sval = current_function_returns_struct;
   int cxt = current_function_needs_context;
 
   data_section ();
   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
   ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
-  assemble_integer (const0_rtx, POINTER_SIZE / BITS_PER_UNIT, 1);
+  assemble_integer (const0_rtx, LONG_TYPE_SIZE / BITS_PER_UNIT, 1);
 
-  text_section ();
+  function_section (current_function_decl);
 
-#ifdef STRUCT_VALUE_INCOMING_REGNUM
+#if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
   if (sval)
     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
 #else
-#ifdef STRUCT_VALUE_REGNUM
+#if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
   if (sval)
     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
 #endif
 #endif
 
-#if 0
-#ifdef STATIC_CHAIN_INCOMING_REGNUM
+#if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
   if (cxt)
     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
 #else
-#ifdef STATIC_CHAIN_REGNUM
+#if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
   if (cxt)
     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
 #endif
 #endif
-#endif                         /* 0 */
 
   FUNCTION_PROFILER (file, profile_label_no);
 
-#if 0
-#ifdef STATIC_CHAIN_INCOMING_REGNUM
+#if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
   if (cxt)
     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
 #else
-#ifdef STATIC_CHAIN_REGNUM
+#if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
   if (cxt)
     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
 #endif
 #endif
-#endif                         /* 0 */
 
-#ifdef STRUCT_VALUE_INCOMING_REGNUM
+#if defined(STRUCT_VALUE_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
   if (sval)
     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
 #else
-#ifdef STRUCT_VALUE_REGNUM
+#if defined(STRUCT_VALUE_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
   if (sval)
     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
 #endif
@@ -1080,6 +1138,11 @@ final_end_function (first, file, optimize)
     dwarfout_end_epilogue ();
 #endif
 
+#ifdef DWARF2_DEBUGGING_INFO
+  if (write_symbols == DWARF2_DEBUG)
+    dwarf2out_end_epilogue ();
+#endif
+
 #ifdef XCOFF_DEBUGGING_INFO
   if (write_symbols == XCOFF_DEBUG)
     xcoffout_end_epilogue (file);
@@ -1117,6 +1180,8 @@ add_bb (file)
      count of times it was entered.  */
 #ifdef BLOCK_PROFILER
   BLOCK_PROFILER (file, count_basic_blocks);
+#endif
+#ifdef HAVE_cc0
   CC_STATUS_INIT;
 #endif
 
@@ -1152,7 +1217,7 @@ add_bb_string (string, perm_p)
       string = p;
     }
   else
-    for (ptr = sbb_head; ptr != (struct bb_str *)0; ptr = ptr->next)
+    for (ptr = sbb_head; ptr != (struct bb_str *) 0; ptr = ptr->next)
       if (ptr->string == string)
        break;
 
@@ -1196,6 +1261,12 @@ final (first, file, optimize, prescan)
   last_ignored_compare = 0;
   new_block = 1;
 
+#if defined (DWARF2_DEBUGGING_INFO) && defined (HAVE_prologue)
+  dwarf2out_frame_debug (NULL_RTX);
+#endif
+
+  check_exception_handler_labels ();
+
   /* Make a map indicating which line numbers appear in this function.
      When producing SDB debugging info, delete troublesome line number
      notes from inlined functions in other files as well as duplicate
@@ -1243,7 +1314,12 @@ final (first, file, optimize, prescan)
 
   /* Output the insns.  */
   for (insn = NEXT_INSN (first); insn;)
-    insn = final_scan_insn (insn, file, optimize, prescan, 0);
+    {
+#ifdef HAVE_ATTR_length
+      insn_current_address = insn_addresses[INSN_UID (insn)];
+#endif
+      insn = final_scan_insn (insn, file, optimize, prescan, 0);
+    }
 
   /* Do basic-block profiling here
      if the last insn was a conditional branch.  */
@@ -1298,6 +1374,25 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
        break;
 
+      if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
+       {
+         ASM_OUTPUT_INTERNAL_LABEL (file, "LEHB", NOTE_BLOCK_NUMBER (insn));
+         add_eh_table_entry (NOTE_BLOCK_NUMBER (insn));
+#ifdef ASM_OUTPUT_EH_REGION_BEG
+         ASM_OUTPUT_EH_REGION_BEG (file, NOTE_BLOCK_NUMBER (insn));
+#endif
+         break;
+       }
+
+      if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
+       {
+         ASM_OUTPUT_INTERNAL_LABEL (file, "LEHE", NOTE_BLOCK_NUMBER (insn));
+#ifdef ASM_OUTPUT_EH_REGION_END
+         ASM_OUTPUT_EH_REGION_END (file, NOTE_BLOCK_NUMBER (insn));
+#endif
+         break;
+       }
+
       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
        {
 #ifdef FUNCTION_END_PROLOGUE
@@ -1321,7 +1416,7 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
        {
 #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. */
+            function entry point rather than before.  */
          if (write_symbols == SDB_DEBUG)
            sdbout_begin_function (last_linenum);
          else
@@ -1344,11 +1439,8 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
          && (debug_info_level == DINFO_LEVEL_NORMAL
              || debug_info_level == DINFO_LEVEL_VERBOSE
-#ifdef DWARF_DEBUGGING_INFO
              || write_symbols == DWARF_DEBUG
-#endif
-            )
-        )
+             || write_symbols == DWARF2_DEBUG))
        {
          /* Beginning of a symbol-block.  Assign it a sequence number
             and push the number onto the stack PENDING_BLOCKS.  */
@@ -1380,20 +1472,21 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
            ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
 #endif
 #ifdef DWARF_DEBUGGING_INFO
-         if (write_symbols == DWARF_DEBUG && block_depth > 1)
+         if (write_symbols == DWARF_DEBUG)
            dwarfout_begin_block (next_block_index);
 #endif
+#ifdef DWARF2_DEBUGGING_INFO
+         if (write_symbols == DWARF2_DEBUG)
+           dwarf2out_begin_block (next_block_index);
+#endif
 
          next_block_index++;
        }
       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END
               && (debug_info_level == DINFO_LEVEL_NORMAL
                   || debug_info_level == DINFO_LEVEL_VERBOSE
-#ifdef DWARF_DEBUGGING_INFO
                   || write_symbols == DWARF_DEBUG
-#endif
-                 )
-             )
+                  || write_symbols == DWARF2_DEBUG))
        {
          /* End of a symbol-block.  Pop its sequence number off
             PENDING_BLOCKS and output debugging info based on that.  */
@@ -1416,9 +1509,13 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
                              pending_blocks[block_depth]);
 #endif
 #ifdef DWARF_DEBUGGING_INFO
-         if (write_symbols == DWARF_DEBUG && block_depth >= 1)
+         if (write_symbols == DWARF_DEBUG && block_depth >= 0)
            dwarfout_end_block (pending_blocks[block_depth]);
 #endif
+#ifdef DWARF2_DEBUGGING_INFO
+         if (write_symbols == DWARF2_DEBUG && block_depth >= 0)
+           dwarf2out_end_block (pending_blocks[block_depth]);
+#endif
        }
       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL
               && (debug_info_level == DINFO_LEVEL_NORMAL
@@ -1428,6 +1525,10 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
           if (write_symbols == DWARF_DEBUG)
             dwarfout_label (insn);
 #endif
+#ifdef DWARF2_DEBUGGING_INFO
+          if (write_symbols == DWARF2_DEBUG)
+            dwarf2out_label (insn);
+#endif
        }
       else if (NOTE_LINE_NUMBER (insn) > 0)
        /* This note is a line-number.  */
@@ -1504,6 +1605,10 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
       if (write_symbols == DWARF_DEBUG && LABEL_NAME (insn))
        dwarfout_label (insn);
 #endif
+#ifdef DWARF2_DEBUGGING_INFO
+      if (write_symbols == DWARF2_DEBUG && LABEL_NAME (insn))
+       dwarf2out_label (insn);
+#endif
       if (app_on)
        {
          fprintf (file, ASM_APP_OFF);
@@ -1546,7 +1651,7 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
 
     default:
       {
-       register rtx body = PATTERN (insn);
+       register rtx body = PATTERN (insn), set;
        int insn_code_number;
        char *template;
        rtx note;
@@ -1748,6 +1853,8 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
        body = PATTERN (insn);
 
 #ifdef HAVE_cc0
+       set = single_set(insn);
+
        /* Check for redundant test and compare instructions
           (when the condition codes are already set up as desired).
           This is done only when optimizing; if not optimizing,
@@ -1758,7 +1865,9 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
 
        if (optimize)
          {
+#if 0
            rtx set = single_set(insn);
+#endif
 
            if (set
                && GET_CODE (SET_DEST (set)) == CC0
@@ -1869,12 +1978,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)
+           && set != 0)
          {
-           switch (GET_CODE (SET_SRC (body)))
+           rtx cond_rtx, then_rtx, else_rtx;
+           
+           if (GET_CODE (insn) != JUMP_INSN
+               && GET_CODE (SET_SRC (set)) == IF_THEN_ELSE)
+             {
+               cond_rtx = XEXP (SET_SRC (set), 0);
+               then_rtx = XEXP (SET_SRC (set), 1);
+               else_rtx = XEXP (SET_SRC (set), 2);
+             }
+           else
+             {
+               cond_rtx = SET_SRC (set);
+               then_rtx = const_true_rtx;
+               else_rtx = const0_rtx;
+             }
+           
+           switch (GET_CODE (cond_rtx))
              {
              case GTU:
              case GT:
@@ -1888,18 +2014,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 (set), then_rtx, 0);
                  else if (result == -1)
-                   validate_change (insn, &SET_SRC (body), const0_rtx, 0);
+                   validate_change (insn, &SET_SRC (set), else_rtx, 0);
                  else if (result == 2)
                    INSN_CODE (insn) = -1;
+                 if (SET_DEST (set) == SET_SRC (set))
+                   {
+                     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.  */
@@ -2014,6 +2148,13 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
            if (new == insn && PATTERN (new) == body)
              abort ();
              
+#ifdef HAVE_ATTR_length
+           /* This instruction should have been split in shorten_branches,
+              to ensure that we would have valid length info for the
+              splitees.  */
+           abort ();
+#endif
+
            new_block = 0;
            return new;
          }
@@ -2025,6 +2166,13 @@ final_scan_insn (insn, file, optimize, prescan, nopeepholes)
 
        output_asm_insn (template, recog_operand);
 
+#if defined (DWARF2_DEBUGGING_INFO) && defined (HAVE_prologue)
+       /* If this insn is part of the prologue, emit DWARF v2
+          call frame info.  */
+       if (write_symbols == DWARF2_DEBUG && RTX_FRAME_RELATED_P (insn))
+         dwarf2out_frame_debug (insn);
+#endif
+
 #if 0
        /* It's not at all clear why we did this and doing so interferes
           with tests we'd like to do to use REG_WAS_0 notes, so let's try
@@ -2098,6 +2246,11 @@ output_source_line (file, insn)
       if (write_symbols == DWARF_DEBUG)
        dwarfout_line (filename, NOTE_LINE_NUMBER (insn));
 #endif
+
+#ifdef DWARF2_DEBUGGING_INFO
+      if (write_symbols == DWARF2_DEBUG)
+       dwarf2out_line (filename, NOTE_LINE_NUMBER (insn));
+#endif
     }
 }
 \f
@@ -2471,12 +2624,7 @@ output_asm_insn (template, operands)
            else if (letter == 'n')
              {
                if (GET_CODE (operands[c]) == CONST_INT)
-                 fprintf (asm_out_file,
-#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
-                          "%d",
-#else
-                          "%ld",
-#endif
+                 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC,
                           - INTVAL (operands[c]));
                else
                  {
@@ -2612,13 +2760,7 @@ output_addr_const (file, x)
       break;
 
     case CONST_INT:
-      fprintf (file,
-#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
-              "%d",
-#else
-              "%ld",
-#endif
-              INTVAL (x));
+      fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
       break;
 
     case CONST:
@@ -2632,37 +2774,12 @@ output_addr_const (file, x)
        {
          /* We can use %d if the number is one word and positive.  */
          if (CONST_DOUBLE_HIGH (x))
-           fprintf (file,
-#if HOST_BITS_PER_WIDE_INT == 64
-#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
-                    "0x%lx%016lx",
-#else
-                    "0x%x%016x",
-#endif
-#else
-#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
-                    "0x%lx%08lx",
-#else
-                    "0x%x%08x",
-#endif
-#endif
+           fprintf (file, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
                     CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
          else if  (CONST_DOUBLE_LOW (x) < 0)
-           fprintf (file,
-#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
-                    "0x%x",
-#else
-                    "0x%lx",
-#endif
-                    CONST_DOUBLE_LOW (x));
+           fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
          else
-           fprintf (file,
-#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
-                    "%d",
-#else
-                    "%ld",
-#endif
-                    CONST_DOUBLE_LOW (x));
+           fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
        }
       else
        /* We can't handle floating point constants;
@@ -2743,8 +2860,8 @@ asm_fprintf VPROTO((FILE *file, char *p, ...))
   VA_START (argptr, p);
 
 #ifndef __STDC__
-  file = va_arg (argptr, FILE*);
-  p = va_arg (argptr, char*);
+  file = va_arg (argptr, FILE *);
+  p = va_arg (argptr, char *);
 #endif
 
   buf[0] = '%';
@@ -2803,8 +2920,14 @@ asm_fprintf VPROTO((FILE *file, char *p, ...))
               but we do not check for those cases.  It means that the value
               is a HOST_WIDE_INT, which may be either `int' or `long'.  */
 
-#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
+#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
+#else
+#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
            *q++ = 'l';
+#else
+           *q++ = 'l';
+           *q++ = 'l';
+#endif
 #endif
 
            *q++ = *p++;
@@ -2966,7 +3089,7 @@ split_double (value, first, second)
       /* Note, this converts the REAL_VALUE_TYPE to the target's
         format, splits up the floating point double and outputs
         exactly 32 bits of it into each of l[0] and l[1] --
-        not necessarily BITS_PER_WORD bits. */
+        not necessarily BITS_PER_WORD bits.  */
       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
 
       *first = GEN_INT ((HOST_WIDE_INT) l[0]);
@@ -3005,7 +3128,7 @@ leaf_function_p ()
 {
   rtx insn;
 
-  if (profile_flag || profile_block_flag)
+  if (profile_flag || profile_block_flag || profile_arc_flag)
     return 0;
 
   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))