Print SCoPs under CLooG format.
[official-gcc/graphite-test-results.git] / gcc / toplev.c
blobf23d0def3a886f42a00e7bdc24b1c601b585561c
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
27 #include "config.h"
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
43 #include "line-map.h"
44 #include "input.h"
45 #include "tree.h"
46 #include "version.h"
47 #include "rtl.h"
48 #include "tm_p.h"
49 #include "flags.h"
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
54 #include "recog.h"
55 #include "output.h"
56 #include "except.h"
57 #include "function.h"
58 #include "toplev.h"
59 #include "expr.h"
60 #include "basic-block.h"
61 #include "intl.h"
62 #include "ggc.h"
63 #include "graph.h"
64 #include "regs.h"
65 #include "timevar.h"
66 #include "diagnostic.h"
67 #include "params.h"
68 #include "reload.h"
69 #include "ira.h"
70 #include "dwarf2asm.h"
71 #include "integrate.h"
72 #include "real.h"
73 #include "debug.h"
74 #include "target.h"
75 #include "langhooks.h"
76 #include "cfglayout.h"
77 #include "cfgloop.h"
78 #include "hosthooks.h"
79 #include "cgraph.h"
80 #include "opts.h"
81 #include "coverage.h"
82 #include "value-prof.h"
83 #include "alloc-pool.h"
84 #include "tree-mudflap.h"
85 #include "tree-pass.h"
86 #include "gimple.h"
87 #include "tree-ssa-alias.h"
88 #include "plugin.h"
90 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
91 #include "dwarf2out.h"
92 #endif
94 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
95 #include "dbxout.h"
96 #endif
98 #ifdef SDB_DEBUGGING_INFO
99 #include "sdbout.h"
100 #endif
102 #ifdef XCOFF_DEBUGGING_INFO
103 #include "xcoffout.h" /* Needed for external data
104 declarations for e.g. AIX 4.x. */
105 #endif
107 static void general_init (const char *);
108 static void do_compile (void);
109 static void process_options (void);
110 static void backend_init (void);
111 static int lang_dependent_init (const char *);
112 static void init_asm_output (const char *);
113 static void finalize (void);
115 static void crash_signal (int) ATTRIBUTE_NORETURN;
116 static void setup_core_dumping (void);
117 static void compile_file (void);
119 /* Nonzero to dump debug info whilst parsing (-dy option). */
120 static int set_yydebug;
122 /* True if we don't need a backend (e.g. preprocessing only). */
123 static bool no_backend;
125 /* Length of line when printing switch values. */
126 #define MAX_LINE 75
128 /* Name of program invoked, sans directories. */
130 const char *progname;
132 /* Copy of argument vector to toplev_main. */
133 static const char **save_argv;
135 /* Name of top-level original source file (what was input to cpp).
136 This comes from the #-command at the beginning of the actual input.
137 If there isn't any there, then this is the cc1 input file name. */
139 const char *main_input_filename;
141 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
142 to optimize and default_debug_hooks in process_options (). */
143 #define AUTODETECT_VALUE 2
145 /* Current position in real source file. */
147 location_t input_location;
149 struct line_maps *line_table;
151 /* Name to use as base of names for dump output files. */
153 const char *dump_base_name;
155 /* Directory used for dump output files. */
157 const char *dump_dir_name;
159 /* Name to use as a base for auxiliary output files. */
161 const char *aux_base_name;
163 /* Prefix for profile data files */
164 const char *profile_data_prefix;
166 /* A mask of target_flags that includes bit X if X was set or cleared
167 on the command line. */
169 int target_flags_explicit;
171 /* Debug hooks - dependent upon command line options. */
173 const struct gcc_debug_hooks *debug_hooks;
175 /* Debug hooks - target default. */
177 static const struct gcc_debug_hooks *default_debug_hooks;
179 /* Other flags saying which kinds of debugging dump have been requested. */
181 int rtl_dump_and_exit;
182 int flag_print_asm_name;
183 enum graph_dump_types graph_dump_format;
185 /* Name for output file of assembly code, specified with -o. */
187 const char *asm_file_name;
189 /* Nonzero means do optimizations. -O.
190 Particular numeric values stand for particular amounts of optimization;
191 thus, -O2 stores 2 here. However, the optimizations beyond the basic
192 ones are not controlled directly by this variable. Instead, they are
193 controlled by individual `flag_...' variables that are defaulted
194 based on this variable. */
196 int optimize = 0;
198 /* Nonzero means optimize for size. -Os.
199 The only valid values are zero and nonzero. When optimize_size is
200 nonzero, optimize defaults to 2, but certain individual code
201 bloating optimizations are disabled. */
203 int optimize_size = 0;
205 /* True if this is the lto front end. This is used to disable
206 gimple generation and lowering passes that are normally run on the
207 output of a front end. These passes must be bypassed for lto since
208 they have already been done before the gimple was written. */
210 bool in_lto_p = false;
212 /* Nonzero if we should write GIMPLE bytecode for link-time optimization. */
214 int flag_generate_lto;
216 /* The FUNCTION_DECL for the function currently being compiled,
217 or 0 if between functions. */
218 tree current_function_decl;
220 /* Set to the FUNC_BEGIN label of the current function, or NULL
221 if none. */
222 const char * current_function_func_begin_label;
224 /* Nonzero means to collect statistics which might be expensive
225 and to print them when we are done. */
226 int flag_detailed_statistics = 0;
228 /* A random sequence of characters, unless overridden by user. */
229 static const char *flag_random_seed;
231 /* A local time stamp derived from the time of compilation. It will be
232 zero if the system cannot provide a time. It will be -1u, if the
233 user has specified a particular random seed. */
234 unsigned local_tick;
236 /* -f flags. */
238 /* Nonzero means `char' should be signed. */
240 int flag_signed_char;
242 /* Nonzero means give an enum type only as many bytes as it needs. A value
243 of 2 means it has not yet been initialized. */
245 int flag_short_enums;
247 /* Nonzero if structures and unions should be returned in memory.
249 This should only be defined if compatibility with another compiler or
250 with an ABI is needed, because it results in slower code. */
252 #ifndef DEFAULT_PCC_STRUCT_RETURN
253 #define DEFAULT_PCC_STRUCT_RETURN 1
254 #endif
256 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
258 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
260 /* 0 means straightforward implementation of complex divide acceptable.
261 1 means wide ranges of inputs must work for complex divide.
262 2 means C99-like requirements for complex multiply and divide. */
264 int flag_complex_method = 1;
266 /* Nonzero means we should be saving declaration info into a .X file. */
268 int flag_gen_aux_info = 0;
270 /* Specified name of aux-info file. */
272 const char *aux_info_file_name;
274 /* Nonzero if we are compiling code for a shared library, zero for
275 executable. */
277 int flag_shlib;
279 /* Generate code for GNU or NeXT Objective-C runtime environment. */
281 #ifdef NEXT_OBJC_RUNTIME
282 int flag_next_runtime = 1;
283 #else
284 int flag_next_runtime = 0;
285 #endif
287 /* Set to the default thread-local storage (tls) model to use. */
289 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
291 /* Set the default region and algorithm for the integrated register
292 allocator. */
294 enum ira_algorithm flag_ira_algorithm = IRA_ALGORITHM_CB;
295 enum ira_region flag_ira_region = IRA_REGION_MIXED;
297 /* Set the default value for -fira-verbose. */
299 unsigned int flag_ira_verbose = 5;
301 /* Set the default for excess precision. */
303 enum excess_precision flag_excess_precision_cmdline = EXCESS_PRECISION_DEFAULT;
304 enum excess_precision flag_excess_precision = EXCESS_PRECISION_DEFAULT;
306 /* Nonzero means change certain warnings into errors.
307 Usually these are warnings about failure to conform to some standard. */
309 int flag_pedantic_errors = 0;
311 /* Nonzero means make permerror produce warnings instead of errors. */
313 int flag_permissive = 0;
315 /* -dA causes debug commentary information to be produced in
316 the generated assembly code (to make it more readable). This option
317 is generally only of use to those who actually need to read the
318 generated assembly code (perhaps while debugging the compiler itself).
319 Currently, this switch is only used by dwarfout.c; however, it is intended
320 to be a catchall for printing debug information in the assembler file. */
322 int flag_debug_asm = 0;
324 /* -dP causes the rtl to be emitted as a comment in assembly. */
326 int flag_dump_rtl_in_asm = 0;
328 /* When non-NULL, indicates that whenever space is allocated on the
329 stack, the resulting stack pointer must not pass this
330 address---that is, for stacks that grow downward, the stack pointer
331 must always be greater than or equal to this address; for stacks
332 that grow upward, the stack pointer must be less than this address.
333 At present, the rtx may be either a REG or a SYMBOL_REF, although
334 the support provided depends on the backend. */
335 rtx stack_limit_rtx;
337 /* Positive if we should track variables, negative if we should run
338 the var-tracking pass only to discard debug annotations, zero if
339 we're not to run it. When flag_var_tracking == AUTODETECT_VALUE it
340 will be set according to optimize, debug_info_level and debug_hooks
341 in process_options (). */
342 int flag_var_tracking = AUTODETECT_VALUE;
344 /* Positive if we should track variables at assignments, negative if
345 we should run the var-tracking pass only to discard debug
346 annotations. When flag_var_tracking_assignments ==
347 AUTODETECT_VALUE it will be set according to flag_var_tracking. */
348 int flag_var_tracking_assignments = AUTODETECT_VALUE;
350 /* Nonzero if we should toggle flag_var_tracking_assignments after
351 processing options and computing its default. */
352 int flag_var_tracking_assignments_toggle = 0;
354 /* Type of stack check. */
355 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
357 /* True if the user has tagged the function with the 'section'
358 attribute. */
360 bool user_defined_section_attribute = false;
362 /* Values of the -falign-* flags: how much to align labels in code.
363 0 means `use default', 1 means `don't align'.
364 For each variable, there is an _log variant which is the power
365 of two not less than the variable, for .align output. */
367 int align_loops_log;
368 int align_loops_max_skip;
369 int align_jumps_log;
370 int align_jumps_max_skip;
371 int align_labels_log;
372 int align_labels_max_skip;
373 int align_functions_log;
375 typedef struct
377 const char *const string;
378 int *const variable;
379 const int on_value;
381 lang_independent_options;
383 /* Nonzero if subexpressions must be evaluated from left-to-right. */
384 int flag_evaluation_order = 0;
386 /* The user symbol prefix after having resolved same. */
387 const char *user_label_prefix;
389 static const param_info lang_independent_params[] = {
390 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
391 { OPTION, DEFAULT, false, MIN, MAX, HELP },
392 #include "params.def"
393 #undef DEFPARAM
394 { NULL, 0, false, 0, 0, NULL }
397 /* Output files for assembler code (real compiler output)
398 and debugging dumps. */
400 FILE *asm_out_file;
401 FILE *graphite_out_file;
402 FILE *graphite_in_file;
403 FILE *aux_info_file;
404 FILE *dump_file = NULL;
405 const char *dump_file_name;
407 /* The current working directory of a translation. It's generally the
408 directory from which compilation was initiated, but a preprocessed
409 file may specify the original directory in which it was
410 created. */
412 static const char *src_pwd;
414 /* Initialize src_pwd with the given string, and return true. If it
415 was already initialized, return false. As a special case, it may
416 be called with a NULL argument to test whether src_pwd has NOT been
417 initialized yet. */
419 bool
420 set_src_pwd (const char *pwd)
422 if (src_pwd)
424 if (strcmp (src_pwd, pwd) == 0)
425 return true;
426 else
427 return false;
430 src_pwd = xstrdup (pwd);
431 return true;
434 /* Return the directory from which the translation unit was initiated,
435 in case set_src_pwd() was not called before to assign it a
436 different value. */
438 const char *
439 get_src_pwd (void)
441 if (! src_pwd)
443 src_pwd = getpwd ();
444 if (!src_pwd)
445 src_pwd = ".";
448 return src_pwd;
451 /* Called when the start of a function definition is parsed,
452 this function prints on stderr the name of the function. */
453 void
454 announce_function (tree decl)
456 if (!quiet_flag)
458 if (rtl_dump_and_exit)
459 fprintf (stderr, "%s ",
460 identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (decl))));
461 else
462 fprintf (stderr, " %s",
463 identifier_to_locale (lang_hooks.decl_printable_name (decl, 2)));
464 fflush (stderr);
465 pp_needs_newline (global_dc->printer) = true;
466 diagnostic_set_last_function (global_dc, (diagnostic_info *) NULL);
470 /* Initialize local_tick with the time of day, or -1 if
471 flag_random_seed is set. */
473 static void
474 init_local_tick (void)
476 if (!flag_random_seed)
478 /* Get some more or less random data. */
479 #ifdef HAVE_GETTIMEOFDAY
481 struct timeval tv;
483 gettimeofday (&tv, NULL);
484 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
486 #else
488 time_t now = time (NULL);
490 if (now != (time_t)-1)
491 local_tick = (unsigned) now;
493 #endif
495 else
496 local_tick = -1;
499 /* Set up a default flag_random_seed and local_tick, unless the user
500 already specified one. Must be called after init_local_tick. */
502 static void
503 init_random_seed (void)
505 unsigned HOST_WIDE_INT value;
506 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
508 value = local_tick ^ getpid ();
510 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
511 flag_random_seed = random_seed;
514 /* Obtain the random_seed string. Unless NOINIT, initialize it if
515 it's not provided in the command line. */
517 const char *
518 get_random_seed (bool noinit)
520 if (!flag_random_seed && !noinit)
521 init_random_seed ();
522 return flag_random_seed;
525 /* Modify the random_seed string to VAL. Return its previous
526 value. */
528 const char *
529 set_random_seed (const char *val)
531 const char *old = flag_random_seed;
532 flag_random_seed = val;
533 return old;
536 /* Decode the string P as an integral parameter.
537 If the string is indeed an integer return its numeric value else
538 issue an Invalid Option error for the option PNAME and return DEFVAL.
539 If PNAME is zero just return DEFVAL, do not call error. */
542 read_integral_parameter (const char *p, const char *pname, const int defval)
544 const char *endp = p;
546 while (*endp)
548 if (ISDIGIT (*endp))
549 endp++;
550 else
551 break;
554 if (*endp != 0)
556 if (pname != 0)
557 error ("invalid option argument %qs", pname);
558 return defval;
561 return atoi (p);
564 #if GCC_VERSION < 3004
566 /* The functions floor_log2 and exact_log2 are defined as inline
567 functions in toplev.h if GCC_VERSION >= 3004. The definitions here
568 are used for older versions of gcc. */
570 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
571 If X is 0, return -1. */
574 floor_log2 (unsigned HOST_WIDE_INT x)
576 int t = 0;
578 if (x == 0)
579 return -1;
581 if (HOST_BITS_PER_WIDE_INT > 64)
582 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
583 t += 64;
584 if (HOST_BITS_PER_WIDE_INT > 32)
585 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
586 t += 32;
587 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
588 t += 16;
589 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
590 t += 8;
591 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
592 t += 4;
593 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
594 t += 2;
595 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
596 t += 1;
598 return t;
601 /* Return the logarithm of X, base 2, considering X unsigned,
602 if X is a power of 2. Otherwise, returns -1. */
605 exact_log2 (unsigned HOST_WIDE_INT x)
607 if (x != (x & -x))
608 return -1;
609 return floor_log2 (x);
612 #endif /* GCC_VERSION < 3004 */
614 /* Handler for fatal signals, such as SIGSEGV. These are transformed
615 into ICE messages, which is much more user friendly. In case the
616 error printer crashes, reset the signal to prevent infinite recursion. */
618 static void
619 crash_signal (int signo)
621 signal (signo, SIG_DFL);
623 /* If we crashed while processing an ASM statement, then be a little more
624 graceful. It's most likely the user's fault. */
625 if (this_is_asm_operands)
627 output_operand_lossage ("unrecoverable error");
628 exit (FATAL_EXIT_CODE);
631 internal_error ("%s", strsignal (signo));
634 /* Arrange to dump core on error. (The regular error message is still
635 printed first, except in the case of abort().) */
637 static void
638 setup_core_dumping (void)
640 #ifdef SIGABRT
641 signal (SIGABRT, SIG_DFL);
642 #endif
643 #if defined(HAVE_SETRLIMIT)
645 struct rlimit rlim;
646 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
647 fatal_error ("getting core file size maximum limit: %m");
648 rlim.rlim_cur = rlim.rlim_max;
649 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
650 fatal_error ("setting core file size limit to maximum: %m");
652 #endif
653 diagnostic_abort_on_error (global_dc);
657 /* Strip off a legitimate source ending from the input string NAME of
658 length LEN. Rather than having to know the names used by all of
659 our front ends, we strip off an ending of a period followed by
660 up to five characters. (Java uses ".class".) */
662 void
663 strip_off_ending (char *name, int len)
665 int i;
666 for (i = 2; i < 6 && len > i; i++)
668 if (name[len - i] == '.')
670 name[len - i] = '\0';
671 break;
676 /* Output a quoted string. */
678 void
679 output_quoted_string (FILE *asm_file, const char *string)
681 #ifdef OUTPUT_QUOTED_STRING
682 OUTPUT_QUOTED_STRING (asm_file, string);
683 #else
684 char c;
686 putc ('\"', asm_file);
687 while ((c = *string++) != 0)
689 if (ISPRINT (c))
691 if (c == '\"' || c == '\\')
692 putc ('\\', asm_file);
693 putc (c, asm_file);
695 else
696 fprintf (asm_file, "\\%03o", (unsigned char) c);
698 putc ('\"', asm_file);
699 #endif
702 /* Output a file name in the form wanted by System V. */
704 void
705 output_file_directive (FILE *asm_file, const char *input_name)
707 int len;
708 const char *na;
710 if (input_name == NULL)
711 input_name = "<stdin>";
712 else
713 input_name = remap_debug_filename (input_name);
715 len = strlen (input_name);
716 na = input_name + len;
718 /* NA gets INPUT_NAME sans directory names. */
719 while (na > input_name)
721 if (IS_DIR_SEPARATOR (na[-1]))
722 break;
723 na--;
726 #ifdef ASM_OUTPUT_SOURCE_FILENAME
727 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
728 #else
729 fprintf (asm_file, "\t.file\t");
730 output_quoted_string (asm_file, na);
731 putc ('\n', asm_file);
732 #endif
735 /* A subroutine of wrapup_global_declarations. We've come to the end of
736 the compilation unit. All deferred variables should be undeferred,
737 and all incomplete decls should be finalized. */
739 void
740 wrapup_global_declaration_1 (tree decl)
742 /* We're not deferring this any longer. Assignment is conditional to
743 avoid needlessly dirtying PCH pages. */
744 if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
745 && DECL_DEFER_OUTPUT (decl) != 0)
746 DECL_DEFER_OUTPUT (decl) = 0;
748 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
749 lang_hooks.finish_incomplete_decl (decl);
752 /* A subroutine of wrapup_global_declarations. Decide whether or not DECL
753 needs to be output. Return true if it is output. */
755 bool
756 wrapup_global_declaration_2 (tree decl)
758 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
759 return false;
761 /* Don't write out static consts, unless we still need them.
763 We also keep static consts if not optimizing (for debugging),
764 unless the user specified -fno-keep-static-consts.
765 ??? They might be better written into the debug information.
766 This is possible when using DWARF.
768 A language processor that wants static constants to be always
769 written out (even if it is not used) is responsible for
770 calling rest_of_decl_compilation itself. E.g. the C front-end
771 calls rest_of_decl_compilation from finish_decl.
772 One motivation for this is that is conventional in some
773 environments to write things like:
774 static const char rcsid[] = "... version string ...";
775 intending to force the string to be in the executable.
777 A language processor that would prefer to have unneeded
778 static constants "optimized away" would just defer writing
779 them out until here. E.g. C++ does this, because static
780 constants are often defined in header files.
782 ??? A tempting alternative (for both C and C++) would be
783 to force a constant to be written if and only if it is
784 defined in a main file, as opposed to an include file. */
786 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
788 struct varpool_node *node;
789 bool needed = true;
790 node = varpool_node (decl);
792 if (node->finalized)
793 needed = false;
794 else if (node->alias)
795 needed = false;
796 else if (!cgraph_global_info_ready
797 && (TREE_USED (decl)
798 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
799 /* needed */;
800 else if (node->needed)
801 /* needed */;
802 else if (DECL_COMDAT (decl))
803 needed = false;
804 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
805 && (optimize || !flag_keep_static_consts
806 || DECL_ARTIFICIAL (decl)))
807 needed = false;
809 if (needed)
811 rest_of_decl_compilation (decl, 1, 1);
812 return true;
816 return false;
819 /* Do any final processing required for the declarations in VEC, of
820 which there are LEN. We write out inline functions and variables
821 that have been deferred until this point, but which are required.
822 Returns nonzero if anything was put out. */
824 bool
825 wrapup_global_declarations (tree *vec, int len)
827 bool reconsider, output_something = false;
828 int i;
830 for (i = 0; i < len; i++)
831 wrapup_global_declaration_1 (vec[i]);
833 /* Now emit any global variables or functions that we have been
834 putting off. We need to loop in case one of the things emitted
835 here references another one which comes earlier in the list. */
838 reconsider = false;
839 for (i = 0; i < len; i++)
840 reconsider |= wrapup_global_declaration_2 (vec[i]);
841 if (reconsider)
842 output_something = true;
844 while (reconsider);
846 return output_something;
849 /* A subroutine of check_global_declarations. Issue appropriate warnings
850 for the global declaration DECL. */
852 void
853 check_global_declaration_1 (tree decl)
855 /* Warn about any function declared static but not defined. We don't
856 warn about variables, because many programs have static variables
857 that exist only to get some text into the object file. */
858 if (TREE_CODE (decl) == FUNCTION_DECL
859 && DECL_INITIAL (decl) == 0
860 && DECL_EXTERNAL (decl)
861 && ! DECL_ARTIFICIAL (decl)
862 && ! TREE_NO_WARNING (decl)
863 && ! TREE_PUBLIC (decl)
864 && (warn_unused_function
865 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
867 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
868 pedwarn (input_location, 0, "%q+F used but never defined", decl);
869 else
870 warning (OPT_Wunused_function, "%q+F declared %<static%> but never defined", decl);
871 /* This symbol is effectively an "extern" declaration now. */
872 TREE_PUBLIC (decl) = 1;
873 assemble_external (decl);
876 /* Warn about static fns or vars defined but not used. */
877 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
878 /* We don't warn about "static const" variables because the
879 "rcs_id" idiom uses that construction. */
880 || (warn_unused_variable
881 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
882 && ! DECL_IN_SYSTEM_HEADER (decl)
883 && ! TREE_USED (decl)
884 /* The TREE_USED bit for file-scope decls is kept in the identifier,
885 to handle multiple external decls in different scopes. */
886 && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
887 && ! DECL_EXTERNAL (decl)
888 && ! TREE_PUBLIC (decl)
889 /* A volatile variable might be used in some non-obvious way. */
890 && ! TREE_THIS_VOLATILE (decl)
891 /* Global register variables must be declared to reserve them. */
892 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
893 /* Otherwise, ask the language. */
894 && lang_hooks.decls.warn_unused_global (decl))
895 warning ((TREE_CODE (decl) == FUNCTION_DECL)
896 ? OPT_Wunused_function
897 : OPT_Wunused_variable,
898 "%q+D defined but not used", decl);
901 /* Issue appropriate warnings for the global declarations in VEC (of
902 which there are LEN). */
904 void
905 check_global_declarations (tree *vec, int len)
907 int i;
909 for (i = 0; i < len; i++)
910 check_global_declaration_1 (vec[i]);
913 /* Emit debugging information for all global declarations in VEC. */
915 void
916 emit_debug_global_declarations (tree *vec, int len)
918 int i;
920 /* Avoid confusing the debug information machinery when there are errors. */
921 if (errorcount != 0 || sorrycount != 0)
922 return;
924 timevar_push (TV_SYMOUT);
925 for (i = 0; i < len; i++)
926 debug_hooks->global_decl (vec[i]);
927 timevar_pop (TV_SYMOUT);
930 /* Warn about a use of an identifier which was marked deprecated. */
931 void
932 warn_deprecated_use (tree node, tree attr)
934 const char *msg;
936 if (node == 0 || !warn_deprecated_decl)
937 return;
939 if (!attr)
941 if (DECL_P (node))
942 attr = DECL_ATTRIBUTES (node);
943 else if (TYPE_P (node))
945 tree decl = TYPE_STUB_DECL (node);
946 if (decl)
947 attr = lookup_attribute ("deprecated",
948 TYPE_ATTRIBUTES (TREE_TYPE (decl)));
952 if (attr)
953 attr = lookup_attribute ("deprecated", attr);
955 if (attr)
956 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)));
957 else
958 msg = NULL;
960 if (DECL_P (node))
962 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
963 if (msg)
964 warning (OPT_Wdeprecated_declarations,
965 "%qD is deprecated (declared at %s:%d): %s",
966 node, xloc.file, xloc.line, msg);
967 else
968 warning (OPT_Wdeprecated_declarations,
969 "%qD is deprecated (declared at %s:%d)",
970 node, xloc.file, xloc.line);
972 else if (TYPE_P (node))
974 tree what = NULL_TREE;
975 tree decl = TYPE_STUB_DECL (node);
977 if (TYPE_NAME (node))
979 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
980 what = TYPE_NAME (node);
981 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
982 && DECL_NAME (TYPE_NAME (node)))
983 what = DECL_NAME (TYPE_NAME (node));
986 if (decl)
988 expanded_location xloc
989 = expand_location (DECL_SOURCE_LOCATION (decl));
990 if (what)
992 if (msg)
993 warning (OPT_Wdeprecated_declarations,
994 "%qE is deprecated (declared at %s:%d): %s",
995 what, xloc.file, xloc.line, msg);
996 else
997 warning (OPT_Wdeprecated_declarations,
998 "%qE is deprecated (declared at %s:%d)", what,
999 xloc.file, xloc.line);
1001 else
1003 if (msg)
1004 warning (OPT_Wdeprecated_declarations,
1005 "type is deprecated (declared at %s:%d): %s",
1006 xloc.file, xloc.line, msg);
1007 else
1008 warning (OPT_Wdeprecated_declarations,
1009 "type is deprecated (declared at %s:%d)",
1010 xloc.file, xloc.line);
1013 else
1015 if (what)
1017 if (msg)
1018 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
1019 what, msg);
1020 else
1021 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
1023 else
1025 if (msg)
1026 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
1027 msg);
1028 else
1029 warning (OPT_Wdeprecated_declarations, "type is deprecated");
1035 /* Compile an entire translation unit. Write a file of assembly
1036 output and various debugging dumps. */
1038 static void
1039 compile_file (void)
1041 /* Initialize yet another pass. */
1043 ggc_protect_identifiers = true;
1045 init_cgraph ();
1046 init_final (main_input_filename);
1047 coverage_init (aux_base_name);
1048 statistics_init ();
1049 invoke_plugin_callbacks (PLUGIN_START_UNIT, NULL);
1051 timevar_push (TV_PARSE);
1053 /* Call the parser, which parses the entire file (calling
1054 rest_of_compilation for each function). */
1055 lang_hooks.parse_file (set_yydebug);
1057 /* Compilation is now finished except for writing
1058 what's left of the symbol table output. */
1059 timevar_pop (TV_PARSE);
1061 if (flag_syntax_only)
1062 return;
1064 ggc_protect_identifiers = false;
1066 /* This must also call cgraph_finalize_compilation_unit. */
1067 lang_hooks.decls.final_write_globals ();
1069 if (errorcount || sorrycount)
1070 return;
1072 varpool_assemble_pending_decls ();
1073 finish_aliases_2 ();
1075 /* Likewise for mudflap static object registrations. */
1076 if (flag_mudflap)
1077 mudflap_finish_file ();
1079 /* Likewise for emulated thread-local storage. */
1080 if (!targetm.have_tls)
1081 emutls_finish ();
1083 output_shared_constant_pool ();
1084 output_object_blocks ();
1086 /* Write out any pending weak symbol declarations. */
1087 weak_finish ();
1089 /* Do dbx symbols. */
1090 timevar_push (TV_SYMOUT);
1092 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
1093 if (dwarf2out_do_frame ())
1094 dwarf2out_frame_finish ();
1095 #endif
1097 (*debug_hooks->finish) (main_input_filename);
1098 timevar_pop (TV_SYMOUT);
1100 /* Output some stuff at end of file if nec. */
1102 dw2_output_indirect_constants ();
1104 /* Flush any pending external directives. */
1105 process_pending_assemble_externals ();
1107 /* Emit LTO marker if LTO info has been previously emitted. This is
1108 used by collect2 to determine whether an object file contains IL.
1109 We used to emit an undefined reference here, but this produces
1110 link errors if an object file with IL is stored into a shared
1111 library without invoking lto1. */
1112 if (flag_generate_lto)
1114 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1115 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, NULL_TREE,
1116 "__gnu_lto_v1",
1117 (unsigned HOST_WIDE_INT) 1, 8);
1118 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1119 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, "__gnu_lto_v1",
1120 (unsigned HOST_WIDE_INT) 1, 8);
1121 #else
1122 ASM_OUTPUT_COMMON (asm_out_file, "__gnu_lto_v1",
1123 (unsigned HOST_WIDE_INT) 1,
1124 (unsigned HOST_WIDE_INT) 1);
1125 #endif
1128 /* Attach a special .ident directive to the end of the file to identify
1129 the version of GCC which compiled this code. The format of the .ident
1130 string is patterned after the ones produced by native SVR4 compilers. */
1131 #ifdef IDENT_ASM_OP
1132 if (!flag_no_ident)
1134 const char *pkg_version = "(GNU) ";
1136 if (strcmp ("(GCC) ", pkgversion_string))
1137 pkg_version = pkgversion_string;
1138 fprintf (asm_out_file, "%s\"GCC: %s%s\"\n",
1139 IDENT_ASM_OP, pkg_version, version_string);
1141 #endif
1143 /* Invoke registered plugin callbacks. */
1144 invoke_plugin_callbacks (PLUGIN_FINISH_UNIT, NULL);
1146 /* This must be at the end. Some target ports emit end of file directives
1147 into the assembly file here, and hence we can not output anything to the
1148 assembly file after this point. */
1149 targetm.asm_out.file_end ();
1152 /* Parse a -d... command line switch. */
1154 void
1155 decode_d_option (const char *arg)
1157 int c;
1159 while (*arg)
1160 switch (c = *arg++)
1162 case 'A':
1163 flag_debug_asm = 1;
1164 break;
1165 case 'p':
1166 flag_print_asm_name = 1;
1167 break;
1168 case 'P':
1169 flag_dump_rtl_in_asm = 1;
1170 flag_print_asm_name = 1;
1171 break;
1172 case 'v':
1173 graph_dump_format = vcg;
1174 break;
1175 case 'x':
1176 rtl_dump_and_exit = 1;
1177 break;
1178 case 'y':
1179 set_yydebug = 1;
1180 break;
1181 case 'D': /* These are handled by the preprocessor. */
1182 case 'I':
1183 case 'M':
1184 case 'N':
1185 case 'U':
1186 break;
1187 case 'H':
1188 setup_core_dumping();
1189 break;
1190 case 'a':
1191 enable_rtl_dump_file ();
1192 break;
1194 default:
1195 warning (0, "unrecognized gcc debugging option: %c", c);
1196 break;
1200 /* Indexed by enum debug_info_type. */
1201 const char *const debug_type_names[] =
1203 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1206 /* Print version information to FILE.
1207 Each line begins with INDENT (for the case where FILE is the
1208 assembler output file). */
1210 void
1211 print_version (FILE *file, const char *indent)
1213 static const char fmt1[] =
1214 #ifdef __GNUC__
1215 N_("%s%s%s %sversion %s (%s)\n%s\tcompiled by GNU C version %s, ")
1216 #else
1217 N_("%s%s%s %sversion %s (%s) compiled by CC, ")
1218 #endif
1220 static const char fmt2[] =
1221 N_("GMP version %s, MPFR version %s, MPC version %s\n");
1222 static const char fmt3[] =
1223 N_("%s%swarning: %s header version %s differs from library version %s.\n");
1224 static const char fmt4[] =
1225 N_("%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n");
1226 #ifndef __VERSION__
1227 #define __VERSION__ "[?]"
1228 #endif
1229 fprintf (file,
1230 file == stderr ? _(fmt1) : fmt1,
1231 indent, *indent != 0 ? " " : "",
1232 lang_hooks.name, pkgversion_string, version_string, TARGET_NAME,
1233 indent, __VERSION__);
1235 /* We need to stringify the GMP macro values. Ugh, gmp_version has
1236 two string formats, "i.j.k" and "i.j" when k is zero. As of
1237 gmp-4.3.0, GMP always uses the 3 number format. */
1238 #define GCC_GMP_STRINGIFY_VERSION3(X) #X
1239 #define GCC_GMP_STRINGIFY_VERSION2(X) GCC_GMP_STRINGIFY_VERSION3(X)
1240 #define GCC_GMP_VERSION_NUM(X,Y,Z) (((X) << 16L) | ((Y) << 8) | (Z))
1241 #define GCC_GMP_VERSION \
1242 GCC_GMP_VERSION_NUM(__GNU_MP_VERSION, __GNU_MP_VERSION_MINOR, __GNU_MP_VERSION_PATCHLEVEL)
1243 #if GCC_GMP_VERSION < GCC_GMP_VERSION_NUM(4,3,0) && __GNU_MP_VERSION_PATCHLEVEL == 0
1244 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1245 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR)
1246 #else
1247 #define GCC_GMP_STRINGIFY_VERSION GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION) "." \
1248 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_MINOR) "." \
1249 GCC_GMP_STRINGIFY_VERSION2(__GNU_MP_VERSION_PATCHLEVEL)
1250 #endif
1251 fprintf (file,
1252 file == stderr ? _(fmt2) : fmt2,
1253 GCC_GMP_STRINGIFY_VERSION, MPFR_VERSION_STRING, MPC_VERSION_STRING);
1254 if (strcmp (GCC_GMP_STRINGIFY_VERSION, gmp_version))
1255 fprintf (file,
1256 file == stderr ? _(fmt3) : fmt3,
1257 indent, *indent != 0 ? " " : "",
1258 "GMP", GCC_GMP_STRINGIFY_VERSION, gmp_version);
1259 if (strcmp (MPFR_VERSION_STRING, mpfr_get_version ()))
1260 fprintf (file,
1261 file == stderr ? _(fmt3) : fmt3,
1262 indent, *indent != 0 ? " " : "",
1263 "MPFR", MPFR_VERSION_STRING, mpfr_get_version ());
1264 if (strcmp (MPC_VERSION_STRING, mpc_get_version ()))
1265 fprintf (file,
1266 file == stderr ? _(fmt3) : fmt3,
1267 indent, *indent != 0 ? " " : "",
1268 "MPC", MPC_VERSION_STRING, mpc_get_version ());
1269 fprintf (file,
1270 file == stderr ? _(fmt4) : fmt4,
1271 indent, *indent != 0 ? " " : "",
1272 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1274 print_plugins_versions (file, indent);
1277 #ifdef ASM_COMMENT_START
1278 static int
1279 print_to_asm_out_file (print_switch_type type, const char * text)
1281 bool prepend_sep = true;
1283 switch (type)
1285 case SWITCH_TYPE_LINE_END:
1286 putc ('\n', asm_out_file);
1287 return 1;
1289 case SWITCH_TYPE_LINE_START:
1290 fputs (ASM_COMMENT_START, asm_out_file);
1291 return strlen (ASM_COMMENT_START);
1293 case SWITCH_TYPE_DESCRIPTIVE:
1294 if (ASM_COMMENT_START[0] == 0)
1295 prepend_sep = false;
1296 /* Drop through. */
1297 case SWITCH_TYPE_PASSED:
1298 case SWITCH_TYPE_ENABLED:
1299 if (prepend_sep)
1300 fputc (' ', asm_out_file);
1301 fputs (text, asm_out_file);
1302 /* No need to return the length here as
1303 print_single_switch has already done it. */
1304 return 0;
1306 default:
1307 return -1;
1310 #endif
1312 static int
1313 print_to_stderr (print_switch_type type, const char * text)
1315 switch (type)
1317 case SWITCH_TYPE_LINE_END:
1318 putc ('\n', stderr);
1319 return 1;
1321 case SWITCH_TYPE_LINE_START:
1322 return 0;
1324 case SWITCH_TYPE_PASSED:
1325 case SWITCH_TYPE_ENABLED:
1326 fputc (' ', stderr);
1327 /* Drop through. */
1329 case SWITCH_TYPE_DESCRIPTIVE:
1330 fputs (text, stderr);
1331 /* No need to return the length here as
1332 print_single_switch has already done it. */
1333 return 0;
1335 default:
1336 return -1;
1340 /* Print an option value and return the adjusted position in the line.
1341 ??? print_fn doesn't handle errors, eg disk full; presumably other
1342 code will catch a disk full though. */
1344 static int
1345 print_single_switch (print_switch_fn_type print_fn,
1346 int pos,
1347 print_switch_type type,
1348 const char * text)
1350 /* The ultrix fprintf returns 0 on success, so compute the result
1351 we want here since we need it for the following test. The +1
1352 is for the separator character that will probably be emitted. */
1353 int len = strlen (text) + 1;
1355 if (pos != 0
1356 && pos + len > MAX_LINE)
1358 print_fn (SWITCH_TYPE_LINE_END, NULL);
1359 pos = 0;
1362 if (pos == 0)
1363 pos += print_fn (SWITCH_TYPE_LINE_START, NULL);
1365 print_fn (type, text);
1366 return pos + len;
1369 /* Print active target switches using PRINT_FN.
1370 POS is the current cursor position and MAX is the size of a "line".
1371 Each line begins with INDENT and ends with TERM.
1372 Each switch is separated from the next by SEP. */
1374 static void
1375 print_switch_values (print_switch_fn_type print_fn)
1377 int pos = 0;
1378 size_t j;
1379 const char **p;
1381 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1382 that it can be printed below. This helps reproducibility. */
1383 if (!flag_random_seed)
1384 init_random_seed ();
1386 /* Print the options as passed. */
1387 pos = print_single_switch (print_fn, pos,
1388 SWITCH_TYPE_DESCRIPTIVE, _("options passed: "));
1390 for (p = &save_argv[1]; *p != NULL; p++)
1392 if (**p == '-')
1394 /* Ignore these. */
1395 if (strcmp (*p, "-o") == 0
1396 || strcmp (*p, "-dumpbase") == 0
1397 || strcmp (*p, "-dumpdir") == 0
1398 || strcmp (*p, "-auxbase") == 0)
1400 if (p[1] != NULL)
1401 p++;
1402 continue;
1405 if (strcmp (*p, "-quiet") == 0
1406 || strcmp (*p, "-version") == 0)
1407 continue;
1409 if ((*p)[1] == 'd')
1410 continue;
1413 pos = print_single_switch (print_fn, pos, SWITCH_TYPE_PASSED, *p);
1416 if (pos > 0)
1417 print_fn (SWITCH_TYPE_LINE_END, NULL);
1419 /* Print the -f and -m options that have been enabled.
1420 We don't handle language specific options but printing argv
1421 should suffice. */
1422 pos = print_single_switch (print_fn, 0,
1423 SWITCH_TYPE_DESCRIPTIVE, _("options enabled: "));
1425 for (j = 0; j < cl_options_count; j++)
1426 if ((cl_options[j].flags & CL_REPORT)
1427 && option_enabled (j) > 0)
1428 pos = print_single_switch (print_fn, pos,
1429 SWITCH_TYPE_ENABLED, cl_options[j].opt_text);
1431 print_fn (SWITCH_TYPE_LINE_END, NULL);
1434 /* Open assembly code output file. Do this even if -fsyntax-only is
1435 on, because then the driver will have provided the name of a
1436 temporary file or bit bucket for us. NAME is the file specified on
1437 the command line, possibly NULL. */
1438 static void
1439 init_asm_output (const char *name)
1441 if (name == NULL && asm_file_name == 0)
1442 asm_out_file = stdout;
1443 else
1445 if (asm_file_name == 0)
1447 int len = strlen (dump_base_name);
1448 char *dumpname = XNEWVEC (char, len + 6);
1450 memcpy (dumpname, dump_base_name, len + 1);
1451 strip_off_ending (dumpname, len);
1452 strcat (dumpname, ".s");
1453 asm_file_name = dumpname;
1455 if (!strcmp (asm_file_name, "-"))
1456 asm_out_file = stdout;
1457 else
1458 asm_out_file = fopen (asm_file_name, "w+b");
1459 if (asm_out_file == 0)
1460 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1463 if (flag_graphite_read)
1465 int len = strlen (dump_base_name);
1466 char *dumpname = XNEWVEC (char, len + 10);
1468 gcc_assert (!flag_graphite_write);
1470 memcpy (dumpname, dump_base_name, len + 1);
1471 strip_off_ending (dumpname, len);
1472 strcat (dumpname, ".graphite");
1473 graphite_in_file = fopen (dumpname, "r+b");
1474 if (graphite_in_file == 0)
1475 fatal_error ("can%'t open %s for writing: %m", dumpname);
1476 free (dumpname);
1479 if (flag_graphite_write)
1481 int len = strlen (dump_base_name);
1482 char *dumpname = XNEWVEC (char, len + 10);
1484 gcc_assert (!flag_graphite_read);
1486 memcpy (dumpname, dump_base_name, len + 1);
1487 strip_off_ending (dumpname, len);
1488 strcat (dumpname, ".graphite");
1489 graphite_out_file = fopen (dumpname, "w+b");
1490 if (graphite_out_file == 0)
1491 fatal_error ("can%'t open %s for writing: %m", dumpname);
1492 free (dumpname);
1495 if (!flag_syntax_only)
1497 targetm.asm_out.file_start ();
1499 if (flag_record_gcc_switches)
1501 if (targetm.asm_out.record_gcc_switches)
1503 /* Let the target know that we are about to start recording. */
1504 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1505 NULL);
1506 /* Now record the switches. */
1507 print_switch_values (targetm.asm_out.record_gcc_switches);
1508 /* Let the target know that the recording is over. */
1509 targetm.asm_out.record_gcc_switches (SWITCH_TYPE_DESCRIPTIVE,
1510 NULL);
1512 else
1513 inform (input_location, "-frecord-gcc-switches is not supported by the current target");
1516 #ifdef ASM_COMMENT_START
1517 if (flag_verbose_asm)
1519 /* Print the list of switches in effect
1520 into the assembler file as comments. */
1521 print_version (asm_out_file, ASM_COMMENT_START);
1522 print_switch_values (print_to_asm_out_file);
1523 putc ('\n', asm_out_file);
1525 #endif
1529 /* Return true if the state of option OPTION should be stored in PCH files
1530 and checked by default_pch_valid_p. Store the option's current state
1531 in STATE if so. */
1533 static inline bool
1534 option_affects_pch_p (int option, struct cl_option_state *state)
1536 if ((cl_options[option].flags & CL_TARGET) == 0)
1537 return false;
1538 if (cl_options[option].flag_var == &target_flags)
1539 if (targetm.check_pch_target_flags)
1540 return false;
1541 return get_option_state (option, state);
1544 /* Default version of get_pch_validity.
1545 By default, every flag difference is fatal; that will be mostly right for
1546 most targets, but completely right for very few. */
1548 void *
1549 default_get_pch_validity (size_t *sz)
1551 struct cl_option_state state;
1552 size_t i;
1553 char *result, *r;
1555 *sz = 2;
1556 if (targetm.check_pch_target_flags)
1557 *sz += sizeof (target_flags);
1558 for (i = 0; i < cl_options_count; i++)
1559 if (option_affects_pch_p (i, &state))
1560 *sz += state.size;
1562 result = r = XNEWVEC (char, *sz);
1563 r[0] = flag_pic;
1564 r[1] = flag_pie;
1565 r += 2;
1566 if (targetm.check_pch_target_flags)
1568 memcpy (r, &target_flags, sizeof (target_flags));
1569 r += sizeof (target_flags);
1572 for (i = 0; i < cl_options_count; i++)
1573 if (option_affects_pch_p (i, &state))
1575 memcpy (r, state.data, state.size);
1576 r += state.size;
1579 return result;
1582 /* Return a message which says that a PCH file was created with a different
1583 setting of OPTION. */
1585 static const char *
1586 pch_option_mismatch (const char *option)
1588 char *r;
1590 asprintf (&r, _("created and used with differing settings of '%s'"), option);
1591 if (r == NULL)
1592 return _("out of memory");
1593 return r;
1596 /* Default version of pch_valid_p. */
1598 const char *
1599 default_pch_valid_p (const void *data_p, size_t len)
1601 struct cl_option_state state;
1602 const char *data = (const char *)data_p;
1603 size_t i;
1605 /* -fpic and -fpie also usually make a PCH invalid. */
1606 if (data[0] != flag_pic)
1607 return _("created and used with different settings of -fpic");
1608 if (data[1] != flag_pie)
1609 return _("created and used with different settings of -fpie");
1610 data += 2;
1612 /* Check target_flags. */
1613 if (targetm.check_pch_target_flags)
1615 int tf;
1616 const char *r;
1618 memcpy (&tf, data, sizeof (target_flags));
1619 data += sizeof (target_flags);
1620 len -= sizeof (target_flags);
1621 r = targetm.check_pch_target_flags (tf);
1622 if (r != NULL)
1623 return r;
1626 for (i = 0; i < cl_options_count; i++)
1627 if (option_affects_pch_p (i, &state))
1629 if (memcmp (data, state.data, state.size) != 0)
1630 return pch_option_mismatch (cl_options[i].opt_text);
1631 data += state.size;
1632 len -= state.size;
1635 return NULL;
1638 /* Default tree printer. Handles declarations only. */
1639 bool
1640 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
1641 int precision, bool wide, bool set_locus, bool hash)
1643 tree t;
1645 /* FUTURE: %+x should set the locus. */
1646 if (precision != 0 || wide || hash)
1647 return false;
1649 switch (*spec)
1651 case 'E':
1652 t = va_arg (*text->args_ptr, tree);
1653 if (TREE_CODE (t) == IDENTIFIER_NODE)
1655 pp_identifier (pp, IDENTIFIER_POINTER (t));
1656 return true;
1658 break;
1660 case 'D':
1661 t = va_arg (*text->args_ptr, tree);
1662 if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
1663 t = DECL_DEBUG_EXPR (t);
1664 break;
1666 case 'F':
1667 case 'T':
1668 t = va_arg (*text->args_ptr, tree);
1669 break;
1671 default:
1672 return false;
1675 if (set_locus && text->locus)
1676 *text->locus = DECL_SOURCE_LOCATION (t);
1678 if (DECL_P (t))
1680 const char *n = DECL_NAME (t)
1681 ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2))
1682 : _("<anonymous>");
1683 pp_string (pp, n);
1685 else
1686 dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0);
1688 return true;
1691 /* A helper function; used as the reallocator function for cpp's line
1692 table. */
1693 static void *
1694 realloc_for_line_map (void *ptr, size_t len)
1696 return ggc_realloc (ptr, len);
1699 /* Initialization of the front end environment, before command line
1700 options are parsed. Signal handlers, internationalization etc.
1701 ARGV0 is main's argv[0]. */
1702 static void
1703 general_init (const char *argv0)
1705 const char *p;
1707 p = argv0 + strlen (argv0);
1708 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1709 --p;
1710 progname = p;
1712 xmalloc_set_program_name (progname);
1714 hex_init ();
1716 /* Unlock the stdio streams. */
1717 unlock_std_streams ();
1719 gcc_init_libintl ();
1721 /* Initialize the diagnostics reporting machinery, so option parsing
1722 can give warnings and errors. */
1723 diagnostic_initialize (global_dc);
1724 /* Set a default printer. Language specific initializations will
1725 override it later. */
1726 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1728 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1729 #ifdef SIGSEGV
1730 signal (SIGSEGV, crash_signal);
1731 #endif
1732 #ifdef SIGILL
1733 signal (SIGILL, crash_signal);
1734 #endif
1735 #ifdef SIGBUS
1736 signal (SIGBUS, crash_signal);
1737 #endif
1738 #ifdef SIGABRT
1739 signal (SIGABRT, crash_signal);
1740 #endif
1741 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1742 signal (SIGIOT, crash_signal);
1743 #endif
1744 #ifdef SIGFPE
1745 signal (SIGFPE, crash_signal);
1746 #endif
1748 /* Other host-specific signal setup. */
1749 (*host_hooks.extra_signals)();
1751 /* Initialize the garbage-collector, string pools and tree type hash
1752 table. */
1753 init_ggc ();
1754 init_stringpool ();
1755 line_table = GGC_NEW (struct line_maps);
1756 linemap_init (line_table);
1757 line_table->reallocator = realloc_for_line_map;
1758 init_ttree ();
1760 /* Initialize register usage now so switches may override. */
1761 init_reg_sets ();
1763 /* Register the language-independent parameters. */
1764 add_params (lang_independent_params, LAST_PARAM);
1766 /* This must be done after add_params but before argument processing. */
1767 init_ggc_heuristics();
1768 init_optimization_passes ();
1769 statistics_early_init ();
1772 /* Return true if the current target supports -fsection-anchors. */
1774 static bool
1775 target_supports_section_anchors_p (void)
1777 if (targetm.min_anchor_offset == 0 && targetm.max_anchor_offset == 0)
1778 return false;
1780 if (targetm.asm_out.output_anchor == NULL)
1781 return false;
1783 return true;
1786 /* Default the align_* variables to 1 if they're still unset, and
1787 set up the align_*_log variables. */
1788 static void
1789 init_alignments (void)
1791 if (align_loops <= 0)
1792 align_loops = 1;
1793 if (align_loops_max_skip > align_loops)
1794 align_loops_max_skip = align_loops - 1;
1795 align_loops_log = floor_log2 (align_loops * 2 - 1);
1796 if (align_jumps <= 0)
1797 align_jumps = 1;
1798 if (align_jumps_max_skip > align_jumps)
1799 align_jumps_max_skip = align_jumps - 1;
1800 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1801 if (align_labels <= 0)
1802 align_labels = 1;
1803 align_labels_log = floor_log2 (align_labels * 2 - 1);
1804 if (align_labels_max_skip > align_labels)
1805 align_labels_max_skip = align_labels - 1;
1806 if (align_functions <= 0)
1807 align_functions = 1;
1808 align_functions_log = floor_log2 (align_functions * 2 - 1);
1811 /* Process the options that have been parsed. */
1812 static void
1813 process_options (void)
1815 /* Just in case lang_hooks.post_options ends up calling a debug_hook.
1816 This can happen with incorrect pre-processed input. */
1817 debug_hooks = &do_nothing_debug_hooks;
1819 /* This replaces set_Wunused. */
1820 if (warn_unused_function == -1)
1821 warn_unused_function = warn_unused;
1822 if (warn_unused_label == -1)
1823 warn_unused_label = warn_unused;
1824 /* Wunused-parameter is enabled if both -Wunused -Wextra are enabled. */
1825 if (warn_unused_parameter == -1)
1826 warn_unused_parameter = (warn_unused && extra_warnings);
1827 if (warn_unused_variable == -1)
1828 warn_unused_variable = warn_unused;
1829 if (warn_unused_value == -1)
1830 warn_unused_value = warn_unused;
1832 /* This replaces set_Wextra. */
1833 if (warn_uninitialized == -1)
1834 warn_uninitialized = extra_warnings;
1836 /* Allow the front end to perform consistency checks and do further
1837 initialization based on the command line options. This hook also
1838 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1839 so we can correctly initialize debug output. */
1840 no_backend = lang_hooks.post_options (&main_input_filename);
1842 #ifdef OVERRIDE_OPTIONS
1843 /* Some machines may reject certain combinations of options. */
1844 OVERRIDE_OPTIONS;
1845 #endif
1847 /* Avoid any informative notes in the second run of -fcompare-debug. */
1848 if (flag_compare_debug)
1849 diagnostic_inhibit_notes (global_dc);
1851 if (flag_section_anchors && !target_supports_section_anchors_p ())
1853 warning (OPT_fsection_anchors,
1854 "this target does not support %qs", "-fsection-anchors");
1855 flag_section_anchors = 0;
1858 if (flag_short_enums == 2)
1859 flag_short_enums = targetm.default_short_enums ();
1861 /* Set aux_base_name if not already set. */
1862 if (aux_base_name)
1864 else if (main_input_filename)
1866 char *name = xstrdup (lbasename (main_input_filename));
1868 strip_off_ending (name, strlen (name));
1869 aux_base_name = name;
1871 else
1872 aux_base_name = "gccaux";
1874 #ifndef HAVE_cloog
1875 if (flag_graphite
1876 || flag_loop_block
1877 || flag_loop_interchange
1878 || flag_loop_strip_mine
1879 || flag_graphite_identity
1880 || flag_loop_parallelize_all)
1881 sorry ("Graphite loop optimizations cannot be used");
1882 #endif
1884 /* Unrolling all loops implies that standard loop unrolling must also
1885 be done. */
1886 if (flag_unroll_all_loops)
1887 flag_unroll_loops = 1;
1889 /* The loop unrolling code assumes that cse will be run after loop.
1890 web and rename-registers also help when run after loop unrolling. */
1891 if (flag_rerun_cse_after_loop == AUTODETECT_VALUE)
1892 flag_rerun_cse_after_loop = flag_unroll_loops || flag_peel_loops;
1894 if (flag_web == AUTODETECT_VALUE)
1895 flag_web = flag_unroll_loops || flag_peel_loops;
1897 if (flag_rename_registers == AUTODETECT_VALUE)
1898 flag_rename_registers = flag_unroll_loops || flag_peel_loops;
1900 if (flag_non_call_exceptions)
1901 flag_asynchronous_unwind_tables = 1;
1902 if (flag_asynchronous_unwind_tables)
1903 flag_unwind_tables = 1;
1905 if (flag_value_profile_transformations)
1906 flag_profile_values = 1;
1908 /* Warn about options that are not supported on this machine. */
1909 #ifndef INSN_SCHEDULING
1910 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1911 warning (0, "instruction scheduling not supported on this target machine");
1912 #endif
1913 #ifndef DELAY_SLOTS
1914 if (flag_delayed_branch)
1915 warning (0, "this target machine does not have delayed branches");
1916 #endif
1918 user_label_prefix = USER_LABEL_PREFIX;
1919 if (flag_leading_underscore != -1)
1921 /* If the default prefix is more complicated than "" or "_",
1922 issue a warning and ignore this option. */
1923 if (user_label_prefix[0] == 0 ||
1924 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1926 user_label_prefix = flag_leading_underscore ? "_" : "";
1928 else
1929 warning (0, "-f%sleading-underscore not supported on this target machine",
1930 flag_leading_underscore ? "" : "no-");
1933 /* If we are in verbose mode, write out the version and maybe all the
1934 option flags in use. */
1935 if (version_flag)
1937 print_version (stderr, "");
1938 if (! quiet_flag)
1939 print_switch_values (print_to_stderr);
1942 if (flag_syntax_only)
1944 write_symbols = NO_DEBUG;
1945 profile_flag = 0;
1948 if (flag_gtoggle)
1950 if (debug_info_level == DINFO_LEVEL_NONE)
1952 debug_info_level = DINFO_LEVEL_NORMAL;
1954 if (write_symbols == NO_DEBUG)
1955 write_symbols = PREFERRED_DEBUGGING_TYPE;
1957 else
1958 debug_info_level = DINFO_LEVEL_NONE;
1961 if (flag_dump_final_insns && !flag_syntax_only && !no_backend)
1963 FILE *final_output = fopen (flag_dump_final_insns, "w");
1964 if (!final_output)
1966 error ("could not open final insn dump file %qs: %s",
1967 flag_dump_final_insns, strerror (errno));
1968 flag_dump_final_insns = NULL;
1970 else if (fclose (final_output))
1972 error ("could not close zeroed insn dump file %qs: %s",
1973 flag_dump_final_insns, strerror (errno));
1974 flag_dump_final_insns = NULL;
1978 /* Unless over-ridden for the target, assume that all DWARF levels
1979 may be emitted, if DWARF2_DEBUG is selected. */
1980 if (dwarf_strict < 0)
1981 dwarf_strict = 0;
1983 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1984 level is 0. */
1985 if (debug_info_level == DINFO_LEVEL_NONE)
1986 write_symbols = NO_DEBUG;
1988 /* Now we know write_symbols, set up the debug hooks based on it.
1989 By default we do nothing for debug output. */
1990 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1991 default_debug_hooks = &do_nothing_debug_hooks;
1992 #if defined(DBX_DEBUGGING_INFO)
1993 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1994 default_debug_hooks = &dbx_debug_hooks;
1995 #endif
1996 #if defined(XCOFF_DEBUGGING_INFO)
1997 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1998 default_debug_hooks = &xcoff_debug_hooks;
1999 #endif
2000 #ifdef SDB_DEBUGGING_INFO
2001 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
2002 default_debug_hooks = &sdb_debug_hooks;
2003 #endif
2004 #ifdef DWARF2_DEBUGGING_INFO
2005 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
2006 default_debug_hooks = &dwarf2_debug_hooks;
2007 #endif
2008 #ifdef VMS_DEBUGGING_INFO
2009 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
2010 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
2011 default_debug_hooks = &vmsdbg_debug_hooks;
2012 #endif
2014 if (write_symbols == NO_DEBUG)
2016 #if defined(DBX_DEBUGGING_INFO)
2017 else if (write_symbols == DBX_DEBUG)
2018 debug_hooks = &dbx_debug_hooks;
2019 #endif
2020 #if defined(XCOFF_DEBUGGING_INFO)
2021 else if (write_symbols == XCOFF_DEBUG)
2022 debug_hooks = &xcoff_debug_hooks;
2023 #endif
2024 #ifdef SDB_DEBUGGING_INFO
2025 else if (write_symbols == SDB_DEBUG)
2026 debug_hooks = &sdb_debug_hooks;
2027 #endif
2028 #ifdef DWARF2_DEBUGGING_INFO
2029 else if (write_symbols == DWARF2_DEBUG)
2030 debug_hooks = &dwarf2_debug_hooks;
2031 #endif
2032 #ifdef VMS_DEBUGGING_INFO
2033 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2034 debug_hooks = &vmsdbg_debug_hooks;
2035 #endif
2036 else
2037 error ("target system does not support the \"%s\" debug format",
2038 debug_type_names[write_symbols]);
2040 /* We know which debug output will be used so we can set flag_var_tracking
2041 and flag_var_tracking_uninit if the user has not specified them. */
2042 if (debug_info_level < DINFO_LEVEL_NORMAL
2043 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
2045 if (flag_var_tracking == 1
2046 || flag_var_tracking_uninit == 1)
2048 if (debug_info_level < DINFO_LEVEL_NORMAL)
2049 warning (0, "variable tracking requested, but useless unless "
2050 "producing debug info");
2051 else
2052 warning (0, "variable tracking requested, but not supported "
2053 "by this debug format");
2055 flag_var_tracking = 0;
2056 flag_var_tracking_uninit = 0;
2059 /* If the user specifically requested variable tracking with tagging
2060 uninitialized variables, we need to turn on variable tracking.
2061 (We already determined above that variable tracking is feasible.) */
2062 if (flag_var_tracking_uninit)
2063 flag_var_tracking = 1;
2065 if (flag_var_tracking == AUTODETECT_VALUE)
2066 flag_var_tracking = optimize >= 1;
2068 if (flag_var_tracking_assignments == AUTODETECT_VALUE)
2069 flag_var_tracking_assignments = flag_var_tracking
2070 && !(flag_selective_scheduling || flag_selective_scheduling2);
2072 if (flag_var_tracking_assignments_toggle)
2073 flag_var_tracking_assignments = !flag_var_tracking_assignments;
2075 if (flag_var_tracking_assignments && !flag_var_tracking)
2076 flag_var_tracking = flag_var_tracking_assignments = -1;
2078 if (flag_var_tracking_assignments
2079 && (flag_selective_scheduling || flag_selective_scheduling2))
2080 warning (0, "var-tracking-assignments changes selective scheduling");
2082 if (flag_tree_cselim == AUTODETECT_VALUE)
2083 #ifdef HAVE_conditional_move
2084 flag_tree_cselim = 1;
2085 #else
2086 flag_tree_cselim = 0;
2087 #endif
2089 /* If auxiliary info generation is desired, open the output file.
2090 This goes in the same directory as the source file--unlike
2091 all the other output files. */
2092 if (flag_gen_aux_info)
2094 aux_info_file = fopen (aux_info_file_name, "w");
2095 if (aux_info_file == 0)
2096 fatal_error ("can%'t open %s: %m", aux_info_file_name);
2099 if (! targetm.have_named_sections)
2101 if (flag_function_sections)
2103 warning (0, "-ffunction-sections not supported for this target");
2104 flag_function_sections = 0;
2106 if (flag_data_sections)
2108 warning (0, "-fdata-sections not supported for this target");
2109 flag_data_sections = 0;
2113 if (flag_function_sections && profile_flag)
2115 warning (0, "-ffunction-sections disabled; it makes profiling impossible");
2116 flag_function_sections = 0;
2119 #ifndef HAVE_prefetch
2120 if (flag_prefetch_loop_arrays)
2122 warning (0, "-fprefetch-loop-arrays not supported for this target");
2123 flag_prefetch_loop_arrays = 0;
2125 #else
2126 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
2128 warning (0, "-fprefetch-loop-arrays not supported for this target (try -march switches)");
2129 flag_prefetch_loop_arrays = 0;
2131 #endif
2133 /* This combination of options isn't handled for i386 targets and doesn't
2134 make much sense anyway, so don't allow it. */
2135 if (flag_prefetch_loop_arrays && optimize_size)
2137 warning (0, "-fprefetch-loop-arrays is not supported with -Os");
2138 flag_prefetch_loop_arrays = 0;
2141 /* The presence of IEEE signaling NaNs, implies all math can trap. */
2142 if (flag_signaling_nans)
2143 flag_trapping_math = 1;
2145 /* We cannot reassociate if we want traps or signed zeros. */
2146 if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))
2148 warning (0, "-fassociative-math disabled; other options take precedence");
2149 flag_associative_math = 0;
2152 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
2153 if (flag_cx_limited_range)
2154 flag_complex_method = 0;
2156 /* With -fcx-fortran-rules, we do something in-between cheap and C99. */
2157 if (flag_cx_fortran_rules)
2158 flag_complex_method = 1;
2160 /* Targets must be able to place spill slots at lower addresses. If the
2161 target already uses a soft frame pointer, the transition is trivial. */
2162 if (!FRAME_GROWS_DOWNWARD && flag_stack_protect)
2164 warning (0, "-fstack-protector not supported for this target");
2165 flag_stack_protect = 0;
2167 if (!flag_stack_protect)
2168 warn_stack_protect = 0;
2170 /* ??? Unwind info is not correct around the CFG unless either a frame
2171 pointer is present or A_O_A is set. Fixing this requires rewriting
2172 unwind info generation to be aware of the CFG and propagating states
2173 around edges. */
2174 if (flag_unwind_tables && !ACCUMULATE_OUTGOING_ARGS
2175 && flag_omit_frame_pointer)
2177 warning (0, "unwind tables currently require a frame pointer "
2178 "for correctness");
2179 flag_omit_frame_pointer = 0;
2183 /* This function can be called multiple times to reinitialize the compiler
2184 back end when register classes or instruction sets have changed,
2185 before each function. */
2186 static void
2187 backend_init_target (void)
2189 /* Initialize alignment variables. */
2190 init_alignments ();
2192 /* This reinitializes hard_frame_pointer, and calls init_reg_modes_target()
2193 to initialize reg_raw_mode[]. */
2194 init_emit_regs ();
2196 /* This invokes target hooks to set fixed_reg[] etc, which is
2197 mode-dependent. */
2198 init_regs ();
2200 /* This depends on stack_pointer_rtx. */
2201 init_fake_stack_mems ();
2203 /* Sets static_base_value[HARD_FRAME_POINTER_REGNUM], which is
2204 mode-dependent. */
2205 init_alias_target ();
2207 /* Depends on HARD_FRAME_POINTER_REGNUM. */
2208 init_reload ();
2210 /* The following initialization functions need to generate rtl, so
2211 provide a dummy function context for them. */
2212 init_dummy_function_start ();
2214 /* rtx_cost is mode-dependent, so cached values need to be recomputed
2215 on a mode change. */
2216 init_expmed ();
2218 /* We may need to recompute regno_save_code[] and regno_restore_code[]
2219 after a mode change as well. */
2220 if (flag_caller_saves)
2221 init_caller_save ();
2222 expand_dummy_function_end ();
2225 /* Initialize the compiler back end. This function is called only once,
2226 when starting the compiler. */
2227 static void
2228 backend_init (void)
2230 init_emit_once ();
2232 init_rtlanal ();
2233 init_inline_once ();
2234 init_varasm_once ();
2235 save_register_info ();
2237 /* Initialize the target-specific back end pieces. */
2238 ira_init_once ();
2239 backend_init_target ();
2242 /* Initialize excess precision settings. */
2243 static void
2244 init_excess_precision (void)
2246 /* Adjust excess precision handling based on the target options. If
2247 the front end cannot handle it, flag_excess_precision_cmdline
2248 will already have been set accordingly in the post_options
2249 hook. */
2250 gcc_assert (flag_excess_precision_cmdline != EXCESS_PRECISION_DEFAULT);
2251 flag_excess_precision = flag_excess_precision_cmdline;
2252 if (flag_unsafe_math_optimizations)
2253 flag_excess_precision = EXCESS_PRECISION_FAST;
2254 if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
2256 int flt_eval_method = TARGET_FLT_EVAL_METHOD;
2257 switch (flt_eval_method)
2259 case -1:
2260 case 0:
2261 /* Either the target acts unpredictably (-1) or has all the
2262 operations required not to have excess precision (0). */
2263 flag_excess_precision = EXCESS_PRECISION_FAST;
2264 break;
2265 case 1:
2266 case 2:
2267 /* In these cases, predictable excess precision makes
2268 sense. */
2269 break;
2270 default:
2271 /* Any other implementation-defined FLT_EVAL_METHOD values
2272 require the compiler to handle the associated excess
2273 precision rules in excess_precision_type. */
2274 gcc_unreachable ();
2279 /* Initialize things that are both lang-dependent and target-dependent.
2280 This function can be called more than once if target parameters change. */
2281 static void
2282 lang_dependent_init_target (void)
2284 /* This determines excess precision settings. */
2285 init_excess_precision ();
2287 /* This creates various _DECL nodes, so needs to be called after the
2288 front end is initialized. It also depends on the HAVE_xxx macros
2289 generated from the target machine description. */
2290 init_optabs ();
2292 /* The following initialization functions need to generate rtl, so
2293 provide a dummy function context for them. */
2294 init_dummy_function_start ();
2296 /* Do the target-specific parts of expr initialization. */
2297 init_expr_target ();
2299 /* Although the actions of these functions are language-independent,
2300 they use optabs, so we cannot call them from backend_init. */
2301 init_set_costs ();
2302 ira_init ();
2304 expand_dummy_function_end ();
2307 /* Language-dependent initialization. Returns nonzero on success. */
2308 static int
2309 lang_dependent_init (const char *name)
2311 location_t save_loc = input_location;
2312 if (dump_base_name == 0)
2313 dump_base_name = name && name[0] ? name : "gccdump";
2315 /* Other front-end initialization. */
2316 input_location = BUILTINS_LOCATION;
2317 if (lang_hooks.init () == 0)
2318 return 0;
2319 input_location = save_loc;
2321 init_asm_output (name);
2323 /* This creates various _DECL nodes, so needs to be called after the
2324 front end is initialized. */
2325 init_eh ();
2327 /* Do the target-specific parts of the initialization. */
2328 lang_dependent_init_target ();
2330 /* If dbx symbol table desired, initialize writing it and output the
2331 predefined types. */
2332 timevar_push (TV_SYMOUT);
2334 #if defined DWARF2_DEBUGGING_INFO || defined DWARF2_UNWIND_INFO
2335 if (dwarf2out_do_frame ())
2336 dwarf2out_frame_init ();
2337 #endif
2339 /* Now we have the correct original filename, we can initialize
2340 debug output. */
2341 (*debug_hooks->init) (name);
2343 timevar_pop (TV_SYMOUT);
2345 return 1;
2349 /* Reinitialize everything when target parameters, such as register usage,
2350 have changed. */
2351 void
2352 target_reinit (void)
2354 /* Reinitialize RTL backend. */
2355 backend_init_target ();
2357 /* Reinitialize lang-dependent parts. */
2358 lang_dependent_init_target ();
2361 void
2362 dump_memory_report (bool final)
2364 ggc_print_statistics ();
2365 stringpool_statistics ();
2366 dump_tree_statistics ();
2367 dump_gimple_statistics ();
2368 dump_rtx_statistics ();
2369 dump_varray_statistics ();
2370 dump_alloc_pool_statistics ();
2371 dump_bitmap_statistics ();
2372 dump_vec_loc_statistics ();
2373 dump_ggc_loc_statistics (final);
2374 dump_alias_stats (stderr);
2375 dump_pta_stats (stderr);
2378 /* Clean up: close opened files, etc. */
2380 static void
2381 finalize (void)
2383 /* Close the dump files. */
2384 if (flag_gen_aux_info)
2386 fclose (aux_info_file);
2387 if (errorcount)
2388 unlink (aux_info_file_name);
2391 /* Close non-debugging input and output files. Take special care to note
2392 whether fclose returns an error, since the pages might still be on the
2393 buffer chain while the file is open. */
2395 if (asm_out_file)
2397 if (ferror (asm_out_file) != 0)
2398 fatal_error ("error writing to %s: %m", asm_file_name);
2399 if (fclose (asm_out_file) != 0)
2400 fatal_error ("error closing %s: %m", asm_file_name);
2401 if (flag_wpa)
2402 unlink_if_ordinary (asm_file_name);
2405 statistics_fini ();
2406 finish_optimization_passes ();
2408 ira_finish_once ();
2410 if (mem_report)
2411 dump_memory_report (true);
2413 /* Language-specific end of compilation actions. */
2414 lang_hooks.finish ();
2417 /* Initialize the compiler, and compile the input file. */
2418 static void
2419 do_compile (void)
2421 /* Initialize timing first. The C front ends read the main file in
2422 the post_options hook, and C++ does file timings. */
2423 if (time_report || !quiet_flag || flag_detailed_statistics)
2424 timevar_init ();
2425 timevar_start (TV_TOTAL);
2427 process_options ();
2429 /* Don't do any more if an error has already occurred. */
2430 if (!errorcount)
2432 /* This must be run always, because it is needed to compute the FP
2433 predefined macros, such as __LDBL_MAX__, for targets using non
2434 default FP formats. */
2435 init_adjust_machine_modes ();
2437 /* Set up the back-end if requested. */
2438 if (!no_backend)
2439 backend_init ();
2441 /* Language-dependent initialization. Returns true on success. */
2442 if (lang_dependent_init (main_input_filename))
2443 compile_file ();
2445 finalize ();
2448 /* Stop timing and print the times. */
2449 timevar_stop (TV_TOTAL);
2450 timevar_print (stderr);
2453 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2454 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2455 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2457 It is not safe to call this function more than once. */
2460 toplev_main (int argc, char **argv)
2462 expandargv (&argc, &argv);
2464 save_argv = CONST_CAST2 (const char **, char **, argv);
2466 /* Initialization of GCC's environment, and diagnostics. */
2467 general_init (argv[0]);
2469 /* Parse the options and do minimal processing; basically just
2470 enough to default flags appropriately. */
2471 decode_options (argc, CONST_CAST2 (const char **, char **, argv));
2473 init_local_tick ();
2475 initialize_plugins ();
2477 if (version_flag)
2478 print_version (stderr, "");
2480 if (help_flag)
2481 print_plugins_help (stderr, "");
2483 /* Exit early if we can (e.g. -help). */
2484 if (!exit_after_options)
2485 do_compile ();
2487 if (warningcount || errorcount)
2488 print_ignored_options ();
2490 /* Invoke registered plugin callbacks if any. */
2491 invoke_plugin_callbacks (PLUGIN_FINISH, NULL);
2493 finalize_plugins ();
2494 if (errorcount || sorrycount)
2495 return (FATAL_EXIT_CODE);
2497 return (SUCCESS_EXIT_CODE);