1 # Copyright (C) 2003-2019 Free Software Foundation, Inc.
2 # Contributed by Kelley Cook, June 2004.
3 # Original code from Neil Booth, May 2003.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any
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
;
132 var_opt_other
[n_opt_other
++] = name
;
136 for (i =
0; i
< n_opt_char
; i
++) {
137 name = var_opt_char
[i
];
138 if (var_opt_range
[name
] != "")
139 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_opt_range
[name
] "));";
143 for (i =
0; i
< n_opt_other
; i
++) {
144 print " ptr->x_" var_opt_other
[i
] " = opts->x_" var_opt_other
[i
] ";";
147 for (i =
0; i
< n_opt_int
; i
++) {
148 print " ptr->x_" var_opt_int
[i
] " = opts->x_" var_opt_int
[i
] ";";
151 for (i =
0; i
< n_opt_enum
; i
++) {
152 print " ptr->x_" var_opt_enum
[i
] " = opts->x_" var_opt_enum
[i
] ";";
155 for (i =
0; i
< n_opt_short
; i
++) {
156 print " ptr->x_" var_opt_short
[i
] " = opts->x_" var_opt_short
[i
] ";";
159 for (i =
0; i
< n_opt_char
; i
++) {
160 print " ptr->x_" var_opt_char
[i
] " = opts->x_" var_opt_char
[i
] ";";
163 for (i =
0; i
< n_opt_string
; i
++) {
164 print " ptr->x_" var_opt_string
[i
] " = opts->x_" var_opt_string
[i
] ";";
170 print "/* Restore optimization options from a structure. */";
172 print "cl_optimization_restore (struct gcc_options *opts, struct cl_optimization *ptr)";
175 for (i =
0; i
< n_opt_other
; i
++) {
176 print " opts->x_" var_opt_other
[i
] " = ptr->x_" var_opt_other
[i
] ";";
179 for (i =
0; i
< n_opt_int
; i
++) {
180 print " opts->x_" var_opt_int
[i
] " = ptr->x_" var_opt_int
[i
] ";";
183 for (i =
0; i
< n_opt_enum
; i
++) {
184 print " opts->x_" var_opt_enum
[i
] " = ptr->x_" var_opt_enum
[i
] ";";
187 for (i =
0; i
< n_opt_short
; i
++) {
188 print " opts->x_" var_opt_short
[i
] " = ptr->x_" var_opt_short
[i
] ";";
191 for (i =
0; i
< n_opt_char
; i
++) {
192 print " opts->x_" var_opt_char
[i
] " = ptr->x_" var_opt_char
[i
] ";";
195 for (i =
0; i
< n_opt_string
; i
++) {
196 print " opts->x_" var_opt_string
[i
] " = ptr->x_" var_opt_string
[i
] ";";
199 print " targetm.override_options_after_change ();";
203 print "/* Print optimization options from a structure. */";
205 print "cl_optimization_print (FILE *file,";
206 print " int indent_to,";
207 print " struct cl_optimization *ptr)";
210 print " fputs (\"\\n\", file);";
211 for (i =
0; i
< n_opt_other
; i
++) {
212 print " if (ptr->x_" var_opt_other
[i
] ")";
213 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
214 print " indent_to, \"\",";
215 print " \"" var_opt_other
[i
] "\",";
216 print " (unsigned long)ptr->x_" var_opt_other
[i
] ");";
220 for (i =
0; i
< n_opt_int
; i
++) {
221 print " if (ptr->x_" var_opt_int
[i
] ")";
222 print " fprintf (file, \"%*s%s (%#x)\\n\",";
223 print " indent_to, \"\",";
224 print " \"" var_opt_int
[i
] "\",";
225 print " ptr->x_" var_opt_int
[i
] ");";
229 for (i =
0; i
< n_opt_enum
; i
++) {
230 print " fprintf (file, \"%*s%s (%#x)\\n\",";
231 print " indent_to, \"\",";
232 print " \"" var_opt_enum
[i
] "\",";
233 print " (int) ptr->x_" var_opt_enum
[i
] ");";
237 for (i =
0; i
< n_opt_short
; i
++) {
238 print " if (ptr->x_" var_opt_short
[i
] ")";
239 print " fprintf (file, \"%*s%s (%#x)\\n\",";
240 print " indent_to, \"\",";
241 print " \"" var_opt_short
[i
] "\",";
242 print " ptr->x_" var_opt_short
[i
] ");";
246 for (i =
0; i
< n_opt_char
; i
++) {
247 print " if (ptr->x_" var_opt_char
[i
] ")";
248 print " fprintf (file, \"%*s%s (%#x)\\n\",";
249 print " indent_to, \"\",";
250 print " \"" var_opt_char
[i
] "\",";
251 print " ptr->x_" var_opt_char
[i
] ");";
255 for (i =
0; i
< n_opt_string
; i
++) {
256 print " if (ptr->x_" var_opt_string
[i
] ")";
257 print " fprintf (file, \"%*s%s (%s)\\n\",";
258 print " indent_to, \"\",";
259 print " \"" var_opt_string
[i
] "\",";
260 print " ptr->x_" var_opt_string
[i
] ");";
267 print "/* Print different optimization variables from structures provided as arguments. */";
269 print "cl_optimization_print_diff (FILE *file,";
270 print " int indent_to,";
271 print " struct cl_optimization *ptr1,";
272 print " struct cl_optimization *ptr2)";
275 print " fputs (\"\\n\", file);";
276 for (i =
0; i
< n_opt_other
; i
++) {
277 print " if (ptr1->x_" var_opt_other
[i
] " != ptr2->x_" var_opt_other
[i
] ")";
278 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
279 print " indent_to, \"\",";
280 print " \"" var_opt_other
[i
] "\",";
281 print " (unsigned long)ptr1->x_" var_opt_other
[i
] ",";
282 print " (unsigned long)ptr2->x_" var_opt_other
[i
] ");";
286 for (i =
0; i
< n_opt_int
; i
++) {
287 print " if (ptr1->x_" var_opt_int
[i
] " != ptr2->x_" var_opt_int
[i
] ")";
288 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
289 print " indent_to, \"\",";
290 print " \"" var_opt_int
[i
] "\",";
291 print " ptr1->x_" var_opt_int
[i
] ",";
292 print " ptr2->x_" var_opt_int
[i
] ");";
296 for (i =
0; i
< n_opt_enum
; i
++) {
297 print " if (ptr1->x_" var_opt_enum
[i
] " != ptr2->x_" var_opt_enum
[i
] ")";
298 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
299 print " indent_to, \"\",";
300 print " \"" var_opt_enum
[i
] "\",";
301 print " (int) ptr1->x_" var_opt_enum
[i
] ",";
302 print " (int) ptr2->x_" var_opt_enum
[i
] ");";
306 for (i =
0; i
< n_opt_short
; i
++) {
307 print " if (ptr1->x_" var_opt_short
[i
] " != ptr2->x_" var_opt_short
[i
] ")";
308 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
309 print " indent_to, \"\",";
310 print " \"" var_opt_short
[i
] "\",";
311 print " ptr1->x_" var_opt_short
[i
] ",";
312 print " ptr2->x_" var_opt_short
[i
] ");";
316 for (i =
0; i
< n_opt_char
; i
++) {
317 print " if (ptr1->x_" var_opt_char
[i
] " != ptr2->x_" var_opt_char
[i
] ")";
318 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
319 print " indent_to, \"\",";
320 print " \"" var_opt_char
[i
] "\",";
321 print " ptr1->x_" var_opt_char
[i
] ",";
322 print " ptr2->x_" var_opt_char
[i
] ");";
326 for (i =
0; i
< n_opt_string
; i
++) {
327 name = var_opt_string
[i
]
328 print " if (ptr1->x_" name
" != ptr2->x_" name
"";
329 print " && (!ptr1->x_" name
" || !ptr2->x_" name
330 print " || strcmp (ptr1->x_" name
", ptr2->x_" name
")))";
331 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
332 print " indent_to, \"\",";
333 print " \"" name
"\",";
334 print " ptr1->x_" name
" ? ptr1->x_" name
" : \"(null)\",";
335 print " ptr2->x_" name
" ? ptr1->x_" name
" : \"(null)\");";
343 print "/* Save selected option variables into a structure. */"
345 print "cl_target_option_save (struct cl_target_option *ptr, struct gcc_options *opts)";
356 for (i =
0; i
< n_opts
; i
++) {
357 if (flag_set_p
("Save", flags
[i
])) {
358 name = var_name
(flags
[i
])
360 name =
"target_flags";
362 if(name in var_save_seen
)
365 var_save_seen
[name
]++;
366 otype = var_type_struct
(flags
[i
])
367 if (otype ~
"^((un)?signed +)?int *$")
368 var_target_int
[n_target_int
++] = name
;
370 else if (otype ~
"^((un)?signed +)?short *$")
371 var_target_short
[n_target_short
++] = name
;
373 else if (otype ~
("^enum +[_" alnum
"]+ *$"))
374 var_target_enum
[n_target_enum
++] = name
;
376 else if (otype ~
"^((un)?signed +)?char *$") {
377 var_target_char
[n_target_char
++] = name
;
378 if (otype ~
"^unsigned +char *$")
379 var_target_range
[name
] =
"0, 255"
380 else if (otype ~
"^signed +char *$")
381 var_target_range
[name
] =
"-128, 127"
382 if (otype == var_type
(flags
[i
]))
383 var_target_range
[name
] =
""
385 else if (otype ~
"^const char \\**$")
386 var_target_string
[n_target_string
++] = name
;
388 var_target_other
[n_target_other
++] = name
;
392 var_target_int
[n_target_int
++] =
"target_flags";
396 for (i =
0; i
< n_target_char
; i
++) {
397 name = var_target_char
[i
];
398 if (var_target_range
[name
] != "") {
400 print " gcc_assert (IN_RANGE (opts->x_" name
", " var_target_range
[name
] "));";
407 print " if (targetm.target_option.save)";
408 print " targetm.target_option.save (ptr, opts);";
411 for (i =
0; i
< n_extra_target_vars
; i
++) {
412 print " ptr->x_" extra_target_vars
[i
] " = opts->x_" extra_target_vars
[i
] ";";
415 for (i =
0; i
< n_target_other
; i
++) {
416 print " ptr->x_" var_target_other
[i
] " = opts->x_" var_target_other
[i
] ";";
419 for (i =
0; i
< n_target_enum
; i
++) {
420 print " ptr->x_" var_target_enum
[i
] " = opts->x_" var_target_enum
[i
] ";";
423 for (i =
0; i
< n_target_int
; i
++) {
424 print " ptr->x_" var_target_int
[i
] " = opts->x_" var_target_int
[i
] ";";
427 for (i =
0; i
< n_target_short
; i
++) {
428 print " ptr->x_" var_target_short
[i
] " = opts->x_" var_target_short
[i
] ";";
431 for (i =
0; i
< n_target_char
; i
++) {
432 print " ptr->x_" var_target_char
[i
] " = opts->x_" var_target_char
[i
] ";";
435 for (i =
0; i
< n_target_string
; i
++) {
436 print " ptr->x_" var_target_string
[i
] " = opts->x_" var_target_string
[i
] ";";
442 print "/* Restore selected current options from a structure. */";
444 print "cl_target_option_restore (struct gcc_options *opts, struct cl_target_option *ptr)";
447 for (i =
0; i
< n_extra_target_vars
; i
++) {
448 print " opts->x_" extra_target_vars
[i
] " = ptr->x_" extra_target_vars
[i
] ";";
451 for (i =
0; i
< n_target_other
; i
++) {
452 print " opts->x_" var_target_other
[i
] " = ptr->x_" var_target_other
[i
] ";";
455 for (i =
0; i
< n_target_enum
; i
++) {
456 print " opts->x_" var_target_enum
[i
] " = ptr->x_" var_target_enum
[i
] ";";
459 for (i =
0; i
< n_target_int
; i
++) {
460 print " opts->x_" var_target_int
[i
] " = ptr->x_" var_target_int
[i
] ";";
463 for (i =
0; i
< n_target_short
; i
++) {
464 print " opts->x_" var_target_short
[i
] " = ptr->x_" var_target_short
[i
] ";";
467 for (i =
0; i
< n_target_char
; i
++) {
468 print " opts->x_" var_target_char
[i
] " = ptr->x_" var_target_char
[i
] ";";
471 for (i =
0; i
< n_target_string
; i
++) {
472 print " opts->x_" var_target_string
[i
] " = ptr->x_" var_target_string
[i
] ";";
475 # This must occur after the normal variables in case the code depends on those
478 print " if (targetm.target_option.restore)";
479 print " targetm.target_option.restore (opts, ptr);";
484 print "/* Print optimization options from a structure. */";
486 print "cl_target_option_print (FILE *file,";
487 print " int indent,";
488 print " struct cl_target_option *ptr)";
491 print " fputs (\"\\n\", file);";
492 for (i =
0; i
< n_target_other
; i
++) {
493 print " if (ptr->x_" var_target_other
[i
] ")";
494 hwi = host_wide_int
[var_target_other
[i
]]
496 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
498 print " fprintf (file, \"%*s%s (%#lx)\\n\",";
499 print " indent, \"\",";
500 print " \"" var_target_other
[i
] "\",";
502 print " ptr->x_" var_target_other
[i
] ");";
504 print " (unsigned long)ptr->x_" var_target_other
[i
] ");";
508 for (i =
0; i
< n_target_enum
; i
++) {
509 print " if (ptr->x_" var_target_enum
[i
] ")";
510 print " fprintf (file, \"%*s%s (%#x)\\n\",";
511 print " indent, \"\",";
512 print " \"" var_target_enum
[i
] "\",";
513 print " ptr->x_" var_target_enum
[i
] ");";
517 for (i =
0; i
< n_target_int
; i
++) {
518 print " if (ptr->x_" var_target_int
[i
] ")";
519 print " fprintf (file, \"%*s%s (%#x)\\n\",";
520 print " indent, \"\",";
521 print " \"" var_target_int
[i
] "\",";
522 print " ptr->x_" var_target_int
[i
] ");";
526 for (i =
0; i
< n_target_short
; i
++) {
527 print " if (ptr->x_" var_target_short
[i
] ")";
528 print " fprintf (file, \"%*s%s (%#x)\\n\",";
529 print " indent, \"\",";
530 print " \"" var_target_short
[i
] "\",";
531 print " ptr->x_" var_target_short
[i
] ");";
535 for (i =
0; i
< n_target_char
; i
++) {
536 print " if (ptr->x_" var_target_char
[i
] ")";
537 print " fprintf (file, \"%*s%s (%#x)\\n\",";
538 print " indent, \"\",";
539 print " \"" var_target_char
[i
] "\",";
540 print " ptr->x_" var_target_char
[i
] ");";
544 for (i =
0; i
< n_target_string
; i
++) {
545 print " if (ptr->x_" var_target_string
[i
] ")";
546 print " fprintf (file, \"%*s%s (%s)\\n\",";
547 print " indent, \"\",";
548 print " \"" var_target_string
[i
] "\",";
549 print " ptr->x_" var_target_string
[i
] ");";
554 print " if (targetm.target_option.print)";
555 print " targetm.target_option.print (file, indent, ptr);";
559 print "/* Print different target option variables from structures provided as arguments. */";
561 print "cl_target_option_print_diff (FILE *file,";
562 print " int indent ATTRIBUTE_UNUSED,";
563 print " struct cl_target_option *ptr1 ATTRIBUTE_UNUSED,";
564 print " struct cl_target_option *ptr2 ATTRIBUTE_UNUSED)";
567 print " fputs (\"\\n\", file);";
568 for (i =
0; i
< n_target_other
; i
++) {
569 print " if (ptr1->x_" var_target_other
[i
] " != ptr2->x_" var_target_other
[i
] ")";
570 hwi = host_wide_int
[var_target_other
[i
]]
572 print " fprintf (file, \"%*s%s (%#\" HOST_WIDE_INT_PRINT \"x/%#\" HOST_WIDE_INT_PRINT \"x)\\n\",";
574 print " fprintf (file, \"%*s%s (%#lx/%#lx)\\n\",";
575 print " indent, \"\",";
576 print " \"" var_target_other
[i
] "\",";
578 print " ptr1->x_" var_target_other
[i
] ",";
579 print " ptr2->x_" var_target_other
[i
] ");";
582 print " (unsigned long)ptr1->x_" var_target_other
[i
] ",";
583 print " (unsigned long)ptr2->x_" var_target_other
[i
] ");";
588 for (i =
0; i
< n_target_enum
; i
++) {
589 print " if (ptr1->x_" var_target_enum
[i
] " != ptr2->x_" var_target_enum
[i
] ")";
590 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
591 print " indent, \"\",";
592 print " \"" var_target_enum
[i
] "\",";
593 print " ptr1->x_" var_target_enum
[i
] ",";
594 print " ptr2->x_" var_target_enum
[i
] ");";
598 for (i =
0; i
< n_target_int
; i
++) {
599 print " if (ptr1->x_" var_target_int
[i
] " != ptr2->x_" var_target_int
[i
] ")";
600 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
601 print " indent, \"\",";
602 print " \"" var_target_int
[i
] "\",";
603 print " ptr1->x_" var_target_int
[i
] ",";
604 print " ptr2->x_" var_target_int
[i
] ");";
608 for (i =
0; i
< n_target_short
; i
++) {
609 print " if (ptr1->x_" var_target_short
[i
] " != ptr2->x_" var_target_short
[i
] ")";
610 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
611 print " indent, \"\",";
612 print " \"" var_target_short
[i
] "\",";
613 print " ptr1->x_" var_target_short
[i
] ",";
614 print " ptr2->x_" var_target_short
[i
] ");";
618 for (i =
0; i
< n_target_char
; i
++) {
619 print " if (ptr1->x_" var_target_char
[i
] " != ptr2->x_" var_target_char
[i
] ")";
620 print " fprintf (file, \"%*s%s (%#x/%#x)\\n\",";
621 print " indent, \"\",";
622 print " \"" var_target_char
[i
] "\",";
623 print " ptr1->x_" var_target_char
[i
] ",";
624 print " ptr2->x_" var_target_char
[i
] ");";
628 for (i =
0; i
< n_target_string
; i
++) {
629 name = var_target_string
[i
]
630 print " if (ptr1->x_" name
" != ptr2->x_" name
"";
631 print " && (!ptr1->x_" name
" || !ptr2->x_" name
632 print " || strcmp (ptr1->x_" name
", ptr2->x_" name
")))";
633 print " fprintf (file, \"%*s%s (%s/%s)\\n\",";
634 print " indent, \"\",";
635 print " \"" name
"\",";
636 print " ptr1->x_" name
" ? ptr1->x_" name
" : \"(null)\",";
637 print " ptr2->x_" name
" ? ptr1->x_" name
" : \"(null)\");";
644 print "/* Compare two target options */";
646 print "cl_target_option_eq (struct cl_target_option const *ptr1 ATTRIBUTE_UNUSED,";
647 print " struct cl_target_option const *ptr2 ATTRIBUTE_UNUSED)";
653 for (i =
0; i
< n_target_save
; i
++) {
654 var = target_save_decl
[i
];
655 sub (" *=.*", "", var
);
658 sub("^.*[ *]", "", name
)
659 sub(" *" name
"$", "", type
)
660 if (target_save_decl
[i
] ~
"^const char \\*+[_" alnum
"]+$")
661 var_target_str
[n_target_str
++] = name
;
663 if (target_save_decl
[i
] ~
" .*\\[.+\\]+$") {
665 sub("[^\\[]+\\[", "", size
);
666 sub("\\]$", "", size
);
667 sub("\\[.+", "", name
)
668 sub(" [^ ]+$", "", type
)
669 var_target_array
[n_target_array
] = name
670 var_target_array_type
[n_target_array
] = type
671 var_target_array_size
[n_target_array
++] = size
674 var_target_val_type
[n_target_val
] = type
;
675 var_target_val
[n_target_val
++] = name
;
680 for (i =
0; i
< n_opts
; i
++) {
681 if (flag_set_p
("Save", flags
[i
])) {
682 name = var_name
(flags
[i
])
684 name =
"target_flags";
686 if(name in var_list_seen
)
689 var_list_seen
[name
]++;
690 otype = var_type_struct
(flags
[i
])
691 if (otype ~
"^const char \\**$")
692 var_target_str
[n_target_str
++] =
"x_" name
;
694 var_target_val_type
[n_target_val
] = otype
;
695 var_target_val
[n_target_val
++] =
"x_" name
;
700 var_target_val_type
[n_target_val
] =
"int";
701 var_target_val
[n_target_val
++] =
"x_target_flags";
704 for (i =
0; i
< n_target_str
; i
++) {
705 name = var_target_str
[i
]
706 print " if (ptr1->" name
" != ptr2->" name
;
707 print " && (!ptr1->" name
" || !ptr2->" name
708 print " || strcmp (ptr1->" name
", ptr2->" name
")))";
709 print " return false;";
711 for (i =
0; i
< n_target_array
; i
++) {
712 name = var_target_array
[i
]
713 size = var_target_array_size
[i
]
714 type = var_target_array_type
[i
]
715 print " if (ptr1->" name
" != ptr2->" name
"";
716 print " || memcmp (ptr1->" name
", ptr2->" name
", " size
" * sizeof(" type
")))"
717 print " return false;";
719 for (i =
0; i
< n_target_val
; i
++) {
720 name = var_target_val
[i
]
721 print " if (ptr1->" name
" != ptr2->" name
")";
722 print " return false;";
725 print " return true;";
730 print "/* Hash target options */";
732 print "cl_target_option_hash (struct cl_target_option const *ptr ATTRIBUTE_UNUSED)";
734 print " inchash::hash hstate;";
735 for (i =
0; i
< n_target_str
; i
++) {
736 name = var_target_str
[i
]
737 print " if (ptr->" name
")";
738 print " hstate.add (ptr->" name
", strlen (ptr->" name
"));";
740 print " hstate.add_int (0);";
742 for (i =
0; i
< n_target_array
; i
++) {
743 name= var_target_array
[i
]
744 size = var_target_array_size
[i
]
745 type = var_target_array_type
[i
]
746 print " hstate.add_int (" size
");";
747 print " hstate.add (ptr->" name
", sizeof (" type
") * " size
");";
749 for (i =
0; i
< n_target_val
; i
++) {
750 name = var_target_val
[i
]
751 print " hstate.add_hwi (ptr->" name
");";
753 print " return hstate.end ();";
757 print "/* Stream out target options */";
759 print "cl_target_option_stream_out (struct output_block *ob ATTRIBUTE_UNUSED,";
760 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
761 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
763 for (i =
0; i
< n_target_str
; i
++) {
764 name = var_target_str
[i
]
765 print " bp_pack_string (ob, bp, ptr->" name
", true);";
767 for (i =
0; i
< n_target_array
; i
++) {
768 name = var_target_array
[i
]
769 size = var_target_array_size
[i
]
770 print " for (unsigned i = 0; i < " size
"; i++)"
771 print " bp_pack_value (bp, ptr->" name
"[i], 64);";
773 for (i =
0; i
< n_target_val
; i
++) {
774 name = var_target_val
[i
]
775 print " bp_pack_value (bp, ptr->" name
", 64);";
780 print "/* Stream in target options */";
782 print "cl_target_option_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
783 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
784 print " struct cl_target_option *ptr ATTRIBUTE_UNUSED)";
786 for (i =
0; i
< n_target_str
; i
++) {
787 name = var_target_str
[i
]
788 print " ptr->" name
" = bp_unpack_string (data_in, bp);";
789 print " if (ptr->" name
")";
790 print " ptr->" name
" = xstrdup (ptr->" name
");";
792 for (i =
0; i
< n_target_array
; i
++) {
793 name = var_target_array
[i
]
794 size = var_target_array_size
[i
]
795 print " for (int i = " size
" - 1; i >= 0; i--)"
796 print " ptr->" name
"[i] = (" var_target_array_type
[i
] ") bp_unpack_value (bp, 64);";
798 for (i =
0; i
< n_target_val
; i
++) {
799 name = var_target_val
[i
]
800 print " ptr->" name
" = (" var_target_val_type
[i
] ") bp_unpack_value (bp, 64);";
806 var_opt_val
[0] =
"x_optimize"
807 var_opt_val_type
[0] =
"char "
809 var_opt_val
[1] =
"x_optimize_size"
810 var_opt_val_type
[1] =
"char "
812 var_opt_val
[2] =
"x_optimize_debug"
813 var_opt_val_type
[2] =
"char "
815 var_opt_val
[3] =
"x_optimize_fast"
816 var_opt_val_type
[3] =
"char "
818 for (i =
0; i
< n_opts
; i
++) {
819 if (flag_set_p
("(Optimization|PerFunction)", flags
[i
])) {
820 name = var_name
(flags
[i
])
824 if(name in var_opt_list_seen
)
827 var_opt_list_seen
[name
]++;
829 otype = var_type_struct
(flags
[i
])
830 var_opt_val_type
[n_opt_val
] = otype
;
831 var_opt_val
[n_opt_val
] =
"x_" name
;
832 var_opt_hash
[n_opt_val
] = flag_set_p
("Optimization", flags
[i
]);
837 print "/* Hash optimization options */";
839 print "cl_optimization_hash (struct cl_optimization const *ptr ATTRIBUTE_UNUSED)";
841 print " inchash::hash hstate;";
842 for (i =
0; i
< n_opt_val
; i
++) {
843 if (!var_opt_hash
[i
])
845 name = var_opt_val
[i
]
846 otype = var_opt_val_type
[i
];
847 if (otype ~
"^const char \\**$")
849 print " if (ptr->" name
")";
850 print " hstate.add (ptr->" name
", strlen (ptr->" name
"));";
852 print " hstate.add_int (0);";
855 print " hstate.add_hwi (ptr->" name
");";
857 print " return hstate.end ();";
861 print "/* Compare two optimization options */";
863 print "cl_optimization_option_eq (cl_optimization const *ptr1,";
864 print " cl_optimization const *ptr2)";
866 for (i =
0; i
< n_opt_val
; i
++) {
867 if (!var_opt_hash
[i
])
869 name = var_opt_val
[i
]
870 otype = var_opt_val_type
[i
];
871 if (otype ~
"^const char \\**$")
873 print " if (ptr1->" name
" != ptr2->" name
;
874 print " && (!ptr1->" name
" || !ptr2->" name
875 print " || strcmp (ptr1->" name
", ptr2->" name
")))";
876 print " return false;";
880 print " if (ptr1->" name
" != ptr2->" name
")";
881 print " return false;";
884 print " return true;";
888 print "/* Stream out optimization options */";
890 print "cl_optimization_stream_out (struct output_block *ob,";
891 print " struct bitpack_d *bp,";
892 print " struct cl_optimization *ptr)";
894 for (i =
0; i
< n_opt_val
; i
++) {
895 name = var_opt_val
[i
]
896 otype = var_opt_val_type
[i
];
897 if (otype ~
"^const char \\**$")
898 print " bp_pack_string (ob, bp, ptr->" name
", true);";
900 print " bp_pack_value (bp, ptr->" name
", 64);";
905 print "/* Stream in optimization options */";
907 print "cl_optimization_stream_in (struct data_in *data_in ATTRIBUTE_UNUSED,";
908 print " struct bitpack_d *bp ATTRIBUTE_UNUSED,";
909 print " struct cl_optimization *ptr ATTRIBUTE_UNUSED)";
911 for (i =
0; i
< n_opt_val
; i
++) {
912 name = var_opt_val
[i
]
913 otype = var_opt_val_type
[i
];
914 if (otype ~
"^const char \\**$")
916 print " ptr->" name
" = bp_unpack_string (data_in, bp);";
917 print " if (ptr->" name
")";
918 print " ptr->" name
" = xstrdup (ptr->" name
");";
921 print " ptr->" name
" = (" var_opt_val_type
[i
] ") bp_unpack_value (bp, 64);";