1 /* Gimple simplify definitions.
3 Copyright (C) 2011-2023 Free Software Foundation, Inc.
4 Contributed by Richard Guenther <rguenther@suse.de>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_GIMPLE_MATCH_H
23 #define GCC_GIMPLE_MATCH_H
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. */
29 class gimple_match_cond
32 enum uncond
{ UNCOND
};
34 /* Build an unconditional op. */
35 gimple_match_cond (uncond
) : cond (NULL_TREE
), else_value (NULL_TREE
) {}
36 gimple_match_cond (tree
, tree
);
37 gimple_match_cond (tree
, tree
, tree
, tree
);
39 gimple_match_cond
any_else () const;
41 /* The condition under which the operation occurs, or NULL_TREE
42 if the operation is unconditional. */
45 /* The value to use when the condition is false. This is NULL_TREE if
46 the operation is unconditional or if the value doesn't matter. */
49 /* The length and bias parameters to be applied to a vector operation,
50 so that the condition is forced to false when the element index is
51 >= LEN + BIAS. These are NULL_TREE if the operation isn't applied
52 to vectors, or if no such length limit is in use. */
58 gimple_match_cond::gimple_match_cond (tree cond_in
, tree else_value_in
)
59 : cond (cond_in
), else_value (else_value_in
)
64 gimple_match_cond::gimple_match_cond (tree cond_in
, tree else_value_in
,
65 tree len_in
, tree bias_in
)
66 : cond (cond_in
), else_value (else_value_in
), len (len_in
), bias (bias_in
)
69 /* Return a gimple_match_cond with the same condition but with an
70 arbitrary ELSE_VALUE. */
72 inline gimple_match_cond
73 gimple_match_cond::any_else () const
75 return gimple_match_cond (cond
, NULL_TREE
);
78 /* Represents an operation to be simplified, or the result of the
84 gimple_match_op (const gimple_match_cond
&, code_helper
, tree
, unsigned int);
85 gimple_match_op (const gimple_match_cond
&,
86 code_helper
, tree
, tree
);
87 gimple_match_op (const gimple_match_cond
&,
88 code_helper
, tree
, tree
, tree
);
89 gimple_match_op (const gimple_match_cond
&,
90 code_helper
, tree
, tree
, tree
, tree
);
91 gimple_match_op (const gimple_match_cond
&,
92 code_helper
, tree
, tree
, tree
, tree
, tree
);
93 gimple_match_op (const gimple_match_cond
&,
94 code_helper
, tree
, tree
, tree
, tree
, tree
, tree
);
96 void set_op (code_helper
, tree
, unsigned int);
97 void set_op (code_helper
, tree
, tree
);
98 void set_op (code_helper
, tree
, tree
, tree
);
99 void set_op (code_helper
, tree
, tree
, tree
, tree
);
100 void set_op (code_helper
, tree
, tree
, tree
, tree
, bool);
101 void set_op (code_helper
, tree
, tree
, tree
, tree
, tree
);
102 void set_op (code_helper
, tree
, tree
, tree
, tree
, tree
, tree
);
103 void set_value (tree
);
105 tree
op_or_null (unsigned int) const;
107 bool resimplify (gimple_seq
*, tree (*)(tree
));
109 /* The maximum value of NUM_OPS. */
110 static const unsigned int MAX_NUM_OPS
= 7;
112 /* The conditions under which the operation is performed, and the value to
113 use as a fallback. */
114 gimple_match_cond cond
;
116 /* The operation being performed. */
119 /* The type of the result. */
122 /* For a BIT_FIELD_REF, whether the group of bits is stored in reverse order
123 from the target order. */
126 /* The number of operands to CODE. */
127 unsigned int num_ops
;
129 /* The operands to CODE. Only the first NUM_OPS entries are meaningful. */
130 tree ops
[MAX_NUM_OPS
];
134 gimple_match_op::gimple_match_op ()
135 : cond (gimple_match_cond::UNCOND
), type (NULL_TREE
), reverse (false),
140 /* Constructor that takes the condition, code, type and number of
141 operands, but leaves the caller to fill in the operands. */
144 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
145 code_helper code_in
, tree type_in
,
146 unsigned int num_ops_in
)
147 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
152 /* Constructors for various numbers of operands. */
155 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
156 code_helper code_in
, tree type_in
,
158 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
165 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
166 code_helper code_in
, tree type_in
,
168 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
176 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
177 code_helper code_in
, tree type_in
,
178 tree op0
, tree op1
, tree op2
)
179 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
188 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
189 code_helper code_in
, tree type_in
,
190 tree op0
, tree op1
, tree op2
, tree op3
)
191 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
201 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
202 code_helper code_in
, tree type_in
,
203 tree op0
, tree op1
, tree op2
, tree op3
,
205 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
215 /* Change the operation performed to CODE_IN, the type of the result to
216 TYPE_IN, and the number of operands to NUM_OPS_IN. The caller needs
217 to set the operands itself. */
220 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
221 unsigned int num_ops_in
)
225 num_ops
= num_ops_in
;
228 /* Functions for changing the operation performed, for various numbers
232 gimple_match_op::set_op (code_helper code_in
, tree type_in
, tree op0
)
241 gimple_match_op::set_op (code_helper code_in
, tree type_in
, tree op0
, tree op1
)
251 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
252 tree op0
, tree op1
, tree op2
)
263 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
264 tree op0
, tree op1
, tree op2
, bool reverse_in
)
268 reverse
= reverse_in
;
276 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
277 tree op0
, tree op1
, tree op2
, tree op3
)
289 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
290 tree op0
, tree op1
, tree op2
, tree op3
, tree op4
)
302 /* Set the "operation" to be the single value VALUE, such as a constant
306 gimple_match_op::set_value (tree value
)
308 set_op (TREE_CODE (value
), TREE_TYPE (value
), value
);
311 /* Return the value of operand I, or null if there aren't that many
315 gimple_match_op::op_or_null (unsigned int i
) const
317 return i
< num_ops
? ops
[i
] : NULL_TREE
;
320 /* Return whether OP is a non-expression result and a gimple value. */
323 gimple_simplified_result_is_gimple_val (const gimple_match_op
*op
)
325 return (op
->code
.is_tree_code ()
326 && (TREE_CODE_LENGTH ((tree_code
) op
->code
) == 0
327 || ((tree_code
) op
->code
) == ADDR_EXPR
)
328 && is_gimple_val (op
->ops
[0]));
331 extern tree (*mprts_hook
) (gimple_match_op
*);
333 bool gimple_extract_op (gimple
*, gimple_match_op
*);
334 bool gimple_simplify (gimple
*, gimple_match_op
*, gimple_seq
*,
335 tree (*)(tree
), tree (*)(tree
));
336 tree
maybe_push_res_to_seq (gimple_match_op
*, gimple_seq
*,
337 tree res
= NULL_TREE
);
338 void maybe_build_generic_op (gimple_match_op
*);
340 bool commutative_binary_op_p (code_helper
, tree
);
341 bool commutative_ternary_op_p (code_helper
, tree
);
342 int first_commutative_argument (code_helper
, tree
);
343 bool associative_binary_op_p (code_helper
, tree
);
344 code_helper
canonicalize_code (code_helper
, tree
);
346 #ifdef GCC_OPTABS_TREE_H
347 bool directly_supported_p (code_helper
, tree
, optab_subtype
= optab_default
);
350 internal_fn
get_conditional_internal_fn (code_helper
, tree
);
352 #endif /* GCC_GIMPLE_MATCH_H */