annotate gcc/genopinit.c @ 132:d34655255c78

update gcc-8.2
author mir3636
date Thu, 25 Oct 2018 10:21:07 +0900
parents 84e7813d76e9
children 1830386684a0
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.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 1993-2018 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
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
107 /* Declare the maybe_code_for_* function for ONAME, and provide
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
108 an inline definition of the assserting code_for_* wrapper. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
110 static void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
111 handle_overloaded_code_for (FILE *file, overloaded_name *oname)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
112 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
113 fprintf (file, "\nextern insn_code maybe_code_for_%s (", oname->name);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
114 for (unsigned int i = 0; i < oname->arg_types.length (); ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
115 fprintf (file, "%s%s", i == 0 ? "" : ", ", oname->arg_types[i]);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
116 fprintf (file, ");\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
117
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
118 fprintf (file, "inline insn_code\ncode_for_%s (", oname->name);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
119 for (unsigned int i = 0; i < oname->arg_types.length (); ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
120 fprintf (file, "%s%s arg%d", i == 0 ? "" : ", ", oname->arg_types[i], i);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
121 fprintf (file, ")\n{\n insn_code code = maybe_code_for_%s (", oname->name);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
122 for (unsigned int i = 0; i < oname->arg_types.length (); ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
123 fprintf (file, "%sarg%d", i == 0 ? "" : ", ", i);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
124 fprintf (file,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
125 ");\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
126 " gcc_assert (code != CODE_FOR_nothing);\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
127 " return code;\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
128 "}\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
129 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
130
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
131 /* Declare the maybe_gen_* function for ONAME, and provide
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
132 an inline definition of the assserting gen_* wrapper. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
133
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
134 static void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
135 handle_overloaded_gen (FILE *file, overloaded_name *oname)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
136 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
137 pattern_stats stats;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138 get_pattern_stats (&stats, XVEC (oname->first_instance->insn, 1));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
139
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
140 fprintf (file, "\nextern rtx maybe_gen_%s (", oname->name);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
141 for (unsigned int i = 0; i < oname->arg_types.length (); ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
142 fprintf (file, "%s%s", i == 0 ? "" : ", ", oname->arg_types[i]);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
143 for (int i = 0; i < stats.num_generator_args; ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
144 fprintf (file, ", rtx");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
145 fprintf (file, ");\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
146
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
147 fprintf (file, "inline rtx\ngen_%s (", oname->name);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
148 for (unsigned int i = 0; i < oname->arg_types.length (); ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
149 fprintf (file, "%s%s arg%d", i == 0 ? "" : ", ", oname->arg_types[i], i);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
150 for (int i = 0; i < stats.num_generator_args; ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
151 fprintf (file, ", rtx x%d", i);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
152 fprintf (file, ")\n{\n rtx res = maybe_gen_%s (", oname->name);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
153 for (unsigned int i = 0; i < oname->arg_types.length (); ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
154 fprintf (file, "%sarg%d", i == 0 ? "" : ", ", i);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
155 for (int i = 0; i < stats.num_generator_args; ++i)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
156 fprintf (file, ", x%d", i);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
157 fprintf (file,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
158 ");\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
159 " gcc_assert (res);\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
160 " return res;\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
161 "}\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
162 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
163
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 int
111
kono
parents: 67
diff changeset
165 main (int argc, const char **argv)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 {
111
kono
parents: 67
diff changeset
167 FILE *h_file, *s_file;
kono
parents: 67
diff changeset
168 unsigned int i, j, n, last_kind[5];
kono
parents: 67
diff changeset
169 optab_pattern *p;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 progname = "genopinit";
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172
111
kono
parents: 67
diff changeset
173 if (NUM_OPTABS > 0xffff || MAX_MACHINE_MODE >= 0xff)
kono
parents: 67
diff changeset
174 fatal ("genopinit range assumptions invalid");
kono
parents: 67
diff changeset
175
kono
parents: 67
diff changeset
176 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
177 return (FATAL_EXIT_CODE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
111
kono
parents: 67
diff changeset
179 h_file = open_outfile (header_file_name);
kono
parents: 67
diff changeset
180 s_file = open_outfile (source_file_name);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 /* Read the machine description. */
111
kono
parents: 67
diff changeset
183 md_rtx_info info;
kono
parents: 67
diff changeset
184 while (read_md_rtx (&info))
kono
parents: 67
diff changeset
185 switch (GET_CODE (info.def))
kono
parents: 67
diff changeset
186 {
kono
parents: 67
diff changeset
187 case DEFINE_INSN:
kono
parents: 67
diff changeset
188 case DEFINE_EXPAND:
kono
parents: 67
diff changeset
189 gen_insn (&info);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191
111
kono
parents: 67
diff changeset
192 default:
kono
parents: 67
diff changeset
193 break;
kono
parents: 67
diff changeset
194 }
kono
parents: 67
diff changeset
195
kono
parents: 67
diff changeset
196 /* Sort the collected patterns. */
kono
parents: 67
diff changeset
197 patterns.qsort (pattern_cmp);
kono
parents: 67
diff changeset
198
kono
parents: 67
diff changeset
199 /* Now that we've handled the "extra" patterns, eliminate them from
kono
parents: 67
diff changeset
200 the optabs array. That way they don't get in the way below. */
kono
parents: 67
diff changeset
201 n = num_optabs;
kono
parents: 67
diff changeset
202 for (i = 0; i < n; )
kono
parents: 67
diff changeset
203 if (optabs[i].base == NULL)
kono
parents: 67
diff changeset
204 optabs[i] = optabs[--n];
kono
parents: 67
diff changeset
205 else
kono
parents: 67
diff changeset
206 ++i;
kono
parents: 67
diff changeset
207
kono
parents: 67
diff changeset
208 /* Sort the (real) optabs. Better than forcing the optabs.def file to
kono
parents: 67
diff changeset
209 remain sorted by kind. We also scrogged any real ordering with the
kono
parents: 67
diff changeset
210 purging of the X patterns above. */
kono
parents: 67
diff changeset
211 qsort (optabs, n, sizeof (optab_def), optab_kind_cmp);
kono
parents: 67
diff changeset
212
kono
parents: 67
diff changeset
213 fprintf (h_file, "#ifndef GCC_INSN_OPINIT_H\n");
kono
parents: 67
diff changeset
214 fprintf (h_file, "#define GCC_INSN_OPINIT_H 1\n");
kono
parents: 67
diff changeset
215
kono
parents: 67
diff changeset
216 /* Emit the optab enumeration for the header file. */
kono
parents: 67
diff changeset
217 fprintf (h_file, "enum optab_tag {\n");
kono
parents: 67
diff changeset
218 for (i = j = 0; i < n; ++i)
kono
parents: 67
diff changeset
219 {
kono
parents: 67
diff changeset
220 optabs[i].op = i;
kono
parents: 67
diff changeset
221 fprintf (h_file, " %s,\n", optabs[i].name);
kono
parents: 67
diff changeset
222 if (optabs[i].kind != j)
kono
parents: 67
diff changeset
223 last_kind[j++] = i - 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 }
111
kono
parents: 67
diff changeset
225 fprintf (h_file, " FIRST_CONV_OPTAB = %s,\n", optabs[last_kind[0]+1].name);
kono
parents: 67
diff changeset
226 fprintf (h_file, " LAST_CONVLIB_OPTAB = %s,\n", optabs[last_kind[1]].name);
kono
parents: 67
diff changeset
227 fprintf (h_file, " LAST_CONV_OPTAB = %s,\n", optabs[last_kind[2]].name);
kono
parents: 67
diff changeset
228 fprintf (h_file, " FIRST_NORM_OPTAB = %s,\n", optabs[last_kind[2]+1].name);
kono
parents: 67
diff changeset
229 fprintf (h_file, " LAST_NORMLIB_OPTAB = %s,\n", optabs[last_kind[3]].name);
kono
parents: 67
diff changeset
230 fprintf (h_file, " LAST_NORM_OPTAB = %s\n", optabs[i-1].name);
kono
parents: 67
diff changeset
231 fprintf (h_file, "};\n\n");
kono
parents: 67
diff changeset
232
kono
parents: 67
diff changeset
233 fprintf (h_file, "#define NUM_OPTABS %u\n", n);
kono
parents: 67
diff changeset
234 fprintf (h_file, "#define NUM_CONVLIB_OPTABS %u\n",
kono
parents: 67
diff changeset
235 last_kind[1] - last_kind[0]);
kono
parents: 67
diff changeset
236 fprintf (h_file, "#define NUM_NORMLIB_OPTABS %u\n",
kono
parents: 67
diff changeset
237 last_kind[3] - last_kind[2]);
kono
parents: 67
diff changeset
238 fprintf (h_file, "#define NUM_OPTAB_PATTERNS %u\n",
kono
parents: 67
diff changeset
239 (unsigned) patterns.length ());
kono
parents: 67
diff changeset
240
kono
parents: 67
diff changeset
241 fprintf (h_file,
kono
parents: 67
diff changeset
242 "typedef enum optab_tag optab;\n"
kono
parents: 67
diff changeset
243 "typedef enum optab_tag convert_optab;\n"
kono
parents: 67
diff changeset
244 "typedef enum optab_tag direct_optab;\n"
kono
parents: 67
diff changeset
245 "\n"
kono
parents: 67
diff changeset
246 "struct optab_libcall_d\n"
kono
parents: 67
diff changeset
247 "{\n"
kono
parents: 67
diff changeset
248 " char libcall_suffix;\n"
kono
parents: 67
diff changeset
249 " const char *libcall_basename;\n"
kono
parents: 67
diff changeset
250 " void (*libcall_gen) (optab, const char *name,\n"
kono
parents: 67
diff changeset
251 " char suffix, machine_mode);\n"
kono
parents: 67
diff changeset
252 "};\n"
kono
parents: 67
diff changeset
253 "\n"
kono
parents: 67
diff changeset
254 "struct convert_optab_libcall_d\n"
kono
parents: 67
diff changeset
255 "{\n"
kono
parents: 67
diff changeset
256 " const char *libcall_basename;\n"
kono
parents: 67
diff changeset
257 " void (*libcall_gen) (convert_optab, const char *name,\n"
kono
parents: 67
diff changeset
258 " machine_mode, machine_mode);\n"
kono
parents: 67
diff changeset
259 "};\n"
kono
parents: 67
diff changeset
260 "\n"
kono
parents: 67
diff changeset
261 "/* Given an enum insn_code, access the function to construct\n"
kono
parents: 67
diff changeset
262 " the body of that kind of insn. */\n"
kono
parents: 67
diff changeset
263 "#define GEN_FCN(CODE) (insn_data[CODE].genfun)\n"
kono
parents: 67
diff changeset
264 "\n"
kono
parents: 67
diff changeset
265 "#ifdef NUM_RTX_CODE\n"
kono
parents: 67
diff changeset
266 "/* Contains the optab used for each rtx code, and vice-versa. */\n"
kono
parents: 67
diff changeset
267 "extern const optab code_to_optab_[NUM_RTX_CODE];\n"
kono
parents: 67
diff changeset
268 "extern const enum rtx_code optab_to_code_[NUM_OPTABS];\n"
kono
parents: 67
diff changeset
269 "\n"
kono
parents: 67
diff changeset
270 "static inline optab\n"
kono
parents: 67
diff changeset
271 "code_to_optab (enum rtx_code code)\n"
kono
parents: 67
diff changeset
272 "{\n"
kono
parents: 67
diff changeset
273 " return code_to_optab_[code];\n"
kono
parents: 67
diff changeset
274 "}\n"
kono
parents: 67
diff changeset
275 "\n"
kono
parents: 67
diff changeset
276 "static inline enum rtx_code\n"
kono
parents: 67
diff changeset
277 "optab_to_code (optab op)\n"
kono
parents: 67
diff changeset
278 "{\n"
kono
parents: 67
diff changeset
279 " return optab_to_code_[op];\n"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
280 "}\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
281
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
282 for (overloaded_name *oname = rtx_reader_ptr->get_overloads ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
283 oname; oname = oname->next)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
284 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
285 handle_overloaded_code_for (h_file, oname);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
286 handle_overloaded_gen (h_file, oname);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
287 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
288
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
289 fprintf (h_file,
111
kono
parents: 67
diff changeset
290 "#endif\n"
kono
parents: 67
diff changeset
291 "\n"
kono
parents: 67
diff changeset
292 "extern const struct convert_optab_libcall_d convlib_def[NUM_CONVLIB_OPTABS];\n"
kono
parents: 67
diff changeset
293 "extern const struct optab_libcall_d normlib_def[NUM_NORMLIB_OPTABS];\n"
kono
parents: 67
diff changeset
294 "\n"
kono
parents: 67
diff changeset
295 "/* Returns the active icode for the given (encoded) optab. */\n"
kono
parents: 67
diff changeset
296 "extern enum insn_code raw_optab_handler (unsigned);\n"
kono
parents: 67
diff changeset
297 "extern bool swap_optab_enable (optab, machine_mode, bool);\n"
kono
parents: 67
diff changeset
298 "\n"
kono
parents: 67
diff changeset
299 "/* Target-dependent globals. */\n"
kono
parents: 67
diff changeset
300 "struct target_optabs {\n"
kono
parents: 67
diff changeset
301 " /* Patterns that are used by optabs that are enabled for this target. */\n"
kono
parents: 67
diff changeset
302 " bool pat_enable[NUM_OPTAB_PATTERNS];\n"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
303 "\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
304 " /* Cache if the target supports vec_gather_load for at least one vector\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
305 " mode. */\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
306 " bool supports_vec_gather_load;\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
307 " bool supports_vec_gather_load_cached;\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
308 " bool supports_vec_scatter_store;\n"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
309 " bool supports_vec_scatter_store_cached;\n"
111
kono
parents: 67
diff changeset
310 "};\n"
kono
parents: 67
diff changeset
311 "extern void init_all_optabs (struct target_optabs *);\n"
kono
parents: 67
diff changeset
312 "\n"
kono
parents: 67
diff changeset
313 "extern struct target_optabs default_target_optabs;\n"
kono
parents: 67
diff changeset
314 "extern struct target_optabs *this_fn_optabs;\n"
kono
parents: 67
diff changeset
315 "#if SWITCHABLE_TARGET\n"
kono
parents: 67
diff changeset
316 "extern struct target_optabs *this_target_optabs;\n"
kono
parents: 67
diff changeset
317 "#else\n"
kono
parents: 67
diff changeset
318 "#define this_target_optabs (&default_target_optabs)\n"
kono
parents: 67
diff changeset
319 "#endif\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
111
kono
parents: 67
diff changeset
321 fprintf (s_file,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
322 "#define IN_TARGET_CODE 1\n"
111
kono
parents: 67
diff changeset
323 "#include \"config.h\"\n"
kono
parents: 67
diff changeset
324 "#include \"system.h\"\n"
kono
parents: 67
diff changeset
325 "#include \"coretypes.h\"\n"
kono
parents: 67
diff changeset
326 "#include \"backend.h\"\n"
kono
parents: 67
diff changeset
327 "#include \"predict.h\"\n"
kono
parents: 67
diff changeset
328 "#include \"tree.h\"\n"
kono
parents: 67
diff changeset
329 "#include \"rtl.h\"\n"
kono
parents: 67
diff changeset
330 "#include \"alias.h\"\n"
kono
parents: 67
diff changeset
331 "#include \"varasm.h\"\n"
kono
parents: 67
diff changeset
332 "#include \"stor-layout.h\"\n"
kono
parents: 67
diff changeset
333 "#include \"calls.h\"\n"
kono
parents: 67
diff changeset
334 "#include \"memmodel.h\"\n"
kono
parents: 67
diff changeset
335 "#include \"tm_p.h\"\n"
kono
parents: 67
diff changeset
336 "#include \"flags.h\"\n"
kono
parents: 67
diff changeset
337 "#include \"insn-config.h\"\n"
kono
parents: 67
diff changeset
338 "#include \"expmed.h\"\n"
kono
parents: 67
diff changeset
339 "#include \"dojump.h\"\n"
kono
parents: 67
diff changeset
340 "#include \"explow.h\"\n"
kono
parents: 67
diff changeset
341 "#include \"emit-rtl.h\"\n"
kono
parents: 67
diff changeset
342 "#include \"stmt.h\"\n"
kono
parents: 67
diff changeset
343 "#include \"expr.h\"\n"
kono
parents: 67
diff changeset
344 "#include \"insn-codes.h\"\n"
kono
parents: 67
diff changeset
345 "#include \"optabs.h\"\n"
kono
parents: 67
diff changeset
346 "\n"
kono
parents: 67
diff changeset
347 "struct optab_pat {\n"
kono
parents: 67
diff changeset
348 " unsigned scode;\n"
kono
parents: 67
diff changeset
349 " enum insn_code icode;\n"
kono
parents: 67
diff changeset
350 "};\n\n");
kono
parents: 67
diff changeset
351
kono
parents: 67
diff changeset
352 fprintf (s_file,
kono
parents: 67
diff changeset
353 "static const struct optab_pat pats[NUM_OPTAB_PATTERNS] = {\n");
kono
parents: 67
diff changeset
354 for (i = 0; patterns.iterate (i, &p); ++i)
kono
parents: 67
diff changeset
355 fprintf (s_file, " { %#08x, CODE_FOR_%s },\n", p->sort_num, p->name);
kono
parents: 67
diff changeset
356 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
357
kono
parents: 67
diff changeset
358 fprintf (s_file, "void\ninit_all_optabs (struct target_optabs *optabs)\n{\n");
kono
parents: 67
diff changeset
359 fprintf (s_file, " bool *ena = optabs->pat_enable;\n");
kono
parents: 67
diff changeset
360 for (i = 0; patterns.iterate (i, &p); ++i)
kono
parents: 67
diff changeset
361 fprintf (s_file, " ena[%u] = HAVE_%s;\n", i, p->name);
kono
parents: 67
diff changeset
362 fprintf (s_file, "}\n\n");
kono
parents: 67
diff changeset
363
kono
parents: 67
diff changeset
364 /* Perform a binary search on a pre-encoded optab+mode*2. */
kono
parents: 67
diff changeset
365 /* ??? Perhaps even better to generate a minimal perfect hash.
kono
parents: 67
diff changeset
366 Using gperf directly is awkward since it's so geared to working
kono
parents: 67
diff changeset
367 with strings. Plus we have no visibility into the ordering of
kono
parents: 67
diff changeset
368 the hash entries, which complicates the pat_enable array. */
kono
parents: 67
diff changeset
369 fprintf (s_file,
kono
parents: 67
diff changeset
370 "static int\n"
kono
parents: 67
diff changeset
371 "lookup_handler (unsigned scode)\n"
kono
parents: 67
diff changeset
372 "{\n"
kono
parents: 67
diff changeset
373 " int l = 0, h = ARRAY_SIZE (pats), m;\n"
kono
parents: 67
diff changeset
374 " while (h > l)\n"
kono
parents: 67
diff changeset
375 " {\n"
kono
parents: 67
diff changeset
376 " m = (h + l) / 2;\n"
kono
parents: 67
diff changeset
377 " if (scode == pats[m].scode)\n"
kono
parents: 67
diff changeset
378 " return m;\n"
kono
parents: 67
diff changeset
379 " else if (scode < pats[m].scode)\n"
kono
parents: 67
diff changeset
380 " h = m;\n"
kono
parents: 67
diff changeset
381 " else\n"
kono
parents: 67
diff changeset
382 " l = m + 1;\n"
kono
parents: 67
diff changeset
383 " }\n"
kono
parents: 67
diff changeset
384 " return -1;\n"
kono
parents: 67
diff changeset
385 "}\n\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386
111
kono
parents: 67
diff changeset
387 fprintf (s_file,
kono
parents: 67
diff changeset
388 "enum insn_code\n"
kono
parents: 67
diff changeset
389 "raw_optab_handler (unsigned scode)\n"
kono
parents: 67
diff changeset
390 "{\n"
kono
parents: 67
diff changeset
391 " int i = lookup_handler (scode);\n"
kono
parents: 67
diff changeset
392 " return (i >= 0 && this_fn_optabs->pat_enable[i]\n"
kono
parents: 67
diff changeset
393 " ? pats[i].icode : CODE_FOR_nothing);\n"
kono
parents: 67
diff changeset
394 "}\n\n");
kono
parents: 67
diff changeset
395
kono
parents: 67
diff changeset
396 fprintf (s_file,
kono
parents: 67
diff changeset
397 "bool\n"
kono
parents: 67
diff changeset
398 "swap_optab_enable (optab op, machine_mode m, bool set)\n"
kono
parents: 67
diff changeset
399 "{\n"
kono
parents: 67
diff changeset
400 " unsigned scode = (op << 16) | m;\n"
kono
parents: 67
diff changeset
401 " int i = lookup_handler (scode);\n"
kono
parents: 67
diff changeset
402 " if (i >= 0)\n"
kono
parents: 67
diff changeset
403 " {\n"
kono
parents: 67
diff changeset
404 " bool ret = this_fn_optabs->pat_enable[i];\n"
kono
parents: 67
diff changeset
405 " this_fn_optabs->pat_enable[i] = set;\n"
kono
parents: 67
diff changeset
406 " return ret;\n"
kono
parents: 67
diff changeset
407 " }\n"
kono
parents: 67
diff changeset
408 " else\n"
kono
parents: 67
diff changeset
409 " {\n"
kono
parents: 67
diff changeset
410 " gcc_assert (!set);\n"
kono
parents: 67
diff changeset
411 " return false;\n"
kono
parents: 67
diff changeset
412 " }\n"
kono
parents: 67
diff changeset
413 "}\n\n");
kono
parents: 67
diff changeset
414
kono
parents: 67
diff changeset
415 /* C++ (even G++) does not support (non-trivial) designated initializers.
kono
parents: 67
diff changeset
416 To work around that, generate these arrays programatically rather than
kono
parents: 67
diff changeset
417 by our traditional multiple inclusion of def files. */
kono
parents: 67
diff changeset
418
kono
parents: 67
diff changeset
419 fprintf (s_file,
kono
parents: 67
diff changeset
420 "const struct convert_optab_libcall_d "
kono
parents: 67
diff changeset
421 "convlib_def[NUM_CONVLIB_OPTABS] = {\n");
kono
parents: 67
diff changeset
422 for (i = last_kind[0] + 1; i <= last_kind[1]; ++i)
kono
parents: 67
diff changeset
423 fprintf (s_file, " { %s, %s },\n", optabs[i].base, optabs[i].libcall);
kono
parents: 67
diff changeset
424 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
425
kono
parents: 67
diff changeset
426 fprintf (s_file,
kono
parents: 67
diff changeset
427 "const struct optab_libcall_d "
kono
parents: 67
diff changeset
428 "normlib_def[NUM_NORMLIB_OPTABS] = {\n");
kono
parents: 67
diff changeset
429 for (i = last_kind[2] + 1; i <= last_kind[3]; ++i)
kono
parents: 67
diff changeset
430 fprintf (s_file, " { %s, %s, %s },\n",
kono
parents: 67
diff changeset
431 optabs[i].suffix, optabs[i].base, optabs[i].libcall);
kono
parents: 67
diff changeset
432 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
433
kono
parents: 67
diff changeset
434 fprintf (s_file, "enum rtx_code const optab_to_code_[NUM_OPTABS] = {\n");
kono
parents: 67
diff changeset
435 for (i = 0; i < n; ++i)
kono
parents: 67
diff changeset
436 fprintf (s_file, " %s,\n", rtx_upname[optabs[i].fcode]);
kono
parents: 67
diff changeset
437 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
438
kono
parents: 67
diff changeset
439 qsort (optabs, n, sizeof (optab_def), optab_rcode_cmp);
kono
parents: 67
diff changeset
440
kono
parents: 67
diff changeset
441 fprintf (s_file, "const optab code_to_optab_[NUM_RTX_CODE] = {\n");
kono
parents: 67
diff changeset
442 for (j = 0; optabs[j].rcode == UNKNOWN; ++j)
kono
parents: 67
diff changeset
443 continue;
kono
parents: 67
diff changeset
444 for (i = 0; i < NON_GENERATOR_NUM_RTX_CODE; ++i)
kono
parents: 67
diff changeset
445 {
kono
parents: 67
diff changeset
446 if (j < n && optabs[j].rcode == i)
kono
parents: 67
diff changeset
447 fprintf (s_file, " %s,\n", optabs[j++].name);
kono
parents: 67
diff changeset
448 else
kono
parents: 67
diff changeset
449 fprintf (s_file, " unknown_optab,\n");
kono
parents: 67
diff changeset
450 }
kono
parents: 67
diff changeset
451 fprintf (s_file, "};\n\n");
kono
parents: 67
diff changeset
452
kono
parents: 67
diff changeset
453 fprintf (h_file, "#endif\n");
kono
parents: 67
diff changeset
454 return (fclose (h_file) == 0 && fclose (s_file) == 0
kono
parents: 67
diff changeset
455 ? SUCCESS_EXIT_CODE : FATAL_EXIT_CODE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 }