]> gcc.gnu.org Git - gcc.git/blame - gcc/gimple-match.h
Daily bump.
[gcc.git] / gcc / gimple-match.h
CommitLineData
3d2cf79f
RB
1/* Gimple simplify definitions.
2
a5544970 3 Copyright (C) 2011-2019 Free Software Foundation, Inc.
3d2cf79f
RB
4 Contributed by Richard Guenther <rguenther@suse.de>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#ifndef GCC_GIMPLE_MATCH_H
23#define GCC_GIMPLE_MATCH_H
24
25
26/* Helper to transparently allow tree codes and builtin function codes
27 exist in one storage entity. */
28class code_helper
29{
30public:
31 code_helper () {}
32 code_helper (tree_code code) : rep ((int) code) {}
c9e926ce 33 code_helper (combined_fn fn) : rep (-(int) fn) {}
3d2cf79f 34 operator tree_code () const { return (tree_code) rep; }
c9e926ce 35 operator combined_fn () const { return (combined_fn) -rep; }
3d2cf79f
RB
36 bool is_tree_code () const { return rep > 0; }
37 bool is_fn_code () const { return rep < 0; }
38 int get_rep () const { return rep; }
39private:
40 int rep;
41};
42
6a86928d
RS
43/* Represents the condition under which an operation should happen,
44 and the value to use otherwise. The condition applies elementwise
45 (as for VEC_COND_EXPR) if the values are vectors. */
46struct gimple_match_cond
47{
48 enum uncond { UNCOND };
49
50 /* Build an unconditional op. */
51 gimple_match_cond (uncond) : cond (NULL_TREE), else_value (NULL_TREE) {}
52 gimple_match_cond (tree, tree);
53
54 gimple_match_cond any_else () const;
55
56 /* The condition under which the operation occurs, or NULL_TREE
57 if the operation is unconditional. */
58 tree cond;
59
60 /* The value to use when the condition is false. This is NULL_TREE if
61 the operation is unconditional or if the value doesn't matter. */
62 tree else_value;
63};
64
65inline
66gimple_match_cond::gimple_match_cond (tree cond_in, tree else_value_in)
67 : cond (cond_in), else_value (else_value_in)
68{
69}
70
71/* Return a gimple_match_cond with the same condition but with an
72 arbitrary ELSE_VALUE. */
73
74inline gimple_match_cond
75gimple_match_cond::any_else () const
76{
77 return gimple_match_cond (cond, NULL_TREE);
78}
79
5d75ad95
RS
80/* Represents an operation to be simplified, or the result of the
81 simplification. */
82struct gimple_match_op
83{
6a86928d
RS
84 gimple_match_op ();
85 gimple_match_op (const gimple_match_cond &, code_helper, tree, unsigned int);
86 gimple_match_op (const gimple_match_cond &,
87 code_helper, tree, tree);
88 gimple_match_op (const gimple_match_cond &,
89 code_helper, tree, tree, tree);
90 gimple_match_op (const gimple_match_cond &,
91 code_helper, tree, tree, tree, tree);
92 gimple_match_op (const gimple_match_cond &,
93 code_helper, tree, tree, tree, tree, tree);
b41d1f6e
RS
94 gimple_match_op (const gimple_match_cond &,
95 code_helper, tree, tree, tree, tree, tree, tree);
5d75ad95
RS
96
97 void set_op (code_helper, tree, unsigned int);
98 void set_op (code_helper, tree, tree);
99 void set_op (code_helper, tree, tree, tree);
100 void set_op (code_helper, tree, tree, tree, tree);
de310193 101 void set_op (code_helper, tree, tree, tree, tree, bool);
0d2b3bca 102 void set_op (code_helper, tree, tree, tree, tree, tree);
b41d1f6e 103 void set_op (code_helper, tree, tree, tree, tree, tree, tree);
5d75ad95
RS
104 void set_value (tree);
105
106 tree op_or_null (unsigned int) const;
107
108 /* The maximum value of NUM_OPS. */
b41d1f6e 109 static const unsigned int MAX_NUM_OPS = 5;
5d75ad95 110
6a86928d
RS
111 /* The conditions under which the operation is performed, and the value to
112 use as a fallback. */
113 gimple_match_cond cond;
114
5d75ad95
RS
115 /* The operation being performed. */
116 code_helper code;
117
118 /* The type of the result. */
119 tree type;
120
de310193
EB
121 /* For a BIT_FIELD_REF, whether the group of bits is stored in reverse order
122 from the target order. */
123 bool reverse;
124
5d75ad95
RS
125 /* The number of operands to CODE. */
126 unsigned int num_ops;
127
128 /* The operands to CODE. Only the first NUM_OPS entries are meaningful. */
129 tree ops[MAX_NUM_OPS];
130};
131
6a86928d
RS
132inline
133gimple_match_op::gimple_match_op ()
6fd8679f
EB
134 : cond (gimple_match_cond::UNCOND), type (NULL_TREE), reverse (false),
135 num_ops (0)
6a86928d
RS
136{
137}
138
139/* Constructor that takes the condition, code, type and number of
140 operands, but leaves the caller to fill in the operands. */
5d75ad95
RS
141
142inline
6a86928d
RS
143gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
144 code_helper code_in, tree type_in,
5d75ad95 145 unsigned int num_ops_in)
6fd8679f
EB
146 : cond (cond_in), code (code_in), type (type_in), reverse (false),
147 num_ops (num_ops_in)
5d75ad95
RS
148{
149}
150
151/* Constructors for various numbers of operands. */
152
153inline
6a86928d
RS
154gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
155 code_helper code_in, tree type_in,
5d75ad95 156 tree op0)
6fd8679f
EB
157 : cond (cond_in), code (code_in), type (type_in), reverse (false),
158 num_ops (1)
5d75ad95
RS
159{
160 ops[0] = op0;
161}
162
163inline
6a86928d
RS
164gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
165 code_helper code_in, tree type_in,
5d75ad95 166 tree op0, tree op1)
6fd8679f
EB
167 : cond (cond_in), code (code_in), type (type_in), reverse (false),
168 num_ops (2)
5d75ad95
RS
169{
170 ops[0] = op0;
171 ops[1] = op1;
172}
173
174inline
6a86928d
RS
175gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
176 code_helper code_in, tree type_in,
5d75ad95 177 tree op0, tree op1, tree op2)
6fd8679f
EB
178 : cond (cond_in), code (code_in), type (type_in), reverse (false),
179 num_ops (3)
5d75ad95
RS
180{
181 ops[0] = op0;
182 ops[1] = op1;
183 ops[2] = op2;
184}
185
0d2b3bca 186inline
6a86928d
RS
187gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
188 code_helper code_in, tree type_in,
0d2b3bca 189 tree op0, tree op1, tree op2, tree op3)
6fd8679f
EB
190 : cond (cond_in), code (code_in), type (type_in), reverse (false),
191 num_ops (4)
0d2b3bca
RS
192{
193 ops[0] = op0;
194 ops[1] = op1;
195 ops[2] = op2;
196 ops[3] = op3;
197}
198
b41d1f6e
RS
199inline
200gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
201 code_helper code_in, tree type_in,
202 tree op0, tree op1, tree op2, tree op3,
203 tree op4)
6fd8679f
EB
204 : cond (cond_in), code (code_in), type (type_in), reverse (false),
205 num_ops (5)
b41d1f6e
RS
206{
207 ops[0] = op0;
208 ops[1] = op1;
209 ops[2] = op2;
210 ops[3] = op3;
211 ops[4] = op4;
212}
213
5d75ad95
RS
214/* Change the operation performed to CODE_IN, the type of the result to
215 TYPE_IN, and the number of operands to NUM_OPS_IN. The caller needs
216 to set the operands itself. */
217
218inline void
219gimple_match_op::set_op (code_helper code_in, tree type_in,
220 unsigned int num_ops_in)
221{
222 code = code_in;
223 type = type_in;
224 num_ops = num_ops_in;
225}
226
227/* Functions for changing the operation performed, for various numbers
228 of operands. */
229
230inline void
231gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0)
232{
233 code = code_in;
234 type = type_in;
235 num_ops = 1;
236 ops[0] = op0;
237}
238
239inline void
240gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0, tree op1)
241{
242 code = code_in;
243 type = type_in;
244 num_ops = 2;
245 ops[0] = op0;
246 ops[1] = op1;
247}
248
249inline void
250gimple_match_op::set_op (code_helper code_in, tree type_in,
251 tree op0, tree op1, tree op2)
252{
253 code = code_in;
254 type = type_in;
255 num_ops = 3;
256 ops[0] = op0;
257 ops[1] = op1;
258 ops[2] = op2;
259}
260
de310193
EB
261inline void
262gimple_match_op::set_op (code_helper code_in, tree type_in,
263 tree op0, tree op1, tree op2, bool reverse_in)
264{
265 code = code_in;
266 type = type_in;
267 reverse = reverse_in;
268 num_ops = 3;
269 ops[0] = op0;
270 ops[1] = op1;
271 ops[2] = op2;
272}
273
0d2b3bca
RS
274inline void
275gimple_match_op::set_op (code_helper code_in, tree type_in,
276 tree op0, tree op1, tree op2, tree op3)
277{
278 code = code_in;
279 type = type_in;
280 num_ops = 4;
281 ops[0] = op0;
282 ops[1] = op1;
283 ops[2] = op2;
284 ops[3] = op3;
285}
286
b41d1f6e
RS
287inline void
288gimple_match_op::set_op (code_helper code_in, tree type_in,
289 tree op0, tree op1, tree op2, tree op3, tree op4)
290{
291 code = code_in;
292 type = type_in;
293 num_ops = 5;
294 ops[0] = op0;
295 ops[1] = op1;
296 ops[2] = op2;
297 ops[3] = op3;
298 ops[4] = op4;
299}
300
5d75ad95
RS
301/* Set the "operation" to be the single value VALUE, such as a constant
302 or SSA_NAME. */
303
304inline void
305gimple_match_op::set_value (tree value)
306{
307 set_op (TREE_CODE (value), TREE_TYPE (value), value);
308}
309
310/* Return the value of operand I, or null if there aren't that many
311 operands. */
312
313inline tree
314gimple_match_op::op_or_null (unsigned int i) const
315{
316 return i < num_ops ? ops[i] : NULL_TREE;
317}
318
319/* Return whether OP is a non-expression result and a gimple value. */
c0f62740
RB
320
321inline bool
5d75ad95 322gimple_simplified_result_is_gimple_val (const gimple_match_op *op)
c0f62740 323{
5d75ad95
RS
324 return (op->code.is_tree_code ()
325 && (TREE_CODE_LENGTH ((tree_code) op->code) == 0
326 || ((tree_code) op->code) == ADDR_EXPR)
327 && is_gimple_val (op->ops[0]));
c0f62740
RB
328}
329
5d75ad95 330extern tree (*mprts_hook) (gimple_match_op *);
34050b6b 331
5d75ad95 332bool gimple_simplify (gimple *, gimple_match_op *, gimple_seq *,
0ff093d8 333 tree (*)(tree), tree (*)(tree));
5d75ad95
RS
334bool gimple_resimplify1 (gimple_seq *, gimple_match_op *, tree (*)(tree));
335bool gimple_resimplify2 (gimple_seq *, gimple_match_op *, tree (*)(tree));
336bool gimple_resimplify3 (gimple_seq *, gimple_match_op *, tree (*)(tree));
0d2b3bca 337bool gimple_resimplify4 (gimple_seq *, gimple_match_op *, tree (*)(tree));
b41d1f6e 338bool gimple_resimplify5 (gimple_seq *, gimple_match_op *, tree (*)(tree));
5d75ad95
RS
339tree maybe_push_res_to_seq (gimple_match_op *, gimple_seq *,
340 tree res = NULL_TREE);
341void maybe_build_generic_op (gimple_match_op *);
3d2cf79f
RB
342
343
344#endif /* GCC_GIMPLE_MATCH_H */
This page took 2.238986 seconds and 5 git commands to generate.