Daily bump.
[official-gcc.git] / gcc / optc-save-gen.awk
blobff173fee4042c2b17b1ba3f2554f8bf72ad9a9f9
1 # Copyright (C) 2003-2020 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
8 # later version.
9 #
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
21 # C file.
24 # This program uses functions from opt-functions.awk and code from
25 # opt-read.awk.
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.
31 END {
32 print "/* This file is auto-generated by optc-save-gen.awk. */"
33 print ""
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
39 print ""
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 "hash-set.h" quote
44 print "#include " quote "vec.h" quote
45 print "#include " quote "input.h" quote
46 print "#include " quote "alias.h" quote
47 print "#include " quote "symtab.h" quote
48 print "#include " quote "inchash.h" quote
49 print "#include " quote "tree.h" quote
50 print "#include " quote "fold-const.h" quote
51 print "#include " quote "tree-ssa-alias.h" quote
52 print "#include " quote "is-a.h" quote
53 print "#include " quote "predict.h" quote
54 print "#include " quote "function.h" quote
55 print "#include " quote "basic-block.h" quote
56 print "#include " quote "gimple-expr.h" quote
57 print "#include " quote "gimple.h" quote
58 print "#include " quote "data-streamer.h" quote
59 print "#include " quote "ipa-ref.h" quote
60 print "#include " quote "cgraph.h" quote
61 print ""
63 if (n_extra_c_includes > 0) {
64 for (i = 0; i < n_extra_c_includes; i++) {
65 print "#include " quote extra_c_includes[i] quote
67 print ""
70 have_save = 0;
71 if (n_extra_target_vars)
72 have_save = 1
74 for (i = 0; i < n_opts; i++) {
75 if (flag_set_p("Save", flags[i]))
76 have_save = 1;
79 print "/* Save optimization variables into a structure. */"
80 print "void";
81 print "cl_optimization_save (struct cl_optimization *ptr, struct gcc_options *opts)";
82 print "{";
84 n_opt_char = 4;
85 n_opt_short = 0;
86 n_opt_int = 0;
87 n_opt_enum = 0;
88 n_opt_string = 0;
89 n_opt_other = 0;
90 var_opt_char[0] = "optimize";
91 var_opt_char[1] = "optimize_size";
92 var_opt_char[2] = "optimize_debug";
93 var_opt_char[3] = "optimize_fast";
94 var_opt_range["optimize"] = "0, 255";
95 var_opt_range["optimize_size"] = "0, 1";
96 var_opt_range["optimize_debug"] = "0, 1";
97 var_opt_range["optimize_fast"] = "0, 1";
99 # Sort by size to mimic how the structure is laid out to be friendlier to the
100 # cache.
102 for (i = 0; i < n_opts; i++) {
103 if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
104 name = var_name(flags[i])
105 if(name == "")
106 continue;
108 if(name in var_opt_seen)
109 continue;
111 var_opt_seen[name]++;
112 otype = var_type_struct(flags[i]);
113 if (otype ~ "^((un)?signed +)?int *$")
114 var_opt_int[n_opt_int++] = name;
116 else if (otype ~ "^((un)?signed +)?short *$")
117 var_opt_short[n_opt_short++] = name;
119 else if (otype ~ ("^enum +[_" alnum "]+ *"))
120 var_opt_enum[n_opt_enum++] = name;
122 else if (otype ~ "^((un)?signed +)?char *$") {
123 var_opt_char[n_opt_char++] = name;
124 if (otype ~ "^unsigned +char *$")
125 var_opt_range[name] = "0, 255"
126 else if (otype ~ "^signed +char *$")
127 var_opt_range[name] = "-128, 127"
129 else if (otype ~ "^const char \\**$") {
130 var_opt_string[n_opt_string++] = name;
131 string_options_names[name]++
133 else
134 var_opt_other[n_opt_other++] = name;
138 for (i = 0; i < n_opt_char; i++) {
139 name = var_opt_char[i];
140 if (var_opt_range[name] != "")
141 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_opt_range[name] "));";
144 print "";
145 for (i = 0; i < n_opt_other; i++) {
146 print " ptr->x_" var_opt_other[i] " = opts->x_" var_opt_other[i] ";";
149 for (i = 0; i < n_opt_int; i++) {
150 print " ptr->x_" var_opt_int[i] " = opts->x_" var_opt_int[i] ";";
153 for (i = 0; i < n_opt_enum; i++) {
154 print " ptr->x_" var_opt_enum[i] " = opts->x_" var_opt_enum[i] ";";
157 for (i = 0; i < n_opt_short; i++) {
158 print " ptr->x_" var_opt_short[i] " = opts->x_" var_opt_short[i] ";";
161 for (i = 0; i < n_opt_char; i++) {
162 print " ptr->x_" var_opt_char[i] " = opts->x_" var_opt_char[i] ";";
165 for (i = 0; i < n_opt_string; i++) {
166 print " ptr->x_" var_opt_string[i] " = opts->x_" var_opt_string[i] ";";
169 print "}";
171 print "";
172 print "/* Restore optimization options from a structure. */";
173 print "void";
174 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
175 print "{";
177 for (i = 0; i < n_opt_other; i++) {
178 print " opts->x_" var_opt_other[i] " = ptr->x_" var_opt_other[i] ";";
181 for (i = 0; i < n_opt_int; i++) {
182 print " opts->x_" var_opt_int[i] " = ptr->x_" var_opt_int[i] ";";
185 for (i = 0; i < n_opt_enum; i++) {
186 print " opts->x_" var_opt_enum[i] " = ptr->x_" var_opt_enum[i] ";";
189 for (i = 0; i < n_opt_short; i++) {
190 print " opts->x_" var_opt_short[i] " = ptr->x_" var_opt_short[i] ";";
193 for (i = 0; i < n_opt_char; i++) {
194 print " opts->x_" var_opt_char[i] " = ptr->x_" var_opt_char[i] ";";
197 for (i = 0; i < n_opt_string; i++) {
198 print " opts->x_" var_opt_string[i] " = ptr->x_" var_opt_string[i] ";";
201 print " targetm.override_options_after_change ();";
202 print "}";
204 print "";
205 print "/* Print optimization options from a structure. */";
206 print "void";
207 print "cl_optimization_print (FILE *file,";
208 print " int indent_to,";
209 print " struct cl_optimization *ptr)";
210 print "{";
212 print " fputs (\"\\n\", file);";
213 for (i = 0; i < n_opt_other; i++) {
214 print " if (ptr->x_" var_opt_other[i] ")";
215 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
216 print " indent_to, \"\",";
217 print " \"" var_opt_other[i] "\",";
218 print " (unsigned long)ptr->x_" var_opt_other[i] ");";
219 print "";
222 for (i = 0; i < n_opt_int; i++) {
223 print " if (ptr->x_" var_opt_int[i] ")";
224 print " fprintf (file, \"%*s%s (%#x)\\n\",";
225 print " indent_to, \"\",";
226 print " \"" var_opt_int[i] "\",";
227 print " ptr->x_" var_opt_int[i] ");";
228 print "";
231 for (i = 0; i < n_opt_enum; i++) {
232 print " fprintf (file, \"%*s%s (%#x)\\n\",";
233 print " indent_to, \"\",";
234 print " \"" var_opt_enum[i] "\",";
235 print " (int) ptr->x_" var_opt_enum[i] ");";
236 print "";
239 for (i = 0; i < n_opt_short; i++) {
240 print " if (ptr->x_" var_opt_short[i] ")";
241 print " fprintf (file, \"%*s%s (%#x)\\n\",";
242 print " indent_to, \"\",";
243 print " \"" var_opt_short[i] "\",";
244 print " ptr->x_" var_opt_short[i] ");";
245 print "";
248 for (i = 0; i < n_opt_char; i++) {
249 print " if (ptr->x_" var_opt_char[i] ")";
250 print " fprintf (file, \"%*s%s (%#x)\\n\",";
251 print " indent_to, \"\",";
252 print " \"" var_opt_char[i] "\",";
253 print " ptr->x_" var_opt_char[i] ");";
254 print "";
257 for (i = 0; i < n_opt_string; i++) {
258 print " if (ptr->x_" var_opt_string[i] ")";
259 print " fprintf (file, \"%*s%s (%s)\\n\",";
260 print " indent_to, \"\",";
261 print " \"" var_opt_string[i] "\",";
262 print " ptr->x_" var_opt_string[i] ");";
263 print "";
266 print "}";
268 print "";
269 print "/* Print different optimization variables from structures provided as arguments. */";
270 print "void";
271 print "cl_optimization_print_diff (FILE *file,";
272 print " int indent_to,";
273 print " struct cl_optimization *ptr1,";
274 print " struct cl_optimization *ptr2)";
275 print "{";
277 print " fputs (\"\\n\", file);";
278 for (i = 0; i < n_opt_other; i++) {
279 print " if (ptr1->x_" var_opt_other[i] " != ptr2->x_" var_opt_other[i] ")";
280 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
281 print " indent_to, \"\",";
282 print " \"" var_opt_other[i] "\",";
283 print " (unsigned long)ptr1->x_" var_opt_other[i] ",";
284 print " (unsigned long)ptr2->x_" var_opt_other[i] ");";
285 print "";
288 for (i = 0; i < n_opt_int; i++) {
289 print " if (ptr1->x_" var_opt_int[i] " != ptr2->x_" var_opt_int[i] ")";
290 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
291 print " indent_to, \"\",";
292 print " \"" var_opt_int[i] "\",";
293 print " ptr1->x_" var_opt_int[i] ",";
294 print " ptr2->x_" var_opt_int[i] ");";
295 print "";
298 for (i = 0; i < n_opt_enum; i++) {
299 print " if (ptr1->x_" var_opt_enum[i] " != ptr2->x_" var_opt_enum[i] ")";
300 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
301 print " indent_to, \"\",";
302 print " \"" var_opt_enum[i] "\",";
303 print " (int) ptr1->x_" var_opt_enum[i] ",";
304 print " (int) ptr2->x_" var_opt_enum[i] ");";
305 print "";
308 for (i = 0; i < n_opt_short; i++) {
309 print " if (ptr1->x_" var_opt_short[i] " != ptr2->x_" var_opt_short[i] ")";
310 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
311 print " indent_to, \"\",";
312 print " \"" var_opt_short[i] "\",";
313 print " ptr1->x_" var_opt_short[i] ",";
314 print " ptr2->x_" var_opt_short[i] ");";
315 print "";
318 for (i = 0; i < n_opt_char; i++) {
319 print " if (ptr1->x_" var_opt_char[i] " != ptr2->x_" var_opt_char[i] ")";
320 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
321 print " indent_to, \"\",";
322 print " \"" var_opt_char[i] "\",";
323 print " ptr1->x_" var_opt_char[i] ",";
324 print " ptr2->x_" var_opt_char[i] ");";
325 print "";
328 for (i = 0; i < n_opt_string; i++) {
329 name = var_opt_string[i]
330 print " if (ptr1->x_" name " != ptr2->x_" name "";
331 print " && (!ptr1->x_" name" || !ptr2->x_" name
332 print " || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
333 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
334 print " indent_to, \"\",";
335 print " \"" name "\",";
336 print " ptr1->x_" name " ? ptr1->x_" name " : \"(null)\",";
337 print " ptr2->x_" name " ? ptr2->x_" name " : \"(null)\");";
338 print "";
341 print "}";
344 print "";
345 print "/* Save selected option variables into a structure. */"
346 print "void";
347 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
348 print "{";
350 n_target_char = 0;
351 n_target_short = 0;
352 n_target_int = 0;
353 n_target_enum = 0;
354 n_target_string = 0;
355 n_target_other = 0;
357 if (have_save) {
358 for (i = 0; i < n_opts; i++) {
359 if (flag_set_p("Save", flags[i])) {
360 name = var_name(flags[i])
361 if(name == "")
362 name = "target_flags";
364 if(name in var_save_seen)
365 continue;
367 var_save_seen[name]++;
368 otype = var_type_struct(flags[i])
369 if (otype ~ "^((un)?signed +)?int *$")
370 var_target_int[n_target_int++] = name;
372 else if (otype ~ "^((un)?signed +)?short *$")
373 var_target_short[n_target_short++] = name;
375 else if (otype ~ ("^enum +[_" alnum "]+ *$"))
376 var_target_enum[n_target_enum++] = name;
378 else if (otype ~ "^((un)?signed +)?char *$") {
379 var_target_char[n_target_char++] = name;
380 if (otype ~ "^unsigned +char *$")
381 var_target_range[name] = "0, 255"
382 else if (otype ~ "^signed +char *$")
383 var_target_range[name] = "-128, 127"
384 if (otype == var_type(flags[i]))
385 var_target_range[name] = ""
387 else if (otype ~ "^const char \\**$") {
388 var_target_string[n_target_string++] = name;
389 string_options_names[name]++
391 else
392 var_target_other[n_target_other++] = name;
395 } else {
396 var_target_int[n_target_int++] = "target_flags";
399 have_assert = 0;
400 for (i = 0; i < n_target_char; i++) {
401 name = var_target_char[i];
402 if (var_target_range[name] != "") {
403 have_assert = 1;
404 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_target_range[name] "));";
408 if (have_assert)
409 print "";
411 print " if (targetm.target_option.save)";
412 print " targetm.target_option.save (ptr, opts);";
413 print "";
415 for (i = 0; i < n_extra_target_vars; i++) {
416 print " ptr->x_" extra_target_vars[i] " = opts->x_" extra_target_vars[i] ";";
419 for (i = 0; i < n_target_other; i++) {
420 print " ptr->x_" var_target_other[i] " = opts->x_" var_target_other[i] ";";
423 for (i = 0; i < n_target_enum; i++) {
424 print " ptr->x_" var_target_enum[i] " = opts->x_" var_target_enum[i] ";";
427 for (i = 0; i < n_target_int; i++) {
428 print " ptr->x_" var_target_int[i] " = opts->x_" var_target_int[i] ";";
431 for (i = 0; i < n_target_short; i++) {
432 print " ptr->x_" var_target_short[i] " = opts->x_" var_target_short[i] ";";
435 for (i = 0; i < n_target_char; i++) {
436 print " ptr->x_" var_target_char[i] " = opts->x_" var_target_char[i] ";";
439 for (i = 0; i < n_target_string; i++) {
440 print " ptr->x_" var_target_string[i] " = opts->x_" var_target_string[i] ";";
443 print "}";
445 print "";
446 print "/* Restore selected current options from a structure. */";
447 print "void";
448 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
449 print "{";
451 for (i = 0; i < n_extra_target_vars; i++) {
452 print " opts->x_" extra_target_vars[i] " = ptr->x_" extra_target_vars[i] ";";
455 for (i = 0; i < n_target_other; i++) {
456 print " opts->x_" var_target_other[i] " = ptr->x_" var_target_other[i] ";";
459 for (i = 0; i < n_target_enum; i++) {
460 print " opts->x_" var_target_enum[i] " = ptr->x_" var_target_enum[i] ";";
463 for (i = 0; i < n_target_int; i++) {
464 print " opts->x_" var_target_int[i] " = ptr->x_" var_target_int[i] ";";
467 for (i = 0; i < n_target_short; i++) {
468 print " opts->x_" var_target_short[i] " = ptr->x_" var_target_short[i] ";";
471 for (i = 0; i < n_target_char; i++) {
472 print " opts->x_" var_target_char[i] " = ptr->x_" var_target_char[i] ";";
475 for (i = 0; i < n_target_string; i++) {
476 print " opts->x_" var_target_string[i] " = ptr->x_" var_target_string[i] ";";
479 # This must occur after the normal variables in case the code depends on those
480 # variables.
481 print "";
482 print " if (targetm.target_option.restore)";
483 print " targetm.target_option.restore (opts, ptr);";
485 print "}";
487 print "";
488 print "/* Print optimization options from a structure. */";
489 print "void";
490 print "cl_target_option_print (FILE *file,";
491 print " int indent,";
492 print " struct cl_target_option *ptr)";
493 print "{";
495 print " fputs (\"\\n\", file);";
496 for (i = 0; i < n_target_other; i++) {
497 print " if (ptr->x_" var_target_other[i] ")";
498 hwi = host_wide_int[var_target_other[i]]
499 if (hwi == "yes")
500 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
501 else
502 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
503 print " indent, \"\",";
504 print " \"" var_target_other[i] "\",";
505 if (hwi == "yes")
506 print " ptr->x_" var_target_other[i] ");";
507 else
508 print " (unsigned long)ptr->x_" var_target_other[i] ");";
509 print "";
512 for (i = 0; i < n_target_enum; i++) {
513 print " if (ptr->x_" var_target_enum[i] ")";
514 print " fprintf (file, \"%*s%s (%#x)\\n\",";
515 print " indent, \"\",";
516 print " \"" var_target_enum[i] "\",";
517 print " ptr->x_" var_target_enum[i] ");";
518 print "";
521 for (i = 0; i < n_target_int; i++) {
522 print " if (ptr->x_" var_target_int[i] ")";
523 print " fprintf (file, \"%*s%s (%#x)\\n\",";
524 print " indent, \"\",";
525 print " \"" var_target_int[i] "\",";
526 print " ptr->x_" var_target_int[i] ");";
527 print "";
530 for (i = 0; i < n_target_short; i++) {
531 print " if (ptr->x_" var_target_short[i] ")";
532 print " fprintf (file, \"%*s%s (%#x)\\n\",";
533 print " indent, \"\",";
534 print " \"" var_target_short[i] "\",";
535 print " ptr->x_" var_target_short[i] ");";
536 print "";
539 for (i = 0; i < n_target_char; i++) {
540 print " if (ptr->x_" var_target_char[i] ")";
541 print " fprintf (file, \"%*s%s (%#x)\\n\",";
542 print " indent, \"\",";
543 print " \"" var_target_char[i] "\",";
544 print " ptr->x_" var_target_char[i] ");";
545 print "";
548 for (i = 0; i < n_target_string; i++) {
549 print " if (ptr->x_" var_target_string[i] ")";
550 print " fprintf (file, \"%*s%s (%s)\\n\",";
551 print " indent, \"\",";
552 print " \"" var_target_string[i] "\",";
553 print " ptr->x_" var_target_string[i] ");";
554 print "";
557 print "";
558 print " if (targetm.target_option.print)";
559 print " targetm.target_option.print (file, indent, ptr);";
560 print "}";
562 print "";
563 print "/* Print different target option variables from structures provided as arguments. */";
564 print "void";
565 print "cl_target_option_print_diff (FILE *file,";
566 print " int indent ATTRIBUTE_UNUSED,";
567 print " struct cl_target_option *ptr1 ATTRIBUTE_UNUSED,";
568 print " struct cl_target_option *ptr2 ATTRIBUTE_UNUSED)";
569 print "{";
571 print " fputs (\"\\n\", file);";
572 for (i = 0; i < n_target_other; i++) {
573 print " if (ptr1->x_" var_target_other[i] " != ptr2->x_" var_target_other[i] ")";
574 hwi = host_wide_int[var_target_other[i]]
575 if (hwi == "yes")
576 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x/%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
577 else
578 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
579 print " indent, \"\",";
580 print " \"" var_target_other[i] "\",";
581 if (hwi == "yes") {
582 print " ptr1->x_" var_target_other[i] ",";
583 print " ptr2->x_" var_target_other[i] ");";
585 else {
586 print " (unsigned long)ptr1->x_" var_target_other[i] ",";
587 print " (unsigned long)ptr2->x_" var_target_other[i] ");";
589 print "";
592 for (i = 0; i < n_target_enum; i++) {
593 print " if (ptr1->x_" var_target_enum[i] " != ptr2->x_" var_target_enum[i] ")";
594 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
595 print " indent, \"\",";
596 print " \"" var_target_enum[i] "\",";
597 print " ptr1->x_" var_target_enum[i] ",";
598 print " ptr2->x_" var_target_enum[i] ");";
599 print "";
602 for (i = 0; i < n_target_int; i++) {
603 print " if (ptr1->x_" var_target_int[i] " != ptr2->x_" var_target_int[i] ")";
604 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
605 print " indent, \"\",";
606 print " \"" var_target_int[i] "\",";
607 print " ptr1->x_" var_target_int[i] ",";
608 print " ptr2->x_" var_target_int[i] ");";
609 print "";
612 for (i = 0; i < n_target_short; i++) {
613 print " if (ptr1->x_" var_target_short[i] " != ptr2->x_" var_target_short[i] ")";
614 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
615 print " indent, \"\",";
616 print " \"" var_target_short[i] "\",";
617 print " ptr1->x_" var_target_short[i] ",";
618 print " ptr2->x_" var_target_short[i] ");";
619 print "";
622 for (i = 0; i < n_target_char; i++) {
623 print " if (ptr1->x_" var_target_char[i] " != ptr2->x_" var_target_char[i] ")";
624 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
625 print " indent, \"\",";
626 print " \"" var_target_char[i] "\",";
627 print " ptr1->x_" var_target_char[i] ",";
628 print " ptr2->x_" var_target_char[i] ");";
629 print "";
632 for (i = 0; i < n_target_string; i++) {
633 name = var_target_string[i]
634 print " if (ptr1->x_" name " != ptr2->x_" name "";
635 print " && (!ptr1->x_" name" || !ptr2->x_" name
636 print " || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
637 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
638 print " indent, \"\",";
639 print " \"" name "\",";
640 print " ptr1->x_" name " ? ptr1->x_" name " : \"(null)\",";
641 print " ptr2->x_" name " ? ptr1->x_" name " : \"(null)\");";
642 print "";
645 print "}";
647 print "";
648 print "/* Compare two target options */";
649 print "bool";
650 print "cl_target_option_eq (struct cl_target_option const *ptr1 ATTRIBUTE_UNUSED,";
651 print " struct cl_target_option const *ptr2 ATTRIBUTE_UNUSED)";
652 print "{";
653 n_target_val = 0;
654 n_target_str = 0;
655 n_target_array = 0;
657 for (i = 0; i < n_target_save; i++) {
658 var = target_save_decl[i];
659 sub (" *=.*", "", var);
660 name = var;
661 type = var;
662 sub("^.*[ *]", "", name)
663 sub(" *" name "$", "", type)
664 if (target_save_decl[i] ~ "^const char \\*+[_" alnum "]+$")
665 var_target_str[n_target_str++] = name;
666 else {
667 if (target_save_decl[i] ~ " .*\\[.+\\]+$") {
668 size = name;
669 sub("[^\\[]+\\[", "", size);
670 sub("\\]$", "", size);
671 sub("\\[.+", "", name)
672 sub(" [^ ]+$", "", type)
673 var_target_array[n_target_array] = name
674 var_target_array_type[n_target_array] = type
675 var_target_array_size[n_target_array++] = size
677 else {
678 var_target_val_type[n_target_val] = type;
679 var_target_val[n_target_val++] = name;
683 if (have_save) {
684 for (i = 0; i < n_opts; i++) {
685 if (flag_set_p("Save", flags[i])) {
686 name = var_name(flags[i])
687 if(name == "")
688 name = "target_flags";
690 if(name in var_list_seen)
691 continue;
693 var_list_seen[name]++;
694 otype = var_type_struct(flags[i])
695 if (otype ~ "^const char \\**$")
696 var_target_str[n_target_str++] = "x_" name;
697 else {
698 var_target_val_type[n_target_val] = otype;
699 var_target_val[n_target_val++] = "x_" name;
703 } else {
704 var_target_val_type[n_target_val] = "int";
705 var_target_val[n_target_val++] = "x_target_flags";
708 for (i = 0; i < n_target_str; i++) {
709 name = var_target_str[i]
710 print " if (ptr1->" name" != ptr2->" name;
711 print " && (!ptr1->" name" || !ptr2->" name
712 print " || strcmp (ptr1->" name", ptr2->" name ")))";
713 print " return false;";
715 for (i = 0; i < n_target_array; i++) {
716 name = var_target_array[i]
717 size = var_target_array_size[i]
718 type = var_target_array_type[i]
719 print " if (ptr1->" name" != ptr2->" name "";
720 print " || memcmp (ptr1->" name ", ptr2->" name ", " size " * sizeof(" type ")))"
721 print " return false;";
723 for (i = 0; i < n_target_val; i++) {
724 name = var_target_val[i]
725 print " if (ptr1->" name" != ptr2->" name ")";
726 print " return false;";
729 print " return true;";
731 print "}";
733 print "";
734 print "/* Hash target options */";
735 print "hashval_t";
736 print "cl_target_option_hash (struct cl_target_option const *ptr ATTRIBUTE_UNUSED)";
737 print "{";
738 print " inchash::hash hstate;";
739 for (i = 0; i < n_target_str; i++) {
740 name = var_target_str[i]
741 print " if (ptr->" name")";
742 print " hstate.add (ptr->" name", strlen (ptr->" name"));";
743 print " else";
744 print " hstate.add_int (0);";
746 for (i = 0; i < n_target_array; i++) {
747 name= var_target_array[i]
748 size = var_target_array_size[i]
749 type = var_target_array_type[i]
750 print " hstate.add_int (" size ");";
751 print " hstate.add (ptr->" name ", sizeof (" type ") * " size ");";
753 for (i = 0; i < n_target_val; i++) {
754 name = var_target_val[i]
755 print " hstate.add_hwi (ptr->" name");";
757 print " return hstate.end ();";
758 print "}";
760 print "";
761 print "/* Stream out target options */";
762 print "void";
763 print "cl_target_option_stream_out (struct output_block *ob ATTRIBUTE_UNUSED,";
764 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
765 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
766 print "{";
767 for (i = 0; i < n_target_str; i++) {
768 name = var_target_str[i]
769 print " bp_pack_string (ob, bp, ptr->" name", true);";
771 for (i = 0; i < n_target_array; i++) {
772 name = var_target_array[i]
773 size = var_target_array_size[i]
774 print " for (unsigned i = 0; i < " size "; i++)"
775 print " bp_pack_value (bp, ptr->" name "[i], 64);";
777 for (i = 0; i < n_target_val; i++) {
778 name = var_target_val[i]
779 print " bp_pack_value (bp, ptr->" name", 64);";
781 print "}";
783 print "";
784 print "/* Stream in target options */";
785 print "void";
786 print "cl_target_option_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
787 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
788 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
789 print "{";
790 for (i = 0; i < n_target_str; i++) {
791 name = var_target_str[i]
792 print " ptr->" name" = bp_unpack_string (data_in, bp);";
793 print " if (ptr->" name")";
794 print " ptr->" name" = xstrdup (ptr->" name");";
796 for (i = 0; i < n_target_array; i++) {
797 name = var_target_array[i]
798 size = var_target_array_size[i]
799 print " for (int i = " size " - 1; i >= 0; i--)"
800 print " ptr->" name "[i] = (" var_target_array_type[i] ") bp_unpack_value (bp, 64);";
802 for (i = 0; i < n_target_val; i++) {
803 name = var_target_val[i]
804 print " ptr->" name" = (" var_target_val_type[i] ") bp_unpack_value (bp, 64);";
807 print "}";
809 print "/* free heap memory used by target options */";
810 print "void";
811 print "cl_target_option_free (struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
812 print "{";
813 for (i = 0; i < n_target_str; i++) {
814 name = var_target_str[i]
815 print " if (ptr->" name")";
816 print " free (const_cast <char *>(ptr->" name"));";
818 print "}";
820 n_opt_val = 4;
821 var_opt_val[0] = "x_optimize"
822 var_opt_val_type[0] = "char "
823 var_opt_hash[0] = 1;
824 var_opt_val[1] = "x_optimize_size"
825 var_opt_val_type[1] = "char "
826 var_opt_hash[1] = 1;
827 var_opt_val[2] = "x_optimize_debug"
828 var_opt_val_type[2] = "char "
829 var_opt_hash[2] = 1;
830 var_opt_val[3] = "x_optimize_fast"
831 var_opt_val_type[3] = "char "
832 var_opt_hash[3] = 1;
833 for (i = 0; i < n_opts; i++) {
834 if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
835 name = var_name(flags[i])
836 if(name == "")
837 continue;
839 if(name in var_opt_list_seen)
840 continue;
842 var_opt_list_seen[name]++;
844 otype = var_type_struct(flags[i])
845 var_opt_val_type[n_opt_val] = otype;
846 var_opt_val[n_opt_val] = "x_" name;
847 var_opt_hash[n_opt_val] = flag_set_p("Optimization", flags[i]);
848 n_opt_val++;
851 print "";
852 print "/* Hash optimization options */";
853 print "hashval_t";
854 print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)";
855 print "{";
856 print " inchash::hash hstate;";
857 for (i = 0; i < n_opt_val; i++) {
858 if (!var_opt_hash[i])
859 continue;
860 name = var_opt_val[i]
861 otype = var_opt_val_type[i];
862 if (otype ~ "^const char \\**$")
864 print " if (ptr->" name")";
865 print " hstate.add (ptr->" name", strlen (ptr->" name"));";
866 print " else";
867 print " hstate.add_int (0);";
869 else
870 print " hstate.add_hwi (ptr->" name");";
872 print " return hstate.end ();";
873 print "}";
875 print "";
876 print "/* Compare two optimization options */";
877 print "bool";
878 print "cl_optimization_option_eq (cl_optimization const *ptr1,";
879 print " cl_optimization const *ptr2)";
880 print "{";
881 for (i = 0; i < n_opt_val; i++) {
882 if (!var_opt_hash[i])
883 continue;
884 name = var_opt_val[i]
885 otype = var_opt_val_type[i];
886 if (otype ~ "^const char \\**$")
888 print " if (ptr1->" name" != ptr2->" name;
889 print " && (!ptr1->" name" || !ptr2->" name
890 print " || strcmp (ptr1->" name", ptr2->" name ")))";
891 print " return false;";
893 else
895 print " if (ptr1->" name" != ptr2->" name ")";
896 print " return false;";
899 print " return true;";
900 print "}";
902 print "";
903 print "/* Stream out optimization options */";
904 print "void";
905 print "cl_optimization_stream_out (struct output_block *ob,";
906 print " struct bitpack_d *bp,";
907 print " struct cl_optimization *ptr)";
908 print "{";
909 for (i = 0; i < n_opt_val; i++) {
910 name = var_opt_val[i]
911 otype = var_opt_val_type[i];
912 if (otype ~ "^const char \\**$")
913 print " bp_pack_string (ob, bp, ptr->" name", true);";
914 else
915 print " bp_pack_value (bp, ptr->" name", 64);";
917 print "}";
919 print "";
920 print "/* Stream in optimization options */";
921 print "void";
922 print "cl_optimization_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
923 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
924 print " struct cl_optimization *ptr ATTRIBUTE_UNUSED)";
925 print "{";
926 for (i = 0; i < n_opt_val; i++) {
927 name = var_opt_val[i]
928 otype = var_opt_val_type[i];
929 if (otype ~ "^const char \\**$")
931 print " ptr->" name" = bp_unpack_string (data_in, bp);";
932 print " if (ptr->" name")";
933 print " ptr->" name" = xstrdup (ptr->" name");";
935 else
936 print " ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_value (bp, 64);";
938 print "}";
939 print "/* Free heap memory used by optimization options */";
940 print "void";
941 print "cl_optimization_option_free (struct cl_optimization *ptr ATTRIBUTE_UNUSED)";
942 print "{";
943 for (i = 0; i < n_opt_val; i++) {
944 name = var_opt_val[i]
945 otype = var_opt_val_type[i];
946 if (otype ~ "^const char \\**$")
948 print " if (ptr->" name")";
949 print " free (const_cast <char *>(ptr->" name"));";
952 print "}";
954 print "void";
955 print "cl_optimization_compare (gcc_options *ptr1, gcc_options *ptr2)"
956 print "{"
958 # all these options are mentioned in PR92860
959 checked_options["flag_merge_constants"]++
960 checked_options["param_max_fields_for_field_sensitive"]++
961 checked_options["flag_omit_frame_pointer"]++
962 checked_options["unroll_only_small_loops"]++
963 # arc exceptions
964 checked_options["TARGET_ALIGN_CALL"]++
965 checked_options["TARGET_CASE_VECTOR_PC_RELATIVE"]++
966 checked_options["arc_size_opt_level"]++
968 for (i = 0; i < n_opts; i++) {
969 name = var_name(flags[i]);
970 if (name == "")
971 continue;
973 if (name in checked_options)
974 continue;
975 checked_options[name]++
977 if (name in string_options_names) {
978 print " if (ptr1->x_" name " != ptr2->x_" name "";
979 print " && (!ptr1->x_" name" || !ptr2->x_" name
980 print " || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
981 print " internal_error (\"%<global_options%> are modified in local context\");";
983 else {
984 print " if (ptr1->x_" name " != ptr2->x_" name ")"
985 print " internal_error (\"%<global_options%> are modified in local context\");";
989 print "}";