annotate gcc/tree-ssanames.c @ 131:84e7813d76e9

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