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
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 an operation to be simplified, or the result of the
45 struct gimple_match_op
47 gimple_match_op () : type (NULL_TREE
), num_ops (0) {}
48 gimple_match_op (code_helper
, tree
, unsigned int);
49 gimple_match_op (code_helper
, tree
, tree
);
50 gimple_match_op (code_helper
, tree
, tree
, tree
);
51 gimple_match_op (code_helper
, tree
, tree
, tree
, tree
);
52 gimple_match_op (code_helper
, tree
, tree
, tree
, tree
, tree
);
54 void set_op (code_helper
, tree
, unsigned int);
55 void set_op (code_helper
, tree
, tree
);
56 void set_op (code_helper
, tree
, tree
, tree
);
57 void set_op (code_helper
, tree
, tree
, tree
, tree
);
58 void set_op (code_helper
, tree
, tree
, tree
, tree
, tree
);
59 void set_value (tree
);
61 tree
op_or_null (unsigned int) const;
63 /* The maximum value of NUM_OPS. */
64 static const unsigned int MAX_NUM_OPS
= 4;
66 /* The operation being performed. */
69 /* The type of the result. */
72 /* The number of operands to CODE. */
75 /* The operands to CODE. Only the first NUM_OPS entries are meaningful. */
76 tree ops
[MAX_NUM_OPS
];
79 /* Constructor that takes the code, type and number of operands, but leaves
80 the caller to fill in the operands. */
83 gimple_match_op::gimple_match_op (code_helper code_in
, tree type_in
,
84 unsigned int num_ops_in
)
85 : code (code_in
), type (type_in
), num_ops (num_ops_in
)
89 /* Constructors for various numbers of operands. */
92 gimple_match_op::gimple_match_op (code_helper code_in
, tree type_in
,
94 : code (code_in
), type (type_in
), num_ops (1)
100 gimple_match_op::gimple_match_op (code_helper code_in
, tree type_in
,
102 : code (code_in
), type (type_in
), num_ops (2)
109 gimple_match_op::gimple_match_op (code_helper code_in
, tree type_in
,
110 tree op0
, tree op1
, tree op2
)
111 : code (code_in
), type (type_in
), num_ops (3)
119 gimple_match_op::gimple_match_op (code_helper code_in
, tree type_in
,
120 tree op0
, tree op1
, tree op2
, tree op3
)
121 : code (code_in
), type (type_in
), num_ops (4)
129 /* Change the operation performed to CODE_IN, the type of the result to
130 TYPE_IN, and the number of operands to NUM_OPS_IN. The caller needs
131 to set the operands itself. */
134 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
135 unsigned int num_ops_in
)
139 num_ops
= num_ops_in
;
142 /* Functions for changing the operation performed, for various numbers
146 gimple_match_op::set_op (code_helper code_in
, tree type_in
, tree op0
)
155 gimple_match_op::set_op (code_helper code_in
, tree type_in
, tree op0
, tree op1
)
165 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
166 tree op0
, tree op1
, tree op2
)
177 gimple_match_op::set_op (code_helper code_in
, tree type_in
,
178 tree op0
, tree op1
, tree op2
, tree op3
)
189 /* Set the "operation" to be the single value VALUE, such as a constant
193 gimple_match_op::set_value (tree value
)
195 set_op (TREE_CODE (value
), TREE_TYPE (value
), value
);
198 /* Return the value of operand I, or null if there aren't that many
202 gimple_match_op::op_or_null (unsigned int i
) const
204 return i
< num_ops
? ops
[i
] : NULL_TREE
;
207 /* Return whether OP is a non-expression result and a gimple value. */
210 gimple_simplified_result_is_gimple_val (const gimple_match_op
*op
)
212 return (op
->code
.is_tree_code ()
213 && (TREE_CODE_LENGTH ((tree_code
) op
->code
) == 0
214 || ((tree_code
) op
->code
) == ADDR_EXPR
)
215 && is_gimple_val (op
->ops
[0]));
218 extern tree (*mprts_hook
) (gimple_match_op
*);
220 bool gimple_simplify (gimple
*, gimple_match_op
*, gimple_seq
*,
221 tree (*)(tree
), tree (*)(tree
));
222 bool gimple_resimplify1 (gimple_seq
*, gimple_match_op
*, tree (*)(tree
));
223 bool gimple_resimplify2 (gimple_seq
*, gimple_match_op
*, tree (*)(tree
));
224 bool gimple_resimplify3 (gimple_seq
*, gimple_match_op
*, tree (*)(tree
));
225 bool gimple_resimplify4 (gimple_seq
*, gimple_match_op
*, tree (*)(tree
));
226 tree
maybe_push_res_to_seq (gimple_match_op
*, gimple_seq
*,
227 tree res
= NULL_TREE
);
228 void maybe_build_generic_op (gimple_match_op
*);
231 #endif /* GCC_GIMPLE_MATCH_H */