xref: /dflybsd-src/contrib/gcc-4.7/gcc/lto-opts.c (revision 81fc95a5293ee307c688a350a3feb4734aaddbb4)
1e4b17023SJohn Marino /* LTO IL options.
2e4b17023SJohn Marino 
3e4b17023SJohn Marino    Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4e4b17023SJohn Marino    Contributed by Simon Baldwin <simonb@google.com>
5e4b17023SJohn Marino 
6e4b17023SJohn Marino This file is part of GCC.
7e4b17023SJohn Marino 
8e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
9e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
10e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
11e4b17023SJohn Marino version.
12e4b17023SJohn Marino 
13e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
15e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16e4b17023SJohn Marino for more details.
17e4b17023SJohn Marino 
18e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19e4b17023SJohn Marino along with GCC; see the file COPYING3.  If not see
20e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
21e4b17023SJohn Marino 
22e4b17023SJohn Marino #include "config.h"
23e4b17023SJohn Marino #include "system.h"
24e4b17023SJohn Marino #include "coretypes.h"
25e4b17023SJohn Marino #include "tree.h"
26e4b17023SJohn Marino #include "hashtab.h"
27e4b17023SJohn Marino #include "ggc.h"
28e4b17023SJohn Marino #include "vec.h"
29e4b17023SJohn Marino #include "bitmap.h"
30e4b17023SJohn Marino #include "flags.h"
31e4b17023SJohn Marino #include "opts.h"
32e4b17023SJohn Marino #include "options.h"
33e4b17023SJohn Marino #include "common/common-target.h"
34e4b17023SJohn Marino #include "diagnostic.h"
35e4b17023SJohn Marino #include "lto-streamer.h"
36e4b17023SJohn Marino #include "toplev.h"
37e4b17023SJohn Marino 
38e4b17023SJohn Marino /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
39e4b17023SJohn Marino    set up by OB, appropriately quoted and separated by spaces
40e4b17023SJohn Marino    (if !*FIRST_P).  */
41e4b17023SJohn Marino 
42e4b17023SJohn Marino static void
append_to_collect_gcc_options(struct obstack * ob,bool * first_p,const char * opt)43e4b17023SJohn Marino append_to_collect_gcc_options (struct obstack *ob,
44e4b17023SJohn Marino 			       bool *first_p, const char *opt)
45e4b17023SJohn Marino {
46e4b17023SJohn Marino   const char *p, *q = opt;
47e4b17023SJohn Marino   if (!first_p)
48e4b17023SJohn Marino     obstack_grow (ob, " ", 1);
49e4b17023SJohn Marino   obstack_grow (ob, "'", 1);
50e4b17023SJohn Marino   while ((p = strchr (q, '\'')))
51e4b17023SJohn Marino     {
52e4b17023SJohn Marino       obstack_grow (ob, q, p - q);
53e4b17023SJohn Marino       obstack_grow (ob, "'\\''", 4);
54e4b17023SJohn Marino       q = ++p;
55e4b17023SJohn Marino     }
56e4b17023SJohn Marino   obstack_grow (ob, q, strlen (q));
57e4b17023SJohn Marino   obstack_grow (ob, "'", 1);
58e4b17023SJohn Marino   *first_p = false;
59e4b17023SJohn Marino }
60e4b17023SJohn Marino 
61e4b17023SJohn Marino /* Write currently held options to an LTO IL section.  */
62e4b17023SJohn Marino 
63e4b17023SJohn Marino void
lto_write_options(void)64e4b17023SJohn Marino lto_write_options (void)
65e4b17023SJohn Marino {
66e4b17023SJohn Marino   struct lto_output_stream stream;
67e4b17023SJohn Marino   char *section_name;
68e4b17023SJohn Marino   struct obstack temporary_obstack;
69e4b17023SJohn Marino   unsigned int i, j;
70e4b17023SJohn Marino   char *args;
71e4b17023SJohn Marino   bool first_p = true;
72e4b17023SJohn Marino 
73e4b17023SJohn Marino   section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
74e4b17023SJohn Marino   lto_begin_section (section_name, false);
75e4b17023SJohn Marino   memset (&stream, 0, sizeof (stream));
76e4b17023SJohn Marino 
77e4b17023SJohn Marino   obstack_init (&temporary_obstack);
78e4b17023SJohn Marino 
79e4b17023SJohn Marino   /* Output options that affect GIMPLE IL semantics and are implicitely
80e4b17023SJohn Marino      enabled by the frontend.
81e4b17023SJohn Marino      This for now includes an explicit set of options that we also handle
82e4b17023SJohn Marino      explicitly in lto-wrapper.c.  In the end the effects on GIMPLE IL
83e4b17023SJohn Marino      semantics should be explicitely encoded in the IL or saved per
84e4b17023SJohn Marino      function rather than per compilation unit.  */
85e4b17023SJohn Marino   /* -fexceptions causes the EH machinery to be initialized, enabling
86e4b17023SJohn Marino      generation of unwind data so that explicit throw() calls work.  */
87e4b17023SJohn Marino   if (global_options.x_flag_exceptions)
88e4b17023SJohn Marino     append_to_collect_gcc_options (&temporary_obstack, &first_p,
89e4b17023SJohn Marino 				   "-fexceptions");
90e4b17023SJohn Marino 
91e4b17023SJohn Marino   /* Output explicitely passed options.  */
92e4b17023SJohn Marino   for (i = 1; i < save_decoded_options_count; ++i)
93e4b17023SJohn Marino     {
94e4b17023SJohn Marino       struct cl_decoded_option *option = &save_decoded_options[i];
95e4b17023SJohn Marino 
96*5ce9237cSJohn Marino       /* Skip explicitly some common options that we do not need.  */
97*5ce9237cSJohn Marino       switch (option->opt_index)
98*5ce9237cSJohn Marino       {
99*5ce9237cSJohn Marino 	case OPT_dumpbase:
100*5ce9237cSJohn Marino 	case OPT_SPECIAL_unknown:
101*5ce9237cSJohn Marino 	case OPT_SPECIAL_ignore:
102*5ce9237cSJohn Marino 	case OPT_SPECIAL_program_name:
103*5ce9237cSJohn Marino 	case OPT_SPECIAL_input_file:
104*5ce9237cSJohn Marino 	  continue;
105*5ce9237cSJohn Marino 
106*5ce9237cSJohn Marino 	default:
107*5ce9237cSJohn Marino 	  break;
108*5ce9237cSJohn Marino       }
109*5ce9237cSJohn Marino 
110e4b17023SJohn Marino       /* Skip frontend and driver specific options here.  */
111e4b17023SJohn Marino       if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
112e4b17023SJohn Marino 	continue;
113e4b17023SJohn Marino 
114e4b17023SJohn Marino       /* Drop options created from the gcc driver that will be rejected
115e4b17023SJohn Marino 	 when passed on to the driver again.  */
116e4b17023SJohn Marino       if (cl_options[option->opt_index].cl_reject_driver)
117e4b17023SJohn Marino 	continue;
118e4b17023SJohn Marino 
119e4b17023SJohn Marino       /* Also drop all options that are handled by the driver as well,
120e4b17023SJohn Marino          which includes things like -o and -v or -fhelp for example.
121e4b17023SJohn Marino 	 We do not need those.  Also drop all diagnostic options.  */
122e4b17023SJohn Marino       if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
123e4b17023SJohn Marino 	continue;
124e4b17023SJohn Marino 
125e4b17023SJohn Marino       for (j = 0; j < option->canonical_option_num_elements; ++j)
126e4b17023SJohn Marino 	append_to_collect_gcc_options (&temporary_obstack, &first_p,
127e4b17023SJohn Marino 				       option->canonical_option[j]);
128e4b17023SJohn Marino     }
129e4b17023SJohn Marino   obstack_grow (&temporary_obstack, "\0", 1);
130e4b17023SJohn Marino   args = XOBFINISH (&temporary_obstack, char *);
131e4b17023SJohn Marino   lto_output_data_stream (&stream, args, strlen (args) + 1);
132e4b17023SJohn Marino 
133e4b17023SJohn Marino   lto_write_stream (&stream);
134e4b17023SJohn Marino   lto_end_section ();
135e4b17023SJohn Marino 
136e4b17023SJohn Marino   obstack_free (&temporary_obstack, NULL);
137e4b17023SJohn Marino   free (section_name);
138e4b17023SJohn Marino }
139