annotate gcc/tree-ssa-uninit.c @ 158:494b0b89df80 default tip

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