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
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
24 # This program uses functions from opt-functions.awk and code from
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.
32 print "/* This file is auto-generated by optc-save-gen.awk. */"
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
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
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
71 if (n_extra_target_vars
)
74 for (i =
0; i
< n_opts
; i
++) {
75 if (flag_set_p
("Save", flags
[i
]))
79 print "/* Save optimization variables into a structure. */"
81 print "cl_optimization_save (struct cl_optimization *ptr, struct gcc_options *opts)";
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
100 for (i =
0; i
< n_opts
; i
++) {
101 if (flag_set_p
("(Optimization|PerFunction)", flags
[i
])) {
102 name = var_name
(flags
[i
])
106 if(name in var_opt_seen
)
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
;
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
] "));";
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
] ";";
168 print "/* Restore optimization options from a structure. */";
170 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
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 ();";
201 print "/* Print optimization options from a structure. */";
203 print "cl_optimization_print (FILE *file,";
204 print " int indent_to,";
205 print " struct cl_optimization *ptr)";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
265 print "/* Print different optimization variables from structures provided as arguments. */";
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)";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
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
");";
341 print "/* Save selected option variables into a structure. */"
343 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
353 for (i =
0; i
< n_opts
; i
++) {
354 if (flag_set_p
("Save", flags
[i
])) {
355 name = var_name
(flags
[i
])
357 name =
"target_flags";
359 if(name in var_save_seen
)
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
] =
""
383 var_target_other
[n_target_other
++] = name
;
387 var_target_int
[n_target_int
++] =
"target_flags";
391 for (i =
0; i
< n_target_char
; i
++) {
392 name = var_target_char
[i
];
393 if (var_target_range
[name
] != "") {
395 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_target_range
[name
] "));";
402 print " if (targetm.target_option.save)";
403 print " targetm.target_option.save (ptr, opts);";
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
] ";";
433 print "/* Restore selected current options from a structure. */";
435 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
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
465 print " if (targetm.target_option.restore)";
466 print " targetm.target_option.restore (opts, ptr);";
471 print "/* Print optimization options from a structure. */";
473 print "cl_target_option_print (FILE *file,";
474 print " int indent,";
475 print " struct cl_target_option *ptr)";
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
]]
483 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
485 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
486 print " indent, \"\",";
487 print " \"" var_target_other
[i
] "\",";
489 print " ptr->x_" var_target_other
[i
] ");";
491 print " (unsigned long)ptr->x_" var_target_other
[i
] ");";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
532 print " if (targetm.target_option.print)";
533 print " targetm.target_option.print (file, indent, ptr);";
537 print "/* Print different target option variables from structures provided as arguments. */";
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)";
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
]]
550 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x/%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
552 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
553 print " indent, \"\",";
554 print " \"" var_target_other
[i
] "\",";
556 print " ptr1->x_" var_target_other
[i
] ",";
557 print " ptr2->x_" var_target_other
[i
] ");";
560 print " (unsigned long)ptr1->x_" var_target_other
[i
] ",";
561 print " (unsigned long)ptr2->x_" var_target_other
[i
] ");";
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
] ");";
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
] ");";
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
] ");";
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
] ");";
609 print "/* Compare two target options */";
611 print "cl_target_option_eq (struct cl_target_option const *ptr1 ATTRIBUTE_UNUSED,";
612 print " struct cl_target_option const *ptr2 ATTRIBUTE_UNUSED)";
618 for (i =
0; i
< n_target_save
; i
++) {
619 var = target_save_decl
[i
];
620 sub (" *=.*", "", 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
;
628 if (target_save_decl
[i
] ~
" .*\\[.+\\]+$") {
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
639 var_target_val_type
[n_target_val
] = type
;
640 var_target_val
[n_target_val
++] = name
;
645 for (i =
0; i
< n_opts
; i
++) {
646 if (flag_set_p
("Save", flags
[i
])) {
647 name = var_name
(flags
[i
])
649 name =
"target_flags";
651 if(name in var_list_seen
)
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
;
659 var_target_val_type
[n_target_val
] = otype
;
660 var_target_val
[n_target_val
++] =
"x_" name
;
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;";
695 print "/* Hash target options */";
697 print "cl_target_option_hash (struct cl_target_option const *ptr ATTRIBUTE_UNUSED)";
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
"));";
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 ();";
722 print "/* Stream out target options */";
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)";
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);";
745 print "/* Stream in target options */";
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)";
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);";
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
])
783 if(name in var_opt_list_seen
)
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
]);
795 print "/* Hash optimization options */";
797 print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)";
799 print " inchash::hash hstate;";
800 for (i =
0; i
< n_opt_val
; i
++) {
801 if (!var_opt_hash
[i
])
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
"));";
810 print " hstate.add_int (0);";
813 print " hstate.add_hwi (ptr->" name
");";
815 print " return hstate.end ();";
819 print "/* Compare two optimization options */";
821 print "cl_optimization_option_eq (cl_optimization const *ptr1,";
822 print " cl_optimization const *ptr2)";
824 for (i =
0; i
< n_opt_val
; i
++) {
825 if (!var_opt_hash
[i
])
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;";
838 print " if (ptr1->" name
" != ptr2->" name
")";
839 print " return false;";
842 print " return true;";
846 print "/* Stream out optimization options */";
848 print "cl_optimization_stream_out (struct output_block *ob,";
849 print " struct bitpack_d *bp,";
850 print " struct cl_optimization *ptr)";
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);";
858 print " bp_pack_value (bp, ptr->" name
", 64);";
863 print "/* Stream in optimization options */";
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)";
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
");";
879 print " ptr->" name
" = (" var_opt_val_type
[i
] ") bp_unpack_value (bp, 64);";