OSDN Git Service

2002-09-10 Frank Ch. Eigler <fche@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / toplev.c
index e9a15a5..6ce6ecd 100644 (file)
@@ -1,4 +1,3 @@
-
 /* Top level of GNU C compiler
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
    1999, 2000, 2001, 2002 Free Software Foundation, Inc.
@@ -98,10 +97,10 @@ extern tree last_assemble_variable_decl;
 extern void reg_alloc PARAMS ((void));
 
 static void general_init PARAMS ((char *));
-static bool parse_options_and_default_flags PARAMS ((int, char **));
-static void do_compile PARAMS ((int));
+static void parse_options_and_default_flags PARAMS ((int, char **));
+static void do_compile PARAMS ((void));
 static void process_options PARAMS ((void));
-static void lang_independent_init PARAMS ((int));
+static void backend_init PARAMS ((void));
 static int lang_dependent_init PARAMS ((const char *));
 static void init_asm_output PARAMS ((const char *));
 static void finalize PARAMS ((void));
@@ -169,6 +168,10 @@ int input_file_stack_tick;
 
 const char *dump_base_name;
 
+/* Name to use as a base for auxiliary output files.  */
+
+const char *aux_base_name;
+
 /* Format to use to print dumpfile index value */
 #ifndef DUMPFILE_FORMAT
 #define DUMPFILE_FORMAT ".%02d."
@@ -180,6 +183,11 @@ const char *dump_base_name;
 
 extern int target_flags;
 
+/* A mask of target_flags that includes bit X if X was set or cleared
+   on the command line.  */
+
+int target_flags_explicit;
+
 /* Debug hooks - dependent upon command line options.  */
 
 const struct gcc_debug_hooks *debug_hooks = &do_nothing_debug_hooks;
@@ -571,12 +579,24 @@ int flag_errno_math = 1;
 
 int flag_unsafe_math_optimizations = 0;
 
+/* Nonzero means that no NaNs or +-Infs are expected.  */
+
+int flag_finite_math_only = 0;
+
 /* Zero means that floating-point math operations cannot generate a
    (user-visible) trap.  This is the case, for example, in nonstop
-   IEEE 754 arithmetic.  */
+   IEEE 754 arithmetic.  Trapping conditions include division by zero,
+   overflow, underflow, invalid and inexact, but does not include 
+   operations on signaling NaNs (see below).  */
 
 int flag_trapping_math = 1;
 
+/* Nonzero means disable transformations observable by signaling NaNs.
+   This option implies that any operation on a IEEE signaling NaN can
+   generate a (user-visible) trap.  */
+
+int flag_signaling_nans = 0;
+
 /* 0 means straightforward implementation of complex divide acceptable.
    1 means wide ranges of inputs must work for complex divide.
    2 means C99-like requirements for complex divide (not yet implemented).  */
@@ -1158,6 +1178,8 @@ static const lang_independent_options f_options[] =
    N_("Process #ident directives") },
   { "peephole2", &flag_peephole2, 1,
    N_("Enables an rtl peephole pass run before sched2") },
+  {"finite-math-only", &flag_finite_math_only, 1,
+   N_("Assume no NaNs or +-Infs are generated") },
   { "guess-branch-probability", &flag_guess_branch_prob, 1,
    N_("Enables guessing of branch probabilities") },
   {"math-errno", &flag_errno_math, 1,
@@ -1166,6 +1188,8 @@ static const lang_independent_options f_options[] =
    N_("Floating-point operations can trap") },
   {"unsafe-math-optimizations", &flag_unsafe_math_optimizations, 1,
    N_("Allow math optimizations that may violate IEEE or ANSI standards") },
+  {"signaling-nans", &flag_signaling_nans, 1,
+   N_("Disable optimizations observable by IEEE signaling NaNs") },
   {"bounded-pointers", &flag_bounded_pointers, 1,
    N_("Compile pointers as triples: value, base & end") },
   {"bounds-check", &flag_bounds_check, 1,
@@ -1196,7 +1220,7 @@ documented_lang_options[] =
      enabled by default.  */
 
   { "-ansi",
-    N_("Compile just for ISO C89") },
+    N_("Compile just for ISO C90") },
   { "-std= ",
     N_("Determine language standard") },
 
@@ -1561,7 +1585,10 @@ set_fast_math_flags (set)
 {
   flag_trapping_math = !set;
   flag_unsafe_math_optimizations = set;
+  flag_finite_math_only = set;
   flag_errno_math = !set;
+  if (set)
+    flag_signaling_nans = 0;
 }
 
 /* Return true iff flags are set as if -ffast-math.  */
@@ -1570,6 +1597,7 @@ fast_math_flags_set_p ()
 {
   return (!flag_trapping_math
          && flag_unsafe_math_optimizations
+         && flag_finite_math_only
          && !flag_errno_math);
 }
 
@@ -1672,7 +1700,7 @@ static void
 crash_signal (signo)
      int signo;
 {
-  internal_error ("internal error: %s", strsignal (signo));
+  internal_error ("%s", strsignal (signo));
 }
 
 /* Strip off a legitimate source ending from the input string NAME of
@@ -2093,7 +2121,7 @@ compile_file ()
   /* Initialize yet another pass.  */
 
   init_final (main_input_filename);
-  init_branch_prob (dump_base_name);
+  init_branch_prob (aux_base_name);
 
   timevar_push (TV_PARSE);
 
@@ -2166,7 +2194,7 @@ compile_file ()
 
   dw2_output_indirect_constants ();
 
-  end_final (dump_base_name);
+  end_final (aux_base_name);
 
   if (profile_arc_flag || flag_test_coverage || flag_branch_probabilities)
     {
@@ -2478,7 +2506,7 @@ rest_of_compilation (decl)
              free_bb_for_insn ();
            }
 
-         current_function_nothrow = nothrow_function_p ();
+         set_nothrow_function_flags ();
          if (current_function_nothrow)
            /* Now we know that this can't throw; set the flag for the benefit
               of other functions later in this translation unit.  */
@@ -2878,6 +2906,8 @@ rest_of_compilation (decl)
 
   if (optimize > 0 && flag_loop_optimize)
     {
+      int do_unroll, do_prefetch;
+
       timevar_push (TV_LOOP);
       delete_dead_jumptables ();
       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
@@ -2885,12 +2915,15 @@ rest_of_compilation (decl)
       /* CFG is no longer maintained up-to-date.  */
       free_bb_for_insn ();
 
+      do_unroll = flag_unroll_loops ? LOOP_UNROLL : LOOP_AUTO_UNROLL;
+      do_prefetch = flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0;
       if (flag_rerun_loop_opt)
        {
          cleanup_barriers ();
 
          /* We only want to perform unrolling once.  */
-         loop_optimize (insns, rtl_dump_file, LOOP_FIRST_PASS);
+         loop_optimize (insns, rtl_dump_file, do_unroll);
+         do_unroll = 0;
 
          /* The first call to loop_optimize makes some instructions
             trivially dead.  We delete those instructions now in the
@@ -2903,9 +2936,7 @@ rest_of_compilation (decl)
          reg_scan (insns, max_reg_num (), 1);
        }
       cleanup_barriers ();
-      loop_optimize (insns, rtl_dump_file,
-                    (flag_unroll_loops ? LOOP_UNROLL : 0) | LOOP_BCT
-                    | (flag_prefetch_loop_arrays ? LOOP_PREFETCH : 0));
+      loop_optimize (insns, rtl_dump_file, do_unroll | LOOP_BCT | do_prefetch);
 
       /* Loop can create trivially dead instructions.  */
       delete_trivially_dead_insns (insns, max_reg_num ());
@@ -2952,13 +2983,13 @@ rest_of_compilation (decl)
         block.  The loop infrastructure does the real job for us.  */
       flow_loops_find (&loops, LOOP_TREE);
 
+      if (rtl_dump_file)
+       flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
+
       /* Estimate using heuristics if no profiling info is available.  */
       if (flag_guess_branch_prob)
        estimate_probability (&loops);
 
-      if (rtl_dump_file)
-       flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
-
       flow_loops_free (&loops);
       close_dump_file (DFI_bp, print_rtl_with_bb, insns);
       timevar_pop (TV_BRANCH_PROB);
@@ -3497,7 +3528,7 @@ rest_of_compilation (decl)
   shorten_branches (get_insns ());
   timevar_pop (TV_SHORTEN_BRANCH);
 
-  current_function_nothrow = nothrow_function_p ();
+  set_nothrow_function_flags ();
   if (current_function_nothrow)
     /* Now we know that this can't throw; set the flag for the benefit
        of other functions later in this translation unit.  */
@@ -4270,7 +4301,9 @@ independent_decode_option (argc, argv)
          if (argc == 1)
            return 0;
 
-         dump_base_name = argv[1];
+         if (argv[1][0])
+           dump_base_name = argv[1];
+         
          return 2;
        }
       else
@@ -4343,6 +4376,30 @@ independent_decode_option (argc, argv)
          else
            return 0;
        }
+      else if (!strcmp (arg, "auxbase"))
+       {
+         if (argc == 1)
+           return 0;
+
+         if (argv[1][0])
+           aux_base_name = argv[1];
+         
+         return 2;
+       }
+      else if (!strcmp (arg, "auxbase-strip"))
+       {
+         if (argc == 1)
+           return 0;
+
+         if (argv[1][0])
+           {
+             strip_off_ending (argv[1], strlen (argv[1]));
+             if (argv[1][0])
+               aux_base_name = argv[1];
+           }
+         
+         return 2;
+       }
       else
        return 0;
       break;
@@ -4409,6 +4466,13 @@ set_target_switch (name)
          target_flags &= ~-target_switches[j].value;
        else
          target_flags |= target_switches[j].value;
+       if (name[0] != 0)
+         {
+           if (target_switches[j].value < 0)
+             target_flags_explicit |= -target_switches[j].value;
+           else
+             target_flags_explicit |= target_switches[j].value;
+         }
        valid_target_option = 1;
       }
 
@@ -4659,6 +4723,12 @@ general_init (argv0)
   /* Initialize the diagnostics reporting machinery, so option parsing
      can give warnings and errors.  */
   diagnostic_initialize (global_dc);
+
+  /* Initialize the garbage-collector, string pools and tree type hash
+     table.  */
+  init_ggc ();
+  init_stringpool ();
+  init_ttree ();
 }
 \f
 /* Parse command line options and set default flag values, called
@@ -4667,7 +4737,7 @@ general_init (argv0)
    and identifier hashtables etc. are not initialized yet.
 
    Return non-zero to suppress compiler back end initialization.  */
-static bool
+static void
 parse_options_and_default_flags (argc, argv)
      int argc;
      char **argv;
@@ -4779,6 +4849,15 @@ parse_options_and_default_flags (argc, argv)
       align_jumps = 1;
       align_labels = 1;
       align_functions = 1;
+
+      /* Don't reorder blocks when optimizing for size because extra
+        jump insns may be created; also barrier may create extra padding.
+
+        More correctly we should have a block reordering mode that tried
+        to minimize the combined size of all the jumps.  This would more
+        or less automatically remove extra jumps, but would also try to
+        use more short jumps instead of long jumps.  */
+      flag_reorder_blocks = 0;
     }
 
   /* Initialize whether `char' is signed.  */
@@ -4895,10 +4974,6 @@ parse_options_and_default_flags (argc, argv)
 
   if (flag_really_no_inline == 2)
     flag_really_no_inline = flag_no_inline;
-
-  /* All command line options have been parsed; allow the front end to
-     perform consistency checks, etc.  */
-  return (*lang_hooks.post_options) ();
 }
 \f
 /* Process the options that have been parsed.  */
@@ -5072,23 +5147,16 @@ process_options ()
   if (flag_function_sections && write_symbols != NO_DEBUG)
     warning ("-ffunction-sections may affect debugging on some targets");
 #endif
+
+    /* The presence of IEEE signaling NaNs, implies all math can trap.  */
+    if (flag_signaling_nans)
+      flag_trapping_math = 1;
 }
 \f
-/* Language-independent initialization, before language-dependent
-   initialization.  */
+/* Initialize the compiler back end.  */
 static void
-lang_independent_init (no_backend)
-     int no_backend;
+backend_init ()
 {
-  /* Initialize the garbage-collector, and string pools.  */
-  init_ggc ();
-
-  init_stringpool ();
-  init_obstacks ();
-
-  if (no_backend)
-    return;
-
   /* init_emit_once uses reg_raw_mode and therefore must be called
      after init_regs which initialized reg_raw_mode.  */
   init_regs ();
@@ -5123,7 +5191,7 @@ lang_dependent_init (name)
 {
   if (dump_base_name == 0)
     dump_base_name = name ? name : "gccdump";
-
+  
   /* Front-end initialization.  This hook can assume that GC,
      identifier hashes etc. are set up, but debug initialization is
      not done yet.  This routine must return the original filename
@@ -5141,7 +5209,12 @@ lang_dependent_init (name)
      front end is initialized.  */
   init_eh ();
   init_optabs ();
+
+  /* The following initialization functions need to generate rtl, so
+     provide a dummy function context for them.  */
+  init_dummy_function_start ();
   init_expr_once ();
+  expand_dummy_function_end ();
 
   /* Put an entry on the input file stack for the main input file.  */
   push_srcloc (input_filename, 0);
@@ -5223,20 +5296,39 @@ finalize ()
 \f
 /* Initialize the compiler, and compile the input file.  */
 static void
-do_compile (no_backend)
-     int no_backend;
+do_compile ()
 {
+  /* All command line options have been parsed; allow the front end to
+     perform consistency checks, etc.  */
+  bool no_backend = (*lang_hooks.post_options) ();
+
   /* The bulk of command line switch processing.  */
   process_options ();
 
+  /* If an error has already occurred, give up.  */
+  if (errorcount)
+    return;
+
+  if (aux_base_name)
+    /*NOP*/;
+  else if (filename)
+    {
+      char *name = xstrdup (lbasename (filename));
+      
+      aux_base_name = name;
+      strip_off_ending (name, strlen (name));
+    }
+  else
+    aux_base_name = "gccaux";
+
   /* We cannot start timing until after options are processed since that
      says if we run timers or not.  */
   init_timevar ();
   timevar_start (TV_TOTAL);
 
-  /* Language-independent initialization.  Also sets up GC, identifier
-     hashes etc., and the back-end if requested.  */
-  lang_independent_init (no_backend);
+  /* Set up the back-end if requested.  */
+  if (!no_backend)
+    backend_init ();
 
   /* Language-dependent initialization.  Returns true on success.  */
   if (lang_dependent_init (filename))
@@ -5261,18 +5353,16 @@ toplev_main (argc, argv)
      int argc;
      char **argv;
 {
-  bool no_backend;
-
   /* Initialization of GCC's environment, and diagnostics.  */
   general_init (argv[0]);
 
   /* Parse the options and do minimal processing; basically just
      enough to default flags appropriately.  */
-  no_backend = parse_options_and_default_flags (argc, argv);
+  parse_options_and_default_flags (argc, argv);
 
   /* Exit early if we can (e.g. -help).  */
-  if (!errorcount && !exit_after_options)
-    do_compile (no_backend);
+  if (!exit_after_options)
+    do_compile ();
 
   if (errorcount || sorrycount)
     return (FATAL_EXIT_CODE);