OSDN Git Service

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