GCC Middle and Back End API Reference
gimple-match.h
Go to the documentation of this file.
1/* Gimple simplify definitions.
2
3 Copyright (C) 2011-2024 Free Software Foundation, Inc.
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/* Represents the condition under which an operation should happen,
27 and the value to use otherwise. The condition applies elementwise
28 (as for VEC_COND_EXPR) if the values are vectors. */
30{
31public:
32 enum uncond { UNCOND };
33
34 /* Build an unconditional op. */
39
41
42 /* The condition under which the operation occurs, or NULL_TREE
43 if the operation is unconditional. */
45
46 /* The value to use when the condition is false. This is NULL_TREE if
47 the operation is unconditional or if the value doesn't matter. */
49
50 /* The length and bias parameters to be applied to a vector operation,
51 so that the condition is forced to false when the element index is
52 >= LEN + BIAS. These are NULL_TREE if the operation isn't applied
53 to vectors, or if no such length limit is in use. */
56};
57
58inline
60 : cond (cond_in), else_value (else_value_in), len (NULL_TREE),
61 bias (NULL_TREE)
62{
63}
64
65inline
67 tree len_in, tree bias_in)
68 : cond (cond_in), else_value (else_value_in), len (len_in), bias (bias_in)
69{}
70
71/* Return a gimple_match_cond with the same condition but with an
72 arbitrary ELSE_VALUE. */
73
79
80/* Represents an operation to be simplified, or the result of the
81 simplification. */
83{
84public:
86 gimple_match_op (const gimple_match_cond &, code_helper, tree, unsigned int);
101
102 void set_op (code_helper, tree, unsigned int);
103 void set_op (code_helper, tree, tree);
104 void set_op (code_helper, tree, tree, tree);
105 void set_op (code_helper, tree, tree, tree, tree);
106 void set_op (code_helper, tree, tree, tree, tree, bool);
111 void set_value (tree);
112
113 tree op_or_null (unsigned int) const;
114
115 bool resimplify (gimple_seq *, tree (*)(tree));
116
117 /* The maximum value of NUM_OPS. */
118 static const unsigned int MAX_NUM_OPS = 7;
119
120 /* The conditions under which the operation is performed, and the value to
121 use as a fallback. */
123
124 /* The operation being performed. */
126
127 /* The type of the result. */
129
130 /* For a BIT_FIELD_REF, whether the group of bits is stored in reverse order
131 from the target order. */
133
134 /* The number of operands to CODE. */
135 unsigned int num_ops;
136
137 /* The operands to CODE. Only the first NUM_OPS entries are meaningful. */
139
141};
142
143inline
145 : cond (gimple_match_cond::UNCOND), type (NULL_TREE), reverse (false),
146 num_ops (0)
147{
148}
149
150/* Constructor that takes the condition, code, type and number of
151 operands, but leaves the caller to fill in the operands. */
152
153inline
155 code_helper code_in, tree type_in,
156 unsigned int num_ops_in)
157 : cond (cond_in), code (code_in), type (type_in), reverse (false),
158 num_ops (num_ops_in)
159{
160}
161
162/* Constructors for various numbers of operands. */
163
164inline
166 code_helper code_in, tree type_in,
167 tree op0)
168 : cond (cond_in), code (code_in), type (type_in), reverse (false),
169 num_ops (1)
170{
171 ops[0] = op0;
172}
173
174inline
176 code_helper code_in, tree type_in,
177 tree op0, tree op1)
178 : cond (cond_in), code (code_in), type (type_in), reverse (false),
179 num_ops (2)
180{
181 ops[0] = op0;
182 ops[1] = op1;
183}
184
185inline
187 code_helper code_in, tree type_in,
188 tree op0, tree op1, tree op2)
189 : cond (cond_in), code (code_in), type (type_in), reverse (false),
190 num_ops (3)
191{
192 ops[0] = op0;
193 ops[1] = op1;
194 ops[2] = op2;
195}
196
197inline
199 code_helper code_in, tree type_in,
200 tree op0, tree op1, tree op2, tree op3)
201 : cond (cond_in), code (code_in), type (type_in), reverse (false),
202 num_ops (4)
203{
204 ops[0] = op0;
205 ops[1] = op1;
206 ops[2] = op2;
207 ops[3] = op3;
208}
209
210inline
212 code_helper code_in, tree type_in,
213 tree op0, tree op1, tree op2, tree op3,
214 tree op4)
215 : cond (cond_in), code (code_in), type (type_in), reverse (false),
216 num_ops (5)
217{
218 ops[0] = op0;
219 ops[1] = op1;
220 ops[2] = op2;
221 ops[3] = op3;
222 ops[4] = op4;
223}
224
225inline
227 code_helper code_in, tree type_in,
228 tree op0, tree op1, tree op2, tree op3,
229 tree op4, tree op5)
230 : cond (cond_in), code (code_in), type (type_in), reverse (false),
231 num_ops (6)
232{
233 ops[0] = op0;
234 ops[1] = op1;
235 ops[2] = op2;
236 ops[3] = op3;
237 ops[4] = op4;
238 ops[5] = op5;
239}
240
241inline
243 code_helper code_in, tree type_in,
244 tree op0, tree op1, tree op2, tree op3,
245 tree op4, tree op5, tree op6)
246 : cond (cond_in), code (code_in), type (type_in), reverse (false),
247 num_ops (7)
248{
249 ops[0] = op0;
250 ops[1] = op1;
251 ops[2] = op2;
252 ops[3] = op3;
253 ops[4] = op4;
254 ops[5] = op5;
255 ops[6] = op6;
256}
257
258/* Change the operation performed to CODE_IN, the type of the result to
259 TYPE_IN, and the number of operands to NUM_OPS_IN. The caller needs
260 to set the operands itself. */
261
262inline void
264 unsigned int num_ops_in)
265{
266 code = code_in;
267 type = type_in;
268 num_ops = num_ops_in;
269}
270
271/* Functions for changing the operation performed, for various numbers
272 of operands. */
273
274inline void
276{
277 code = code_in;
278 type = type_in;
279 num_ops = 1;
280 ops[0] = op0;
281}
282
283inline void
285{
286 code = code_in;
287 type = type_in;
288 num_ops = 2;
289 ops[0] = op0;
290 ops[1] = op1;
291}
292
293inline void
295 tree op0, tree op1, tree op2)
296{
297 code = code_in;
298 type = type_in;
299 num_ops = 3;
300 ops[0] = op0;
301 ops[1] = op1;
302 ops[2] = op2;
303}
304
305inline void
307 tree op0, tree op1, tree op2, bool reverse_in)
308{
309 code = code_in;
310 type = type_in;
311 reverse = reverse_in;
312 num_ops = 3;
313 ops[0] = op0;
314 ops[1] = op1;
315 ops[2] = op2;
316}
317
318inline void
320 tree op0, tree op1, tree op2, tree op3)
321{
322 code = code_in;
323 type = type_in;
324 num_ops = 4;
325 ops[0] = op0;
326 ops[1] = op1;
327 ops[2] = op2;
328 ops[3] = op3;
329}
330
331inline void
333 tree op0, tree op1, tree op2, tree op3, tree op4)
334{
335 code = code_in;
336 type = type_in;
337 num_ops = 5;
338 ops[0] = op0;
339 ops[1] = op1;
340 ops[2] = op2;
341 ops[3] = op3;
342 ops[4] = op4;
343}
344
345inline void
347 tree op0, tree op1, tree op2, tree op3, tree op4,
348 tree op5)
349{
350 code = code_in;
351 type = type_in;
352 num_ops = 6;
353 ops[0] = op0;
354 ops[1] = op1;
355 ops[2] = op2;
356 ops[3] = op3;
357 ops[4] = op4;
358 ops[5] = op5;
359}
360
361inline void
363 tree op0, tree op1, tree op2, tree op3, tree op4,
364 tree op5, tree op6)
365{
366 code = code_in;
367 type = type_in;
368 num_ops = 7;
369 ops[0] = op0;
370 ops[1] = op1;
371 ops[2] = op2;
372 ops[3] = op3;
373 ops[4] = op4;
374 ops[5] = op5;
375 ops[6] = op6;
376}
377
378/* Set the "operation" to be the single value VALUE, such as a constant
379 or SSA_NAME. */
380
381inline void
383{
384 set_op (TREE_CODE (value), TREE_TYPE (value), value);
385}
386
387/* Return the value of operand I, or null if there aren't that many
388 operands. */
389
390inline tree
391gimple_match_op::op_or_null (unsigned int i) const
392{
393 return i < num_ops ? ops[i] : NULL_TREE;
394}
395
396/* Return whether OP is a non-expression result and a gimple value. */
397
398inline bool
400{
401 return (op->code.is_tree_code ()
402 && (TREE_CODE_LENGTH ((tree_code) op->code) == 0
403 || ((tree_code) op->code) == ADDR_EXPR)
404 && is_gimple_val (op->ops[0]));
405}
406
407extern tree (*mprts_hook) (gimple_match_op *);
408
411 tree (*)(tree), tree (*)(tree));
413 tree res = NULL_TREE);
415
421
422#ifdef GCC_OPTABS_TREE_H
426#endif
427
429
430#endif /* GCC_GIMPLE_MATCH_H */
Definition tree.h:81
bool is_tree_code() const
Definition tree.h:91
Definition gimple-match.h:30
gimple_match_cond any_else() const
Definition gimple-match.h:75
gimple_match_cond(uncond)
Definition gimple-match.h:35
tree bias
Definition gimple-match.h:55
tree cond
Definition gimple-match.h:44
tree else_value
Definition gimple-match.h:48
tree len
Definition gimple-match.h:54
uncond
Definition gimple-match.h:32
@ UNCOND
Definition gimple-match.h:32
Definition gimple-match.h:83
void set_value(tree)
Definition gimple-match.h:382
bool resimplify(gimple_seq *, tree(*)(tree))
Definition gimple-match-exports.cc:106
tree ops[MAX_NUM_OPS]
Definition gimple-match.h:138
code_helper code
Definition gimple-match.h:125
tree op_or_null(unsigned int) const
Definition gimple-match.h:391
void set_op(code_helper, tree, unsigned int)
Definition gimple-match.h:263
gimple_match_op()
Definition gimple-match.h:144
unsigned int num_ops
Definition gimple-match.h:135
bool reverse
Definition gimple-match.h:132
bool operands_occurs_in_abnormal_phi() const
Definition gimple-match-exports.cc:132
gimple_match_cond cond
Definition gimple-match.h:122
tree type
Definition gimple-match.h:128
static const unsigned int MAX_NUM_OPS
Definition gimple-match.h:118
union tree_node * tree
Definition coretypes.h:97
internal_fn
Definition genmatch.cc:1005
tree_code
Definition genmatch.cc:992
bool is_gimple_val(tree t)
Definition gimple-expr.cc:836
bool directly_supported_p(code_helper code, tree type, optab_subtype query_type)
Definition gimple-match-exports.cc:1382
void maybe_build_generic_op(gimple_match_op *)
Definition gimple-match-exports.cc:220
int first_commutative_argument(code_helper, tree)
Definition gimple-match-exports.cc:1352
internal_fn get_conditional_internal_fn(code_helper, tree)
Definition gimple-match-exports.cc:1426
bool associative_binary_op_p(code_helper, tree)
Definition gimple-match-exports.cc:1370
bool gimple_extract_op(gimple *, gimple_match_op *)
Definition gimple-match-exports.cc:852
tree(* mprts_hook)(gimple_match_op *)
Definition gimple-match-exports.cc:51
bool gimple_simplified_result_is_gimple_val(const gimple_match_op *op)
Definition gimple-match.h:399
tree maybe_push_res_to_seq(gimple_match_op *, gimple_seq *, tree res=NULL_TREE)
Definition gimple-match-exports.cc:458
bool commutative_ternary_op_p(code_helper, tree)
Definition gimple-match-exports.cc:1340
code_helper canonicalize_code(code_helper, tree)
Definition gimple-match-exports.cc:1317
bool gimple_simplify(gimple *, gimple_match_op *, gimple_seq *, tree(*)(tree), tree(*)(tree))
Definition gimple-match-exports.cc:862
bool commutative_binary_op_p(code_helper, tree)
Definition gimple-match-exports.cc:1328
optab_subtype
Definition optabs-tree.h:29
@ optab_default
Definition optabs-tree.h:30
i
Definition poly-int.h:776
Definition gimple.h:221
Definition gengtype.h:252
#define false
Definition system.h:888
#define TREE_CODE(NODE)
Definition tree.h:324
#define TREE_TYPE(NODE)
Definition tree.h:512
#define TREE_CODE_LENGTH(CODE)
Definition tree.h:301
#define NULL_TREE
Definition tree.h:317