annotate gcc/genopinit.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Generate code to initialize optabs from machine description.
111
kono
parents: 67
diff changeset
2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "bconfig.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #include "coretypes.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "tm.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "rtl.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "errors.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "gensupport.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
111
kono
parents: 67
diff changeset
30 #define DEF_RTL_EXPR(V, N, X, C) #V,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
111
kono
parents: 67
diff changeset
32 static const char * const rtx_upname[] = {
kono
parents: 67
diff changeset
33 #include "rtl.def"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
111
kono
parents: 67
diff changeset
36 #undef DEF_RTL_EXPR
kono
parents: 67
diff changeset
37
kono
parents: 67
diff changeset
38 /* Vector in which to collect insns that match. */
kono
parents: 67
diff changeset
39 static vec<optab_pattern> patterns;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 static void
111
kono
parents: 67
diff changeset
42 gen_insn (md_rtx_info *info)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 {
111
kono
parents: 67
diff changeset
44 optab_pattern p;
kono
parents: 67
diff changeset
45 if (find_optab (&p, XSTR (info->def, 0)))
kono
parents: 67
diff changeset
46 patterns.safe_push (p);
kono
parents: 67
diff changeset
47 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
111
kono
parents: 67
diff changeset
49 static int
kono
parents: 67
diff changeset
50 pattern_cmp (const void *va, const void *vb)
kono
parents: 67
diff changeset
51 {
kono
parents: 67
diff changeset
52 const optab_pattern *a = (const optab_pattern *)va;
kono
parents: 67
diff changeset
53 const optab_pattern *b = (const optab_pattern *)vb;
kono
parents: 67
diff changeset
54 return a->sort_num - b->sort_num;
kono
parents: 67
diff changeset
55 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
111
kono
parents: 67
diff changeset
57 static int
kono
parents: 67
diff changeset
58 optab_kind_cmp (const void *va, const void *vb)
kono
parents: 67
diff changeset
59 {
kono
parents: 67
diff changeset
60 const optab_def *a = (const optab_def *)va;
kono
parents: 67
diff changeset
61 const optab_def *b = (const optab_def *)vb;
kono
parents: 67
diff changeset
62 int diff = a->kind - b->kind;
kono
parents: 67
diff changeset
63 if (diff == 0)
kono
parents: 67
diff changeset
64 diff = a->op - b->op;
kono
parents: 67
diff changeset
65 return diff;
kono
parents: 67
diff changeset
66 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
111
kono
parents: 67
diff changeset
68 static int
kono
parents: 67
diff changeset
69 optab_rcode_cmp (const void *va, const void *vb)
kono
parents: 67
diff changeset
70 {
kono
parents: 67
diff changeset
71 const optab_def *a = (const optab_def *)va;
kono
parents: 67
diff changeset
72 const optab_def *b = (const optab_def *)vb;
kono
parents: 67
diff changeset
73 return a->rcode - b->rcode;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
111
kono
parents: 67
diff changeset
76 static const char *header_file_name = "init-opinit.h";
kono
parents: 67
diff changeset
77 static const char *source_file_name = "init-opinit.c";
kono
parents: 67
diff changeset
78
kono
parents: 67
diff changeset
79 static bool
kono
parents: 67
diff changeset
80 handle_arg (const char *arg)
kono
parents: 67
diff changeset
81 {
kono
parents: 67
diff changeset
82 switch (arg[1])
kono
parents: 67
diff changeset
83 {
kono
parents: 67
diff changeset
84 case 'h':
kono
parents: 67
diff changeset
85 header_file_name = &arg[2];
kono
parents: 67
diff changeset
86 return true;
kono
parents: 67
diff changeset
87 case 'c':
kono
parents: 67
diff changeset
88 source_file_name = &arg[2];
kono
parents: 67
diff changeset
89 return true;
kono
parents: 67
diff changeset
90 default:
kono
parents: 67
diff changeset
91 return false;
kono
parents: 67
diff changeset
92 }
kono
parents: 67
diff changeset
93 }
kono
parents: 67
diff changeset
94
kono
parents: 67
diff changeset
95 static FILE *
kono
parents: 67
diff changeset
96 open_outfile (const char *file_name)
kono
parents: 67
diff changeset
97 {
kono
parents: 67
diff changeset
98 FILE *f = fopen (file_name, "w");
kono
parents: 67
diff changeset
99 if (!f)
kono
parents: 67
diff changeset
100 fatal ("cannot open file %s: %s", file_name, xstrerror (errno));
kono
parents: 67
diff changeset
101 fprintf (f,
kono
parents: 67
diff changeset
102 "/* Generated automatically by the program `genopinit'\n"
kono
parents: 67
diff changeset
103 " from the machine description file `md'. */\n\n");
kono
parents: 67
diff changeset
104 return f;
kono
parents: 67
diff changeset
105 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 int
111
kono
parents: 67
diff changeset
108 main (int argc, const char **argv)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 {
111
kono
parents: 67
diff changeset
110 FILE *h_file, *s_file;
kono
parents: 67
diff changeset
111 unsigned int i, j, n, last_kind[5];
kono
parents: 67
diff changeset
112 optab_pattern *p;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 progname = "genopinit";
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
111
kono
parents: 67
diff changeset
116 if (NUM_OPTABS > 0xffff || MAX_MACHINE_MODE >= 0xff)
kono
parents: 67
diff changeset
117 fatal ("genopinit range assumptions invalid");
kono
parents: 67
diff changeset
118
kono
parents: 67
diff changeset
119 if (!init_rtx_reader_args_cb (argc, argv, handle_arg))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 return (FATAL_EXIT_CODE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
111
kono
parents: 67
diff changeset
122 h_file = open_outfile (header_file_name);
kono
parents: 67
diff changeset
123 s_file = open_outfile (source_file_name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 /* Read the machine description. */
111
kono
parents: 67
diff changeset
126 md_rtx_info info;
kono
parents: 67
diff changeset
127 while (read_md_rtx (&info))
kono
parents: 67
diff changeset
128 switch (GET_CODE (info.def))
kono
parents: 67
diff changeset
129 {
kono
parents: 67
diff changeset
130 case DEFINE_INSN:
kono
parents: 67
diff changeset
131 case DEFINE_EXPAND:
kono
parents: 67
diff changeset
132 gen_insn (&info);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
111
kono
parents: 67
diff changeset
135 default:
kono
parents: 67
diff changeset
136 break;
kono
parents: 67
diff changeset
137 }
kono
parents: 67
diff changeset
138
kono
parents: 67
diff changeset
139 /* Sort the collected patterns. */
kono
parents: 67
diff changeset
140 patterns.qsort (pattern_cmp);
kono
parents: 67
diff changeset
141
kono
parents: 67
diff changeset
142 /* Now that we've handled the "extra" patterns, eliminate them from
kono
parents: 67
diff changeset
143 the optabs array. That way they don't get in the way below. */
kono
parents: 67
diff changeset
144 n = num_optabs;
kono
parents: 67
diff changeset
145 for (i = 0; i < n; )
kono
parents: 67
diff changeset
146 if (optabs[i].base == NULL)
kono
parents: 67
diff changeset
147 optabs[i] = optabs[--n];
kono
parents: 67
diff changeset
148 else
kono
parents: 67
diff changeset
149 ++i;
kono
parents: 67
diff changeset
150
kono
parents: 67
diff changeset
151 /* Sort the (real) optabs. Better than forcing the optabs.def file to
kono
parents: 67
diff changeset
152 remain sorted by kind. We also scrogged any real ordering with the
kono
parents: 67
diff changeset
153 purging of the X patterns above. */
kono
parents: 67
diff changeset
154 qsort (optabs, n, sizeof (optab_def), optab_kind_cmp);
kono
parents: 67
diff changeset
155
kono
parents: 67
diff changeset
156 fprintf (h_file, "#ifndef GCC_INSN_OPINIT_H\n");
kono
parents: 67
diff changeset
157 fprintf (h_file, "#define GCC_INSN_OPINIT_H 1\n");
kono
parents: 67
diff changeset
158
kono
parents: 67
diff changeset
159 /* Emit the optab enumeration for the header file. */
kono
parents: 67
diff changeset
160 fprintf (h_file, "enum optab_tag {\n");
kono
parents: 67
diff changeset
161 for (i = j = 0; i < n; ++i)
kono
parents: 67
diff changeset
162 {
kono
parents: 67
diff changeset
163 optabs[i].op = i;
kono
parents: 67
diff changeset
164 fprintf (h_file, " %s,\n", optabs[i].name);
kono
parents: 67
diff changeset
165 if (optabs[i].kind != j)
kono
parents: 67
diff changeset
166 last_kind[j++] = i - 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 }
111
kono
parents: 67
diff changeset
168 fprintf (h_file, " FIRST_CONV_OPTAB = %s,\n", optabs[last_kind[0]+1].name);
kono
parents: 67
diff changeset
169 fprintf (h_file, " LAST_CONVLIB_OPTAB = %s,\n", optabs[last_kind[1]].name);
kono
parents: 67
diff changeset
170 fprintf (h_file, " LAST_CONV_OPTAB = %s,\n", optabs[last_kind[2]].name);
kono
parents: 67
diff changeset
171 fprintf (h_file, " FIRST_NORM_OPTAB = %s,\n", optabs[last_kind[2]+1].name);
kono
parents: 67
diff changeset
172 fprintf (h_file, " LAST_NORMLIB_OPTAB = %s,\n", optabs[last_kind[3]].name);
kono
parents: 67
diff changeset
173 fprintf (h_file, " LAST_NORM_OPTAB = %s\n", optabs[i-1].name);
kono
parents: 67
diff changeset
174 fprintf (h_file, "};\n\n");
kono
parents: 67
diff changeset
175
kono
parents: 67
diff changeset
176 fprintf (h_file, "#define NUM_OPTABS %u\n", n);
kono
parents: 67
diff changeset
177 fprintf (h_file, "#define NUM_CONVLIB_OPTABS %u\n",
kono
parents: 67
diff changeset
178 last_kind[1] - last_kind[0]);
kono
parents: 67
diff changeset
179 fprintf (h_file, "#define NUM_NORMLIB_OPTABS %u\n",
kono
parents: 67
diff changeset
180 last_kind[3] - last_kind[2]);
kono
parents: 67
diff changeset
181 fprintf (h_file, "#define NUM_OPTAB_PATTERNS %u\n",
kono
parents: 67
diff changeset
182 (unsigned) patterns.length ());
kono
parents: 67
diff changeset
183
kono
parents: 67
diff changeset
184 fprintf (h_file,
kono
parents: 67
diff changeset
185 "typedef enum optab_tag optab;\n"
kono
parents: 67
diff changeset
186 "typedef enum optab_tag convert_optab;\n"
kono
parents: 67
diff changeset
187 "typedef enum optab_tag direct_optab;\n"
kono
parents: 67
diff changeset
188 "\n"
kono
parents: 67
diff changeset
189 "struct optab_libcall_d\n"
kono
parents: 67
diff changeset
190 "{\n"
kono
parents: 67
diff changeset
191 " char libcall_suffix;\n"
kono
parents: 67
diff changeset
192 " const char *libcall_basename;\n"
kono
parents: 67
diff changeset
193 " void (*libcall_gen) (optab, const char *name,\n"
kono
parents: 67
diff changeset
194 " char suffix, machine_mode);\n"
kono
parents: 67
diff changeset
195 "};\n"
kono
parents: 67
diff changeset
196 "\n"
kono
parents: 67
diff changeset
197 "struct convert_optab_libcall_d\n"
kono
parents: 67
diff changeset
198 "{\n"
kono
parents: 67
diff changeset
199 " const char *libcall_basename;\n"
kono
parents: 67
diff changeset
200 " void (*libcall_gen) (convert_optab, const char *name,\n"
kono
parents: 67
diff changeset
201 " machine_mode, machine_mode);\n"
kono
parents: 67
diff changeset
202 "};\n"
kono
parents: 67
diff changeset
203 "\n"
kono
parents: 67
diff changeset
204 "/* Given an enum insn_code, access the function to construct\n"
kono
parents: 67
diff changeset
205 " the body of that kind of insn. */\n"
kono
parents: 67
diff changeset
206 "#define GEN_FCN(CODE) (insn_data[CODE].genfun)\n"
kono
parents: 67
diff changeset
207 "\n"
kono
parents: 67
diff changeset
208 "#ifdef NUM_RTX_CODE\n"
kono
parents: 67
diff changeset
209 "/* Contains the optab used for each rtx code, and vice-versa. */\n"
kono
parents: 67
diff changeset
210 "extern const optab code_to_optab_[NUM_RTX_CODE];\n"
kono
parents: 67
diff changeset
211 "extern const enum rtx_code optab_to_code_[NUM_OPTABS];\n"
kono
parents: 67
diff changeset
212 "\n"
kono
parents: 67
diff changeset
213 "static inline optab\n"
kono
parents: 67
diff changeset
214 "code_to_optab (enum rtx_code code)\n"
kono
parents: 67
diff changeset
215 "{\n"
kono
parents: 67
diff changeset
216 " return code_to_optab_[code];\n"
kono
parents: 67
diff changeset
217 "}\n"
kono
parents: 67
diff changeset
218 "\n"
kono
parents: 67
diff changeset
219 "static inline enum rtx_code\n"
kono
parents: 67
diff changeset
220 "optab_to_code (optab op)\n"
kono
parents: 67
diff changeset
221 "{\n"
kono
parents: 67
diff changeset
222 " return optab_to_code_[op];\n"
kono
parents: 67
diff changeset
223 "}\n"
kono
parents: 67
diff changeset
224 "#endif\n"
kono
parents: 67
diff changeset
225 "\n"
kono
parents: 67
diff changeset
226 "extern const struct convert_optab_libcall_d convlib_def[NUM_CONVLIB_OPTABS];\n"
kono
parents: 67
diff changeset
227 "extern const struct optab_libcall_d normlib_def[NUM_NORMLIB_OPTABS];\n"
kono
parents: 67
diff changeset
228 "\n"
kono
parents: 67
diff changeset
229 "/* Returns the active icode for the given (encoded) optab. */\n"
kono
parents: 67
diff changeset
230 "extern enum insn_code raw_optab_handler (unsigned);\n"
kono
parents: 67
diff changeset
231 "extern bool swap_optab_enable (optab, machine_mode, bool);\n"
kono
parents: 67
diff changeset
232 "\n"
kono
parents: 67
diff changeset
233 "/* Target-dependent globals. */\n"
kono
parents: 67
diff changeset
234 "struct target_optabs {\n"
kono
parents: 67
diff changeset
235 " /* Patterns that are used by optabs that are enabled for this target. */\n"
kono
parents: 67
diff changeset
236 " bool pat_enable[NUM_OPTAB_PATTERNS];\n"
kono
parents: 67
diff changeset
237 "};\n"
kono
parents: 67
diff changeset
238 "extern void init_all_optabs (struct target_optabs *);\n"
kono
parents: 67
diff changeset
239 "\n"
kono
parents: 67
diff changeset
240 "extern struct target_optabs default_target_optabs;\n"
kono
parents: 67
diff changeset
241 "extern struct target_optabs *this_fn_optabs;\n"
kono
parents: 67
diff changeset
242 "#if SWITCHABLE_TARGET\n"
kono
parents: 67
diff changeset
243 "extern struct target_optabs *this_target_optabs;\n"
kono
parents: 67
diff changeset
244 "#else\n"
kono
parents: 67
diff changeset
245 "#define this_target_optabs (&default_target_optabs)\n"
kono
parents: 67
diff changeset
246 "#endif\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247
111
kono
parents: 67
diff changeset
248 fprintf (s_file,
kono
parents: 67
diff changeset
249 "#include \"config.h\"\n"
kono
parents: 67
diff changeset
250 "#include \"system.h\"\n"
kono
parents: 67
diff changeset
251 "#include \"coretypes.h\"\n"
kono
parents: 67
diff changeset
252 "#include \"backend.h\"\n"
kono
parents: 67
diff changeset
253 "#include \"predict.h\"\n"
kono
parents: 67
diff changeset
254 "#include \"tree.h\"\n"
kono
parents: 67
diff changeset
255 "#include \"rtl.h\"\n"
kono
parents: 67
diff changeset
256 "#include \"alias.h\"\n"
kono
parents: 67
diff changeset
257 "#include \"varasm.h\"\n"
kono
parents: 67
diff changeset
258 "#include \"stor-layout.h\"\n"
kono
parents: 67
diff changeset
259 "#include \"calls.h\"\n"
kono
parents: 67
diff changeset
260 "#include \"memmodel.h\"\n"
kono
parents: 67
diff changeset
261 "#include \"tm_p.h\"\n"
kono
parents: 67
diff changeset
262 "#include \"flags.h\"\n"
kono
parents: 67
diff changeset
263 "#include \"insn-config.h\"\n"
kono
parents: 67
diff changeset
264 "#include \"expmed.h\"\n"
kono
parents: 67
diff changeset
265 "#include \"dojump.h\"\n"
kono
parents: 67
diff changeset
266 "#include \"explow.h\"\n"
kono
parents: 67
diff changeset
267 "#include \"emit-rtl.h\"\n"
kono
parents: 67
diff changeset
268 "#include \"stmt.h\"\n"
kono
parents: 67
diff changeset
269 "#include \"expr.h\"\n"
kono
parents: 67
diff changeset
270 "#include \"insn-codes.h\"\n"
kono
parents: 67
diff changeset
271 "#include \"optabs.h\"\n"
kono
parents: 67
diff changeset
272 "\n"
kono
parents: 67
diff changeset
273 "struct optab_pat {\n"
kono
parents: 67
diff changeset
274 " unsigned scode;\n"
kono
parents: 67
diff changeset
275 " enum insn_code icode;\n"
kono
parents: 67
diff changeset
276 "};\n\n");
kono
parents: 67
diff changeset
277
kono
parents: 67
diff changeset
278 fprintf (s_file,
kono
parents: 67
diff changeset
279 "static const struct optab_pat pats[NUM_OPTAB_PATTERNS] = {\n");
kono
parents: 67
diff changeset
280 for (i = 0; patterns.iterate (i, &p); ++i)
kono
parents: 67
diff changeset
281 fprintf (s_file, " { %#08x, CODE_FOR_%s },\n", p->sort_num, p->name);
kono
parents: 67
diff changeset
282 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
283
kono
parents: 67
diff changeset
284 fprintf (s_file, "void\ninit_all_optabs (struct target_optabs *optabs)\n{\n");
kono
parents: 67
diff changeset
285 fprintf (s_file, " bool *ena = optabs->pat_enable;\n");
kono
parents: 67
diff changeset
286 for (i = 0; patterns.iterate (i, &p); ++i)
kono
parents: 67
diff changeset
287 fprintf (s_file, " ena[%u] = HAVE_%s;\n", i, p->name);
kono
parents: 67
diff changeset
288 fprintf (s_file, "}\n\n");
kono
parents: 67
diff changeset
289
kono
parents: 67
diff changeset
290 /* Perform a binary search on a pre-encoded optab+mode*2. */
kono
parents: 67
diff changeset
291 /* ??? Perhaps even better to generate a minimal perfect hash.
kono
parents: 67
diff changeset
292 Using gperf directly is awkward since it's so geared to working
kono
parents: 67
diff changeset
293 with strings. Plus we have no visibility into the ordering of
kono
parents: 67
diff changeset
294 the hash entries, which complicates the pat_enable array. */
kono
parents: 67
diff changeset
295 fprintf (s_file,
kono
parents: 67
diff changeset
296 "static int\n"
kono
parents: 67
diff changeset
297 "lookup_handler (unsigned scode)\n"
kono
parents: 67
diff changeset
298 "{\n"
kono
parents: 67
diff changeset
299 " int l = 0, h = ARRAY_SIZE (pats), m;\n"
kono
parents: 67
diff changeset
300 " while (h > l)\n"
kono
parents: 67
diff changeset
301 " {\n"
kono
parents: 67
diff changeset
302 " m = (h + l) / 2;\n"
kono
parents: 67
diff changeset
303 " if (scode == pats[m].scode)\n"
kono
parents: 67
diff changeset
304 " return m;\n"
kono
parents: 67
diff changeset
305 " else if (scode < pats[m].scode)\n"
kono
parents: 67
diff changeset
306 " h = m;\n"
kono
parents: 67
diff changeset
307 " else\n"
kono
parents: 67
diff changeset
308 " l = m + 1;\n"
kono
parents: 67
diff changeset
309 " }\n"
kono
parents: 67
diff changeset
310 " return -1;\n"
kono
parents: 67
diff changeset
311 "}\n\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
111
kono
parents: 67
diff changeset
313 fprintf (s_file,
kono
parents: 67
diff changeset
314 "enum insn_code\n"
kono
parents: 67
diff changeset
315 "raw_optab_handler (unsigned scode)\n"
kono
parents: 67
diff changeset
316 "{\n"
kono
parents: 67
diff changeset
317 " int i = lookup_handler (scode);\n"
kono
parents: 67
diff changeset
318 " return (i >= 0 && this_fn_optabs->pat_enable[i]\n"
kono
parents: 67
diff changeset
319 " ? pats[i].icode : CODE_FOR_nothing);\n"
kono
parents: 67
diff changeset
320 "}\n\n");
kono
parents: 67
diff changeset
321
kono
parents: 67
diff changeset
322 fprintf (s_file,
kono
parents: 67
diff changeset
323 "bool\n"
kono
parents: 67
diff changeset
324 "swap_optab_enable (optab op, machine_mode m, bool set)\n"
kono
parents: 67
diff changeset
325 "{\n"
kono
parents: 67
diff changeset
326 " unsigned scode = (op << 16) | m;\n"
kono
parents: 67
diff changeset
327 " int i = lookup_handler (scode);\n"
kono
parents: 67
diff changeset
328 " if (i >= 0)\n"
kono
parents: 67
diff changeset
329 " {\n"
kono
parents: 67
diff changeset
330 " bool ret = this_fn_optabs->pat_enable[i];\n"
kono
parents: 67
diff changeset
331 " this_fn_optabs->pat_enable[i] = set;\n"
kono
parents: 67
diff changeset
332 " return ret;\n"
kono
parents: 67
diff changeset
333 " }\n"
kono
parents: 67
diff changeset
334 " else\n"
kono
parents: 67
diff changeset
335 " {\n"
kono
parents: 67
diff changeset
336 " gcc_assert (!set);\n"
kono
parents: 67
diff changeset
337 " return false;\n"
kono
parents: 67
diff changeset
338 " }\n"
kono
parents: 67
diff changeset
339 "}\n\n");
kono
parents: 67
diff changeset
340
kono
parents: 67
diff changeset
341 /* C++ (even G++) does not support (non-trivial) designated initializers.
kono
parents: 67
diff changeset
342 To work around that, generate these arrays programatically rather than
kono
parents: 67
diff changeset
343 by our traditional multiple inclusion of def files. */
kono
parents: 67
diff changeset
344
kono
parents: 67
diff changeset
345 fprintf (s_file,
kono
parents: 67
diff changeset
346 "const struct convert_optab_libcall_d "
kono
parents: 67
diff changeset
347 "convlib_def[NUM_CONVLIB_OPTABS] = {\n");
kono
parents: 67
diff changeset
348 for (i = last_kind[0] + 1; i <= last_kind[1]; ++i)
kono
parents: 67
diff changeset
349 fprintf (s_file, " { %s, %s },\n", optabs[i].base, optabs[i].libcall);
kono
parents: 67
diff changeset
350 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
351
kono
parents: 67
diff changeset
352 fprintf (s_file,
kono
parents: 67
diff changeset
353 "const struct optab_libcall_d "
kono
parents: 67
diff changeset
354 "normlib_def[NUM_NORMLIB_OPTABS] = {\n");
kono
parents: 67
diff changeset
355 for (i = last_kind[2] + 1; i <= last_kind[3]; ++i)
kono
parents: 67
diff changeset
356 fprintf (s_file, " { %s, %s, %s },\n",
kono
parents: 67
diff changeset
357 optabs[i].suffix, optabs[i].base, optabs[i].libcall);
kono
parents: 67
diff changeset
358 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
359
kono
parents: 67
diff changeset
360 fprintf (s_file, "enum rtx_code const optab_to_code_[NUM_OPTABS] = {\n");
kono
parents: 67
diff changeset
361 for (i = 0; i < n; ++i)
kono
parents: 67
diff changeset
362 fprintf (s_file, " %s,\n", rtx_upname[optabs[i].fcode]);
kono
parents: 67
diff changeset
363 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
364
kono
parents: 67
diff changeset
365 qsort (optabs, n, sizeof (optab_def), optab_rcode_cmp);
kono
parents: 67
diff changeset
366
kono
parents: 67
diff changeset
367 fprintf (s_file, "const optab code_to_optab_[NUM_RTX_CODE] = {\n");
kono
parents: 67
diff changeset
368 for (j = 0; optabs[j].rcode == UNKNOWN; ++j)
kono
parents: 67
diff changeset
369 continue;
kono
parents: 67
diff changeset
370 for (i = 0; i < NON_GENERATOR_NUM_RTX_CODE; ++i)
kono
parents: 67
diff changeset
371 {
kono
parents: 67
diff changeset
372 if (j < n && optabs[j].rcode == i)
kono
parents: 67
diff changeset
373 fprintf (s_file, " %s,\n", optabs[j++].name);
kono
parents: 67
diff changeset
374 else
kono
parents: 67
diff changeset
375 fprintf (s_file, " unknown_optab,\n");
kono
parents: 67
diff changeset
376 }
kono
parents: 67
diff changeset
377 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
378
kono
parents: 67
diff changeset
379 fprintf (h_file, "#endif\n");
kono
parents: 67
diff changeset
380 return (fclose (h_file) == 0 && fclose (s_file) == 0
kono
parents: 67
diff changeset
381 ? SUCCESS_EXIT_CODE : FATAL_EXIT_CODE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 }