[Ada] Add special bypass for obsolete code pattern
[official-gcc.git] / gcc / optc-save-gen.awk
blob74096bc5462c4802567a081690fdf55273ed7aa6
1 # Copyright (C) 2003-2019 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 else
132 var_opt_other[n_opt_other++] = name;
136 for (i = 0; i < n_opt_char; i++) {
137 name = var_opt_char[i];
138 if (var_opt_range[name] != "")
139 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_opt_range[name] "));";
142 print "";
143 for (i = 0; i < n_opt_other; i++) {
144 print " ptr->x_" var_opt_other[i] " = opts->x_" var_opt_other[i] ";";
147 for (i = 0; i < n_opt_int; i++) {
148 print " ptr->x_" var_opt_int[i] " = opts->x_" var_opt_int[i] ";";
151 for (i = 0; i < n_opt_enum; i++) {
152 print " ptr->x_" var_opt_enum[i] " = opts->x_" var_opt_enum[i] ";";
155 for (i = 0; i < n_opt_short; i++) {
156 print " ptr->x_" var_opt_short[i] " = opts->x_" var_opt_short[i] ";";
159 for (i = 0; i < n_opt_char; i++) {
160 print " ptr->x_" var_opt_char[i] " = opts->x_" var_opt_char[i] ";";
163 for (i = 0; i < n_opt_string; i++) {
164 print " ptr->x_" var_opt_string[i] " = opts->x_" var_opt_string[i] ";";
167 print "}";
169 print "";
170 print "/* Restore optimization options from a structure. */";
171 print "void";
172 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
173 print "{";
175 for (i = 0; i < n_opt_other; i++) {
176 print " opts->x_" var_opt_other[i] " = ptr->x_" var_opt_other[i] ";";
179 for (i = 0; i < n_opt_int; i++) {
180 print " opts->x_" var_opt_int[i] " = ptr->x_" var_opt_int[i] ";";
183 for (i = 0; i < n_opt_enum; i++) {
184 print " opts->x_" var_opt_enum[i] " = ptr->x_" var_opt_enum[i] ";";
187 for (i = 0; i < n_opt_short; i++) {
188 print " opts->x_" var_opt_short[i] " = ptr->x_" var_opt_short[i] ";";
191 for (i = 0; i < n_opt_char; i++) {
192 print " opts->x_" var_opt_char[i] " = ptr->x_" var_opt_char[i] ";";
195 for (i = 0; i < n_opt_string; i++) {
196 print " opts->x_" var_opt_string[i] " = ptr->x_" var_opt_string[i] ";";
199 print " targetm.override_options_after_change ();";
200 print "}";
202 print "";
203 print "/* Print optimization options from a structure. */";
204 print "void";
205 print "cl_optimization_print (FILE *file,";
206 print " int indent_to,";
207 print " struct cl_optimization *ptr)";
208 print "{";
210 print " fputs (\"\\n\", file);";
211 for (i = 0; i < n_opt_other; i++) {
212 print " if (ptr->x_" var_opt_other[i] ")";
213 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
214 print " indent_to, \"\",";
215 print " \"" var_opt_other[i] "\",";
216 print " (unsigned long)ptr->x_" var_opt_other[i] ");";
217 print "";
220 for (i = 0; i < n_opt_int; i++) {
221 print " if (ptr->x_" var_opt_int[i] ")";
222 print " fprintf (file, \"%*s%s (%#x)\\n\",";
223 print " indent_to, \"\",";
224 print " \"" var_opt_int[i] "\",";
225 print " ptr->x_" var_opt_int[i] ");";
226 print "";
229 for (i = 0; i < n_opt_enum; i++) {
230 print " fprintf (file, \"%*s%s (%#x)\\n\",";
231 print " indent_to, \"\",";
232 print " \"" var_opt_enum[i] "\",";
233 print " (int) ptr->x_" var_opt_enum[i] ");";
234 print "";
237 for (i = 0; i < n_opt_short; i++) {
238 print " if (ptr->x_" var_opt_short[i] ")";
239 print " fprintf (file, \"%*s%s (%#x)\\n\",";
240 print " indent_to, \"\",";
241 print " \"" var_opt_short[i] "\",";
242 print " ptr->x_" var_opt_short[i] ");";
243 print "";
246 for (i = 0; i < n_opt_char; i++) {
247 print " if (ptr->x_" var_opt_char[i] ")";
248 print " fprintf (file, \"%*s%s (%#x)\\n\",";
249 print " indent_to, \"\",";
250 print " \"" var_opt_char[i] "\",";
251 print " ptr->x_" var_opt_char[i] ");";
252 print "";
255 for (i = 0; i < n_opt_string; i++) {
256 print " if (ptr->x_" var_opt_string[i] ")";
257 print " fprintf (file, \"%*s%s (%s)\\n\",";
258 print " indent_to, \"\",";
259 print " \"" var_opt_string[i] "\",";
260 print " ptr->x_" var_opt_string[i] ");";
261 print "";
264 print "}";
266 print "";
267 print "/* Print different optimization variables from structures provided as arguments. */";
268 print "void";
269 print "cl_optimization_print_diff (FILE *file,";
270 print " int indent_to,";
271 print " struct cl_optimization *ptr1,";
272 print " struct cl_optimization *ptr2)";
273 print "{";
275 print " fputs (\"\\n\", file);";
276 for (i = 0; i < n_opt_other; i++) {
277 print " if (ptr1->x_" var_opt_other[i] " != ptr2->x_" var_opt_other[i] ")";
278 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
279 print " indent_to, \"\",";
280 print " \"" var_opt_other[i] "\",";
281 print " (unsigned long)ptr1->x_" var_opt_other[i] ",";
282 print " (unsigned long)ptr2->x_" var_opt_other[i] ");";
283 print "";
286 for (i = 0; i < n_opt_int; i++) {
287 print " if (ptr1->x_" var_opt_int[i] " != ptr2->x_" var_opt_int[i] ")";
288 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
289 print " indent_to, \"\",";
290 print " \"" var_opt_int[i] "\",";
291 print " ptr1->x_" var_opt_int[i] ",";
292 print " ptr2->x_" var_opt_int[i] ");";
293 print "";
296 for (i = 0; i < n_opt_enum; i++) {
297 print " if (ptr1->x_" var_opt_enum[i] " != ptr2->x_" var_opt_enum[i] ")";
298 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
299 print " indent_to, \"\",";
300 print " \"" var_opt_enum[i] "\",";
301 print " (int) ptr1->x_" var_opt_enum[i] ",";
302 print " (int) ptr2->x_" var_opt_enum[i] ");";
303 print "";
306 for (i = 0; i < n_opt_short; i++) {
307 print " if (ptr1->x_" var_opt_short[i] " != ptr2->x_" var_opt_short[i] ")";
308 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
309 print " indent_to, \"\",";
310 print " \"" var_opt_short[i] "\",";
311 print " ptr1->x_" var_opt_short[i] ",";
312 print " ptr2->x_" var_opt_short[i] ");";
313 print "";
316 for (i = 0; i < n_opt_char; i++) {
317 print " if (ptr1->x_" var_opt_char[i] " != ptr2->x_" var_opt_char[i] ")";
318 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
319 print " indent_to, \"\",";
320 print " \"" var_opt_char[i] "\",";
321 print " ptr1->x_" var_opt_char[i] ",";
322 print " ptr2->x_" var_opt_char[i] ");";
323 print "";
326 for (i = 0; i < n_opt_string; i++) {
327 name = var_opt_string[i]
328 print " if (ptr1->x_" name " != ptr2->x_" name "";
329 print " && (!ptr1->x_" name" || !ptr2->x_" name
330 print " || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
331 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
332 print " indent_to, \"\",";
333 print " \"" name "\",";
334 print " ptr1->x_" name " ? ptr1->x_" name " : \"(null)\",";
335 print " ptr2->x_" name " ? ptr1->x_" name " : \"(null)\");";
336 print "";
339 print "}";
342 print "";
343 print "/* Save selected option variables into a structure. */"
344 print "void";
345 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
346 print "{";
348 n_target_char = 0;
349 n_target_short = 0;
350 n_target_int = 0;
351 n_target_enum = 0;
352 n_target_string = 0;
353 n_target_other = 0;
355 if (have_save) {
356 for (i = 0; i < n_opts; i++) {
357 if (flag_set_p("Save", flags[i])) {
358 name = var_name(flags[i])
359 if(name == "")
360 name = "target_flags";
362 if(name in var_save_seen)
363 continue;
365 var_save_seen[name]++;
366 otype = var_type_struct(flags[i])
367 if (otype ~ "^((un)?signed +)?int *$")
368 var_target_int[n_target_int++] = name;
370 else if (otype ~ "^((un)?signed +)?short *$")
371 var_target_short[n_target_short++] = name;
373 else if (otype ~ ("^enum +[_" alnum "]+ *$"))
374 var_target_enum[n_target_enum++] = name;
376 else if (otype ~ "^((un)?signed +)?char *$") {
377 var_target_char[n_target_char++] = name;
378 if (otype ~ "^unsigned +char *$")
379 var_target_range[name] = "0, 255"
380 else if (otype ~ "^signed +char *$")
381 var_target_range[name] = "-128, 127"
382 if (otype == var_type(flags[i]))
383 var_target_range[name] = ""
385 else if (otype ~ "^const char \\**$")
386 var_target_string[n_target_string++] = name;
387 else
388 var_target_other[n_target_other++] = name;
391 } else {
392 var_target_int[n_target_int++] = "target_flags";
395 have_assert = 0;
396 for (i = 0; i < n_target_char; i++) {
397 name = var_target_char[i];
398 if (var_target_range[name] != "") {
399 have_assert = 1;
400 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_target_range[name] "));";
404 if (have_assert)
405 print "";
407 print " if (targetm.target_option.save)";
408 print " targetm.target_option.save (ptr, opts);";
409 print "";
411 for (i = 0; i < n_extra_target_vars; i++) {
412 print " ptr->x_" extra_target_vars[i] " = opts->x_" extra_target_vars[i] ";";
415 for (i = 0; i < n_target_other; i++) {
416 print " ptr->x_" var_target_other[i] " = opts->x_" var_target_other[i] ";";
419 for (i = 0; i < n_target_enum; i++) {
420 print " ptr->x_" var_target_enum[i] " = opts->x_" var_target_enum[i] ";";
423 for (i = 0; i < n_target_int; i++) {
424 print " ptr->x_" var_target_int[i] " = opts->x_" var_target_int[i] ";";
427 for (i = 0; i < n_target_short; i++) {
428 print " ptr->x_" var_target_short[i] " = opts->x_" var_target_short[i] ";";
431 for (i = 0; i < n_target_char; i++) {
432 print " ptr->x_" var_target_char[i] " = opts->x_" var_target_char[i] ";";
435 for (i = 0; i < n_target_string; i++) {
436 print " ptr->x_" var_target_string[i] " = opts->x_" var_target_string[i] ";";
439 print "}";
441 print "";
442 print "/* Restore selected current options from a structure. */";
443 print "void";
444 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
445 print "{";
447 for (i = 0; i < n_extra_target_vars; i++) {
448 print " opts->x_" extra_target_vars[i] " = ptr->x_" extra_target_vars[i] ";";
451 for (i = 0; i < n_target_other; i++) {
452 print " opts->x_" var_target_other[i] " = ptr->x_" var_target_other[i] ";";
455 for (i = 0; i < n_target_enum; i++) {
456 print " opts->x_" var_target_enum[i] " = ptr->x_" var_target_enum[i] ";";
459 for (i = 0; i < n_target_int; i++) {
460 print " opts->x_" var_target_int[i] " = ptr->x_" var_target_int[i] ";";
463 for (i = 0; i < n_target_short; i++) {
464 print " opts->x_" var_target_short[i] " = ptr->x_" var_target_short[i] ";";
467 for (i = 0; i < n_target_char; i++) {
468 print " opts->x_" var_target_char[i] " = ptr->x_" var_target_char[i] ";";
471 for (i = 0; i < n_target_string; i++) {
472 print " opts->x_" var_target_string[i] " = ptr->x_" var_target_string[i] ";";
475 # This must occur after the normal variables in case the code depends on those
476 # variables.
477 print "";
478 print " if (targetm.target_option.restore)";
479 print " targetm.target_option.restore (opts, ptr);";
481 print "}";
483 print "";
484 print "/* Print optimization options from a structure. */";
485 print "void";
486 print "cl_target_option_print (FILE *file,";
487 print " int indent,";
488 print " struct cl_target_option *ptr)";
489 print "{";
491 print " fputs (\"\\n\", file);";
492 for (i = 0; i < n_target_other; i++) {
493 print " if (ptr->x_" var_target_other[i] ")";
494 hwi = host_wide_int[var_target_other[i]]
495 if (hwi == "yes")
496 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
497 else
498 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
499 print " indent, \"\",";
500 print " \"" var_target_other[i] "\",";
501 if (hwi == "yes")
502 print " ptr->x_" var_target_other[i] ");";
503 else
504 print " (unsigned long)ptr->x_" var_target_other[i] ");";
505 print "";
508 for (i = 0; i < n_target_enum; i++) {
509 print " if (ptr->x_" var_target_enum[i] ")";
510 print " fprintf (file, \"%*s%s (%#x)\\n\",";
511 print " indent, \"\",";
512 print " \"" var_target_enum[i] "\",";
513 print " ptr->x_" var_target_enum[i] ");";
514 print "";
517 for (i = 0; i < n_target_int; i++) {
518 print " if (ptr->x_" var_target_int[i] ")";
519 print " fprintf (file, \"%*s%s (%#x)\\n\",";
520 print " indent, \"\",";
521 print " \"" var_target_int[i] "\",";
522 print " ptr->x_" var_target_int[i] ");";
523 print "";
526 for (i = 0; i < n_target_short; i++) {
527 print " if (ptr->x_" var_target_short[i] ")";
528 print " fprintf (file, \"%*s%s (%#x)\\n\",";
529 print " indent, \"\",";
530 print " \"" var_target_short[i] "\",";
531 print " ptr->x_" var_target_short[i] ");";
532 print "";
535 for (i = 0; i < n_target_char; i++) {
536 print " if (ptr->x_" var_target_char[i] ")";
537 print " fprintf (file, \"%*s%s (%#x)\\n\",";
538 print " indent, \"\",";
539 print " \"" var_target_char[i] "\",";
540 print " ptr->x_" var_target_char[i] ");";
541 print "";
544 for (i = 0; i < n_target_string; i++) {
545 print " if (ptr->x_" var_target_string[i] ")";
546 print " fprintf (file, \"%*s%s (%s)\\n\",";
547 print " indent, \"\",";
548 print " \"" var_target_string[i] "\",";
549 print " ptr->x_" var_target_string[i] ");";
550 print "";
553 print "";
554 print " if (targetm.target_option.print)";
555 print " targetm.target_option.print (file, indent, ptr);";
556 print "}";
558 print "";
559 print "/* Print different target option variables from structures provided as arguments. */";
560 print "void";
561 print "cl_target_option_print_diff (FILE *file,";
562 print " int indent ATTRIBUTE_UNUSED,";
563 print " struct cl_target_option *ptr1 ATTRIBUTE_UNUSED,";
564 print " struct cl_target_option *ptr2 ATTRIBUTE_UNUSED)";
565 print "{";
567 print " fputs (\"\\n\", file);";
568 for (i = 0; i < n_target_other; i++) {
569 print " if (ptr1->x_" var_target_other[i] " != ptr2->x_" var_target_other[i] ")";
570 hwi = host_wide_int[var_target_other[i]]
571 if (hwi == "yes")
572 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x/%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
573 else
574 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
575 print " indent, \"\",";
576 print " \"" var_target_other[i] "\",";
577 if (hwi == "yes") {
578 print " ptr1->x_" var_target_other[i] ",";
579 print " ptr2->x_" var_target_other[i] ");";
581 else {
582 print " (unsigned long)ptr1->x_" var_target_other[i] ",";
583 print " (unsigned long)ptr2->x_" var_target_other[i] ");";
585 print "";
588 for (i = 0; i < n_target_enum; i++) {
589 print " if (ptr1->x_" var_target_enum[i] " != ptr2->x_" var_target_enum[i] ")";
590 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
591 print " indent, \"\",";
592 print " \"" var_target_enum[i] "\",";
593 print " ptr1->x_" var_target_enum[i] ",";
594 print " ptr2->x_" var_target_enum[i] ");";
595 print "";
598 for (i = 0; i < n_target_int; i++) {
599 print " if (ptr1->x_" var_target_int[i] " != ptr2->x_" var_target_int[i] ")";
600 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
601 print " indent, \"\",";
602 print " \"" var_target_int[i] "\",";
603 print " ptr1->x_" var_target_int[i] ",";
604 print " ptr2->x_" var_target_int[i] ");";
605 print "";
608 for (i = 0; i < n_target_short; i++) {
609 print " if (ptr1->x_" var_target_short[i] " != ptr2->x_" var_target_short[i] ")";
610 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
611 print " indent, \"\",";
612 print " \"" var_target_short[i] "\",";
613 print " ptr1->x_" var_target_short[i] ",";
614 print " ptr2->x_" var_target_short[i] ");";
615 print "";
618 for (i = 0; i < n_target_char; i++) {
619 print " if (ptr1->x_" var_target_char[i] " != ptr2->x_" var_target_char[i] ")";
620 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
621 print " indent, \"\",";
622 print " \"" var_target_char[i] "\",";
623 print " ptr1->x_" var_target_char[i] ",";
624 print " ptr2->x_" var_target_char[i] ");";
625 print "";
628 for (i = 0; i < n_target_string; i++) {
629 name = var_target_string[i]
630 print " if (ptr1->x_" name " != ptr2->x_" name "";
631 print " && (!ptr1->x_" name" || !ptr2->x_" name
632 print " || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
633 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
634 print " indent, \"\",";
635 print " \"" name "\",";
636 print " ptr1->x_" name " ? ptr1->x_" name " : \"(null)\",";
637 print " ptr2->x_" name " ? ptr1->x_" name " : \"(null)\");";
638 print "";
641 print "}";
643 print "";
644 print "/* Compare two target options */";
645 print "bool";
646 print "cl_target_option_eq (struct cl_target_option const *ptr1 ATTRIBUTE_UNUSED,";
647 print " struct cl_target_option const *ptr2 ATTRIBUTE_UNUSED)";
648 print "{";
649 n_target_val = 0;
650 n_target_str = 0;
651 n_target_array = 0;
653 for (i = 0; i < n_target_save; i++) {
654 var = target_save_decl[i];
655 sub (" *=.*", "", var);
656 name = var;
657 type = var;
658 sub("^.*[ *]", "", name)
659 sub(" *" name "$", "", type)
660 if (target_save_decl[i] ~ "^const char \\*+[_" alnum "]+$")
661 var_target_str[n_target_str++] = name;
662 else {
663 if (target_save_decl[i] ~ " .*\\[.+\\]+$") {
664 size = name;
665 sub("[^\\[]+\\[", "", size);
666 sub("\\]$", "", size);
667 sub("\\[.+", "", name)
668 sub(" [^ ]+$", "", type)
669 var_target_array[n_target_array] = name
670 var_target_array_type[n_target_array] = type
671 var_target_array_size[n_target_array++] = size
673 else {
674 var_target_val_type[n_target_val] = type;
675 var_target_val[n_target_val++] = name;
679 if (have_save) {
680 for (i = 0; i < n_opts; i++) {
681 if (flag_set_p("Save", flags[i])) {
682 name = var_name(flags[i])
683 if(name == "")
684 name = "target_flags";
686 if(name in var_list_seen)
687 continue;
689 var_list_seen[name]++;
690 otype = var_type_struct(flags[i])
691 if (otype ~ "^const char \\**$")
692 var_target_str[n_target_str++] = "x_" name;
693 else {
694 var_target_val_type[n_target_val] = otype;
695 var_target_val[n_target_val++] = "x_" name;
699 } else {
700 var_target_val_type[n_target_val] = "int";
701 var_target_val[n_target_val++] = "x_target_flags";
704 for (i = 0; i < n_target_str; i++) {
705 name = var_target_str[i]
706 print " if (ptr1->" name" != ptr2->" name;
707 print " && (!ptr1->" name" || !ptr2->" name
708 print " || strcmp (ptr1->" name", ptr2->" name ")))";
709 print " return false;";
711 for (i = 0; i < n_target_array; i++) {
712 name = var_target_array[i]
713 size = var_target_array_size[i]
714 type = var_target_array_type[i]
715 print " if (ptr1->" name" != ptr2->" name "";
716 print " || memcmp (ptr1->" name ", ptr2->" name ", " size " * sizeof(" type ")))"
717 print " return false;";
719 for (i = 0; i < n_target_val; i++) {
720 name = var_target_val[i]
721 print " if (ptr1->" name" != ptr2->" name ")";
722 print " return false;";
725 print " return true;";
727 print "}";
729 print "";
730 print "/* Hash target options */";
731 print "hashval_t";
732 print "cl_target_option_hash (struct cl_target_option const *ptr ATTRIBUTE_UNUSED)";
733 print "{";
734 print " inchash::hash hstate;";
735 for (i = 0; i < n_target_str; i++) {
736 name = var_target_str[i]
737 print " if (ptr->" name")";
738 print " hstate.add (ptr->" name", strlen (ptr->" name"));";
739 print " else";
740 print " hstate.add_int (0);";
742 for (i = 0; i < n_target_array; i++) {
743 name= var_target_array[i]
744 size = var_target_array_size[i]
745 type = var_target_array_type[i]
746 print " hstate.add_int (" size ");";
747 print " hstate.add (ptr->" name ", sizeof (" type ") * " size ");";
749 for (i = 0; i < n_target_val; i++) {
750 name = var_target_val[i]
751 print " hstate.add_hwi (ptr->" name");";
753 print " return hstate.end ();";
754 print "}";
756 print "";
757 print "/* Stream out target options */";
758 print "void";
759 print "cl_target_option_stream_out (struct output_block *ob ATTRIBUTE_UNUSED,";
760 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
761 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
762 print "{";
763 for (i = 0; i < n_target_str; i++) {
764 name = var_target_str[i]
765 print " bp_pack_string (ob, bp, ptr->" name", true);";
767 for (i = 0; i < n_target_array; i++) {
768 name = var_target_array[i]
769 size = var_target_array_size[i]
770 print " for (unsigned i = 0; i < " size "; i++)"
771 print " bp_pack_value (bp, ptr->" name "[i], 64);";
773 for (i = 0; i < n_target_val; i++) {
774 name = var_target_val[i]
775 print " bp_pack_value (bp, ptr->" name", 64);";
777 print "}";
779 print "";
780 print "/* Stream in target options */";
781 print "void";
782 print "cl_target_option_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
783 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
784 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
785 print "{";
786 for (i = 0; i < n_target_str; i++) {
787 name = var_target_str[i]
788 print " ptr->" name" = bp_unpack_string (data_in, bp);";
789 print " if (ptr->" name")";
790 print " ptr->" name" = xstrdup (ptr->" name");";
792 for (i = 0; i < n_target_array; i++) {
793 name = var_target_array[i]
794 size = var_target_array_size[i]
795 print " for (int i = " size " - 1; i >= 0; i--)"
796 print " ptr->" name "[i] = (" var_target_array_type[i] ") bp_unpack_value (bp, 64);";
798 for (i = 0; i < n_target_val; i++) {
799 name = var_target_val[i]
800 print " ptr->" name" = (" var_target_val_type[i] ") bp_unpack_value (bp, 64);";
803 print "}";
805 n_opt_val = 4;
806 var_opt_val[0] = "x_optimize"
807 var_opt_val_type[0] = "char "
808 var_opt_hash[0] = 1;
809 var_opt_val[1] = "x_optimize_size"
810 var_opt_val_type[1] = "char "
811 var_opt_hash[1] = 1;
812 var_opt_val[2] = "x_optimize_debug"
813 var_opt_val_type[2] = "char "
814 var_opt_hash[2] = 1;
815 var_opt_val[3] = "x_optimize_fast"
816 var_opt_val_type[3] = "char "
817 var_opt_hash[3] = 1;
818 for (i = 0; i < n_opts; i++) {
819 if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
820 name = var_name(flags[i])
821 if(name == "")
822 continue;
824 if(name in var_opt_list_seen)
825 continue;
827 var_opt_list_seen[name]++;
829 otype = var_type_struct(flags[i])
830 var_opt_val_type[n_opt_val] = otype;
831 var_opt_val[n_opt_val] = "x_" name;
832 var_opt_hash[n_opt_val] = flag_set_p("Optimization", flags[i]);
833 n_opt_val++;
836 print "";
837 print "/* Hash optimization options */";
838 print "hashval_t";
839 print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)";
840 print "{";
841 print " inchash::hash hstate;";
842 for (i = 0; i < n_opt_val; i++) {
843 if (!var_opt_hash[i])
844 continue;
845 name = var_opt_val[i]
846 otype = var_opt_val_type[i];
847 if (otype ~ "^const char \\**$")
849 print " if (ptr->" name")";
850 print " hstate.add (ptr->" name", strlen (ptr->" name"));";
851 print " else";
852 print " hstate.add_int (0);";
854 else
855 print " hstate.add_hwi (ptr->" name");";
857 print " return hstate.end ();";
858 print "}";
860 print "";
861 print "/* Compare two optimization options */";
862 print "bool";
863 print "cl_optimization_option_eq (cl_optimization const *ptr1,";
864 print " cl_optimization const *ptr2)";
865 print "{";
866 for (i = 0; i < n_opt_val; i++) {
867 if (!var_opt_hash[i])
868 continue;
869 name = var_opt_val[i]
870 otype = var_opt_val_type[i];
871 if (otype ~ "^const char \\**$")
873 print " if (ptr1->" name" != ptr2->" name;
874 print " && (!ptr1->" name" || !ptr2->" name
875 print " || strcmp (ptr1->" name", ptr2->" name ")))";
876 print " return false;";
878 else
880 print " if (ptr1->" name" != ptr2->" name ")";
881 print " return false;";
884 print " return true;";
885 print "}";
887 print "";
888 print "/* Stream out optimization options */";
889 print "void";
890 print "cl_optimization_stream_out (struct output_block *ob,";
891 print " struct bitpack_d *bp,";
892 print " struct cl_optimization *ptr)";
893 print "{";
894 for (i = 0; i < n_opt_val; i++) {
895 name = var_opt_val[i]
896 otype = var_opt_val_type[i];
897 if (otype ~ "^const char \\**$")
898 print " bp_pack_string (ob, bp, ptr->" name", true);";
899 else
900 print " bp_pack_value (bp, ptr->" name", 64);";
902 print "}";
904 print "";
905 print "/* Stream in optimization options */";
906 print "void";
907 print "cl_optimization_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
908 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
909 print " struct cl_optimization *ptr ATTRIBUTE_UNUSED)";
910 print "{";
911 for (i = 0; i < n_opt_val; i++) {
912 name = var_opt_val[i]
913 otype = var_opt_val_type[i];
914 if (otype ~ "^const char \\**$")
916 print " ptr->" name" = bp_unpack_string (data_in, bp);";
917 print " if (ptr->" name")";
918 print " ptr->" name" = xstrdup (ptr->" name");";
920 else
921 print " ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_value (bp, 64);";
923 print "}";