Reset optimization_default_node after global option resetting
[official-gcc.git] / gcc-4_9 / gcc / params.c
blob03b769cfdb093a1c07793c880bc68b9d2240a1f1
1 /* params.c - Run-time parameters.
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
3 Written by Mark Mitchell <mark@codesourcery.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "common/common-target.h"
25 #include "params.h"
26 #include "diagnostic-core.h"
28 /* An array containing the compiler parameters and their current
29 values. */
31 param_info *compiler_params;
33 /* The number of entries in the table. */
34 static size_t num_compiler_params;
36 /* Whether the parameters have all been initialized and had their
37 default values determined. */
38 static bool params_finished;
40 static const param_info lang_independent_params[] = {
41 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
42 { OPTION, DEFAULT, MIN, MAX, HELP },
43 #include "params.def"
44 #undef DEFPARAM
45 { NULL, 0, 0, 0, NULL }
48 /* Add the N PARAMS to the current list of compiler parameters. */
50 void
51 add_params (const param_info params[], size_t n)
53 gcc_assert (!params_finished);
55 /* Allocate enough space for the new parameters. */
56 compiler_params = XRESIZEVEC (param_info, compiler_params,
57 num_compiler_params + n);
58 /* Copy them into the table. */
59 memcpy (compiler_params + num_compiler_params,
60 params,
61 n * sizeof (param_info));
62 /* Keep track of how many parameters we have. */
63 num_compiler_params += n;
66 /* Add all parameters and default values that can be set in both the
67 driver and the compiler proper. */
69 void
70 global_init_params (void)
72 add_params (lang_independent_params, LAST_PARAM);
73 #ifndef IN_GCOV_TOOL
74 targetm_common.option_default_params ();
75 #endif
78 /* Note that all parameters have been added and all default values
79 set. */
81 void
82 finish_params (void)
84 params_finished = true;
87 /* Set the value of the parameter given by NUM to VALUE in PARAMS and
88 PARAMS_SET. If EXPLICIT_P, this is being set by the user;
89 otherwise it is being set implicitly by the compiler. */
91 static void
92 set_param_value_internal (compiler_param num, int value,
93 int *params, int *params_set,
94 bool explicit_p)
96 size_t i = (size_t) num;
98 gcc_assert (params_finished);
100 params[i] = value;
101 if (explicit_p)
102 params_set[i] = true;
105 /* Set the VALUE associated with the parameter given by NAME in PARAMS
106 and PARAMS_SET. */
108 void
109 set_param_value (const char *name, int value,
110 int *params, int *params_set)
112 size_t i;
114 /* Make sure nobody tries to set a parameter to an invalid value. */
115 gcc_assert (value != INVALID_PARAM_VAL);
117 /* Scan the parameter table to find a matching entry. */
118 for (i = 0; i < num_compiler_params; ++i)
119 if (strcmp (compiler_params[i].option, name) == 0)
121 if (value < compiler_params[i].min_value)
122 error ("minimum value of parameter %qs is %u",
123 compiler_params[i].option,
124 compiler_params[i].min_value);
125 else if (compiler_params[i].max_value > compiler_params[i].min_value
126 && value > compiler_params[i].max_value)
127 error ("maximum value of parameter %qs is %u",
128 compiler_params[i].option,
129 compiler_params[i].max_value);
130 else
131 set_param_value_internal ((compiler_param) i, value,
132 params, params_set, true);
133 return;
136 /* If we didn't find this parameter, issue an error message. */
137 error ("invalid parameter %qs", name);
140 /* Set the value of the parameter given by NUM to VALUE in PARAMS and
141 PARAMS_SET, implicitly, if it has not been set explicitly by the
142 user. */
144 void
145 maybe_set_param_value (compiler_param num, int value,
146 int *params, int *params_set)
148 if (!params_set[(int) num])
149 set_param_value_internal (num, value, params, params_set, false);
152 /* Set the default value of a parameter given by NUM to VALUE, before
153 option processing. */
155 void
156 set_default_param_value (compiler_param num, int value)
158 gcc_assert (!params_finished);
160 compiler_params[(int) num].default_value = value;
163 /* Return the default value of parameter NUM. */
166 default_param_value (compiler_param num)
168 return compiler_params[(int) num].default_value;
171 /* Initialize an array PARAMS with default values of the
172 parameters. */
174 void
175 init_param_values (int *params)
177 size_t i;
179 gcc_assert (params_finished);
181 for (i = 0; i < num_compiler_params; i++)
182 params[i] = compiler_params[i].default_value;
185 /* Return the current value of num_compiler_params, for the benefit of
186 plugins that use parameters as features. */
188 size_t
189 get_num_compiler_params (void)
191 return num_compiler_params;
194 /* Dump values of parameters. */
196 void
197 dump_params (int *params, int *params_set)
199 size_t i;
201 /* Scan the parameter table to find a matching entry. */
202 for (i = 0; i < num_compiler_params; ++i)
204 fprintf (stderr, "%s\t%d (%s)\n", compiler_params[i].option,
205 params[i], params_set[i] ? "explicit" : "implicit");