annotate gcc/tree-ssanames.c @ 127:4c56639505ff

fix function.c and add CbC-example Makefile
author mir3636
date Wed, 11 Apr 2018 18:46:58 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Generic routines for manipulating SSA_NAME expressions
111
kono
parents: 67
diff changeset
2 Copyright (C) 2003-2017 Free Software Foundation, Inc.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
3
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
5
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 any later version.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
10
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 GNU General Public License for more details.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
15
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "coretypes.h"
111
kono
parents: 67
diff changeset
23 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "tree.h"
111
kono
parents: 67
diff changeset
25 #include "gimple.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "tree-pass.h"
111
kono
parents: 67
diff changeset
27 #include "ssa.h"
kono
parents: 67
diff changeset
28 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
29 #include "stor-layout.h"
kono
parents: 67
diff changeset
30 #include "tree-into-ssa.h"
kono
parents: 67
diff changeset
31 #include "tree-ssa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 /* Rewriting a function into SSA form can create a huge number of SSA_NAMEs,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 many of which may be thrown away shortly after their creation if jumps
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
35 were threaded through PHI nodes.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 While our garbage collection mechanisms will handle this situation, it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 is extremely wasteful to create nodes and throw them away, especially
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 when the nodes can be reused.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 For PR 8361, we can significantly reduce the number of nodes allocated
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 and thus the total amount of memory allocated by managing SSA_NAMEs a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 little. This additionally helps reduce the amount of work done by the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 garbage collector. Similar results have been seen on a wider variety
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 of tests (such as the compiler itself).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 Right now we maintain our free list on a per-function basis. It may
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 or may not make sense to maintain the free list for the duration of
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
49 a compilation unit.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 External code should rely solely upon HIGHEST_SSA_VERSION and the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 externally defined functions. External code should not know about
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 the details of the free list management.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 External code should also not assume the version number on nodes is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 monotonically increasing. We reuse the version number when we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 reuse an SSA_NAME expression. This helps keep arrays and bitmaps
111
kono
parents: 67
diff changeset
58 more compact. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 /* Version numbers with special meanings. We start allocating new version
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 numbers after the special ones. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 #define UNUSED_NAME_VERSION 0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 unsigned int ssa_name_nodes_reused;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 unsigned int ssa_name_nodes_created;
111
kono
parents: 67
diff changeset
67
kono
parents: 67
diff changeset
68 #define FREE_SSANAMES(fun) (fun)->gimple_df->free_ssanames
kono
parents: 67
diff changeset
69 #define FREE_SSANAMES_QUEUE(fun) (fun)->gimple_df->free_ssanames_queue
kono
parents: 67
diff changeset
70
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 /* Initialize management of SSA_NAMEs to default SIZE. If SIZE is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 zero use default. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 init_ssanames (struct function *fn, int size)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 if (size < 50)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 size = 50;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
111
kono
parents: 67
diff changeset
81 vec_alloc (SSANAMES (fn), size);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 /* Version 0 is special, so reserve the first slot in the table. Though
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 currently unused, we may use version 0 in alias analysis as part of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 the heuristics used to group aliases when the alias sets are too
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 large.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
111
kono
parents: 67
diff changeset
88 We use vec::quick_push here because we know that SSA_NAMES has at
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 least 50 elements reserved in it. */
111
kono
parents: 67
diff changeset
90 SSANAMES (fn)->quick_push (NULL_TREE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 FREE_SSANAMES (fn) = NULL;
111
kono
parents: 67
diff changeset
92 FREE_SSANAMES_QUEUE (fn) = NULL;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
93
111
kono
parents: 67
diff changeset
94 fn->gimple_df->ssa_renaming_needed = 0;
kono
parents: 67
diff changeset
95 fn->gimple_df->rename_vops = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 /* Finalize management of SSA_NAMEs. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 void
111
kono
parents: 67
diff changeset
101 fini_ssanames (struct function *fn)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 {
111
kono
parents: 67
diff changeset
103 vec_free (SSANAMES (fn));
kono
parents: 67
diff changeset
104 vec_free (FREE_SSANAMES (fn));
kono
parents: 67
diff changeset
105 vec_free (FREE_SSANAMES_QUEUE (fn));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 /* Dump some simple statistics regarding the re-use of SSA_NAME nodes. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 ssanames_print_statistics (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 fprintf (stderr, "SSA_NAME nodes allocated: %u\n", ssa_name_nodes_created);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 fprintf (stderr, "SSA_NAME nodes reused: %u\n", ssa_name_nodes_reused);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 }
111
kono
parents: 67
diff changeset
116
kono
parents: 67
diff changeset
117 /* Verify the state of the SSA_NAME lists.
kono
parents: 67
diff changeset
118
kono
parents: 67
diff changeset
119 There must be no duplicates on the free list.
kono
parents: 67
diff changeset
120 Every name on the free list must be marked as on the free list.
kono
parents: 67
diff changeset
121 Any name on the free list must not appear in the IL.
kono
parents: 67
diff changeset
122 No names can be leaked. */
kono
parents: 67
diff changeset
123
kono
parents: 67
diff changeset
124 DEBUG_FUNCTION void
kono
parents: 67
diff changeset
125 verify_ssaname_freelists (struct function *fun)
kono
parents: 67
diff changeset
126 {
kono
parents: 67
diff changeset
127 if (!gimple_in_ssa_p (fun))
kono
parents: 67
diff changeset
128 return;
kono
parents: 67
diff changeset
129
kono
parents: 67
diff changeset
130 auto_bitmap names_in_il;
kono
parents: 67
diff changeset
131
kono
parents: 67
diff changeset
132 /* Walk the entire IL noting every SSA_NAME we see. */
kono
parents: 67
diff changeset
133 basic_block bb;
kono
parents: 67
diff changeset
134 FOR_EACH_BB_FN (bb, fun)
kono
parents: 67
diff changeset
135 {
kono
parents: 67
diff changeset
136 tree t;
kono
parents: 67
diff changeset
137 /* First note the result and arguments of PHI nodes. */
kono
parents: 67
diff changeset
138 for (gphi_iterator gsi = gsi_start_phis (bb);
kono
parents: 67
diff changeset
139 !gsi_end_p (gsi);
kono
parents: 67
diff changeset
140 gsi_next (&gsi))
kono
parents: 67
diff changeset
141 {
kono
parents: 67
diff changeset
142 gphi *phi = gsi.phi ();
kono
parents: 67
diff changeset
143 t = gimple_phi_result (phi);
kono
parents: 67
diff changeset
144 bitmap_set_bit (names_in_il, SSA_NAME_VERSION (t));
kono
parents: 67
diff changeset
145
kono
parents: 67
diff changeset
146 for (unsigned int i = 0; i < gimple_phi_num_args (phi); i++)
kono
parents: 67
diff changeset
147 {
kono
parents: 67
diff changeset
148 t = gimple_phi_arg_def (phi, i);
kono
parents: 67
diff changeset
149 if (TREE_CODE (t) == SSA_NAME)
kono
parents: 67
diff changeset
150 bitmap_set_bit (names_in_il, SSA_NAME_VERSION (t));
kono
parents: 67
diff changeset
151 }
kono
parents: 67
diff changeset
152 }
kono
parents: 67
diff changeset
153
kono
parents: 67
diff changeset
154 /* Then note the operands of each statement. */
kono
parents: 67
diff changeset
155 for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
kono
parents: 67
diff changeset
156 !gsi_end_p (gsi);
kono
parents: 67
diff changeset
157 gsi_next (&gsi))
kono
parents: 67
diff changeset
158 {
kono
parents: 67
diff changeset
159 ssa_op_iter iter;
kono
parents: 67
diff changeset
160 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
161 FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, SSA_OP_ALL_OPERANDS)
kono
parents: 67
diff changeset
162 bitmap_set_bit (names_in_il, SSA_NAME_VERSION (t));
kono
parents: 67
diff changeset
163 }
kono
parents: 67
diff changeset
164 }
kono
parents: 67
diff changeset
165
kono
parents: 67
diff changeset
166 /* Now walk the free list noting what we find there and verifying
kono
parents: 67
diff changeset
167 there are no duplicates. */
kono
parents: 67
diff changeset
168 auto_bitmap names_in_freelists;
kono
parents: 67
diff changeset
169 if (FREE_SSANAMES (fun))
kono
parents: 67
diff changeset
170 {
kono
parents: 67
diff changeset
171 for (unsigned int i = 0; i < FREE_SSANAMES (fun)->length (); i++)
kono
parents: 67
diff changeset
172 {
kono
parents: 67
diff changeset
173 tree t = (*FREE_SSANAMES (fun))[i];
kono
parents: 67
diff changeset
174
kono
parents: 67
diff changeset
175 /* Verify that the name is marked as being in the free list. */
kono
parents: 67
diff changeset
176 gcc_assert (SSA_NAME_IN_FREE_LIST (t));
kono
parents: 67
diff changeset
177
kono
parents: 67
diff changeset
178 /* Verify the name has not already appeared in the free list and
kono
parents: 67
diff changeset
179 note it in the list of names found in the free list. */
kono
parents: 67
diff changeset
180 gcc_assert (!bitmap_bit_p (names_in_freelists, SSA_NAME_VERSION (t)));
kono
parents: 67
diff changeset
181 bitmap_set_bit (names_in_freelists, SSA_NAME_VERSION (t));
kono
parents: 67
diff changeset
182 }
kono
parents: 67
diff changeset
183 }
kono
parents: 67
diff changeset
184
kono
parents: 67
diff changeset
185 /* Similarly for the names in the pending free list. */
kono
parents: 67
diff changeset
186 if (FREE_SSANAMES_QUEUE (fun))
kono
parents: 67
diff changeset
187 {
kono
parents: 67
diff changeset
188 for (unsigned int i = 0; i < FREE_SSANAMES_QUEUE (fun)->length (); i++)
kono
parents: 67
diff changeset
189 {
kono
parents: 67
diff changeset
190 tree t = (*FREE_SSANAMES_QUEUE (fun))[i];
kono
parents: 67
diff changeset
191
kono
parents: 67
diff changeset
192 /* Verify that the name is marked as being in the free list. */
kono
parents: 67
diff changeset
193 gcc_assert (SSA_NAME_IN_FREE_LIST (t));
kono
parents: 67
diff changeset
194
kono
parents: 67
diff changeset
195 /* Verify the name has not already appeared in the free list and
kono
parents: 67
diff changeset
196 note it in the list of names found in the free list. */
kono
parents: 67
diff changeset
197 gcc_assert (!bitmap_bit_p (names_in_freelists, SSA_NAME_VERSION (t)));
kono
parents: 67
diff changeset
198 bitmap_set_bit (names_in_freelists, SSA_NAME_VERSION (t));
kono
parents: 67
diff changeset
199 }
kono
parents: 67
diff changeset
200 }
kono
parents: 67
diff changeset
201
kono
parents: 67
diff changeset
202 /* If any name appears in both the IL and the freelists, then
kono
parents: 67
diff changeset
203 something horrible has happened. */
kono
parents: 67
diff changeset
204 bool intersect_p = bitmap_intersect_p (names_in_il, names_in_freelists);
kono
parents: 67
diff changeset
205 gcc_assert (!intersect_p);
kono
parents: 67
diff changeset
206
kono
parents: 67
diff changeset
207 /* Names can be queued up for release if there is an ssa update
kono
parents: 67
diff changeset
208 pending. Pretend we saw them in the IL. */
kono
parents: 67
diff changeset
209 if (names_to_release)
kono
parents: 67
diff changeset
210 bitmap_ior_into (names_in_il, names_to_release);
kono
parents: 67
diff changeset
211
kono
parents: 67
diff changeset
212 /* Function splitting can "lose" SSA_NAMEs in an effort to ensure that
kono
parents: 67
diff changeset
213 debug/non-debug compilations have the same SSA_NAMEs. So for each
kono
parents: 67
diff changeset
214 lost SSA_NAME, see if it's likely one from that wart. These will always
kono
parents: 67
diff changeset
215 be marked as default definitions. So we loosely assume that anything
kono
parents: 67
diff changeset
216 marked as a default definition isn't leaked by pretending they are
kono
parents: 67
diff changeset
217 in the IL. */
kono
parents: 67
diff changeset
218 for (unsigned int i = UNUSED_NAME_VERSION + 1; i < num_ssa_names; i++)
kono
parents: 67
diff changeset
219 if (ssa_name (i) && SSA_NAME_IS_DEFAULT_DEF (ssa_name (i)))
kono
parents: 67
diff changeset
220 bitmap_set_bit (names_in_il, i);
kono
parents: 67
diff changeset
221
kono
parents: 67
diff changeset
222 unsigned int i;
kono
parents: 67
diff changeset
223 bitmap_iterator bi;
kono
parents: 67
diff changeset
224 auto_bitmap all_names;
kono
parents: 67
diff changeset
225 bitmap_set_range (all_names, UNUSED_NAME_VERSION + 1, num_ssa_names - 1);
kono
parents: 67
diff changeset
226 bitmap_ior_into (names_in_il, names_in_freelists);
kono
parents: 67
diff changeset
227
kono
parents: 67
diff changeset
228 /* Any name not mentioned in the IL and not in the feelists
kono
parents: 67
diff changeset
229 has been leaked. */
kono
parents: 67
diff changeset
230 EXECUTE_IF_AND_COMPL_IN_BITMAP(all_names, names_in_il,
kono
parents: 67
diff changeset
231 UNUSED_NAME_VERSION + 1, i, bi)
kono
parents: 67
diff changeset
232 gcc_assert (!ssa_name (i));
kono
parents: 67
diff changeset
233 }
kono
parents: 67
diff changeset
234
kono
parents: 67
diff changeset
235 /* Move all SSA_NAMEs from FREE_SSA_NAMES_QUEUE to FREE_SSA_NAMES.
kono
parents: 67
diff changeset
236
kono
parents: 67
diff changeset
237 We do not, but should have a mode to verify the state of the SSA_NAMEs
kono
parents: 67
diff changeset
238 lists. In particular at this point every name must be in the IL,
kono
parents: 67
diff changeset
239 on the free list or in the queue. Anything else is an error. */
kono
parents: 67
diff changeset
240
kono
parents: 67
diff changeset
241 void
kono
parents: 67
diff changeset
242 flush_ssaname_freelist (void)
kono
parents: 67
diff changeset
243 {
kono
parents: 67
diff changeset
244 vec_safe_splice (FREE_SSANAMES (cfun), FREE_SSANAMES_QUEUE (cfun));
kono
parents: 67
diff changeset
245 vec_safe_truncate (FREE_SSANAMES_QUEUE (cfun), 0);
kono
parents: 67
diff changeset
246 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 /* Return an SSA_NAME node for variable VAR defined in statement STMT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 in function FN. STMT may be an empty statement for artificial
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 references (e.g., default definitions created when a variable is
111
kono
parents: 67
diff changeset
251 used without a preceding definition). If VERISON is not zero then
kono
parents: 67
diff changeset
252 allocate the SSA name with that version. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 tree
111
kono
parents: 67
diff changeset
255 make_ssa_name_fn (struct function *fn, tree var, gimple *stmt,
kono
parents: 67
diff changeset
256 unsigned int version)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 tree t;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 use_operand_p imm;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
111
kono
parents: 67
diff changeset
261 gcc_assert (VAR_P (var)
kono
parents: 67
diff changeset
262 || TREE_CODE (var) == PARM_DECL
kono
parents: 67
diff changeset
263 || TREE_CODE (var) == RESULT_DECL
kono
parents: 67
diff changeset
264 || (TYPE_P (var) && is_gimple_reg_type (var)));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265
111
kono
parents: 67
diff changeset
266 /* Get the specified SSA name version. */
kono
parents: 67
diff changeset
267 if (version != 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 {
111
kono
parents: 67
diff changeset
269 t = make_node (SSA_NAME);
kono
parents: 67
diff changeset
270 SSA_NAME_VERSION (t) = version;
kono
parents: 67
diff changeset
271 if (version >= SSANAMES (fn)->length ())
kono
parents: 67
diff changeset
272 vec_safe_grow_cleared (SSANAMES (fn), version + 1);
kono
parents: 67
diff changeset
273 gcc_assert ((*SSANAMES (fn))[version] == NULL);
kono
parents: 67
diff changeset
274 (*SSANAMES (fn))[version] = t;
kono
parents: 67
diff changeset
275 ssa_name_nodes_created++;
kono
parents: 67
diff changeset
276 }
kono
parents: 67
diff changeset
277 /* If our free list has an element, then use it. */
kono
parents: 67
diff changeset
278 else if (!vec_safe_is_empty (FREE_SSANAMES (fn)))
kono
parents: 67
diff changeset
279 {
kono
parents: 67
diff changeset
280 t = FREE_SSANAMES (fn)->pop ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 ssa_name_nodes_reused++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 /* The node was cleared out when we put it on the free list, so
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 there is no need to do so again here. */
111
kono
parents: 67
diff changeset
285 gcc_assert ((*SSANAMES (fn))[SSA_NAME_VERSION (t)] == NULL);
kono
parents: 67
diff changeset
286 (*SSANAMES (fn))[SSA_NAME_VERSION (t)] = t;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 t = make_node (SSA_NAME);
111
kono
parents: 67
diff changeset
291 SSA_NAME_VERSION (t) = SSANAMES (fn)->length ();
kono
parents: 67
diff changeset
292 vec_safe_push (SSANAMES (fn), t);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 ssa_name_nodes_created++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
111
kono
parents: 67
diff changeset
296 if (TYPE_P (var))
kono
parents: 67
diff changeset
297 {
kono
parents: 67
diff changeset
298 TREE_TYPE (t) = TYPE_MAIN_VARIANT (var);
kono
parents: 67
diff changeset
299 SET_SSA_NAME_VAR_OR_IDENTIFIER (t, NULL_TREE);
kono
parents: 67
diff changeset
300 }
kono
parents: 67
diff changeset
301 else
kono
parents: 67
diff changeset
302 {
kono
parents: 67
diff changeset
303 TREE_TYPE (t) = TREE_TYPE (var);
kono
parents: 67
diff changeset
304 SET_SSA_NAME_VAR_OR_IDENTIFIER (t, var);
kono
parents: 67
diff changeset
305 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 SSA_NAME_DEF_STMT (t) = stmt;
111
kono
parents: 67
diff changeset
307 if (POINTER_TYPE_P (TREE_TYPE (t)))
kono
parents: 67
diff changeset
308 SSA_NAME_PTR_INFO (t) = NULL;
kono
parents: 67
diff changeset
309 else
kono
parents: 67
diff changeset
310 SSA_NAME_RANGE_INFO (t) = NULL;
kono
parents: 67
diff changeset
311
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 SSA_NAME_IN_FREE_LIST (t) = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 SSA_NAME_IS_DEFAULT_DEF (t) = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 imm = &(SSA_NAME_IMM_USE_NODE (t));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 imm->use = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 imm->prev = imm;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 imm->next = imm;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 imm->loc.ssa_name = t;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 return t;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322
111
kono
parents: 67
diff changeset
323 /* Helper function for set_range_info.
kono
parents: 67
diff changeset
324
kono
parents: 67
diff changeset
325 Store range information RANGE_TYPE, MIN, and MAX to tree ssa_name
kono
parents: 67
diff changeset
326 NAME. */
kono
parents: 67
diff changeset
327
kono
parents: 67
diff changeset
328 void
kono
parents: 67
diff changeset
329 set_range_info_raw (tree name, enum value_range_type range_type,
kono
parents: 67
diff changeset
330 const wide_int_ref &min, const wide_int_ref &max)
kono
parents: 67
diff changeset
331 {
kono
parents: 67
diff changeset
332 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
kono
parents: 67
diff changeset
333 gcc_assert (range_type == VR_RANGE || range_type == VR_ANTI_RANGE);
kono
parents: 67
diff changeset
334 range_info_def *ri = SSA_NAME_RANGE_INFO (name);
kono
parents: 67
diff changeset
335 unsigned int precision = TYPE_PRECISION (TREE_TYPE (name));
kono
parents: 67
diff changeset
336
kono
parents: 67
diff changeset
337 /* Allocate if not available. */
kono
parents: 67
diff changeset
338 if (ri == NULL)
kono
parents: 67
diff changeset
339 {
kono
parents: 67
diff changeset
340 size_t size = (sizeof (range_info_def)
kono
parents: 67
diff changeset
341 + trailing_wide_ints <3>::extra_size (precision));
kono
parents: 67
diff changeset
342 ri = static_cast<range_info_def *> (ggc_internal_alloc (size));
kono
parents: 67
diff changeset
343 ri->ints.set_precision (precision);
kono
parents: 67
diff changeset
344 SSA_NAME_RANGE_INFO (name) = ri;
kono
parents: 67
diff changeset
345 ri->set_nonzero_bits (wi::shwi (-1, precision));
kono
parents: 67
diff changeset
346 }
kono
parents: 67
diff changeset
347
kono
parents: 67
diff changeset
348 /* Record the range type. */
kono
parents: 67
diff changeset
349 if (SSA_NAME_RANGE_TYPE (name) != range_type)
kono
parents: 67
diff changeset
350 SSA_NAME_ANTI_RANGE_P (name) = (range_type == VR_ANTI_RANGE);
kono
parents: 67
diff changeset
351
kono
parents: 67
diff changeset
352 /* Set the values. */
kono
parents: 67
diff changeset
353 ri->set_min (min);
kono
parents: 67
diff changeset
354 ri->set_max (max);
kono
parents: 67
diff changeset
355
kono
parents: 67
diff changeset
356 /* If it is a range, try to improve nonzero_bits from the min/max. */
kono
parents: 67
diff changeset
357 if (range_type == VR_RANGE)
kono
parents: 67
diff changeset
358 {
kono
parents: 67
diff changeset
359 wide_int xorv = ri->get_min () ^ ri->get_max ();
kono
parents: 67
diff changeset
360 if (xorv != 0)
kono
parents: 67
diff changeset
361 xorv = wi::mask (precision - wi::clz (xorv), false, precision);
kono
parents: 67
diff changeset
362 ri->set_nonzero_bits (ri->get_nonzero_bits () & (ri->get_min () | xorv));
kono
parents: 67
diff changeset
363 }
kono
parents: 67
diff changeset
364 }
kono
parents: 67
diff changeset
365
kono
parents: 67
diff changeset
366 /* Store range information RANGE_TYPE, MIN, and MAX to tree ssa_name
kono
parents: 67
diff changeset
367 NAME while making sure we don't store useless range info. */
kono
parents: 67
diff changeset
368
kono
parents: 67
diff changeset
369 void
kono
parents: 67
diff changeset
370 set_range_info (tree name, enum value_range_type range_type,
kono
parents: 67
diff changeset
371 const wide_int_ref &min, const wide_int_ref &max)
kono
parents: 67
diff changeset
372 {
kono
parents: 67
diff changeset
373 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
kono
parents: 67
diff changeset
374
kono
parents: 67
diff changeset
375 /* A range of the entire domain is really no range at all. */
kono
parents: 67
diff changeset
376 tree type = TREE_TYPE (name);
kono
parents: 67
diff changeset
377 if (min == wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type))
kono
parents: 67
diff changeset
378 && max == wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)))
kono
parents: 67
diff changeset
379 {
kono
parents: 67
diff changeset
380 range_info_def *ri = SSA_NAME_RANGE_INFO (name);
kono
parents: 67
diff changeset
381 if (ri == NULL)
kono
parents: 67
diff changeset
382 return;
kono
parents: 67
diff changeset
383 if (ri->get_nonzero_bits () == -1)
kono
parents: 67
diff changeset
384 {
kono
parents: 67
diff changeset
385 ggc_free (ri);
kono
parents: 67
diff changeset
386 SSA_NAME_RANGE_INFO (name) = NULL;
kono
parents: 67
diff changeset
387 return;
kono
parents: 67
diff changeset
388 }
kono
parents: 67
diff changeset
389 }
kono
parents: 67
diff changeset
390
kono
parents: 67
diff changeset
391 set_range_info_raw (name, range_type, min, max);
kono
parents: 67
diff changeset
392 }
kono
parents: 67
diff changeset
393
kono
parents: 67
diff changeset
394
kono
parents: 67
diff changeset
395 /* Gets range information MIN, MAX and returns enum value_range_type
kono
parents: 67
diff changeset
396 corresponding to tree ssa_name NAME. enum value_range_type returned
kono
parents: 67
diff changeset
397 is used to determine if MIN and MAX are valid values. */
kono
parents: 67
diff changeset
398
kono
parents: 67
diff changeset
399 enum value_range_type
kono
parents: 67
diff changeset
400 get_range_info (const_tree name, wide_int *min, wide_int *max)
kono
parents: 67
diff changeset
401 {
kono
parents: 67
diff changeset
402 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
kono
parents: 67
diff changeset
403 gcc_assert (min && max);
kono
parents: 67
diff changeset
404 range_info_def *ri = SSA_NAME_RANGE_INFO (name);
kono
parents: 67
diff changeset
405
kono
parents: 67
diff changeset
406 /* Return VR_VARYING for SSA_NAMEs with NULL RANGE_INFO or SSA_NAMEs
kono
parents: 67
diff changeset
407 with integral types width > 2 * HOST_BITS_PER_WIDE_INT precision. */
kono
parents: 67
diff changeset
408 if (!ri || (GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (TREE_TYPE (name)))
kono
parents: 67
diff changeset
409 > 2 * HOST_BITS_PER_WIDE_INT))
kono
parents: 67
diff changeset
410 return VR_VARYING;
kono
parents: 67
diff changeset
411
kono
parents: 67
diff changeset
412 *min = ri->get_min ();
kono
parents: 67
diff changeset
413 *max = ri->get_max ();
kono
parents: 67
diff changeset
414 return SSA_NAME_RANGE_TYPE (name);
kono
parents: 67
diff changeset
415 }
kono
parents: 67
diff changeset
416
kono
parents: 67
diff changeset
417 /* Set nonnull attribute to pointer NAME. */
kono
parents: 67
diff changeset
418
kono
parents: 67
diff changeset
419 void
kono
parents: 67
diff changeset
420 set_ptr_nonnull (tree name)
kono
parents: 67
diff changeset
421 {
kono
parents: 67
diff changeset
422 gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
kono
parents: 67
diff changeset
423 struct ptr_info_def *pi = get_ptr_info (name);
kono
parents: 67
diff changeset
424 pi->pt.null = 0;
kono
parents: 67
diff changeset
425 }
kono
parents: 67
diff changeset
426
kono
parents: 67
diff changeset
427 /* Return nonnull attribute of pointer NAME. */
kono
parents: 67
diff changeset
428 bool
kono
parents: 67
diff changeset
429 get_ptr_nonnull (const_tree name)
kono
parents: 67
diff changeset
430 {
kono
parents: 67
diff changeset
431 gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
kono
parents: 67
diff changeset
432 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name);
kono
parents: 67
diff changeset
433 if (pi == NULL)
kono
parents: 67
diff changeset
434 return false;
kono
parents: 67
diff changeset
435 /* TODO Now pt->null is conservatively set to true in PTA
kono
parents: 67
diff changeset
436 analysis. vrp is the only pass (including ipa-vrp)
kono
parents: 67
diff changeset
437 that clears pt.null via set_ptr_nonull when it knows
kono
parents: 67
diff changeset
438 for sure. PTA will preserves the pt.null value set by VRP.
kono
parents: 67
diff changeset
439
kono
parents: 67
diff changeset
440 When PTA analysis is improved, pt.anything, pt.nonlocal
kono
parents: 67
diff changeset
441 and pt.escaped may also has to be considered before
kono
parents: 67
diff changeset
442 deciding that pointer cannot point to NULL. */
kono
parents: 67
diff changeset
443 return !pi->pt.null;
kono
parents: 67
diff changeset
444 }
kono
parents: 67
diff changeset
445
kono
parents: 67
diff changeset
446 /* Change non-zero bits bitmask of NAME. */
kono
parents: 67
diff changeset
447
kono
parents: 67
diff changeset
448 void
kono
parents: 67
diff changeset
449 set_nonzero_bits (tree name, const wide_int_ref &mask)
kono
parents: 67
diff changeset
450 {
kono
parents: 67
diff changeset
451 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
kono
parents: 67
diff changeset
452 if (SSA_NAME_RANGE_INFO (name) == NULL)
kono
parents: 67
diff changeset
453 {
kono
parents: 67
diff changeset
454 if (mask == -1)
kono
parents: 67
diff changeset
455 return;
kono
parents: 67
diff changeset
456 set_range_info_raw (name, VR_RANGE,
kono
parents: 67
diff changeset
457 wi::to_wide (TYPE_MIN_VALUE (TREE_TYPE (name))),
kono
parents: 67
diff changeset
458 wi::to_wide (TYPE_MAX_VALUE (TREE_TYPE (name))));
kono
parents: 67
diff changeset
459 }
kono
parents: 67
diff changeset
460 range_info_def *ri = SSA_NAME_RANGE_INFO (name);
kono
parents: 67
diff changeset
461 ri->set_nonzero_bits (mask);
kono
parents: 67
diff changeset
462 }
kono
parents: 67
diff changeset
463
kono
parents: 67
diff changeset
464 /* Return a widest_int with potentially non-zero bits in SSA_NAME
kono
parents: 67
diff changeset
465 NAME, the constant for INTEGER_CST, or -1 if unknown. */
kono
parents: 67
diff changeset
466
kono
parents: 67
diff changeset
467 wide_int
kono
parents: 67
diff changeset
468 get_nonzero_bits (const_tree name)
kono
parents: 67
diff changeset
469 {
kono
parents: 67
diff changeset
470 if (TREE_CODE (name) == INTEGER_CST)
kono
parents: 67
diff changeset
471 return wi::to_wide (name);
kono
parents: 67
diff changeset
472
kono
parents: 67
diff changeset
473 /* Use element_precision instead of TYPE_PRECISION so complex and
kono
parents: 67
diff changeset
474 vector types get a non-zero precision. */
kono
parents: 67
diff changeset
475 unsigned int precision = element_precision (TREE_TYPE (name));
kono
parents: 67
diff changeset
476 if (POINTER_TYPE_P (TREE_TYPE (name)))
kono
parents: 67
diff changeset
477 {
kono
parents: 67
diff changeset
478 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name);
kono
parents: 67
diff changeset
479 if (pi && pi->align)
kono
parents: 67
diff changeset
480 return wi::shwi (-(HOST_WIDE_INT) pi->align
kono
parents: 67
diff changeset
481 | (HOST_WIDE_INT) pi->misalign, precision);
kono
parents: 67
diff changeset
482 return wi::shwi (-1, precision);
kono
parents: 67
diff changeset
483 }
kono
parents: 67
diff changeset
484
kono
parents: 67
diff changeset
485 range_info_def *ri = SSA_NAME_RANGE_INFO (name);
kono
parents: 67
diff changeset
486 if (!ri)
kono
parents: 67
diff changeset
487 return wi::shwi (-1, precision);
kono
parents: 67
diff changeset
488
kono
parents: 67
diff changeset
489 return ri->get_nonzero_bits ();
kono
parents: 67
diff changeset
490 }
kono
parents: 67
diff changeset
491
kono
parents: 67
diff changeset
492 /* Return TRUE is OP, an SSA_NAME has a range of values [0..1], false
kono
parents: 67
diff changeset
493 otherwise.
kono
parents: 67
diff changeset
494
kono
parents: 67
diff changeset
495 This can be because it is a boolean type, any unsigned integral
kono
parents: 67
diff changeset
496 type with a single bit of precision, or has known range of [0..1]
kono
parents: 67
diff changeset
497 via VRP analysis. */
kono
parents: 67
diff changeset
498
kono
parents: 67
diff changeset
499 bool
kono
parents: 67
diff changeset
500 ssa_name_has_boolean_range (tree op)
kono
parents: 67
diff changeset
501 {
kono
parents: 67
diff changeset
502 gcc_assert (TREE_CODE (op) == SSA_NAME);
kono
parents: 67
diff changeset
503
kono
parents: 67
diff changeset
504 /* Boolean types always have a range [0..1]. */
kono
parents: 67
diff changeset
505 if (TREE_CODE (TREE_TYPE (op)) == BOOLEAN_TYPE)
kono
parents: 67
diff changeset
506 return true;
kono
parents: 67
diff changeset
507
kono
parents: 67
diff changeset
508 /* An integral type with a single bit of precision. */
kono
parents: 67
diff changeset
509 if (INTEGRAL_TYPE_P (TREE_TYPE (op))
kono
parents: 67
diff changeset
510 && TYPE_UNSIGNED (TREE_TYPE (op))
kono
parents: 67
diff changeset
511 && TYPE_PRECISION (TREE_TYPE (op)) == 1)
kono
parents: 67
diff changeset
512 return true;
kono
parents: 67
diff changeset
513
kono
parents: 67
diff changeset
514 /* An integral type with more precision, but the object
kono
parents: 67
diff changeset
515 only takes on values [0..1] as determined by VRP
kono
parents: 67
diff changeset
516 analysis. */
kono
parents: 67
diff changeset
517 if (INTEGRAL_TYPE_P (TREE_TYPE (op))
kono
parents: 67
diff changeset
518 && (TYPE_PRECISION (TREE_TYPE (op)) > 1)
kono
parents: 67
diff changeset
519 && wi::eq_p (get_nonzero_bits (op), 1))
kono
parents: 67
diff changeset
520 return true;
kono
parents: 67
diff changeset
521
kono
parents: 67
diff changeset
522 return false;
kono
parents: 67
diff changeset
523 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 /* We no longer need the SSA_NAME expression VAR, release it so that
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
526 it may be reused.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 Note it is assumed that no calls to make_ssa_name will be made
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 until all uses of the ssa name are released and that the only
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 use of the SSA_NAME expression is to check its SSA_NAME_VAR. All
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 other fields must be assumed clobbered. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 void
111
kono
parents: 67
diff changeset
534 release_ssa_name_fn (struct function *fn, tree var)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 if (!var)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 /* Never release the default definition for a symbol. It's a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 special SSA name that should always exist once it's created. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 if (SSA_NAME_IS_DEFAULT_DEF (var))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 /* If VAR has been registered for SSA updating, don't remove it.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 After update_ssa has run, the name will be released. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 if (name_registered_for_update_p (var))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 release_ssa_name_after_update_ssa (var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 /* release_ssa_name can be called multiple times on a single SSA_NAME.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 However, it should only end up on our free list one time. We
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 keep a status bit in the SSA_NAME node itself to indicate it has
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
555 been put on the free list.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 Note that once on the freelist you can not reference the SSA_NAME's
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 defining statement. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 if (! SSA_NAME_IN_FREE_LIST (var))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 tree saved_ssa_name_var = SSA_NAME_VAR (var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 int saved_ssa_name_version = SSA_NAME_VERSION (var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 use_operand_p imm = &(SSA_NAME_IMM_USE_NODE (var));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
565 if (MAY_HAVE_DEBUG_STMTS)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
566 insert_debug_temp_for_var_def (NULL, var);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
567
111
kono
parents: 67
diff changeset
568 if (flag_checking)
kono
parents: 67
diff changeset
569 verify_imm_links (stderr, var);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 while (imm->next != imm)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 delink_imm_use (imm->next);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572
111
kono
parents: 67
diff changeset
573 (*SSANAMES (fn))[SSA_NAME_VERSION (var)] = NULL_TREE;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 memset (var, 0, tree_size (var));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 imm->prev = imm;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 imm->next = imm;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 imm->loc.ssa_name = var;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 /* First put back the right tree node so that the tree checking
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 macros do not complain. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 TREE_SET_CODE (var, SSA_NAME);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 /* Restore the version number. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 SSA_NAME_VERSION (var) = saved_ssa_name_version;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 /* Hopefully this can go away once we have the new incremental
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 SSA updating code installed. */
111
kono
parents: 67
diff changeset
589 SET_SSA_NAME_VAR_OR_IDENTIFIER (var, saved_ssa_name_var);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 /* Note this SSA_NAME is now in the first list. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 SSA_NAME_IN_FREE_LIST (var) = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593
111
kono
parents: 67
diff changeset
594 /* And finally queue it so that it will be put on the free list. */
kono
parents: 67
diff changeset
595 vec_safe_push (FREE_SSANAMES_QUEUE (fn), var);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598
111
kono
parents: 67
diff changeset
599 /* If the alignment of the pointer described by PI is known, return true and
kono
parents: 67
diff changeset
600 store the alignment and the deviation from it into *ALIGNP and *MISALIGNP
kono
parents: 67
diff changeset
601 respectively. Otherwise return false. */
kono
parents: 67
diff changeset
602
kono
parents: 67
diff changeset
603 bool
kono
parents: 67
diff changeset
604 get_ptr_info_alignment (struct ptr_info_def *pi, unsigned int *alignp,
kono
parents: 67
diff changeset
605 unsigned int *misalignp)
kono
parents: 67
diff changeset
606 {
kono
parents: 67
diff changeset
607 if (pi->align)
kono
parents: 67
diff changeset
608 {
kono
parents: 67
diff changeset
609 *alignp = pi->align;
kono
parents: 67
diff changeset
610 *misalignp = pi->misalign;
kono
parents: 67
diff changeset
611 return true;
kono
parents: 67
diff changeset
612 }
kono
parents: 67
diff changeset
613 else
kono
parents: 67
diff changeset
614 return false;
kono
parents: 67
diff changeset
615 }
kono
parents: 67
diff changeset
616
kono
parents: 67
diff changeset
617 /* State that the pointer described by PI has unknown alignment. */
kono
parents: 67
diff changeset
618
kono
parents: 67
diff changeset
619 void
kono
parents: 67
diff changeset
620 mark_ptr_info_alignment_unknown (struct ptr_info_def *pi)
kono
parents: 67
diff changeset
621 {
kono
parents: 67
diff changeset
622 pi->align = 0;
kono
parents: 67
diff changeset
623 pi->misalign = 0;
kono
parents: 67
diff changeset
624 }
kono
parents: 67
diff changeset
625
kono
parents: 67
diff changeset
626 /* Store the power-of-two byte alignment and the deviation from that
kono
parents: 67
diff changeset
627 alignment of pointer described by PI to ALIOGN and MISALIGN
kono
parents: 67
diff changeset
628 respectively. */
kono
parents: 67
diff changeset
629
kono
parents: 67
diff changeset
630 void
kono
parents: 67
diff changeset
631 set_ptr_info_alignment (struct ptr_info_def *pi, unsigned int align,
kono
parents: 67
diff changeset
632 unsigned int misalign)
kono
parents: 67
diff changeset
633 {
kono
parents: 67
diff changeset
634 gcc_checking_assert (align != 0);
kono
parents: 67
diff changeset
635 gcc_assert ((align & (align - 1)) == 0);
kono
parents: 67
diff changeset
636 gcc_assert ((misalign & ~(align - 1)) == 0);
kono
parents: 67
diff changeset
637
kono
parents: 67
diff changeset
638 pi->align = align;
kono
parents: 67
diff changeset
639 pi->misalign = misalign;
kono
parents: 67
diff changeset
640 }
kono
parents: 67
diff changeset
641
kono
parents: 67
diff changeset
642 /* If pointer described by PI has known alignment, increase its known
kono
parents: 67
diff changeset
643 misalignment by INCREMENT modulo its current alignment. */
kono
parents: 67
diff changeset
644
kono
parents: 67
diff changeset
645 void
kono
parents: 67
diff changeset
646 adjust_ptr_info_misalignment (struct ptr_info_def *pi,
kono
parents: 67
diff changeset
647 unsigned int increment)
kono
parents: 67
diff changeset
648 {
kono
parents: 67
diff changeset
649 if (pi->align != 0)
kono
parents: 67
diff changeset
650 {
kono
parents: 67
diff changeset
651 pi->misalign += increment;
kono
parents: 67
diff changeset
652 pi->misalign &= (pi->align - 1);
kono
parents: 67
diff changeset
653 }
kono
parents: 67
diff changeset
654 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655
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
656 /* Return the alias information associated with pointer T. It creates a
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
657 new instance if none existed. */
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
658
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
659 struct ptr_info_def *
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
660 get_ptr_info (tree t)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 {
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
662 struct ptr_info_def *pi;
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
663
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
664 gcc_assert (POINTER_TYPE_P (TREE_TYPE (t)));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665
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
666 pi = SSA_NAME_PTR_INFO (t);
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
667 if (pi == 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
668 {
111
kono
parents: 67
diff changeset
669 pi = ggc_cleared_alloc<ptr_info_def> ();
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
670 pt_solution_reset (&pi->pt);
111
kono
parents: 67
diff changeset
671 mark_ptr_info_alignment_unknown (pi);
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
672 SSA_NAME_PTR_INFO (t) = pi;
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
673 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674
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
675 return pi;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677
111
kono
parents: 67
diff changeset
678
kono
parents: 67
diff changeset
679 /* Creates a new SSA name using the template NAME tobe defined by
kono
parents: 67
diff changeset
680 statement STMT in function FN. */
kono
parents: 67
diff changeset
681
kono
parents: 67
diff changeset
682 tree
kono
parents: 67
diff changeset
683 copy_ssa_name_fn (struct function *fn, tree name, gimple *stmt)
kono
parents: 67
diff changeset
684 {
kono
parents: 67
diff changeset
685 tree new_name;
kono
parents: 67
diff changeset
686
kono
parents: 67
diff changeset
687 if (SSA_NAME_VAR (name))
kono
parents: 67
diff changeset
688 new_name = make_ssa_name_fn (fn, SSA_NAME_VAR (name), stmt);
kono
parents: 67
diff changeset
689 else
kono
parents: 67
diff changeset
690 {
kono
parents: 67
diff changeset
691 new_name = make_ssa_name_fn (fn, TREE_TYPE (name), stmt);
kono
parents: 67
diff changeset
692 SET_SSA_NAME_VAR_OR_IDENTIFIER (new_name, SSA_NAME_IDENTIFIER (name));
kono
parents: 67
diff changeset
693 }
kono
parents: 67
diff changeset
694
kono
parents: 67
diff changeset
695 return new_name;
kono
parents: 67
diff changeset
696 }
kono
parents: 67
diff changeset
697
kono
parents: 67
diff changeset
698
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 /* Creates a duplicate of the ptr_info_def at PTR_INFO for use by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 the SSA name NAME. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 duplicate_ssa_name_ptr_info (tree name, struct ptr_info_def *ptr_info)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 struct ptr_info_def *new_ptr_info;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 gcc_assert (POINTER_TYPE_P (TREE_TYPE (name)));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 gcc_assert (!SSA_NAME_PTR_INFO (name));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 if (!ptr_info)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712
111
kono
parents: 67
diff changeset
713 new_ptr_info = ggc_alloc<ptr_info_def> ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 *new_ptr_info = *ptr_info;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
715
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 SSA_NAME_PTR_INFO (name) = new_ptr_info;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718
111
kono
parents: 67
diff changeset
719 /* Creates a duplicate of the range_info_def at RANGE_INFO of type
kono
parents: 67
diff changeset
720 RANGE_TYPE for use by the SSA name NAME. */
kono
parents: 67
diff changeset
721 void
kono
parents: 67
diff changeset
722 duplicate_ssa_name_range_info (tree name, enum value_range_type range_type,
kono
parents: 67
diff changeset
723 struct range_info_def *range_info)
kono
parents: 67
diff changeset
724 {
kono
parents: 67
diff changeset
725 struct range_info_def *new_range_info;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726
111
kono
parents: 67
diff changeset
727 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name)));
kono
parents: 67
diff changeset
728 gcc_assert (!SSA_NAME_RANGE_INFO (name));
kono
parents: 67
diff changeset
729
kono
parents: 67
diff changeset
730 if (!range_info)
kono
parents: 67
diff changeset
731 return;
kono
parents: 67
diff changeset
732
kono
parents: 67
diff changeset
733 unsigned int precision = TYPE_PRECISION (TREE_TYPE (name));
kono
parents: 67
diff changeset
734 size_t size = (sizeof (range_info_def)
kono
parents: 67
diff changeset
735 + trailing_wide_ints <3>::extra_size (precision));
kono
parents: 67
diff changeset
736 new_range_info = static_cast<range_info_def *> (ggc_internal_alloc (size));
kono
parents: 67
diff changeset
737 memcpy (new_range_info, range_info, size);
kono
parents: 67
diff changeset
738
kono
parents: 67
diff changeset
739 gcc_assert (range_type == VR_RANGE || range_type == VR_ANTI_RANGE);
kono
parents: 67
diff changeset
740 SSA_NAME_ANTI_RANGE_P (name) = (range_type == VR_ANTI_RANGE);
kono
parents: 67
diff changeset
741 SSA_NAME_RANGE_INFO (name) = new_range_info;
kono
parents: 67
diff changeset
742 }
kono
parents: 67
diff changeset
743
kono
parents: 67
diff changeset
744
kono
parents: 67
diff changeset
745
kono
parents: 67
diff changeset
746 /* Creates a duplicate of a ssa name NAME tobe defined by statement STMT
kono
parents: 67
diff changeset
747 in function FN. */
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
748
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
749 tree
111
kono
parents: 67
diff changeset
750 duplicate_ssa_name_fn (struct function *fn, tree name, gimple *stmt)
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
751 {
111
kono
parents: 67
diff changeset
752 tree new_name = copy_ssa_name_fn (fn, name, stmt);
kono
parents: 67
diff changeset
753 if (POINTER_TYPE_P (TREE_TYPE (name)))
kono
parents: 67
diff changeset
754 {
kono
parents: 67
diff changeset
755 struct ptr_info_def *old_ptr_info = SSA_NAME_PTR_INFO (name);
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
756
111
kono
parents: 67
diff changeset
757 if (old_ptr_info)
kono
parents: 67
diff changeset
758 duplicate_ssa_name_ptr_info (new_name, old_ptr_info);
kono
parents: 67
diff changeset
759 }
kono
parents: 67
diff changeset
760 else
kono
parents: 67
diff changeset
761 {
kono
parents: 67
diff changeset
762 struct range_info_def *old_range_info = SSA_NAME_RANGE_INFO (name);
kono
parents: 67
diff changeset
763
kono
parents: 67
diff changeset
764 if (old_range_info)
kono
parents: 67
diff changeset
765 duplicate_ssa_name_range_info (new_name, SSA_NAME_RANGE_TYPE (name),
kono
parents: 67
diff changeset
766 old_range_info);
kono
parents: 67
diff changeset
767 }
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
768
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
769 return new_name;
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
770 }
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
771
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
772
111
kono
parents: 67
diff changeset
773 /* Reset all flow sensitive data on NAME such as range-info, nonzero
kono
parents: 67
diff changeset
774 bits and alignment. */
kono
parents: 67
diff changeset
775
kono
parents: 67
diff changeset
776 void
kono
parents: 67
diff changeset
777 reset_flow_sensitive_info (tree name)
kono
parents: 67
diff changeset
778 {
kono
parents: 67
diff changeset
779 if (POINTER_TYPE_P (TREE_TYPE (name)))
kono
parents: 67
diff changeset
780 {
kono
parents: 67
diff changeset
781 /* points-to info is not flow-sensitive. */
kono
parents: 67
diff changeset
782 if (SSA_NAME_PTR_INFO (name))
kono
parents: 67
diff changeset
783 mark_ptr_info_alignment_unknown (SSA_NAME_PTR_INFO (name));
kono
parents: 67
diff changeset
784 }
kono
parents: 67
diff changeset
785 else
kono
parents: 67
diff changeset
786 SSA_NAME_RANGE_INFO (name) = NULL;
kono
parents: 67
diff changeset
787 }
kono
parents: 67
diff changeset
788
kono
parents: 67
diff changeset
789 /* Clear all flow sensitive data from all statements and PHI definitions
kono
parents: 67
diff changeset
790 in BB. */
kono
parents: 67
diff changeset
791
kono
parents: 67
diff changeset
792 void
kono
parents: 67
diff changeset
793 reset_flow_sensitive_info_in_bb (basic_block bb)
kono
parents: 67
diff changeset
794 {
kono
parents: 67
diff changeset
795 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
kono
parents: 67
diff changeset
796 gsi_next (&gsi))
kono
parents: 67
diff changeset
797 {
kono
parents: 67
diff changeset
798 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
799 ssa_op_iter i;
kono
parents: 67
diff changeset
800 tree op;
kono
parents: 67
diff changeset
801 FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF)
kono
parents: 67
diff changeset
802 reset_flow_sensitive_info (op);
kono
parents: 67
diff changeset
803 }
kono
parents: 67
diff changeset
804
kono
parents: 67
diff changeset
805 for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
kono
parents: 67
diff changeset
806 gsi_next (&gsi))
kono
parents: 67
diff changeset
807 {
kono
parents: 67
diff changeset
808 tree phi_def = gimple_phi_result (gsi.phi ());
kono
parents: 67
diff changeset
809 reset_flow_sensitive_info (phi_def);
kono
parents: 67
diff changeset
810 }
kono
parents: 67
diff changeset
811 }
kono
parents: 67
diff changeset
812
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 /* Release all the SSA_NAMEs created by STMT. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 void
111
kono
parents: 67
diff changeset
816 release_defs (gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 tree def;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
819 ssa_op_iter iter;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_ALL_DEFS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 if (TREE_CODE (def) == SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 release_ssa_name (def);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 /* Replace the symbol associated with SSA_NAME with SYM. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 replace_ssa_name_symbol (tree ssa_name, tree sym)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 {
111
kono
parents: 67
diff changeset
832 SET_SSA_NAME_VAR_OR_IDENTIFIER (ssa_name, sym);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 TREE_TYPE (ssa_name) = TREE_TYPE (sym);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835
111
kono
parents: 67
diff changeset
836 /* Release the vector of free SSA_NAMEs and compact the vector of SSA_NAMEs
kono
parents: 67
diff changeset
837 that are live. */
kono
parents: 67
diff changeset
838
kono
parents: 67
diff changeset
839 static void
kono
parents: 67
diff changeset
840 release_free_names_and_compact_live_names (function *fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 {
111
kono
parents: 67
diff changeset
842 unsigned i, j;
kono
parents: 67
diff changeset
843 int n = vec_safe_length (FREE_SSANAMES (fun));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 /* Now release the freelist. */
111
kono
parents: 67
diff changeset
846 vec_free (FREE_SSANAMES (fun));
kono
parents: 67
diff changeset
847
kono
parents: 67
diff changeset
848 /* And compact the SSA number space. We make sure to not change the
kono
parents: 67
diff changeset
849 relative order of SSA versions. */
kono
parents: 67
diff changeset
850 for (i = 1, j = 1; i < fun->gimple_df->ssa_names->length (); ++i)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 {
111
kono
parents: 67
diff changeset
852 tree name = ssa_name (i);
kono
parents: 67
diff changeset
853 if (name)
kono
parents: 67
diff changeset
854 {
kono
parents: 67
diff changeset
855 if (i != j)
kono
parents: 67
diff changeset
856 {
kono
parents: 67
diff changeset
857 SSA_NAME_VERSION (name) = j;
kono
parents: 67
diff changeset
858 (*fun->gimple_df->ssa_names)[j] = name;
kono
parents: 67
diff changeset
859 }
kono
parents: 67
diff changeset
860 j++;
kono
parents: 67
diff changeset
861 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862 }
111
kono
parents: 67
diff changeset
863 fun->gimple_df->ssa_names->truncate (j);
kono
parents: 67
diff changeset
864
kono
parents: 67
diff changeset
865 statistics_counter_event (fun, "SSA names released", n);
kono
parents: 67
diff changeset
866 statistics_counter_event (fun, "SSA name holes removed", i - j);
kono
parents: 67
diff changeset
867 if (dump_file)
kono
parents: 67
diff changeset
868 fprintf (dump_file, "Released %i names, %.2f%%, removed %i holes\n",
kono
parents: 67
diff changeset
869 n, n * 100.0 / num_ssa_names, i - j);
kono
parents: 67
diff changeset
870 }
kono
parents: 67
diff changeset
871
kono
parents: 67
diff changeset
872 /* Return SSA names that are unused to GGC memory and compact the SSA
kono
parents: 67
diff changeset
873 version namespace. This is used to keep footprint of compiler during
kono
parents: 67
diff changeset
874 interprocedural optimization. */
kono
parents: 67
diff changeset
875
kono
parents: 67
diff changeset
876 namespace {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877
111
kono
parents: 67
diff changeset
878 const pass_data pass_data_release_ssa_names =
kono
parents: 67
diff changeset
879 {
kono
parents: 67
diff changeset
880 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
881 "release_ssa", /* name */
kono
parents: 67
diff changeset
882 OPTGROUP_NONE, /* optinfo_flags */
kono
parents: 67
diff changeset
883 TV_TREE_SSA_OTHER, /* tv_id */
kono
parents: 67
diff changeset
884 PROP_ssa, /* properties_required */
kono
parents: 67
diff changeset
885 0, /* properties_provided */
kono
parents: 67
diff changeset
886 0, /* properties_destroyed */
kono
parents: 67
diff changeset
887 TODO_remove_unused_locals, /* todo_flags_start */
kono
parents: 67
diff changeset
888 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
889 };
kono
parents: 67
diff changeset
890
kono
parents: 67
diff changeset
891 class pass_release_ssa_names : public gimple_opt_pass
kono
parents: 67
diff changeset
892 {
kono
parents: 67
diff changeset
893 public:
kono
parents: 67
diff changeset
894 pass_release_ssa_names (gcc::context *ctxt)
kono
parents: 67
diff changeset
895 : gimple_opt_pass (pass_data_release_ssa_names, ctxt)
kono
parents: 67
diff changeset
896 {}
kono
parents: 67
diff changeset
897
kono
parents: 67
diff changeset
898 /* opt_pass methods: */
kono
parents: 67
diff changeset
899 virtual unsigned int execute (function *);
kono
parents: 67
diff changeset
900
kono
parents: 67
diff changeset
901 }; // class pass_release_ssa_names
kono
parents: 67
diff changeset
902
kono
parents: 67
diff changeset
903 unsigned int
kono
parents: 67
diff changeset
904 pass_release_ssa_names::execute (function *fun)
kono
parents: 67
diff changeset
905 {
kono
parents: 67
diff changeset
906 release_free_names_and_compact_live_names (fun);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
909
111
kono
parents: 67
diff changeset
910 } // anon namespace
kono
parents: 67
diff changeset
911
kono
parents: 67
diff changeset
912 gimple_opt_pass *
kono
parents: 67
diff changeset
913 make_pass_release_ssa_names (gcc::context *ctxt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914 {
111
kono
parents: 67
diff changeset
915 return new pass_release_ssa_names (ctxt);
kono
parents: 67
diff changeset
916 }