PR middle-end/85602 - -Wsizeof-pointer-memaccess for strncat with size of source
[official-gcc.git] / gcc / gimple-match.h
blob69b53f2115703a1cf69c12156dfa03cc8e608f80
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 an operation to be simplified, or the result of the
44 simplification. */
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. */
67 code_helper code;
69 /* The type of the result. */
70 tree type;
72 /* The number of operands to CODE. */
73 unsigned int num_ops;
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. */
82 inline
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. */
91 inline
92 gimple_match_op::gimple_match_op (code_helper code_in, tree type_in,
93 tree op0)
94 : code (code_in), type (type_in), num_ops (1)
96 ops[0] = op0;
99 inline
100 gimple_match_op::gimple_match_op (code_helper code_in, tree type_in,
101 tree op0, tree op1)
102 : code (code_in), type (type_in), num_ops (2)
104 ops[0] = op0;
105 ops[1] = op1;
108 inline
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)
113 ops[0] = op0;
114 ops[1] = op1;
115 ops[2] = op2;
118 inline
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)
123 ops[0] = op0;
124 ops[1] = op1;
125 ops[2] = op2;
126 ops[3] = op3;
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. */
133 inline void
134 gimple_match_op::set_op (code_helper code_in, tree type_in,
135 unsigned int num_ops_in)
137 code = code_in;
138 type = type_in;
139 num_ops = num_ops_in;
142 /* Functions for changing the operation performed, for various numbers
143 of operands. */
145 inline void
146 gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0)
148 code = code_in;
149 type = type_in;
150 num_ops = 1;
151 ops[0] = op0;
154 inline void
155 gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0, tree op1)
157 code = code_in;
158 type = type_in;
159 num_ops = 2;
160 ops[0] = op0;
161 ops[1] = op1;
164 inline void
165 gimple_match_op::set_op (code_helper code_in, tree type_in,
166 tree op0, tree op1, tree op2)
168 code = code_in;
169 type = type_in;
170 num_ops = 3;
171 ops[0] = op0;
172 ops[1] = op1;
173 ops[2] = op2;
176 inline void
177 gimple_match_op::set_op (code_helper code_in, tree type_in,
178 tree op0, tree op1, tree op2, tree op3)
180 code = code_in;
181 type = type_in;
182 num_ops = 4;
183 ops[0] = op0;
184 ops[1] = op1;
185 ops[2] = op2;
186 ops[3] = op3;
189 /* Set the "operation" to be the single value VALUE, such as a constant
190 or SSA_NAME. */
192 inline void
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
199 operands. */
201 inline tree
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. */
209 inline bool
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 */