]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/gimple-match.h
Fold VEC_COND_EXPRs to IFN_COND_* where possible
[thirdparty/gcc.git] / gcc / gimple-match.h
1 /* Gimple simplify definitions.
2
3 Copyright (C) 2011-2018 Free Software Foundation, Inc.
4 Contributed by Richard Guenther <rguenther@suse.de>
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>. */
21
22 #ifndef GCC_GIMPLE_MATCH_H
23 #define GCC_GIMPLE_MATCH_H
24
25
26 /* Helper to transparently allow tree codes and builtin function codes
27 exist in one storage entity. */
28 class code_helper
29 {
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;
41 };
42
43 /* Represents an operation to be simplified, or the result of the
44 simplification. */
45 struct gimple_match_op
46 {
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);
53
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);
60
61 tree op_or_null (unsigned int) const;
62
63 /* The maximum value of NUM_OPS. */
64 static const unsigned int MAX_NUM_OPS = 4;
65
66 /* The operation being performed. */
67 code_helper code;
68
69 /* The type of the result. */
70 tree type;
71
72 /* The number of operands to CODE. */
73 unsigned int num_ops;
74
75 /* The operands to CODE. Only the first NUM_OPS entries are meaningful. */
76 tree ops[MAX_NUM_OPS];
77 };
78
79 /* Constructor that takes the code, type and number of operands, but leaves
80 the caller to fill in the operands. */
81
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)
86 {
87 }
88
89 /* Constructors for various numbers of operands. */
90
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)
95 {
96 ops[0] = op0;
97 }
98
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)
103 {
104 ops[0] = op0;
105 ops[1] = op1;
106 }
107
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)
112 {
113 ops[0] = op0;
114 ops[1] = op1;
115 ops[2] = op2;
116 }
117
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)
122 {
123 ops[0] = op0;
124 ops[1] = op1;
125 ops[2] = op2;
126 ops[3] = op3;
127 }
128
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. */
132
133 inline void
134 gimple_match_op::set_op (code_helper code_in, tree type_in,
135 unsigned int num_ops_in)
136 {
137 code = code_in;
138 type = type_in;
139 num_ops = num_ops_in;
140 }
141
142 /* Functions for changing the operation performed, for various numbers
143 of operands. */
144
145 inline void
146 gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0)
147 {
148 code = code_in;
149 type = type_in;
150 num_ops = 1;
151 ops[0] = op0;
152 }
153
154 inline void
155 gimple_match_op::set_op (code_helper code_in, tree type_in, tree op0, tree op1)
156 {
157 code = code_in;
158 type = type_in;
159 num_ops = 2;
160 ops[0] = op0;
161 ops[1] = op1;
162 }
163
164 inline void
165 gimple_match_op::set_op (code_helper code_in, tree type_in,
166 tree op0, tree op1, tree op2)
167 {
168 code = code_in;
169 type = type_in;
170 num_ops = 3;
171 ops[0] = op0;
172 ops[1] = op1;
173 ops[2] = op2;
174 }
175
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)
179 {
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;
187 }
188
189 /* Set the "operation" to be the single value VALUE, such as a constant
190 or SSA_NAME. */
191
192 inline void
193 gimple_match_op::set_value (tree value)
194 {
195 set_op (TREE_CODE (value), TREE_TYPE (value), value);
196 }
197
198 /* Return the value of operand I, or null if there aren't that many
199 operands. */
200
201 inline tree
202 gimple_match_op::op_or_null (unsigned int i) const
203 {
204 return i < num_ops ? ops[i] : NULL_TREE;
205 }
206
207 /* Return whether OP is a non-expression result and a gimple value. */
208
209 inline bool
210 gimple_simplified_result_is_gimple_val (const gimple_match_op *op)
211 {
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]));
216 }
217
218 extern tree (*mprts_hook) (gimple_match_op *);
219
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 *);
229
230
231 #endif /* GCC_GIMPLE_MATCH_H */