1 /* Gimple simplify definitions.
3 Copyright (C) 2011-2019 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 /* Helper to transparently allow tree codes and builtin function codes
27 exist in one storage entity. */
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
; }
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. */
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. */
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
82 struct 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
, bool);
102 void set_op (code_helper
, tree
, tree
, tree
, tree
, tree
);
103 void set_op (code_helper
, tree
, tree
, tree
, tree
, tree
, tree
);
104 void set_value (tree
);
106 tree
op_or_null (unsigned int) const;
108 /* The maximum value of NUM_OPS. */
109 static const unsigned int MAX_NUM_OPS
= 5;
111 /* The conditions under which the operation is performed, and the value to
112 use as a fallback. */
113 gimple_match_cond cond
;
115 /* The operation being performed. */
118 /* The type of the result. */
121 /* For a BIT_FIELD_REF, whether the group of bits is stored in reverse order
122 from the target order. */
125 /* The number of operands to CODE. */
126 unsigned int num_ops
;
128 /* The operands to CODE. Only the first NUM_OPS entries are meaningful. */
129 tree ops
[MAX_NUM_OPS
];
133 gimple_match_op::gimple_match_op ()
134 : cond (gimple_match_cond::UNCOND
), type (NULL_TREE
), reverse (false),
139 /* Constructor that takes the condition, code, type and number of
140 operands, but leaves the caller to fill in the operands. */
143 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
144 code_helper code_in
, tree type_in
,
145 unsigned int num_ops_in
)
146 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
151 /* Constructors for various numbers of operands. */
154 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
155 code_helper code_in
, tree type_in
,
157 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
164 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
165 code_helper code_in
, tree type_in
,
167 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
175 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
176 code_helper code_in
, tree type_in
,
177 tree op0
, tree op1
, tree op2
)
178 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
187 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
188 code_helper code_in
, tree type_in
,
189 tree op0
, tree op1
, tree op2
, tree op3
)
190 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
200 gimple_match_op::gimple_match_op (const gimple_match_cond
&cond_in
,
201 code_helper code_in
, tree type_in
,
202 tree op0
, tree op1
, tree op2
, tree op3
,
204 : cond (cond_in
), code (code_in
), type (type_in
), reverse (false),
214 /* Change the operation performed to CODE_IN, the type of the result to
215 TYPE_IN, and the number of operands to NUM_OPS_IN. The caller needs
216 to set the operands itself. */
219 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
220 unsigned int num_ops_in
)
224 num_ops
= num_ops_in
;
227 /* Functions for changing the operation performed, for various numbers
231 gimple_match_op::set_op (code_helper code_in
, tree type_in
, tree op0
)
240 gimple_match_op::set_op (code_helper code_in
, tree type_in
, tree op0
, tree op1
)
250 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
251 tree op0
, tree op1
, tree op2
)
262 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
263 tree op0
, tree op1
, tree op2
, bool reverse_in
)
267 reverse
= reverse_in
;
275 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
276 tree op0
, tree op1
, tree op2
, tree op3
)
288 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
289 tree op0
, tree op1
, tree op2
, tree op3
, tree op4
)
301 /* Set the "operation" to be the single value VALUE, such as a constant
305 gimple_match_op::set_value (tree value
)
307 set_op (TREE_CODE (value
), TREE_TYPE (value
), value
);
310 /* Return the value of operand I, or null if there aren't that many
314 gimple_match_op::op_or_null (unsigned int i
) const
316 return i
< num_ops
? ops
[i
] : NULL_TREE
;
319 /* Return whether OP is a non-expression result and a gimple value. */
322 gimple_simplified_result_is_gimple_val (const gimple_match_op
*op
)
324 return (op
->code
.is_tree_code ()
325 && (TREE_CODE_LENGTH ((tree_code
) op
->code
) == 0
326 || ((tree_code
) op
->code
) == ADDR_EXPR
)
327 && is_gimple_val (op
->ops
[0]));
330 extern tree (*mprts_hook
) (gimple_match_op
*);
332 bool gimple_simplify (gimple
*, gimple_match_op
*, gimple_seq
*,
333 tree (*)(tree
), tree (*)(tree
));
334 bool gimple_resimplify1 (gimple_seq
*, gimple_match_op
*, tree (*)(tree
));
335 bool gimple_resimplify2 (gimple_seq
*, gimple_match_op
*, tree (*)(tree
));
336 bool gimple_resimplify3 (gimple_seq
*, gimple_match_op
*, tree (*)(tree
));
337 bool gimple_resimplify4 (gimple_seq
*, gimple_match_op
*, tree (*)(tree
));
338 bool gimple_resimplify5 (gimple_seq
*, gimple_match_op
*, tree (*)(tree
));
339 tree
maybe_push_res_to_seq (gimple_match_op
*, gimple_seq
*,
340 tree res
= NULL_TREE
);
341 void maybe_build_generic_op (gimple_match_op
*);
344 #endif /* GCC_GIMPLE_MATCH_H */