1 # Copyright (C) 2003-2020 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_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
102 for (i =
0; i
< n_opts
; i
++) {
103 if (flag_set_p
("(Optimization|PerFunction)", flags
[i
])) {
104 name = var_name
(flags
[i
])
108 if(name in var_opt_seen
)
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 string_options_names
[name
]++
134 var_opt_other
[n_opt_other
++] = name
;
138 for (i =
0; i
< n_opt_char
; i
++) {
139 name = var_opt_char
[i
];
140 if (var_opt_range
[name
] != "")
141 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_opt_range
[name
] "));";
145 for (i =
0; i
< n_opt_other
; i
++) {
146 print " ptr->x_" var_opt_other
[i
] " = opts->x_" var_opt_other
[i
] ";";
149 for (i =
0; i
< n_opt_int
; i
++) {
150 print " ptr->x_" var_opt_int
[i
] " = opts->x_" var_opt_int
[i
] ";";
153 for (i =
0; i
< n_opt_enum
; i
++) {
154 print " ptr->x_" var_opt_enum
[i
] " = opts->x_" var_opt_enum
[i
] ";";
157 for (i =
0; i
< n_opt_short
; i
++) {
158 print " ptr->x_" var_opt_short
[i
] " = opts->x_" var_opt_short
[i
] ";";
161 for (i =
0; i
< n_opt_char
; i
++) {
162 print " ptr->x_" var_opt_char
[i
] " = opts->x_" var_opt_char
[i
] ";";
165 for (i =
0; i
< n_opt_string
; i
++) {
166 print " ptr->x_" var_opt_string
[i
] " = opts->x_" var_opt_string
[i
] ";";
172 print "/* Restore optimization options from a structure. */";
174 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
177 for (i =
0; i
< n_opt_other
; i
++) {
178 print " opts->x_" var_opt_other
[i
] " = ptr->x_" var_opt_other
[i
] ";";
181 for (i =
0; i
< n_opt_int
; i
++) {
182 print " opts->x_" var_opt_int
[i
] " = ptr->x_" var_opt_int
[i
] ";";
185 for (i =
0; i
< n_opt_enum
; i
++) {
186 print " opts->x_" var_opt_enum
[i
] " = ptr->x_" var_opt_enum
[i
] ";";
189 for (i =
0; i
< n_opt_short
; i
++) {
190 print " opts->x_" var_opt_short
[i
] " = ptr->x_" var_opt_short
[i
] ";";
193 for (i =
0; i
< n_opt_char
; i
++) {
194 print " opts->x_" var_opt_char
[i
] " = ptr->x_" var_opt_char
[i
] ";";
197 for (i =
0; i
< n_opt_string
; i
++) {
198 print " opts->x_" var_opt_string
[i
] " = ptr->x_" var_opt_string
[i
] ";";
201 print " targetm.override_options_after_change ();";
205 print "/* Print optimization options from a structure. */";
207 print "cl_optimization_print (FILE *file,";
208 print " int indent_to,";
209 print " struct cl_optimization *ptr)";
212 print " fputs (\"\\n\", file);";
213 for (i =
0; i
< n_opt_other
; i
++) {
214 print " if (ptr->x_" var_opt_other
[i
] ")";
215 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
216 print " indent_to, \"\",";
217 print " \"" var_opt_other
[i
] "\",";
218 print " (unsigned long)ptr->x_" var_opt_other
[i
] ");";
222 for (i =
0; i
< n_opt_int
; i
++) {
223 print " if (ptr->x_" var_opt_int
[i
] ")";
224 print " fprintf (file, \"%*s%s (%#x)\\n\",";
225 print " indent_to, \"\",";
226 print " \"" var_opt_int
[i
] "\",";
227 print " ptr->x_" var_opt_int
[i
] ");";
231 for (i =
0; i
< n_opt_enum
; i
++) {
232 print " fprintf (file, \"%*s%s (%#x)\\n\",";
233 print " indent_to, \"\",";
234 print " \"" var_opt_enum
[i
] "\",";
235 print " (int) ptr->x_" var_opt_enum
[i
] ");";
239 for (i =
0; i
< n_opt_short
; i
++) {
240 print " if (ptr->x_" var_opt_short
[i
] ")";
241 print " fprintf (file, \"%*s%s (%#x)\\n\",";
242 print " indent_to, \"\",";
243 print " \"" var_opt_short
[i
] "\",";
244 print " ptr->x_" var_opt_short
[i
] ");";
248 for (i =
0; i
< n_opt_char
; i
++) {
249 print " if (ptr->x_" var_opt_char
[i
] ")";
250 print " fprintf (file, \"%*s%s (%#x)\\n\",";
251 print " indent_to, \"\",";
252 print " \"" var_opt_char
[i
] "\",";
253 print " ptr->x_" var_opt_char
[i
] ");";
257 for (i =
0; i
< n_opt_string
; i
++) {
258 print " if (ptr->x_" var_opt_string
[i
] ")";
259 print " fprintf (file, \"%*s%s (%s)\\n\",";
260 print " indent_to, \"\",";
261 print " \"" var_opt_string
[i
] "\",";
262 print " ptr->x_" var_opt_string
[i
] ");";
269 print "/* Print different optimization variables from structures provided as arguments. */";
271 print "cl_optimization_print_diff (FILE *file,";
272 print " int indent_to,";
273 print " struct cl_optimization *ptr1,";
274 print " struct cl_optimization *ptr2)";
277 print " fputs (\"\\n\", file);";
278 for (i =
0; i
< n_opt_other
; i
++) {
279 print " if (ptr1->x_" var_opt_other
[i
] " != ptr2->x_" var_opt_other
[i
] ")";
280 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
281 print " indent_to, \"\",";
282 print " \"" var_opt_other
[i
] "\",";
283 print " (unsigned long)ptr1->x_" var_opt_other
[i
] ",";
284 print " (unsigned long)ptr2->x_" var_opt_other
[i
] ");";
288 for (i =
0; i
< n_opt_int
; i
++) {
289 print " if (ptr1->x_" var_opt_int
[i
] " != ptr2->x_" var_opt_int
[i
] ")";
290 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
291 print " indent_to, \"\",";
292 print " \"" var_opt_int
[i
] "\",";
293 print " ptr1->x_" var_opt_int
[i
] ",";
294 print " ptr2->x_" var_opt_int
[i
] ");";
298 for (i =
0; i
< n_opt_enum
; i
++) {
299 print " if (ptr1->x_" var_opt_enum
[i
] " != ptr2->x_" var_opt_enum
[i
] ")";
300 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
301 print " indent_to, \"\",";
302 print " \"" var_opt_enum
[i
] "\",";
303 print " (int) ptr1->x_" var_opt_enum
[i
] ",";
304 print " (int) ptr2->x_" var_opt_enum
[i
] ");";
308 for (i =
0; i
< n_opt_short
; i
++) {
309 print " if (ptr1->x_" var_opt_short
[i
] " != ptr2->x_" var_opt_short
[i
] ")";
310 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
311 print " indent_to, \"\",";
312 print " \"" var_opt_short
[i
] "\",";
313 print " ptr1->x_" var_opt_short
[i
] ",";
314 print " ptr2->x_" var_opt_short
[i
] ");";
318 for (i =
0; i
< n_opt_char
; i
++) {
319 print " if (ptr1->x_" var_opt_char
[i
] " != ptr2->x_" var_opt_char
[i
] ")";
320 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
321 print " indent_to, \"\",";
322 print " \"" var_opt_char
[i
] "\",";
323 print " ptr1->x_" var_opt_char
[i
] ",";
324 print " ptr2->x_" var_opt_char
[i
] ");";
328 for (i =
0; i
< n_opt_string
; i
++) {
329 name = var_opt_string
[i
]
330 print " if (ptr1->x_" name
" != ptr2->x_" name
"";
331 print " && (!ptr1->x_" name
" || !ptr2->x_" name
332 print " || strcmp (ptr1->x_" name
", ptr2->x_" name
")))";
333 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
334 print " indent_to, \"\",";
335 print " \"" name
"\",";
336 print " ptr1->x_" name
" ? ptr1->x_" name
" : \"(null)\",";
337 print " ptr2->x_" name
" ? ptr2->x_" name
" : \"(null)\");";
345 print "/* Save selected option variables into a structure. */"
347 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
358 for (i =
0; i
< n_opts
; i
++) {
359 if (flag_set_p
("Save", flags
[i
])) {
360 name = var_name
(flags
[i
])
362 name =
"target_flags";
364 if(name in var_save_seen
)
367 var_save_seen
[name
]++;
368 otype = var_type_struct
(flags
[i
])
369 if (otype ~
"^((un)?signed +)?int *$")
370 var_target_int
[n_target_int
++] = name
;
372 else if (otype ~
"^((un)?signed +)?short *$")
373 var_target_short
[n_target_short
++] = name
;
375 else if (otype ~
("^enum +[_" alnum
"]+ *$"))
376 var_target_enum
[n_target_enum
++] = name
;
378 else if (otype ~
"^((un)?signed +)?char *$") {
379 var_target_char
[n_target_char
++] = name
;
380 if (otype ~
"^unsigned +char *$")
381 var_target_range
[name
] =
"0, 255"
382 else if (otype ~
"^signed +char *$")
383 var_target_range
[name
] =
"-128, 127"
384 if (otype == var_type
(flags
[i
]))
385 var_target_range
[name
] =
""
387 else if (otype ~
"^const char \\**$") {
388 var_target_string
[n_target_string
++] = name
;
389 string_options_names
[name
]++
392 var_target_other
[n_target_other
++] = name
;
396 var_target_int
[n_target_int
++] =
"target_flags";
400 for (i =
0; i
< n_target_char
; i
++) {
401 name = var_target_char
[i
];
402 if (var_target_range
[name
] != "") {
404 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_target_range
[name
] "));";
411 print " if (targetm.target_option.save)";
412 print " targetm.target_option.save (ptr, opts);";
415 for (i =
0; i
< n_extra_target_vars
; i
++) {
416 print " ptr->x_" extra_target_vars
[i
] " = opts->x_" extra_target_vars
[i
] ";";
419 for (i =
0; i
< n_target_other
; i
++) {
420 print " ptr->x_" var_target_other
[i
] " = opts->x_" var_target_other
[i
] ";";
423 for (i =
0; i
< n_target_enum
; i
++) {
424 print " ptr->x_" var_target_enum
[i
] " = opts->x_" var_target_enum
[i
] ";";
427 for (i =
0; i
< n_target_int
; i
++) {
428 print " ptr->x_" var_target_int
[i
] " = opts->x_" var_target_int
[i
] ";";
431 for (i =
0; i
< n_target_short
; i
++) {
432 print " ptr->x_" var_target_short
[i
] " = opts->x_" var_target_short
[i
] ";";
435 for (i =
0; i
< n_target_char
; i
++) {
436 print " ptr->x_" var_target_char
[i
] " = opts->x_" var_target_char
[i
] ";";
439 for (i =
0; i
< n_target_string
; i
++) {
440 print " ptr->x_" var_target_string
[i
] " = opts->x_" var_target_string
[i
] ";";
446 print "/* Restore selected current options from a structure. */";
448 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
451 for (i =
0; i
< n_extra_target_vars
; i
++) {
452 print " opts->x_" extra_target_vars
[i
] " = ptr->x_" extra_target_vars
[i
] ";";
455 for (i =
0; i
< n_target_other
; i
++) {
456 print " opts->x_" var_target_other
[i
] " = ptr->x_" var_target_other
[i
] ";";
459 for (i =
0; i
< n_target_enum
; i
++) {
460 print " opts->x_" var_target_enum
[i
] " = ptr->x_" var_target_enum
[i
] ";";
463 for (i =
0; i
< n_target_int
; i
++) {
464 print " opts->x_" var_target_int
[i
] " = ptr->x_" var_target_int
[i
] ";";
467 for (i =
0; i
< n_target_short
; i
++) {
468 print " opts->x_" var_target_short
[i
] " = ptr->x_" var_target_short
[i
] ";";
471 for (i =
0; i
< n_target_char
; i
++) {
472 print " opts->x_" var_target_char
[i
] " = ptr->x_" var_target_char
[i
] ";";
475 for (i =
0; i
< n_target_string
; i
++) {
476 print " opts->x_" var_target_string
[i
] " = ptr->x_" var_target_string
[i
] ";";
479 # This must occur after the normal variables in case the code depends on those
482 print " if (targetm.target_option.restore)";
483 print " targetm.target_option.restore (opts, ptr);";
488 print "/* Print optimization options from a structure. */";
490 print "cl_target_option_print (FILE *file,";
491 print " int indent,";
492 print " struct cl_target_option *ptr)";
495 print " fputs (\"\\n\", file);";
496 for (i =
0; i
< n_target_other
; i
++) {
497 print " if (ptr->x_" var_target_other
[i
] ")";
498 hwi = host_wide_int
[var_target_other
[i
]]
500 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
502 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
503 print " indent, \"\",";
504 print " \"" var_target_other
[i
] "\",";
506 print " ptr->x_" var_target_other
[i
] ");";
508 print " (unsigned long)ptr->x_" var_target_other
[i
] ");";
512 for (i =
0; i
< n_target_enum
; i
++) {
513 print " if (ptr->x_" var_target_enum
[i
] ")";
514 print " fprintf (file, \"%*s%s (%#x)\\n\",";
515 print " indent, \"\",";
516 print " \"" var_target_enum
[i
] "\",";
517 print " ptr->x_" var_target_enum
[i
] ");";
521 for (i =
0; i
< n_target_int
; i
++) {
522 print " if (ptr->x_" var_target_int
[i
] ")";
523 print " fprintf (file, \"%*s%s (%#x)\\n\",";
524 print " indent, \"\",";
525 print " \"" var_target_int
[i
] "\",";
526 print " ptr->x_" var_target_int
[i
] ");";
530 for (i =
0; i
< n_target_short
; i
++) {
531 print " if (ptr->x_" var_target_short
[i
] ")";
532 print " fprintf (file, \"%*s%s (%#x)\\n\",";
533 print " indent, \"\",";
534 print " \"" var_target_short
[i
] "\",";
535 print " ptr->x_" var_target_short
[i
] ");";
539 for (i =
0; i
< n_target_char
; i
++) {
540 print " if (ptr->x_" var_target_char
[i
] ")";
541 print " fprintf (file, \"%*s%s (%#x)\\n\",";
542 print " indent, \"\",";
543 print " \"" var_target_char
[i
] "\",";
544 print " ptr->x_" var_target_char
[i
] ");";
548 for (i =
0; i
< n_target_string
; i
++) {
549 print " if (ptr->x_" var_target_string
[i
] ")";
550 print " fprintf (file, \"%*s%s (%s)\\n\",";
551 print " indent, \"\",";
552 print " \"" var_target_string
[i
] "\",";
553 print " ptr->x_" var_target_string
[i
] ");";
558 print " if (targetm.target_option.print)";
559 print " targetm.target_option.print (file, indent, ptr);";
563 print "/* Print different target option variables from structures provided as arguments. */";
565 print "cl_target_option_print_diff (FILE *file,";
566 print " int indent ATTRIBUTE_UNUSED,";
567 print " struct cl_target_option *ptr1 ATTRIBUTE_UNUSED,";
568 print " struct cl_target_option *ptr2 ATTRIBUTE_UNUSED)";
571 print " fputs (\"\\n\", file);";
572 for (i =
0; i
< n_target_other
; i
++) {
573 print " if (ptr1->x_" var_target_other
[i
] " != ptr2->x_" var_target_other
[i
] ")";
574 hwi = host_wide_int
[var_target_other
[i
]]
576 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x/%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
578 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
579 print " indent, \"\",";
580 print " \"" var_target_other
[i
] "\",";
582 print " ptr1->x_" var_target_other
[i
] ",";
583 print " ptr2->x_" var_target_other
[i
] ");";
586 print " (unsigned long)ptr1->x_" var_target_other
[i
] ",";
587 print " (unsigned long)ptr2->x_" var_target_other
[i
] ");";
592 for (i =
0; i
< n_target_enum
; i
++) {
593 print " if (ptr1->x_" var_target_enum
[i
] " != ptr2->x_" var_target_enum
[i
] ")";
594 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
595 print " indent, \"\",";
596 print " \"" var_target_enum
[i
] "\",";
597 print " ptr1->x_" var_target_enum
[i
] ",";
598 print " ptr2->x_" var_target_enum
[i
] ");";
602 for (i =
0; i
< n_target_int
; i
++) {
603 print " if (ptr1->x_" var_target_int
[i
] " != ptr2->x_" var_target_int
[i
] ")";
604 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
605 print " indent, \"\",";
606 print " \"" var_target_int
[i
] "\",";
607 print " ptr1->x_" var_target_int
[i
] ",";
608 print " ptr2->x_" var_target_int
[i
] ");";
612 for (i =
0; i
< n_target_short
; i
++) {
613 print " if (ptr1->x_" var_target_short
[i
] " != ptr2->x_" var_target_short
[i
] ")";
614 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
615 print " indent, \"\",";
616 print " \"" var_target_short
[i
] "\",";
617 print " ptr1->x_" var_target_short
[i
] ",";
618 print " ptr2->x_" var_target_short
[i
] ");";
622 for (i =
0; i
< n_target_char
; i
++) {
623 print " if (ptr1->x_" var_target_char
[i
] " != ptr2->x_" var_target_char
[i
] ")";
624 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
625 print " indent, \"\",";
626 print " \"" var_target_char
[i
] "\",";
627 print " ptr1->x_" var_target_char
[i
] ",";
628 print " ptr2->x_" var_target_char
[i
] ");";
632 for (i =
0; i
< n_target_string
; i
++) {
633 name = var_target_string
[i
]
634 print " if (ptr1->x_" name
" != ptr2->x_" name
"";
635 print " && (!ptr1->x_" name
" || !ptr2->x_" name
636 print " || strcmp (ptr1->x_" name
", ptr2->x_" name
")))";
637 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
638 print " indent, \"\",";
639 print " \"" name
"\",";
640 print " ptr1->x_" name
" ? ptr1->x_" name
" : \"(null)\",";
641 print " ptr2->x_" name
" ? ptr1->x_" name
" : \"(null)\");";
648 print "/* Compare two target options */";
650 print "cl_target_option_eq (struct cl_target_option const *ptr1 ATTRIBUTE_UNUSED,";
651 print " struct cl_target_option const *ptr2 ATTRIBUTE_UNUSED)";
657 for (i =
0; i
< n_target_save
; i
++) {
658 var = target_save_decl
[i
];
659 sub (" *=.*", "", var
);
662 sub("^.*[ *]", "", name
)
663 sub(" *" name
"$", "", type
)
664 if (target_save_decl
[i
] ~
"^const char \\*+[_" alnum
"]+$")
665 var_target_str
[n_target_str
++] = name
;
667 if (target_save_decl
[i
] ~
" .*\\[.+\\]+$") {
669 sub("[^\\[]+\\[", "", size
);
670 sub("\\]$", "", size
);
671 sub("\\[.+", "", name
)
672 sub(" [^ ]+$", "", type
)
673 var_target_array
[n_target_array
] = name
674 var_target_array_type
[n_target_array
] = type
675 var_target_array_size
[n_target_array
++] = size
678 var_target_val_type
[n_target_val
] = type
;
679 var_target_val
[n_target_val
++] = name
;
684 for (i =
0; i
< n_opts
; i
++) {
685 if (flag_set_p
("Save", flags
[i
])) {
686 name = var_name
(flags
[i
])
688 name =
"target_flags";
690 if(name in var_list_seen
)
693 var_list_seen
[name
]++;
694 otype = var_type_struct
(flags
[i
])
695 if (otype ~
"^const char \\**$")
696 var_target_str
[n_target_str
++] =
"x_" name
;
698 var_target_val_type
[n_target_val
] = otype
;
699 var_target_val
[n_target_val
++] =
"x_" name
;
704 var_target_val_type
[n_target_val
] =
"int";
705 var_target_val
[n_target_val
++] =
"x_target_flags";
708 for (i =
0; i
< n_target_str
; i
++) {
709 name = var_target_str
[i
]
710 print " if (ptr1->" name
" != ptr2->" name
;
711 print " && (!ptr1->" name
" || !ptr2->" name
712 print " || strcmp (ptr1->" name
", ptr2->" name
")))";
713 print " return false;";
715 for (i =
0; i
< n_target_array
; i
++) {
716 name = var_target_array
[i
]
717 size = var_target_array_size
[i
]
718 type = var_target_array_type
[i
]
719 print " if (ptr1->" name
" != ptr2->" name
"";
720 print " || memcmp (ptr1->" name
", ptr2->" name
", " size
" * sizeof(" type
")))"
721 print " return false;";
723 for (i =
0; i
< n_target_val
; i
++) {
724 name = var_target_val
[i
]
725 print " if (ptr1->" name
" != ptr2->" name
")";
726 print " return false;";
729 print " return true;";
734 print "/* Hash target options */";
736 print "cl_target_option_hash (struct cl_target_option const *ptr ATTRIBUTE_UNUSED)";
738 print " inchash::hash hstate;";
739 for (i =
0; i
< n_target_str
; i
++) {
740 name = var_target_str
[i
]
741 print " if (ptr->" name
")";
742 print " hstate.add (ptr->" name
", strlen (ptr->" name
"));";
744 print " hstate.add_int (0);";
746 for (i =
0; i
< n_target_array
; i
++) {
747 name= var_target_array
[i
]
748 size = var_target_array_size
[i
]
749 type = var_target_array_type
[i
]
750 print " hstate.add_int (" size
");";
751 print " hstate.add (ptr->" name
", sizeof (" type
") * " size
");";
753 for (i =
0; i
< n_target_val
; i
++) {
754 name = var_target_val
[i
]
755 print " hstate.add_hwi (ptr->" name
");";
757 print " return hstate.end ();";
761 print "/* Stream out target options */";
763 print "cl_target_option_stream_out (struct output_block *ob ATTRIBUTE_UNUSED,";
764 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
765 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
767 for (i =
0; i
< n_target_str
; i
++) {
768 name = var_target_str
[i
]
769 print " bp_pack_string (ob, bp, ptr->" name
", true);";
771 for (i =
0; i
< n_target_array
; i
++) {
772 name = var_target_array
[i
]
773 size = var_target_array_size
[i
]
774 print " for (unsigned i = 0; i < " size
"; i++)"
775 print " bp_pack_value (bp, ptr->" name
"[i], 64);";
777 for (i =
0; i
< n_target_val
; i
++) {
778 name = var_target_val
[i
]
779 print " bp_pack_value (bp, ptr->" name
", 64);";
784 print "/* Stream in target options */";
786 print "cl_target_option_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
787 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
788 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
790 for (i =
0; i
< n_target_str
; i
++) {
791 name = var_target_str
[i
]
792 print " ptr->" name
" = bp_unpack_string (data_in, bp);";
793 print " if (ptr->" name
")";
794 print " ptr->" name
" = xstrdup (ptr->" name
");";
796 for (i =
0; i
< n_target_array
; i
++) {
797 name = var_target_array
[i
]
798 size = var_target_array_size
[i
]
799 print " for (int i = " size
" - 1; i >= 0; i--)"
800 print " ptr->" name
"[i] = (" var_target_array_type
[i
] ") bp_unpack_value (bp, 64);";
802 for (i =
0; i
< n_target_val
; i
++) {
803 name = var_target_val
[i
]
804 print " ptr->" name
" = (" var_target_val_type
[i
] ") bp_unpack_value (bp, 64);";
809 print "/* free heap memory used by target options */";
811 print "cl_target_option_free (struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
813 for (i =
0; i
< n_target_str
; i
++) {
814 name = var_target_str
[i
]
815 print " if (ptr->" name
")";
816 print " free (const_cast <char *>(ptr->" name
"));";
821 var_opt_val
[0] =
"x_optimize"
822 var_opt_val_type
[0] =
"char "
824 var_opt_val
[1] =
"x_optimize_size"
825 var_opt_val_type
[1] =
"char "
827 var_opt_val
[2] =
"x_optimize_debug"
828 var_opt_val_type
[2] =
"char "
830 var_opt_val
[3] =
"x_optimize_fast"
831 var_opt_val_type
[3] =
"char "
833 for (i =
0; i
< n_opts
; i
++) {
834 if (flag_set_p
("(Optimization|PerFunction)", flags
[i
])) {
835 name = var_name
(flags
[i
])
839 if(name in var_opt_list_seen
)
842 var_opt_list_seen
[name
]++;
844 otype = var_type_struct
(flags
[i
])
845 var_opt_val_type
[n_opt_val
] = otype
;
846 var_opt_val
[n_opt_val
] =
"x_" name
;
847 var_opt_hash
[n_opt_val
] = flag_set_p
("Optimization", flags
[i
]);
852 print "/* Hash optimization options */";
854 print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)";
856 print " inchash::hash hstate;";
857 for (i =
0; i
< n_opt_val
; i
++) {
858 if (!var_opt_hash
[i
])
860 name = var_opt_val
[i
]
861 otype = var_opt_val_type
[i
];
862 if (otype ~
"^const char \\**$")
864 print " if (ptr->" name
")";
865 print " hstate.add (ptr->" name
", strlen (ptr->" name
"));";
867 print " hstate.add_int (0);";
870 print " hstate.add_hwi (ptr->" name
");";
872 print " return hstate.end ();";
876 print "/* Compare two optimization options */";
878 print "cl_optimization_option_eq (cl_optimization const *ptr1,";
879 print " cl_optimization const *ptr2)";
881 for (i =
0; i
< n_opt_val
; i
++) {
882 if (!var_opt_hash
[i
])
884 name = var_opt_val
[i
]
885 otype = var_opt_val_type
[i
];
886 if (otype ~
"^const char \\**$")
888 print " if (ptr1->" name
" != ptr2->" name
;
889 print " && (!ptr1->" name
" || !ptr2->" name
890 print " || strcmp (ptr1->" name
", ptr2->" name
")))";
891 print " return false;";
895 print " if (ptr1->" name
" != ptr2->" name
")";
896 print " return false;";
899 print " return true;";
903 print "/* Stream out optimization options */";
905 print "cl_optimization_stream_out (struct output_block *ob,";
906 print " struct bitpack_d *bp,";
907 print " struct cl_optimization *ptr)";
909 for (i =
0; i
< n_opt_val
; i
++) {
910 name = var_opt_val
[i
]
911 otype = var_opt_val_type
[i
];
912 if (otype ~
"^const char \\**$")
913 print " bp_pack_string (ob, bp, ptr->" name
", true);";
915 print " bp_pack_value (bp, ptr->" name
", 64);";
920 print "/* Stream in optimization options */";
922 print "cl_optimization_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
923 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
924 print " struct cl_optimization *ptr ATTRIBUTE_UNUSED)";
926 for (i =
0; i
< n_opt_val
; i
++) {
927 name = var_opt_val
[i
]
928 otype = var_opt_val_type
[i
];
929 if (otype ~
"^const char \\**$")
931 print " ptr->" name
" = bp_unpack_string (data_in, bp);";
932 print " if (ptr->" name
")";
933 print " ptr->" name
" = xstrdup (ptr->" name
");";
936 print " ptr->" name
" = (" var_opt_val_type
[i
] ") bp_unpack_value (bp, 64);";
939 print "/* Free heap memory used by optimization options */";
941 print "cl_optimization_option_free (struct cl_optimization *ptr ATTRIBUTE_UNUSED)";
943 for (i =
0; i
< n_opt_val
; i
++) {
944 name = var_opt_val
[i
]
945 otype = var_opt_val_type
[i
];
946 if (otype ~
"^const char \\**$")
948 print " if (ptr->" name
")";
949 print " free (const_cast <char *>(ptr->" name
"));";
955 print "cl_optimization_compare (gcc_options *ptr1, gcc_options *ptr2)"
958 # all these options are mentioned in PR92860
959 checked_options
["flag_merge_constants"]++
960 checked_options
["param_max_fields_for_field_sensitive"]++
961 checked_options
["flag_omit_frame_pointer"]++
962 checked_options
["unroll_only_small_loops"]++
964 checked_options
["TARGET_ALIGN_CALL"]++
965 checked_options
["TARGET_CASE_VECTOR_PC_RELATIVE"]++
966 checked_options
["arc_size_opt_level"]++
968 for (i =
0; i
< n_opts
; i
++) {
969 name = var_name
(flags
[i
]);
973 if (name in checked_options
)
975 checked_options
[name
]++
977 if (name in string_options_names
) {
978 print " if (ptr1->x_" name
" != ptr2->x_" name
"";
979 print " && (!ptr1->x_" name
" || !ptr2->x_" name
980 print " || strcmp (ptr1->x_" name
", ptr2->x_" name
")))";
981 print " internal_error (\"%<global_options%> are modified in local context\");";
984 print " if (ptr1->x_" name
" != ptr2->x_" name
")"
985 print " internal_error (\"%<global_options%> are modified in local context\");";