RISC-V: Make stack_save_restore tests more robust
[official-gcc.git] / gcc / gimple-match.h
blobbec3ff42e3ecb197c3663898da39acec8a4dd39e
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
11 version.
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
16 for more details.
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
31 public:
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. */
43 tree cond;
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. */
47 tree else_value;
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. */
53 tree len;
54 tree bias;
57 inline
58 gimple_match_cond::gimple_match_cond (tree cond_in, tree else_value_in)
59 : cond (cond_in), else_value (else_value_in)
63 inline
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
79 simplification. */
80 class gimple_match_op
82 public:
83 gimple_match_op ();
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. */
117 code_helper code;
119 /* The type of the result. */
120 tree type;
122 /* For a BIT_FIELD_REF, whether the group of bits is stored in reverse order
123 from the target order. */
124 bool reverse;
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];
133 inline
134 gimple_match_op::gimple_match_op ()
135 : cond (gimple_match_cond::UNCOND), type (NULL_TREE), reverse (false),
136 num_ops (0)
140 /* Constructor that takes the condition, code, type and number of
141 operands, but leaves the caller to fill in the operands. */
143 inline
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),
148 num_ops (num_ops_in)
152 /* Constructors for various numbers of operands. */
154 inline
155 gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
156 code_helper code_in, tree type_in,
157 tree op0)
158 : cond (cond_in), code (code_in), type (type_in), reverse (false),
159 num_ops (1)
161 ops[0] = op0;
164 inline
165 gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
166 code_helper code_in, tree type_in,
167 tree op0, tree op1)
168 : cond (cond_in), code (code_in), type (type_in), reverse (false),
169 num_ops (2)
171 ops[0] = op0;
172 ops[1] = op1;
175 inline
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),
180 num_ops (3)
182 ops[0] = op0;
183 ops[1] = op1;
184 ops[2] = op2;
187 inline
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),
192 num_ops (4)
194 ops[0] = op0;
195 ops[1] = op1;
196 ops[2] = op2;
197 ops[3] = op3;
200 inline
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,
204 tree op4)
205 : cond (cond_in), code (code_in), type (type_in), reverse (false),
206 num_ops (5)
208 ops[0] = op0;
209 ops[1] = op1;
210 ops[2] = op2;
211 ops[3] = op3;
212 ops[4] = op4;
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. */
219 inline void
220 gimple_match_op::set_op (code_helper code_in, tree type_in,
221 unsigned int num_ops_in)
223 code = code_in;
224 type = type_in;
225 num_ops = num_ops_in;
228 /* Functions for changing the operation performed, for various numbers
229 of operands. */
231 inline void
232 gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0)
234 code = code_in;
235 type = type_in;
236 num_ops = 1;
237 ops[0] = op0;
240 inline void
241 gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0, tree op1)
243 code = code_in;
244 type = type_in;
245 num_ops = 2;
246 ops[0] = op0;
247 ops[1] = op1;
250 inline void
251 gimple_match_op::set_op (code_helper code_in, tree type_in,
252 tree op0, tree op1, tree op2)
254 code = code_in;
255 type = type_in;
256 num_ops = 3;
257 ops[0] = op0;
258 ops[1] = op1;
259 ops[2] = op2;
262 inline void
263 gimple_match_op::set_op (code_helper code_in, tree type_in,
264 tree op0, tree op1, tree op2, bool reverse_in)
266 code = code_in;
267 type = type_in;
268 reverse = reverse_in;
269 num_ops = 3;
270 ops[0] = op0;
271 ops[1] = op1;
272 ops[2] = op2;
275 inline void
276 gimple_match_op::set_op (code_helper code_in, tree type_in,
277 tree op0, tree op1, tree op2, tree op3)
279 code = code_in;
280 type = type_in;
281 num_ops = 4;
282 ops[0] = op0;
283 ops[1] = op1;
284 ops[2] = op2;
285 ops[3] = op3;
288 inline void
289 gimple_match_op::set_op (code_helper code_in, tree type_in,
290 tree op0, tree op1, tree op2, tree op3, tree op4)
292 code = code_in;
293 type = type_in;
294 num_ops = 5;
295 ops[0] = op0;
296 ops[1] = op1;
297 ops[2] = op2;
298 ops[3] = op3;
299 ops[4] = op4;
302 /* Set the "operation" to be the single value VALUE, such as a constant
303 or SSA_NAME. */
305 inline void
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
312 operands. */
314 inline tree
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. */
322 inline bool
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);
348 #endif
350 internal_fn get_conditional_internal_fn (code_helper, tree);
352 #endif /* GCC_GIMPLE_MATCH_H */