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
64
65inline
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};
140
141inline
143 : cond (gimple_match_cond::UNCOND), type (NULL_TREE), reverse (false),
144 num_ops (0)
145{
146}
147
148/* Constructor that takes the condition, code, type and number of
149 operands, but leaves the caller to fill in the operands. */
150
151inline
154 unsigned int num_ops_in)
155 : cond (cond_in), code (code_in), type (type_in), reverse (false),
156 num_ops (num_ops_in)
157{
158}
159
160/* Constructors for various numbers of operands. */
161
162inline
165 tree op0)
166 : cond (cond_in), code (code_in), type (type_in), reverse (false),
167 num_ops (1)
168{
169 ops[0] = op0;
170}
171
172inline
175 tree op0, tree op1)
176 : cond (cond_in), code (code_in), type (type_in), reverse (false),
177 num_ops (2)
178{
179 ops[0] = op0;
180 ops[1] = op1;
181}
182
183inline
186 tree op0, tree op1, tree op2)
187 : cond (cond_in), code (code_in), type (type_in), reverse (false),
188 num_ops (3)
189{
190 ops[0] = op0;
191 ops[1] = op1;
192 ops[2] = op2;
193}
194
195inline
198 tree op0, tree op1, tree op2, tree op3)
199 : cond (cond_in), code (code_in), type (type_in), reverse (false),
200 num_ops (4)
201{
202 ops[0] = op0;
203 ops[1] = op1;
204 ops[2] = op2;
205 ops[3] = op3;
206}
207
208inline
211 tree op0, tree op1, tree op2, tree op3,
212 tree op4)
213 : cond (cond_in), code (code_in), type (type_in), reverse (false),
214 num_ops (5)
215{
216 ops[0] = op0;
217 ops[1] = op1;
218 ops[2] = op2;
219 ops[3] = op3;
220 ops[4] = op4;
221}
222
223inline
226 tree op0, tree op1, tree op2, tree op3,
227 tree op4, tree op5)
228 : cond (cond_in), code (code_in), type (type_in), reverse (false),
229 num_ops (6)
230{
231 ops[0] = op0;
232 ops[1] = op1;
233 ops[2] = op2;
234 ops[3] = op3;
235 ops[4] = op4;
236 ops[5] = op5;
237}
238
239inline
242 tree op0, tree op1, tree op2, tree op3,
244 : cond (cond_in), code (code_in), type (type_in), reverse (false),
245 num_ops (7)
246{
247 ops[0] = op0;
248 ops[1] = op1;
249 ops[2] = op2;
250 ops[3] = op3;
251 ops[4] = op4;
252 ops[5] = op5;
253 ops[6] = op6;
254}
255
256/* Change the operation performed to CODE_IN, the type of the result to
257 TYPE_IN, and the number of operands to NUM_OPS_IN. The caller needs
258 to set the operands itself. */
259
260inline void
268
269/* Functions for changing the operation performed, for various numbers
270 of operands. */
271
272inline void
274{
275 code = code_in;
276 type = type_in;
277 num_ops = 1;
278 ops[0] = op0;
279}
280
281inline void
283{
284 code = code_in;
285 type = type_in;
286 num_ops = 2;
287 ops[0] = op0;
288 ops[1] = op1;
289}
290
291inline void
293 tree op0, tree op1, tree op2)
294{
295 code = code_in;
296 type = type_in;
297 num_ops = 3;
298 ops[0] = op0;
299 ops[1] = op1;
300 ops[2] = op2;
301}
302
303inline void
305 tree op0, tree op1, tree op2, bool reverse_in)
306{
307 code = code_in;
308 type = type_in;
310 num_ops = 3;
311 ops[0] = op0;
312 ops[1] = op1;
313 ops[2] = op2;
314}
315
316inline void
318 tree op0, tree op1, tree op2, tree op3)
319{
320 code = code_in;
321 type = type_in;
322 num_ops = 4;
323 ops[0] = op0;
324 ops[1] = op1;
325 ops[2] = op2;
326 ops[3] = op3;
327}
328
329inline void
331 tree op0, tree op1, tree op2, tree op3, tree op4)
332{
333 code = code_in;
334 type = type_in;
335 num_ops = 5;
336 ops[0] = op0;
337 ops[1] = op1;
338 ops[2] = op2;
339 ops[3] = op3;
340 ops[4] = op4;
341}
342
343inline void
345 tree op0, tree op1, tree op2, tree op3, tree op4,
346 tree op5)
347{
348 code = code_in;
349 type = type_in;
350 num_ops = 6;
351 ops[0] = op0;
352 ops[1] = op1;
353 ops[2] = op2;
354 ops[3] = op3;
355 ops[4] = op4;
356 ops[5] = op5;
357}
358
359inline void
361 tree op0, tree op1, tree op2, tree op3, tree op4,
362 tree op5, tree op6)
363{
364 code = code_in;
365 type = type_in;
366 num_ops = 7;
367 ops[0] = op0;
368 ops[1] = op1;
369 ops[2] = op2;
370 ops[3] = op3;
371 ops[4] = op4;
372 ops[5] = op5;
373 ops[6] = op6;
374}
375
376/* Set the "operation" to be the single value VALUE, such as a constant
377 or SSA_NAME. */
378
379inline void
381{
382 set_op (TREE_CODE (value), TREE_TYPE (value), value);
383}
384
385/* Return the value of operand I, or null if there aren't that many
386 operands. */
387
388inline tree
389gimple_match_op::op_or_null (unsigned int i) const
390{
391 return i < num_ops ? ops[i] : NULL_TREE;
392}
393
394/* Return whether OP is a non-expression result and a gimple value. */
395
396inline bool
398{
399 return (op->code.is_tree_code ()
400 && (TREE_CODE_LENGTH ((tree_code) op->code) == 0
401 || ((tree_code) op->code) == ADDR_EXPR)
402 && is_gimple_val (op->ops[0]));
403}
404
405extern tree (*mprts_hook) (gimple_match_op *);
406
409 tree (*)(tree), tree (*)(tree));
411 tree res = NULL_TREE);
413
419
420#ifdef GCC_OPTABS_TREE_H
422#endif
423
425
426#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:380
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:389
void set_op(code_helper, tree, unsigned int)
Definition gimple-match.h:261
gimple_match_op()
Definition gimple-match.h:142
unsigned int num_ops
Definition gimple-match.h:135
bool reverse
Definition gimple-match.h: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:360
tree_code
Definition genmatch.cc:347
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
bool is_gimple_val(tree t)
Definition gimple-expr.cc:840
bool directly_supported_p(code_helper code, tree type, optab_subtype query_type)
Definition gimple-match-exports.cc:1367
void maybe_build_generic_op(gimple_match_op *)
Definition gimple-match-exports.cc:206
int first_commutative_argument(code_helper, tree)
Definition gimple-match-exports.cc:1337
internal_fn get_conditional_internal_fn(code_helper, tree)
Definition gimple-match-exports.cc:1388
bool associative_binary_op_p(code_helper, tree)
Definition gimple-match-exports.cc:1355
bool gimple_extract_op(gimple *, gimple_match_op *)
Definition gimple-match-exports.cc:837
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:397
tree maybe_push_res_to_seq(gimple_match_op *, gimple_seq *, tree res=NULL_TREE)
Definition gimple-match-exports.cc:444
bool commutative_ternary_op_p(code_helper, tree)
Definition gimple-match-exports.cc:1325
code_helper canonicalize_code(code_helper, tree)
Definition gimple-match-exports.cc:1302
bool gimple_simplify(gimple *, gimple_match_op *, gimple_seq *, tree(*)(tree), tree(*)(tree))
Definition gimple-match-exports.cc:847
bool commutative_binary_op_p(code_helper, tree)
Definition gimple-match-exports.cc:1313
optab_subtype
Definition optabs-tree.h:29
@ optab_default
Definition optabs-tree.h:30
i
Definition poly-int.h:772
Definition gimple.h:225
Definition gengtype.h:252
#define false
Definition system.h:895
#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