Mercurial > hg > CbC > CbC_gcc
annotate gcc/tree-ssa-uninit.c @ 138:fc828634a951
merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 08 Nov 2018 14:17:14 +0900 |
parents | 84e7813d76e9 |
children | 1830386684a0 |
rev | line source |
---|---|
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 /* Predicate aware uninitialized variable warning. |
131 | 2 Copyright (C) 2001-2018 Free Software Foundation, Inc. |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 Contributed by Xinliang David Li <davidxl@google.com> |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 This file is part of GCC. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 GCC is free software; you can redistribute it and/or modify |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 it under the terms of the GNU General Public License as published by |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 the Free Software Foundation; either version 3, or (at your option) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 any later version. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 GCC is distributed in the hope that it will be useful, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 GNU General Public License for more details. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 along with GCC; see the file COPYING3. If not see |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 #include "config.h" |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 #include "system.h" |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 #include "coretypes.h" |
111 | 24 #include "backend.h" |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 #include "tree.h" |
111 | 26 #include "gimple.h" |
27 #include "tree-pass.h" | |
28 #include "ssa.h" | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 #include "gimple-pretty-print.h" |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
30 #include "diagnostic-core.h" |
111 | 31 #include "fold-const.h" |
32 #include "gimple-iterator.h" | |
33 #include "tree-ssa.h" | |
34 #include "params.h" | |
35 #include "tree-cfg.h" | |
131 | 36 #include "cfghooks.h" |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 /* This implements the pass that does predicate aware warning on uses of |
111 | 39 possibly uninitialized variables. The pass first collects the set of |
40 possibly uninitialized SSA names. For each such name, it walks through | |
41 all its immediate uses. For each immediate use, it rebuilds the condition | |
42 expression (the predicate) that guards the use. The predicate is then | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 examined to see if the variable is always defined under that same condition. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 This is done either by pruning the unrealizable paths that lead to the |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 default definitions or by checking if the predicate set that guards the |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 defining paths is a superset of the use predicate. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 |
111 | 48 /* Max PHI args we can handle in pass. */ |
49 const unsigned max_phi_args = 32; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 /* Pointer set of potentially undefined ssa names, i.e., |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 ssa names that are defined by phi with operands that |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 are not defined or potentially undefined. */ |
111 | 54 static hash_set<tree> *possibly_undefined_names = 0; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 /* Bit mask handling macros. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 #define MASK_SET_BIT(mask, pos) mask |= (1 << pos) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 #define MASK_TEST_BIT(mask, pos) (mask & (1 << pos)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 #define MASK_EMPTY(mask) (mask == 0) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 /* Returns the first bit position (starting from LSB) |
111 | 62 in mask that is non zero. Returns -1 if the mask is empty. */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 static int |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 get_mask_first_set_bit (unsigned mask) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 int pos = 0; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 if (mask == 0) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 return -1; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 while ((mask & (1 << pos)) == 0) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 pos++; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 return pos; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 #define MASK_FIRST_SET_BIT(mask) get_mask_first_set_bit (mask) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 /* Return true if T, an SSA_NAME, has an undefined value. */ |
111 | 78 static bool |
79 has_undefined_value_p (tree t) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 { |
111 | 81 return (ssa_undefined_value_p (t) |
82 || (possibly_undefined_names | |
83 && possibly_undefined_names->contains (t))); | |
84 } | |
85 | |
86 /* Like has_undefined_value_p, but don't return true if TREE_NO_WARNING | |
87 is set on SSA_NAME_VAR. */ | |
88 | |
89 static inline bool | |
90 uninit_undefined_value_p (tree t) | |
91 { | |
92 if (!has_undefined_value_p (t)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 return false; |
111 | 94 if (SSA_NAME_VAR (t) && TREE_NO_WARNING (SSA_NAME_VAR (t))) |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
95 return false; |
111 | 96 return true; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 |
111 | 99 /* Emit warnings for uninitialized variables. This is done in two passes. |
100 | |
101 The first pass notices real uses of SSA names with undefined values. | |
102 Such uses are unconditionally uninitialized, and we can be certain that | |
103 such a use is a mistake. This pass is run before most optimizations, | |
104 so that we catch as many as we can. | |
105 | |
106 The second pass follows PHI nodes to find uses that are potentially | |
107 uninitialized. In this case we can't necessarily prove that the use | |
108 is really uninitialized. This pass is run after most optimizations, | |
109 so that we thread as many jumps and possible, and delete as much dead | |
110 code as possible, in order to reduce false positives. We also look | |
111 again for plain uninitialized variables, since optimization may have | |
112 changed conditionally uninitialized to unconditionally uninitialized. */ | |
113 | |
114 /* Emit a warning for EXPR based on variable VAR at the point in the | |
115 program T, an SSA_NAME, is used being uninitialized. The exact | |
116 warning text is in MSGID and DATA is the gimple stmt with info about | |
117 the location in source code. When DATA is a GIMPLE_PHI, PHIARG_IDX | |
118 gives which argument of the phi node to take the location from. WC | |
119 is the warning code. */ | |
120 | |
121 static void | |
122 warn_uninit (enum opt_code wc, tree t, tree expr, tree var, | |
123 const char *gmsgid, void *data, location_t phiarg_loc) | |
124 { | |
125 gimple *context = (gimple *) data; | |
126 location_t location, cfun_loc; | |
127 expanded_location xloc, floc; | |
128 | |
129 /* Ignore COMPLEX_EXPR as initializing only a part of a complex | |
130 turns in a COMPLEX_EXPR with the not initialized part being | |
131 set to its previous (undefined) value. */ | |
132 if (is_gimple_assign (context) | |
133 && gimple_assign_rhs_code (context) == COMPLEX_EXPR) | |
134 return; | |
135 if (!has_undefined_value_p (t)) | |
136 return; | |
137 | |
138 /* Anonymous SSA_NAMEs shouldn't be uninitialized, but ssa_undefined_value_p | |
139 can return true if the def stmt of anonymous SSA_NAME is COMPLEX_EXPR | |
140 created for conversion from scalar to complex. Use the underlying var of | |
141 the COMPLEX_EXPRs real part in that case. See PR71581. */ | |
142 if (expr == NULL_TREE | |
143 && var == NULL_TREE | |
144 && SSA_NAME_VAR (t) == NULL_TREE | |
145 && is_gimple_assign (SSA_NAME_DEF_STMT (t)) | |
146 && gimple_assign_rhs_code (SSA_NAME_DEF_STMT (t)) == COMPLEX_EXPR) | |
147 { | |
148 tree v = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (t)); | |
149 if (TREE_CODE (v) == SSA_NAME | |
150 && has_undefined_value_p (v) | |
151 && zerop (gimple_assign_rhs2 (SSA_NAME_DEF_STMT (t)))) | |
152 { | |
153 expr = SSA_NAME_VAR (v); | |
154 var = expr; | |
155 } | |
156 } | |
157 | |
158 if (expr == NULL_TREE) | |
159 return; | |
160 | |
161 /* TREE_NO_WARNING either means we already warned, or the front end | |
162 wishes to suppress the warning. */ | |
163 if ((context | |
164 && (gimple_no_warning_p (context) | |
165 || (gimple_assign_single_p (context) | |
166 && TREE_NO_WARNING (gimple_assign_rhs1 (context))))) | |
167 || TREE_NO_WARNING (expr)) | |
168 return; | |
169 | |
170 if (context != NULL && gimple_has_location (context)) | |
171 location = gimple_location (context); | |
172 else if (phiarg_loc != UNKNOWN_LOCATION) | |
173 location = phiarg_loc; | |
174 else | |
175 location = DECL_SOURCE_LOCATION (var); | |
176 location = linemap_resolve_location (line_table, location, | |
177 LRK_SPELLING_LOCATION, NULL); | |
178 cfun_loc = DECL_SOURCE_LOCATION (cfun->decl); | |
179 xloc = expand_location (location); | |
180 floc = expand_location (cfun_loc); | |
131 | 181 auto_diagnostic_group d; |
111 | 182 if (warning_at (location, wc, gmsgid, expr)) |
183 { | |
184 TREE_NO_WARNING (expr) = 1; | |
185 | |
186 if (location == DECL_SOURCE_LOCATION (var)) | |
187 return; | |
188 if (xloc.file != floc.file | |
189 || linemap_location_before_p (line_table, location, cfun_loc) | |
190 || linemap_location_before_p (line_table, cfun->function_end_locus, | |
191 location)) | |
192 inform (DECL_SOURCE_LOCATION (var), "%qD was declared here", var); | |
193 } | |
194 } | |
195 | |
196 struct check_defs_data | |
197 { | |
198 /* If we found any may-defs besides must-def clobbers. */ | |
199 bool found_may_defs; | |
200 }; | |
201 | |
202 /* Callback for walk_aliased_vdefs. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
203 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
204 static bool |
111 | 205 check_defs (ao_ref *ref, tree vdef, void *data_) |
206 { | |
207 check_defs_data *data = (check_defs_data *)data_; | |
208 gimple *def_stmt = SSA_NAME_DEF_STMT (vdef); | |
209 /* If this is a clobber then if it is not a kill walk past it. */ | |
210 if (gimple_clobber_p (def_stmt)) | |
211 { | |
212 if (stmt_kills_ref_p (def_stmt, ref)) | |
213 return true; | |
214 return false; | |
215 } | |
216 /* Found a may-def on this path. */ | |
217 data->found_may_defs = true; | |
218 return true; | |
219 } | |
220 | |
221 static unsigned int | |
222 warn_uninitialized_vars (bool warn_possibly_uninitialized) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223 { |
111 | 224 gimple_stmt_iterator gsi; |
225 basic_block bb; | |
226 unsigned int vdef_cnt = 0; | |
227 unsigned int oracle_cnt = 0; | |
228 unsigned limit = 0; | |
229 | |
230 FOR_EACH_BB_FN (bb, cfun) | |
231 { | |
232 basic_block succ = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun)); | |
233 bool always_executed = dominated_by_p (CDI_POST_DOMINATORS, succ, bb); | |
234 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | |
235 { | |
236 gimple *stmt = gsi_stmt (gsi); | |
237 use_operand_p use_p; | |
238 ssa_op_iter op_iter; | |
239 tree use; | |
240 | |
241 if (is_gimple_debug (stmt)) | |
242 continue; | |
243 | |
244 /* We only do data flow with SSA_NAMEs, so that's all we | |
245 can warn about. */ | |
246 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, op_iter, SSA_OP_USE) | |
247 { | |
248 /* BIT_INSERT_EXPR first operand should not be considered | |
249 a use for the purpose of uninit warnings. */ | |
250 if (gassign *ass = dyn_cast <gassign *> (stmt)) | |
251 { | |
252 if (gimple_assign_rhs_code (ass) == BIT_INSERT_EXPR | |
253 && use_p->use == gimple_assign_rhs1_ptr (ass)) | |
254 continue; | |
255 } | |
256 use = USE_FROM_PTR (use_p); | |
257 if (always_executed) | |
258 warn_uninit (OPT_Wuninitialized, use, SSA_NAME_VAR (use), | |
259 SSA_NAME_VAR (use), | |
260 "%qD is used uninitialized in this function", stmt, | |
261 UNKNOWN_LOCATION); | |
262 else if (warn_possibly_uninitialized) | |
263 warn_uninit (OPT_Wmaybe_uninitialized, use, SSA_NAME_VAR (use), | |
264 SSA_NAME_VAR (use), | |
265 "%qD may be used uninitialized in this function", | |
266 stmt, UNKNOWN_LOCATION); | |
267 } | |
268 | |
269 /* For limiting the alias walk below we count all | |
270 vdefs in the function. */ | |
271 if (gimple_vdef (stmt)) | |
272 vdef_cnt++; | |
273 | |
274 if (gimple_assign_load_p (stmt) | |
275 && gimple_has_location (stmt)) | |
276 { | |
277 tree rhs = gimple_assign_rhs1 (stmt); | |
278 tree lhs = gimple_assign_lhs (stmt); | |
279 bool has_bit_insert = false; | |
280 use_operand_p luse_p; | |
281 imm_use_iterator liter; | |
282 | |
283 if (TREE_NO_WARNING (rhs)) | |
284 continue; | |
285 | |
286 ao_ref ref; | |
287 ao_ref_init (&ref, rhs); | |
288 | |
289 /* Do not warn if the base was marked so or this is a | |
290 hard register var. */ | |
291 tree base = ao_ref_base (&ref); | |
292 if ((VAR_P (base) | |
293 && DECL_HARD_REGISTER (base)) | |
294 || TREE_NO_WARNING (base)) | |
295 continue; | |
296 | |
297 /* Do not warn if the access is fully outside of the | |
298 variable. */ | |
131 | 299 poly_int64 decl_size; |
111 | 300 if (DECL_P (base) |
131 | 301 && known_size_p (ref.size) |
302 && ((known_eq (ref.max_size, ref.size) | |
303 && known_le (ref.offset + ref.size, 0)) | |
304 || (known_ge (ref.offset, 0) | |
111 | 305 && DECL_SIZE (base) |
131 | 306 && poly_int_tree_p (DECL_SIZE (base), &decl_size) |
307 && known_le (decl_size, ref.offset)))) | |
111 | 308 continue; |
309 | |
310 /* Do not warn if the access is then used for a BIT_INSERT_EXPR. */ | |
311 if (TREE_CODE (lhs) == SSA_NAME) | |
312 FOR_EACH_IMM_USE_FAST (luse_p, liter, lhs) | |
313 { | |
314 gimple *use_stmt = USE_STMT (luse_p); | |
315 /* BIT_INSERT_EXPR first operand should not be considered | |
316 a use for the purpose of uninit warnings. */ | |
317 if (gassign *ass = dyn_cast <gassign *> (use_stmt)) | |
318 { | |
319 if (gimple_assign_rhs_code (ass) == BIT_INSERT_EXPR | |
320 && luse_p->use == gimple_assign_rhs1_ptr (ass)) | |
321 { | |
322 has_bit_insert = true; | |
323 break; | |
324 } | |
325 } | |
326 } | |
327 if (has_bit_insert) | |
328 continue; | |
329 | |
330 /* Limit the walking to a constant number of stmts after | |
331 we overcommit quadratic behavior for small functions | |
332 and O(n) behavior. */ | |
333 if (oracle_cnt > 128 * 128 | |
334 && oracle_cnt > vdef_cnt * 2) | |
335 limit = 32; | |
336 check_defs_data data; | |
337 bool fentry_reached = false; | |
338 data.found_may_defs = false; | |
339 use = gimple_vuse (stmt); | |
340 int res = walk_aliased_vdefs (&ref, use, | |
341 check_defs, &data, NULL, | |
342 &fentry_reached, limit); | |
343 if (res == -1) | |
344 { | |
345 oracle_cnt += limit; | |
346 continue; | |
347 } | |
348 oracle_cnt += res; | |
349 if (data.found_may_defs) | |
350 continue; | |
351 /* Do not warn if it can be initialized outside this function. | |
352 If we did not reach function entry then we found killing | |
353 clobbers on all paths to entry. */ | |
354 if (fentry_reached | |
355 /* ??? We'd like to use ref_may_alias_global_p but that | |
356 excludes global readonly memory and thus we get bougs | |
357 warnings from p = cond ? "a" : "b" for example. */ | |
358 && (!VAR_P (base) | |
359 || is_global_var (base))) | |
360 continue; | |
361 | |
362 /* We didn't find any may-defs so on all paths either | |
363 reached function entry or a killing clobber. */ | |
364 location_t location | |
365 = linemap_resolve_location (line_table, gimple_location (stmt), | |
366 LRK_SPELLING_LOCATION, NULL); | |
367 if (always_executed) | |
368 { | |
369 if (warning_at (location, OPT_Wuninitialized, | |
370 "%qE is used uninitialized in this function", | |
371 rhs)) | |
372 /* ??? This is only effective for decls as in | |
373 gcc.dg/uninit-B-O0.c. Avoid doing this for | |
374 maybe-uninit uses as it may hide important | |
375 locations. */ | |
376 TREE_NO_WARNING (rhs) = 1; | |
377 } | |
378 else if (warn_possibly_uninitialized) | |
379 warning_at (location, OPT_Wmaybe_uninitialized, | |
380 "%qE may be used uninitialized in this function", | |
381 rhs); | |
382 } | |
383 } | |
384 } | |
385 | |
386 return 0; | |
387 } | |
388 | |
389 /* Checks if the operand OPND of PHI is defined by | |
390 another phi with one operand defined by this PHI, | |
391 but the rest operands are all defined. If yes, | |
392 returns true to skip this operand as being | |
393 redundant. Can be enhanced to be more general. */ | |
394 | |
395 static bool | |
396 can_skip_redundant_opnd (tree opnd, gimple *phi) | |
397 { | |
398 gimple *op_def; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
399 tree phi_def; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
400 int i, n; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
401 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
402 phi_def = gimple_phi_result (phi); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
403 op_def = SSA_NAME_DEF_STMT (opnd); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
404 if (gimple_code (op_def) != GIMPLE_PHI) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
405 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
406 n = gimple_phi_num_args (op_def); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
407 for (i = 0; i < n; ++i) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
408 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
409 tree op = gimple_phi_arg_def (op_def, i); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
410 if (TREE_CODE (op) != SSA_NAME) |
111 | 411 continue; |
412 if (op != phi_def && uninit_undefined_value_p (op)) | |
413 return false; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
414 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
415 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
416 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
417 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
418 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
419 /* Returns a bit mask holding the positions of arguments in PHI |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
420 that have empty (or possibly empty) definitions. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
421 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
422 static unsigned |
111 | 423 compute_uninit_opnds_pos (gphi *phi) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
424 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
425 size_t i, n; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
426 unsigned uninit_opnds = 0; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
427 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
428 n = gimple_phi_num_args (phi); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
429 /* Bail out for phi with too many args. */ |
111 | 430 if (n > max_phi_args) |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
431 return 0; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
432 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433 for (i = 0; i < n; ++i) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
434 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
435 tree op = gimple_phi_arg_def (phi, i); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
436 if (TREE_CODE (op) == SSA_NAME |
111 | 437 && uninit_undefined_value_p (op) |
438 && !can_skip_redundant_opnd (op, phi)) | |
439 { | |
440 if (cfun->has_nonlocal_label || cfun->calls_setjmp) | |
441 { | |
442 /* Ignore SSA_NAMEs that appear on abnormal edges | |
443 somewhere. */ | |
444 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (op)) | |
445 continue; | |
446 } | |
447 MASK_SET_BIT (uninit_opnds, i); | |
448 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
449 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
450 return uninit_opnds; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
451 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
452 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
453 /* Find the immediate postdominator PDOM of the specified |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
454 basic block BLOCK. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
455 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
456 static inline basic_block |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
457 find_pdom (basic_block block) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
458 { |
111 | 459 if (block == EXIT_BLOCK_PTR_FOR_FN (cfun)) |
460 return EXIT_BLOCK_PTR_FOR_FN (cfun); | |
461 else | |
462 { | |
463 basic_block bb = get_immediate_dominator (CDI_POST_DOMINATORS, block); | |
464 if (!bb) | |
465 return EXIT_BLOCK_PTR_FOR_FN (cfun); | |
466 return bb; | |
467 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
468 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
469 |
111 | 470 /* Find the immediate DOM of the specified basic block BLOCK. */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
471 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
472 static inline basic_block |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
473 find_dom (basic_block block) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
474 { |
111 | 475 if (block == ENTRY_BLOCK_PTR_FOR_FN (cfun)) |
476 return ENTRY_BLOCK_PTR_FOR_FN (cfun); | |
477 else | |
478 { | |
479 basic_block bb = get_immediate_dominator (CDI_DOMINATORS, block); | |
480 if (!bb) | |
481 return ENTRY_BLOCK_PTR_FOR_FN (cfun); | |
482 return bb; | |
483 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
484 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
485 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
486 /* Returns true if BB1 is postdominating BB2 and BB1 is |
111 | 487 not a loop exit bb. The loop exit bb check is simple and does |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
488 not cover all cases. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
489 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
490 static bool |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
491 is_non_loop_exit_postdominating (basic_block bb1, basic_block bb2) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
492 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
493 if (!dominated_by_p (CDI_POST_DOMINATORS, bb2, bb1)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
494 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
495 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
496 if (single_pred_p (bb1) && !single_succ_p (bb2)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
497 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
498 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
499 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
500 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
501 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
502 /* Find the closest postdominator of a specified BB, which is control |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
503 equivalent to BB. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
504 |
111 | 505 static inline basic_block |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
506 find_control_equiv_block (basic_block bb) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
507 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
508 basic_block pdom; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
509 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
510 pdom = find_pdom (bb); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
511 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
512 /* Skip the postdominating bb that is also loop exit. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
513 if (!is_non_loop_exit_postdominating (pdom, bb)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
514 return NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
515 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
516 if (dominated_by_p (CDI_DOMINATORS, pdom, bb)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
517 return pdom; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
518 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
519 return NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
520 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
521 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
522 #define MAX_NUM_CHAINS 8 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
523 #define MAX_CHAIN_LEN 5 |
111 | 524 #define MAX_POSTDOM_CHECK 8 |
525 #define MAX_SWITCH_CASES 40 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
526 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
527 /* Computes the control dependence chains (paths of edges) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
528 for DEP_BB up to the dominating basic block BB (the head node of a |
111 | 529 chain should be dominated by it). CD_CHAINS is pointer to an |
530 array holding the result chains. CUR_CD_CHAIN is the current | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
531 chain being computed. *NUM_CHAINS is total number of chains. The |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
532 function returns true if the information is successfully computed, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
533 return false if there is no control dependence or not computed. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
534 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
535 static bool |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
536 compute_control_dep_chain (basic_block bb, basic_block dep_bb, |
111 | 537 vec<edge> *cd_chains, |
538 size_t *num_chains, | |
539 vec<edge> *cur_cd_chain, | |
540 int *num_calls) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
541 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
542 edge_iterator ei; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
543 edge e; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
544 size_t i; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
545 bool found_cd_chain = false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
546 size_t cur_chain_len = 0; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
547 |
111 | 548 if (*num_calls > PARAM_VALUE (PARAM_UNINIT_CONTROL_DEP_ATTEMPTS)) |
549 return false; | |
550 ++*num_calls; | |
551 | |
552 /* Could use a set instead. */ | |
553 cur_chain_len = cur_cd_chain->length (); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
554 if (cur_chain_len > MAX_CHAIN_LEN) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
555 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
556 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
557 for (i = 0; i < cur_chain_len; i++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
558 { |
111 | 559 edge e = (*cur_cd_chain)[i]; |
560 /* Cycle detected. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
561 if (e->src == bb) |
111 | 562 return false; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
563 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
564 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
565 FOR_EACH_EDGE (e, ei, bb->succs) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
566 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
567 basic_block cd_bb; |
111 | 568 int post_dom_check = 0; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
569 if (e->flags & (EDGE_FAKE | EDGE_ABNORMAL)) |
111 | 570 continue; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
571 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
572 cd_bb = e->dest; |
111 | 573 cur_cd_chain->safe_push (e); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
574 while (!is_non_loop_exit_postdominating (cd_bb, bb)) |
111 | 575 { |
576 if (cd_bb == dep_bb) | |
577 { | |
578 /* Found a direct control dependence. */ | |
579 if (*num_chains < MAX_NUM_CHAINS) | |
580 { | |
581 cd_chains[*num_chains] = cur_cd_chain->copy (); | |
582 (*num_chains)++; | |
583 } | |
584 found_cd_chain = true; | |
585 /* Check path from next edge. */ | |
586 break; | |
587 } | |
588 | |
589 /* Now check if DEP_BB is indirectly control dependent on BB. */ | |
590 if (compute_control_dep_chain (cd_bb, dep_bb, cd_chains, num_chains, | |
591 cur_cd_chain, num_calls)) | |
592 { | |
593 found_cd_chain = true; | |
594 break; | |
595 } | |
596 | |
597 cd_bb = find_pdom (cd_bb); | |
598 post_dom_check++; | |
599 if (cd_bb == EXIT_BLOCK_PTR_FOR_FN (cfun) | |
600 || post_dom_check > MAX_POSTDOM_CHECK) | |
601 break; | |
602 } | |
603 cur_cd_chain->pop (); | |
604 gcc_assert (cur_cd_chain->length () == cur_chain_len); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
605 } |
111 | 606 gcc_assert (cur_cd_chain->length () == cur_chain_len); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
607 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
608 return found_cd_chain; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
609 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
610 |
111 | 611 /* The type to represent a simple predicate. */ |
612 | |
613 struct pred_info | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
614 { |
111 | 615 tree pred_lhs; |
616 tree pred_rhs; | |
617 enum tree_code cond_code; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
618 bool invert; |
111 | 619 }; |
620 | |
621 /* The type to represent a sequence of predicates grouped | |
622 with .AND. operation. */ | |
623 | |
624 typedef vec<pred_info, va_heap, vl_ptr> pred_chain; | |
625 | |
626 /* The type to represent a sequence of pred_chains grouped | |
627 with .OR. operation. */ | |
628 | |
629 typedef vec<pred_chain, va_heap, vl_ptr> pred_chain_union; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
630 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
631 /* Converts the chains of control dependence edges into a set of |
111 | 632 predicates. A control dependence chain is represented by a vector |
633 edges. DEP_CHAINS points to an array of dependence chains. | |
634 NUM_CHAINS is the size of the chain array. One edge in a dependence | |
635 chain is mapped to predicate expression represented by pred_info | |
636 type. One dependence chain is converted to a composite predicate that | |
637 is the result of AND operation of pred_info mapped to each edge. | |
638 A composite predicate is presented by a vector of pred_info. On | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
639 return, *PREDS points to the resulting array of composite predicates. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
640 *NUM_PREDS is the number of composite predictes. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
641 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
642 static bool |
111 | 643 convert_control_dep_chain_into_preds (vec<edge> *dep_chains, |
644 size_t num_chains, | |
645 pred_chain_union *preds) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
646 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
647 bool has_valid_pred = false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
648 size_t i, j; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
649 if (num_chains == 0 || num_chains >= MAX_NUM_CHAINS) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
650 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
651 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
652 /* Now convert the control dep chain into a set |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
653 of predicates. */ |
111 | 654 preds->reserve (num_chains); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
655 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
656 for (i = 0; i < num_chains; i++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
657 { |
111 | 658 vec<edge> one_cd_chain = dep_chains[i]; |
659 | |
660 has_valid_pred = false; | |
661 pred_chain t_chain = vNULL; | |
662 for (j = 0; j < one_cd_chain.length (); j++) | |
663 { | |
664 gimple *cond_stmt; | |
665 gimple_stmt_iterator gsi; | |
666 basic_block guard_bb; | |
667 pred_info one_pred; | |
668 edge e; | |
669 | |
670 e = one_cd_chain[j]; | |
671 guard_bb = e->src; | |
672 gsi = gsi_last_bb (guard_bb); | |
131 | 673 /* Ignore empty forwarder blocks. */ |
674 if (empty_block_p (guard_bb) && single_succ_p (guard_bb)) | |
675 continue; | |
676 /* An empty basic block here is likely a PHI, and is not one | |
677 of the cases we handle below. */ | |
111 | 678 if (gsi_end_p (gsi)) |
679 { | |
680 has_valid_pred = false; | |
681 break; | |
682 } | |
683 cond_stmt = gsi_stmt (gsi); | |
684 if (is_gimple_call (cond_stmt) && EDGE_COUNT (e->src->succs) >= 2) | |
685 /* Ignore EH edge. Can add assertion on the other edge's flag. */ | |
686 continue; | |
687 /* Skip if there is essentially one succesor. */ | |
688 if (EDGE_COUNT (e->src->succs) == 2) | |
689 { | |
690 edge e1; | |
691 edge_iterator ei1; | |
692 bool skip = false; | |
693 | |
694 FOR_EACH_EDGE (e1, ei1, e->src->succs) | |
695 { | |
696 if (EDGE_COUNT (e1->dest->succs) == 0) | |
697 { | |
698 skip = true; | |
699 break; | |
700 } | |
701 } | |
702 if (skip) | |
703 continue; | |
704 } | |
705 if (gimple_code (cond_stmt) == GIMPLE_COND) | |
706 { | |
707 one_pred.pred_lhs = gimple_cond_lhs (cond_stmt); | |
708 one_pred.pred_rhs = gimple_cond_rhs (cond_stmt); | |
709 one_pred.cond_code = gimple_cond_code (cond_stmt); | |
710 one_pred.invert = !!(e->flags & EDGE_FALSE_VALUE); | |
711 t_chain.safe_push (one_pred); | |
712 has_valid_pred = true; | |
713 } | |
714 else if (gswitch *gs = dyn_cast<gswitch *> (cond_stmt)) | |
715 { | |
716 /* Avoid quadratic behavior. */ | |
717 if (gimple_switch_num_labels (gs) > MAX_SWITCH_CASES) | |
718 { | |
719 has_valid_pred = false; | |
720 break; | |
721 } | |
722 /* Find the case label. */ | |
723 tree l = NULL_TREE; | |
724 unsigned idx; | |
725 for (idx = 0; idx < gimple_switch_num_labels (gs); ++idx) | |
726 { | |
727 tree tl = gimple_switch_label (gs, idx); | |
131 | 728 if (e->dest == label_to_block (cfun, CASE_LABEL (tl))) |
111 | 729 { |
730 if (!l) | |
731 l = tl; | |
732 else | |
733 { | |
734 l = NULL_TREE; | |
735 break; | |
736 } | |
737 } | |
738 } | |
739 /* If more than one label reaches this block or the case | |
740 label doesn't have a single value (like the default one) | |
741 fail. */ | |
742 if (!l | |
743 || !CASE_LOW (l) | |
744 || (CASE_HIGH (l) | |
745 && !operand_equal_p (CASE_LOW (l), CASE_HIGH (l), 0))) | |
746 { | |
747 has_valid_pred = false; | |
748 break; | |
749 } | |
750 one_pred.pred_lhs = gimple_switch_index (gs); | |
751 one_pred.pred_rhs = CASE_LOW (l); | |
752 one_pred.cond_code = EQ_EXPR; | |
753 one_pred.invert = false; | |
754 t_chain.safe_push (one_pred); | |
755 has_valid_pred = true; | |
756 } | |
757 else | |
758 { | |
759 has_valid_pred = false; | |
760 break; | |
761 } | |
762 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
763 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
764 if (!has_valid_pred) |
111 | 765 break; |
766 else | |
767 preds->safe_push (t_chain); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
768 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
769 return has_valid_pred; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
770 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
771 |
111 | 772 /* Computes all control dependence chains for USE_BB. The control |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
773 dependence chains are then converted to an array of composite |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
774 predicates pointed to by PREDS. PHI_BB is the basic block of |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
775 the phi whose result is used in USE_BB. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
776 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
777 static bool |
111 | 778 find_predicates (pred_chain_union *preds, |
779 basic_block phi_bb, | |
780 basic_block use_bb) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
781 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
782 size_t num_chains = 0, i; |
111 | 783 int num_calls = 0; |
784 vec<edge> dep_chains[MAX_NUM_CHAINS]; | |
785 auto_vec<edge, MAX_CHAIN_LEN + 1> cur_chain; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
786 bool has_valid_pred = false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
787 basic_block cd_root = 0; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
788 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
789 /* First find the closest bb that is control equivalent to PHI_BB |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
790 that also dominates USE_BB. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
791 cd_root = phi_bb; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
792 while (dominated_by_p (CDI_DOMINATORS, use_bb, cd_root)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
793 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
794 basic_block ctrl_eq_bb = find_control_equiv_block (cd_root); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
795 if (ctrl_eq_bb && dominated_by_p (CDI_DOMINATORS, use_bb, ctrl_eq_bb)) |
111 | 796 cd_root = ctrl_eq_bb; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
797 else |
111 | 798 break; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
799 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
800 |
111 | 801 compute_control_dep_chain (cd_root, use_bb, dep_chains, &num_chains, |
802 &cur_chain, &num_calls); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
803 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
804 has_valid_pred |
111 | 805 = convert_control_dep_chain_into_preds (dep_chains, num_chains, preds); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
806 for (i = 0; i < num_chains; i++) |
111 | 807 dep_chains[i].release (); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
808 return has_valid_pred; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
809 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
810 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
811 /* Computes the set of incoming edges of PHI that have non empty |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
812 definitions of a phi chain. The collection will be done |
111 | 813 recursively on operands that are defined by phis. CD_ROOT |
814 is the control dependence root. *EDGES holds the result, and | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
815 VISITED_PHIS is a pointer set for detecting cycles. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
816 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
817 static void |
111 | 818 collect_phi_def_edges (gphi *phi, basic_block cd_root, |
819 auto_vec<edge> *edges, | |
820 hash_set<gimple *> *visited_phis) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
821 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
822 size_t i, n; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
823 edge opnd_edge; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
824 tree opnd; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
825 |
111 | 826 if (visited_phis->add (phi)) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
827 return; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
828 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
829 n = gimple_phi_num_args (phi); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
830 for (i = 0; i < n; i++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
831 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
832 opnd_edge = gimple_phi_arg_edge (phi, i); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
833 opnd = gimple_phi_arg_def (phi, i); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
834 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
835 if (TREE_CODE (opnd) != SSA_NAME) |
111 | 836 { |
837 if (dump_file && (dump_flags & TDF_DETAILS)) | |
838 { | |
839 fprintf (dump_file, "\n[CHECK] Found def edge %d in ", (int) i); | |
840 print_gimple_stmt (dump_file, phi, 0); | |
841 } | |
842 edges->safe_push (opnd_edge); | |
843 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
844 else |
111 | 845 { |
846 gimple *def = SSA_NAME_DEF_STMT (opnd); | |
847 | |
848 if (gimple_code (def) == GIMPLE_PHI | |
849 && dominated_by_p (CDI_DOMINATORS, gimple_bb (def), cd_root)) | |
850 collect_phi_def_edges (as_a<gphi *> (def), cd_root, edges, | |
851 visited_phis); | |
852 else if (!uninit_undefined_value_p (opnd)) | |
853 { | |
854 if (dump_file && (dump_flags & TDF_DETAILS)) | |
855 { | |
856 fprintf (dump_file, "\n[CHECK] Found def edge %d in ", | |
857 (int) i); | |
858 print_gimple_stmt (dump_file, phi, 0); | |
859 } | |
860 edges->safe_push (opnd_edge); | |
861 } | |
862 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
863 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
864 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
865 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
866 /* For each use edge of PHI, computes all control dependence chains. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
867 The control dependence chains are then converted to an array of |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
868 composite predicates pointed to by PREDS. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
869 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
870 static bool |
111 | 871 find_def_preds (pred_chain_union *preds, gphi *phi) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
872 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
873 size_t num_chains = 0, i, n; |
111 | 874 vec<edge> dep_chains[MAX_NUM_CHAINS]; |
875 auto_vec<edge, MAX_CHAIN_LEN + 1> cur_chain; | |
876 auto_vec<edge> def_edges; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
877 bool has_valid_pred = false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
878 basic_block phi_bb, cd_root = 0; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
879 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
880 phi_bb = gimple_bb (phi); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
881 /* First find the closest dominating bb to be |
111 | 882 the control dependence root. */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
883 cd_root = find_dom (phi_bb); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
884 if (!cd_root) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
885 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
886 |
111 | 887 hash_set<gimple *> visited_phis; |
888 collect_phi_def_edges (phi, cd_root, &def_edges, &visited_phis); | |
889 | |
890 n = def_edges.length (); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
891 if (n == 0) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
892 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
893 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
894 for (i = 0; i < n; i++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
895 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
896 size_t prev_nc, j; |
111 | 897 int num_calls = 0; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
898 edge opnd_edge; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
899 |
111 | 900 opnd_edge = def_edges[i]; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
901 prev_nc = num_chains; |
111 | 902 compute_control_dep_chain (cd_root, opnd_edge->src, dep_chains, |
903 &num_chains, &cur_chain, &num_calls); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
904 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
905 /* Now update the newly added chains with |
111 | 906 the phi operand edge: */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
907 if (EDGE_COUNT (opnd_edge->src->succs) > 1) |
111 | 908 { |
909 if (prev_nc == num_chains && num_chains < MAX_NUM_CHAINS) | |
910 dep_chains[num_chains++] = vNULL; | |
911 for (j = prev_nc; j < num_chains; j++) | |
912 dep_chains[j].safe_push (opnd_edge); | |
913 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
914 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
915 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
916 has_valid_pred |
111 | 917 = convert_control_dep_chain_into_preds (dep_chains, num_chains, preds); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
918 for (i = 0; i < num_chains; i++) |
111 | 919 dep_chains[i].release (); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
920 return has_valid_pred; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
921 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
922 |
131 | 923 /* Dump a pred_info. */ |
924 | |
925 static void | |
926 dump_pred_info (pred_info one_pred) | |
927 { | |
928 if (one_pred.invert) | |
929 fprintf (dump_file, " (.NOT.) "); | |
930 print_generic_expr (dump_file, one_pred.pred_lhs); | |
931 fprintf (dump_file, " %s ", op_symbol_code (one_pred.cond_code)); | |
932 print_generic_expr (dump_file, one_pred.pred_rhs); | |
933 } | |
934 | |
935 /* Dump a pred_chain. */ | |
936 | |
937 static void | |
938 dump_pred_chain (pred_chain one_pred_chain) | |
939 { | |
940 size_t np = one_pred_chain.length (); | |
941 for (size_t j = 0; j < np; j++) | |
942 { | |
943 dump_pred_info (one_pred_chain[j]); | |
944 if (j < np - 1) | |
945 fprintf (dump_file, " (.AND.) "); | |
946 else | |
947 fprintf (dump_file, "\n"); | |
948 } | |
949 } | |
950 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
951 /* Dumps the predicates (PREDS) for USESTMT. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
952 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
953 static void |
111 | 954 dump_predicates (gimple *usestmt, pred_chain_union preds, const char *msg) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
955 { |
111 | 956 fprintf (dump_file, "%s", msg); |
131 | 957 if (usestmt) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
958 { |
131 | 959 print_gimple_stmt (dump_file, usestmt, 0); |
960 fprintf (dump_file, "is guarded by :\n\n"); | |
961 } | |
962 size_t num_preds = preds.length (); | |
963 for (size_t i = 0; i < num_preds; i++) | |
964 { | |
965 dump_pred_chain (preds[i]); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
966 if (i < num_preds - 1) |
111 | 967 fprintf (dump_file, "(.OR.)\n"); |
968 else | |
969 fprintf (dump_file, "\n\n"); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
970 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
971 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
972 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
973 /* Destroys the predicate set *PREDS. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
974 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
975 static void |
111 | 976 destroy_predicate_vecs (pred_chain_union *preds) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
977 { |
111 | 978 size_t i; |
979 | |
980 size_t n = preds->length (); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
981 for (i = 0; i < n; i++) |
111 | 982 (*preds)[i].release (); |
983 preds->release (); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
984 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
985 |
111 | 986 /* Computes the 'normalized' conditional code with operand |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
987 swapping and condition inversion. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
988 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
989 static enum tree_code |
111 | 990 get_cmp_code (enum tree_code orig_cmp_code, bool swap_cond, bool invert) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
991 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
992 enum tree_code tc = orig_cmp_code; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
993 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
994 if (swap_cond) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
995 tc = swap_tree_comparison (orig_cmp_code); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
996 if (invert) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
997 tc = invert_tree_comparison (tc, false); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
998 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
999 switch (tc) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1000 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1001 case LT_EXPR: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1002 case LE_EXPR: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1003 case GT_EXPR: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1004 case GE_EXPR: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1005 case EQ_EXPR: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1006 case NE_EXPR: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1007 break; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1008 default: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1009 return ERROR_MARK; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1010 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1011 return tc; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1012 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1013 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1014 /* Returns true if VAL falls in the range defined by BOUNDARY and CMPC, i.e. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1015 all values in the range satisfies (x CMPC BOUNDARY) == true. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1016 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1017 static bool |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1018 is_value_included_in (tree val, tree boundary, enum tree_code cmpc) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1019 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1020 bool inverted = false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1021 bool is_unsigned; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1022 bool result; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1023 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1024 /* Only handle integer constant here. */ |
111 | 1025 if (TREE_CODE (val) != INTEGER_CST || TREE_CODE (boundary) != INTEGER_CST) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1026 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1027 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1028 is_unsigned = TYPE_UNSIGNED (TREE_TYPE (val)); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1029 |
111 | 1030 if (cmpc == GE_EXPR || cmpc == GT_EXPR || cmpc == NE_EXPR) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1031 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1032 cmpc = invert_tree_comparison (cmpc, false); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1033 inverted = true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1034 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1035 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1036 if (is_unsigned) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1037 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1038 if (cmpc == EQ_EXPR) |
111 | 1039 result = tree_int_cst_equal (val, boundary); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1040 else if (cmpc == LT_EXPR) |
111 | 1041 result = tree_int_cst_lt (val, boundary); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1042 else |
111 | 1043 { |
1044 gcc_assert (cmpc == LE_EXPR); | |
1045 result = tree_int_cst_le (val, boundary); | |
1046 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1047 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1048 else |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1049 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1050 if (cmpc == EQ_EXPR) |
111 | 1051 result = tree_int_cst_equal (val, boundary); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1052 else if (cmpc == LT_EXPR) |
111 | 1053 result = tree_int_cst_lt (val, boundary); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1054 else |
111 | 1055 { |
1056 gcc_assert (cmpc == LE_EXPR); | |
1057 result = (tree_int_cst_equal (val, boundary) | |
1058 || tree_int_cst_lt (val, boundary)); | |
1059 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1060 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1061 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1062 if (inverted) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1063 result ^= 1; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1064 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1065 return result; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1066 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1067 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1068 /* Returns true if PRED is common among all the predicate |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1069 chains (PREDS) (and therefore can be factored out). |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1070 NUM_PRED_CHAIN is the size of array PREDS. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1071 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1072 static bool |
111 | 1073 find_matching_predicate_in_rest_chains (pred_info pred, |
1074 pred_chain_union preds, | |
1075 size_t num_pred_chains) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1076 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1077 size_t i, j, n; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1078 |
111 | 1079 /* Trival case. */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1080 if (num_pred_chains == 1) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1081 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1082 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1083 for (i = 1; i < num_pred_chains; i++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1084 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1085 bool found = false; |
111 | 1086 pred_chain one_chain = preds[i]; |
1087 n = one_chain.length (); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1088 for (j = 0; j < n; j++) |
111 | 1089 { |
1090 pred_info pred2 = one_chain[j]; | |
1091 /* Can relax the condition comparison to not | |
1092 use address comparison. However, the most common | |
1093 case is that multiple control dependent paths share | |
1094 a common path prefix, so address comparison should | |
1095 be ok. */ | |
1096 | |
1097 if (operand_equal_p (pred2.pred_lhs, pred.pred_lhs, 0) | |
1098 && operand_equal_p (pred2.pred_rhs, pred.pred_rhs, 0) | |
1099 && pred2.invert == pred.invert) | |
1100 { | |
1101 found = true; | |
1102 break; | |
1103 } | |
1104 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1105 if (!found) |
111 | 1106 return false; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1107 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1108 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1109 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1110 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1111 /* Forward declaration. */ |
111 | 1112 static bool is_use_properly_guarded (gimple *use_stmt, |
1113 basic_block use_bb, | |
1114 gphi *phi, | |
1115 unsigned uninit_opnds, | |
1116 pred_chain_union *def_preds, | |
1117 hash_set<gphi *> *visited_phis); | |
1118 | |
1119 /* Returns true if all uninitialized opnds are pruned. Returns false | |
1120 otherwise. PHI is the phi node with uninitialized operands, | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1121 UNINIT_OPNDS is the bitmap of the uninitialize operand positions, |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1122 FLAG_DEF is the statement defining the flag guarding the use of the |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1123 PHI output, BOUNDARY_CST is the const value used in the predicate |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1124 associated with the flag, CMP_CODE is the comparison code used in |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1125 the predicate, VISITED_PHIS is the pointer set of phis visited, and |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1126 VISITED_FLAG_PHIS is the pointer to the pointer set of flag definitions |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1127 that are also phis. |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1128 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1129 Example scenario: |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1130 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1131 BB1: |
111 | 1132 flag_1 = phi <0, 1> // (1) |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1133 var_1 = phi <undef, some_val> |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1134 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1135 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1136 BB2: |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1137 flag_2 = phi <0, flag_1, flag_1> // (2) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1138 var_2 = phi <undef, var_1, var_1> |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1139 if (flag_2 == 1) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1140 goto BB3; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1141 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1142 BB3: |
111 | 1143 use of var_2 // (3) |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1144 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1145 Because some flag arg in (1) is not constant, if we do not look into the |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1146 flag phis recursively, it is conservatively treated as unknown and var_1 |
111 | 1147 is thought to be flowed into use at (3). Since var_1 is potentially |
1148 uninitialized a false warning will be emitted. | |
1149 Checking recursively into (1), the compiler can find out that only some_val | |
1150 (which is defined) can flow into (3) which is OK. */ | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1151 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1152 static bool |
111 | 1153 prune_uninit_phi_opnds (gphi *phi, unsigned uninit_opnds, gphi *flag_def, |
1154 tree boundary_cst, enum tree_code cmp_code, | |
1155 hash_set<gphi *> *visited_phis, | |
1156 bitmap *visited_flag_phis) | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1157 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1158 unsigned i; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1159 |
111 | 1160 for (i = 0; i < MIN (max_phi_args, gimple_phi_num_args (flag_def)); i++) |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1161 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1162 tree flag_arg; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1163 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1164 if (!MASK_TEST_BIT (uninit_opnds, i)) |
111 | 1165 continue; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1166 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1167 flag_arg = gimple_phi_arg_def (flag_def, i); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1168 if (!is_gimple_constant (flag_arg)) |
111 | 1169 { |
1170 gphi *flag_arg_def, *phi_arg_def; | |
1171 tree phi_arg; | |
1172 unsigned uninit_opnds_arg_phi; | |
1173 | |
1174 if (TREE_CODE (flag_arg) != SSA_NAME) | |
1175 return false; | |
1176 flag_arg_def = dyn_cast<gphi *> (SSA_NAME_DEF_STMT (flag_arg)); | |
1177 if (!flag_arg_def) | |
1178 return false; | |
1179 | |
1180 phi_arg = gimple_phi_arg_def (phi, i); | |
1181 if (TREE_CODE (phi_arg) != SSA_NAME) | |
1182 return false; | |
1183 | |
1184 phi_arg_def = dyn_cast<gphi *> (SSA_NAME_DEF_STMT (phi_arg)); | |
1185 if (!phi_arg_def) | |
1186 return false; | |
1187 | |
1188 if (gimple_bb (phi_arg_def) != gimple_bb (flag_arg_def)) | |
1189 return false; | |
1190 | |
1191 if (!*visited_flag_phis) | |
1192 *visited_flag_phis = BITMAP_ALLOC (NULL); | |
1193 | |
1194 tree phi_result = gimple_phi_result (flag_arg_def); | |
1195 if (bitmap_bit_p (*visited_flag_phis, SSA_NAME_VERSION (phi_result))) | |
1196 return false; | |
1197 | |
1198 bitmap_set_bit (*visited_flag_phis, | |
1199 SSA_NAME_VERSION (gimple_phi_result (flag_arg_def))); | |
1200 | |
1201 /* Now recursively prune the uninitialized phi args. */ | |
1202 uninit_opnds_arg_phi = compute_uninit_opnds_pos (phi_arg_def); | |
1203 if (!prune_uninit_phi_opnds | |
1204 (phi_arg_def, uninit_opnds_arg_phi, flag_arg_def, boundary_cst, | |
1205 cmp_code, visited_phis, visited_flag_phis)) | |
1206 return false; | |
1207 | |
1208 phi_result = gimple_phi_result (flag_arg_def); | |
1209 bitmap_clear_bit (*visited_flag_phis, SSA_NAME_VERSION (phi_result)); | |
1210 continue; | |
1211 } | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1212 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1213 /* Now check if the constant is in the guarded range. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1214 if (is_value_included_in (flag_arg, boundary_cst, cmp_code)) |
111 | 1215 { |
1216 tree opnd; | |
1217 gimple *opnd_def; | |
1218 | |
1219 /* Now that we know that this undefined edge is not | |
1220 pruned. If the operand is defined by another phi, | |
1221 we can further prune the incoming edges of that | |
1222 phi by checking the predicates of this operands. */ | |
1223 | |
1224 opnd = gimple_phi_arg_def (phi, i); | |
1225 opnd_def = SSA_NAME_DEF_STMT (opnd); | |
1226 if (gphi *opnd_def_phi = dyn_cast <gphi *> (opnd_def)) | |
1227 { | |
1228 edge opnd_edge; | |
1229 unsigned uninit_opnds2 = compute_uninit_opnds_pos (opnd_def_phi); | |
1230 if (!MASK_EMPTY (uninit_opnds2)) | |
1231 { | |
1232 pred_chain_union def_preds = vNULL; | |
1233 bool ok; | |
1234 opnd_edge = gimple_phi_arg_edge (phi, i); | |
1235 ok = is_use_properly_guarded (phi, | |
1236 opnd_edge->src, | |
1237 opnd_def_phi, | |
1238 uninit_opnds2, | |
1239 &def_preds, | |
1240 visited_phis); | |
1241 destroy_predicate_vecs (&def_preds); | |
1242 if (!ok) | |
1243 return false; | |
1244 } | |
1245 } | |
1246 else | |
1247 return false; | |
1248 } | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1249 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1250 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1251 return true; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1252 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1253 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1254 /* A helper function that determines if the predicate set |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1255 of the use is not overlapping with that of the uninit paths. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1256 The most common senario of guarded use is in Example 1: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1257 Example 1: |
111 | 1258 if (some_cond) |
1259 { | |
1260 x = ...; | |
1261 flag = true; | |
1262 } | |
1263 | |
1264 ... some code ... | |
1265 | |
1266 if (flag) | |
1267 use (x); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1268 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1269 The real world examples are usually more complicated, but similar |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1270 and usually result from inlining: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1271 |
111 | 1272 bool init_func (int * x) |
1273 { | |
1274 if (some_cond) | |
1275 return false; | |
1276 *x = .. | |
1277 return true; | |
1278 } | |
1279 | |
1280 void foo (..) | |
1281 { | |
1282 int x; | |
1283 | |
1284 if (!init_func (&x)) | |
1285 return; | |
1286 | |
1287 .. some_code ... | |
1288 use (x); | |
1289 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1290 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1291 Another possible use scenario is in the following trivial example: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1292 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1293 Example 2: |
111 | 1294 if (n > 0) |
1295 x = 1; | |
1296 ... | |
1297 if (n > 0) | |
1298 { | |
1299 if (m < 2) | |
1300 .. = x; | |
1301 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1302 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1303 Predicate analysis needs to compute the composite predicate: |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1304 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1305 1) 'x' use predicate: (n > 0) .AND. (m < 2) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1306 2) 'x' default value (non-def) predicate: .NOT. (n > 0) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1307 (the predicate chain for phi operand defs can be computed |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1308 starting from a bb that is control equivalent to the phi's |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1309 bb and is dominating the operand def.) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1310 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1311 and check overlapping: |
111 | 1312 (n > 0) .AND. (m < 2) .AND. (.NOT. (n > 0)) |
1313 <==> false | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1314 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1315 This implementation provides framework that can handle |
111 | 1316 scenarios. (Note that many simple cases are handled properly |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1317 without the predicate analysis -- this is due to jump threading |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1318 transformation which eliminates the merge point thus makes |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1319 path sensitive analysis unnecessary.) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1320 |
111 | 1321 PHI is the phi node whose incoming (undefined) paths need to be |
1322 pruned, and UNINIT_OPNDS is the bitmap holding uninit operand | |
1323 positions. VISITED_PHIS is the pointer set of phi stmts being | |
1324 checked. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1325 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1326 static bool |
111 | 1327 use_pred_not_overlap_with_undef_path_pred (pred_chain_union preds, |
1328 gphi *phi, unsigned uninit_opnds, | |
1329 hash_set<gphi *> *visited_phis) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1330 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1331 unsigned int i, n; |
111 | 1332 gimple *flag_def = 0; |
1333 tree boundary_cst = 0; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1334 enum tree_code cmp_code; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1335 bool swap_cond = false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1336 bool invert = false; |
111 | 1337 pred_chain the_pred_chain = vNULL; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1338 bitmap visited_flag_phis = NULL; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1339 bool all_pruned = false; |
111 | 1340 size_t num_preds = preds.length (); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1341 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1342 gcc_assert (num_preds > 0); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1343 /* Find within the common prefix of multiple predicate chains |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1344 a predicate that is a comparison of a flag variable against |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1345 a constant. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1346 the_pred_chain = preds[0]; |
111 | 1347 n = the_pred_chain.length (); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1348 for (i = 0; i < n; i++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1349 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1350 tree cond_lhs, cond_rhs, flag = 0; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1351 |
111 | 1352 pred_info the_pred = the_pred_chain[i]; |
1353 | |
1354 invert = the_pred.invert; | |
1355 cond_lhs = the_pred.pred_lhs; | |
1356 cond_rhs = the_pred.pred_rhs; | |
1357 cmp_code = the_pred.cond_code; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1358 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1359 if (cond_lhs != NULL_TREE && TREE_CODE (cond_lhs) == SSA_NAME |
111 | 1360 && cond_rhs != NULL_TREE && is_gimple_constant (cond_rhs)) |
1361 { | |
1362 boundary_cst = cond_rhs; | |
1363 flag = cond_lhs; | |
1364 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1365 else if (cond_rhs != NULL_TREE && TREE_CODE (cond_rhs) == SSA_NAME |
111 | 1366 && cond_lhs != NULL_TREE && is_gimple_constant (cond_lhs)) |
1367 { | |
1368 boundary_cst = cond_lhs; | |
1369 flag = cond_rhs; | |
1370 swap_cond = true; | |
1371 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1372 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1373 if (!flag) |
111 | 1374 continue; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1375 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1376 flag_def = SSA_NAME_DEF_STMT (flag); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1377 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1378 if (!flag_def) |
111 | 1379 continue; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1380 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1381 if ((gimple_code (flag_def) == GIMPLE_PHI) |
111 | 1382 && (gimple_bb (flag_def) == gimple_bb (phi)) |
1383 && find_matching_predicate_in_rest_chains (the_pred, preds, | |
1384 num_preds)) | |
1385 break; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1386 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1387 flag_def = 0; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1388 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1389 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1390 if (!flag_def) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1391 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1392 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1393 /* Now check all the uninit incoming edge has a constant flag value |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1394 that is in conflict with the use guard/predicate. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1395 cmp_code = get_cmp_code (cmp_code, swap_cond, invert); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1396 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1397 if (cmp_code == ERROR_MARK) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1398 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1399 |
111 | 1400 all_pruned = prune_uninit_phi_opnds |
1401 (phi, uninit_opnds, as_a<gphi *> (flag_def), boundary_cst, cmp_code, | |
1402 visited_phis, &visited_flag_phis); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1403 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1404 if (visited_flag_phis) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1405 BITMAP_FREE (visited_flag_phis); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1406 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1407 return all_pruned; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1408 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1409 |
111 | 1410 /* The helper function returns true if two predicates X1 and X2 |
1411 are equivalent. It assumes the expressions have already | |
1412 properly re-associated. */ | |
1413 | |
1414 static inline bool | |
1415 pred_equal_p (pred_info x1, pred_info x2) | |
1416 { | |
1417 enum tree_code c1, c2; | |
1418 if (!operand_equal_p (x1.pred_lhs, x2.pred_lhs, 0) | |
1419 || !operand_equal_p (x1.pred_rhs, x2.pred_rhs, 0)) | |
1420 return false; | |
1421 | |
1422 c1 = x1.cond_code; | |
1423 if (x1.invert != x2.invert | |
1424 && TREE_CODE_CLASS (x2.cond_code) == tcc_comparison) | |
1425 c2 = invert_tree_comparison (x2.cond_code, false); | |
1426 else | |
1427 c2 = x2.cond_code; | |
1428 | |
1429 return c1 == c2; | |
1430 } | |
1431 | |
1432 /* Returns true if the predication is testing !=. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1433 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1434 static inline bool |
111 | 1435 is_neq_relop_p (pred_info pred) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1436 { |
111 | 1437 |
1438 return ((pred.cond_code == NE_EXPR && !pred.invert) | |
1439 || (pred.cond_code == EQ_EXPR && pred.invert)); | |
1440 } | |
1441 | |
1442 /* Returns true if pred is of the form X != 0. */ | |
1443 | |
1444 static inline bool | |
1445 is_neq_zero_form_p (pred_info pred) | |
1446 { | |
1447 if (!is_neq_relop_p (pred) || !integer_zerop (pred.pred_rhs) | |
1448 || TREE_CODE (pred.pred_lhs) != SSA_NAME) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1449 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1450 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1451 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1452 |
111 | 1453 /* The helper function returns true if two predicates X1 |
1454 is equivalent to X2 != 0. */ | |
1455 | |
1456 static inline bool | |
1457 pred_expr_equal_p (pred_info x1, tree x2) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1458 { |
111 | 1459 if (!is_neq_zero_form_p (x1)) |
1460 return false; | |
1461 | |
1462 return operand_equal_p (x1.pred_lhs, x2, 0); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1463 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1464 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1465 /* Returns true of the domain of single predicate expression |
111 | 1466 EXPR1 is a subset of that of EXPR2. Returns false if it |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1467 can not be proved. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1468 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1469 static bool |
111 | 1470 is_pred_expr_subset_of (pred_info expr1, pred_info expr2) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1471 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1472 enum tree_code code1, code2; |
111 | 1473 |
1474 if (pred_equal_p (expr1, expr2)) | |
1475 return true; | |
1476 | |
1477 if ((TREE_CODE (expr1.pred_rhs) != INTEGER_CST) | |
1478 || (TREE_CODE (expr2.pred_rhs) != INTEGER_CST)) | |
1479 return false; | |
1480 | |
1481 if (!operand_equal_p (expr1.pred_lhs, expr2.pred_lhs, 0)) | |
1482 return false; | |
1483 | |
1484 code1 = expr1.cond_code; | |
1485 if (expr1.invert) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1486 code1 = invert_tree_comparison (code1, false); |
111 | 1487 code2 = expr2.cond_code; |
1488 if (expr2.invert) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1489 code2 = invert_tree_comparison (code2, false); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1490 |
111 | 1491 if ((code1 == EQ_EXPR || code1 == BIT_AND_EXPR) && code2 == BIT_AND_EXPR) |
1492 return (wi::to_wide (expr1.pred_rhs) | |
1493 == (wi::to_wide (expr1.pred_rhs) & wi::to_wide (expr2.pred_rhs))); | |
1494 | |
1495 if (code1 != code2 && code2 != NE_EXPR) | |
1496 return false; | |
1497 | |
1498 if (is_value_included_in (expr1.pred_rhs, expr2.pred_rhs, code2)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1499 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1500 |
111 | 1501 return false; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1502 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1503 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1504 /* Returns true if the domain of PRED1 is a subset |
111 | 1505 of that of PRED2. Returns false if it can not be proved so. */ |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1506 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1507 static bool |
111 | 1508 is_pred_chain_subset_of (pred_chain pred1, pred_chain pred2) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1509 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1510 size_t np1, np2, i1, i2; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1511 |
111 | 1512 np1 = pred1.length (); |
1513 np2 = pred2.length (); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1514 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1515 for (i2 = 0; i2 < np2; i2++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1516 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1517 bool found = false; |
111 | 1518 pred_info info2 = pred2[i2]; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1519 for (i1 = 0; i1 < np1; i1++) |
111 | 1520 { |
1521 pred_info info1 = pred1[i1]; | |
1522 if (is_pred_expr_subset_of (info1, info2)) | |
1523 { | |
1524 found = true; | |
1525 break; | |
1526 } | |
1527 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1528 if (!found) |
111 | 1529 return false; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1530 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1531 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1532 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1533 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1534 /* Returns true if the domain defined by |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1535 one pred chain ONE_PRED is a subset of the domain |
111 | 1536 of *PREDS. It returns false if ONE_PRED's domain is |
1537 not a subset of any of the sub-domains of PREDS | |
1538 (corresponding to each individual chains in it), even | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1539 though it may be still be a subset of whole domain |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1540 of PREDS which is the union (ORed) of all its subdomains. |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1541 In other words, the result is conservative. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1542 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1543 static bool |
111 | 1544 is_included_in (pred_chain one_pred, pred_chain_union preds) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1545 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1546 size_t i; |
111 | 1547 size_t n = preds.length (); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1548 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1549 for (i = 0; i < n; i++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1550 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1551 if (is_pred_chain_subset_of (one_pred, preds[i])) |
111 | 1552 return true; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1553 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1554 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1555 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1556 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1557 |
111 | 1558 /* Compares two predicate sets PREDS1 and PREDS2 and returns |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1559 true if the domain defined by PREDS1 is a superset |
111 | 1560 of PREDS2's domain. N1 and N2 are array sizes of PREDS1 and |
1561 PREDS2 respectively. The implementation chooses not to build | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1562 generic trees (and relying on the folding capability of the |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1563 compiler), but instead performs brute force comparison of |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1564 individual predicate chains (won't be a compile time problem |
111 | 1565 as the chains are pretty short). When the function returns |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1566 false, it does not necessarily mean *PREDS1 is not a superset |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1567 of *PREDS2, but mean it may not be so since the analysis can |
111 | 1568 not prove it. In such cases, false warnings may still be |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1569 emitted. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1570 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1571 static bool |
111 | 1572 is_superset_of (pred_chain_union preds1, pred_chain_union preds2) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1573 { |
111 | 1574 size_t i, n2; |
1575 pred_chain one_pred_chain = vNULL; | |
1576 | |
1577 n2 = preds2.length (); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1578 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1579 for (i = 0; i < n2; i++) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1580 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1581 one_pred_chain = preds2[i]; |
111 | 1582 if (!is_included_in (one_pred_chain, preds1)) |
1583 return false; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1584 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1585 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1586 return true; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1587 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1588 |
111 | 1589 /* Returns true if X1 is the negate of X2. */ |
1590 | |
1591 static inline bool | |
1592 pred_neg_p (pred_info x1, pred_info x2) | |
1593 { | |
1594 enum tree_code c1, c2; | |
1595 if (!operand_equal_p (x1.pred_lhs, x2.pred_lhs, 0) | |
1596 || !operand_equal_p (x1.pred_rhs, x2.pred_rhs, 0)) | |
1597 return false; | |
1598 | |
1599 c1 = x1.cond_code; | |
1600 if (x1.invert == x2.invert) | |
1601 c2 = invert_tree_comparison (x2.cond_code, false); | |
1602 else | |
1603 c2 = x2.cond_code; | |
1604 | |
1605 return c1 == c2; | |
1606 } | |
1607 | |
1608 /* 1) ((x IOR y) != 0) AND (x != 0) is equivalent to (x != 0); | |
1609 2) (X AND Y) OR (!X AND Y) is equivalent to Y; | |
1610 3) X OR (!X AND Y) is equivalent to (X OR Y); | |
1611 4) ((x IAND y) != 0) || (x != 0 AND y != 0)) is equivalent to | |
1612 (x != 0 AND y != 0) | |
1613 5) (X AND Y) OR (!X AND Z) OR (!Y AND Z) is equivalent to | |
1614 (X AND Y) OR Z | |
1615 | |
1616 PREDS is the predicate chains, and N is the number of chains. */ | |
1617 | |
1618 /* Helper function to implement rule 1 above. ONE_CHAIN is | |
1619 the AND predication to be simplified. */ | |
1620 | |
1621 static void | |
1622 simplify_pred (pred_chain *one_chain) | |
1623 { | |
1624 size_t i, j, n; | |
1625 bool simplified = false; | |
1626 pred_chain s_chain = vNULL; | |
1627 | |
1628 n = one_chain->length (); | |
1629 | |
1630 for (i = 0; i < n; i++) | |
1631 { | |
1632 pred_info *a_pred = &(*one_chain)[i]; | |
1633 | |
1634 if (!a_pred->pred_lhs) | |
1635 continue; | |
1636 if (!is_neq_zero_form_p (*a_pred)) | |
1637 continue; | |
1638 | |
1639 gimple *def_stmt = SSA_NAME_DEF_STMT (a_pred->pred_lhs); | |
1640 if (gimple_code (def_stmt) != GIMPLE_ASSIGN) | |
1641 continue; | |
1642 if (gimple_assign_rhs_code (def_stmt) == BIT_IOR_EXPR) | |
1643 { | |
1644 for (j = 0; j < n; j++) | |
1645 { | |
1646 pred_info *b_pred = &(*one_chain)[j]; | |
1647 | |
1648 if (!b_pred->pred_lhs) | |
1649 continue; | |
1650 if (!is_neq_zero_form_p (*b_pred)) | |
1651 continue; | |
1652 | |
1653 if (pred_expr_equal_p (*b_pred, gimple_assign_rhs1 (def_stmt)) | |
1654 || pred_expr_equal_p (*b_pred, gimple_assign_rhs2 (def_stmt))) | |
1655 { | |
1656 /* Mark a_pred for removal. */ | |
1657 a_pred->pred_lhs = NULL; | |
1658 a_pred->pred_rhs = NULL; | |
1659 simplified = true; | |
1660 break; | |
1661 } | |
1662 } | |
1663 } | |
1664 } | |
1665 | |
1666 if (!simplified) | |
1667 return; | |
1668 | |
1669 for (i = 0; i < n; i++) | |
1670 { | |
1671 pred_info *a_pred = &(*one_chain)[i]; | |
1672 if (!a_pred->pred_lhs) | |
1673 continue; | |
1674 s_chain.safe_push (*a_pred); | |
1675 } | |
1676 | |
1677 one_chain->release (); | |
1678 *one_chain = s_chain; | |
1679 } | |
1680 | |
1681 /* The helper function implements the rule 2 for the | |
1682 OR predicate PREDS. | |
1683 | |
1684 2) (X AND Y) OR (!X AND Y) is equivalent to Y. */ | |
1685 | |
1686 static bool | |
1687 simplify_preds_2 (pred_chain_union *preds) | |
1688 { | |
1689 size_t i, j, n; | |
1690 bool simplified = false; | |
1691 pred_chain_union s_preds = vNULL; | |
1692 | |
1693 /* (X AND Y) OR (!X AND Y) is equivalent to Y. | |
1694 (X AND Y) OR (X AND !Y) is equivalent to X. */ | |
1695 | |
1696 n = preds->length (); | |
1697 for (i = 0; i < n; i++) | |
1698 { | |
1699 pred_info x, y; | |
1700 pred_chain *a_chain = &(*preds)[i]; | |
1701 | |
1702 if (a_chain->length () != 2) | |
1703 continue; | |
1704 | |
1705 x = (*a_chain)[0]; | |
1706 y = (*a_chain)[1]; | |
1707 | |
1708 for (j = 0; j < n; j++) | |
1709 { | |
1710 pred_chain *b_chain; | |
1711 pred_info x2, y2; | |
1712 | |
1713 if (j == i) | |
1714 continue; | |
1715 | |
1716 b_chain = &(*preds)[j]; | |
1717 if (b_chain->length () != 2) | |
1718 continue; | |
1719 | |
1720 x2 = (*b_chain)[0]; | |
1721 y2 = (*b_chain)[1]; | |
1722 | |
1723 if (pred_equal_p (x, x2) && pred_neg_p (y, y2)) | |
1724 { | |
1725 /* Kill a_chain. */ | |
1726 a_chain->release (); | |
1727 b_chain->release (); | |
1728 b_chain->safe_push (x); | |
1729 simplified = true; | |
1730 break; | |
1731 } | |
1732 if (pred_neg_p (x, x2) && pred_equal_p (y, y2)) | |
1733 { | |
1734 /* Kill a_chain. */ | |
1735 a_chain->release (); | |
1736 b_chain->release (); | |
1737 b_chain->safe_push (y); | |
1738 simplified = true; | |
1739 break; | |
1740 } | |
1741 } | |
1742 } | |
1743 /* Now clean up the chain. */ | |
1744 if (simplified) | |
1745 { | |
1746 for (i = 0; i < n; i++) | |
1747 { | |
1748 if ((*preds)[i].is_empty ()) | |
1749 continue; | |
1750 s_preds.safe_push ((*preds)[i]); | |
1751 } | |
1752 preds->release (); | |
1753 (*preds) = s_preds; | |
1754 s_preds = vNULL; | |
1755 } | |
1756 | |
1757 return simplified; | |
1758 } | |
1759 | |
1760 /* The helper function implements the rule 2 for the | |
1761 OR predicate PREDS. | |
1762 | |
1763 3) x OR (!x AND y) is equivalent to x OR y. */ | |
1764 | |
1765 static bool | |
1766 simplify_preds_3 (pred_chain_union *preds) | |
1767 { | |
1768 size_t i, j, n; | |
1769 bool simplified = false; | |
1770 | |
1771 /* Now iteratively simplify X OR (!X AND Z ..) | |
1772 into X OR (Z ...). */ | |
1773 | |
1774 n = preds->length (); | |
1775 if (n < 2) | |
1776 return false; | |
1777 | |
1778 for (i = 0; i < n; i++) | |
1779 { | |
1780 pred_info x; | |
1781 pred_chain *a_chain = &(*preds)[i]; | |
1782 | |
1783 if (a_chain->length () != 1) | |
1784 continue; | |
1785 | |
1786 x = (*a_chain)[0]; | |
1787 | |
1788 for (j = 0; j < n; j++) | |
1789 { | |
1790 pred_chain *b_chain; | |
1791 pred_info x2; | |
1792 size_t k; | |
1793 | |
1794 if (j == i) | |
1795 continue; | |
1796 | |
1797 b_chain = &(*preds)[j]; | |
1798 if (b_chain->length () < 2) | |
1799 continue; | |
1800 | |
1801 for (k = 0; k < b_chain->length (); k++) | |
1802 { | |
1803 x2 = (*b_chain)[k]; | |
1804 if (pred_neg_p (x, x2)) | |
1805 { | |
1806 b_chain->unordered_remove (k); | |
1807 simplified = true; | |
1808 break; | |
1809 } | |
1810 } | |
1811 } | |
1812 } | |
1813 return simplified; | |
1814 } | |
1815 | |
1816 /* The helper function implements the rule 4 for the | |
1817 OR predicate PREDS. | |
1818 | |
1819 2) ((x AND y) != 0) OR (x != 0 AND y != 0) is equivalent to | |
1820 (x != 0 ANd y != 0). */ | |
1821 | |
1822 static bool | |
1823 simplify_preds_4 (pred_chain_union *preds) | |
1824 { | |
1825 size_t i, j, n; | |
1826 bool simplified = false; | |
1827 pred_chain_union s_preds = vNULL; | |
1828 gimple *def_stmt; | |
1829 | |
1830 n = preds->length (); | |
1831 for (i = 0; i < n; i++) | |
1832 { | |
1833 pred_info z; | |
1834 pred_chain *a_chain = &(*preds)[i]; | |
1835 | |
1836 if (a_chain->length () != 1) | |
1837 continue; | |
1838 | |
1839 z = (*a_chain)[0]; | |
1840 | |
1841 if (!is_neq_zero_form_p (z)) | |
1842 continue; | |
1843 | |
1844 def_stmt = SSA_NAME_DEF_STMT (z.pred_lhs); | |
1845 if (gimple_code (def_stmt) != GIMPLE_ASSIGN) | |
1846 continue; | |
1847 | |
1848 if (gimple_assign_rhs_code (def_stmt) != BIT_AND_EXPR) | |
1849 continue; | |
1850 | |
1851 for (j = 0; j < n; j++) | |
1852 { | |
1853 pred_chain *b_chain; | |
1854 pred_info x2, y2; | |
1855 | |
1856 if (j == i) | |
1857 continue; | |
1858 | |
1859 b_chain = &(*preds)[j]; | |
1860 if (b_chain->length () != 2) | |
1861 continue; | |
1862 | |
1863 x2 = (*b_chain)[0]; | |
1864 y2 = (*b_chain)[1]; | |
1865 if (!is_neq_zero_form_p (x2) || !is_neq_zero_form_p (y2)) | |
1866 continue; | |
1867 | |
1868 if ((pred_expr_equal_p (x2, gimple_assign_rhs1 (def_stmt)) | |
1869 && pred_expr_equal_p (y2, gimple_assign_rhs2 (def_stmt))) | |
1870 || (pred_expr_equal_p (x2, gimple_assign_rhs2 (def_stmt)) | |
1871 && pred_expr_equal_p (y2, gimple_assign_rhs1 (def_stmt)))) | |
1872 { | |
1873 /* Kill a_chain. */ | |
1874 a_chain->release (); | |
1875 simplified = true; | |
1876 break; | |
1877 } | |
1878 } | |
1879 } | |
1880 /* Now clean up the chain. */ | |
1881 if (simplified) | |
1882 { | |
1883 for (i = 0; i < n; i++) | |
1884 { | |
1885 if ((*preds)[i].is_empty ()) | |
1886 continue; | |
1887 s_preds.safe_push ((*preds)[i]); | |
1888 } | |
1889 | |
1890 preds->release (); | |
1891 (*preds) = s_preds; | |
1892 s_preds = vNULL; | |
1893 } | |
1894 | |
1895 return simplified; | |
1896 } | |
1897 | |
1898 /* This function simplifies predicates in PREDS. */ | |
1899 | |
1900 static void | |
1901 simplify_preds (pred_chain_union *preds, gimple *use_or_def, bool is_use) | |
1902 { | |
1903 size_t i, n; | |
1904 bool changed = false; | |
1905 | |
1906 if (dump_file && dump_flags & TDF_DETAILS) | |
1907 { | |
1908 fprintf (dump_file, "[BEFORE SIMPLICATION -- "); | |
1909 dump_predicates (use_or_def, *preds, is_use ? "[USE]:\n" : "[DEF]:\n"); | |
1910 } | |
1911 | |
1912 for (i = 0; i < preds->length (); i++) | |
1913 simplify_pred (&(*preds)[i]); | |
1914 | |
1915 n = preds->length (); | |
1916 if (n < 2) | |
1917 return; | |
1918 | |
1919 do | |
1920 { | |
1921 changed = false; | |
1922 if (simplify_preds_2 (preds)) | |
1923 changed = true; | |
1924 | |
1925 /* Now iteratively simplify X OR (!X AND Z ..) | |
1926 into X OR (Z ...). */ | |
1927 if (simplify_preds_3 (preds)) | |
1928 changed = true; | |
1929 | |
1930 if (simplify_preds_4 (preds)) | |
1931 changed = true; | |
1932 } | |
1933 while (changed); | |
1934 | |
1935 return; | |
1936 } | |
1937 | |
1938 /* This is a helper function which attempts to normalize predicate chains | |
1939 by following UD chains. It basically builds up a big tree of either IOR | |
1940 operations or AND operations, and convert the IOR tree into a | |
1941 pred_chain_union or BIT_AND tree into a pred_chain. | |
1942 Example: | |
1943 | |
1944 _3 = _2 RELOP1 _1; | |
1945 _6 = _5 RELOP2 _4; | |
1946 _9 = _8 RELOP3 _7; | |
1947 _10 = _3 | _6; | |
1948 _12 = _9 | _0; | |
1949 _t = _10 | _12; | |
1950 | |
1951 then _t != 0 will be normalized into a pred_chain_union | |
1952 | |
1953 (_2 RELOP1 _1) OR (_5 RELOP2 _4) OR (_8 RELOP3 _7) OR (_0 != 0) | |
1954 | |
1955 Similarly given, | |
1956 | |
1957 _3 = _2 RELOP1 _1; | |
1958 _6 = _5 RELOP2 _4; | |
1959 _9 = _8 RELOP3 _7; | |
1960 _10 = _3 & _6; | |
1961 _12 = _9 & _0; | |
1962 | |
1963 then _t != 0 will be normalized into a pred_chain: | |
1964 (_2 RELOP1 _1) AND (_5 RELOP2 _4) AND (_8 RELOP3 _7) AND (_0 != 0) | |
1965 | |
1966 */ | |
1967 | |
1968 /* This is a helper function that stores a PRED into NORM_PREDS. */ | |
1969 | |
1970 inline static void | |
1971 push_pred (pred_chain_union *norm_preds, pred_info pred) | |
1972 { | |
1973 pred_chain pred_chain = vNULL; | |
1974 pred_chain.safe_push (pred); | |
1975 norm_preds->safe_push (pred_chain); | |
1976 } | |
1977 | |
1978 /* A helper function that creates a predicate of the form | |
1979 OP != 0 and push it WORK_LIST. */ | |
1980 | |
1981 inline static void | |
1982 push_to_worklist (tree op, vec<pred_info, va_heap, vl_ptr> *work_list, | |
1983 hash_set<tree> *mark_set) | |
1984 { | |
1985 if (mark_set->contains (op)) | |
1986 return; | |
1987 mark_set->add (op); | |
1988 | |
1989 pred_info arg_pred; | |
1990 arg_pred.pred_lhs = op; | |
1991 arg_pred.pred_rhs = integer_zero_node; | |
1992 arg_pred.cond_code = NE_EXPR; | |
1993 arg_pred.invert = false; | |
1994 work_list->safe_push (arg_pred); | |
1995 } | |
1996 | |
1997 /* A helper that generates a pred_info from a gimple assignment | |
1998 CMP_ASSIGN with comparison rhs. */ | |
1999 | |
2000 static pred_info | |
2001 get_pred_info_from_cmp (gimple *cmp_assign) | |
2002 { | |
2003 pred_info n_pred; | |
2004 n_pred.pred_lhs = gimple_assign_rhs1 (cmp_assign); | |
2005 n_pred.pred_rhs = gimple_assign_rhs2 (cmp_assign); | |
2006 n_pred.cond_code = gimple_assign_rhs_code (cmp_assign); | |
2007 n_pred.invert = false; | |
2008 return n_pred; | |
2009 } | |
2010 | |
2011 /* Returns true if the PHI is a degenerated phi with | |
2012 all args with the same value (relop). In that case, *PRED | |
2013 will be updated to that value. */ | |
2014 | |
2015 static bool | |
2016 is_degenerated_phi (gimple *phi, pred_info *pred_p) | |
2017 { | |
2018 int i, n; | |
2019 tree op0; | |
2020 gimple *def0; | |
2021 pred_info pred0; | |
2022 | |
2023 n = gimple_phi_num_args (phi); | |
2024 op0 = gimple_phi_arg_def (phi, 0); | |
2025 | |
2026 if (TREE_CODE (op0) != SSA_NAME) | |
2027 return false; | |
2028 | |
2029 def0 = SSA_NAME_DEF_STMT (op0); | |
2030 if (gimple_code (def0) != GIMPLE_ASSIGN) | |
2031 return false; | |
2032 if (TREE_CODE_CLASS (gimple_assign_rhs_code (def0)) != tcc_comparison) | |
2033 return false; | |
2034 pred0 = get_pred_info_from_cmp (def0); | |
2035 | |
2036 for (i = 1; i < n; ++i) | |
2037 { | |
2038 gimple *def; | |
2039 pred_info pred; | |
2040 tree op = gimple_phi_arg_def (phi, i); | |
2041 | |
2042 if (TREE_CODE (op) != SSA_NAME) | |
2043 return false; | |
2044 | |
2045 def = SSA_NAME_DEF_STMT (op); | |
2046 if (gimple_code (def) != GIMPLE_ASSIGN) | |
2047 return false; | |
2048 if (TREE_CODE_CLASS (gimple_assign_rhs_code (def)) != tcc_comparison) | |
2049 return false; | |
2050 pred = get_pred_info_from_cmp (def); | |
2051 if (!pred_equal_p (pred, pred0)) | |
2052 return false; | |
2053 } | |
2054 | |
2055 *pred_p = pred0; | |
2056 return true; | |
2057 } | |
2058 | |
2059 /* Normalize one predicate PRED | |
2060 1) if PRED can no longer be normlized, put it into NORM_PREDS. | |
2061 2) otherwise if PRED is of the form x != 0, follow x's definition | |
2062 and put normalized predicates into WORK_LIST. */ | |
2063 | |
2064 static void | |
2065 normalize_one_pred_1 (pred_chain_union *norm_preds, | |
2066 pred_chain *norm_chain, | |
2067 pred_info pred, | |
2068 enum tree_code and_or_code, | |
2069 vec<pred_info, va_heap, vl_ptr> *work_list, | |
2070 hash_set<tree> *mark_set) | |
2071 { | |
2072 if (!is_neq_zero_form_p (pred)) | |
2073 { | |
2074 if (and_or_code == BIT_IOR_EXPR) | |
2075 push_pred (norm_preds, pred); | |
2076 else | |
2077 norm_chain->safe_push (pred); | |
2078 return; | |
2079 } | |
2080 | |
2081 gimple *def_stmt = SSA_NAME_DEF_STMT (pred.pred_lhs); | |
2082 | |
2083 if (gimple_code (def_stmt) == GIMPLE_PHI | |
2084 && is_degenerated_phi (def_stmt, &pred)) | |
2085 work_list->safe_push (pred); | |
2086 else if (gimple_code (def_stmt) == GIMPLE_PHI && and_or_code == BIT_IOR_EXPR) | |
2087 { | |
2088 int i, n; | |
2089 n = gimple_phi_num_args (def_stmt); | |
2090 | |
2091 /* If we see non zero constant, we should punt. The predicate | |
2092 * should be one guarding the phi edge. */ | |
2093 for (i = 0; i < n; ++i) | |
2094 { | |
2095 tree op = gimple_phi_arg_def (def_stmt, i); | |
2096 if (TREE_CODE (op) == INTEGER_CST && !integer_zerop (op)) | |
2097 { | |
2098 push_pred (norm_preds, pred); | |
2099 return; | |
2100 } | |
2101 } | |
2102 | |
2103 for (i = 0; i < n; ++i) | |
2104 { | |
2105 tree op = gimple_phi_arg_def (def_stmt, i); | |
2106 if (integer_zerop (op)) | |
2107 continue; | |
2108 | |
2109 push_to_worklist (op, work_list, mark_set); | |
2110 } | |
2111 } | |
2112 else if (gimple_code (def_stmt) != GIMPLE_ASSIGN) | |
2113 { | |
2114 if (and_or_code == BIT_IOR_EXPR) | |
2115 push_pred (norm_preds, pred); | |
2116 else | |
2117 norm_chain->safe_push (pred); | |
2118 } | |
2119 else if (gimple_assign_rhs_code (def_stmt) == and_or_code) | |
2120 { | |
2121 /* Avoid splitting up bit manipulations like x & 3 or y | 1. */ | |
2122 if (is_gimple_min_invariant (gimple_assign_rhs2 (def_stmt))) | |
2123 { | |
2124 /* But treat x & 3 as condition. */ | |
2125 if (and_or_code == BIT_AND_EXPR) | |
2126 { | |
2127 pred_info n_pred; | |
2128 n_pred.pred_lhs = gimple_assign_rhs1 (def_stmt); | |
2129 n_pred.pred_rhs = gimple_assign_rhs2 (def_stmt); | |
2130 n_pred.cond_code = and_or_code; | |
2131 n_pred.invert = false; | |
2132 norm_chain->safe_push (n_pred); | |
2133 } | |
2134 } | |
2135 else | |
2136 { | |
2137 push_to_worklist (gimple_assign_rhs1 (def_stmt), work_list, mark_set); | |
2138 push_to_worklist (gimple_assign_rhs2 (def_stmt), work_list, mark_set); | |
2139 } | |
2140 } | |
2141 else if (TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) | |
2142 == tcc_comparison) | |
2143 { | |
2144 pred_info n_pred = get_pred_info_from_cmp (def_stmt); | |
2145 if (and_or_code == BIT_IOR_EXPR) | |
2146 push_pred (norm_preds, n_pred); | |
2147 else | |
2148 norm_chain->safe_push (n_pred); | |
2149 } | |
2150 else | |
2151 { | |
2152 if (and_or_code == BIT_IOR_EXPR) | |
2153 push_pred (norm_preds, pred); | |
2154 else | |
2155 norm_chain->safe_push (pred); | |
2156 } | |
2157 } | |
2158 | |
2159 /* Normalize PRED and store the normalized predicates into NORM_PREDS. */ | |
2160 | |
2161 static void | |
2162 normalize_one_pred (pred_chain_union *norm_preds, pred_info pred) | |
2163 { | |
2164 vec<pred_info, va_heap, vl_ptr> work_list = vNULL; | |
2165 enum tree_code and_or_code = ERROR_MARK; | |
2166 pred_chain norm_chain = vNULL; | |
2167 | |
2168 if (!is_neq_zero_form_p (pred)) | |
2169 { | |
2170 push_pred (norm_preds, pred); | |
2171 return; | |
2172 } | |
2173 | |
2174 gimple *def_stmt = SSA_NAME_DEF_STMT (pred.pred_lhs); | |
2175 if (gimple_code (def_stmt) == GIMPLE_ASSIGN) | |
2176 and_or_code = gimple_assign_rhs_code (def_stmt); | |
2177 if (and_or_code != BIT_IOR_EXPR && and_or_code != BIT_AND_EXPR) | |
2178 { | |
2179 if (TREE_CODE_CLASS (and_or_code) == tcc_comparison) | |
2180 { | |
2181 pred_info n_pred = get_pred_info_from_cmp (def_stmt); | |
2182 push_pred (norm_preds, n_pred); | |
2183 } | |
2184 else | |
2185 push_pred (norm_preds, pred); | |
2186 return; | |
2187 } | |
2188 | |
2189 work_list.safe_push (pred); | |
2190 hash_set<tree> mark_set; | |
2191 | |
2192 while (!work_list.is_empty ()) | |
2193 { | |
2194 pred_info a_pred = work_list.pop (); | |
2195 normalize_one_pred_1 (norm_preds, &norm_chain, a_pred, and_or_code, | |
2196 &work_list, &mark_set); | |
2197 } | |
2198 if (and_or_code == BIT_AND_EXPR) | |
2199 norm_preds->safe_push (norm_chain); | |
2200 | |
2201 work_list.release (); | |
2202 } | |
2203 | |
2204 static void | |
2205 normalize_one_pred_chain (pred_chain_union *norm_preds, pred_chain one_chain) | |
2206 { | |
2207 vec<pred_info, va_heap, vl_ptr> work_list = vNULL; | |
2208 hash_set<tree> mark_set; | |
2209 pred_chain norm_chain = vNULL; | |
2210 size_t i; | |
2211 | |
2212 for (i = 0; i < one_chain.length (); i++) | |
2213 { | |
2214 work_list.safe_push (one_chain[i]); | |
2215 mark_set.add (one_chain[i].pred_lhs); | |
2216 } | |
2217 | |
2218 while (!work_list.is_empty ()) | |
2219 { | |
2220 pred_info a_pred = work_list.pop (); | |
2221 normalize_one_pred_1 (0, &norm_chain, a_pred, BIT_AND_EXPR, &work_list, | |
2222 &mark_set); | |
2223 } | |
2224 | |
2225 norm_preds->safe_push (norm_chain); | |
2226 work_list.release (); | |
2227 } | |
2228 | |
2229 /* Normalize predicate chains PREDS and returns the normalized one. */ | |
2230 | |
2231 static pred_chain_union | |
2232 normalize_preds (pred_chain_union preds, gimple *use_or_def, bool is_use) | |
2233 { | |
2234 pred_chain_union norm_preds = vNULL; | |
2235 size_t n = preds.length (); | |
2236 size_t i; | |
2237 | |
2238 if (dump_file && dump_flags & TDF_DETAILS) | |
2239 { | |
2240 fprintf (dump_file, "[BEFORE NORMALIZATION --"); | |
2241 dump_predicates (use_or_def, preds, is_use ? "[USE]:\n" : "[DEF]:\n"); | |
2242 } | |
2243 | |
2244 for (i = 0; i < n; i++) | |
2245 { | |
2246 if (preds[i].length () != 1) | |
2247 normalize_one_pred_chain (&norm_preds, preds[i]); | |
2248 else | |
2249 { | |
2250 normalize_one_pred (&norm_preds, preds[i][0]); | |
2251 preds[i].release (); | |
2252 } | |
2253 } | |
2254 | |
2255 if (dump_file) | |
2256 { | |
2257 fprintf (dump_file, "[AFTER NORMALIZATION -- "); | |
2258 dump_predicates (use_or_def, norm_preds, | |
2259 is_use ? "[USE]:\n" : "[DEF]:\n"); | |
2260 } | |
2261 | |
2262 destroy_predicate_vecs (&preds); | |
2263 return norm_preds; | |
2264 } | |
2265 | |
2266 /* Return TRUE if PREDICATE can be invalidated by any individual | |
131 | 2267 predicate in USE_GUARD. */ |
111 | 2268 |
2269 static bool | |
2270 can_one_predicate_be_invalidated_p (pred_info predicate, | |
2271 pred_chain use_guard) | |
2272 { | |
131 | 2273 if (dump_file && dump_flags & TDF_DETAILS) |
2274 { | |
2275 fprintf (dump_file, "Testing if this predicate: "); | |
2276 dump_pred_info (predicate); | |
2277 fprintf (dump_file, "\n...can be invalidated by a USE guard of: "); | |
2278 dump_pred_chain (use_guard); | |
2279 } | |
111 | 2280 for (size_t i = 0; i < use_guard.length (); ++i) |
2281 { | |
2282 /* NOTE: This is a very simple check, and only understands an | |
2283 exact opposite. So, [i == 0] is currently only invalidated | |
2284 by [.NOT. i == 0] or [i != 0]. Ideally we should also | |
2285 invalidate with say [i > 5] or [i == 8]. There is certainly | |
2286 room for improvement here. */ | |
2287 if (pred_neg_p (predicate, use_guard[i])) | |
131 | 2288 { |
2289 if (dump_file && dump_flags & TDF_DETAILS) | |
2290 { | |
2291 fprintf (dump_file, " Predicate was invalidated by: "); | |
2292 dump_pred_info (use_guard[i]); | |
2293 fputc ('\n', dump_file); | |
2294 } | |
2295 return true; | |
2296 } | |
111 | 2297 } |
2298 return false; | |
2299 } | |
2300 | |
2301 /* Return TRUE if all predicates in UNINIT_PRED are invalidated by | |
2302 USE_GUARD being true. */ | |
2303 | |
2304 static bool | |
2305 can_chain_union_be_invalidated_p (pred_chain_union uninit_pred, | |
2306 pred_chain use_guard) | |
2307 { | |
2308 if (uninit_pred.is_empty ()) | |
2309 return false; | |
131 | 2310 if (dump_file && dump_flags & TDF_DETAILS) |
2311 dump_predicates (NULL, uninit_pred, | |
2312 "Testing if anything here can be invalidated: "); | |
111 | 2313 for (size_t i = 0; i < uninit_pred.length (); ++i) |
2314 { | |
2315 pred_chain c = uninit_pred[i]; | |
131 | 2316 size_t j; |
2317 for (j = 0; j < c.length (); ++j) | |
2318 if (can_one_predicate_be_invalidated_p (c[j], use_guard)) | |
2319 break; | |
2320 | |
2321 /* If we were unable to invalidate any predicate in C, then there | |
2322 is a viable path from entry to the PHI where the PHI takes | |
2323 an uninitialized value and continues to a use of the PHI. */ | |
2324 if (j == c.length ()) | |
2325 return false; | |
111 | 2326 } |
2327 return true; | |
2328 } | |
2329 | |
2330 /* Return TRUE if none of the uninitialized operands in UNINT_OPNDS | |
2331 can actually happen if we arrived at a use for PHI. | |
2332 | |
2333 PHI_USE_GUARDS are the guard conditions for the use of the PHI. */ | |
2334 | |
2335 static bool | |
2336 uninit_uses_cannot_happen (gphi *phi, unsigned uninit_opnds, | |
2337 pred_chain_union phi_use_guards) | |
2338 { | |
2339 unsigned phi_args = gimple_phi_num_args (phi); | |
2340 if (phi_args > max_phi_args) | |
2341 return false; | |
2342 | |
2343 /* PHI_USE_GUARDS are OR'ed together. If we have more than one | |
2344 possible guard, there's no way of knowing which guard was true. | |
2345 Since we need to be absolutely sure that the uninitialized | |
2346 operands will be invalidated, bail. */ | |
2347 if (phi_use_guards.length () != 1) | |
2348 return false; | |
2349 | |
2350 /* Look for the control dependencies of all the uninitialized | |
2351 operands and build guard predicates describing them. */ | |
2352 pred_chain_union uninit_preds; | |
2353 bool ret = true; | |
2354 for (unsigned i = 0; i < phi_args; ++i) | |
2355 { | |
2356 if (!MASK_TEST_BIT (uninit_opnds, i)) | |
2357 continue; | |
2358 | |
2359 edge e = gimple_phi_arg_edge (phi, i); | |
2360 vec<edge> dep_chains[MAX_NUM_CHAINS]; | |
2361 auto_vec<edge, MAX_CHAIN_LEN + 1> cur_chain; | |
2362 size_t num_chains = 0; | |
2363 int num_calls = 0; | |
2364 | |
2365 /* Build the control dependency chain for uninit operand `i'... */ | |
2366 uninit_preds = vNULL; | |
131 | 2367 if (!compute_control_dep_chain (ENTRY_BLOCK_PTR_FOR_FN (cfun), |
111 | 2368 e->src, dep_chains, &num_chains, |
2369 &cur_chain, &num_calls)) | |
2370 { | |
2371 ret = false; | |
2372 break; | |
2373 } | |
2374 /* ...and convert it into a set of predicates. */ | |
131 | 2375 bool has_valid_preds |
2376 = convert_control_dep_chain_into_preds (dep_chains, num_chains, | |
2377 &uninit_preds); | |
111 | 2378 for (size_t j = 0; j < num_chains; ++j) |
2379 dep_chains[j].release (); | |
131 | 2380 if (!has_valid_preds) |
2381 { | |
2382 ret = false; | |
2383 break; | |
2384 } | |
111 | 2385 simplify_preds (&uninit_preds, NULL, false); |
2386 uninit_preds = normalize_preds (uninit_preds, NULL, false); | |
2387 | |
2388 /* Can the guard for this uninitialized operand be invalidated | |
2389 by the PHI use? */ | |
2390 if (!can_chain_union_be_invalidated_p (uninit_preds, phi_use_guards[0])) | |
2391 { | |
2392 ret = false; | |
2393 break; | |
2394 } | |
2395 } | |
2396 destroy_predicate_vecs (&uninit_preds); | |
2397 return ret; | |
2398 } | |
2399 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2400 /* Computes the predicates that guard the use and checks |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2401 if the incoming paths that have empty (or possibly |
111 | 2402 empty) definition can be pruned/filtered. The function returns |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2403 true if it can be determined that the use of PHI's def in |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2404 USE_STMT is guarded with a predicate set not overlapping with |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2405 predicate sets of all runtime paths that do not have a definition. |
111 | 2406 |
2407 Returns false if it is not or it can not be determined. USE_BB is | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2408 the bb of the use (for phi operand use, the bb is not the bb of |
111 | 2409 the phi stmt, but the src bb of the operand edge). |
2410 | |
2411 UNINIT_OPNDS is a bit vector. If an operand of PHI is uninitialized, the | |
2412 corresponding bit in the vector is 1. VISITED_PHIS is a pointer | |
2413 set of phis being visited. | |
2414 | |
2415 *DEF_PREDS contains the (memoized) defining predicate chains of PHI. | |
2416 If *DEF_PREDS is the empty vector, the defining predicate chains of | |
2417 PHI will be computed and stored into *DEF_PREDS as needed. | |
2418 | |
2419 VISITED_PHIS is a pointer set of phis being visited. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2420 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2421 static bool |
111 | 2422 is_use_properly_guarded (gimple *use_stmt, |
2423 basic_block use_bb, | |
2424 gphi *phi, | |
2425 unsigned uninit_opnds, | |
2426 pred_chain_union *def_preds, | |
2427 hash_set<gphi *> *visited_phis) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2428 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2429 basic_block phi_bb; |
111 | 2430 pred_chain_union preds = vNULL; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2431 bool has_valid_preds = false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2432 bool is_properly_guarded = false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2433 |
111 | 2434 if (visited_phis->add (phi)) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2435 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2436 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2437 phi_bb = gimple_bb (phi); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2438 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2439 if (is_non_loop_exit_postdominating (use_bb, phi_bb)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2440 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2441 |
111 | 2442 has_valid_preds = find_predicates (&preds, phi_bb, use_bb); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2443 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2444 if (!has_valid_preds) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2445 { |
111 | 2446 destroy_predicate_vecs (&preds); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2447 return false; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2448 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2449 |
111 | 2450 /* Try to prune the dead incoming phi edges. */ |
2451 is_properly_guarded | |
2452 = use_pred_not_overlap_with_undef_path_pred (preds, phi, uninit_opnds, | |
2453 visited_phis); | |
2454 | |
2455 /* We might be able to prove that if the control dependencies | |
2456 for UNINIT_OPNDS are true, that the control dependencies for | |
2457 USE_STMT can never be true. */ | |
2458 if (!is_properly_guarded) | |
2459 is_properly_guarded |= uninit_uses_cannot_happen (phi, uninit_opnds, | |
2460 preds); | |
2461 | |
2462 if (is_properly_guarded) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2463 { |
111 | 2464 destroy_predicate_vecs (&preds); |
2465 return true; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2466 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2467 |
111 | 2468 if (def_preds->is_empty ()) |
2469 { | |
2470 has_valid_preds = find_def_preds (def_preds, phi); | |
2471 | |
2472 if (!has_valid_preds) | |
2473 { | |
2474 destroy_predicate_vecs (&preds); | |
2475 return false; | |
2476 } | |
2477 | |
2478 simplify_preds (def_preds, phi, false); | |
2479 *def_preds = normalize_preds (*def_preds, phi, false); | |
2480 } | |
2481 | |
2482 simplify_preds (&preds, use_stmt, true); | |
2483 preds = normalize_preds (preds, use_stmt, true); | |
2484 | |
2485 is_properly_guarded = is_superset_of (*def_preds, preds); | |
2486 | |
2487 destroy_predicate_vecs (&preds); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2488 return is_properly_guarded; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2489 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2490 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2491 /* Searches through all uses of a potentially |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2492 uninitialized variable defined by PHI and returns a use |
111 | 2493 statement if the use is not properly guarded. It returns |
2494 NULL if all uses are guarded. UNINIT_OPNDS is a bitvector | |
2495 holding the position(s) of uninit PHI operands. WORKLIST | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2496 is the vector of candidate phis that may be updated by this |
111 | 2497 function. ADDED_TO_WORKLIST is the pointer set tracking |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2498 if the new phi is already in the worklist. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2499 |
111 | 2500 static gimple * |
2501 find_uninit_use (gphi *phi, unsigned uninit_opnds, | |
2502 vec<gphi *> *worklist, | |
2503 hash_set<gphi *> *added_to_worklist) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2504 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2505 tree phi_result; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2506 use_operand_p use_p; |
111 | 2507 gimple *use_stmt; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2508 imm_use_iterator iter; |
111 | 2509 pred_chain_union def_preds = vNULL; |
2510 gimple *ret = NULL; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2511 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2512 phi_result = gimple_phi_result (phi); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2513 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2514 FOR_EACH_IMM_USE_FAST (use_p, iter, phi_result) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2515 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2516 basic_block use_bb; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2517 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2518 use_stmt = USE_STMT (use_p); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2519 if (is_gimple_debug (use_stmt)) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2520 continue; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2521 |
111 | 2522 if (gphi *use_phi = dyn_cast<gphi *> (use_stmt)) |
2523 use_bb = gimple_phi_arg_edge (use_phi, | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2524 PHI_ARG_INDEX_FROM_USE (use_p))->src; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2525 else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2526 use_bb = gimple_bb (use_stmt); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2527 |
111 | 2528 hash_set<gphi *> visited_phis; |
2529 if (is_use_properly_guarded (use_stmt, use_bb, phi, uninit_opnds, | |
2530 &def_preds, &visited_phis)) | |
2531 continue; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2532 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2533 if (dump_file && (dump_flags & TDF_DETAILS)) |
111 | 2534 { |
2535 fprintf (dump_file, "[CHECK]: Found unguarded use: "); | |
2536 print_gimple_stmt (dump_file, use_stmt, 0); | |
2537 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2538 /* Found one real use, return. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2539 if (gimple_code (use_stmt) != GIMPLE_PHI) |
111 | 2540 { |
2541 ret = use_stmt; | |
2542 break; | |
2543 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2544 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2545 /* Found a phi use that is not guarded, |
111 | 2546 add the phi to the worklist. */ |
2547 if (!added_to_worklist->add (as_a<gphi *> (use_stmt))) | |
2548 { | |
2549 if (dump_file && (dump_flags & TDF_DETAILS)) | |
2550 { | |
2551 fprintf (dump_file, "[WORKLIST]: Update worklist with phi: "); | |
2552 print_gimple_stmt (dump_file, use_stmt, 0); | |
2553 } | |
2554 | |
2555 worklist->safe_push (as_a<gphi *> (use_stmt)); | |
2556 possibly_undefined_names->add (phi_result); | |
2557 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2558 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2559 |
111 | 2560 destroy_predicate_vecs (&def_preds); |
2561 return ret; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2562 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2563 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2564 /* Look for inputs to PHI that are SSA_NAMEs that have empty definitions |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2565 and gives warning if there exists a runtime path from the entry to a |
111 | 2566 use of the PHI def that does not contain a definition. In other words, |
2567 the warning is on the real use. The more dead paths that can be pruned | |
2568 by the compiler, the fewer false positives the warning is. WORKLIST | |
2569 is a vector of candidate phis to be examined. ADDED_TO_WORKLIST is | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2570 a pointer set tracking if the new phi is added to the worklist or not. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2571 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2572 static void |
111 | 2573 warn_uninitialized_phi (gphi *phi, vec<gphi *> *worklist, |
2574 hash_set<gphi *> *added_to_worklist) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2575 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2576 unsigned uninit_opnds; |
111 | 2577 gimple *uninit_use_stmt = 0; |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2578 tree uninit_op; |
111 | 2579 int phiarg_index; |
2580 location_t loc; | |
2581 | |
2582 /* Don't look at virtual operands. */ | |
2583 if (virtual_operand_p (gimple_phi_result (phi))) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2584 return; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2585 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2586 uninit_opnds = compute_uninit_opnds_pos (phi); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2587 |
111 | 2588 if (MASK_EMPTY (uninit_opnds)) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2589 return; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2590 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2591 if (dump_file && (dump_flags & TDF_DETAILS)) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2592 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2593 fprintf (dump_file, "[CHECK]: examining phi: "); |
111 | 2594 print_gimple_stmt (dump_file, phi, 0); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2595 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2596 |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2597 /* Now check if we have any use of the value without proper guard. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2598 uninit_use_stmt = find_uninit_use (phi, uninit_opnds, |
111 | 2599 worklist, added_to_worklist); |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2600 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2601 /* All uses are properly guarded. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2602 if (!uninit_use_stmt) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2603 return; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2604 |
111 | 2605 phiarg_index = MASK_FIRST_SET_BIT (uninit_opnds); |
2606 uninit_op = gimple_phi_arg_def (phi, phiarg_index); | |
2607 if (SSA_NAME_VAR (uninit_op) == NULL_TREE) | |
2608 return; | |
2609 if (gimple_phi_arg_has_location (phi, phiarg_index)) | |
2610 loc = gimple_phi_arg_location (phi, phiarg_index); | |
2611 else | |
2612 loc = UNKNOWN_LOCATION; | |
2613 warn_uninit (OPT_Wmaybe_uninitialized, uninit_op, SSA_NAME_VAR (uninit_op), | |
2614 SSA_NAME_VAR (uninit_op), | |
2615 "%qD may be used uninitialized in this function", | |
2616 uninit_use_stmt, loc); | |
2617 } | |
2618 | |
2619 static bool | |
2620 gate_warn_uninitialized (void) | |
2621 { | |
2622 return warn_uninitialized || warn_maybe_uninitialized; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2623 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2624 |
111 | 2625 namespace { |
2626 | |
2627 const pass_data pass_data_late_warn_uninitialized = | |
2628 { | |
2629 GIMPLE_PASS, /* type */ | |
2630 "uninit", /* name */ | |
2631 OPTGROUP_NONE, /* optinfo_flags */ | |
2632 TV_NONE, /* tv_id */ | |
2633 PROP_ssa, /* properties_required */ | |
2634 0, /* properties_provided */ | |
2635 0, /* properties_destroyed */ | |
2636 0, /* todo_flags_start */ | |
2637 0, /* todo_flags_finish */ | |
2638 }; | |
2639 | |
2640 class pass_late_warn_uninitialized : public gimple_opt_pass | |
2641 { | |
2642 public: | |
2643 pass_late_warn_uninitialized (gcc::context *ctxt) | |
2644 : gimple_opt_pass (pass_data_late_warn_uninitialized, ctxt) | |
2645 {} | |
2646 | |
2647 /* opt_pass methods: */ | |
2648 opt_pass *clone () { return new pass_late_warn_uninitialized (m_ctxt); } | |
2649 virtual bool gate (function *) { return gate_warn_uninitialized (); } | |
2650 virtual unsigned int execute (function *); | |
2651 | |
2652 }; // class pass_late_warn_uninitialized | |
2653 | |
2654 unsigned int | |
2655 pass_late_warn_uninitialized::execute (function *fun) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2656 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2657 basic_block bb; |
111 | 2658 gphi_iterator gsi; |
2659 vec<gphi *> worklist = vNULL; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2660 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2661 calculate_dominance_info (CDI_DOMINATORS); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2662 calculate_dominance_info (CDI_POST_DOMINATORS); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2663 /* Re-do the plain uninitialized variable check, as optimization may have |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2664 straightened control flow. Do this first so that we don't accidentally |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2665 get a "may be" warning when we'd have seen an "is" warning later. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2666 warn_uninitialized_vars (/*warn_possibly_uninitialized=*/1); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2667 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2668 timevar_push (TV_TREE_UNINIT); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2669 |
111 | 2670 possibly_undefined_names = new hash_set<tree>; |
2671 hash_set<gphi *> added_to_worklist; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2672 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2673 /* Initialize worklist */ |
111 | 2674 FOR_EACH_BB_FN (bb, fun) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2675 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2676 { |
111 | 2677 gphi *phi = gsi.phi (); |
2678 size_t n, i; | |
2679 | |
2680 n = gimple_phi_num_args (phi); | |
2681 | |
2682 /* Don't look at virtual operands. */ | |
2683 if (virtual_operand_p (gimple_phi_result (phi))) | |
2684 continue; | |
2685 | |
2686 for (i = 0; i < n; ++i) | |
2687 { | |
2688 tree op = gimple_phi_arg_def (phi, i); | |
2689 if (TREE_CODE (op) == SSA_NAME && uninit_undefined_value_p (op)) | |
2690 { | |
2691 worklist.safe_push (phi); | |
2692 added_to_worklist.add (phi); | |
2693 if (dump_file && (dump_flags & TDF_DETAILS)) | |
2694 { | |
2695 fprintf (dump_file, "[WORKLIST]: add to initial list: "); | |
2696 print_gimple_stmt (dump_file, phi, 0); | |
2697 } | |
2698 break; | |
2699 } | |
2700 } | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2701 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2702 |
111 | 2703 while (worklist.length () != 0) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2704 { |
111 | 2705 gphi *cur_phi = 0; |
2706 cur_phi = worklist.pop (); | |
2707 warn_uninitialized_phi (cur_phi, &worklist, &added_to_worklist); | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2708 } |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2709 |
111 | 2710 worklist.release (); |
2711 delete possibly_undefined_names; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2712 possibly_undefined_names = NULL; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2713 free_dominance_info (CDI_POST_DOMINATORS); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2714 timevar_pop (TV_TREE_UNINIT); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2715 return 0; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2716 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2717 |
111 | 2718 } // anon namespace |
2719 | |
2720 gimple_opt_pass * | |
2721 make_pass_late_warn_uninitialized (gcc::context *ctxt) | |
2722 { | |
2723 return new pass_late_warn_uninitialized (ctxt); | |
2724 } | |
2725 | |
2726 static unsigned int | |
2727 execute_early_warn_uninitialized (void) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2728 { |
111 | 2729 /* Currently, this pass runs always but |
2730 execute_late_warn_uninitialized only runs with optimization. With | |
2731 optimization we want to warn about possible uninitialized as late | |
2732 as possible, thus don't do it here. However, without | |
2733 optimization we need to warn here about "may be uninitialized". */ | |
2734 calculate_dominance_info (CDI_POST_DOMINATORS); | |
2735 | |
2736 warn_uninitialized_vars (/*warn_possibly_uninitialized=*/!optimize); | |
2737 | |
2738 /* Post-dominator information can not be reliably updated. Free it | |
2739 after the use. */ | |
2740 | |
2741 free_dominance_info (CDI_POST_DOMINATORS); | |
2742 return 0; | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2743 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2744 |
111 | 2745 namespace { |
2746 | |
2747 const pass_data pass_data_early_warn_uninitialized = | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2748 { |
111 | 2749 GIMPLE_PASS, /* type */ |
2750 "*early_warn_uninitialized", /* name */ | |
2751 OPTGROUP_NONE, /* optinfo_flags */ | |
2752 TV_TREE_UNINIT, /* tv_id */ | |
2753 PROP_ssa, /* properties_required */ | |
2754 0, /* properties_provided */ | |
2755 0, /* properties_destroyed */ | |
2756 0, /* todo_flags_start */ | |
2757 0, /* todo_flags_finish */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2758 }; |
111 | 2759 |
2760 class pass_early_warn_uninitialized : public gimple_opt_pass | |
2761 { | |
2762 public: | |
2763 pass_early_warn_uninitialized (gcc::context *ctxt) | |
2764 : gimple_opt_pass (pass_data_early_warn_uninitialized, ctxt) | |
2765 {} | |
2766 | |
2767 /* opt_pass methods: */ | |
2768 virtual bool gate (function *) { return gate_warn_uninitialized (); } | |
2769 virtual unsigned int execute (function *) | |
2770 { | |
2771 return execute_early_warn_uninitialized (); | |
2772 } | |
2773 | |
2774 }; // class pass_early_warn_uninitialized | |
2775 | |
2776 } // anon namespace | |
2777 | |
2778 gimple_opt_pass * | |
2779 make_pass_early_warn_uninitialized (gcc::context *ctxt) | |
2780 { | |
2781 return new pass_early_warn_uninitialized (ctxt); | |
2782 } |