3 Copyright (C) 2009-2014 Free Software Foundation, Inc.
4 Contributed by Simon Baldwin <simonb@google.com>
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
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
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/>. */
24 #include "coretypes.h"
26 #include "basic-block.h"
27 #include "tree-ssa-alias.h"
28 #include "internal-fn.h"
29 #include "gimple-expr.h"
37 #include "common/common-target.h"
38 #include "diagnostic.h"
39 #include "lto-streamer.h"
42 /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
43 set up by OB, appropriately quoted and separated by spaces
47 append_to_collect_gcc_options (struct obstack
*ob
,
48 bool *first_p
, const char *opt
)
50 const char *p
, *q
= opt
;
52 obstack_grow (ob
, " ", 1);
53 obstack_grow (ob
, "'", 1);
54 while ((p
= strchr (q
, '\'')))
56 obstack_grow (ob
, q
, p
- q
);
57 obstack_grow (ob
, "'\\''", 4);
60 obstack_grow (ob
, q
, strlen (q
));
61 obstack_grow (ob
, "'", 1);
65 /* Write currently held options to an LTO IL section. */
68 lto_write_options (void)
70 struct lto_output_stream stream
;
72 struct obstack temporary_obstack
;
77 section_name
= lto_get_section_name (LTO_section_opts
, NULL
, NULL
);
78 lto_begin_section (section_name
, false);
79 memset (&stream
, 0, sizeof (stream
));
81 obstack_init (&temporary_obstack
);
83 /* Output options that affect GIMPLE IL semantics and are implicitly
84 enabled by the frontend.
85 This for now includes an explicit set of options that we also handle
86 explicitly in lto-wrapper.c. In the end the effects on GIMPLE IL
87 semantics should be explicitely encoded in the IL or saved per
88 function rather than per compilation unit. */
89 /* -fexceptions causes the EH machinery to be initialized, enabling
90 generation of unwind data so that explicit throw() calls work. */
91 if (!global_options_set
.x_flag_exceptions
92 && global_options
.x_flag_exceptions
)
93 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
95 /* -fnon-call-exceptions changes the generation of exception
96 regions. It is enabled implicitly by the Go frontend. */
97 if (!global_options_set
.x_flag_non_call_exceptions
98 && global_options
.x_flag_non_call_exceptions
)
99 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
100 "-fnon-call-exceptions");
101 /* The default -ffp-contract changes depending on the language
102 standard. Pass thru conservative standard settings. */
103 if (!global_options_set
.x_flag_fp_contract_mode
)
104 switch (global_options
.x_flag_fp_contract_mode
)
106 case FP_CONTRACT_OFF
:
107 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
108 "-ffp-contract=off");
111 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
114 case FP_CONTRACT_FAST
:
115 /* Nothing. That merges conservatively and is the default for LTO. */
121 /* Output explicitly passed options. */
122 for (i
= 1; i
< save_decoded_options_count
; ++i
)
124 struct cl_decoded_option
*option
= &save_decoded_options
[i
];
126 /* Skip explicitly some common options that we do not need. */
127 switch (option
->opt_index
)
130 case OPT_SPECIAL_unknown
:
131 case OPT_SPECIAL_ignore
:
132 case OPT_SPECIAL_program_name
:
133 case OPT_SPECIAL_input_file
:
140 /* Skip frontend and driver specific options here. */
141 if (!(cl_options
[option
->opt_index
].flags
& (CL_COMMON
|CL_TARGET
|CL_LTO
)))
144 /* Drop options created from the gcc driver that will be rejected
145 when passed on to the driver again. */
146 if (cl_options
[option
->opt_index
].cl_reject_driver
)
149 /* Also drop all options that are handled by the driver as well,
150 which includes things like -o and -v or -fhelp for example.
151 We do not need those. Also drop all diagnostic options. */
152 if (cl_options
[option
->opt_index
].flags
& (CL_DRIVER
|CL_WARNING
))
155 for (j
= 0; j
< option
->canonical_option_num_elements
; ++j
)
156 append_to_collect_gcc_options (&temporary_obstack
, &first_p
,
157 option
->canonical_option
[j
]);
159 obstack_grow (&temporary_obstack
, "\0", 1);
160 args
= XOBFINISH (&temporary_obstack
, char *);
161 lto_output_data_stream (&stream
, args
, strlen (args
) + 1);
163 lto_write_stream (&stream
);
166 obstack_free (&temporary_obstack
, NULL
);