1 # Copyright (C) 2003-2014 Free Software Foundation, Inc.
2 # Contributed by Kelley Cook, June 2004.
3 # Original code from Neil Booth, May 2003.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; see the file COPYING3. If not see
17 # <http://www.gnu.org/licenses/>.
19 # This Awk script reads in the option records generated from
20 # opt-gather.awk, combines the flags of duplicate options and generates a
24 # This program uses functions from opt-functions.awk and code from
27 # Usage: awk -f opt-functions.awk -f opt-read.awk -f optc-save-gen.awk \
28 # [-v header_name=header.h] < inputfile > options-save.c
30 # Dump that array of options into a C file.
32 print "/* This file is auto-generated by optc-save-gen.awk. */"
34 n_headers =
split(header_name
, headers
, " ")
35 for (i =
1; i
<= n_headers
; i
++)
36 print "#include " quote headers
[i
] quote
37 print "#include " quote
"opts.h" quote
38 print "#include " quote
"intl.h" quote
40 print "#include " quote
"flags.h" quote
41 print "#include " quote
"target.h" quote
42 print "#include " quote
"inchash.h" quote
43 print "#include " quote
"tree.h" quote
44 print "#include " quote
"tree-ssa-alias.h" quote
45 print "#include " quote
"is-a.h" quote
46 print "#include " quote
"predict.h" quote
47 print "#include " quote
"function.h" quote
48 print "#include " quote
"basic-block.h" quote
49 print "#include " quote
"gimple-expr.h" quote
50 print "#include " quote
"gimple.h" quote
51 print "#include " quote
"data-streamer.h" quote
52 print "#include " quote
"ipa-ref.h" quote
53 print "#include " quote
"cgraph.h" quote
56 if (n_extra_c_includes
> 0) {
57 for (i =
0; i
< n_extra_c_includes
; i
++) {
58 print "#include " quote extra_c_includes
[i
] quote
64 if (n_extra_target_vars
)
67 for (i =
0; i
< n_opts
; i
++) {
68 if (flag_set_p
("Save", flags
[i
]))
72 print "/* Save optimization variables into a structure. */"
74 print "cl_optimization_save (struct cl_optimization *ptr, struct gcc_options *opts)";
82 var_opt_char
[0] =
"optimize";
83 var_opt_char
[1] =
"optimize_size";
84 var_opt_range
["optimize"] =
"0, 255";
85 var_opt_range
["optimize_size"] =
"0, 255";
86 var_opt_enum
[0] =
"flag_fp_contract_mode";
88 # Sort by size to mimic how the structure is laid out to be friendlier to the
91 for (i =
0; i
< n_opts
; i
++) {
92 if (flag_set_p
("Optimization", flags
[i
])) {
93 name = var_name
(flags
[i
])
97 if(name in var_opt_seen
)
100 var_opt_seen
[name
]++;
101 otype = var_type_struct
(flags
[i
]);
102 if (otype ~
"^((un)?signed +)?int *$")
103 var_opt_int
[n_opt_int
++] = name
;
105 else if (otype ~
"^((un)?signed +)?short *$")
106 var_opt_short
[n_opt_short
++] = name
;
108 else if (otype ~
("^enum +[_" alnum
"]+ *"))
109 var_opt_enum
[n_opt_enum
++] = name
;
111 else if (otype ~
"^((un)?signed +)?char *$") {
112 var_opt_char
[n_opt_char
++] = name
;
113 if (otype ~
"^unsigned +char *$")
114 var_opt_range
[name
] =
"0, 255"
115 else if (otype ~
"^signed +char *$")
116 var_opt_range
[name
] =
"-128, 127"
119 var_opt_other
[n_opt_other
++] = name
;
123 for (i =
0; i
< n_opt_char
; i
++) {
124 name = var_opt_char
[i
];
125 if (var_opt_range
[name
] != "")
126 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_opt_range
[name
] "));";
130 for (i =
0; i
< n_opt_other
; i
++) {
131 print " ptr->x_" var_opt_other
[i
] " = opts->x_" var_opt_other
[i
] ";";
134 for (i =
0; i
< n_opt_int
; i
++) {
135 print " ptr->x_" var_opt_int
[i
] " = opts->x_" var_opt_int
[i
] ";";
138 for (i =
0; i
< n_opt_enum
; i
++) {
139 print " ptr->x_" var_opt_enum
[i
] " = opts->x_" var_opt_enum
[i
] ";";
142 for (i =
0; i
< n_opt_short
; i
++) {
143 print " ptr->x_" var_opt_short
[i
] " = opts->x_" var_opt_short
[i
] ";";
146 for (i =
0; i
< n_opt_char
; i
++) {
147 print " ptr->x_" var_opt_char
[i
] " = opts->x_" var_opt_char
[i
] ";";
153 print "/* Restore optimization options from a structure. */";
155 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
158 for (i =
0; i
< n_opt_other
; i
++) {
159 print " opts->x_" var_opt_other
[i
] " = ptr->x_" var_opt_other
[i
] ";";
162 for (i =
0; i
< n_opt_int
; i
++) {
163 print " opts->x_" var_opt_int
[i
] " = ptr->x_" var_opt_int
[i
] ";";
166 for (i =
0; i
< n_opt_enum
; i
++) {
167 print " opts->x_" var_opt_enum
[i
] " = ptr->x_" var_opt_enum
[i
] ";";
170 for (i =
0; i
< n_opt_short
; i
++) {
171 print " opts->x_" var_opt_short
[i
] " = ptr->x_" var_opt_short
[i
] ";";
174 for (i =
0; i
< n_opt_char
; i
++) {
175 print " opts->x_" var_opt_char
[i
] " = ptr->x_" var_opt_char
[i
] ";";
178 print " targetm.override_options_after_change ();";
182 print "/* Print optimization options from a structure. */";
184 print "cl_optimization_print (FILE *file,";
185 print " int indent_to,";
186 print " struct cl_optimization *ptr)";
189 print " fputs (\"\\n\", file);";
190 for (i =
0; i
< n_opt_other
; i
++) {
191 print " if (ptr->x_" var_opt_other
[i
] ")";
192 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
193 print " indent_to, \"\",";
194 print " \"" var_opt_other
[i
] "\",";
195 print " (unsigned long)ptr->x_" var_opt_other
[i
] ");";
199 for (i =
0; i
< n_opt_int
; i
++) {
200 print " if (ptr->x_" var_opt_int
[i
] ")";
201 print " fprintf (file, \"%*s%s (%#x)\\n\",";
202 print " indent_to, \"\",";
203 print " \"" var_opt_int
[i
] "\",";
204 print " ptr->x_" var_opt_int
[i
] ");";
208 for (i =
0; i
< n_opt_enum
; i
++) {
209 print " fprintf (file, \"%*s%s (%#x)\\n\",";
210 print " indent_to, \"\",";
211 print " \"" var_opt_enum
[i
] "\",";
212 print " (int) ptr->x_" var_opt_enum
[i
] ");";
216 for (i =
0; i
< n_opt_short
; i
++) {
217 print " if (ptr->x_" var_opt_short
[i
] ")";
218 print " fprintf (file, \"%*s%s (%#x)\\n\",";
219 print " indent_to, \"\",";
220 print " \"" var_opt_short
[i
] "\",";
221 print " ptr->x_" var_opt_short
[i
] ");";
225 for (i =
0; i
< n_opt_char
; i
++) {
226 print " if (ptr->x_" var_opt_char
[i
] ")";
227 print " fprintf (file, \"%*s%s (%#x)\\n\",";
228 print " indent_to, \"\",";
229 print " \"" var_opt_char
[i
] "\",";
230 print " ptr->x_" var_opt_char
[i
] ");";
237 print "/* Save selected option variables into a structure. */"
239 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
249 for (i =
0; i
< n_opts
; i
++) {
250 if (flag_set_p
("Save", flags
[i
])) {
251 name = var_name
(flags
[i
])
253 name =
"target_flags";
255 if(name in var_save_seen
)
258 var_save_seen
[name
]++;
259 otype = var_type_struct
(flags
[i
])
260 if (otype ~
"^((un)?signed +)?int *$")
261 var_target_int
[n_target_int
++] = name
;
263 else if (otype ~
"^((un)?signed +)?short *$")
264 var_target_short
[n_target_short
++] = name
;
266 else if (otype ~
("^enum +[_" alnum
"]+ *$"))
267 var_target_enum
[n_target_enum
++] = name
;
269 else if (otype ~
"^((un)?signed +)?char *$") {
270 var_target_char
[n_target_char
++] = name
;
271 if (otype ~
"^unsigned +char *$")
272 var_target_range
[name
] =
"0, 255"
273 else if (otype ~
"^signed +char *$")
274 var_target_range
[name
] =
"-128, 127"
275 if (otype == var_type
(flags
[i
]))
276 var_target_range
[name
] =
""
279 var_target_other
[n_target_other
++] = name
;
283 var_target_int
[n_target_int
++] =
"target_flags";
287 for (i =
0; i
< n_target_char
; i
++) {
288 name = var_target_char
[i
];
289 if (var_target_range
[name
] != "") {
291 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_target_range
[name
] "));";
298 print " if (targetm.target_option.save)";
299 print " targetm.target_option.save (ptr, opts);";
302 for (i =
0; i
< n_extra_target_vars
; i
++) {
303 print " ptr->x_" extra_target_vars
[i
] " = opts->x_" extra_target_vars
[i
] ";";
306 for (i =
0; i
< n_target_other
; i
++) {
307 print " ptr->x_" var_target_other
[i
] " = opts->x_" var_target_other
[i
] ";";
310 for (i =
0; i
< n_target_enum
; i
++) {
311 print " ptr->x_" var_target_enum
[i
] " = opts->x_" var_target_enum
[i
] ";";
314 for (i =
0; i
< n_target_int
; i
++) {
315 print " ptr->x_" var_target_int
[i
] " = opts->x_" var_target_int
[i
] ";";
318 for (i =
0; i
< n_target_short
; i
++) {
319 print " ptr->x_" var_target_short
[i
] " = opts->x_" var_target_short
[i
] ";";
322 for (i =
0; i
< n_target_char
; i
++) {
323 print " ptr->x_" var_target_char
[i
] " = opts->x_" var_target_char
[i
] ";";
329 print "/* Restore selected current options from a structure. */";
331 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
334 for (i =
0; i
< n_extra_target_vars
; i
++) {
335 print " opts->x_" extra_target_vars
[i
] " = ptr->x_" extra_target_vars
[i
] ";";
338 for (i =
0; i
< n_target_other
; i
++) {
339 print " opts->x_" var_target_other
[i
] " = ptr->x_" var_target_other
[i
] ";";
342 for (i =
0; i
< n_target_enum
; i
++) {
343 print " opts->x_" var_target_enum
[i
] " = ptr->x_" var_target_enum
[i
] ";";
346 for (i =
0; i
< n_target_int
; i
++) {
347 print " opts->x_" var_target_int
[i
] " = ptr->x_" var_target_int
[i
] ";";
350 for (i =
0; i
< n_target_short
; i
++) {
351 print " opts->x_" var_target_short
[i
] " = ptr->x_" var_target_short
[i
] ";";
354 for (i =
0; i
< n_target_char
; i
++) {
355 print " opts->x_" var_target_char
[i
] " = ptr->x_" var_target_char
[i
] ";";
358 # This must occur after the normal variables in case the code depends on those
361 print " if (targetm.target_option.restore)";
362 print " targetm.target_option.restore (opts, ptr);";
367 print "/* Print optimization options from a structure. */";
369 print "cl_target_option_print (FILE *file,";
370 print " int indent,";
371 print " struct cl_target_option *ptr)";
374 print " fputs (\"\\n\", file);";
375 for (i =
0; i
< n_target_other
; i
++) {
376 print " if (ptr->x_" var_target_other
[i
] ")";
377 if (host_wide_int
[var_target_other
[i
]] ==
"yes")
378 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
380 print " fprintf (file, \"%*s%s (%#x)\\n\",";
381 print " indent, \"\",";
382 print " \"" var_target_other
[i
] "\",";
383 if (host_wide_int
[var_target_other
[i
]] ==
"yes")
384 print " ptr->x_" var_target_other
[i
] ");";
386 print " (unsigned long)ptr->x_" var_target_other
[i
] ");";
390 for (i =
0; i
< n_target_enum
; i
++) {
391 print " if (ptr->x_" var_target_enum
[i
] ")";
392 print " fprintf (file, \"%*s%s (%#x)\\n\",";
393 print " indent, \"\",";
394 print " \"" var_target_enum
[i
] "\",";
395 print " ptr->x_" var_target_enum
[i
] ");";
399 for (i =
0; i
< n_target_int
; i
++) {
400 print " if (ptr->x_" var_target_int
[i
] ")";
401 print " fprintf (file, \"%*s%s (%#x)\\n\",";
402 print " indent, \"\",";
403 print " \"" var_target_int
[i
] "\",";
404 print " ptr->x_" var_target_int
[i
] ");";
408 for (i =
0; i
< n_target_short
; i
++) {
409 print " if (ptr->x_" var_target_short
[i
] ")";
410 print " fprintf (file, \"%*s%s (%#x)\\n\",";
411 print " indent, \"\",";
412 print " \"" var_target_short
[i
] "\",";
413 print " ptr->x_" var_target_short
[i
] ");";
417 for (i =
0; i
< n_target_char
; i
++) {
418 print " if (ptr->x_" var_target_char
[i
] ")";
419 print " fprintf (file, \"%*s%s (%#x)\\n\",";
420 print " indent, \"\",";
421 print " \"" var_target_char
[i
] "\",";
422 print " ptr->x_" var_target_char
[i
] ");";
427 print " if (targetm.target_option.print)";
428 print " targetm.target_option.print (file, indent, ptr);";
433 print "/* Compare two target options */";
435 print "cl_target_option_eq (struct cl_target_option const *ptr1 ATTRIBUTE_UNUSED,";
436 print " struct cl_target_option const *ptr2 ATTRIBUTE_UNUSED)";
441 for (i =
0; i
< n_target_save
; i
++) {
442 var = target_save_decl
[i
];
443 sub (" *=.*", "", var
);
446 sub("^.*[ *]", "", name
)
447 sub(" *" name
"$", "", type
)
448 if (target_save_decl
[i
] ~
"^const char \\*+[_" alnum
"]+$")
449 var_target_str
[n_target_str
++] = name
;
451 var_target_val_type
[n_target_val
] = type
;
452 var_target_val
[n_target_val
++] = name
;
456 for (i =
0; i
< n_opts
; i
++) {
457 if (flag_set_p
("Save", flags
[i
])) {
458 name = var_name
(flags
[i
])
460 name =
"target_flags";
462 if(name in var_list_seen
)
465 var_list_seen
[name
]++;
466 otype = var_type_struct
(flags
[i
])
467 if (otype ~
"^const char \\**$")
468 var_target_str
[n_target_str
++] =
"x_" name
;
470 var_target_val_type
[n_target_val
] = otype
;
471 var_target_val
[n_target_val
++] =
"x_" name
;
476 var_target_val_type
[n_target_val
] =
"int";
477 var_target_val
[n_target_val
++] =
"x_target_flags";
480 for (i =
0; i
< n_target_str
; i
++) {
481 name = var_target_str
[i
]
482 print " if (ptr1->" name
" != ptr2->" name
;
483 print " && (!ptr1->" name
" || !ptr2->" name
484 print " || strcmp (ptr1->" name
", ptr2->" name
")))";
485 print " return false;";
487 for (i =
0; i
< n_target_val
; i
++) {
488 name = var_target_val
[i
]
489 print " if (ptr1->" name
" != ptr2->" name
")";
490 print " return false;";
493 print " return true;";
498 print "/* Hash target options */";
500 print "cl_target_option_hash (struct cl_target_option const *ptr ATTRIBUTE_UNUSED)";
502 print " inchash::hash hstate;";
503 for (i =
0; i
< n_target_str
; i
++) {
504 name = var_target_str
[i
]
505 print " if (ptr->" name
")";
506 print " hstate.add (ptr->" name
", strlen (ptr->" name
"));";
508 print " hstate.add_int (0);";
510 for (i =
0; i
< n_target_val
; i
++) {
511 name = var_target_val
[i
]
512 print " hstate.add_wide_int (ptr->" name
");";
514 print " return hstate.end ();";
518 print "/* Stream out target options */";
520 print "cl_target_option_stream_out (struct output_block *ob ATTRIBUTE_UNUSED,";
521 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
522 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
524 for (i =
0; i
< n_target_str
; i
++) {
525 name = var_target_str
[i
]
526 print " bp_pack_string (ob, bp, ptr->" name
", true);";
528 for (i =
0; i
< n_target_val
; i
++) {
529 name = var_target_val
[i
]
530 print " bp_pack_value (bp, ptr->" name
", 64);";
535 print "/* Stream in target options */";
537 print "cl_target_option_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
538 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
539 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
541 for (i =
0; i
< n_target_str
; i
++) {
542 name = var_target_str
[i
]
543 print " ptr->" name
" = bp_unpack_string (data_in, bp);";
544 print " if (ptr->" name
")";
545 print " ptr->" name
" = xstrdup (ptr->" name
");";
547 for (i =
0; i
< n_target_val
; i
++) {
548 name = var_target_val
[i
]
549 print " ptr->" name
" = (" var_target_val_type
[i
] ") bp_unpack_value (bp, 64);";
555 var_opt_val
[0] =
"x_optimize"
556 var_opt_val_type
[0] =
"char "
557 var_opt_val
[1] =
"x_optimize_size"
558 var_opt_val_type
[1] =
"char "
559 for (i =
0; i
< n_opts
; i
++) {
560 if (flag_set_p
("Optimization", flags
[i
])) {
561 name = var_name
(flags
[i
])
565 if(name in var_opt_list_seen
)
568 var_opt_list_seen
[name
]++;
570 otype = var_type_struct
(flags
[i
])
571 var_opt_val_type
[n_opt_val
] = otype
;
572 var_opt_val
[n_opt_val
++] =
"x_" name
;
576 print "/* Hash optimization options */";
578 print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)";
580 print " inchash::hash hstate;";
581 for (i =
0; i
< n_opt_val
; i
++) {
582 name = var_opt_val
[i
]
583 print " hstate.add_wide_int (ptr->" name
");";
585 print " return hstate.end ();";
589 print "/* Stream out optimization options */";
591 print "cl_optimization_stream_out (struct bitpack_d *bp,";
592 print " struct cl_optimization *ptr)";
594 for (i =
0; i
< n_opt_val
; i
++) {
595 name = var_opt_val
[i
]
596 print " bp_pack_value (bp, ptr->" name
", 64);";
601 print "/* Stream in optimization options */";
603 print "cl_optimization_stream_in (struct bitpack_d *bp,";
604 print " struct cl_optimization *ptr)";
606 for (i =
0; i
< n_opt_val
; i
++) {
607 name = var_opt_val
[i
]
608 print " ptr->" name
" = (" var_opt_val_type
[i
] ") bp_unpack_value (bp, 64);";