1 /* Gimple simplify definitions.
3 Copyright (C) 2011-2024 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
), len
36 (NULL_TREE
), bias (NULL_TREE
) {}
37 gimple_match_cond (tree
, tree
);
38 gimple_match_cond (tree
, tree
, tree
, tree
);
40 gimple_match_cond
any_else () const;
42 /* The condition under which the operation occurs, or NULL_TREE
43 if the operation is unconditional. */
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. */
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. */
59 gimple_match_cond::gimple_match_cond (tree cond_in
, tree else_value_in
)
60 : cond (cond_in
), else_value (else_value_in
), len (NULL_TREE
),
66 gimple_match_cond::gimple_match_cond (tree cond_in
, tree else_value_in
,
67 tree len_in
, tree bias_in
)
68 : cond (cond_in
), else_value (else_value_in
), len (len_in
), bias (bias_in
)
71 /* Return a gimple_match_cond with the same condition but with an
72 arbitrary ELSE_VALUE. */
74 inline gimple_match_cond
75 gimple_match_cond::any_else () const
77 return gimple_match_cond (cond
, NULL_TREE
);
80 /* Represents an operation to be simplified, or the result of the
86 gimple_match_op (const gimple_match_cond
&, code_helper
, tree
, unsigned int);
87 gimple_match_op (const gimple_match_cond
&,
88 code_helper
, tree
, tree
);
89 gimple_match_op (const gimple_match_cond
&,
90 code_helper
, tree
, tree
, tree
);
91 gimple_match_op (const gimple_match_cond
&,
92 code_helper
, tree
, tree
, tree
, tree
);
93 gimple_match_op (const gimple_match_cond
&,
94 code_helper
, tree
, tree
, tree
, tree
, tree
);
95 gimple_match_op (const gimple_match_cond
&,
96 code_helper
, tree
, tree
, tree
, tree
, tree
, tree
);
97 gimple_match_op (const gimple_match_cond
&,
98 code_helper
, tree
, tree
, tree
, tree
, tree
, tree
, tree
);
99 gimple_match_op (const gimple_match_cond
&,
100 code_helper
, tree
, tree
, tree
, tree
, tree
, tree
, tree
, tree
);
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);
107 void set_op (code_helper
, tree
, tree
, tree
, tree
, tree
);
108 void set_op (code_helper
, tree
, tree
, tree
, tree
, tree
, tree
);
109 void set_op (code_helper
, tree
, tree
, tree
, tree
, tree
, tree
, tree
);
110 void set_op (code_helper
, tree
, tree
, tree
, tree
, tree
, tree
, tree
, tree
);
111 void set_value (tree
);
113 tree
op_or_null (unsigned int) const;
115 bool resimplify (gimple_seq
*, tree (*)(tree
));
117 /* The maximum value of NUM_OPS. */
118 static const unsigned int MAX_NUM_OPS
= 7;
120 /* The conditions under which the operation is performed, and the value to
121 use as a fallback. */
122 gimple_match_cond cond
;
124 /* The operation being performed. */
127 /* The type of the result. */
130 /* For a BIT_FIELD_REF, whether the group of bits is stored in reverse order
131 from the target order. */
134 /* The number of operands to CODE. */
135 unsigned int num_ops
;
137 /* The operands to CODE. Only the first NUM_OPS entries are meaningful. */
138 tree ops
[MAX_NUM_OPS
];
142 gimple_match_op::gimple_match_op ()
143 : cond (gimple_match_cond::UNCOND
), type (NULL_TREE
), reverse (false),
148 /* Constructor that takes the condition, code, type and number of
149 operands, but leaves the caller to fill in the operands. */
152 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
153 code_helper code_in
, tree type_in
,
154 unsigned int num_ops_in
)
155 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
160 /* Constructors for various numbers of operands. */
163 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
164 code_helper code_in
, tree type_in
,
166 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
173 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
174 code_helper code_in
, tree type_in
,
176 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
184 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
185 code_helper code_in
, tree type_in
,
186 tree op0
, tree op1
, tree op2
)
187 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
196 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
197 code_helper code_in
, tree type_in
,
198 tree op0
, tree op1
, tree op2
, tree op3
)
199 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
209 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
210 code_helper code_in
, tree type_in
,
211 tree op0
, tree op1
, tree op2
, tree op3
,
213 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
224 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
225 code_helper code_in
, tree type_in
,
226 tree op0
, tree op1
, tree op2
, tree op3
,
228 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
240 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
241 code_helper code_in
, tree type_in
,
242 tree op0
, tree op1
, tree op2
, tree op3
,
243 tree op4
, tree op5
, tree op6
)
244 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
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. */
261 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
262 unsigned int num_ops_in
)
266 num_ops
= num_ops_in
;
269 /* Functions for changing the operation performed, for various numbers
273 gimple_match_op::set_op (code_helper code_in
, tree type_in
, tree op0
)
282 gimple_match_op::set_op (code_helper code_in
, tree type_in
, tree op0
, tree op1
)
292 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
293 tree op0
, tree op1
, tree op2
)
304 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
305 tree op0
, tree op1
, tree op2
, bool reverse_in
)
309 reverse
= reverse_in
;
317 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
318 tree op0
, tree op1
, tree op2
, tree op3
)
330 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
331 tree op0
, tree op1
, tree op2
, tree op3
, tree op4
)
344 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
345 tree op0
, tree op1
, tree op2
, tree op3
, tree op4
,
360 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
361 tree op0
, tree op1
, tree op2
, tree op3
, tree op4
,
376 /* Set the "operation" to be the single value VALUE, such as a constant
380 gimple_match_op::set_value (tree value
)
382 set_op (TREE_CODE (value
), TREE_TYPE (value
), value
);
385 /* Return the value of operand I, or null if there aren't that many
389 gimple_match_op::op_or_null (unsigned int i
) const
391 return i
< num_ops
? ops
[i
] : NULL_TREE
;
394 /* Return whether OP is a non-expression result and a gimple value. */
397 gimple_simplified_result_is_gimple_val (const gimple_match_op
*op
)
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]));
405 extern tree (*mprts_hook
) (gimple_match_op
*);
407 bool gimple_extract_op (gimple
*, gimple_match_op
*);
408 bool gimple_simplify (gimple
*, gimple_match_op
*, gimple_seq
*,
409 tree (*)(tree
), tree (*)(tree
));
410 tree
maybe_push_res_to_seq (gimple_match_op
*, gimple_seq
*,
411 tree res
= NULL_TREE
);
412 void maybe_build_generic_op (gimple_match_op
*);
414 bool commutative_binary_op_p (code_helper
, tree
);
415 bool commutative_ternary_op_p (code_helper
, tree
);
416 int first_commutative_argument (code_helper
, tree
);
417 bool associative_binary_op_p (code_helper
, tree
);
418 code_helper
canonicalize_code (code_helper
, tree
);
420 #ifdef GCC_OPTABS_TREE_H
421 bool directly_supported_p (code_helper
, tree
, optab_subtype
= optab_default
);
424 internal_fn
get_conditional_internal_fn (code_helper
, tree
);
426 #endif /* GCC_GIMPLE_MATCH_H */