RISC-V: Add RISC-V into vect_cmdline_needed
[official-gcc.git] / gcc / optc-save-gen.awk
blobd2cb53c477fda470a5cdef938b628fa20828593c
1 # Copyright (C) 2003-2023 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.cc
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 " struct gcc_options *opts_set)";
83 print "{";
85 n_opt_char = 4;
86 n_opt_short = 0;
87 n_opt_int = 0;
88 n_opt_enum = 0;
89 n_opt_string = 0;
90 n_opt_other = 0;
91 var_opt_char[0] = "optimize";
92 var_opt_char[1] = "optimize_size";
93 var_opt_char[2] = "optimize_debug";
94 var_opt_char[3] = "optimize_fast";
95 var_opt_range["optimize"] = "0, 255";
96 var_opt_range["optimize_size"] = "0, 2";
97 var_opt_range["optimize_debug"] = "0, 1";
98 var_opt_range["optimize_fast"] = "0, 1";
100 # Sort by size to mimic how the structure is laid out to be friendlier to the
101 # cache.
103 for (i = 0; i < n_opts; i++) {
104 if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
105 name = var_name(flags[i])
106 if(name == "")
107 continue;
109 if(name in var_opt_seen)
110 continue;
112 var_opt_seen[name]++;
113 otype = var_type_struct(flags[i]);
114 if (otype ~ "^((un)?signed +)?int *$")
115 var_opt_int[n_opt_int++] = name;
117 else if (otype ~ "^((un)?signed +)?short *$")
118 var_opt_short[n_opt_short++] = name;
120 else if (otype ~ ("^enum +[_" alnum "]+ *")) {
121 var_opt_enum_type[n_opt_enum] = otype;
122 var_opt_enum[n_opt_enum++] = name;
124 else if (otype ~ "^((un)?signed +)?char *$") {
125 var_opt_char[n_opt_char++] = name;
126 if (otype ~ "^unsigned +char *$")
127 var_opt_range[name] = "0, 255"
128 else if (otype ~ "^signed +char *$")
129 var_opt_range[name] = "-128, 127"
131 else if (otype ~ "^const char \\**$") {
132 var_opt_string[n_opt_string++] = name;
133 string_options_names[name]++
135 else
136 var_opt_other[n_opt_other++] = name;
140 for (i = 0; i < n_opt_char; i++) {
141 name = var_opt_char[i];
142 if (var_opt_range[name] != "")
143 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_opt_range[name] "));";
146 print "";
147 for (i = 0; i < n_opt_other; i++) {
148 print " ptr->x_" var_opt_other[i] " = opts->x_" var_opt_other[i] ";";
151 for (i = 0; i < n_opt_int; i++) {
152 print " ptr->x_" var_opt_int[i] " = opts->x_" var_opt_int[i] ";";
155 for (i = 0; i < n_opt_enum; i++) {
156 print " ptr->x_" var_opt_enum[i] " = opts->x_" var_opt_enum[i] ";";
159 for (i = 0; i < n_opt_short; i++) {
160 print " ptr->x_" var_opt_short[i] " = opts->x_" var_opt_short[i] ";";
163 for (i = 0; i < n_opt_char; i++) {
164 print " ptr->x_" var_opt_char[i] " = opts->x_" var_opt_char[i] ";";
167 for (i = 0; i < n_opt_string; i++) {
168 print " ptr->x_" var_opt_string[i] " = opts->x_" var_opt_string[i] ";";
171 print "";
172 print " unsigned HOST_WIDE_INT mask = 0;";
174 j = 0;
175 k = 0;
176 for (i = 0; i < n_opt_other; i++) {
177 print " if (opts_set->x_" var_opt_other[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
178 j++;
179 if (j == 64) {
180 print " ptr->explicit_mask[" k "] = mask;";
181 print " mask = 0;";
182 j = 0;
183 k++;
187 for (i = 0; i < n_opt_int; i++) {
188 print " if (opts_set->x_" var_opt_int[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
189 j++;
190 if (j == 64) {
191 print " ptr->explicit_mask[" k "] = mask;";
192 print " mask = 0;";
193 j = 0;
194 k++;
198 for (i = 0; i < n_opt_enum; i++) {
199 print " if (opts_set->x_" var_opt_enum[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
200 j++;
201 if (j == 64) {
202 print " ptr->explicit_mask[" k "] = mask;";
203 print " mask = 0;";
204 j = 0;
205 k++;
209 for (i = 0; i < n_opt_short; i++) {
210 print " if (opts_set->x_" var_opt_short[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
211 j++;
212 if (j == 64) {
213 print " ptr->explicit_mask[" k "] = mask;";
214 print " mask = 0;";
215 j = 0;
216 k++;
220 for (i = 0; i < n_opt_char; i++) {
221 print " if (opts_set->x_" var_opt_char[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
222 j++;
223 if (j == 64) {
224 print " ptr->explicit_mask[" k "] = mask;";
225 print " mask = 0;";
226 j = 0;
227 k++;
231 for (i = 0; i < n_opt_string; i++) {
232 print " if (opts_set->x_" var_opt_string[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
233 j++;
234 if (j == 64) {
235 print " ptr->explicit_mask[" k "] = mask;";
236 print " mask = 0;";
237 j = 0;
238 k++;
242 if (j != 0) {
243 print " ptr->explicit_mask[" k "] = mask;";
246 print "}";
248 print "";
249 print "/* Restore optimization options from a structure. */";
250 print "void";
251 print "cl_optimization_restore (struct gcc_options *opts, struct gcc_options *opts_set,";
252 print " struct cl_optimization *ptr)";
253 print "{";
255 for (i = 0; i < n_opt_other; i++) {
256 print " opts->x_" var_opt_other[i] " = ptr->x_" var_opt_other[i] ";";
259 for (i = 0; i < n_opt_int; i++) {
260 print " opts->x_" var_opt_int[i] " = ptr->x_" var_opt_int[i] ";";
263 for (i = 0; i < n_opt_enum; i++) {
264 print " opts->x_" var_opt_enum[i] " = ptr->x_" var_opt_enum[i] ";";
267 for (i = 0; i < n_opt_short; i++) {
268 print " opts->x_" var_opt_short[i] " = ptr->x_" var_opt_short[i] ";";
271 for (i = 0; i < n_opt_char; i++) {
272 print " opts->x_" var_opt_char[i] " = ptr->x_" var_opt_char[i] ";";
275 for (i = 0; i < n_opt_string; i++) {
276 print " opts->x_" var_opt_string[i] " = ptr->x_" var_opt_string[i] ";";
279 print "";
280 print " unsigned HOST_WIDE_INT mask;";
282 j = 64;
283 k = 0;
284 for (i = 0; i < n_opt_other; i++) {
285 if (j == 64) {
286 print " mask = ptr->explicit_mask[" k "];";
287 k++;
288 j = 0;
290 print " opts_set->x_" var_opt_other[i] " = (mask & 1) != 0;";
291 print " mask >>= 1;"
292 j++;
295 for (i = 0; i < n_opt_int; i++) {
296 if (j == 64) {
297 print " mask = ptr->explicit_mask[" k "];";
298 k++;
299 j = 0;
301 print " opts_set->x_" var_opt_int[i] " = (mask & 1) != 0;";
302 print " mask >>= 1;"
303 j++;
306 for (i = 0; i < n_opt_enum; i++) {
307 if (j == 64) {
308 print " mask = ptr->explicit_mask[" k "];";
309 k++;
310 j = 0;
312 print " opts_set->x_" var_opt_enum[i] " = static_cast<" var_opt_enum_type[i] ">((mask & 1) != 0);";
313 print " mask >>= 1;"
314 j++;
317 for (i = 0; i < n_opt_short; i++) {
318 if (j == 64) {
319 print " mask = ptr->explicit_mask[" k "];";
320 k++;
321 j = 0;
323 print " opts_set->x_" var_opt_short[i] " = (mask & 1) != 0;";
324 print " mask >>= 1;"
325 j++;
328 for (i = 0; i < n_opt_char; i++) {
329 if (j == 64) {
330 print " mask = ptr->explicit_mask[" k "];";
331 k++;
332 j = 0;
334 print " opts_set->x_" var_opt_char[i] " = (mask & 1) != 0;";
335 print " mask >>= 1;"
336 j++;
339 for (i = 0; i < n_opt_string; i++) {
340 if (j == 64) {
341 print " mask = ptr->explicit_mask[" k "];";
342 k++;
343 j = 0;
345 print " opts_set->x_" var_opt_string[i] " = (mask & 1) ? \"\" : nullptr;";
346 print " mask >>= 1;"
347 j++;
350 print " targetm.override_options_after_change ();";
351 print "}";
353 print "";
354 print "/* Print optimization options from a structure. */";
355 print "void";
356 print "cl_optimization_print (FILE *file,";
357 print " int indent_to,";
358 print " struct cl_optimization *ptr)";
359 print "{";
361 print " fputs (\"\\n\", file);";
362 for (i = 0; i < n_opt_other; i++) {
363 print " if (ptr->x_" var_opt_other[i] ")";
364 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
365 print " indent_to, \"\",";
366 print " \"" var_opt_other[i] "\",";
367 print " (unsigned long)ptr->x_" var_opt_other[i] ");";
368 print "";
371 for (i = 0; i < n_opt_int; i++) {
372 print " if (ptr->x_" var_opt_int[i] ")";
373 print " fprintf (file, \"%*s%s (%#x)\\n\",";
374 print " indent_to, \"\",";
375 print " \"" var_opt_int[i] "\",";
376 print " ptr->x_" var_opt_int[i] ");";
377 print "";
380 for (i = 0; i < n_opt_enum; i++) {
381 print " fprintf (file, \"%*s%s (%#x)\\n\",";
382 print " indent_to, \"\",";
383 print " \"" var_opt_enum[i] "\",";
384 print " (int) ptr->x_" var_opt_enum[i] ");";
385 print "";
388 for (i = 0; i < n_opt_short; i++) {
389 print " if (ptr->x_" var_opt_short[i] ")";
390 print " fprintf (file, \"%*s%s (%#x)\\n\",";
391 print " indent_to, \"\",";
392 print " \"" var_opt_short[i] "\",";
393 print " ptr->x_" var_opt_short[i] ");";
394 print "";
397 for (i = 0; i < n_opt_char; i++) {
398 print " if (ptr->x_" var_opt_char[i] ")";
399 print " fprintf (file, \"%*s%s (%#x)\\n\",";
400 print " indent_to, \"\",";
401 print " \"" var_opt_char[i] "\",";
402 print " ptr->x_" var_opt_char[i] ");";
403 print "";
406 for (i = 0; i < n_opt_string; i++) {
407 print " if (ptr->x_" var_opt_string[i] ")";
408 print " fprintf (file, \"%*s%s (%s)\\n\",";
409 print " indent_to, \"\",";
410 print " \"" var_opt_string[i] "\",";
411 print " ptr->x_" var_opt_string[i] ");";
412 print "";
415 print "}";
417 print "";
418 print "/* Print different optimization variables from structures provided as arguments. */";
419 print "void";
420 print "cl_optimization_print_diff (FILE *file,";
421 print " int indent_to,";
422 print " struct cl_optimization *ptr1,";
423 print " struct cl_optimization *ptr2)";
424 print "{";
426 print " fputs (\"\\n\", file);";
427 for (i = 0; i < n_opt_other; i++) {
428 print " if (ptr1->x_" var_opt_other[i] " != ptr2->x_" var_opt_other[i] ")";
429 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
430 print " indent_to, \"\",";
431 print " \"" var_opt_other[i] "\",";
432 print " (unsigned long)ptr1->x_" var_opt_other[i] ",";
433 print " (unsigned long)ptr2->x_" var_opt_other[i] ");";
434 print "";
437 for (i = 0; i < n_opt_int; i++) {
438 print " if (ptr1->x_" var_opt_int[i] " != ptr2->x_" var_opt_int[i] ")";
439 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
440 print " indent_to, \"\",";
441 print " \"" var_opt_int[i] "\",";
442 print " ptr1->x_" var_opt_int[i] ",";
443 print " ptr2->x_" var_opt_int[i] ");";
444 print "";
447 for (i = 0; i < n_opt_enum; i++) {
448 print " if (ptr1->x_" var_opt_enum[i] " != ptr2->x_" var_opt_enum[i] ")";
449 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
450 print " indent_to, \"\",";
451 print " \"" var_opt_enum[i] "\",";
452 print " (int) ptr1->x_" var_opt_enum[i] ",";
453 print " (int) ptr2->x_" var_opt_enum[i] ");";
454 print "";
457 for (i = 0; i < n_opt_short; i++) {
458 print " if (ptr1->x_" var_opt_short[i] " != ptr2->x_" var_opt_short[i] ")";
459 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
460 print " indent_to, \"\",";
461 print " \"" var_opt_short[i] "\",";
462 print " ptr1->x_" var_opt_short[i] ",";
463 print " ptr2->x_" var_opt_short[i] ");";
464 print "";
467 for (i = 0; i < n_opt_char; i++) {
468 print " if (ptr1->x_" var_opt_char[i] " != ptr2->x_" var_opt_char[i] ")";
469 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
470 print " indent_to, \"\",";
471 print " \"" var_opt_char[i] "\",";
472 print " ptr1->x_" var_opt_char[i] ",";
473 print " ptr2->x_" var_opt_char[i] ");";
474 print "";
477 for (i = 0; i < n_opt_string; i++) {
478 name = var_opt_string[i]
479 print " if (ptr1->x_" name " != ptr2->x_" name "";
480 print " && (!ptr1->x_" name" || !ptr2->x_" name
481 print " || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
482 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
483 print " indent_to, \"\",";
484 print " \"" name "\",";
485 print " ptr1->x_" name " ? ptr1->x_" name " : \"(null)\",";
486 print " ptr2->x_" name " ? ptr2->x_" name " : \"(null)\");";
487 print "";
490 print "}";
493 print "";
494 print "/* Save selected option variables into a structure. */"
495 print "void";
496 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts,";
497 print " struct gcc_options *opts_set)";
498 print "{";
500 n_target_char = 0;
501 n_target_short = 0;
502 n_target_int = 0;
503 n_target_enum = 0;
504 n_target_string = 0;
505 n_target_other = 0;
507 if (have_save) {
508 for (i = 0; i < n_opts; i++) {
509 if (flag_set_p("Save", flags[i])) {
510 name = var_name(flags[i])
511 if(name == "")
512 name = "target_flags";
514 if(name in var_save_seen)
515 continue;
517 var_save_seen[name]++;
518 otype = var_type_struct(flags[i])
519 if (opt_args("Mask", flags[i]) != "" \
520 || opt_args("InverseMask", flags[i]))
521 var_target_explicit_mask[name] = 1;
523 if (otype ~ "^((un)?signed +)?int *$")
524 var_target_int[n_target_int++] = name;
526 else if (otype ~ "^((un)?signed +)?short *$")
527 var_target_short[n_target_short++] = name;
529 else if (otype ~ ("^enum +[_" alnum "]+ *$")) {
530 var_target_enum_type[n_target_enum] = otype;
531 var_target_enum[n_target_enum++] = name;
533 else if (otype ~ "^((un)?signed +)?char *$") {
534 var_target_char[n_target_char++] = name;
535 if (otype ~ "^unsigned +char *$")
536 var_target_range[name] = "0, 255"
537 else if (otype ~ "^signed +char *$")
538 var_target_range[name] = "-128, 127"
539 if (otype == var_type(flags[i]))
540 var_target_range[name] = ""
542 else if (otype ~ "^const char \\**$") {
543 var_target_string[n_target_string++] = name;
544 string_options_names[name]++
546 else
547 var_target_other[n_target_other++] = name;
550 } else {
551 var_target_int[n_target_int++] = "target_flags";
552 var_target_explicit_mask["target_flags"] = 1;
555 have_assert = 0;
556 for (i = 0; i < n_target_char; i++) {
557 name = var_target_char[i];
558 if (var_target_range[name] != "") {
559 have_assert = 1;
560 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_target_range[name] "));";
564 if (have_assert)
565 print "";
567 print " if (targetm.target_option.save)";
568 print " targetm.target_option.save (ptr, opts, opts_set);";
569 print "";
571 for (i = 0; i < n_extra_target_vars; i++) {
572 print " ptr->x_" extra_target_vars[i] " = opts->x_" extra_target_vars[i] ";";
575 for (i = 0; i < n_target_other; i++) {
576 print " ptr->x_" var_target_other[i] " = opts->x_" var_target_other[i] ";";
579 for (i = 0; i < n_target_enum; i++) {
580 print " ptr->x_" var_target_enum[i] " = opts->x_" var_target_enum[i] ";";
583 for (i = 0; i < n_target_int; i++) {
584 print " ptr->x_" var_target_int[i] " = opts->x_" var_target_int[i] ";";
587 for (i = 0; i < n_target_short; i++) {
588 print " ptr->x_" var_target_short[i] " = opts->x_" var_target_short[i] ";";
591 for (i = 0; i < n_target_char; i++) {
592 print " ptr->x_" var_target_char[i] " = opts->x_" var_target_char[i] ";";
595 for (i = 0; i < n_target_string; i++) {
596 print " ptr->x_" var_target_string[i] " = opts->x_" var_target_string[i] ";";
599 print "";
601 j = 0;
602 k = 0;
603 for (i = 0; i < n_extra_target_vars; i++) {
604 if (j == 0 && k == 0) {
605 print " unsigned HOST_WIDE_INT mask = 0;";
607 print " if (opts_set->x_" extra_target_vars[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
608 j++;
609 if (j == 64) {
610 print " ptr->explicit_mask[" k "] = mask;";
611 print " mask = 0;";
612 j = 0;
613 k++;
617 for (i = 0; i < n_target_other; i++) {
618 if (var_target_other[i] in var_target_explicit_mask) {
619 print " ptr->explicit_mask_" var_target_other[i] " = opts_set->x_" var_target_other[i] ";";
620 continue;
622 if (j == 0 && k == 0) {
623 print " unsigned HOST_WIDE_INT mask = 0;";
625 print " if (opts_set->x_" var_target_other[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
626 j++;
627 if (j == 64) {
628 print " ptr->explicit_mask[" k "] = mask;";
629 print " mask = 0;";
630 j = 0;
631 k++;
635 for (i = 0; i < n_target_enum; i++) {
636 if (j == 0 && k == 0) {
637 print " unsigned HOST_WIDE_INT mask = 0;";
639 print " if (opts_set->x_" var_target_enum[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
640 j++;
641 if (j == 64) {
642 print " ptr->explicit_mask[" k "] = mask;";
643 print " mask = 0;";
644 j = 0;
645 k++;
649 for (i = 0; i < n_target_int; i++) {
650 if (var_target_int[i] in var_target_explicit_mask) {
651 print " ptr->explicit_mask_" var_target_int[i] " = opts_set->x_" var_target_int[i] ";";
652 continue;
654 if (j == 0 && k == 0) {
655 print " unsigned HOST_WIDE_INT mask = 0;";
657 print " if (opts_set->x_" var_target_int[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
658 j++;
659 if (j == 64) {
660 print " ptr->explicit_mask[" k "] = mask;";
661 print " mask = 0;";
662 j = 0;
663 k++;
667 for (i = 0; i < n_target_short; i++) {
668 if (j == 0 && k == 0) {
669 print " unsigned HOST_WIDE_INT mask = 0;";
671 print " if (opts_set->x_" var_target_short[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
672 j++;
673 if (j == 64) {
674 print " ptr->explicit_mask[" k "] = mask;";
675 print " mask = 0;";
676 j = 0;
677 k++;
681 for (i = 0; i < n_target_char; i++) {
682 if (j == 0 && k == 0) {
683 print " unsigned HOST_WIDE_INT mask = 0;";
685 print " if (opts_set->x_" var_target_char[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
686 j++;
687 if (j == 64) {
688 print " ptr->explicit_mask[" k "] = mask;";
689 print " mask = 0;";
690 j = 0;
691 k++;
695 for (i = 0; i < n_target_string; i++) {
696 if (j == 0 && k == 0) {
697 print " unsigned HOST_WIDE_INT mask = 0;";
699 print " if (opts_set->x_" var_target_string[i] ") mask |= HOST_WIDE_INT_1U << " j ";";
700 j++;
701 if (j == 64) {
702 print " ptr->explicit_mask[" k "] = mask;";
703 print " mask = 0;";
704 j = 0;
705 k++;
709 if (j != 0) {
710 print " ptr->explicit_mask[" k "] = mask;";
712 has_target_explicit_mask = 0;
713 if (j != 0 || k != 0) {
714 has_target_explicit_mask = 1;
717 print "}";
719 print "";
720 print "/* Restore selected current options from a structure. */";
721 print "void";
722 print "cl_target_option_restore (struct gcc_options *opts, struct gcc_options *opts_set,";
723 print " struct cl_target_option *ptr)";
724 print "{";
726 for (i = 0; i < n_extra_target_vars; i++) {
727 print " opts->x_" extra_target_vars[i] " = ptr->x_" extra_target_vars[i] ";";
730 for (i = 0; i < n_target_other; i++) {
731 print " opts->x_" var_target_other[i] " = ptr->x_" var_target_other[i] ";";
734 for (i = 0; i < n_target_enum; i++) {
735 print " opts->x_" var_target_enum[i] " = ptr->x_" var_target_enum[i] ";";
738 for (i = 0; i < n_target_int; i++) {
739 print " opts->x_" var_target_int[i] " = ptr->x_" var_target_int[i] ";";
742 for (i = 0; i < n_target_short; i++) {
743 print " opts->x_" var_target_short[i] " = ptr->x_" var_target_short[i] ";";
746 for (i = 0; i < n_target_char; i++) {
747 print " opts->x_" var_target_char[i] " = ptr->x_" var_target_char[i] ";";
750 for (i = 0; i < n_target_string; i++) {
751 print " opts->x_" var_target_string[i] " = ptr->x_" var_target_string[i] ";";
754 print "";
755 if (has_target_explicit_mask) {
756 print " unsigned HOST_WIDE_INT mask;";
759 j = 64;
760 k = 0;
761 for (i = 0; i < n_extra_target_vars; i++) {
762 if (j == 64) {
763 print " mask = ptr->explicit_mask[" k "];";
764 k++;
765 j = 0;
767 if (extra_target_var_types[i] ~ ("^enum +[_" alnum "]+ *$")) {
768 print " opts_set->x_" extra_target_vars[i] " = static_cast<" extra_target_var_types[i] ">((mask & 1) != 0);";
770 else if (extra_target_var_types[i] ~ "^const char \\**$") {
771 print " opts_set->x_" extra_target_vars[i] " = (mask & 1) ? \"\" : nullptr;";
773 else {
774 print " opts_set->x_" extra_target_vars[i] " = (mask & 1) != 0;";
776 print " mask >>= 1;"
777 j++;
780 for (i = 0; i < n_target_other; i++) {
781 if (var_target_other[i] in var_target_explicit_mask) {
782 print " opts_set->x_" var_target_other[i] " = ptr->explicit_mask_" var_target_other[i] ";";
783 continue;
785 if (j == 64) {
786 print " mask = ptr->explicit_mask[" k "];";
787 k++;
788 j = 0;
790 print " opts_set->x_" var_target_other[i] " = (mask & 1) != 0;";
791 print " mask >>= 1;"
792 j++;
795 for (i = 0; i < n_target_enum; i++) {
796 if (j == 64) {
797 print " mask = ptr->explicit_mask[" k "];";
798 k++;
799 j = 0;
801 print " opts_set->x_" var_target_enum[i] " = static_cast<" var_target_enum_type[i] ">((mask & 1) != 0);";
802 print " mask >>= 1;"
803 j++;
806 for (i = 0; i < n_target_int; i++) {
807 if (var_target_int[i] in var_target_explicit_mask) {
808 print " opts_set->x_" var_target_int[i] " = ptr->explicit_mask_" var_target_int[i] ";";
809 continue;
811 if (j == 64) {
812 print " mask = ptr->explicit_mask[" k "];";
813 k++;
814 j = 0;
816 print " opts_set->x_" var_target_int[i] " = (mask & 1) != 0;";
817 print " mask >>= 1;"
818 j++;
821 for (i = 0; i < n_target_short; i++) {
822 if (j == 64) {
823 print " mask = ptr->explicit_mask[" k "];";
824 k++;
825 j = 0;
827 print " opts_set->x_" var_target_short[i] " = (mask & 1) != 0;";
828 print " mask >>= 1;"
829 j++;
832 for (i = 0; i < n_target_char; i++) {
833 if (j == 64) {
834 print " mask = ptr->explicit_mask[" k "];";
835 k++;
836 j = 0;
838 print " opts_set->x_" var_target_char[i] " = (mask & 1) != 0;";
839 print " mask >>= 1;"
840 j++;
843 for (i = 0; i < n_target_string; i++) {
844 if (j == 64) {
845 print " mask = ptr->explicit_mask[" k "];";
846 k++;
847 j = 0;
849 print " opts_set->x_" var_target_string[i] " = (mask & 1) ? \"\" : nullptr;";
850 print " mask >>= 1;"
851 j++;
854 # This must occur after the normal variables in case the code depends on those
855 # variables.
856 print "";
857 print " if (targetm.target_option.restore)";
858 print " targetm.target_option.restore (opts, opts_set, ptr);";
860 print "}";
862 print "";
863 print "/* Print optimization options from a structure. */";
864 print "void";
865 print "cl_target_option_print (FILE *file,";
866 print " int indent,";
867 print " struct cl_target_option *ptr)";
868 print "{";
870 print " fputs (\"\\n\", file);";
871 for (i = 0; i < n_target_other; i++) {
872 print " if (ptr->x_" var_target_other[i] ")";
873 hwi = host_wide_int[var_target_other[i]]
874 if (hwi == "yes")
875 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
876 else
877 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
878 print " indent, \"\",";
879 print " \"" var_target_other[i] "\",";
880 if (hwi == "yes")
881 print " ptr->x_" var_target_other[i] ");";
882 else
883 print " (unsigned long)ptr->x_" var_target_other[i] ");";
884 print "";
887 for (i = 0; i < n_target_enum; i++) {
888 print " if (ptr->x_" var_target_enum[i] ")";
889 print " fprintf (file, \"%*s%s (%#x)\\n\",";
890 print " indent, \"\",";
891 print " \"" var_target_enum[i] "\",";
892 print " ptr->x_" var_target_enum[i] ");";
893 print "";
896 for (i = 0; i < n_target_int; i++) {
897 print " if (ptr->x_" var_target_int[i] ")";
898 print " fprintf (file, \"%*s%s (%#x)\\n\",";
899 print " indent, \"\",";
900 print " \"" var_target_int[i] "\",";
901 print " ptr->x_" var_target_int[i] ");";
902 print "";
905 for (i = 0; i < n_target_short; i++) {
906 print " if (ptr->x_" var_target_short[i] ")";
907 print " fprintf (file, \"%*s%s (%#x)\\n\",";
908 print " indent, \"\",";
909 print " \"" var_target_short[i] "\",";
910 print " ptr->x_" var_target_short[i] ");";
911 print "";
914 for (i = 0; i < n_target_char; i++) {
915 print " if (ptr->x_" var_target_char[i] ")";
916 print " fprintf (file, \"%*s%s (%#x)\\n\",";
917 print " indent, \"\",";
918 print " \"" var_target_char[i] "\",";
919 print " ptr->x_" var_target_char[i] ");";
920 print "";
923 for (i = 0; i < n_target_string; i++) {
924 print " if (ptr->x_" var_target_string[i] ")";
925 print " fprintf (file, \"%*s%s (%s)\\n\",";
926 print " indent, \"\",";
927 print " \"" var_target_string[i] "\",";
928 print " ptr->x_" var_target_string[i] ");";
929 print "";
932 print "";
933 print " if (targetm.target_option.print)";
934 print " targetm.target_option.print (file, indent, ptr);";
935 print "}";
937 print "";
938 print "/* Print different target option variables from structures provided as arguments. */";
939 print "void";
940 print "cl_target_option_print_diff (FILE *file,";
941 print " int indent ATTRIBUTE_UNUSED,";
942 print " struct cl_target_option *ptr1 ATTRIBUTE_UNUSED,";
943 print " struct cl_target_option *ptr2 ATTRIBUTE_UNUSED)";
944 print "{";
946 print " fputs (\"\\n\", file);";
947 for (i = 0; i < n_target_other; i++) {
948 print " if (ptr1->x_" var_target_other[i] " != ptr2->x_" var_target_other[i] ")";
949 hwi = host_wide_int[var_target_other[i]]
950 if (hwi == "yes")
951 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x/%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
952 else
953 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
954 print " indent, \"\",";
955 print " \"" var_target_other[i] "\",";
956 if (hwi == "yes") {
957 print " ptr1->x_" var_target_other[i] ",";
958 print " ptr2->x_" var_target_other[i] ");";
960 else {
961 print " (unsigned long)ptr1->x_" var_target_other[i] ",";
962 print " (unsigned long)ptr2->x_" var_target_other[i] ");";
964 print "";
967 for (i = 0; i < n_target_enum; i++) {
968 print " if (ptr1->x_" var_target_enum[i] " != ptr2->x_" var_target_enum[i] ")";
969 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
970 print " indent, \"\",";
971 print " \"" var_target_enum[i] "\",";
972 print " ptr1->x_" var_target_enum[i] ",";
973 print " ptr2->x_" var_target_enum[i] ");";
974 print "";
977 for (i = 0; i < n_target_int; i++) {
978 print " if (ptr1->x_" var_target_int[i] " != ptr2->x_" var_target_int[i] ")";
979 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
980 print " indent, \"\",";
981 print " \"" var_target_int[i] "\",";
982 print " ptr1->x_" var_target_int[i] ",";
983 print " ptr2->x_" var_target_int[i] ");";
984 print "";
987 for (i = 0; i < n_target_short; i++) {
988 print " if (ptr1->x_" var_target_short[i] " != ptr2->x_" var_target_short[i] ")";
989 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
990 print " indent, \"\",";
991 print " \"" var_target_short[i] "\",";
992 print " ptr1->x_" var_target_short[i] ",";
993 print " ptr2->x_" var_target_short[i] ");";
994 print "";
997 for (i = 0; i < n_target_char; i++) {
998 print " if (ptr1->x_" var_target_char[i] " != ptr2->x_" var_target_char[i] ")";
999 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
1000 print " indent, \"\",";
1001 print " \"" var_target_char[i] "\",";
1002 print " ptr1->x_" var_target_char[i] ",";
1003 print " ptr2->x_" var_target_char[i] ");";
1004 print "";
1007 for (i = 0; i < n_target_string; i++) {
1008 name = var_target_string[i]
1009 print " if (ptr1->x_" name " != ptr2->x_" name "";
1010 print " && (!ptr1->x_" name" || !ptr2->x_" name
1011 print " || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
1012 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
1013 print " indent, \"\",";
1014 print " \"" name "\",";
1015 print " ptr1->x_" name " ? ptr1->x_" name " : \"(null)\",";
1016 print " ptr2->x_" name " ? ptr2->x_" name " : \"(null)\");";
1017 print "";
1020 print "}";
1022 print "";
1023 print "/* Compare two target options */";
1024 print "bool";
1025 print "cl_target_option_eq (struct cl_target_option const *ptr1 ATTRIBUTE_UNUSED,";
1026 print " struct cl_target_option const *ptr2 ATTRIBUTE_UNUSED)";
1027 print "{";
1028 n_target_val = 0;
1029 n_target_str = 0;
1030 n_target_array = 0;
1032 for (i = 0; i < n_target_save; i++) {
1033 var = target_save_decl[i];
1034 sub (" *=.*", "", var);
1035 name = var;
1036 type = var;
1037 sub("^.*[ *]", "", name)
1038 sub(" *" name "$", "", type)
1039 if (target_save_decl[i] ~ "^const char \\*+[_" alnum "]+$") {
1040 var_target_str[n_target_str++] = name;
1041 string_options_names[name]++
1043 else {
1044 if (target_save_decl[i] ~ " .*\\[.+\\]+$") {
1045 size = name;
1046 sub("[^\\[]+\\[", "", size);
1047 sub("\\]$", "", size);
1048 sub("\\[.+", "", name)
1049 sub(" [^ ]+$", "", type)
1050 var_target_array[n_target_array] = name
1051 var_target_array_type[n_target_array] = type
1052 var_target_array_size[n_target_array++] = size
1054 else {
1055 var_target_val_type[n_target_val] = type;
1056 var_target_val[n_target_val++] = name;
1060 if (have_save) {
1061 for (i = 0; i < n_opts; i++) {
1062 if (flag_set_p("Save", flags[i])) {
1063 name = var_name(flags[i])
1064 if(name == "")
1065 name = "target_flags";
1067 if(name in var_list_seen)
1068 continue;
1070 var_list_seen[name]++;
1071 otype = var_type_struct(flags[i])
1072 if (otype ~ "^const char \\**$")
1073 var_target_str[n_target_str++] = "x_" name;
1074 else {
1075 var_target_val_type[n_target_val] = otype;
1076 var_target_val[n_target_val++] = "x_" name;
1080 } else {
1081 var_target_val_type[n_target_val] = "int";
1082 var_target_val[n_target_val++] = "x_target_flags";
1085 for (i = 0; i < n_target_str; i++) {
1086 name = var_target_str[i]
1087 print " if (ptr1->" name" != ptr2->" name;
1088 print " && (!ptr1->" name" || !ptr2->" name
1089 print " || strcmp (ptr1->" name", ptr2->" name ")))";
1090 print " return false;";
1092 for (i = 0; i < n_target_array; i++) {
1093 name = var_target_array[i]
1094 size = var_target_array_size[i]
1095 type = var_target_array_type[i]
1096 print " if (memcmp (ptr1->" name ", ptr2->" name ", " size " * sizeof(" type ")))"
1097 print " return false;";
1099 for (i = 0; i < n_target_val; i++) {
1100 name = var_target_val[i]
1101 print " if (ptr1->" name" != ptr2->" name ")";
1102 print " return false;";
1105 if (has_target_explicit_mask) {
1106 print " for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
1107 print " if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
1108 print " return false;"
1111 for (i = 0; i < n_target_other; i++) {
1112 if (var_target_other[i] in var_target_explicit_mask) {
1113 print " if (ptr1->explicit_mask_" var_target_other[i] " != ptr2->explicit_mask_" var_target_other[i] ")";
1114 print " return false;";
1118 for (i = 0; i < n_target_int; i++) {
1119 if (var_target_int[i] in var_target_explicit_mask) {
1120 print " if (ptr1->explicit_mask_" var_target_int[i] " != ptr2->explicit_mask_" var_target_int[i] ")";
1121 print " return false;";
1125 print " return true;";
1127 print "}";
1129 print "";
1130 print "/* Hash target options */";
1131 print "hashval_t";
1132 print "cl_target_option_hash (struct cl_target_option const *ptr ATTRIBUTE_UNUSED)";
1133 print "{";
1134 print " inchash::hash hstate;";
1135 for (i = 0; i < n_target_str; i++) {
1136 name = var_target_str[i]
1137 print " if (ptr->" name")";
1138 print " hstate.add (ptr->" name", strlen (ptr->" name"));";
1139 print " else";
1140 print " hstate.add_int (0);";
1142 for (i = 0; i < n_target_array; i++) {
1143 name= var_target_array[i]
1144 size = var_target_array_size[i]
1145 type = var_target_array_type[i]
1146 print " hstate.add_int (" size ");";
1147 print " hstate.add (ptr->" name ", sizeof (" type ") * " size ");";
1149 for (i = 0; i < n_target_val; i++) {
1150 name = var_target_val[i]
1151 print " hstate.add_hwi (ptr->" name");";
1153 if (has_target_explicit_mask) {
1154 print " for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
1155 print " hstate.add_hwi (ptr->explicit_mask[i]);";
1158 for (i = 0; i < n_target_other; i++) {
1159 if (var_target_other[i] in var_target_explicit_mask)
1160 print " hstate.add_hwi (ptr->explicit_mask_" var_target_other[i] ");";
1163 for (i = 0; i < n_target_int; i++) {
1164 if (var_target_int[i] in var_target_explicit_mask)
1165 print " hstate.add_hwi (ptr->explicit_mask_" var_target_int[i] ");";
1168 print " return hstate.end ();";
1169 print "}";
1171 print "";
1172 print "/* Stream out target options */";
1173 print "void";
1174 print "cl_target_option_stream_out (struct output_block *ob ATTRIBUTE_UNUSED,";
1175 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
1176 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
1177 print "{";
1178 for (i = 0; i < n_target_str; i++) {
1179 name = var_target_str[i]
1180 print " bp_pack_string (ob, bp, ptr->" name", true);";
1182 for (i = 0; i < n_target_array; i++) {
1183 name = var_target_array[i]
1184 size = var_target_array_size[i]
1185 print " for (unsigned i = 0; i < " size "; i++)"
1186 print " bp_pack_value (bp, ptr->" name "[i], 64);";
1188 for (i = 0; i < n_target_val; i++) {
1189 name = var_target_val[i]
1190 print " bp_pack_value (bp, ptr->" name", 64);";
1193 if (has_target_explicit_mask) {
1194 print " for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
1195 print " bp_pack_value (bp, ptr->explicit_mask[i], 64);";
1198 for (i = 0; i < n_target_other; i++) {
1199 if (var_target_other[i] in var_target_explicit_mask) {
1200 print " bp_pack_value (bp, ptr->explicit_mask_" var_target_other[i] ", 64);";
1204 for (i = 0; i < n_target_int; i++) {
1205 if (var_target_int[i] in var_target_explicit_mask) {
1206 print " bp_pack_value (bp, ptr->explicit_mask_" var_target_int[i] ", 64);";
1210 print "}";
1212 print "";
1213 print "/* Stream in target options */";
1214 print "void";
1215 print "cl_target_option_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
1216 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
1217 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
1218 print "{";
1219 for (i = 0; i < n_target_str; i++) {
1220 name = var_target_str[i]
1221 print " ptr->" name" = bp_unpack_string (data_in, bp);";
1222 print " if (ptr->" name")";
1223 print " ptr->" name" = xstrdup (ptr->" name");";
1225 for (i = 0; i < n_target_array; i++) {
1226 name = var_target_array[i]
1227 size = var_target_array_size[i]
1228 print " for (int i = " size " - 1; i >= 0; i--)"
1229 print " ptr->" name "[i] = (" var_target_array_type[i] ") bp_unpack_value (bp, 64);";
1231 for (i = 0; i < n_target_val; i++) {
1232 name = var_target_val[i]
1233 print " ptr->" name" = (" var_target_val_type[i] ") bp_unpack_value (bp, 64);";
1236 if (has_target_explicit_mask) {
1237 print " for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
1238 print " ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
1241 for (i = 0; i < n_target_other; i++) {
1242 if (var_target_other[i] in var_target_explicit_mask) {
1243 print " ptr->explicit_mask_" var_target_other[i] " = bp_unpack_value (bp, 64);";
1247 for (i = 0; i < n_target_int; i++) {
1248 if (var_target_int[i] in var_target_explicit_mask) {
1249 print " ptr->explicit_mask_" var_target_int[i] " = bp_unpack_value (bp, 64);";
1253 print "}";
1255 print "/* free heap memory used by target options */";
1256 print "void";
1257 print "cl_target_option_free (struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
1258 print "{";
1259 for (i = 0; i < n_target_str; i++) {
1260 name = var_target_str[i]
1261 print " if (ptr->" name")";
1262 print " free (const_cast <char *>(ptr->" name"));";
1264 print "}";
1266 n_opt_val = 4;
1267 var_opt_val[0] = "x_optimize"
1268 var_opt_val_type[0] = "char "
1269 var_opt_hash[0] = 1;
1270 var_opt_val[1] = "x_optimize_size"
1271 var_opt_val_type[1] = "char "
1272 var_opt_hash[1] = 1;
1273 var_opt_val[2] = "x_optimize_debug"
1274 var_opt_val_type[2] = "char "
1275 var_opt_hash[2] = 1;
1276 var_opt_val[3] = "x_optimize_fast"
1277 var_opt_val_type[3] = "char "
1278 var_opt_hash[3] = 1;
1279 for (i = 0; i < n_opts; i++) {
1280 if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
1281 name = var_name(flags[i])
1282 if(name == "")
1283 continue;
1285 if(name in var_opt_list_seen)
1286 continue;
1288 var_opt_list_seen[name]++;
1290 otype = var_type_struct(flags[i])
1291 var_opt_val_type[n_opt_val] = otype;
1292 var_opt_val[n_opt_val] = "x_" name;
1293 var_opt_hash[n_opt_val] = flag_set_p("Optimization", flags[i]);
1295 # If applicable, optimize streaming for the common case that
1296 # the current value is unchanged from the 'Init' value:
1297 # XOR-encode it so that we stream value zero.
1298 # Not handling non-parameters as those really generally don't
1299 # have large initializers.
1300 # Not handling enums as we don't know if '(enum ...) 10' is
1301 # even valid (see synthesized 'if' conditionals below).
1302 if (flag_set_p("Param", flags[i]) \
1303 && !(otype ~ "^enum ")) {
1304 # Those without 'Init' are zero-initialized and thus
1305 # already encoded ideally.
1306 init = opt_args("Init", flags[i])
1307 var_opt_optimize_init[n_opt_val] = init;
1310 n_opt_val++;
1313 print "";
1314 print "/* Hash optimization options */";
1315 print "hashval_t";
1316 print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)";
1317 print "{";
1318 print " inchash::hash hstate;";
1319 for (i = 0; i < n_opt_val; i++) {
1320 if (!var_opt_hash[i])
1321 continue;
1322 name = var_opt_val[i]
1323 otype = var_opt_val_type[i];
1324 if (otype ~ "^const char \\**$")
1326 print " if (ptr->" name")";
1327 print " hstate.add (ptr->" name", strlen (ptr->" name"));";
1328 print " else";
1329 print " hstate.add_int (0);";
1331 else
1332 print " hstate.add_hwi (ptr->" name");";
1334 print " for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
1335 print " hstate.add_hwi (ptr->explicit_mask[i]);";
1336 print " return hstate.end ();";
1337 print "}";
1339 print "";
1340 print "/* Compare two optimization options */";
1341 print "bool";
1342 print "cl_optimization_option_eq (cl_optimization const *ptr1,";
1343 print " cl_optimization const *ptr2)";
1344 print "{";
1345 for (i = 0; i < n_opt_val; i++) {
1346 if (!var_opt_hash[i])
1347 continue;
1348 name = var_opt_val[i]
1349 otype = var_opt_val_type[i];
1350 if (otype ~ "^const char \\**$")
1352 print " if (ptr1->" name" != ptr2->" name;
1353 print " && (!ptr1->" name" || !ptr2->" name
1354 print " || strcmp (ptr1->" name", ptr2->" name ")))";
1355 print " return false;";
1357 else
1359 print " if (ptr1->" name" != ptr2->" name ")";
1360 print " return false;";
1363 print " for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
1364 print " if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
1365 print " return false;"
1366 print " return true;";
1367 print "}";
1369 print "";
1370 print "/* Stream out optimization options */";
1371 print "void";
1372 print "cl_optimization_stream_out (struct output_block *ob,";
1373 print " struct bitpack_d *bp,";
1374 print " struct cl_optimization *ptr)";
1375 print "{";
1376 for (i = 0; i < n_opt_val; i++) {
1377 name = var_opt_val[i]
1378 otype = var_opt_val_type[i];
1379 if (otype ~ "^const char \\**$")
1380 print " bp_pack_string (ob, bp, ptr->" name", true);";
1381 else {
1382 if (otype ~ "^unsigned") {
1383 sgn = "unsigned";
1384 } else {
1385 sgn = "int";
1387 # If applicable, encode the streamed value.
1388 if (var_opt_optimize_init[i]) {
1389 print " if (" var_opt_optimize_init[i] " > (" var_opt_val_type[i] ") 10)";
1390 print " bp_pack_var_len_" sgn " (bp, ptr->" name" ^ " var_opt_optimize_init[i] ");";
1391 print " else";
1392 print " bp_pack_var_len_" sgn " (bp, ptr->" name");";
1393 } else {
1394 print " bp_pack_var_len_" sgn " (bp, ptr->" name");";
1398 print " for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
1399 print " bp_pack_value (bp, ptr->explicit_mask[i], 64);";
1400 print "}";
1402 print "";
1403 print "/* Stream in optimization options */";
1404 print "void";
1405 print "cl_optimization_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
1406 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
1407 print " struct cl_optimization *ptr ATTRIBUTE_UNUSED)";
1408 print "{";
1409 for (i = 0; i < n_opt_val; i++) {
1410 name = var_opt_val[i]
1411 otype = var_opt_val_type[i];
1412 if (otype ~ "^const char \\**$") {
1413 print " ptr->" name" = bp_unpack_string (data_in, bp);";
1414 print " if (ptr->" name")";
1415 print " ptr->" name" = xstrdup (ptr->" name");";
1417 else {
1418 if (otype ~ "^unsigned") {
1419 sgn = "unsigned";
1420 } else {
1421 sgn = "int";
1423 print " ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_var_len_" sgn " (bp);";
1424 # If applicable, decode the streamed value.
1425 if (var_opt_optimize_init[i]) {
1426 print " if (" var_opt_optimize_init[i] " > (" var_opt_val_type[i] ") 10)";
1427 print " ptr->" name" ^= " var_opt_optimize_init[i] ";";
1431 print " for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
1432 print " ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
1433 print "}";
1434 print "/* Free heap memory used by optimization options */";
1435 print "void";
1436 print "cl_optimization_option_free (struct cl_optimization *ptr ATTRIBUTE_UNUSED)";
1437 print "{";
1438 for (i = 0; i < n_opt_val; i++) {
1439 name = var_opt_val[i]
1440 otype = var_opt_val_type[i];
1441 if (otype ~ "^const char \\**$")
1443 print " if (ptr->" name")";
1444 print " free (const_cast <char *>(ptr->" name"));";
1447 print "}";
1449 print "void";
1450 print "cl_optimization_compare (gcc_options *ptr1, gcc_options *ptr2)"
1451 print "{"
1453 # all these options are mentioned in PR92860
1454 checked_options["flag_merge_constants"]++
1455 checked_options["param_max_fields_for_field_sensitive"]++
1456 checked_options["flag_omit_frame_pointer"]++
1457 # arc exceptions
1458 checked_options["TARGET_ALIGN_CALL"]++
1459 checked_options["TARGET_CASE_VECTOR_PC_RELATIVE"]++
1460 checked_options["arc_size_opt_level"]++
1461 # arm exceptions
1462 checked_options["arm_fp16_format"]++
1465 for (i = 0; i < n_opts; i++) {
1466 name = var_name(flags[i]);
1467 if (name == "")
1468 continue;
1470 if (name in checked_options)
1471 continue;
1472 checked_options[name]++
1474 if (name in string_options_names || ("x_" name) in string_options_names) {
1475 print " if (ptr1->x_" name " != ptr2->x_" name "";
1476 print " && (!ptr1->x_" name" || !ptr2->x_" name
1477 print " || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
1478 print " internal_error (\"%<global_options%> are modified in local context\");";
1480 else {
1481 print " if (ptr1->x_" name " != ptr2->x_" name ")"
1482 print " internal_error (\"%<global_options%> are modified in local context\");";
1486 print "}";