Avoid is_constant calls in vectorizable_bswap
[official-gcc.git] / gcc / gimple-match.h
blob704fa76c0a4a9ca76eba5556e02f04b4eadecfa2
1 /* Gimple simplify definitions.
3 Copyright (C) 2011-2018 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 /* Helper to transparently allow tree codes and builtin function codes
27 exist in one storage entity. */
28 class code_helper
30 public:
31 code_helper () {}
32 code_helper (tree_code code) : rep ((int) code) {}
33 code_helper (combined_fn fn) : rep (-(int) fn) {}
34 operator tree_code () const { return (tree_code) rep; }
35 operator combined_fn () const { return (combined_fn) -rep; }
36 bool is_tree_code () const { return rep > 0; }
37 bool is_fn_code () const { return rep < 0; }
38 int get_rep () const { return rep; }
39 private:
40 int rep;
43 /* Represents the condition under which an operation should happen,
44 and the value to use otherwise. The condition applies elementwise
45 (as for VEC_COND_EXPR) if the values are vectors. */
46 struct gimple_match_cond
48 enum uncond { UNCOND };
50 /* Build an unconditional op. */
51 gimple_match_cond (uncond) : cond (NULL_TREE), else_value (NULL_TREE) {}
52 gimple_match_cond (tree, tree);
54 gimple_match_cond any_else () const;
56 /* The condition under which the operation occurs, or NULL_TREE
57 if the operation is unconditional. */
58 tree cond;
60 /* The value to use when the condition is false. This is NULL_TREE if
61 the operation is unconditional or if the value doesn't matter. */
62 tree else_value;
65 inline
66 gimple_match_cond::gimple_match_cond (tree cond_in, tree else_value_in)
67 : cond (cond_in), else_value (else_value_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
81 simplification. */
82 struct gimple_match_op
84 gimple_match_op ();
85 gimple_match_op (const gimple_match_cond &, code_helper, tree, unsigned int);
86 gimple_match_op (const gimple_match_cond &,
87 code_helper, tree, tree);
88 gimple_match_op (const gimple_match_cond &,
89 code_helper, tree, tree, tree);
90 gimple_match_op (const gimple_match_cond &,
91 code_helper, tree, tree, tree, tree);
92 gimple_match_op (const gimple_match_cond &,
93 code_helper, tree, tree, tree, tree, tree);
94 gimple_match_op (const gimple_match_cond &,
95 code_helper, tree, tree, tree, tree, tree, tree);
97 void set_op (code_helper, tree, unsigned int);
98 void set_op (code_helper, tree, tree);
99 void set_op (code_helper, tree, tree, tree);
100 void set_op (code_helper, tree, tree, tree, tree);
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 /* The maximum value of NUM_OPS. */
108 static const unsigned int MAX_NUM_OPS = 5;
110 /* The conditions under which the operation is performed, and the value to
111 use as a fallback. */
112 gimple_match_cond cond;
114 /* The operation being performed. */
115 code_helper code;
117 /* The type of the result. */
118 tree type;
120 /* The number of operands to CODE. */
121 unsigned int num_ops;
123 /* The operands to CODE. Only the first NUM_OPS entries are meaningful. */
124 tree ops[MAX_NUM_OPS];
127 inline
128 gimple_match_op::gimple_match_op ()
129 : cond (gimple_match_cond::UNCOND), type (NULL_TREE), num_ops (0)
133 /* Constructor that takes the condition, code, type and number of
134 operands, but leaves the caller to fill in the operands. */
136 inline
137 gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
138 code_helper code_in, tree type_in,
139 unsigned int num_ops_in)
140 : cond (cond_in), code (code_in), type (type_in), num_ops (num_ops_in)
144 /* Constructors for various numbers of operands. */
146 inline
147 gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
148 code_helper code_in, tree type_in,
149 tree op0)
150 : cond (cond_in), code (code_in), type (type_in), num_ops (1)
152 ops[0] = op0;
155 inline
156 gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
157 code_helper code_in, tree type_in,
158 tree op0, tree op1)
159 : cond (cond_in), code (code_in), type (type_in), num_ops (2)
161 ops[0] = op0;
162 ops[1] = op1;
165 inline
166 gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
167 code_helper code_in, tree type_in,
168 tree op0, tree op1, tree op2)
169 : cond (cond_in), code (code_in), type (type_in), num_ops (3)
171 ops[0] = op0;
172 ops[1] = op1;
173 ops[2] = op2;
176 inline
177 gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
178 code_helper code_in, tree type_in,
179 tree op0, tree op1, tree op2, tree op3)
180 : cond (cond_in), code (code_in), type (type_in), num_ops (4)
182 ops[0] = op0;
183 ops[1] = op1;
184 ops[2] = op2;
185 ops[3] = op3;
188 inline
189 gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in,
190 code_helper code_in, tree type_in,
191 tree op0, tree op1, tree op2, tree op3,
192 tree op4)
193 : cond (cond_in), code (code_in), type (type_in), num_ops (5)
195 ops[0] = op0;
196 ops[1] = op1;
197 ops[2] = op2;
198 ops[3] = op3;
199 ops[4] = op4;
202 /* Change the operation performed to CODE_IN, the type of the result to
203 TYPE_IN, and the number of operands to NUM_OPS_IN. The caller needs
204 to set the operands itself. */
206 inline void
207 gimple_match_op::set_op (code_helper code_in, tree type_in,
208 unsigned int num_ops_in)
210 code = code_in;
211 type = type_in;
212 num_ops = num_ops_in;
215 /* Functions for changing the operation performed, for various numbers
216 of operands. */
218 inline void
219 gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0)
221 code = code_in;
222 type = type_in;
223 num_ops = 1;
224 ops[0] = op0;
227 inline void
228 gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0, tree op1)
230 code = code_in;
231 type = type_in;
232 num_ops = 2;
233 ops[0] = op0;
234 ops[1] = op1;
237 inline void
238 gimple_match_op::set_op (code_helper code_in, tree type_in,
239 tree op0, tree op1, tree op2)
241 code = code_in;
242 type = type_in;
243 num_ops = 3;
244 ops[0] = op0;
245 ops[1] = op1;
246 ops[2] = op2;
249 inline void
250 gimple_match_op::set_op (code_helper code_in, tree type_in,
251 tree op0, tree op1, tree op2, tree op3)
253 code = code_in;
254 type = type_in;
255 num_ops = 4;
256 ops[0] = op0;
257 ops[1] = op1;
258 ops[2] = op2;
259 ops[3] = op3;
262 inline void
263 gimple_match_op::set_op (code_helper code_in, tree type_in,
264 tree op0, tree op1, tree op2, tree op3, tree op4)
266 code = code_in;
267 type = type_in;
268 num_ops = 5;
269 ops[0] = op0;
270 ops[1] = op1;
271 ops[2] = op2;
272 ops[3] = op3;
273 ops[4] = op4;
276 /* Set the "operation" to be the single value VALUE, such as a constant
277 or SSA_NAME. */
279 inline void
280 gimple_match_op::set_value (tree value)
282 set_op (TREE_CODE (value), TREE_TYPE (value), value);
285 /* Return the value of operand I, or null if there aren't that many
286 operands. */
288 inline tree
289 gimple_match_op::op_or_null (unsigned int i) const
291 return i < num_ops ? ops[i] : NULL_TREE;
294 /* Return whether OP is a non-expression result and a gimple value. */
296 inline bool
297 gimple_simplified_result_is_gimple_val (const gimple_match_op *op)
299 return (op->code.is_tree_code ()
300 && (TREE_CODE_LENGTH ((tree_code) op->code) == 0
301 || ((tree_code) op->code) == ADDR_EXPR)
302 && is_gimple_val (op->ops[0]));
305 extern tree (*mprts_hook) (gimple_match_op *);
307 bool gimple_simplify (gimple *, gimple_match_op *, gimple_seq *,
308 tree (*)(tree), tree (*)(tree));
309 bool gimple_resimplify1 (gimple_seq *, gimple_match_op *, tree (*)(tree));
310 bool gimple_resimplify2 (gimple_seq *, gimple_match_op *, tree (*)(tree));
311 bool gimple_resimplify3 (gimple_seq *, gimple_match_op *, tree (*)(tree));
312 bool gimple_resimplify4 (gimple_seq *, gimple_match_op *, tree (*)(tree));
313 bool gimple_resimplify5 (gimple_seq *, gimple_match_op *, tree (*)(tree));
314 tree maybe_push_res_to_seq (gimple_match_op *, gimple_seq *,
315 tree res = NULL_TREE);
316 void maybe_build_generic_op (gimple_match_op *);
319 #endif /* GCC_GIMPLE_MATCH_H */