* cp-tree.h (treat_lvalue_as_rvalue_p): Declare.
[official-gcc.git] / gcc / optc-save-gen.awk
blob4d602230d89354eeefafcc96bc8b00ba61e1e49b
1 # Copyright (C) 2003-2018 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 = 3;
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_range["optimize"] = "0, 255";
94 var_opt_range["optimize_size"] = "0, 1";
95 var_opt_range["optimize_debug"] = "0, 1";
97 # Sort by size to mimic how the structure is laid out to be friendlier to the
98 # cache.
100 for (i = 0; i < n_opts; i++) {
101 if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
102 name = var_name(flags[i])
103 if(name == "")
104 continue;
106 if(name in var_opt_seen)
107 continue;
109 var_opt_seen[name]++;
110 otype = var_type_struct(flags[i]);
111 if (otype ~ "^((un)?signed +)?int *$")
112 var_opt_int[n_opt_int++] = name;
114 else if (otype ~ "^((un)?signed +)?short *$")
115 var_opt_short[n_opt_short++] = name;
117 else if (otype ~ ("^enum +[_" alnum "]+ *"))
118 var_opt_enum[n_opt_enum++] = name;
120 else if (otype ~ "^((un)?signed +)?char *$") {
121 var_opt_char[n_opt_char++] = name;
122 if (otype ~ "^unsigned +char *$")
123 var_opt_range[name] = "0, 255"
124 else if (otype ~ "^signed +char *$")
125 var_opt_range[name] = "-128, 127"
127 else if (otype ~ "^const char \\**$")
128 var_opt_string[n_opt_string++] = name;
129 else
130 var_opt_other[n_opt_other++] = name;
134 for (i = 0; i < n_opt_char; i++) {
135 name = var_opt_char[i];
136 if (var_opt_range[name] != "")
137 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_opt_range[name] "));";
140 print "";
141 for (i = 0; i < n_opt_other; i++) {
142 print " ptr->x_" var_opt_other[i] " = opts->x_" var_opt_other[i] ";";
145 for (i = 0; i < n_opt_int; i++) {
146 print " ptr->x_" var_opt_int[i] " = opts->x_" var_opt_int[i] ";";
149 for (i = 0; i < n_opt_enum; i++) {
150 print " ptr->x_" var_opt_enum[i] " = opts->x_" var_opt_enum[i] ";";
153 for (i = 0; i < n_opt_short; i++) {
154 print " ptr->x_" var_opt_short[i] " = opts->x_" var_opt_short[i] ";";
157 for (i = 0; i < n_opt_char; i++) {
158 print " ptr->x_" var_opt_char[i] " = opts->x_" var_opt_char[i] ";";
161 for (i = 0; i < n_opt_string; i++) {
162 print " ptr->x_" var_opt_string[i] " = opts->x_" var_opt_string[i] ";";
165 print "}";
167 print "";
168 print "/* Restore optimization options from a structure. */";
169 print "void";
170 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
171 print "{";
173 for (i = 0; i < n_opt_other; i++) {
174 print " opts->x_" var_opt_other[i] " = ptr->x_" var_opt_other[i] ";";
177 for (i = 0; i < n_opt_int; i++) {
178 print " opts->x_" var_opt_int[i] " = ptr->x_" var_opt_int[i] ";";
181 for (i = 0; i < n_opt_enum; i++) {
182 print " opts->x_" var_opt_enum[i] " = ptr->x_" var_opt_enum[i] ";";
185 for (i = 0; i < n_opt_short; i++) {
186 print " opts->x_" var_opt_short[i] " = ptr->x_" var_opt_short[i] ";";
189 for (i = 0; i < n_opt_char; i++) {
190 print " opts->x_" var_opt_char[i] " = ptr->x_" var_opt_char[i] ";";
193 for (i = 0; i < n_opt_string; i++) {
194 print " opts->x_" var_opt_string[i] " = ptr->x_" var_opt_string[i] ";";
197 print " targetm.override_options_after_change ();";
198 print "}";
200 print "";
201 print "/* Print optimization options from a structure. */";
202 print "void";
203 print "cl_optimization_print (FILE *file,";
204 print " int indent_to,";
205 print " struct cl_optimization *ptr)";
206 print "{";
208 print " fputs (\"\\n\", file);";
209 for (i = 0; i < n_opt_other; i++) {
210 print " if (ptr->x_" var_opt_other[i] ")";
211 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
212 print " indent_to, \"\",";
213 print " \"" var_opt_other[i] "\",";
214 print " (unsigned long)ptr->x_" var_opt_other[i] ");";
215 print "";
218 for (i = 0; i < n_opt_int; i++) {
219 print " if (ptr->x_" var_opt_int[i] ")";
220 print " fprintf (file, \"%*s%s (%#x)\\n\",";
221 print " indent_to, \"\",";
222 print " \"" var_opt_int[i] "\",";
223 print " ptr->x_" var_opt_int[i] ");";
224 print "";
227 for (i = 0; i < n_opt_enum; i++) {
228 print " fprintf (file, \"%*s%s (%#x)\\n\",";
229 print " indent_to, \"\",";
230 print " \"" var_opt_enum[i] "\",";
231 print " (int) ptr->x_" var_opt_enum[i] ");";
232 print "";
235 for (i = 0; i < n_opt_short; i++) {
236 print " if (ptr->x_" var_opt_short[i] ")";
237 print " fprintf (file, \"%*s%s (%#x)\\n\",";
238 print " indent_to, \"\",";
239 print " \"" var_opt_short[i] "\",";
240 print " ptr->x_" var_opt_short[i] ");";
241 print "";
244 for (i = 0; i < n_opt_char; i++) {
245 print " if (ptr->x_" var_opt_char[i] ")";
246 print " fprintf (file, \"%*s%s (%#x)\\n\",";
247 print " indent_to, \"\",";
248 print " \"" var_opt_char[i] "\",";
249 print " ptr->x_" var_opt_char[i] ");";
250 print "";
253 for (i = 0; i < n_opt_string; i++) {
254 print " if (ptr->x_" var_opt_char[i] ")";
255 print " fprintf (file, \"%*s%s (%s)\\n\",";
256 print " indent_to, \"\",";
257 print " \"" var_opt_string[i] "\",";
258 print " ptr->x_" var_opt_string[i] ");";
259 print "";
262 print "}";
264 print "";
265 print "/* Print different optimization variables from structures provided as arguments. */";
266 print "void";
267 print "cl_optimization_print_diff (FILE *file,";
268 print " int indent_to,";
269 print " struct cl_optimization *ptr1,";
270 print " struct cl_optimization *ptr2)";
271 print "{";
273 print " fputs (\"\\n\", file);";
274 for (i = 0; i < n_opt_other; i++) {
275 print " if (ptr1->x_" var_opt_other[i] " != ptr2->x_" var_opt_other[i] ")";
276 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
277 print " indent_to, \"\",";
278 print " \"" var_opt_other[i] "\",";
279 print " (unsigned long)ptr1->x_" var_opt_other[i] ",";
280 print " (unsigned long)ptr2->x_" var_opt_other[i] ");";
281 print "";
284 for (i = 0; i < n_opt_int; i++) {
285 print " if (ptr1->x_" var_opt_int[i] " != ptr2->x_" var_opt_int[i] ")";
286 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
287 print " indent_to, \"\",";
288 print " \"" var_opt_int[i] "\",";
289 print " ptr1->x_" var_opt_int[i] ",";
290 print " ptr2->x_" var_opt_int[i] ");";
291 print "";
294 for (i = 0; i < n_opt_enum; i++) {
295 print " if (ptr1->x_" var_opt_enum[i] " != ptr2->x_" var_opt_enum[i] ")";
296 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
297 print " indent_to, \"\",";
298 print " \"" var_opt_enum[i] "\",";
299 print " (int) ptr1->x_" var_opt_enum[i] ",";
300 print " (int) ptr2->x_" var_opt_enum[i] ");";
301 print "";
304 for (i = 0; i < n_opt_short; i++) {
305 print " if (ptr1->x_" var_opt_short[i] " != ptr2->x_" var_opt_short[i] ")";
306 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
307 print " indent_to, \"\",";
308 print " \"" var_opt_short[i] "\",";
309 print " ptr1->x_" var_opt_short[i] ",";
310 print " ptr2->x_" var_opt_short[i] ");";
311 print "";
314 for (i = 0; i < n_opt_char; i++) {
315 print " if (ptr1->x_" var_opt_char[i] " != ptr2->x_" var_opt_char[i] ")";
316 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
317 print " indent_to, \"\",";
318 print " \"" var_opt_char[i] "\",";
319 print " ptr1->x_" var_opt_char[i] ",";
320 print " ptr2->x_" var_opt_char[i] ");";
321 print "";
324 for (i = 0; i < n_opt_string; i++) {
325 name = var_opt_string[i]
326 print " if (ptr1->x_" name " != ptr2->x_" name "";
327 print " || (!ptr1->x_" name" || !ptr2->x_" name
328 print " || strcmp (ptr1->x_" name", ptr2->x_" name ")))";
329 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
330 print " indent_to, \"\",";
331 print " \"" name "\",";
332 print " ptr1->x_" name ",";
333 print " ptr2->x_" name ");";
334 print "";
337 print "}";
340 print "";
341 print "/* Save selected option variables into a structure. */"
342 print "void";
343 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
344 print "{";
346 n_target_char = 0;
347 n_target_short = 0;
348 n_target_int = 0;
349 n_target_enum = 0;
350 n_target_other = 0;
352 if (have_save) {
353 for (i = 0; i < n_opts; i++) {
354 if (flag_set_p("Save", flags[i])) {
355 name = var_name(flags[i])
356 if(name == "")
357 name = "target_flags";
359 if(name in var_save_seen)
360 continue;
362 var_save_seen[name]++;
363 otype = var_type_struct(flags[i])
364 if (otype ~ "^((un)?signed +)?int *$")
365 var_target_int[n_target_int++] = name;
367 else if (otype ~ "^((un)?signed +)?short *$")
368 var_target_short[n_target_short++] = name;
370 else if (otype ~ ("^enum +[_" alnum "]+ *$"))
371 var_target_enum[n_target_enum++] = name;
373 else if (otype ~ "^((un)?signed +)?char *$") {
374 var_target_char[n_target_char++] = name;
375 if (otype ~ "^unsigned +char *$")
376 var_target_range[name] = "0, 255"
377 else if (otype ~ "^signed +char *$")
378 var_target_range[name] = "-128, 127"
379 if (otype == var_type(flags[i]))
380 var_target_range[name] = ""
382 else
383 var_target_other[n_target_other++] = name;
386 } else {
387 var_target_int[n_target_int++] = "target_flags";
390 have_assert = 0;
391 for (i = 0; i < n_target_char; i++) {
392 name = var_target_char[i];
393 if (var_target_range[name] != "") {
394 have_assert = 1;
395 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_target_range[name] "));";
399 if (have_assert)
400 print "";
402 print " if (targetm.target_option.save)";
403 print " targetm.target_option.save (ptr, opts);";
404 print "";
406 for (i = 0; i < n_extra_target_vars; i++) {
407 print " ptr->x_" extra_target_vars[i] " = opts->x_" extra_target_vars[i] ";";
410 for (i = 0; i < n_target_other; i++) {
411 print " ptr->x_" var_target_other[i] " = opts->x_" var_target_other[i] ";";
414 for (i = 0; i < n_target_enum; i++) {
415 print " ptr->x_" var_target_enum[i] " = opts->x_" var_target_enum[i] ";";
418 for (i = 0; i < n_target_int; i++) {
419 print " ptr->x_" var_target_int[i] " = opts->x_" var_target_int[i] ";";
422 for (i = 0; i < n_target_short; i++) {
423 print " ptr->x_" var_target_short[i] " = opts->x_" var_target_short[i] ";";
426 for (i = 0; i < n_target_char; i++) {
427 print " ptr->x_" var_target_char[i] " = opts->x_" var_target_char[i] ";";
430 print "}";
432 print "";
433 print "/* Restore selected current options from a structure. */";
434 print "void";
435 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
436 print "{";
438 for (i = 0; i < n_extra_target_vars; i++) {
439 print " opts->x_" extra_target_vars[i] " = ptr->x_" extra_target_vars[i] ";";
442 for (i = 0; i < n_target_other; i++) {
443 print " opts->x_" var_target_other[i] " = ptr->x_" var_target_other[i] ";";
446 for (i = 0; i < n_target_enum; i++) {
447 print " opts->x_" var_target_enum[i] " = ptr->x_" var_target_enum[i] ";";
450 for (i = 0; i < n_target_int; i++) {
451 print " opts->x_" var_target_int[i] " = ptr->x_" var_target_int[i] ";";
454 for (i = 0; i < n_target_short; i++) {
455 print " opts->x_" var_target_short[i] " = ptr->x_" var_target_short[i] ";";
458 for (i = 0; i < n_target_char; i++) {
459 print " opts->x_" var_target_char[i] " = ptr->x_" var_target_char[i] ";";
462 # This must occur after the normal variables in case the code depends on those
463 # variables.
464 print "";
465 print " if (targetm.target_option.restore)";
466 print " targetm.target_option.restore (opts, ptr);";
468 print "}";
470 print "";
471 print "/* Print optimization options from a structure. */";
472 print "void";
473 print "cl_target_option_print (FILE *file,";
474 print " int indent,";
475 print " struct cl_target_option *ptr)";
476 print "{";
478 print " fputs (\"\\n\", file);";
479 for (i = 0; i < n_target_other; i++) {
480 print " if (ptr->x_" var_target_other[i] ")";
481 hwi = host_wide_int[var_target_other[i]]
482 if (hwi == "yes")
483 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
484 else
485 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
486 print " indent, \"\",";
487 print " \"" var_target_other[i] "\",";
488 if (hwi == "yes")
489 print " ptr->x_" var_target_other[i] ");";
490 else
491 print " (unsigned long)ptr->x_" var_target_other[i] ");";
492 print "";
495 for (i = 0; i < n_target_enum; i++) {
496 print " if (ptr->x_" var_target_enum[i] ")";
497 print " fprintf (file, \"%*s%s (%#x)\\n\",";
498 print " indent, \"\",";
499 print " \"" var_target_enum[i] "\",";
500 print " ptr->x_" var_target_enum[i] ");";
501 print "";
504 for (i = 0; i < n_target_int; i++) {
505 print " if (ptr->x_" var_target_int[i] ")";
506 print " fprintf (file, \"%*s%s (%#x)\\n\",";
507 print " indent, \"\",";
508 print " \"" var_target_int[i] "\",";
509 print " ptr->x_" var_target_int[i] ");";
510 print "";
513 for (i = 0; i < n_target_short; i++) {
514 print " if (ptr->x_" var_target_short[i] ")";
515 print " fprintf (file, \"%*s%s (%#x)\\n\",";
516 print " indent, \"\",";
517 print " \"" var_target_short[i] "\",";
518 print " ptr->x_" var_target_short[i] ");";
519 print "";
522 for (i = 0; i < n_target_char; i++) {
523 print " if (ptr->x_" var_target_char[i] ")";
524 print " fprintf (file, \"%*s%s (%#x)\\n\",";
525 print " indent, \"\",";
526 print " \"" var_target_char[i] "\",";
527 print " ptr->x_" var_target_char[i] ");";
528 print "";
531 print "";
532 print " if (targetm.target_option.print)";
533 print " targetm.target_option.print (file, indent, ptr);";
534 print "}";
536 print "";
537 print "/* Print different target option variables from structures provided as arguments. */";
538 print "void";
539 print "cl_target_option_print_diff (FILE *file,";
540 print " int indent ATTRIBUTE_UNUSED,";
541 print " struct cl_target_option *ptr1 ATTRIBUTE_UNUSED,";
542 print " struct cl_target_option *ptr2 ATTRIBUTE_UNUSED)";
543 print "{";
545 print " fputs (\"\\n\", file);";
546 for (i = 0; i < n_target_other; i++) {
547 print " if (ptr1->x_" var_target_other[i] " != ptr2->x_" var_target_other[i] ")";
548 hwi = host_wide_int[var_target_other[i]]
549 if (hwi == "yes")
550 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x/%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
551 else
552 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
553 print " indent, \"\",";
554 print " \"" var_target_other[i] "\",";
555 if (hwi == "yes") {
556 print " ptr1->x_" var_target_other[i] ",";
557 print " ptr2->x_" var_target_other[i] ");";
559 else {
560 print " (unsigned long)ptr1->x_" var_target_other[i] ",";
561 print " (unsigned long)ptr2->x_" var_target_other[i] ");";
563 print "";
566 for (i = 0; i < n_target_enum; i++) {
567 print " if (ptr1->x_" var_target_enum[i] " != ptr2->x_" var_target_enum[i] ")";
568 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
569 print " indent, \"\",";
570 print " \"" var_target_enum[i] "\",";
571 print " ptr1->x_" var_target_enum[i] ",";
572 print " ptr2->x_" var_target_enum[i] ");";
573 print "";
576 for (i = 0; i < n_target_int; i++) {
577 print " if (ptr1->x_" var_target_int[i] " != ptr2->x_" var_target_int[i] ")";
578 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
579 print " indent, \"\",";
580 print " \"" var_target_int[i] "\",";
581 print " ptr1->x_" var_target_int[i] ",";
582 print " ptr2->x_" var_target_int[i] ");";
583 print "";
586 for (i = 0; i < n_target_short; i++) {
587 print " if (ptr1->x_" var_target_short[i] " != ptr2->x_" var_target_short[i] ")";
588 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
589 print " indent, \"\",";
590 print " \"" var_target_short[i] "\",";
591 print " ptr1->x_" var_target_short[i] ",";
592 print " ptr2->x_" var_target_short[i] ");";
593 print "";
596 for (i = 0; i < n_target_char; i++) {
597 print " if (ptr1->x_" var_target_char[i] " != ptr2->x_" var_target_char[i] ")";
598 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
599 print " indent, \"\",";
600 print " \"" var_target_char[i] "\",";
601 print " ptr1->x_" var_target_char[i] ",";
602 print " ptr2->x_" var_target_char[i] ");";
603 print "";
606 print "}";
608 print "";
609 print "/* Compare two target options */";
610 print "bool";
611 print "cl_target_option_eq (struct cl_target_option const *ptr1 ATTRIBUTE_UNUSED,";
612 print " struct cl_target_option const *ptr2 ATTRIBUTE_UNUSED)";
613 print "{";
614 n_target_val = 0;
615 n_target_str = 0;
616 n_target_array = 0;
618 for (i = 0; i < n_target_save; i++) {
619 var = target_save_decl[i];
620 sub (" *=.*", "", var);
621 name = var;
622 type = var;
623 sub("^.*[ *]", "", name)
624 sub(" *" name "$", "", type)
625 if (target_save_decl[i] ~ "^const char \\*+[_" alnum "]+$")
626 var_target_str[n_target_str++] = name;
627 else {
628 if (target_save_decl[i] ~ " .*\\[.+\\]+$") {
629 size = name;
630 sub("[^\\[]+\\[", "", size);
631 sub("\\]$", "", size);
632 sub("\\[.+", "", name)
633 sub(" [^ ]+$", "", type)
634 var_target_array[n_target_array] = name
635 var_target_array_type[n_target_array] = type
636 var_target_array_size[n_target_array++] = size
638 else {
639 var_target_val_type[n_target_val] = type;
640 var_target_val[n_target_val++] = name;
644 if (have_save) {
645 for (i = 0; i < n_opts; i++) {
646 if (flag_set_p("Save", flags[i])) {
647 name = var_name(flags[i])
648 if(name == "")
649 name = "target_flags";
651 if(name in var_list_seen)
652 continue;
654 var_list_seen[name]++;
655 otype = var_type_struct(flags[i])
656 if (otype ~ "^const char \\**$")
657 var_target_str[n_target_str++] = "x_" name;
658 else {
659 var_target_val_type[n_target_val] = otype;
660 var_target_val[n_target_val++] = "x_" name;
664 } else {
665 var_target_val_type[n_target_val] = "int";
666 var_target_val[n_target_val++] = "x_target_flags";
669 for (i = 0; i < n_target_str; i++) {
670 name = var_target_str[i]
671 print " if (ptr1->" name" != ptr2->" name;
672 print " && (!ptr1->" name" || !ptr2->" name
673 print " || strcmp (ptr1->" name", ptr2->" name ")))";
674 print " return false;";
676 for (i = 0; i < n_target_array; i++) {
677 name = var_target_array[i]
678 size = var_target_array_size[i]
679 type = var_target_array_type[i]
680 print " if (ptr1->" name" != ptr2->" name "";
681 print " || memcmp (ptr1->" name ", ptr2->" name ", " size " * sizeof(" type ")))"
682 print " return false;";
684 for (i = 0; i < n_target_val; i++) {
685 name = var_target_val[i]
686 print " if (ptr1->" name" != ptr2->" name ")";
687 print " return false;";
690 print " return true;";
692 print "}";
694 print "";
695 print "/* Hash target options */";
696 print "hashval_t";
697 print "cl_target_option_hash (struct cl_target_option const *ptr ATTRIBUTE_UNUSED)";
698 print "{";
699 print " inchash::hash hstate;";
700 for (i = 0; i < n_target_str; i++) {
701 name = var_target_str[i]
702 print " if (ptr->" name")";
703 print " hstate.add (ptr->" name", strlen (ptr->" name"));";
704 print " else";
705 print " hstate.add_int (0);";
707 for (i = 0; i < n_target_array; i++) {
708 name= var_target_array[i]
709 size = var_target_array_size[i]
710 type = var_target_array_type[i]
711 print " hstate.add_int (" size ");";
712 print " hstate.add (ptr->" name ", sizeof (" type ") * " size ");";
714 for (i = 0; i < n_target_val; i++) {
715 name = var_target_val[i]
716 print " hstate.add_hwi (ptr->" name");";
718 print " return hstate.end ();";
719 print "}";
721 print "";
722 print "/* Stream out target options */";
723 print "void";
724 print "cl_target_option_stream_out (struct output_block *ob ATTRIBUTE_UNUSED,";
725 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
726 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
727 print "{";
728 for (i = 0; i < n_target_str; i++) {
729 name = var_target_str[i]
730 print " bp_pack_string (ob, bp, ptr->" name", true);";
732 for (i = 0; i < n_target_array; i++) {
733 name = var_target_array[i]
734 size = var_target_array_size[i]
735 print " for (unsigned i = 0; i < " size "; i++)"
736 print " bp_pack_value (bp, ptr->" name "[i], 64);";
738 for (i = 0; i < n_target_val; i++) {
739 name = var_target_val[i]
740 print " bp_pack_value (bp, ptr->" name", 64);";
742 print "}";
744 print "";
745 print "/* Stream in target options */";
746 print "void";
747 print "cl_target_option_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
748 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
749 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
750 print "{";
751 for (i = 0; i < n_target_str; i++) {
752 name = var_target_str[i]
753 print " ptr->" name" = bp_unpack_string (data_in, bp);";
754 print " if (ptr->" name")";
755 print " ptr->" name" = xstrdup (ptr->" name");";
757 for (i = 0; i < n_target_array; i++) {
758 name = var_target_array[i]
759 size = var_target_array_size[i]
760 print " for (int i = " size " - 1; i >= 0; i--)"
761 print " ptr->" name "[i] = (" var_target_array_type[i] ") bp_unpack_value (bp, 64);";
763 for (i = 0; i < n_target_val; i++) {
764 name = var_target_val[i]
765 print " ptr->" name" = (" var_target_val_type[i] ") bp_unpack_value (bp, 64);";
768 print "}";
770 n_opt_val = 3;
771 var_opt_val[0] = "x_optimize"
772 var_opt_val_type[0] = "char "
773 var_opt_val[1] = "x_optimize_size"
774 var_opt_val[2] = "x_optimize_debug"
775 var_opt_val_type[1] = "char "
776 var_opt_val_type[2] = "char "
777 for (i = 0; i < n_opts; i++) {
778 if (flag_set_p("(Optimization|PerFunction)", flags[i])) {
779 name = var_name(flags[i])
780 if(name == "")
781 continue;
783 if(name in var_opt_list_seen)
784 continue;
786 var_opt_list_seen[name]++;
788 otype = var_type_struct(flags[i])
789 var_opt_val_type[n_opt_val] = otype;
790 var_opt_val[n_opt_val++] = "x_" name;
791 var_opt_hash[n_opt_val] = flag_set_p("Optimization", flags[i]);
794 print "";
795 print "/* Hash optimization options */";
796 print "hashval_t";
797 print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)";
798 print "{";
799 print " inchash::hash hstate;";
800 for (i = 0; i < n_opt_val; i++) {
801 if (!var_opt_hash[i])
802 continue;
803 name = var_opt_val[i]
804 otype = var_opt_val_type[i];
805 if (otype ~ "^const char \\**$")
807 print " if (ptr->" name")";
808 print " hstate.add (ptr->" name", strlen (ptr->" name"));";
809 print " else";
810 print " hstate.add_int (0);";
812 else
813 print " hstate.add_hwi (ptr->" name");";
815 print " return hstate.end ();";
816 print "}";
818 print "";
819 print "/* Compare two optimization options */";
820 print "bool";
821 print "cl_optimization_option_eq (cl_optimization const *ptr1,";
822 print " cl_optimization const *ptr2)";
823 print "{";
824 for (i = 0; i < n_opt_val; i++) {
825 if (!var_opt_hash[i])
826 continue;
827 name = var_opt_val[i]
828 otype = var_opt_val_type[i];
829 if (otype ~ "^const char \\**$")
831 print " if (ptr1->" name" != ptr2->" name;
832 print " && (!ptr1->" name" || !ptr2->" name
833 print " || strcmp (ptr1->" name", ptr2->" name ")))";
834 print " return false;";
836 else
838 print " if (ptr1->" name" != ptr2->" name ")";
839 print " return false;";
842 print " return true;";
843 print "}";
845 print "";
846 print "/* Stream out optimization options */";
847 print "void";
848 print "cl_optimization_stream_out (struct output_block *ob,";
849 print " struct bitpack_d *bp,";
850 print " struct cl_optimization *ptr)";
851 print "{";
852 for (i = 0; i < n_opt_val; i++) {
853 name = var_opt_val[i]
854 otype = var_opt_val_type[i];
855 if (otype ~ "^const char \\**$")
856 print " bp_pack_string (ob, bp, ptr->" name", true);";
857 else
858 print " bp_pack_value (bp, ptr->" name", 64);";
860 print "}";
862 print "";
863 print "/* Stream in optimization options */";
864 print "void";
865 print "cl_optimization_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
866 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
867 print " struct cl_optimization *ptr ATTRIBUTE_UNUSED)";
868 print "{";
869 for (i = 0; i < n_opt_val; i++) {
870 name = var_opt_val[i]
871 otype = var_opt_val_type[i];
872 if (otype ~ "^const char \\**$")
874 print " ptr->" name" = bp_unpack_string (data_in, bp);";
875 print " if (ptr->" name")";
876 print " ptr->" name" = xstrdup (ptr->" name");";
878 else
879 print " ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_value (bp, 64);";
881 print "}";