OSDN Git Service

gcc/ChangeLog:
[pf3gnuchains/gcc-fork.git] / gcc / toplev.c
index 4dd17e4..0943f37 100644 (file)
@@ -1,6 +1,6 @@
 /* Top level of GCC compilers (cc1, cc1plus, etc.)
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -25,8 +25,6 @@ along with GCC; see the file COPYING3.  If not see
    Error messages and low-level interface to malloc also handled here.  */
 
 #include "config.h"
-#undef FLOAT /* This is for hpux. They should change hpux.  */
-#undef FFS  /* Some systems define this in param.h.  */
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
@@ -43,6 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "line-map.h"
 #include "input.h"
 #include "tree.h"
+#include "realmpfr.h"  /* For GMP/MPFR/MPC versions, in print_version.  */
 #include "version.h"
 #include "rtl.h"
 #include "tm_p.h"
@@ -64,12 +63,13 @@ along with GCC; see the file COPYING3.  If not see
 #include "regs.h"
 #include "timevar.h"
 #include "diagnostic.h"
+#include "tree-diagnostic.h"
+#include "tree-pretty-print.h"
 #include "params.h"
 #include "reload.h"
 #include "ira.h"
 #include "dwarf2asm.h"
 #include "integrate.h"
-#include "real.h"
 #include "debug.h"
 #include "target.h"
 #include "langhooks.h"
@@ -86,6 +86,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple.h"
 #include "tree-ssa-alias.h"
 #include "plugin.h"
+#include "varray.h"
 
 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
 #include "dwarf2out.h"
@@ -139,7 +140,7 @@ static const char **save_argv;
 const char *main_input_filename;
 
 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
-   to optimize and default_debug_hooks in process_options ().  */
+   to optimize in process_options ().  */
 #define AUTODETECT_VALUE 2
 
 /* Current position in real source file.  */
@@ -152,6 +153,10 @@ struct line_maps *line_table;
 
 const char *dump_base_name;
 
+/* Directory used for dump output files.  */
+
+const char *dump_dir_name;
+
 /* Name to use as a base for auxiliary output files.  */
 
 const char *aux_base_name;
@@ -168,10 +173,6 @@ int target_flags_explicit;
 
 const struct gcc_debug_hooks *debug_hooks;
 
-/* Debug hooks - target default.  */
-
-static const struct gcc_debug_hooks *default_debug_hooks;
-
 /* Other flags saying which kinds of debugging dump have been requested.  */
 
 int rtl_dump_and_exit;
@@ -198,6 +199,17 @@ int optimize = 0;
 
 int optimize_size = 0;
 
+/* True if this is the lto front end.  This is used to disable
+   gimple generation and lowering passes that are normally run on the
+   output of a front end.  These passes must be bypassed for lto since
+   they have already been done before the gimple was written.  */
+
+bool in_lto_p = false;
+
+/* Nonzero if we should write GIMPLE bytecode for link-time optimization.  */
+
+int flag_generate_lto;
+
 /* The FUNCTION_DECL for the function currently being compiled,
    or 0 if between functions.  */
 tree current_function_decl;
@@ -875,9 +887,9 @@ check_global_declaration_1 (tree decl)
       && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
       /* Otherwise, ask the language.  */
       && lang_hooks.decls.warn_unused_global (decl))
-    warning ((TREE_CODE (decl) == FUNCTION_DECL) 
-            ? OPT_Wunused_function 
-             : OPT_Wunused_variable, 
+    warning ((TREE_CODE (decl) == FUNCTION_DECL)
+            ? OPT_Wunused_function
+             : OPT_Wunused_variable,
             "%q+D defined but not used", decl);
 }
 
@@ -1041,7 +1053,7 @@ compile_file (void)
      what's left of the symbol table output.  */
   timevar_pop (TV_PARSE);
 
-  if (flag_syntax_only)
+  if (flag_syntax_only || flag_wpa)
     return;
 
   ggc_protect_identifiers = false;
@@ -1069,6 +1081,10 @@ compile_file (void)
   /* Write out any pending weak symbol declarations.  */
   weak_finish ();
 
+  /* This must be at the end before unwind and debug info.
+     Some target ports emit PIC setup thunks here.  */
+  targetm.asm_out.code_end ();
+
   /* Do dbx symbols.  */
   timevar_push (TV_SYMOUT);
 
@@ -1087,6 +1103,27 @@ compile_file (void)
   /* Flush any pending external directives.  */
   process_pending_assemble_externals ();
 
+  /* Emit LTO marker if LTO info has been previously emitted.  This is
+     used by collect2 to determine whether an object file contains IL.
+     We used to emit an undefined reference here, but this produces
+     link errors if an object file with IL is stored into a shared
+     library without invoking lto1.  */
+  if (flag_generate_lto)
+    {
+#if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
+      ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
+                                     "__gnu_lto_v1",
+                                     (unsigned HOST_WIDE_INT) 1, 8);
+#elif defined ASM_OUTPUT_ALIGNED_COMMON
+      ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
+                                (unsigned HOST_WIDE_INT) 1, 8);
+#else
+      ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
+                        (unsigned HOST_WIDE_INT) 1,
+                        (unsigned HOST_WIDE_INT) 1);
+#endif
+    }
+
   /* Attach a special .ident directive to the end of the file to identify
      the version of GCC which compiled this code.  The format of the .ident
      string is patterned after the ones produced by native SVR4 compilers.  */
@@ -1104,7 +1141,7 @@ compile_file (void)
 
   /* Invoke registered plugin callbacks.  */
   invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
-  
+
   /* This must be at the end.  Some target ports emit end of file directives
      into the assembly file here, and hence we can not output anything to the
      assembly file after this point.  */
@@ -1179,13 +1216,8 @@ print_version (FILE *file, const char *indent)
     N_("%s%s%s %sversion %s (%s) compiled by CC, ")
 #endif
     ;
-#ifdef HAVE_mpc
   static const char fmt2[] =
     N_("GMP version %s, MPFR version %s, MPC version %s\n");
-#else
-  static const char fmt2[] =
-    N_("GMP version %s, MPFR version %s\n");
-#endif
   static const char fmt3[] =
     N_("%s%swarning: %s header version %s differs from library version %s.\n");
   static const char fmt4[] =
@@ -1217,11 +1249,7 @@ print_version (FILE *file, const char *indent)
 #endif
   fprintf (file,
           file == stderr ? _(fmt2) : fmt2,
-          GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING
-#ifdef HAVE_mpc
-          , MPC_VERSION_STRING
-#endif
-          );
+          GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
   if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
     fprintf (file,
             file == stderr ? _(fmt3) : fmt3,
@@ -1232,13 +1260,11 @@ print_version (FILE *file, const char *indent)
             file == stderr ? _(fmt3) : fmt3,
             indent, *indent != 0 ? " " : "",
             "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
-#ifdef HAVE_mpc
   if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
     fprintf (file,
             file == stderr ? _(fmt3) : fmt3,
             indent, *indent != 0 ? " " : "",
             "MPC", MPC_VERSION_STRING, mpc_get_version ());
-#endif
   fprintf (file,
           file == stderr ? _(fmt4) : fmt4,
           indent, *indent != 0 ? " " : "",
@@ -1293,7 +1319,7 @@ print_to_stderr (print_switch_type type, const char * text)
 
     case SWITCH_TYPE_LINE_START:
       return 0;
-      
+
     case SWITCH_TYPE_PASSED:
     case SWITCH_TYPE_ENABLED:
       fputc (' ', stderr);
@@ -1367,6 +1393,7 @@ print_switch_values (print_switch_fn_type print_fn)
          /* Ignore these.  */
          if (strcmp (*p, "-o") == 0
              || strcmp (*p, "-dumpbase") == 0
+             || strcmp (*p, "-dumpdir") == 0
              || strcmp (*p, "-auxbase") == 0)
            {
              if (p[1] != NULL)
@@ -1486,20 +1513,20 @@ option_affects_pch_p (int option, struct cl_option_state *state)
    most targets, but completely right for very few.  */
 
 void *
-default_get_pch_validity (size_t *len)
+default_get_pch_validity (size_t *sz)
 {
   struct cl_option_state state;
   size_t i;
   char *result, *r;
 
-  *len = 2;
+  *sz = 2;
   if (targetm.check_pch_target_flags)
-    *len += sizeof (target_flags);
+    *sz += sizeof (target_flags);
   for (i = 0; i < cl_options_count; i++)
     if (option_affects_pch_p (i, &state))
-      *len += state.size;
+      *sz += state.size;
 
-  result = r = XNEWVEC (char, *len);
+  result = r = XNEWVEC (char, *sz);
   r[0] = flag_pic;
   r[1] = flag_pie;
   r += 2;
@@ -1608,6 +1635,10 @@ default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
       t = va_arg (*text->args_ptr, tree);
       break;
 
+    case 'K':
+      percent_K_format (text);
+      return true;
+
     default:
       return false;
     }
@@ -1661,9 +1692,11 @@ general_init (const char *argv0)
   /* Initialize the diagnostics reporting machinery, so option parsing
      can give warnings and errors.  */
   diagnostic_initialize (global_dc);
+  diagnostic_starter (global_dc) = default_tree_diagnostic_starter;
   /* Set a default printer.  Language specific initializations will
      override it later.  */
   pp_format_decoder (global_dc->printer) = &default_tree_printer;
+  global_dc->show_option_requested = flag_diagnostics_show_option;
 
   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
 #ifdef SIGSEGV
@@ -1766,6 +1799,12 @@ process_options (void)
     warn_unused_parameter = (warn_unused && extra_warnings);
   if (warn_unused_variable == -1)
     warn_unused_variable = warn_unused;
+  /* Wunused-but-set-parameter is enabled if both -Wunused -Wextra are
+     enabled.  */
+  if (warn_unused_but_set_parameter == -1)
+    warn_unused_but_set_parameter = (warn_unused && extra_warnings);
+  if (warn_unused_but_set_variable == -1)
+    warn_unused_but_set_variable = warn_unused;
   if (warn_unused_value == -1)
     warn_unused_value = warn_unused;
 
@@ -1784,6 +1823,10 @@ process_options (void)
   OVERRIDE_OPTIONS;
 #endif
 
+  /* Avoid any informative notes in the second run of -fcompare-debug.  */
+  if (flag_compare_debug) 
+    diagnostic_inhibit_notes (global_dc);
+
   if (flag_section_anchors && !target_supports_section_anchors_p ())
     {
       warning (OPT_fsection_anchors,
@@ -1824,11 +1867,12 @@ process_options (void)
 
   /* The loop unrolling code assumes that cse will be run after loop.
      web and rename-registers also help when run after loop unrolling.  */
-
   if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
     flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
+
   if (flag_web == AUTODETECT_VALUE)
     flag_web = flag_unroll_loops || flag_peel_loops;
+
   if (flag_rename_registers == AUTODETECT_VALUE)
     flag_rename_registers = flag_unroll_loops || flag_peel_loops;
 
@@ -1912,7 +1956,7 @@ process_options (void)
 
   /* Unless over-ridden for the target, assume that all DWARF levels
      may be emitted, if DWARF2_DEBUG is selected.  */
-  if (dwarf_strict < 0) 
+  if (dwarf_strict < 0)
     dwarf_strict = 0;
 
   /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
@@ -1920,32 +1964,6 @@ process_options (void)
   if (debug_info_level == DINFO_LEVEL_NONE)
     write_symbols = NO_DEBUG;
 
-  /* Now we know write_symbols, set up the debug hooks based on it.
-     By default we do nothing for debug output.  */
-  if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
-    default_debug_hooks = &do_nothing_debug_hooks;
-#if defined(DBX_DEBUGGING_INFO)
-  else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
-    default_debug_hooks = &dbx_debug_hooks;
-#endif
-#if defined(XCOFF_DEBUGGING_INFO)
-  else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
-    default_debug_hooks = &xcoff_debug_hooks;
-#endif
-#ifdef SDB_DEBUGGING_INFO
-  else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
-    default_debug_hooks = &sdb_debug_hooks;
-#endif
-#ifdef DWARF2_DEBUGGING_INFO
-  else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
-    default_debug_hooks = &dwarf2_debug_hooks;
-#endif
-#ifdef VMS_DEBUGGING_INFO
-  else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
-          || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
-    default_debug_hooks = &vmsdbg_debug_hooks;
-#endif
-
   if (write_symbols == NO_DEBUG)
     ;
 #if defined(DBX_DEBUGGING_INFO)
@@ -1972,9 +1990,8 @@ process_options (void)
     error ("target system does not support the \"%s\" debug format",
           debug_type_names[write_symbols]);
 
-  /* Now we know which debug output will be used so we can set
-     flag_var_tracking, flag_rename_registers if the user has
-     not specified them.  */
+  /* We know which debug output will be used so we can set flag_var_tracking
+     and flag_var_tracking_uninit if the user has not specified them.  */
   if (debug_info_level < DINFO_LEVEL_NORMAL
       || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
     {
@@ -2015,10 +2032,6 @@ process_options (void)
       && (flag_selective_scheduling || flag_selective_scheduling2))
     warning (0, "var-tracking-assignments changes selective scheduling");
 
-  if (flag_rename_registers == AUTODETECT_VALUE)
-    flag_rename_registers = default_debug_hooks->var_location
-                           != do_nothing_debug_hooks.var_location;
-
   if (flag_tree_cselim == AUTODETECT_VALUE)
 #ifdef HAVE_conditional_move
     flag_tree_cselim = 1;
@@ -2118,6 +2131,10 @@ process_options (void)
               "for correctness");
       flag_omit_frame_pointer = 0;
     }
+
+  /* Save the current optimization options.  */
+  optimization_default_node = build_optimization_node ();
+  optimization_current_node = optimization_default_node;
 }
 
 /* This function can be called multiple times to reinitialize the compiler
@@ -2157,8 +2174,8 @@ backend_init_target (void)
 
   /* We may need to recompute regno_save_code[] and regno_restore_code[]
      after a mode change as well.  */
-  if (flag_caller_saves)
-    init_caller_save ();
+  caller_save_initialized_p = false;
+
   expand_dummy_function_end ();
 }
 
@@ -2167,13 +2184,7 @@ backend_init_target (void)
 static void
 backend_init (void)
 {
-  init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
-                 || debug_info_level == DINFO_LEVEL_VERBOSE
-#ifdef VMS_DEBUGGING_INFO
-                   /* Enable line number info for traceback.  */
-                   || debug_info_level > DINFO_LEVEL_NONE
-#endif
-                   || flag_test_coverage);
+  init_emit_once ();
 
   init_rtlanal ();
   init_inline_once ();
@@ -2312,7 +2323,6 @@ dump_memory_report (bool final)
   dump_tree_statistics ();
   dump_gimple_statistics ();
   dump_rtx_statistics ();
-  dump_varray_statistics ();
   dump_alloc_pool_statistics ();
   dump_bitmap_statistics ();
   dump_vec_loc_statistics ();
@@ -2344,6 +2354,8 @@ finalize (void)
        fatal_error ("error writing to %s: %m", asm_file_name);
       if (fclose (asm_out_file) != 0)
        fatal_error ("error closing %s: %m", asm_file_name);
+      if (flag_wpa)
+       unlink_if_ordinary (asm_file_name);
     }
 
   statistics_fini ();
@@ -2428,8 +2440,9 @@ toplev_main (int argc, char **argv)
   if (!exit_after_options)
     do_compile ();
 
-  if (warningcount || errorcount) 
+  if (warningcount || errorcount)
     print_ignored_options ();
+  diagnostic_finish (global_dc);
 
   /* Invoke registered plugin callbacks if any.  */
   invoke_plugin_callbacks (PLUGIN_FINISH, NULL);