2016-10-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / optc-save-gen.awk
blob8ce424813b55a164eb3bd54445d8fa8c73bb5ee0
1 # Copyright (C) 2003-2016 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 "machmode.h" quote
45 print "#include " quote "vec.h" quote
46 print "#include " quote "double-int.h" quote
47 print "#include " quote "input.h" quote
48 print "#include " quote "alias.h" quote
49 print "#include " quote "symtab.h" quote
50 print "#include " quote "wide-int.h" quote
51 print "#include " quote "inchash.h" quote
52 print "#include " quote "tree.h" quote
53 print "#include " quote "fold-const.h" quote
54 print "#include " quote "tree-ssa-alias.h" quote
55 print "#include " quote "is-a.h" quote
56 print "#include " quote "predict.h" quote
57 print "#include " quote "function.h" quote
58 print "#include " quote "basic-block.h" quote
59 print "#include " quote "gimple-expr.h" quote
60 print "#include " quote "gimple.h" quote
61 print "#include " quote "data-streamer.h" quote
62 print "#include " quote "ipa-ref.h" quote
63 print "#include " quote "cgraph.h" quote
64 print ""
66 if (n_extra_c_includes > 0) {
67 for (i = 0; i < n_extra_c_includes; i++) {
68 print "#include " quote extra_c_includes[i] quote
70 print ""
73 have_save = 0;
74 if (n_extra_target_vars)
75 have_save = 1
77 for (i = 0; i < n_opts; i++) {
78 if (flag_set_p("Save", flags[i]))
79 have_save = 1;
82 print "/* Save optimization variables into a structure. */"
83 print "void";
84 print "cl_optimization_save (struct cl_optimization *ptr, struct gcc_options *opts)";
85 print "{";
87 n_opt_char = 3;
88 n_opt_short = 0;
89 n_opt_int = 0;
90 n_opt_enum = 0;
91 n_opt_other = 0;
92 var_opt_char[0] = "optimize";
93 var_opt_char[1] = "optimize_size";
94 var_opt_char[2] = "optimize_debug";
95 var_opt_range["optimize"] = "0, 255";
96 var_opt_range["optimize_size"] = "0, 1";
97 var_opt_range["optimize_debug"] = "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", 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
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 print "}";
163 print "";
164 print "/* Restore optimization options from a structure. */";
165 print "void";
166 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
167 print "{";
169 for (i = 0; i < n_opt_other; i++) {
170 print " opts->x_" var_opt_other[i] " = ptr->x_" var_opt_other[i] ";";
173 for (i = 0; i < n_opt_int; i++) {
174 print " opts->x_" var_opt_int[i] " = ptr->x_" var_opt_int[i] ";";
177 for (i = 0; i < n_opt_enum; i++) {
178 print " opts->x_" var_opt_enum[i] " = ptr->x_" var_opt_enum[i] ";";
181 for (i = 0; i < n_opt_short; i++) {
182 print " opts->x_" var_opt_short[i] " = ptr->x_" var_opt_short[i] ";";
185 for (i = 0; i < n_opt_char; i++) {
186 print " opts->x_" var_opt_char[i] " = ptr->x_" var_opt_char[i] ";";
189 print " targetm.override_options_after_change ();";
190 print "}";
192 print "";
193 print "/* Print optimization options from a structure. */";
194 print "void";
195 print "cl_optimization_print (FILE *file,";
196 print " int indent_to,";
197 print " struct cl_optimization *ptr)";
198 print "{";
200 print " fputs (\"\\n\", file);";
201 for (i = 0; i < n_opt_other; i++) {
202 print " if (ptr->x_" var_opt_other[i] ")";
203 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
204 print " indent_to, \"\",";
205 print " \"" var_opt_other[i] "\",";
206 print " (unsigned long)ptr->x_" var_opt_other[i] ");";
207 print "";
210 for (i = 0; i < n_opt_int; i++) {
211 print " if (ptr->x_" var_opt_int[i] ")";
212 print " fprintf (file, \"%*s%s (%#x)\\n\",";
213 print " indent_to, \"\",";
214 print " \"" var_opt_int[i] "\",";
215 print " ptr->x_" var_opt_int[i] ");";
216 print "";
219 for (i = 0; i < n_opt_enum; i++) {
220 print " fprintf (file, \"%*s%s (%#x)\\n\",";
221 print " indent_to, \"\",";
222 print " \"" var_opt_enum[i] "\",";
223 print " (int) ptr->x_" var_opt_enum[i] ");";
224 print "";
227 for (i = 0; i < n_opt_short; i++) {
228 print " if (ptr->x_" var_opt_short[i] ")";
229 print " fprintf (file, \"%*s%s (%#x)\\n\",";
230 print " indent_to, \"\",";
231 print " \"" var_opt_short[i] "\",";
232 print " ptr->x_" var_opt_short[i] ");";
233 print "";
236 for (i = 0; i < n_opt_char; i++) {
237 print " if (ptr->x_" var_opt_char[i] ")";
238 print " fprintf (file, \"%*s%s (%#x)\\n\",";
239 print " indent_to, \"\",";
240 print " \"" var_opt_char[i] "\",";
241 print " ptr->x_" var_opt_char[i] ");";
242 print "";
245 print "}";
247 print "";
248 print "/* Print different optimization variables from structures provided as arguments. */";
249 print "void";
250 print "cl_optimization_print_diff (FILE *file,";
251 print " int indent_to,";
252 print " struct cl_optimization *ptr1,";
253 print " struct cl_optimization *ptr2)";
254 print "{";
256 print " fputs (\"\\n\", file);";
257 for (i = 0; i < n_opt_other; i++) {
258 print " if (ptr1->x_" var_opt_other[i] " != ptr2->x_" var_opt_other[i] ")";
259 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
260 print " indent_to, \"\",";
261 print " \"" var_opt_other[i] "\",";
262 print " (unsigned long)ptr1->x_" var_opt_other[i] ",";
263 print " (unsigned long)ptr2->x_" var_opt_other[i] ");";
264 print "";
267 for (i = 0; i < n_opt_int; i++) {
268 print " if (ptr1->x_" var_opt_int[i] " != ptr2->x_" var_opt_int[i] ")";
269 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
270 print " indent_to, \"\",";
271 print " \"" var_opt_int[i] "\",";
272 print " ptr1->x_" var_opt_int[i] ",";
273 print " ptr2->x_" var_opt_int[i] ");";
274 print "";
277 for (i = 0; i < n_opt_enum; i++) {
278 print " if (ptr1->x_" var_opt_enum[i] " != ptr2->x_" var_opt_enum[i] ")";
279 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
280 print " indent_to, \"\",";
281 print " \"" var_opt_enum[i] "\",";
282 print " (int) ptr1->x_" var_opt_enum[i] ",";
283 print " (int) ptr2->x_" var_opt_enum[i] ");";
284 print "";
287 for (i = 0; i < n_opt_short; i++) {
288 print " if (ptr1->x_" var_opt_short[i] " != ptr2->x_" var_opt_short[i] ")";
289 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
290 print " indent_to, \"\",";
291 print " \"" var_opt_short[i] "\",";
292 print " ptr1->x_" var_opt_short[i] ",";
293 print " ptr2->x_" var_opt_short[i] ");";
294 print "";
297 for (i = 0; i < n_opt_char; i++) {
298 print " if (ptr1->x_" var_opt_char[i] " != ptr2->x_" var_opt_char[i] ")";
299 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
300 print " indent_to, \"\",";
301 print " \"" var_opt_char[i] "\",";
302 print " ptr1->x_" var_opt_char[i] ",";
303 print " ptr2->x_" var_opt_char[i] ");";
304 print "";
307 print "}";
310 print "";
311 print "/* Save selected option variables into a structure. */"
312 print "void";
313 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
314 print "{";
316 n_target_char = 0;
317 n_target_short = 0;
318 n_target_int = 0;
319 n_target_enum = 0;
320 n_target_other = 0;
322 if (have_save) {
323 for (i = 0; i < n_opts; i++) {
324 if (flag_set_p("Save", flags[i])) {
325 name = var_name(flags[i])
326 if(name == "")
327 name = "target_flags";
329 if(name in var_save_seen)
330 continue;
332 var_save_seen[name]++;
333 otype = var_type_struct(flags[i])
334 if (otype ~ "^((un)?signed +)?int *$")
335 var_target_int[n_target_int++] = name;
337 else if (otype ~ "^((un)?signed +)?short *$")
338 var_target_short[n_target_short++] = name;
340 else if (otype ~ ("^enum +[_" alnum "]+ *$"))
341 var_target_enum[n_target_enum++] = name;
343 else if (otype ~ "^((un)?signed +)?char *$") {
344 var_target_char[n_target_char++] = name;
345 if (otype ~ "^unsigned +char *$")
346 var_target_range[name] = "0, 255"
347 else if (otype ~ "^signed +char *$")
348 var_target_range[name] = "-128, 127"
349 if (otype == var_type(flags[i]))
350 var_target_range[name] = ""
352 else
353 var_target_other[n_target_other++] = name;
356 } else {
357 var_target_int[n_target_int++] = "target_flags";
360 have_assert = 0;
361 for (i = 0; i < n_target_char; i++) {
362 name = var_target_char[i];
363 if (var_target_range[name] != "") {
364 have_assert = 1;
365 print " gcc_assert (IN_RANGE (opts->x_" name ", " var_target_range[name] "));";
369 if (have_assert)
370 print "";
372 print " if (targetm.target_option.save)";
373 print " targetm.target_option.save (ptr, opts);";
374 print "";
376 for (i = 0; i < n_extra_target_vars; i++) {
377 print " ptr->x_" extra_target_vars[i] " = opts->x_" extra_target_vars[i] ";";
380 for (i = 0; i < n_target_other; i++) {
381 print " ptr->x_" var_target_other[i] " = opts->x_" var_target_other[i] ";";
384 for (i = 0; i < n_target_enum; i++) {
385 print " ptr->x_" var_target_enum[i] " = opts->x_" var_target_enum[i] ";";
388 for (i = 0; i < n_target_int; i++) {
389 print " ptr->x_" var_target_int[i] " = opts->x_" var_target_int[i] ";";
392 for (i = 0; i < n_target_short; i++) {
393 print " ptr->x_" var_target_short[i] " = opts->x_" var_target_short[i] ";";
396 for (i = 0; i < n_target_char; i++) {
397 print " ptr->x_" var_target_char[i] " = opts->x_" var_target_char[i] ";";
400 print "}";
402 print "";
403 print "/* Restore selected current options from a structure. */";
404 print "void";
405 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
406 print "{";
408 for (i = 0; i < n_extra_target_vars; i++) {
409 print " opts->x_" extra_target_vars[i] " = ptr->x_" extra_target_vars[i] ";";
412 for (i = 0; i < n_target_other; i++) {
413 print " opts->x_" var_target_other[i] " = ptr->x_" var_target_other[i] ";";
416 for (i = 0; i < n_target_enum; i++) {
417 print " opts->x_" var_target_enum[i] " = ptr->x_" var_target_enum[i] ";";
420 for (i = 0; i < n_target_int; i++) {
421 print " opts->x_" var_target_int[i] " = ptr->x_" var_target_int[i] ";";
424 for (i = 0; i < n_target_short; i++) {
425 print " opts->x_" var_target_short[i] " = ptr->x_" var_target_short[i] ";";
428 for (i = 0; i < n_target_char; i++) {
429 print " opts->x_" var_target_char[i] " = ptr->x_" var_target_char[i] ";";
432 # This must occur after the normal variables in case the code depends on those
433 # variables.
434 print "";
435 print " if (targetm.target_option.restore)";
436 print " targetm.target_option.restore (opts, ptr);";
438 print "}";
440 print "";
441 print "/* Print optimization options from a structure. */";
442 print "void";
443 print "cl_target_option_print (FILE *file,";
444 print " int indent,";
445 print " struct cl_target_option *ptr)";
446 print "{";
448 print " fputs (\"\\n\", file);";
449 for (i = 0; i < n_target_other; i++) {
450 print " if (ptr->x_" var_target_other[i] ")";
451 if (host_wide_int[var_target_other[i]] == "yes")
452 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
453 else
454 print " fprintf (file, \"%*s%s (%#x)\\n\",";
455 print " indent, \"\",";
456 print " \"" var_target_other[i] "\",";
457 if (host_wide_int[var_target_other[i]] == "yes")
458 print " ptr->x_" var_target_other[i] ");";
459 else
460 print " (unsigned long)ptr->x_" var_target_other[i] ");";
461 print "";
464 for (i = 0; i < n_target_enum; i++) {
465 print " if (ptr->x_" var_target_enum[i] ")";
466 print " fprintf (file, \"%*s%s (%#x)\\n\",";
467 print " indent, \"\",";
468 print " \"" var_target_enum[i] "\",";
469 print " ptr->x_" var_target_enum[i] ");";
470 print "";
473 for (i = 0; i < n_target_int; i++) {
474 print " if (ptr->x_" var_target_int[i] ")";
475 print " fprintf (file, \"%*s%s (%#x)\\n\",";
476 print " indent, \"\",";
477 print " \"" var_target_int[i] "\",";
478 print " ptr->x_" var_target_int[i] ");";
479 print "";
482 for (i = 0; i < n_target_short; i++) {
483 print " if (ptr->x_" var_target_short[i] ")";
484 print " fprintf (file, \"%*s%s (%#x)\\n\",";
485 print " indent, \"\",";
486 print " \"" var_target_short[i] "\",";
487 print " ptr->x_" var_target_short[i] ");";
488 print "";
491 for (i = 0; i < n_target_char; i++) {
492 print " if (ptr->x_" var_target_char[i] ")";
493 print " fprintf (file, \"%*s%s (%#x)\\n\",";
494 print " indent, \"\",";
495 print " \"" var_target_char[i] "\",";
496 print " ptr->x_" var_target_char[i] ");";
497 print "";
500 print "";
501 print " if (targetm.target_option.print)";
502 print " targetm.target_option.print (file, indent, ptr);";
503 print "}";
505 print "";
506 print "/* Print different target option variables from structures provided as arguments. */";
507 print "void";
508 print "cl_target_option_print_diff (FILE *file,";
509 print " int indent ATTRIBUTE_UNUSED,";
510 print " struct cl_target_option *ptr1 ATTRIBUTE_UNUSED,";
511 print " struct cl_target_option *ptr2 ATTRIBUTE_UNUSED)";
512 print "{";
514 print " fputs (\"\\n\", file);";
515 for (i = 0; i < n_target_other; i++) {
516 print " if (ptr1->x_" var_target_other[i] " != ptr2->x_" var_target_other[i] ")";
517 if (host_wide_int[var_target_other[i]] == "yes")
518 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x/%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
519 else
520 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
521 print " indent, \"\",";
522 print " \"" var_target_other[i] "\",";
523 if (host_wide_int[var_target_other[i]] == "yes") {
524 print " ptr1->x_" var_target_other[i] ",";
525 print " ptr2->x_" var_target_other[i] ");";
527 else {
528 print " (unsigned long)ptr1->x_" var_target_other[i] ",";
529 print " (unsigned long)ptr2->x_" var_target_other[i] ");";
531 print "";
534 for (i = 0; i < n_target_enum; i++) {
535 print " if (ptr1->x_" var_target_enum[i] " != ptr2->x_" var_target_enum[i] ")";
536 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
537 print " indent, \"\",";
538 print " \"" var_target_enum[i] "\",";
539 print " ptr1->x_" var_target_enum[i] ",";
540 print " ptr2->x_" var_target_enum[i] ");";
541 print "";
544 for (i = 0; i < n_target_int; i++) {
545 print " if (ptr1->x_" var_target_int[i] " != ptr2->x_" var_target_int[i] ")";
546 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
547 print " indent, \"\",";
548 print " \"" var_target_int[i] "\",";
549 print " ptr1->x_" var_target_int[i] ",";
550 print " ptr2->x_" var_target_int[i] ");";
551 print "";
554 for (i = 0; i < n_target_short; i++) {
555 print " if (ptr1->x_" var_target_short[i] " != ptr2->x_" var_target_short[i] ")";
556 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
557 print " indent, \"\",";
558 print " \"" var_target_short[i] "\",";
559 print " ptr1->x_" var_target_short[i] ",";
560 print " ptr2->x_" var_target_short[i] ");";
561 print "";
564 for (i = 0; i < n_target_char; i++) {
565 print " if (ptr1->x_" var_target_char[i] " != ptr2->x_" var_target_char[i] ")";
566 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
567 print " indent, \"\",";
568 print " \"" var_target_char[i] "\",";
569 print " ptr1->x_" var_target_char[i] ",";
570 print " ptr2->x_" var_target_char[i] ");";
571 print "";
574 print "}";
576 print "";
577 print "/* Compare two target options */";
578 print "bool";
579 print "cl_target_option_eq (struct cl_target_option const *ptr1 ATTRIBUTE_UNUSED,";
580 print " struct cl_target_option const *ptr2 ATTRIBUTE_UNUSED)";
581 print "{";
582 n_target_val = 0;
583 n_target_str = 0;
584 n_target_array = 0;
586 for (i = 0; i < n_target_save; i++) {
587 var = target_save_decl[i];
588 sub (" *=.*", "", var);
589 name = var;
590 type = var;
591 sub("^.*[ *]", "", name)
592 sub(" *" name "$", "", type)
593 if (target_save_decl[i] ~ "^const char \\*+[_" alnum "]+$")
594 var_target_str[n_target_str++] = name;
595 else {
596 if (target_save_decl[i] ~ " .*\\[.+\\]+$") {
597 size = name;
598 sub("[^\\[]+\\[", "", size);
599 sub("\\]$", "", size);
600 sub("\\[.+", "", name)
601 sub(" [^ ]+$", "", type)
602 var_target_array[n_target_array] = name
603 var_target_array_type[n_target_array] = type
604 var_target_array_size[n_target_array++] = size
606 else {
607 var_target_val_type[n_target_val] = type;
608 var_target_val[n_target_val++] = name;
612 if (have_save) {
613 for (i = 0; i < n_opts; i++) {
614 if (flag_set_p("Save", flags[i])) {
615 name = var_name(flags[i])
616 if(name == "")
617 name = "target_flags";
619 if(name in var_list_seen)
620 continue;
622 var_list_seen[name]++;
623 otype = var_type_struct(flags[i])
624 if (otype ~ "^const char \\**$")
625 var_target_str[n_target_str++] = "x_" name;
626 else {
627 var_target_val_type[n_target_val] = otype;
628 var_target_val[n_target_val++] = "x_" name;
632 } else {
633 var_target_val_type[n_target_val] = "int";
634 var_target_val[n_target_val++] = "x_target_flags";
637 for (i = 0; i < n_target_str; i++) {
638 name = var_target_str[i]
639 print " if (ptr1->" name" != ptr2->" name;
640 print " && (!ptr1->" name" || !ptr2->" name
641 print " || strcmp (ptr1->" name", ptr2->" name ")))";
642 print " return false;";
644 for (i = 0; i < n_target_array; i++) {
645 name = var_target_array[i]
646 size = var_target_array_size[i]
647 type = var_target_array_type[i]
648 print " if (ptr1->" name" != ptr2->" name "";
649 print " || memcmp (ptr1->" name ", ptr2->" name ", " size " * sizeof(" type ")))"
650 print " return false;";
652 for (i = 0; i < n_target_val; i++) {
653 name = var_target_val[i]
654 print " if (ptr1->" name" != ptr2->" name ")";
655 print " return false;";
658 print " return true;";
660 print "}";
662 print "";
663 print "/* Hash target options */";
664 print "hashval_t";
665 print "cl_target_option_hash (struct cl_target_option const *ptr ATTRIBUTE_UNUSED)";
666 print "{";
667 print " inchash::hash hstate;";
668 for (i = 0; i < n_target_str; i++) {
669 name = var_target_str[i]
670 print " if (ptr->" name")";
671 print " hstate.add (ptr->" name", strlen (ptr->" name"));";
672 print " else";
673 print " hstate.add_int (0);";
675 for (i = 0; i < n_target_array; i++) {
676 name= var_target_array[i]
677 size = var_target_array_size[i]
678 type = var_target_array_type[i]
679 print " hstate.add_int (" size ");";
680 print " hstate.add (ptr->" name ", sizeof (" type ") * " size ");";
682 for (i = 0; i < n_target_val; i++) {
683 name = var_target_val[i]
684 print " hstate.add_wide_int (ptr->" name");";
686 print " return hstate.end ();";
687 print "}";
689 print "";
690 print "/* Stream out target options */";
691 print "void";
692 print "cl_target_option_stream_out (struct output_block *ob ATTRIBUTE_UNUSED,";
693 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
694 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
695 print "{";
696 for (i = 0; i < n_target_str; i++) {
697 name = var_target_str[i]
698 print " bp_pack_string (ob, bp, ptr->" name", true);";
700 for (i = 0; i < n_target_array; i++) {
701 name = var_target_array[i]
702 size = var_target_array_size[i]
703 print " for (unsigned i = 0; i < " size "; i++)"
704 print " bp_pack_value (bp, ptr->" name "[i], 64);";
706 for (i = 0; i < n_target_val; i++) {
707 name = var_target_val[i]
708 print " bp_pack_value (bp, ptr->" name", 64);";
710 print "}";
712 print "";
713 print "/* Stream in target options */";
714 print "void";
715 print "cl_target_option_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
716 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
717 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
718 print "{";
719 for (i = 0; i < n_target_str; i++) {
720 name = var_target_str[i]
721 print " ptr->" name" = bp_unpack_string (data_in, bp);";
722 print " if (ptr->" name")";
723 print " ptr->" name" = xstrdup (ptr->" name");";
725 for (i = 0; i < n_target_array; i++) {
726 name = var_target_array[i]
727 size = var_target_array_size[i]
728 print " for (int i = " size " - 1; i >= 0; i--)"
729 print " ptr->" name "[i] = (" var_target_array_type[i] ") bp_unpack_value (bp, 64);";
731 for (i = 0; i < n_target_val; i++) {
732 name = var_target_val[i]
733 print " ptr->" name" = (" var_target_val_type[i] ") bp_unpack_value (bp, 64);";
736 print "}";
738 n_opt_val = 3;
739 var_opt_val[0] = "x_optimize"
740 var_opt_val_type[0] = "char "
741 var_opt_val[1] = "x_optimize_size"
742 var_opt_val[2] = "x_optimize_debug"
743 var_opt_val_type[1] = "char "
744 var_opt_val_type[2] = "char "
745 for (i = 0; i < n_opts; i++) {
746 if (flag_set_p("Optimization", flags[i])) {
747 name = var_name(flags[i])
748 if(name == "")
749 continue;
751 if(name in var_opt_list_seen)
752 continue;
754 var_opt_list_seen[name]++;
756 otype = var_type_struct(flags[i])
757 var_opt_val_type[n_opt_val] = otype;
758 var_opt_val[n_opt_val++] = "x_" name;
761 print "";
762 print "/* Hash optimization options */";
763 print "hashval_t";
764 print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)";
765 print "{";
766 print " inchash::hash hstate;";
767 for (i = 0; i < n_opt_val; i++) {
768 name = var_opt_val[i]
769 print " hstate.add_wide_int (ptr->" name");";
771 print " return hstate.end ();";
772 print "}";
774 print "";
775 print "/* Stream out optimization options */";
776 print "void";
777 print "cl_optimization_stream_out (struct bitpack_d *bp,";
778 print " struct cl_optimization *ptr)";
779 print "{";
780 for (i = 0; i < n_opt_val; i++) {
781 name = var_opt_val[i]
782 print " bp_pack_value (bp, ptr->" name", 64);";
784 print "}";
786 print "";
787 print "/* Stream in optimization options */";
788 print "void";
789 print "cl_optimization_stream_in (struct bitpack_d *bp,";
790 print " struct cl_optimization *ptr)";
791 print "{";
792 for (i = 0; i < n_opt_val; i++) {
793 name = var_opt_val[i]
794 print " ptr->" name" = (" var_opt_val_type[i] ") bp_unpack_value (bp, 64);";
796 print "}";