annotate gcc/tree-ssa-threadupdate.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 /* Thread edges through blocks and update the control flow and SSA graphs.
111
kono
parents: 67
diff changeset
2 Copyright (C) 2004-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
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.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
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.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
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"
kono
parents: 67
diff changeset
26 #include "cfghooks.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "tree-pass.h"
111
kono
parents: 67
diff changeset
28 #include "ssa.h"
kono
parents: 67
diff changeset
29 #include "fold-const.h"
kono
parents: 67
diff changeset
30 #include "cfganal.h"
kono
parents: 67
diff changeset
31 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
32 #include "tree-ssa.h"
kono
parents: 67
diff changeset
33 #include "tree-ssa-threadupdate.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 #include "cfgloop.h"
111
kono
parents: 67
diff changeset
35 #include "dbgcnt.h"
kono
parents: 67
diff changeset
36 #include "tree-cfg.h"
kono
parents: 67
diff changeset
37 #include "tree-vectorizer.h"
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 /* Given a block B, update the CFG and SSA graph to reflect redirecting
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 one or more in-edges to B to instead reach the destination of an
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 out-edge from B while preserving any side effects in B.
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 i.e., given A->B and B->C, change A->B to be A->C yet still preserve the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 side effects of executing B.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 1. Make a copy of B (including its outgoing edges and statements). Call
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 the copy B'. Note B' has no incoming edges or PHIs at this time.
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 2. Remove the control statement at the end of B' and all outgoing edges
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 except B'->C.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 3. Add a new argument to each PHI in C with the same value as the existing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 argument associated with edge B->C. Associate the new PHI arguments
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 with the edge B'->C.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 4. For each PHI in B, find or create a PHI in B' with an identical
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 PHI_RESULT. Add an argument to the PHI in B' which has the same
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 value as the PHI in B associated with the edge A->B. Associate
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 the new argument in the PHI in B' with the edge A->B.
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 5. Change the edge A->B to A->B'.
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 5a. This automatically deletes any PHI arguments associated with the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 edge A->B in B.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 5b. This automatically associates each new argument added in step 4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 with the edge A->B'.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 6. Repeat for other incoming edges into B.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 7. Put the duplicated resources in B and all the B' blocks into SSA form.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 Note that block duplication can be minimized by first collecting the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 set of unique destination blocks that the incoming edges should
111
kono
parents: 67
diff changeset
75 be threaded to.
kono
parents: 67
diff changeset
76
kono
parents: 67
diff changeset
77 We reduce the number of edges and statements we create by not copying all
kono
parents: 67
diff changeset
78 the outgoing edges and the control statement in step #1. We instead create
kono
parents: 67
diff changeset
79 a template block without the outgoing edges and duplicate the template.
kono
parents: 67
diff changeset
80
kono
parents: 67
diff changeset
81 Another case this code handles is threading through a "joiner" block. In
kono
parents: 67
diff changeset
82 this case, we do not know the destination of the joiner block, but one
kono
parents: 67
diff changeset
83 of the outgoing edges from the joiner block leads to a threadable path. This
kono
parents: 67
diff changeset
84 case largely works as outlined above, except the duplicate of the joiner
kono
parents: 67
diff changeset
85 block still contains a full set of outgoing edges and its control statement.
kono
parents: 67
diff changeset
86 We just redirect one of its outgoing edges to our jump threading path. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 /* Steps #5 and #6 of the above algorithm are best implemented by walking
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 all the incoming edges which thread to the same destination edge at
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 the same time. That avoids lots of table lookups to get information
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 for the destination edge.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 To realize that implementation we create a list of incoming edges
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 which thread to the same outgoing edge. Thus to implement steps
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 #5 and #6 we traverse our hash table of outgoing edge information.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 For each entry we walk the list of incoming edges which thread to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 the current outgoing edge. */
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 struct el
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 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 struct el *next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 /* Main data structure recording information regarding B's duplicate
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 blocks. */
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 /* We need to efficiently record the unique thread destinations of this
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 block and specific information associated with those destinations. We
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 may have many incoming edges threaded to the same outgoing edge. This
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 can be naturally implemented with a hash table. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
111
kono
parents: 67
diff changeset
114 struct redirection_data : free_ptr_hash<redirection_data>
kono
parents: 67
diff changeset
115 {
kono
parents: 67
diff changeset
116 /* We support wiring up two block duplicates in a jump threading path.
kono
parents: 67
diff changeset
117
kono
parents: 67
diff changeset
118 One is a normal block copy where we remove the control statement
kono
parents: 67
diff changeset
119 and wire up its single remaining outgoing edge to the thread path.
kono
parents: 67
diff changeset
120
kono
parents: 67
diff changeset
121 The other is a joiner block where we leave the control statement
kono
parents: 67
diff changeset
122 in place, but wire one of the outgoing edges to a thread path.
kono
parents: 67
diff changeset
123
kono
parents: 67
diff changeset
124 In theory we could have multiple block duplicates in a jump
kono
parents: 67
diff changeset
125 threading path, but I haven't tried that.
kono
parents: 67
diff changeset
126
kono
parents: 67
diff changeset
127 The duplicate blocks appear in this array in the same order in
kono
parents: 67
diff changeset
128 which they appear in the jump thread path. */
kono
parents: 67
diff changeset
129 basic_block dup_blocks[2];
kono
parents: 67
diff changeset
130
kono
parents: 67
diff changeset
131 /* The jump threading path. */
kono
parents: 67
diff changeset
132 vec<jump_thread_edge *> *path;
kono
parents: 67
diff changeset
133
kono
parents: 67
diff changeset
134 /* A list of incoming edges which we want to thread to the
kono
parents: 67
diff changeset
135 same path. */
kono
parents: 67
diff changeset
136 struct el *incoming_edges;
kono
parents: 67
diff changeset
137
kono
parents: 67
diff changeset
138 /* hash_table support. */
kono
parents: 67
diff changeset
139 static inline hashval_t hash (const redirection_data *);
kono
parents: 67
diff changeset
140 static inline int equal (const redirection_data *, const redirection_data *);
kono
parents: 67
diff changeset
141 };
kono
parents: 67
diff changeset
142
kono
parents: 67
diff changeset
143 /* Dump a jump threading path, including annotations about each
kono
parents: 67
diff changeset
144 edge in the path. */
kono
parents: 67
diff changeset
145
kono
parents: 67
diff changeset
146 static void
kono
parents: 67
diff changeset
147 dump_jump_thread_path (FILE *dump_file, vec<jump_thread_edge *> path,
kono
parents: 67
diff changeset
148 bool registering)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 {
111
kono
parents: 67
diff changeset
150 fprintf (dump_file,
kono
parents: 67
diff changeset
151 " %s%s jump thread: (%d, %d) incoming edge; ",
kono
parents: 67
diff changeset
152 (registering ? "Registering" : "Cancelling"),
kono
parents: 67
diff changeset
153 (path[0]->type == EDGE_FSM_THREAD ? " FSM": ""),
kono
parents: 67
diff changeset
154 path[0]->e->src->index, path[0]->e->dest->index);
kono
parents: 67
diff changeset
155
kono
parents: 67
diff changeset
156 for (unsigned int i = 1; i < path.length (); i++)
kono
parents: 67
diff changeset
157 {
kono
parents: 67
diff changeset
158 /* We can get paths with a NULL edge when the final destination
kono
parents: 67
diff changeset
159 of a jump thread turns out to be a constant address. We dump
kono
parents: 67
diff changeset
160 those paths when debugging, so we have to be prepared for that
kono
parents: 67
diff changeset
161 possibility here. */
kono
parents: 67
diff changeset
162 if (path[i]->e == NULL)
kono
parents: 67
diff changeset
163 continue;
kono
parents: 67
diff changeset
164
kono
parents: 67
diff changeset
165 if (path[i]->type == EDGE_COPY_SRC_JOINER_BLOCK)
kono
parents: 67
diff changeset
166 fprintf (dump_file, " (%d, %d) joiner; ",
kono
parents: 67
diff changeset
167 path[i]->e->src->index, path[i]->e->dest->index);
kono
parents: 67
diff changeset
168 if (path[i]->type == EDGE_COPY_SRC_BLOCK)
kono
parents: 67
diff changeset
169 fprintf (dump_file, " (%d, %d) normal;",
kono
parents: 67
diff changeset
170 path[i]->e->src->index, path[i]->e->dest->index);
kono
parents: 67
diff changeset
171 if (path[i]->type == EDGE_NO_COPY_SRC_BLOCK)
kono
parents: 67
diff changeset
172 fprintf (dump_file, " (%d, %d) nocopy;",
kono
parents: 67
diff changeset
173 path[i]->e->src->index, path[i]->e->dest->index);
kono
parents: 67
diff changeset
174 if (path[0]->type == EDGE_FSM_THREAD)
kono
parents: 67
diff changeset
175 fprintf (dump_file, " (%d, %d) ",
kono
parents: 67
diff changeset
176 path[i]->e->src->index, path[i]->e->dest->index);
kono
parents: 67
diff changeset
177 }
kono
parents: 67
diff changeset
178 fputc ('\n', dump_file);
kono
parents: 67
diff changeset
179 }
kono
parents: 67
diff changeset
180
kono
parents: 67
diff changeset
181 /* Simple hashing function. For any given incoming edge E, we're going
kono
parents: 67
diff changeset
182 to be most concerned with the final destination of its jump thread
kono
parents: 67
diff changeset
183 path. So hash on the block index of the final edge in the path. */
kono
parents: 67
diff changeset
184
kono
parents: 67
diff changeset
185 inline hashval_t
kono
parents: 67
diff changeset
186 redirection_data::hash (const redirection_data *p)
kono
parents: 67
diff changeset
187 {
kono
parents: 67
diff changeset
188 vec<jump_thread_edge *> *path = p->path;
kono
parents: 67
diff changeset
189 return path->last ()->e->dest->index;
kono
parents: 67
diff changeset
190 }
kono
parents: 67
diff changeset
191
kono
parents: 67
diff changeset
192 /* Given two hash table entries, return true if they have the same
kono
parents: 67
diff changeset
193 jump threading path. */
kono
parents: 67
diff changeset
194 inline int
kono
parents: 67
diff changeset
195 redirection_data::equal (const redirection_data *p1, const redirection_data *p2)
kono
parents: 67
diff changeset
196 {
kono
parents: 67
diff changeset
197 vec<jump_thread_edge *> *path1 = p1->path;
kono
parents: 67
diff changeset
198 vec<jump_thread_edge *> *path2 = p2->path;
kono
parents: 67
diff changeset
199
kono
parents: 67
diff changeset
200 if (path1->length () != path2->length ())
kono
parents: 67
diff changeset
201 return false;
kono
parents: 67
diff changeset
202
kono
parents: 67
diff changeset
203 for (unsigned int i = 1; i < path1->length (); i++)
kono
parents: 67
diff changeset
204 {
kono
parents: 67
diff changeset
205 if ((*path1)[i]->type != (*path2)[i]->type
kono
parents: 67
diff changeset
206 || (*path1)[i]->e != (*path2)[i]->e)
kono
parents: 67
diff changeset
207 return false;
kono
parents: 67
diff changeset
208 }
kono
parents: 67
diff changeset
209
kono
parents: 67
diff changeset
210 return true;
kono
parents: 67
diff changeset
211 }
kono
parents: 67
diff changeset
212
kono
parents: 67
diff changeset
213 /* Rather than search all the edges in jump thread paths each time
kono
parents: 67
diff changeset
214 DOM is able to simply if control statement, we build a hash table
kono
parents: 67
diff changeset
215 with the deleted edges. We only care about the address of the edge,
kono
parents: 67
diff changeset
216 not its contents. */
kono
parents: 67
diff changeset
217 struct removed_edges : nofree_ptr_hash<edge_def>
kono
parents: 67
diff changeset
218 {
kono
parents: 67
diff changeset
219 static hashval_t hash (edge e) { return htab_hash_pointer (e); }
kono
parents: 67
diff changeset
220 static bool equal (edge e1, edge e2) { return e1 == e2; }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
111
kono
parents: 67
diff changeset
223 static hash_table<removed_edges> *removed_edges;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 /* Data structure of information to pass to hash table traversal routines. */
111
kono
parents: 67
diff changeset
226 struct ssa_local_info_t
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 /* The current block we are working on. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230
111
kono
parents: 67
diff changeset
231 /* We only create a template block for the first duplicated block in a
kono
parents: 67
diff changeset
232 jump threading path as we may need many duplicates of that block.
kono
parents: 67
diff changeset
233
kono
parents: 67
diff changeset
234 The second duplicate block in a path is specific to that path. Creating
kono
parents: 67
diff changeset
235 and sharing a template for that block is considerably more difficult. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 basic_block template_block;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237
111
kono
parents: 67
diff changeset
238 /* Blocks duplicated for the thread. */
kono
parents: 67
diff changeset
239 bitmap duplicate_blocks;
kono
parents: 67
diff changeset
240
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 /* TRUE if we thread one or more jumps, FALSE otherwise. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 bool jumps_threaded;
111
kono
parents: 67
diff changeset
243
kono
parents: 67
diff changeset
244 /* When we have multiple paths through a joiner which reach different
kono
parents: 67
diff changeset
245 final destinations, then we may need to correct for potential
kono
parents: 67
diff changeset
246 profile insanities. */
kono
parents: 67
diff changeset
247 bool need_profile_correction;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 /* Passes which use the jump threading code register jump threading
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 opportunities as they are discovered. We keep the registered
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 jump threading opportunities in this vector as edge pairs
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 (original_edge, target_edge). */
111
kono
parents: 67
diff changeset
254 static vec<vec<jump_thread_edge *> *> paths;
kono
parents: 67
diff changeset
255
kono
parents: 67
diff changeset
256 /* When we start updating the CFG for threading, data necessary for jump
kono
parents: 67
diff changeset
257 threading is attached to the AUX field for the incoming edge. Use these
kono
parents: 67
diff changeset
258 macros to access the underlying structure attached to the AUX field. */
kono
parents: 67
diff changeset
259 #define THREAD_PATH(E) ((vec<jump_thread_edge *> *)(E)->aux)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 /* Jump threading statistics. */
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 struct thread_stats_d
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 unsigned long num_threaded_edges;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 struct thread_stats_d thread_stats;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 /* Remove the last statement in block BB if it is a control statement
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 Also remove all outgoing edges except the edge which reaches DEST_BB.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 If DEST_BB is NULL, then remove all outgoing edges. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
111
kono
parents: 67
diff changeset
275 void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 remove_ctrl_stmt_and_useless_edges (basic_block bb, basic_block dest_bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 gsi = gsi_last_bb (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 /* If the duplicate ends with a control statement, then remove it.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 Note that if we are duplicating the template block rather than the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 original basic block, then the duplicate might not have any real
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 statements in it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 if (!gsi_end_p (gsi)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 && gsi_stmt (gsi)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 && (gimple_code (gsi_stmt (gsi)) == GIMPLE_COND
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 || gimple_code (gsi_stmt (gsi)) == GIMPLE_GOTO
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 || gimple_code (gsi_stmt (gsi)) == GIMPLE_SWITCH))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 gsi_remove (&gsi, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 if (e->dest != dest_bb)
111
kono
parents: 67
diff changeset
299 {
kono
parents: 67
diff changeset
300 free_dom_edge_info (e);
kono
parents: 67
diff changeset
301 remove_edge (e);
kono
parents: 67
diff changeset
302 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 else
111
kono
parents: 67
diff changeset
304 {
kono
parents: 67
diff changeset
305 e->probability = profile_probability::always ();
kono
parents: 67
diff changeset
306 ei_next (&ei);
kono
parents: 67
diff changeset
307 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 }
111
kono
parents: 67
diff changeset
309
kono
parents: 67
diff changeset
310 /* If the remaining edge is a loop exit, there must have
kono
parents: 67
diff changeset
311 a removed edge that was not a loop exit.
kono
parents: 67
diff changeset
312
kono
parents: 67
diff changeset
313 In that case BB and possibly other blocks were previously
kono
parents: 67
diff changeset
314 in the loop, but are now outside the loop. Thus, we need
kono
parents: 67
diff changeset
315 to update the loop structures. */
kono
parents: 67
diff changeset
316 if (single_succ_p (bb)
kono
parents: 67
diff changeset
317 && loop_outer (bb->loop_father)
kono
parents: 67
diff changeset
318 && loop_exit_edge_p (bb->loop_father, single_succ_edge (bb)))
kono
parents: 67
diff changeset
319 loops_state_set (LOOPS_NEED_FIXUP);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321
111
kono
parents: 67
diff changeset
322 /* Create a duplicate of BB. Record the duplicate block in an array
kono
parents: 67
diff changeset
323 indexed by COUNT stored in RD. */
0
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 static void
111
kono
parents: 67
diff changeset
326 create_block_for_threading (basic_block bb,
kono
parents: 67
diff changeset
327 struct redirection_data *rd,
kono
parents: 67
diff changeset
328 unsigned int count,
kono
parents: 67
diff changeset
329 bitmap *duplicate_blocks)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 {
111
kono
parents: 67
diff changeset
331 edge_iterator ei;
kono
parents: 67
diff changeset
332 edge e;
kono
parents: 67
diff changeset
333
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 /* We can use the generic block duplication code and simply remove
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 the stuff we do not need. */
111
kono
parents: 67
diff changeset
336 rd->dup_blocks[count] = duplicate_block (bb, NULL, NULL);
kono
parents: 67
diff changeset
337
kono
parents: 67
diff changeset
338 FOR_EACH_EDGE (e, ei, rd->dup_blocks[count]->succs)
kono
parents: 67
diff changeset
339 e->aux = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 /* Zero out the profile, since the block is unreachable for now. */
111
kono
parents: 67
diff changeset
342 rd->dup_blocks[count]->frequency = 0;
kono
parents: 67
diff changeset
343 rd->dup_blocks[count]->count = profile_count::uninitialized ();
kono
parents: 67
diff changeset
344 if (duplicate_blocks)
kono
parents: 67
diff changeset
345 bitmap_set_bit (*duplicate_blocks, rd->dup_blocks[count]->index);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347
111
kono
parents: 67
diff changeset
348 /* Main data structure to hold information for duplicates of BB. */
kono
parents: 67
diff changeset
349
kono
parents: 67
diff changeset
350 static hash_table<redirection_data> *redirection_data;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 /* Given an outgoing edge E lookup and return its entry in our hash table.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 If INSERT is true, then we insert the entry into the hash table if
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 it is not already present. INCOMING_EDGE is added to the list of incoming
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 edges associated with E in the hash table. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 static struct redirection_data *
111
kono
parents: 67
diff changeset
359 lookup_redirection_data (edge e, enum insert_option insert)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 {
111
kono
parents: 67
diff changeset
361 struct redirection_data **slot;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 struct redirection_data *elt;
111
kono
parents: 67
diff changeset
363 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
364
kono
parents: 67
diff changeset
365 /* Build a hash table element so we can see if E is already
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 in the table. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 elt = XNEW (struct redirection_data);
111
kono
parents: 67
diff changeset
368 elt->path = path;
kono
parents: 67
diff changeset
369 elt->dup_blocks[0] = NULL;
kono
parents: 67
diff changeset
370 elt->dup_blocks[1] = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 elt->incoming_edges = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372
111
kono
parents: 67
diff changeset
373 slot = redirection_data->find_slot (elt, insert);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 /* This will only happen if INSERT is false and the entry is not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 in the hash table. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 if (slot == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 free (elt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 return NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 /* This will only happen if E was not in the hash table and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 INSERT is true. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 if (*slot == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 {
111
kono
parents: 67
diff changeset
387 *slot = elt;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 elt->incoming_edges = XNEW (struct el);
111
kono
parents: 67
diff changeset
389 elt->incoming_edges->e = e;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 elt->incoming_edges->next = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 return elt;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 /* E was in the hash table. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 /* Free ELT as we do not need it anymore, we will extract the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 relevant entry from the hash table itself. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 free (elt);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 /* Get the entry stored in the hash table. */
111
kono
parents: 67
diff changeset
401 elt = *slot;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 /* If insertion was requested, then we need to add INCOMING_EDGE
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 to the list of incoming edges associated with E. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 if (insert)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 {
111
kono
parents: 67
diff changeset
407 struct el *el = XNEW (struct el);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 el->next = elt->incoming_edges;
111
kono
parents: 67
diff changeset
409 el->e = e;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 elt->incoming_edges = el;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 return elt;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416
111
kono
parents: 67
diff changeset
417 /* Similar to copy_phi_args, except that the PHI arg exists, it just
kono
parents: 67
diff changeset
418 does not have a value associated with it. */
kono
parents: 67
diff changeset
419
kono
parents: 67
diff changeset
420 static void
kono
parents: 67
diff changeset
421 copy_phi_arg_into_existing_phi (edge src_e, edge tgt_e)
kono
parents: 67
diff changeset
422 {
kono
parents: 67
diff changeset
423 int src_idx = src_e->dest_idx;
kono
parents: 67
diff changeset
424 int tgt_idx = tgt_e->dest_idx;
kono
parents: 67
diff changeset
425
kono
parents: 67
diff changeset
426 /* Iterate over each PHI in e->dest. */
kono
parents: 67
diff changeset
427 for (gphi_iterator gsi = gsi_start_phis (src_e->dest),
kono
parents: 67
diff changeset
428 gsi2 = gsi_start_phis (tgt_e->dest);
kono
parents: 67
diff changeset
429 !gsi_end_p (gsi);
kono
parents: 67
diff changeset
430 gsi_next (&gsi), gsi_next (&gsi2))
kono
parents: 67
diff changeset
431 {
kono
parents: 67
diff changeset
432 gphi *src_phi = gsi.phi ();
kono
parents: 67
diff changeset
433 gphi *dest_phi = gsi2.phi ();
kono
parents: 67
diff changeset
434 tree val = gimple_phi_arg_def (src_phi, src_idx);
kono
parents: 67
diff changeset
435 source_location locus = gimple_phi_arg_location (src_phi, src_idx);
kono
parents: 67
diff changeset
436
kono
parents: 67
diff changeset
437 SET_PHI_ARG_DEF (dest_phi, tgt_idx, val);
kono
parents: 67
diff changeset
438 gimple_phi_arg_set_location (dest_phi, tgt_idx, locus);
kono
parents: 67
diff changeset
439 }
kono
parents: 67
diff changeset
440 }
kono
parents: 67
diff changeset
441
kono
parents: 67
diff changeset
442 /* Given ssa_name DEF, backtrack jump threading PATH from node IDX
kono
parents: 67
diff changeset
443 to see if it has constant value in a flow sensitive manner. Set
kono
parents: 67
diff changeset
444 LOCUS to location of the constant phi arg and return the value.
kono
parents: 67
diff changeset
445 Return DEF directly if either PATH or idx is ZERO. */
kono
parents: 67
diff changeset
446
kono
parents: 67
diff changeset
447 static tree
kono
parents: 67
diff changeset
448 get_value_locus_in_path (tree def, vec<jump_thread_edge *> *path,
kono
parents: 67
diff changeset
449 basic_block bb, int idx, source_location *locus)
kono
parents: 67
diff changeset
450 {
kono
parents: 67
diff changeset
451 tree arg;
kono
parents: 67
diff changeset
452 gphi *def_phi;
kono
parents: 67
diff changeset
453 basic_block def_bb;
kono
parents: 67
diff changeset
454
kono
parents: 67
diff changeset
455 if (path == NULL || idx == 0)
kono
parents: 67
diff changeset
456 return def;
kono
parents: 67
diff changeset
457
kono
parents: 67
diff changeset
458 def_phi = dyn_cast <gphi *> (SSA_NAME_DEF_STMT (def));
kono
parents: 67
diff changeset
459 if (!def_phi)
kono
parents: 67
diff changeset
460 return def;
kono
parents: 67
diff changeset
461
kono
parents: 67
diff changeset
462 def_bb = gimple_bb (def_phi);
kono
parents: 67
diff changeset
463 /* Don't propagate loop invariants into deeper loops. */
kono
parents: 67
diff changeset
464 if (!def_bb || bb_loop_depth (def_bb) < bb_loop_depth (bb))
kono
parents: 67
diff changeset
465 return def;
kono
parents: 67
diff changeset
466
kono
parents: 67
diff changeset
467 /* Backtrack jump threading path from IDX to see if def has constant
kono
parents: 67
diff changeset
468 value. */
kono
parents: 67
diff changeset
469 for (int j = idx - 1; j >= 0; j--)
kono
parents: 67
diff changeset
470 {
kono
parents: 67
diff changeset
471 edge e = (*path)[j]->e;
kono
parents: 67
diff changeset
472 if (e->dest == def_bb)
kono
parents: 67
diff changeset
473 {
kono
parents: 67
diff changeset
474 arg = gimple_phi_arg_def (def_phi, e->dest_idx);
kono
parents: 67
diff changeset
475 if (is_gimple_min_invariant (arg))
kono
parents: 67
diff changeset
476 {
kono
parents: 67
diff changeset
477 *locus = gimple_phi_arg_location (def_phi, e->dest_idx);
kono
parents: 67
diff changeset
478 return arg;
kono
parents: 67
diff changeset
479 }
kono
parents: 67
diff changeset
480 break;
kono
parents: 67
diff changeset
481 }
kono
parents: 67
diff changeset
482 }
kono
parents: 67
diff changeset
483
kono
parents: 67
diff changeset
484 return def;
kono
parents: 67
diff changeset
485 }
kono
parents: 67
diff changeset
486
kono
parents: 67
diff changeset
487 /* For each PHI in BB, copy the argument associated with SRC_E to TGT_E.
kono
parents: 67
diff changeset
488 Try to backtrack jump threading PATH from node IDX to see if the arg
kono
parents: 67
diff changeset
489 has constant value, copy constant value instead of argument itself
kono
parents: 67
diff changeset
490 if yes. */
kono
parents: 67
diff changeset
491
kono
parents: 67
diff changeset
492 static void
kono
parents: 67
diff changeset
493 copy_phi_args (basic_block bb, edge src_e, edge tgt_e,
kono
parents: 67
diff changeset
494 vec<jump_thread_edge *> *path, int idx)
kono
parents: 67
diff changeset
495 {
kono
parents: 67
diff changeset
496 gphi_iterator gsi;
kono
parents: 67
diff changeset
497 int src_indx = src_e->dest_idx;
kono
parents: 67
diff changeset
498
kono
parents: 67
diff changeset
499 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents: 67
diff changeset
500 {
kono
parents: 67
diff changeset
501 gphi *phi = gsi.phi ();
kono
parents: 67
diff changeset
502 tree def = gimple_phi_arg_def (phi, src_indx);
kono
parents: 67
diff changeset
503 source_location locus = gimple_phi_arg_location (phi, src_indx);
kono
parents: 67
diff changeset
504
kono
parents: 67
diff changeset
505 if (TREE_CODE (def) == SSA_NAME
kono
parents: 67
diff changeset
506 && !virtual_operand_p (gimple_phi_result (phi)))
kono
parents: 67
diff changeset
507 def = get_value_locus_in_path (def, path, bb, idx, &locus);
kono
parents: 67
diff changeset
508
kono
parents: 67
diff changeset
509 add_phi_arg (phi, def, tgt_e, locus);
kono
parents: 67
diff changeset
510 }
kono
parents: 67
diff changeset
511 }
kono
parents: 67
diff changeset
512
kono
parents: 67
diff changeset
513 /* We have recently made a copy of ORIG_BB, including its outgoing
kono
parents: 67
diff changeset
514 edges. The copy is NEW_BB. Every PHI node in every direct successor of
kono
parents: 67
diff changeset
515 ORIG_BB has a new argument associated with edge from NEW_BB to the
kono
parents: 67
diff changeset
516 successor. Initialize the PHI argument so that it is equal to the PHI
kono
parents: 67
diff changeset
517 argument associated with the edge from ORIG_BB to the successor.
kono
parents: 67
diff changeset
518 PATH and IDX are used to check if the new PHI argument has constant
kono
parents: 67
diff changeset
519 value in a flow sensitive manner. */
kono
parents: 67
diff changeset
520
kono
parents: 67
diff changeset
521 static void
kono
parents: 67
diff changeset
522 update_destination_phis (basic_block orig_bb, basic_block new_bb,
kono
parents: 67
diff changeset
523 vec<jump_thread_edge *> *path, int idx)
kono
parents: 67
diff changeset
524 {
kono
parents: 67
diff changeset
525 edge_iterator ei;
kono
parents: 67
diff changeset
526 edge e;
kono
parents: 67
diff changeset
527
kono
parents: 67
diff changeset
528 FOR_EACH_EDGE (e, ei, orig_bb->succs)
kono
parents: 67
diff changeset
529 {
kono
parents: 67
diff changeset
530 edge e2 = find_edge (new_bb, e->dest);
kono
parents: 67
diff changeset
531 copy_phi_args (e->dest, e, e2, path, idx);
kono
parents: 67
diff changeset
532 }
kono
parents: 67
diff changeset
533 }
kono
parents: 67
diff changeset
534
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 /* Given a duplicate block and its single destination (both stored
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 in RD). Create an edge between the duplicate and its single
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 destination.
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 Add an additional argument to any PHI nodes at the single
111
kono
parents: 67
diff changeset
540 destination. IDX is the start node in jump threading path
kono
parents: 67
diff changeset
541 we start to check to see if the new PHI argument has constant
kono
parents: 67
diff changeset
542 value along the jump threading path. */
0
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 static void
111
kono
parents: 67
diff changeset
545 create_edge_and_update_destination_phis (struct redirection_data *rd,
kono
parents: 67
diff changeset
546 basic_block bb, int idx)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 {
111
kono
parents: 67
diff changeset
548 edge e = make_single_succ_edge (bb, rd->path->last ()->e->dest, EDGE_FALLTHRU);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 rescan_loop_exit (e, true, false);
111
kono
parents: 67
diff changeset
551
kono
parents: 67
diff changeset
552 /* We used to copy the thread path here. That was added in 2007
kono
parents: 67
diff changeset
553 and dutifully updated through the representation changes in 2013.
kono
parents: 67
diff changeset
554
kono
parents: 67
diff changeset
555 In 2013 we added code to thread from an interior node through
kono
parents: 67
diff changeset
556 the backedge to another interior node. That runs after the code
kono
parents: 67
diff changeset
557 to thread through loop headers from outside the loop.
kono
parents: 67
diff changeset
558
kono
parents: 67
diff changeset
559 The latter may delete edges in the CFG, including those
kono
parents: 67
diff changeset
560 which appeared in the jump threading path we copied here. Thus
kono
parents: 67
diff changeset
561 we'd end up using a dangling pointer.
kono
parents: 67
diff changeset
562
kono
parents: 67
diff changeset
563 After reviewing the 2007/2011 code, I can't see how anything
kono
parents: 67
diff changeset
564 depended on copying the AUX field and clearly copying the jump
kono
parents: 67
diff changeset
565 threading path is problematical due to embedded edge pointers.
kono
parents: 67
diff changeset
566 It has been removed. */
kono
parents: 67
diff changeset
567 e->aux = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 /* If there are any PHI nodes at the destination of the outgoing edge
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 from the duplicate block, then we will need to add a new argument
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 to them. The argument should have the same value as the argument
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 associated with the outgoing edge stored in RD. */
111
kono
parents: 67
diff changeset
573 copy_phi_args (e->dest, rd->path->last ()->e, e, rd->path, idx);
kono
parents: 67
diff changeset
574 }
kono
parents: 67
diff changeset
575
kono
parents: 67
diff changeset
576 /* Look through PATH beginning at START and return TRUE if there are
kono
parents: 67
diff changeset
577 any additional blocks that need to be duplicated. Otherwise,
kono
parents: 67
diff changeset
578 return FALSE. */
kono
parents: 67
diff changeset
579 static bool
kono
parents: 67
diff changeset
580 any_remaining_duplicated_blocks (vec<jump_thread_edge *> *path,
kono
parents: 67
diff changeset
581 unsigned int start)
kono
parents: 67
diff changeset
582 {
kono
parents: 67
diff changeset
583 for (unsigned int i = start + 1; i < path->length (); i++)
kono
parents: 67
diff changeset
584 {
kono
parents: 67
diff changeset
585 if ((*path)[i]->type == EDGE_COPY_SRC_JOINER_BLOCK
kono
parents: 67
diff changeset
586 || (*path)[i]->type == EDGE_COPY_SRC_BLOCK)
kono
parents: 67
diff changeset
587 return true;
kono
parents: 67
diff changeset
588 }
kono
parents: 67
diff changeset
589 return false;
kono
parents: 67
diff changeset
590 }
kono
parents: 67
diff changeset
591
kono
parents: 67
diff changeset
592
kono
parents: 67
diff changeset
593 /* Compute the amount of profile count/frequency coming into the jump threading
kono
parents: 67
diff changeset
594 path stored in RD that we are duplicating, returned in PATH_IN_COUNT_PTR and
kono
parents: 67
diff changeset
595 PATH_IN_FREQ_PTR, as well as the amount of counts flowing out of the
kono
parents: 67
diff changeset
596 duplicated path, returned in PATH_OUT_COUNT_PTR. LOCAL_INFO is used to
kono
parents: 67
diff changeset
597 identify blocks duplicated for jump threading, which have duplicated
kono
parents: 67
diff changeset
598 edges that need to be ignored in the analysis. Return true if path contains
kono
parents: 67
diff changeset
599 a joiner, false otherwise.
kono
parents: 67
diff changeset
600
kono
parents: 67
diff changeset
601 In the non-joiner case, this is straightforward - all the counts/frequency
kono
parents: 67
diff changeset
602 flowing into the jump threading path should flow through the duplicated
kono
parents: 67
diff changeset
603 block and out of the duplicated path.
kono
parents: 67
diff changeset
604
kono
parents: 67
diff changeset
605 In the joiner case, it is very tricky. Some of the counts flowing into
kono
parents: 67
diff changeset
606 the original path go offpath at the joiner. The problem is that while
kono
parents: 67
diff changeset
607 we know how much total count goes off-path in the original control flow,
kono
parents: 67
diff changeset
608 we don't know how many of the counts corresponding to just the jump
kono
parents: 67
diff changeset
609 threading path go offpath at the joiner.
kono
parents: 67
diff changeset
610
kono
parents: 67
diff changeset
611 For example, assume we have the following control flow and identified
kono
parents: 67
diff changeset
612 jump threading paths:
kono
parents: 67
diff changeset
613
kono
parents: 67
diff changeset
614 A B C
kono
parents: 67
diff changeset
615 \ | /
kono
parents: 67
diff changeset
616 Ea \ |Eb / Ec
kono
parents: 67
diff changeset
617 \ | /
kono
parents: 67
diff changeset
618 v v v
kono
parents: 67
diff changeset
619 J <-- Joiner
kono
parents: 67
diff changeset
620 / \
kono
parents: 67
diff changeset
621 Eoff/ \Eon
kono
parents: 67
diff changeset
622 / \
kono
parents: 67
diff changeset
623 v v
kono
parents: 67
diff changeset
624 Soff Son <--- Normal
kono
parents: 67
diff changeset
625 /\
kono
parents: 67
diff changeset
626 Ed/ \ Ee
kono
parents: 67
diff changeset
627 / \
kono
parents: 67
diff changeset
628 v v
kono
parents: 67
diff changeset
629 D E
kono
parents: 67
diff changeset
630
kono
parents: 67
diff changeset
631 Jump threading paths: A -> J -> Son -> D (path 1)
kono
parents: 67
diff changeset
632 C -> J -> Son -> E (path 2)
kono
parents: 67
diff changeset
633
kono
parents: 67
diff changeset
634 Note that the control flow could be more complicated:
kono
parents: 67
diff changeset
635 - Each jump threading path may have more than one incoming edge. I.e. A and
kono
parents: 67
diff changeset
636 Ea could represent multiple incoming blocks/edges that are included in
kono
parents: 67
diff changeset
637 path 1.
kono
parents: 67
diff changeset
638 - There could be EDGE_NO_COPY_SRC_BLOCK edges after the joiner (either
kono
parents: 67
diff changeset
639 before or after the "normal" copy block). These are not duplicated onto
kono
parents: 67
diff changeset
640 the jump threading path, as they are single-successor.
kono
parents: 67
diff changeset
641 - Any of the blocks along the path may have other incoming edges that
kono
parents: 67
diff changeset
642 are not part of any jump threading path, but add profile counts along
kono
parents: 67
diff changeset
643 the path.
kono
parents: 67
diff changeset
644
kono
parents: 67
diff changeset
645 In the above example, after all jump threading is complete, we will
kono
parents: 67
diff changeset
646 end up with the following control flow:
kono
parents: 67
diff changeset
647
kono
parents: 67
diff changeset
648 A B C
kono
parents: 67
diff changeset
649 | | |
kono
parents: 67
diff changeset
650 Ea| |Eb |Ec
kono
parents: 67
diff changeset
651 | | |
kono
parents: 67
diff changeset
652 v v v
kono
parents: 67
diff changeset
653 Ja J Jc
kono
parents: 67
diff changeset
654 / \ / \Eon' / \
kono
parents: 67
diff changeset
655 Eona/ \ ---/---\-------- \Eonc
kono
parents: 67
diff changeset
656 / \ / / \ \
kono
parents: 67
diff changeset
657 v v v v v
kono
parents: 67
diff changeset
658 Sona Soff Son Sonc
kono
parents: 67
diff changeset
659 \ /\ /
kono
parents: 67
diff changeset
660 \___________ / \ _____/
kono
parents: 67
diff changeset
661 \ / \/
kono
parents: 67
diff changeset
662 vv v
kono
parents: 67
diff changeset
663 D E
kono
parents: 67
diff changeset
664
kono
parents: 67
diff changeset
665 The main issue to notice here is that when we are processing path 1
kono
parents: 67
diff changeset
666 (A->J->Son->D) we need to figure out the outgoing edge weights to
kono
parents: 67
diff changeset
667 the duplicated edges Ja->Sona and Ja->Soff, while ensuring that the
kono
parents: 67
diff changeset
668 sum of the incoming weights to D remain Ed. The problem with simply
kono
parents: 67
diff changeset
669 assuming that Ja (and Jc when processing path 2) has the same outgoing
kono
parents: 67
diff changeset
670 probabilities to its successors as the original block J, is that after
kono
parents: 67
diff changeset
671 all paths are processed and other edges/counts removed (e.g. none
kono
parents: 67
diff changeset
672 of Ec will reach D after processing path 2), we may end up with not
kono
parents: 67
diff changeset
673 enough count flowing along duplicated edge Sona->D.
kono
parents: 67
diff changeset
674
kono
parents: 67
diff changeset
675 Therefore, in the case of a joiner, we keep track of all counts
kono
parents: 67
diff changeset
676 coming in along the current path, as well as from predecessors not
kono
parents: 67
diff changeset
677 on any jump threading path (Eb in the above example). While we
kono
parents: 67
diff changeset
678 first assume that the duplicated Eona for Ja->Sona has the same
kono
parents: 67
diff changeset
679 probability as the original, we later compensate for other jump
kono
parents: 67
diff changeset
680 threading paths that may eliminate edges. We do that by keep track
kono
parents: 67
diff changeset
681 of all counts coming into the original path that are not in a jump
kono
parents: 67
diff changeset
682 thread (Eb in the above example, but as noted earlier, there could
kono
parents: 67
diff changeset
683 be other predecessors incoming to the path at various points, such
kono
parents: 67
diff changeset
684 as at Son). Call this cumulative non-path count coming into the path
kono
parents: 67
diff changeset
685 before D as Enonpath. We then ensure that the count from Sona->D is as at
kono
parents: 67
diff changeset
686 least as big as (Ed - Enonpath), but no bigger than the minimum
kono
parents: 67
diff changeset
687 weight along the jump threading path. The probabilities of both the
kono
parents: 67
diff changeset
688 original and duplicated joiner block J and Ja will be adjusted
kono
parents: 67
diff changeset
689 accordingly after the updates. */
kono
parents: 67
diff changeset
690
kono
parents: 67
diff changeset
691 static bool
kono
parents: 67
diff changeset
692 compute_path_counts (struct redirection_data *rd,
kono
parents: 67
diff changeset
693 ssa_local_info_t *local_info,
kono
parents: 67
diff changeset
694 profile_count *path_in_count_ptr,
kono
parents: 67
diff changeset
695 profile_count *path_out_count_ptr,
kono
parents: 67
diff changeset
696 int *path_in_freq_ptr)
kono
parents: 67
diff changeset
697 {
kono
parents: 67
diff changeset
698 edge e = rd->incoming_edges->e;
kono
parents: 67
diff changeset
699 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
700 edge elast = path->last ()->e;
kono
parents: 67
diff changeset
701 profile_count nonpath_count = profile_count::zero ();
kono
parents: 67
diff changeset
702 bool has_joiner = false;
kono
parents: 67
diff changeset
703 profile_count path_in_count = profile_count::zero ();
kono
parents: 67
diff changeset
704 int path_in_freq = 0;
kono
parents: 67
diff changeset
705
kono
parents: 67
diff changeset
706 /* Start by accumulating incoming edge counts to the path's first bb
kono
parents: 67
diff changeset
707 into a couple buckets:
kono
parents: 67
diff changeset
708 path_in_count: total count of incoming edges that flow into the
kono
parents: 67
diff changeset
709 current path.
kono
parents: 67
diff changeset
710 nonpath_count: total count of incoming edges that are not
kono
parents: 67
diff changeset
711 flowing along *any* path. These are the counts
kono
parents: 67
diff changeset
712 that will still flow along the original path after
kono
parents: 67
diff changeset
713 all path duplication is done by potentially multiple
kono
parents: 67
diff changeset
714 calls to this routine.
kono
parents: 67
diff changeset
715 (any other incoming edge counts are for a different jump threading
kono
parents: 67
diff changeset
716 path that will be handled by a later call to this routine.)
kono
parents: 67
diff changeset
717 To make this easier, start by recording all incoming edges that flow into
kono
parents: 67
diff changeset
718 the current path in a bitmap. We could add up the path's incoming edge
kono
parents: 67
diff changeset
719 counts here, but we still need to walk all the first bb's incoming edges
kono
parents: 67
diff changeset
720 below to add up the counts of the other edges not included in this jump
kono
parents: 67
diff changeset
721 threading path. */
kono
parents: 67
diff changeset
722 struct el *next, *el;
kono
parents: 67
diff changeset
723 auto_bitmap in_edge_srcs;
kono
parents: 67
diff changeset
724 for (el = rd->incoming_edges; el; el = next)
kono
parents: 67
diff changeset
725 {
kono
parents: 67
diff changeset
726 next = el->next;
kono
parents: 67
diff changeset
727 bitmap_set_bit (in_edge_srcs, el->e->src->index);
kono
parents: 67
diff changeset
728 }
kono
parents: 67
diff changeset
729 edge ein;
kono
parents: 67
diff changeset
730 edge_iterator ei;
kono
parents: 67
diff changeset
731 FOR_EACH_EDGE (ein, ei, e->dest->preds)
kono
parents: 67
diff changeset
732 {
kono
parents: 67
diff changeset
733 vec<jump_thread_edge *> *ein_path = THREAD_PATH (ein);
kono
parents: 67
diff changeset
734 /* Simply check the incoming edge src against the set captured above. */
kono
parents: 67
diff changeset
735 if (ein_path
kono
parents: 67
diff changeset
736 && bitmap_bit_p (in_edge_srcs, (*ein_path)[0]->e->src->index))
kono
parents: 67
diff changeset
737 {
kono
parents: 67
diff changeset
738 /* It is necessary but not sufficient that the last path edges
kono
parents: 67
diff changeset
739 are identical. There may be different paths that share the
kono
parents: 67
diff changeset
740 same last path edge in the case where the last edge has a nocopy
kono
parents: 67
diff changeset
741 source block. */
kono
parents: 67
diff changeset
742 gcc_assert (ein_path->last ()->e == elast);
kono
parents: 67
diff changeset
743 path_in_count += ein->count ();
kono
parents: 67
diff changeset
744 path_in_freq += EDGE_FREQUENCY (ein);
kono
parents: 67
diff changeset
745 }
kono
parents: 67
diff changeset
746 else if (!ein_path)
kono
parents: 67
diff changeset
747 {
kono
parents: 67
diff changeset
748 /* Keep track of the incoming edges that are not on any jump-threading
kono
parents: 67
diff changeset
749 path. These counts will still flow out of original path after all
kono
parents: 67
diff changeset
750 jump threading is complete. */
kono
parents: 67
diff changeset
751 nonpath_count += ein->count ();
kono
parents: 67
diff changeset
752 }
kono
parents: 67
diff changeset
753 }
kono
parents: 67
diff changeset
754
kono
parents: 67
diff changeset
755 /* This is needed due to insane incoming frequencies. */
kono
parents: 67
diff changeset
756 if (path_in_freq > BB_FREQ_MAX)
kono
parents: 67
diff changeset
757 path_in_freq = BB_FREQ_MAX;
kono
parents: 67
diff changeset
758
kono
parents: 67
diff changeset
759 /* Now compute the fraction of the total count coming into the first
kono
parents: 67
diff changeset
760 path bb that is from the current threading path. */
kono
parents: 67
diff changeset
761 profile_count total_count = e->dest->count;
kono
parents: 67
diff changeset
762 /* Handle incoming profile insanities. */
kono
parents: 67
diff changeset
763 if (total_count < path_in_count)
kono
parents: 67
diff changeset
764 path_in_count = total_count;
kono
parents: 67
diff changeset
765 profile_probability onpath_scale = path_in_count.probability_in (total_count);
kono
parents: 67
diff changeset
766
kono
parents: 67
diff changeset
767 /* Walk the entire path to do some more computation in order to estimate
kono
parents: 67
diff changeset
768 how much of the path_in_count will flow out of the duplicated threading
kono
parents: 67
diff changeset
769 path. In the non-joiner case this is straightforward (it should be
kono
parents: 67
diff changeset
770 the same as path_in_count, although we will handle incoming profile
kono
parents: 67
diff changeset
771 insanities by setting it equal to the minimum count along the path).
kono
parents: 67
diff changeset
772
kono
parents: 67
diff changeset
773 In the joiner case, we need to estimate how much of the path_in_count
kono
parents: 67
diff changeset
774 will stay on the threading path after the joiner's conditional branch.
kono
parents: 67
diff changeset
775 We don't really know for sure how much of the counts
kono
parents: 67
diff changeset
776 associated with this path go to each successor of the joiner, but we'll
kono
parents: 67
diff changeset
777 estimate based on the fraction of the total count coming into the path
kono
parents: 67
diff changeset
778 bb was from the threading paths (computed above in onpath_scale).
kono
parents: 67
diff changeset
779 Afterwards, we will need to do some fixup to account for other threading
kono
parents: 67
diff changeset
780 paths and possible profile insanities.
kono
parents: 67
diff changeset
781
kono
parents: 67
diff changeset
782 In order to estimate the joiner case's counts we also need to update
kono
parents: 67
diff changeset
783 nonpath_count with any additional counts coming into the path. Other
kono
parents: 67
diff changeset
784 blocks along the path may have additional predecessors from outside
kono
parents: 67
diff changeset
785 the path. */
kono
parents: 67
diff changeset
786 profile_count path_out_count = path_in_count;
kono
parents: 67
diff changeset
787 profile_count min_path_count = path_in_count;
kono
parents: 67
diff changeset
788 for (unsigned int i = 1; i < path->length (); i++)
kono
parents: 67
diff changeset
789 {
kono
parents: 67
diff changeset
790 edge epath = (*path)[i]->e;
kono
parents: 67
diff changeset
791 profile_count cur_count = epath->count ();
kono
parents: 67
diff changeset
792 if ((*path)[i]->type == EDGE_COPY_SRC_JOINER_BLOCK)
kono
parents: 67
diff changeset
793 {
kono
parents: 67
diff changeset
794 has_joiner = true;
kono
parents: 67
diff changeset
795 cur_count = cur_count.apply_probability (onpath_scale);
kono
parents: 67
diff changeset
796 }
kono
parents: 67
diff changeset
797 /* In the joiner case we need to update nonpath_count for any edges
kono
parents: 67
diff changeset
798 coming into the path that will contribute to the count flowing
kono
parents: 67
diff changeset
799 into the path successor. */
kono
parents: 67
diff changeset
800 if (has_joiner && epath != elast)
kono
parents: 67
diff changeset
801 {
kono
parents: 67
diff changeset
802 /* Look for other incoming edges after joiner. */
kono
parents: 67
diff changeset
803 FOR_EACH_EDGE (ein, ei, epath->dest->preds)
kono
parents: 67
diff changeset
804 {
kono
parents: 67
diff changeset
805 if (ein != epath
kono
parents: 67
diff changeset
806 /* Ignore in edges from blocks we have duplicated for a
kono
parents: 67
diff changeset
807 threading path, which have duplicated edge counts until
kono
parents: 67
diff changeset
808 they are redirected by an invocation of this routine. */
kono
parents: 67
diff changeset
809 && !bitmap_bit_p (local_info->duplicate_blocks,
kono
parents: 67
diff changeset
810 ein->src->index))
kono
parents: 67
diff changeset
811 nonpath_count += ein->count ();
kono
parents: 67
diff changeset
812 }
kono
parents: 67
diff changeset
813 }
kono
parents: 67
diff changeset
814 if (cur_count < path_out_count)
kono
parents: 67
diff changeset
815 path_out_count = cur_count;
kono
parents: 67
diff changeset
816 if (epath->count () < min_path_count)
kono
parents: 67
diff changeset
817 min_path_count = epath->count ();
kono
parents: 67
diff changeset
818 }
kono
parents: 67
diff changeset
819
kono
parents: 67
diff changeset
820 /* We computed path_out_count above assuming that this path targeted
kono
parents: 67
diff changeset
821 the joiner's on-path successor with the same likelihood as it
kono
parents: 67
diff changeset
822 reached the joiner. However, other thread paths through the joiner
kono
parents: 67
diff changeset
823 may take a different path through the normal copy source block
kono
parents: 67
diff changeset
824 (i.e. they have a different elast), meaning that they do not
kono
parents: 67
diff changeset
825 contribute any counts to this path's elast. As a result, it may
kono
parents: 67
diff changeset
826 turn out that this path must have more count flowing to the on-path
kono
parents: 67
diff changeset
827 successor of the joiner. Essentially, all of this path's elast
kono
parents: 67
diff changeset
828 count must be contributed by this path and any nonpath counts
kono
parents: 67
diff changeset
829 (since any path through the joiner with a different elast will not
kono
parents: 67
diff changeset
830 include a copy of this elast in its duplicated path).
kono
parents: 67
diff changeset
831 So ensure that this path's path_out_count is at least the
kono
parents: 67
diff changeset
832 difference between elast->count () and nonpath_count. Otherwise the edge
kono
parents: 67
diff changeset
833 counts after threading will not be sane. */
kono
parents: 67
diff changeset
834 if (local_info->need_profile_correction
kono
parents: 67
diff changeset
835 && has_joiner && path_out_count < elast->count () - nonpath_count)
kono
parents: 67
diff changeset
836 {
kono
parents: 67
diff changeset
837 path_out_count = elast->count () - nonpath_count;
kono
parents: 67
diff changeset
838 /* But neither can we go above the minimum count along the path
kono
parents: 67
diff changeset
839 we are duplicating. This can be an issue due to profile
kono
parents: 67
diff changeset
840 insanities coming in to this pass. */
kono
parents: 67
diff changeset
841 if (path_out_count > min_path_count)
kono
parents: 67
diff changeset
842 path_out_count = min_path_count;
kono
parents: 67
diff changeset
843 }
kono
parents: 67
diff changeset
844
kono
parents: 67
diff changeset
845 *path_in_count_ptr = path_in_count;
kono
parents: 67
diff changeset
846 *path_out_count_ptr = path_out_count;
kono
parents: 67
diff changeset
847 *path_in_freq_ptr = path_in_freq;
kono
parents: 67
diff changeset
848 return has_joiner;
kono
parents: 67
diff changeset
849 }
kono
parents: 67
diff changeset
850
kono
parents: 67
diff changeset
851
kono
parents: 67
diff changeset
852 /* Update the counts and frequencies for both an original path
kono
parents: 67
diff changeset
853 edge EPATH and its duplicate EDUP. The duplicate source block
kono
parents: 67
diff changeset
854 will get a count/frequency of PATH_IN_COUNT and PATH_IN_FREQ,
kono
parents: 67
diff changeset
855 and the duplicate edge EDUP will have a count of PATH_OUT_COUNT. */
kono
parents: 67
diff changeset
856 static void
kono
parents: 67
diff changeset
857 update_profile (edge epath, edge edup, profile_count path_in_count,
kono
parents: 67
diff changeset
858 profile_count path_out_count, int path_in_freq)
kono
parents: 67
diff changeset
859 {
kono
parents: 67
diff changeset
860 if (!(path_in_count > 0))
kono
parents: 67
diff changeset
861 return;
kono
parents: 67
diff changeset
862
kono
parents: 67
diff changeset
863 /* First update the duplicated block's count / frequency. */
kono
parents: 67
diff changeset
864 if (edup)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 {
111
kono
parents: 67
diff changeset
866 basic_block dup_block = edup->src;
kono
parents: 67
diff changeset
867
kono
parents: 67
diff changeset
868 /* Edup's count is reduced by path_out_count. We need to redistribute
kono
parents: 67
diff changeset
869 probabilities to the remaining edges. */
kono
parents: 67
diff changeset
870
kono
parents: 67
diff changeset
871 edge esucc;
kono
parents: 67
diff changeset
872 edge_iterator ei;
kono
parents: 67
diff changeset
873 profile_probability edup_prob
kono
parents: 67
diff changeset
874 = path_out_count.probability_in (path_in_count);
kono
parents: 67
diff changeset
875
kono
parents: 67
diff changeset
876 /* Either scale up or down the remaining edges.
kono
parents: 67
diff changeset
877 probabilities are always in range <0,1> and thus we can't do
kono
parents: 67
diff changeset
878 both by same loop. */
kono
parents: 67
diff changeset
879 if (edup->probability > edup_prob)
kono
parents: 67
diff changeset
880 {
kono
parents: 67
diff changeset
881 profile_probability rev_scale
kono
parents: 67
diff changeset
882 = (profile_probability::always () - edup->probability)
kono
parents: 67
diff changeset
883 / (profile_probability::always () - edup_prob);
kono
parents: 67
diff changeset
884 FOR_EACH_EDGE (esucc, ei, dup_block->succs)
kono
parents: 67
diff changeset
885 if (esucc != edup)
kono
parents: 67
diff changeset
886 esucc->probability /= rev_scale;
kono
parents: 67
diff changeset
887 }
kono
parents: 67
diff changeset
888 else if (edup->probability < edup_prob)
kono
parents: 67
diff changeset
889 {
kono
parents: 67
diff changeset
890 profile_probability scale
kono
parents: 67
diff changeset
891 = (profile_probability::always () - edup_prob)
kono
parents: 67
diff changeset
892 / (profile_probability::always () - edup->probability);
kono
parents: 67
diff changeset
893 FOR_EACH_EDGE (esucc, ei, dup_block->succs)
kono
parents: 67
diff changeset
894 if (esucc != edup)
kono
parents: 67
diff changeset
895 esucc->probability *= scale;
kono
parents: 67
diff changeset
896 }
kono
parents: 67
diff changeset
897 edup->probability = edup_prob;
kono
parents: 67
diff changeset
898
kono
parents: 67
diff changeset
899 /* FIXME once freqs_to_counts is dropped re-enable this check. */
kono
parents: 67
diff changeset
900 gcc_assert (!dup_block->count.initialized_p () || 1);
kono
parents: 67
diff changeset
901 gcc_assert (dup_block->frequency == 0);
kono
parents: 67
diff changeset
902 dup_block->count = path_in_count;
kono
parents: 67
diff changeset
903 dup_block->frequency = path_in_freq;
kono
parents: 67
diff changeset
904 }
kono
parents: 67
diff changeset
905
kono
parents: 67
diff changeset
906 profile_count final_count = epath->count () - path_out_count;
kono
parents: 67
diff changeset
907
kono
parents: 67
diff changeset
908 /* Now update the original block's count and frequency in the
kono
parents: 67
diff changeset
909 opposite manner - remove the counts/freq that will flow
kono
parents: 67
diff changeset
910 into the duplicated block. Handle underflow due to precision/
kono
parents: 67
diff changeset
911 rounding issues. */
kono
parents: 67
diff changeset
912 epath->src->count -= path_in_count;
kono
parents: 67
diff changeset
913 epath->src->frequency -= path_in_freq;
kono
parents: 67
diff changeset
914 if (epath->src->frequency < 0)
kono
parents: 67
diff changeset
915 epath->src->frequency = 0;
kono
parents: 67
diff changeset
916
kono
parents: 67
diff changeset
917 /* Next update this path edge's original and duplicated counts. We know
kono
parents: 67
diff changeset
918 that the duplicated path will have path_out_count flowing
kono
parents: 67
diff changeset
919 out of it (in the joiner case this is the count along the duplicated path
kono
parents: 67
diff changeset
920 out of the duplicated joiner). This count can then be removed from the
kono
parents: 67
diff changeset
921 original path edge. */
kono
parents: 67
diff changeset
922 if (epath->src->count > 0)
kono
parents: 67
diff changeset
923 {
kono
parents: 67
diff changeset
924 edge esucc;
kono
parents: 67
diff changeset
925 edge_iterator ei;
kono
parents: 67
diff changeset
926 profile_probability epath_prob = final_count.probability_in (epath->src->count);
kono
parents: 67
diff changeset
927
kono
parents: 67
diff changeset
928 if (epath->probability > epath_prob)
kono
parents: 67
diff changeset
929 {
kono
parents: 67
diff changeset
930 profile_probability rev_scale
kono
parents: 67
diff changeset
931 = (profile_probability::always () - epath->probability)
kono
parents: 67
diff changeset
932 / (profile_probability::always () - epath_prob);
kono
parents: 67
diff changeset
933 FOR_EACH_EDGE (esucc, ei, epath->src->succs)
kono
parents: 67
diff changeset
934 if (esucc != epath)
kono
parents: 67
diff changeset
935 esucc->probability /= rev_scale;
kono
parents: 67
diff changeset
936 }
kono
parents: 67
diff changeset
937 else if (epath->probability < epath_prob)
kono
parents: 67
diff changeset
938 {
kono
parents: 67
diff changeset
939 profile_probability scale
kono
parents: 67
diff changeset
940 = (profile_probability::always () - epath_prob)
kono
parents: 67
diff changeset
941 / (profile_probability::always () - epath->probability);
kono
parents: 67
diff changeset
942 FOR_EACH_EDGE (esucc, ei, epath->src->succs)
kono
parents: 67
diff changeset
943 if (esucc != epath)
kono
parents: 67
diff changeset
944 esucc->probability *= scale;
kono
parents: 67
diff changeset
945 }
kono
parents: 67
diff changeset
946 epath->probability = epath_prob;
kono
parents: 67
diff changeset
947 }
kono
parents: 67
diff changeset
948 }
kono
parents: 67
diff changeset
949
kono
parents: 67
diff changeset
950
kono
parents: 67
diff changeset
951 /* Check if the paths through RD all have estimated frequencies but zero
kono
parents: 67
diff changeset
952 profile counts. This is more accurate than checking the entry block
kono
parents: 67
diff changeset
953 for a zero profile count, since profile insanities sometimes creep in. */
kono
parents: 67
diff changeset
954
kono
parents: 67
diff changeset
955 static bool
kono
parents: 67
diff changeset
956 estimated_freqs_path (struct redirection_data *rd)
kono
parents: 67
diff changeset
957 {
kono
parents: 67
diff changeset
958 edge e = rd->incoming_edges->e;
kono
parents: 67
diff changeset
959 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
960 edge ein;
kono
parents: 67
diff changeset
961 edge_iterator ei;
kono
parents: 67
diff changeset
962 bool non_zero_freq = false;
kono
parents: 67
diff changeset
963 FOR_EACH_EDGE (ein, ei, e->dest->preds)
kono
parents: 67
diff changeset
964 {
kono
parents: 67
diff changeset
965 if (ein->count () > 0)
kono
parents: 67
diff changeset
966 return false;
kono
parents: 67
diff changeset
967 non_zero_freq |= ein->src->frequency != 0;
kono
parents: 67
diff changeset
968 }
kono
parents: 67
diff changeset
969
kono
parents: 67
diff changeset
970 for (unsigned int i = 1; i < path->length (); i++)
kono
parents: 67
diff changeset
971 {
kono
parents: 67
diff changeset
972 edge epath = (*path)[i]->e;
kono
parents: 67
diff changeset
973 if (epath->src->count > 0)
kono
parents: 67
diff changeset
974 return false;
kono
parents: 67
diff changeset
975 non_zero_freq |= epath->src->frequency != 0;
kono
parents: 67
diff changeset
976 edge esucc;
kono
parents: 67
diff changeset
977 FOR_EACH_EDGE (esucc, ei, epath->src->succs)
kono
parents: 67
diff changeset
978 {
kono
parents: 67
diff changeset
979 if (esucc->count () > 0)
kono
parents: 67
diff changeset
980 return false;
kono
parents: 67
diff changeset
981 non_zero_freq |= esucc->src->frequency != 0;
kono
parents: 67
diff changeset
982 }
kono
parents: 67
diff changeset
983 }
kono
parents: 67
diff changeset
984 return non_zero_freq;
kono
parents: 67
diff changeset
985 }
kono
parents: 67
diff changeset
986
kono
parents: 67
diff changeset
987
kono
parents: 67
diff changeset
988 /* Invoked for routines that have guessed frequencies and no profile
kono
parents: 67
diff changeset
989 counts to record the block and edge frequencies for paths through RD
kono
parents: 67
diff changeset
990 in the profile count fields of those blocks and edges. This is because
kono
parents: 67
diff changeset
991 ssa_fix_duplicate_block_edges incrementally updates the block and
kono
parents: 67
diff changeset
992 edge counts as edges are redirected, and it is difficult to do that
kono
parents: 67
diff changeset
993 for edge frequencies which are computed on the fly from the source
kono
parents: 67
diff changeset
994 block frequency and probability. When a block frequency is updated
kono
parents: 67
diff changeset
995 its outgoing edge frequencies are affected and become difficult to
kono
parents: 67
diff changeset
996 adjust. */
kono
parents: 67
diff changeset
997
kono
parents: 67
diff changeset
998 static void
kono
parents: 67
diff changeset
999 freqs_to_counts_path (struct redirection_data *rd)
kono
parents: 67
diff changeset
1000 {
kono
parents: 67
diff changeset
1001 edge e = rd->incoming_edges->e;
kono
parents: 67
diff changeset
1002 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
1003 edge ein;
kono
parents: 67
diff changeset
1004 edge_iterator ei;
kono
parents: 67
diff changeset
1005
kono
parents: 67
diff changeset
1006 FOR_EACH_EDGE (ein, ei, e->dest->preds)
kono
parents: 67
diff changeset
1007 ein->src->count = profile_count::from_gcov_type
kono
parents: 67
diff changeset
1008 (ein->src->frequency * REG_BR_PROB_BASE);
kono
parents: 67
diff changeset
1009 for (unsigned int i = 1; i < path->length (); i++)
kono
parents: 67
diff changeset
1010 {
kono
parents: 67
diff changeset
1011 edge epath = (*path)[i]->e;
kono
parents: 67
diff changeset
1012 /* Scale up the frequency by REG_BR_PROB_BASE, to avoid rounding
kono
parents: 67
diff changeset
1013 errors applying the edge probability when the frequencies are very
kono
parents: 67
diff changeset
1014 small. */
kono
parents: 67
diff changeset
1015 epath->src->count =
kono
parents: 67
diff changeset
1016 profile_count::from_gcov_type
kono
parents: 67
diff changeset
1017 (epath->src->frequency * REG_BR_PROB_BASE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1018 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020
111
kono
parents: 67
diff changeset
1021
kono
parents: 67
diff changeset
1022 /* For routines that have guessed frequencies and no profile counts, where we
kono
parents: 67
diff changeset
1023 used freqs_to_counts_path to record block and edge frequencies for paths
kono
parents: 67
diff changeset
1024 through RD, we clear the counts after completing all updates for RD.
kono
parents: 67
diff changeset
1025 The updates in ssa_fix_duplicate_block_edges are based off the count fields,
kono
parents: 67
diff changeset
1026 but the block frequencies and edge probabilities were updated as well,
kono
parents: 67
diff changeset
1027 so we can simply clear the count fields. */
kono
parents: 67
diff changeset
1028
kono
parents: 67
diff changeset
1029 static void
kono
parents: 67
diff changeset
1030 clear_counts_path (struct redirection_data *rd)
kono
parents: 67
diff changeset
1031 {
kono
parents: 67
diff changeset
1032 edge e = rd->incoming_edges->e;
kono
parents: 67
diff changeset
1033 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
1034 profile_count val = profile_count::uninitialized ();
kono
parents: 67
diff changeset
1035 if (profile_status_for_fn (cfun) == PROFILE_READ)
kono
parents: 67
diff changeset
1036 val = profile_count::zero ();
kono
parents: 67
diff changeset
1037
kono
parents: 67
diff changeset
1038 edge ein;
kono
parents: 67
diff changeset
1039 edge_iterator ei;
kono
parents: 67
diff changeset
1040
kono
parents: 67
diff changeset
1041 FOR_EACH_EDGE (ein, ei, e->dest->preds)
kono
parents: 67
diff changeset
1042 ein->src->count = val;
kono
parents: 67
diff changeset
1043
kono
parents: 67
diff changeset
1044 /* First clear counts along original path. */
kono
parents: 67
diff changeset
1045 for (unsigned int i = 1; i < path->length (); i++)
kono
parents: 67
diff changeset
1046 {
kono
parents: 67
diff changeset
1047 edge epath = (*path)[i]->e;
kono
parents: 67
diff changeset
1048 epath->src->count = val;
kono
parents: 67
diff changeset
1049 }
kono
parents: 67
diff changeset
1050 /* Also need to clear the counts along duplicated path. */
kono
parents: 67
diff changeset
1051 for (unsigned int i = 0; i < 2; i++)
kono
parents: 67
diff changeset
1052 {
kono
parents: 67
diff changeset
1053 basic_block dup = rd->dup_blocks[i];
kono
parents: 67
diff changeset
1054 if (!dup)
kono
parents: 67
diff changeset
1055 continue;
kono
parents: 67
diff changeset
1056 dup->count = val;
kono
parents: 67
diff changeset
1057 }
kono
parents: 67
diff changeset
1058 }
kono
parents: 67
diff changeset
1059
kono
parents: 67
diff changeset
1060 /* Wire up the outgoing edges from the duplicate blocks and
kono
parents: 67
diff changeset
1061 update any PHIs as needed. Also update the profile counts
kono
parents: 67
diff changeset
1062 on the original and duplicate blocks and edges. */
kono
parents: 67
diff changeset
1063 void
kono
parents: 67
diff changeset
1064 ssa_fix_duplicate_block_edges (struct redirection_data *rd,
kono
parents: 67
diff changeset
1065 ssa_local_info_t *local_info)
kono
parents: 67
diff changeset
1066 {
kono
parents: 67
diff changeset
1067 bool multi_incomings = (rd->incoming_edges->next != NULL);
kono
parents: 67
diff changeset
1068 edge e = rd->incoming_edges->e;
kono
parents: 67
diff changeset
1069 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
1070 edge elast = path->last ()->e;
kono
parents: 67
diff changeset
1071 profile_count path_in_count = profile_count::zero ();
kono
parents: 67
diff changeset
1072 profile_count path_out_count = profile_count::zero ();
kono
parents: 67
diff changeset
1073 int path_in_freq = 0;
kono
parents: 67
diff changeset
1074
kono
parents: 67
diff changeset
1075 /* This routine updates profile counts, frequencies, and probabilities
kono
parents: 67
diff changeset
1076 incrementally. Since it is difficult to do the incremental updates
kono
parents: 67
diff changeset
1077 using frequencies/probabilities alone, for routines without profile
kono
parents: 67
diff changeset
1078 data we first take a snapshot of the existing block and edge frequencies
kono
parents: 67
diff changeset
1079 by copying them into the empty profile count fields. These counts are
kono
parents: 67
diff changeset
1080 then used to do the incremental updates, and cleared at the end of this
kono
parents: 67
diff changeset
1081 routine. If the function is marked as having a profile, we still check
kono
parents: 67
diff changeset
1082 to see if the paths through RD are using estimated frequencies because
kono
parents: 67
diff changeset
1083 the routine had zero profile counts. */
kono
parents: 67
diff changeset
1084 bool do_freqs_to_counts = (profile_status_for_fn (cfun) != PROFILE_READ
kono
parents: 67
diff changeset
1085 || estimated_freqs_path (rd));
kono
parents: 67
diff changeset
1086 if (do_freqs_to_counts)
kono
parents: 67
diff changeset
1087 freqs_to_counts_path (rd);
kono
parents: 67
diff changeset
1088
kono
parents: 67
diff changeset
1089 /* First determine how much profile count to move from original
kono
parents: 67
diff changeset
1090 path to the duplicate path. This is tricky in the presence of
kono
parents: 67
diff changeset
1091 a joiner (see comments for compute_path_counts), where some portion
kono
parents: 67
diff changeset
1092 of the path's counts will flow off-path from the joiner. In the
kono
parents: 67
diff changeset
1093 non-joiner case the path_in_count and path_out_count should be the
kono
parents: 67
diff changeset
1094 same. */
kono
parents: 67
diff changeset
1095 bool has_joiner = compute_path_counts (rd, local_info,
kono
parents: 67
diff changeset
1096 &path_in_count, &path_out_count,
kono
parents: 67
diff changeset
1097 &path_in_freq);
kono
parents: 67
diff changeset
1098
kono
parents: 67
diff changeset
1099 int cur_path_freq = path_in_freq;
kono
parents: 67
diff changeset
1100 for (unsigned int count = 0, i = 1; i < path->length (); i++)
kono
parents: 67
diff changeset
1101 {
kono
parents: 67
diff changeset
1102 edge epath = (*path)[i]->e;
kono
parents: 67
diff changeset
1103
kono
parents: 67
diff changeset
1104 /* If we were threading through an joiner block, then we want
kono
parents: 67
diff changeset
1105 to keep its control statement and redirect an outgoing edge.
kono
parents: 67
diff changeset
1106 Else we want to remove the control statement & edges, then create
kono
parents: 67
diff changeset
1107 a new outgoing edge. In both cases we may need to update PHIs. */
kono
parents: 67
diff changeset
1108 if ((*path)[i]->type == EDGE_COPY_SRC_JOINER_BLOCK)
kono
parents: 67
diff changeset
1109 {
kono
parents: 67
diff changeset
1110 edge victim;
kono
parents: 67
diff changeset
1111 edge e2;
kono
parents: 67
diff changeset
1112
kono
parents: 67
diff changeset
1113 gcc_assert (has_joiner);
kono
parents: 67
diff changeset
1114
kono
parents: 67
diff changeset
1115 /* This updates the PHIs at the destination of the duplicate
kono
parents: 67
diff changeset
1116 block. Pass 0 instead of i if we are threading a path which
kono
parents: 67
diff changeset
1117 has multiple incoming edges. */
kono
parents: 67
diff changeset
1118 update_destination_phis (local_info->bb, rd->dup_blocks[count],
kono
parents: 67
diff changeset
1119 path, multi_incomings ? 0 : i);
kono
parents: 67
diff changeset
1120
kono
parents: 67
diff changeset
1121 /* Find the edge from the duplicate block to the block we're
kono
parents: 67
diff changeset
1122 threading through. That's the edge we want to redirect. */
kono
parents: 67
diff changeset
1123 victim = find_edge (rd->dup_blocks[count], (*path)[i]->e->dest);
kono
parents: 67
diff changeset
1124
kono
parents: 67
diff changeset
1125 /* If there are no remaining blocks on the path to duplicate,
kono
parents: 67
diff changeset
1126 then redirect VICTIM to the final destination of the jump
kono
parents: 67
diff changeset
1127 threading path. */
kono
parents: 67
diff changeset
1128 if (!any_remaining_duplicated_blocks (path, i))
kono
parents: 67
diff changeset
1129 {
kono
parents: 67
diff changeset
1130 e2 = redirect_edge_and_branch (victim, elast->dest);
kono
parents: 67
diff changeset
1131 /* If we redirected the edge, then we need to copy PHI arguments
kono
parents: 67
diff changeset
1132 at the target. If the edge already existed (e2 != victim
kono
parents: 67
diff changeset
1133 case), then the PHIs in the target already have the correct
kono
parents: 67
diff changeset
1134 arguments. */
kono
parents: 67
diff changeset
1135 if (e2 == victim)
kono
parents: 67
diff changeset
1136 copy_phi_args (e2->dest, elast, e2,
kono
parents: 67
diff changeset
1137 path, multi_incomings ? 0 : i);
kono
parents: 67
diff changeset
1138 }
kono
parents: 67
diff changeset
1139 else
kono
parents: 67
diff changeset
1140 {
kono
parents: 67
diff changeset
1141 /* Redirect VICTIM to the next duplicated block in the path. */
kono
parents: 67
diff changeset
1142 e2 = redirect_edge_and_branch (victim, rd->dup_blocks[count + 1]);
kono
parents: 67
diff changeset
1143
kono
parents: 67
diff changeset
1144 /* We need to update the PHIs in the next duplicated block. We
kono
parents: 67
diff changeset
1145 want the new PHI args to have the same value as they had
kono
parents: 67
diff changeset
1146 in the source of the next duplicate block.
kono
parents: 67
diff changeset
1147
kono
parents: 67
diff changeset
1148 Thus, we need to know which edge we traversed into the
kono
parents: 67
diff changeset
1149 source of the duplicate. Furthermore, we may have
kono
parents: 67
diff changeset
1150 traversed many edges to reach the source of the duplicate.
kono
parents: 67
diff changeset
1151
kono
parents: 67
diff changeset
1152 Walk through the path starting at element I until we
kono
parents: 67
diff changeset
1153 hit an edge marked with EDGE_COPY_SRC_BLOCK. We want
kono
parents: 67
diff changeset
1154 the edge from the prior element. */
kono
parents: 67
diff changeset
1155 for (unsigned int j = i + 1; j < path->length (); j++)
kono
parents: 67
diff changeset
1156 {
kono
parents: 67
diff changeset
1157 if ((*path)[j]->type == EDGE_COPY_SRC_BLOCK)
kono
parents: 67
diff changeset
1158 {
kono
parents: 67
diff changeset
1159 copy_phi_arg_into_existing_phi ((*path)[j - 1]->e, e2);
kono
parents: 67
diff changeset
1160 break;
kono
parents: 67
diff changeset
1161 }
kono
parents: 67
diff changeset
1162 }
kono
parents: 67
diff changeset
1163 }
kono
parents: 67
diff changeset
1164
kono
parents: 67
diff changeset
1165 /* Update the counts and frequency of both the original block
kono
parents: 67
diff changeset
1166 and path edge, and the duplicates. The path duplicate's
kono
parents: 67
diff changeset
1167 incoming count and frequency are the totals for all edges
kono
parents: 67
diff changeset
1168 incoming to this jump threading path computed earlier.
kono
parents: 67
diff changeset
1169 And we know that the duplicated path will have path_out_count
kono
parents: 67
diff changeset
1170 flowing out of it (i.e. along the duplicated path out of the
kono
parents: 67
diff changeset
1171 duplicated joiner). */
kono
parents: 67
diff changeset
1172 update_profile (epath, e2, path_in_count, path_out_count,
kono
parents: 67
diff changeset
1173 path_in_freq);
kono
parents: 67
diff changeset
1174
kono
parents: 67
diff changeset
1175 /* Record the frequency flowing to the downstream duplicated
kono
parents: 67
diff changeset
1176 path blocks. */
kono
parents: 67
diff changeset
1177 cur_path_freq = EDGE_FREQUENCY (e2);
kono
parents: 67
diff changeset
1178 }
kono
parents: 67
diff changeset
1179 else if ((*path)[i]->type == EDGE_COPY_SRC_BLOCK)
kono
parents: 67
diff changeset
1180 {
kono
parents: 67
diff changeset
1181 remove_ctrl_stmt_and_useless_edges (rd->dup_blocks[count], NULL);
kono
parents: 67
diff changeset
1182 create_edge_and_update_destination_phis (rd, rd->dup_blocks[count],
kono
parents: 67
diff changeset
1183 multi_incomings ? 0 : i);
kono
parents: 67
diff changeset
1184 if (count == 1)
kono
parents: 67
diff changeset
1185 single_succ_edge (rd->dup_blocks[1])->aux = NULL;
kono
parents: 67
diff changeset
1186
kono
parents: 67
diff changeset
1187 /* Update the counts and frequency of both the original block
kono
parents: 67
diff changeset
1188 and path edge, and the duplicates. Since we are now after
kono
parents: 67
diff changeset
1189 any joiner that may have existed on the path, the count
kono
parents: 67
diff changeset
1190 flowing along the duplicated threaded path is path_out_count.
kono
parents: 67
diff changeset
1191 If we didn't have a joiner, then cur_path_freq was the sum
kono
parents: 67
diff changeset
1192 of the total frequencies along all incoming edges to the
kono
parents: 67
diff changeset
1193 thread path (path_in_freq). If we had a joiner, it would have
kono
parents: 67
diff changeset
1194 been updated at the end of that handling to the edge frequency
kono
parents: 67
diff changeset
1195 along the duplicated joiner path edge. */
kono
parents: 67
diff changeset
1196 update_profile (epath, EDGE_SUCC (rd->dup_blocks[count], 0),
kono
parents: 67
diff changeset
1197 path_out_count, path_out_count, cur_path_freq);
kono
parents: 67
diff changeset
1198 }
kono
parents: 67
diff changeset
1199 else
kono
parents: 67
diff changeset
1200 {
kono
parents: 67
diff changeset
1201 /* No copy case. In this case we don't have an equivalent block
kono
parents: 67
diff changeset
1202 on the duplicated thread path to update, but we do need
kono
parents: 67
diff changeset
1203 to remove the portion of the counts/freqs that were moved
kono
parents: 67
diff changeset
1204 to the duplicated path from the counts/freqs flowing through
kono
parents: 67
diff changeset
1205 this block on the original path. Since all the no-copy edges
kono
parents: 67
diff changeset
1206 are after any joiner, the removed count is the same as
kono
parents: 67
diff changeset
1207 path_out_count.
kono
parents: 67
diff changeset
1208
kono
parents: 67
diff changeset
1209 If we didn't have a joiner, then cur_path_freq was the sum
kono
parents: 67
diff changeset
1210 of the total frequencies along all incoming edges to the
kono
parents: 67
diff changeset
1211 thread path (path_in_freq). If we had a joiner, it would have
kono
parents: 67
diff changeset
1212 been updated at the end of that handling to the edge frequency
kono
parents: 67
diff changeset
1213 along the duplicated joiner path edge. */
kono
parents: 67
diff changeset
1214 update_profile (epath, NULL, path_out_count, path_out_count,
kono
parents: 67
diff changeset
1215 cur_path_freq);
kono
parents: 67
diff changeset
1216 }
kono
parents: 67
diff changeset
1217
kono
parents: 67
diff changeset
1218 /* Increment the index into the duplicated path when we processed
kono
parents: 67
diff changeset
1219 a duplicated block. */
kono
parents: 67
diff changeset
1220 if ((*path)[i]->type == EDGE_COPY_SRC_JOINER_BLOCK
kono
parents: 67
diff changeset
1221 || (*path)[i]->type == EDGE_COPY_SRC_BLOCK)
kono
parents: 67
diff changeset
1222 {
kono
parents: 67
diff changeset
1223 count++;
kono
parents: 67
diff changeset
1224 }
kono
parents: 67
diff changeset
1225 }
kono
parents: 67
diff changeset
1226
kono
parents: 67
diff changeset
1227 /* Done with all profile and frequency updates, clear counts if they
kono
parents: 67
diff changeset
1228 were copied. */
kono
parents: 67
diff changeset
1229 if (do_freqs_to_counts)
kono
parents: 67
diff changeset
1230 clear_counts_path (rd);
kono
parents: 67
diff changeset
1231 }
kono
parents: 67
diff changeset
1232
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233 /* Hash table traversal callback routine to create duplicate blocks. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1234
111
kono
parents: 67
diff changeset
1235 int
kono
parents: 67
diff changeset
1236 ssa_create_duplicates (struct redirection_data **slot,
kono
parents: 67
diff changeset
1237 ssa_local_info_t *local_info)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1238 {
111
kono
parents: 67
diff changeset
1239 struct redirection_data *rd = *slot;
kono
parents: 67
diff changeset
1240
kono
parents: 67
diff changeset
1241 /* The second duplicated block in a jump threading path is specific
kono
parents: 67
diff changeset
1242 to the path. So it gets stored in RD rather than in LOCAL_DATA.
kono
parents: 67
diff changeset
1243
kono
parents: 67
diff changeset
1244 Each time we're called, we have to look through the path and see
kono
parents: 67
diff changeset
1245 if a second block needs to be duplicated.
kono
parents: 67
diff changeset
1246
kono
parents: 67
diff changeset
1247 Note the search starts with the third edge on the path. The first
kono
parents: 67
diff changeset
1248 edge is the incoming edge, the second edge always has its source
kono
parents: 67
diff changeset
1249 duplicated. Thus we start our search with the third edge. */
kono
parents: 67
diff changeset
1250 vec<jump_thread_edge *> *path = rd->path;
kono
parents: 67
diff changeset
1251 for (unsigned int i = 2; i < path->length (); i++)
kono
parents: 67
diff changeset
1252 {
kono
parents: 67
diff changeset
1253 if ((*path)[i]->type == EDGE_COPY_SRC_BLOCK
kono
parents: 67
diff changeset
1254 || (*path)[i]->type == EDGE_COPY_SRC_JOINER_BLOCK)
kono
parents: 67
diff changeset
1255 {
kono
parents: 67
diff changeset
1256 create_block_for_threading ((*path)[i]->e->src, rd, 1,
kono
parents: 67
diff changeset
1257 &local_info->duplicate_blocks);
kono
parents: 67
diff changeset
1258 break;
kono
parents: 67
diff changeset
1259 }
kono
parents: 67
diff changeset
1260 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1261
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262 /* Create a template block if we have not done so already. Otherwise
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1263 use the template to create a new block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 if (local_info->template_block == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265 {
111
kono
parents: 67
diff changeset
1266 create_block_for_threading ((*path)[1]->e->src, rd, 0,
kono
parents: 67
diff changeset
1267 &local_info->duplicate_blocks);
kono
parents: 67
diff changeset
1268 local_info->template_block = rd->dup_blocks[0];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1269
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 /* We do not create any outgoing edges for the template. We will
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1271 take care of that in a later traversal. That way we do not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1272 create edges that are going to just be deleted. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1275 {
111
kono
parents: 67
diff changeset
1276 create_block_for_threading (local_info->template_block, rd, 0,
kono
parents: 67
diff changeset
1277 &local_info->duplicate_blocks);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1278
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1279 /* Go ahead and wire up outgoing edges and update PHIs for the duplicate
111
kono
parents: 67
diff changeset
1280 block. */
kono
parents: 67
diff changeset
1281 ssa_fix_duplicate_block_edges (rd, local_info);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284 /* Keep walking the hash table. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1285 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 /* We did not create any outgoing edges for the template block during
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 block creation. This hash table traversal callback creates the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 outgoing edge for the template block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1291
111
kono
parents: 67
diff changeset
1292 inline int
kono
parents: 67
diff changeset
1293 ssa_fixup_template_block (struct redirection_data **slot,
kono
parents: 67
diff changeset
1294 ssa_local_info_t *local_info)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1295 {
111
kono
parents: 67
diff changeset
1296 struct redirection_data *rd = *slot;
kono
parents: 67
diff changeset
1297
kono
parents: 67
diff changeset
1298 /* If this is the template block halt the traversal after updating
kono
parents: 67
diff changeset
1299 it appropriately.
kono
parents: 67
diff changeset
1300
kono
parents: 67
diff changeset
1301 If we were threading through an joiner block, then we want
kono
parents: 67
diff changeset
1302 to keep its control statement and redirect an outgoing edge.
kono
parents: 67
diff changeset
1303 Else we want to remove the control statement & edges, then create
kono
parents: 67
diff changeset
1304 a new outgoing edge. In both cases we may need to update PHIs. */
kono
parents: 67
diff changeset
1305 if (rd->dup_blocks[0] && rd->dup_blocks[0] == local_info->template_block)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 {
111
kono
parents: 67
diff changeset
1307 ssa_fix_duplicate_block_edges (rd, local_info);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1309 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1312 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314 /* Hash table traversal callback to redirect each incoming edge
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1315 associated with this hash table element to its new destination. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1316
111
kono
parents: 67
diff changeset
1317 int
kono
parents: 67
diff changeset
1318 ssa_redirect_edges (struct redirection_data **slot,
kono
parents: 67
diff changeset
1319 ssa_local_info_t *local_info)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1320 {
111
kono
parents: 67
diff changeset
1321 struct redirection_data *rd = *slot;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1322 struct el *next, *el;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1323
111
kono
parents: 67
diff changeset
1324 /* Walk over all the incoming edges associated with this hash table
kono
parents: 67
diff changeset
1325 entry. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326 for (el = rd->incoming_edges; el; el = next)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 edge e = el->e;
111
kono
parents: 67
diff changeset
1329 vec<jump_thread_edge *> *path = THREAD_PATH (e);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1331 /* Go ahead and free this element from the list. Doing this now
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1332 avoids the need for another list walk when we destroy the hash
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1333 table. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1334 next = el->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1335 free (el);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1336
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1337 thread_stats.num_threaded_edges++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1338
111
kono
parents: 67
diff changeset
1339 if (rd->dup_blocks[0])
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1340 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 edge e2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1342
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1343 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1344 fprintf (dump_file, " Threaded jump %d --> %d to %d\n",
111
kono
parents: 67
diff changeset
1345 e->src->index, e->dest->index, rd->dup_blocks[0]->index);
kono
parents: 67
diff changeset
1346
kono
parents: 67
diff changeset
1347 /* Redirect the incoming edge (possibly to the joiner block) to the
kono
parents: 67
diff changeset
1348 appropriate duplicate block. */
kono
parents: 67
diff changeset
1349 e2 = redirect_edge_and_branch (e, rd->dup_blocks[0]);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1350 gcc_assert (e == e2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1351 flush_pending_stmts (e2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1352 }
111
kono
parents: 67
diff changeset
1353
kono
parents: 67
diff changeset
1354 /* Go ahead and clear E->aux. It's not needed anymore and failure
kono
parents: 67
diff changeset
1355 to clear it will cause all kinds of unpleasant problems later. */
kono
parents: 67
diff changeset
1356 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
1357 e->aux = NULL;
kono
parents: 67
diff changeset
1358
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1360
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361 /* Indicate that we actually threaded one or more jumps. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 if (rd->incoming_edges)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363 local_info->jumps_threaded = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1364
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1366 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1367
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1368 /* Return true if this block has no executable statements other than
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1369 a simple ctrl flow instruction. When the number of outgoing edges
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1370 is one, this is equivalent to a "forwarder" block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1371
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1372 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1373 redirection_block_p (basic_block bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1374 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1375 gimple_stmt_iterator gsi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1376
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1377 /* Advance to the first executable statement. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1378 gsi = gsi_start_bb (bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1379 while (!gsi_end_p (gsi)
111
kono
parents: 67
diff changeset
1380 && (gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1381 || is_gimple_debug (gsi_stmt (gsi))
111
kono
parents: 67
diff changeset
1382 || gimple_nop_p (gsi_stmt (gsi))
kono
parents: 67
diff changeset
1383 || gimple_clobber_p (gsi_stmt (gsi))))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1384 gsi_next (&gsi);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1385
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1386 /* Check if this is an empty block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1387 if (gsi_end_p (gsi))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1388 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1389
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1390 /* Test that we've reached the terminating control statement. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1391 return gsi_stmt (gsi)
111
kono
parents: 67
diff changeset
1392 && (gimple_code (gsi_stmt (gsi)) == GIMPLE_COND
kono
parents: 67
diff changeset
1393 || gimple_code (gsi_stmt (gsi)) == GIMPLE_GOTO
kono
parents: 67
diff changeset
1394 || gimple_code (gsi_stmt (gsi)) == GIMPLE_SWITCH);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1395 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1396
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1397 /* BB is a block which ends with a COND_EXPR or SWITCH_EXPR and when BB
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1398 is reached via one or more specific incoming edges, we know which
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1399 outgoing edge from BB will be traversed.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1400
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1401 We want to redirect those incoming edges to the target of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1402 appropriate outgoing edge. Doing so avoids a conditional branch
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1403 and may expose new optimization opportunities. Note that we have
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1404 to update dominator tree and SSA graph after such changes.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1405
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1406 The key to keeping the SSA graph update manageable is to duplicate
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1407 the side effects occurring in BB so that those side effects still
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1408 occur on the paths which bypass BB after redirecting edges.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1409
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1410 We accomplish this by creating duplicates of BB and arranging for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1411 the duplicates to unconditionally pass control to one specific
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1412 successor of BB. We then revector the incoming edges into BB to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1413 the appropriate duplicate of BB.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1414
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1415 If NOLOOP_ONLY is true, we only perform the threading as long as it
111
kono
parents: 67
diff changeset
1416 does not affect the structure of the loops in a nontrivial way.
kono
parents: 67
diff changeset
1417
kono
parents: 67
diff changeset
1418 If JOINERS is true, then thread through joiner blocks as well. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1420 static bool
111
kono
parents: 67
diff changeset
1421 thread_block_1 (basic_block bb, bool noloop_only, bool joiners)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1422 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1423 /* E is an incoming edge into BB that we may or may not want to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1424 redirect to a duplicate of BB. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1425 edge e, e2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1426 edge_iterator ei;
111
kono
parents: 67
diff changeset
1427 ssa_local_info_t local_info;
kono
parents: 67
diff changeset
1428
kono
parents: 67
diff changeset
1429 local_info.duplicate_blocks = BITMAP_ALLOC (NULL);
kono
parents: 67
diff changeset
1430 local_info.need_profile_correction = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1431
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1432 /* To avoid scanning a linear array for the element we need we instead
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1433 use a hash table. For normal code there should be no noticeable
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1434 difference. However, if we have a block with a large number of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1435 incoming and outgoing edges such linear searches can get expensive. */
111
kono
parents: 67
diff changeset
1436 redirection_data
kono
parents: 67
diff changeset
1437 = new hash_table<struct redirection_data> (EDGE_COUNT (bb->succs));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1438
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1439 /* Record each unique threaded destination into a hash table for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1440 efficient lookups. */
111
kono
parents: 67
diff changeset
1441 edge last = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1442 FOR_EACH_EDGE (e, ei, bb->preds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1443 {
111
kono
parents: 67
diff changeset
1444 if (e->aux == NULL)
kono
parents: 67
diff changeset
1445 continue;
kono
parents: 67
diff changeset
1446
kono
parents: 67
diff changeset
1447 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
1448
kono
parents: 67
diff changeset
1449 if (((*path)[1]->type == EDGE_COPY_SRC_JOINER_BLOCK && !joiners)
kono
parents: 67
diff changeset
1450 || ((*path)[1]->type == EDGE_COPY_SRC_BLOCK && joiners))
kono
parents: 67
diff changeset
1451 continue;
kono
parents: 67
diff changeset
1452
kono
parents: 67
diff changeset
1453 e2 = path->last ()->e;
kono
parents: 67
diff changeset
1454 if (!e2 || noloop_only)
kono
parents: 67
diff changeset
1455 {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1456 /* If NOLOOP_ONLY is true, we only allow threading through the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1457 header of a loop to exit edges. */
111
kono
parents: 67
diff changeset
1458
kono
parents: 67
diff changeset
1459 /* One case occurs when there was loop header buried in a jump
kono
parents: 67
diff changeset
1460 threading path that crosses loop boundaries. We do not try
kono
parents: 67
diff changeset
1461 and thread this elsewhere, so just cancel the jump threading
kono
parents: 67
diff changeset
1462 request by clearing the AUX field now. */
kono
parents: 67
diff changeset
1463 if (bb->loop_father != e2->src->loop_father
kono
parents: 67
diff changeset
1464 && !loop_exit_edge_p (e2->src->loop_father, e2))
kono
parents: 67
diff changeset
1465 {
kono
parents: 67
diff changeset
1466 /* Since this case is not handled by our special code
kono
parents: 67
diff changeset
1467 to thread through a loop header, we must explicitly
kono
parents: 67
diff changeset
1468 cancel the threading request here. */
kono
parents: 67
diff changeset
1469 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
1470 e->aux = NULL;
kono
parents: 67
diff changeset
1471 continue;
kono
parents: 67
diff changeset
1472 }
kono
parents: 67
diff changeset
1473
kono
parents: 67
diff changeset
1474 /* Another case occurs when trying to thread through our
kono
parents: 67
diff changeset
1475 own loop header, possibly from inside the loop. We will
kono
parents: 67
diff changeset
1476 thread these later. */
kono
parents: 67
diff changeset
1477 unsigned int i;
kono
parents: 67
diff changeset
1478 for (i = 1; i < path->length (); i++)
kono
parents: 67
diff changeset
1479 {
kono
parents: 67
diff changeset
1480 if ((*path)[i]->e->src == bb->loop_father->header
kono
parents: 67
diff changeset
1481 && (!loop_exit_edge_p (bb->loop_father, e2)
kono
parents: 67
diff changeset
1482 || (*path)[1]->type == EDGE_COPY_SRC_JOINER_BLOCK))
kono
parents: 67
diff changeset
1483 break;
kono
parents: 67
diff changeset
1484 }
kono
parents: 67
diff changeset
1485
kono
parents: 67
diff changeset
1486 if (i != path->length ())
kono
parents: 67
diff changeset
1487 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1488 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1489
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1490 /* Insert the outgoing edge into the hash table if it is not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1491 already in the hash table. */
111
kono
parents: 67
diff changeset
1492 lookup_redirection_data (e, INSERT);
kono
parents: 67
diff changeset
1493
kono
parents: 67
diff changeset
1494 /* When we have thread paths through a common joiner with different
kono
parents: 67
diff changeset
1495 final destinations, then we may need corrections to deal with
kono
parents: 67
diff changeset
1496 profile insanities. See the big comment before compute_path_counts. */
kono
parents: 67
diff changeset
1497 if ((*path)[1]->type == EDGE_COPY_SRC_JOINER_BLOCK)
kono
parents: 67
diff changeset
1498 {
kono
parents: 67
diff changeset
1499 if (!last)
kono
parents: 67
diff changeset
1500 last = e2;
kono
parents: 67
diff changeset
1501 else if (e2 != last)
kono
parents: 67
diff changeset
1502 local_info.need_profile_correction = true;
kono
parents: 67
diff changeset
1503 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1504 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1505
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1506 /* We do not update dominance info. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1507 free_dominance_info (CDI_DOMINATORS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1508
111
kono
parents: 67
diff changeset
1509 /* We know we only thread through the loop header to loop exits.
kono
parents: 67
diff changeset
1510 Let the basic block duplication hook know we are not creating
kono
parents: 67
diff changeset
1511 a multiple entry loop. */
kono
parents: 67
diff changeset
1512 if (noloop_only
kono
parents: 67
diff changeset
1513 && bb == bb->loop_father->header)
kono
parents: 67
diff changeset
1514 set_loop_copy (bb->loop_father, loop_outer (bb->loop_father));
kono
parents: 67
diff changeset
1515
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1516 /* Now create duplicates of BB.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1517
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1518 Note that for a block with a high outgoing degree we can waste
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1519 a lot of time and memory creating and destroying useless edges.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1520
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1521 So we first duplicate BB and remove the control structure at the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1522 tail of the duplicate as well as all outgoing edges from the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1523 duplicate. We then use that duplicate block as a template for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1524 the rest of the duplicates. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1525 local_info.template_block = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1526 local_info.bb = bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1527 local_info.jumps_threaded = false;
111
kono
parents: 67
diff changeset
1528 redirection_data->traverse <ssa_local_info_t *, ssa_create_duplicates>
kono
parents: 67
diff changeset
1529 (&local_info);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1530
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1531 /* The template does not have an outgoing edge. Create that outgoing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1532 edge and update PHI nodes as the edge's target as necessary.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1533
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1534 We do this after creating all the duplicates to avoid creating
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1535 unnecessary edges. */
111
kono
parents: 67
diff changeset
1536 redirection_data->traverse <ssa_local_info_t *, ssa_fixup_template_block>
kono
parents: 67
diff changeset
1537 (&local_info);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1538
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1539 /* The hash table traversals above created the duplicate blocks (and the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1540 statements within the duplicate blocks). This loop creates PHI nodes for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1541 the duplicated blocks and redirects the incoming edges into BB to reach
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1542 the duplicates of BB. */
111
kono
parents: 67
diff changeset
1543 redirection_data->traverse <ssa_local_info_t *, ssa_redirect_edges>
kono
parents: 67
diff changeset
1544 (&local_info);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1545
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1546 /* Done with this block. Clear REDIRECTION_DATA. */
111
kono
parents: 67
diff changeset
1547 delete redirection_data;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1548 redirection_data = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1549
111
kono
parents: 67
diff changeset
1550 if (noloop_only
kono
parents: 67
diff changeset
1551 && bb == bb->loop_father->header)
kono
parents: 67
diff changeset
1552 set_loop_copy (bb->loop_father, NULL);
kono
parents: 67
diff changeset
1553
kono
parents: 67
diff changeset
1554 BITMAP_FREE (local_info.duplicate_blocks);
kono
parents: 67
diff changeset
1555 local_info.duplicate_blocks = NULL;
kono
parents: 67
diff changeset
1556
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1557 /* Indicate to our caller whether or not any jumps were threaded. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1558 return local_info.jumps_threaded;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1559 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1560
111
kono
parents: 67
diff changeset
1561 /* Wrapper for thread_block_1 so that we can first handle jump
kono
parents: 67
diff changeset
1562 thread paths which do not involve copying joiner blocks, then
kono
parents: 67
diff changeset
1563 handle jump thread paths which have joiner blocks.
kono
parents: 67
diff changeset
1564
kono
parents: 67
diff changeset
1565 By doing things this way we can be as aggressive as possible and
kono
parents: 67
diff changeset
1566 not worry that copying a joiner block will create a jump threading
kono
parents: 67
diff changeset
1567 opportunity. */
kono
parents: 67
diff changeset
1568
kono
parents: 67
diff changeset
1569 static bool
kono
parents: 67
diff changeset
1570 thread_block (basic_block bb, bool noloop_only)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1571 {
111
kono
parents: 67
diff changeset
1572 bool retval;
kono
parents: 67
diff changeset
1573 retval = thread_block_1 (bb, noloop_only, false);
kono
parents: 67
diff changeset
1574 retval |= thread_block_1 (bb, noloop_only, true);
kono
parents: 67
diff changeset
1575 return retval;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1576 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1577
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1578 /* Callback for dfs_enumerate_from. Returns true if BB is different
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1579 from STOP and DBDS_CE_STOP. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1580
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1581 static basic_block dbds_ce_stop;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1582 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1583 dbds_continue_enumeration_p (const_basic_block bb, const void *stop)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1584 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1585 return (bb != (const_basic_block) stop
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1586 && bb != dbds_ce_stop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1587 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1588
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1589 /* Evaluates the dominance relationship of latch of the LOOP and BB, and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1590 returns the state. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1591
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1592 enum bb_dom_status
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1593 determine_bb_domination_status (struct loop *loop, basic_block bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1594 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1595 basic_block *bblocks;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1596 unsigned nblocks, i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1597 bool bb_reachable = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1598 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1599 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1600
111
kono
parents: 67
diff changeset
1601 /* This function assumes BB is a successor of LOOP->header.
kono
parents: 67
diff changeset
1602 If that is not the case return DOMST_NONDOMINATING which
kono
parents: 67
diff changeset
1603 is always safe. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1604 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1605 bool ok = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1606
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1607 FOR_EACH_EDGE (e, ei, bb->preds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1608 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1609 if (e->src == loop->header)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1610 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1611 ok = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1612 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1613 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1614 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1615
111
kono
parents: 67
diff changeset
1616 if (!ok)
kono
parents: 67
diff changeset
1617 return DOMST_NONDOMINATING;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1618 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1619
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1620 if (bb == loop->latch)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1621 return DOMST_DOMINATING;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1622
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1623 /* Check that BB dominates LOOP->latch, and that it is back-reachable
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1624 from it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1625
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1626 bblocks = XCNEWVEC (basic_block, loop->num_nodes);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1627 dbds_ce_stop = loop->header;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1628 nblocks = dfs_enumerate_from (loop->latch, 1, dbds_continue_enumeration_p,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1629 bblocks, loop->num_nodes, bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1630 for (i = 0; i < nblocks; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1631 FOR_EACH_EDGE (e, ei, bblocks[i]->preds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1632 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1633 if (e->src == loop->header)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1634 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1635 free (bblocks);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1636 return DOMST_NONDOMINATING;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1637 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1638 if (e->src == bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1639 bb_reachable = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1640 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1641
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1642 free (bblocks);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1643 return (bb_reachable ? DOMST_DOMINATING : DOMST_LOOP_BROKEN);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1644 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1645
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1646 /* Thread jumps through the header of LOOP. Returns true if cfg changes.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1647 If MAY_PEEL_LOOP_HEADERS is false, we avoid threading from entry edges
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1648 to the inside of the loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1649
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1650 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1651 thread_through_loop_header (struct loop *loop, bool may_peel_loop_headers)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1652 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1653 basic_block header = loop->header;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1654 edge e, tgt_edge, latch = loop_latch_edge (loop);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1655 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1656 basic_block tgt_bb, atgt_bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1657 enum bb_dom_status domst;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1658
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1659 /* We have already threaded through headers to exits, so all the threading
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1660 requests now are to the inside of the loop. We need to avoid creating
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1661 irreducible regions (i.e., loops with more than one entry block), and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1662 also loop with several latch edges, or new subloops of the loop (although
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1663 there are cases where it might be appropriate, it is difficult to decide,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1664 and doing it wrongly may confuse other optimizers).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1665
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1666 We could handle more general cases here. However, the intention is to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1667 preserve some information about the loop, which is impossible if its
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1668 structure changes significantly, in a way that is not well understood.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1669 Thus we only handle few important special cases, in which also updating
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1670 of the loop-carried information should be feasible:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1671
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1672 1) Propagation of latch edge to a block that dominates the latch block
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1673 of a loop. This aims to handle the following idiom:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1674
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1675 first = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1676 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1677 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1678 if (first)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1679 initialize;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1680 first = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1681 body;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1682 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1683
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1684 After threading the latch edge, this becomes
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1685
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1686 first = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1687 if (first)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1688 initialize;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1689 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1690 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1691 first = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1692 body;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1693 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1694
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1695 The original header of the loop is moved out of it, and we may thread
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1696 the remaining edges through it without further constraints.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1697
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1698 2) All entry edges are propagated to a single basic block that dominates
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1699 the latch block of the loop. This aims to handle the following idiom
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1700 (normally created for "for" loops):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1701
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1702 i = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1703 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1704 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1705 if (i >= 100)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1706 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1707 body;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1708 i++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1709 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1710
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1711 This becomes
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1712
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1713 i = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1714 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1715 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1716 body;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1717 i++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1718 if (i >= 100)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1719 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1720 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1721 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1722
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1723 /* Threading through the header won't improve the code if the header has just
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1724 one successor. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1725 if (single_succ_p (header))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1726 goto fail;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1727
111
kono
parents: 67
diff changeset
1728 if (!may_peel_loop_headers && !redirection_block_p (loop->header))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1729 goto fail;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1730 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1731 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1732 tgt_bb = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1733 tgt_edge = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1734 FOR_EACH_EDGE (e, ei, header->preds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1735 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1736 if (!e->aux)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1737 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1738 if (e == latch)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1739 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1740
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1741 /* If latch is not threaded, and there is a header
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1742 edge that is not threaded, we would create loop
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1743 with multiple entries. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1744 goto fail;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1745 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1746
111
kono
parents: 67
diff changeset
1747 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
1748
kono
parents: 67
diff changeset
1749 if ((*path)[1]->type == EDGE_COPY_SRC_JOINER_BLOCK)
kono
parents: 67
diff changeset
1750 goto fail;
kono
parents: 67
diff changeset
1751 tgt_edge = (*path)[1]->e;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1752 atgt_bb = tgt_edge->dest;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1753 if (!tgt_bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1754 tgt_bb = atgt_bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1755 /* Two targets of threading would make us create loop
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1756 with multiple entries. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1757 else if (tgt_bb != atgt_bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1758 goto fail;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1759 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1760
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1761 if (!tgt_bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1762 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1763 /* There are no threading requests. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1764 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1765 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1766
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1767 /* Redirecting to empty loop latch is useless. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1768 if (tgt_bb == loop->latch
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1769 && empty_block_p (loop->latch))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1770 goto fail;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1771 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1772
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1773 /* The target block must dominate the loop latch, otherwise we would be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1774 creating a subloop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1775 domst = determine_bb_domination_status (loop, tgt_bb);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1776 if (domst == DOMST_NONDOMINATING)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1777 goto fail;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1778 if (domst == DOMST_LOOP_BROKEN)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1779 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1780 /* If the loop ceased to exist, mark it as such, and thread through its
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1781 original header. */
111
kono
parents: 67
diff changeset
1782 mark_loop_for_removal (loop);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1783 return thread_block (header, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1784 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1785
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1786 if (tgt_bb->loop_father->header == tgt_bb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1787 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1788 /* If the target of the threading is a header of a subloop, we need
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1789 to create a preheader for it, so that the headers of the two loops
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1790 do not merge. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1791 if (EDGE_COUNT (tgt_bb->preds) > 2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1792 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1793 tgt_bb = create_preheader (tgt_bb->loop_father, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1794 gcc_assert (tgt_bb != NULL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1795 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1796 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1797 tgt_bb = split_edge (tgt_edge);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1798 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1799
111
kono
parents: 67
diff changeset
1800 basic_block new_preheader;
kono
parents: 67
diff changeset
1801
kono
parents: 67
diff changeset
1802 /* Now consider the case entry edges are redirected to the new entry
kono
parents: 67
diff changeset
1803 block. Remember one entry edge, so that we can find the new
kono
parents: 67
diff changeset
1804 preheader (its destination after threading). */
kono
parents: 67
diff changeset
1805 FOR_EACH_EDGE (e, ei, header->preds)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1806 {
111
kono
parents: 67
diff changeset
1807 if (e->aux)
kono
parents: 67
diff changeset
1808 break;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1809 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1810
111
kono
parents: 67
diff changeset
1811 /* The duplicate of the header is the new preheader of the loop. Ensure
kono
parents: 67
diff changeset
1812 that it is placed correctly in the loop hierarchy. */
kono
parents: 67
diff changeset
1813 set_loop_copy (loop, loop_outer (loop));
kono
parents: 67
diff changeset
1814
kono
parents: 67
diff changeset
1815 thread_block (header, false);
kono
parents: 67
diff changeset
1816 set_loop_copy (loop, NULL);
kono
parents: 67
diff changeset
1817 new_preheader = e->dest;
kono
parents: 67
diff changeset
1818
kono
parents: 67
diff changeset
1819 /* Create the new latch block. This is always necessary, as the latch
kono
parents: 67
diff changeset
1820 must have only a single successor, but the original header had at
kono
parents: 67
diff changeset
1821 least two successors. */
kono
parents: 67
diff changeset
1822 loop->latch = NULL;
kono
parents: 67
diff changeset
1823 mfb_kj_edge = single_succ_edge (new_preheader);
kono
parents: 67
diff changeset
1824 loop->header = mfb_kj_edge->dest;
kono
parents: 67
diff changeset
1825 latch = make_forwarder_block (tgt_bb, mfb_keep_just, NULL);
kono
parents: 67
diff changeset
1826 loop->header = latch->dest;
kono
parents: 67
diff changeset
1827 loop->latch = latch->src;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1828 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1829
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1830 fail:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1831 /* We failed to thread anything. Cancel the requests. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1832 FOR_EACH_EDGE (e, ei, header->preds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1833 {
111
kono
parents: 67
diff changeset
1834 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
1835
kono
parents: 67
diff changeset
1836 if (path)
kono
parents: 67
diff changeset
1837 {
kono
parents: 67
diff changeset
1838 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
1839 e->aux = NULL;
kono
parents: 67
diff changeset
1840 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1841 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1842 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1843 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1844
111
kono
parents: 67
diff changeset
1845 /* E1 and E2 are edges into the same basic block. Return TRUE if the
kono
parents: 67
diff changeset
1846 PHI arguments associated with those edges are equal or there are no
kono
parents: 67
diff changeset
1847 PHI arguments, otherwise return FALSE. */
kono
parents: 67
diff changeset
1848
kono
parents: 67
diff changeset
1849 static bool
kono
parents: 67
diff changeset
1850 phi_args_equal_on_edges (edge e1, edge e2)
kono
parents: 67
diff changeset
1851 {
kono
parents: 67
diff changeset
1852 gphi_iterator gsi;
kono
parents: 67
diff changeset
1853 int indx1 = e1->dest_idx;
kono
parents: 67
diff changeset
1854 int indx2 = e2->dest_idx;
kono
parents: 67
diff changeset
1855
kono
parents: 67
diff changeset
1856 for (gsi = gsi_start_phis (e1->dest); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents: 67
diff changeset
1857 {
kono
parents: 67
diff changeset
1858 gphi *phi = gsi.phi ();
kono
parents: 67
diff changeset
1859
kono
parents: 67
diff changeset
1860 if (!operand_equal_p (gimple_phi_arg_def (phi, indx1),
kono
parents: 67
diff changeset
1861 gimple_phi_arg_def (phi, indx2), 0))
kono
parents: 67
diff changeset
1862 return false;
kono
parents: 67
diff changeset
1863 }
kono
parents: 67
diff changeset
1864 return true;
kono
parents: 67
diff changeset
1865 }
kono
parents: 67
diff changeset
1866
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1867 /* Walk through the registered jump threads and convert them into a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1868 form convenient for this pass.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1869
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1870 Any block which has incoming edges threaded to outgoing edges
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1871 will have its entry in THREADED_BLOCK set.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1872
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1873 Any threaded edge will have its new outgoing edge stored in the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1874 original edge's AUX field.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1875
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1876 This form avoids the need to walk all the edges in the CFG to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1877 discover blocks which need processing and avoids unnecessary
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1878 hash table lookups to map from threaded edge to new target. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1879
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1880 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1881 mark_threaded_blocks (bitmap threaded_blocks)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1882 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1883 unsigned int i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1884 bitmap_iterator bi;
111
kono
parents: 67
diff changeset
1885 auto_bitmap tmp;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1886 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1887 edge e;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1888 edge_iterator ei;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1889
111
kono
parents: 67
diff changeset
1890 /* It is possible to have jump threads in which one is a subpath
kono
parents: 67
diff changeset
1891 of the other. ie, (A, B), (B, C), (C, D) where B is a joiner
kono
parents: 67
diff changeset
1892 block and (B, C), (C, D) where no joiner block exists.
kono
parents: 67
diff changeset
1893
kono
parents: 67
diff changeset
1894 When this occurs ignore the jump thread request with the joiner
kono
parents: 67
diff changeset
1895 block. It's totally subsumed by the simpler jump thread request.
kono
parents: 67
diff changeset
1896
kono
parents: 67
diff changeset
1897 This results in less block copying, simpler CFGs. More importantly,
kono
parents: 67
diff changeset
1898 when we duplicate the joiner block, B, in this case we will create
kono
parents: 67
diff changeset
1899 a new threading opportunity that we wouldn't be able to optimize
kono
parents: 67
diff changeset
1900 until the next jump threading iteration.
kono
parents: 67
diff changeset
1901
kono
parents: 67
diff changeset
1902 So first convert the jump thread requests which do not require a
kono
parents: 67
diff changeset
1903 joiner block. */
kono
parents: 67
diff changeset
1904 for (i = 0; i < paths.length (); i++)
kono
parents: 67
diff changeset
1905 {
kono
parents: 67
diff changeset
1906 vec<jump_thread_edge *> *path = paths[i];
kono
parents: 67
diff changeset
1907
kono
parents: 67
diff changeset
1908 if ((*path)[1]->type != EDGE_COPY_SRC_JOINER_BLOCK)
kono
parents: 67
diff changeset
1909 {
kono
parents: 67
diff changeset
1910 edge e = (*path)[0]->e;
kono
parents: 67
diff changeset
1911 e->aux = (void *)path;
kono
parents: 67
diff changeset
1912 bitmap_set_bit (tmp, e->dest->index);
kono
parents: 67
diff changeset
1913 }
kono
parents: 67
diff changeset
1914 }
kono
parents: 67
diff changeset
1915
kono
parents: 67
diff changeset
1916 /* Now iterate again, converting cases where we want to thread
kono
parents: 67
diff changeset
1917 through a joiner block, but only if no other edge on the path
kono
parents: 67
diff changeset
1918 already has a jump thread attached to it. We do this in two passes,
kono
parents: 67
diff changeset
1919 to avoid situations where the order in the paths vec can hide overlapping
kono
parents: 67
diff changeset
1920 threads (the path is recorded on the incoming edge, so we would miss
kono
parents: 67
diff changeset
1921 cases where the second path starts at a downstream edge on the same
kono
parents: 67
diff changeset
1922 path). First record all joiner paths, deleting any in the unexpected
kono
parents: 67
diff changeset
1923 case where there is already a path for that incoming edge. */
kono
parents: 67
diff changeset
1924 for (i = 0; i < paths.length ();)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1925 {
111
kono
parents: 67
diff changeset
1926 vec<jump_thread_edge *> *path = paths[i];
kono
parents: 67
diff changeset
1927
kono
parents: 67
diff changeset
1928 if ((*path)[1]->type == EDGE_COPY_SRC_JOINER_BLOCK)
kono
parents: 67
diff changeset
1929 {
kono
parents: 67
diff changeset
1930 /* Attach the path to the starting edge if none is yet recorded. */
kono
parents: 67
diff changeset
1931 if ((*path)[0]->e->aux == NULL)
kono
parents: 67
diff changeset
1932 {
kono
parents: 67
diff changeset
1933 (*path)[0]->e->aux = path;
kono
parents: 67
diff changeset
1934 i++;
kono
parents: 67
diff changeset
1935 }
kono
parents: 67
diff changeset
1936 else
kono
parents: 67
diff changeset
1937 {
kono
parents: 67
diff changeset
1938 paths.unordered_remove (i);
kono
parents: 67
diff changeset
1939 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
1940 dump_jump_thread_path (dump_file, *path, false);
kono
parents: 67
diff changeset
1941 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
1942 }
kono
parents: 67
diff changeset
1943 }
kono
parents: 67
diff changeset
1944 else
kono
parents: 67
diff changeset
1945 {
kono
parents: 67
diff changeset
1946 i++;
kono
parents: 67
diff changeset
1947 }
kono
parents: 67
diff changeset
1948 }
kono
parents: 67
diff changeset
1949
kono
parents: 67
diff changeset
1950 /* Second, look for paths that have any other jump thread attached to
kono
parents: 67
diff changeset
1951 them, and either finish converting them or cancel them. */
kono
parents: 67
diff changeset
1952 for (i = 0; i < paths.length ();)
kono
parents: 67
diff changeset
1953 {
kono
parents: 67
diff changeset
1954 vec<jump_thread_edge *> *path = paths[i];
kono
parents: 67
diff changeset
1955 edge e = (*path)[0]->e;
kono
parents: 67
diff changeset
1956
kono
parents: 67
diff changeset
1957 if ((*path)[1]->type == EDGE_COPY_SRC_JOINER_BLOCK && e->aux == path)
kono
parents: 67
diff changeset
1958 {
kono
parents: 67
diff changeset
1959 unsigned int j;
kono
parents: 67
diff changeset
1960 for (j = 1; j < path->length (); j++)
kono
parents: 67
diff changeset
1961 if ((*path)[j]->e->aux != NULL)
kono
parents: 67
diff changeset
1962 break;
kono
parents: 67
diff changeset
1963
kono
parents: 67
diff changeset
1964 /* If we iterated through the entire path without exiting the loop,
kono
parents: 67
diff changeset
1965 then we are good to go, record it. */
kono
parents: 67
diff changeset
1966 if (j == path->length ())
kono
parents: 67
diff changeset
1967 {
kono
parents: 67
diff changeset
1968 bitmap_set_bit (tmp, e->dest->index);
kono
parents: 67
diff changeset
1969 i++;
kono
parents: 67
diff changeset
1970 }
kono
parents: 67
diff changeset
1971 else
kono
parents: 67
diff changeset
1972 {
kono
parents: 67
diff changeset
1973 e->aux = NULL;
kono
parents: 67
diff changeset
1974 paths.unordered_remove (i);
kono
parents: 67
diff changeset
1975 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
1976 dump_jump_thread_path (dump_file, *path, false);
kono
parents: 67
diff changeset
1977 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
1978 }
kono
parents: 67
diff changeset
1979 }
kono
parents: 67
diff changeset
1980 else
kono
parents: 67
diff changeset
1981 {
kono
parents: 67
diff changeset
1982 i++;
kono
parents: 67
diff changeset
1983 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1984 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1985
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1986 /* If optimizing for size, only thread through block if we don't have
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1987 to duplicate it or it's an otherwise empty redirection block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1988 if (optimize_function_for_size_p (cfun))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1989 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1990 EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1991 {
111
kono
parents: 67
diff changeset
1992 bb = BASIC_BLOCK_FOR_FN (cfun, i);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1993 if (EDGE_COUNT (bb->preds) > 1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1994 && !redirection_block_p (bb))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1995 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1996 FOR_EACH_EDGE (e, ei, bb->preds)
111
kono
parents: 67
diff changeset
1997 {
kono
parents: 67
diff changeset
1998 if (e->aux)
kono
parents: 67
diff changeset
1999 {
kono
parents: 67
diff changeset
2000 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
2001 delete_jump_thread_path (path);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2002 e->aux = NULL;
111
kono
parents: 67
diff changeset
2003 }
kono
parents: 67
diff changeset
2004 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2005 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2006 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2007 bitmap_set_bit (threaded_blocks, i);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2008 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2009 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2010 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2011 bitmap_copy (threaded_blocks, tmp);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2012
111
kono
parents: 67
diff changeset
2013 /* If we have a joiner block (J) which has two successors S1 and S2 and
kono
parents: 67
diff changeset
2014 we are threading though S1 and the final destination of the thread
kono
parents: 67
diff changeset
2015 is S2, then we must verify that any PHI nodes in S2 have the same
kono
parents: 67
diff changeset
2016 PHI arguments for the edge J->S2 and J->S1->...->S2.
kono
parents: 67
diff changeset
2017
kono
parents: 67
diff changeset
2018 We used to detect this prior to registering the jump thread, but
kono
parents: 67
diff changeset
2019 that prohibits propagation of edge equivalences into non-dominated
kono
parents: 67
diff changeset
2020 PHI nodes as the equivalency test might occur before propagation.
kono
parents: 67
diff changeset
2021
kono
parents: 67
diff changeset
2022 This must also occur after we truncate any jump threading paths
kono
parents: 67
diff changeset
2023 as this scenario may only show up after truncation.
kono
parents: 67
diff changeset
2024
kono
parents: 67
diff changeset
2025 This works for now, but will need improvement as part of the FSA
kono
parents: 67
diff changeset
2026 optimization.
kono
parents: 67
diff changeset
2027
kono
parents: 67
diff changeset
2028 Note since we've moved the thread request data to the edges,
kono
parents: 67
diff changeset
2029 we have to iterate on those rather than the threaded_edges vector. */
kono
parents: 67
diff changeset
2030 EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
kono
parents: 67
diff changeset
2031 {
kono
parents: 67
diff changeset
2032 bb = BASIC_BLOCK_FOR_FN (cfun, i);
kono
parents: 67
diff changeset
2033 FOR_EACH_EDGE (e, ei, bb->preds)
kono
parents: 67
diff changeset
2034 {
kono
parents: 67
diff changeset
2035 if (e->aux)
kono
parents: 67
diff changeset
2036 {
kono
parents: 67
diff changeset
2037 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
2038 bool have_joiner = ((*path)[1]->type == EDGE_COPY_SRC_JOINER_BLOCK);
kono
parents: 67
diff changeset
2039
kono
parents: 67
diff changeset
2040 if (have_joiner)
kono
parents: 67
diff changeset
2041 {
kono
parents: 67
diff changeset
2042 basic_block joiner = e->dest;
kono
parents: 67
diff changeset
2043 edge final_edge = path->last ()->e;
kono
parents: 67
diff changeset
2044 basic_block final_dest = final_edge->dest;
kono
parents: 67
diff changeset
2045 edge e2 = find_edge (joiner, final_dest);
kono
parents: 67
diff changeset
2046
kono
parents: 67
diff changeset
2047 if (e2 && !phi_args_equal_on_edges (e2, final_edge))
kono
parents: 67
diff changeset
2048 {
kono
parents: 67
diff changeset
2049 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
2050 e->aux = NULL;
kono
parents: 67
diff changeset
2051 }
kono
parents: 67
diff changeset
2052 }
kono
parents: 67
diff changeset
2053 }
kono
parents: 67
diff changeset
2054 }
kono
parents: 67
diff changeset
2055 }
kono
parents: 67
diff changeset
2056
kono
parents: 67
diff changeset
2057 /* Look for jump threading paths which cross multiple loop headers.
kono
parents: 67
diff changeset
2058
kono
parents: 67
diff changeset
2059 The code to thread through loop headers will change the CFG in ways
kono
parents: 67
diff changeset
2060 that invalidate the cached loop iteration information. So we must
kono
parents: 67
diff changeset
2061 detect that case and wipe the cached information. */
kono
parents: 67
diff changeset
2062 EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
kono
parents: 67
diff changeset
2063 {
kono
parents: 67
diff changeset
2064 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
kono
parents: 67
diff changeset
2065 FOR_EACH_EDGE (e, ei, bb->preds)
kono
parents: 67
diff changeset
2066 {
kono
parents: 67
diff changeset
2067 if (e->aux)
kono
parents: 67
diff changeset
2068 {
kono
parents: 67
diff changeset
2069 vec<jump_thread_edge *> *path = THREAD_PATH (e);
kono
parents: 67
diff changeset
2070
kono
parents: 67
diff changeset
2071 for (unsigned int i = 0, crossed_headers = 0;
kono
parents: 67
diff changeset
2072 i < path->length ();
kono
parents: 67
diff changeset
2073 i++)
kono
parents: 67
diff changeset
2074 {
kono
parents: 67
diff changeset
2075 basic_block dest = (*path)[i]->e->dest;
kono
parents: 67
diff changeset
2076 basic_block src = (*path)[i]->e->src;
kono
parents: 67
diff changeset
2077 /* If we enter a loop. */
kono
parents: 67
diff changeset
2078 if (flow_loop_nested_p (src->loop_father, dest->loop_father))
kono
parents: 67
diff changeset
2079 ++crossed_headers;
kono
parents: 67
diff changeset
2080 /* If we step from a block outside an irreducible region
kono
parents: 67
diff changeset
2081 to a block inside an irreducible region, then we have
kono
parents: 67
diff changeset
2082 crossed into a loop. */
kono
parents: 67
diff changeset
2083 else if (! (src->flags & BB_IRREDUCIBLE_LOOP)
kono
parents: 67
diff changeset
2084 && (dest->flags & BB_IRREDUCIBLE_LOOP))
kono
parents: 67
diff changeset
2085 ++crossed_headers;
kono
parents: 67
diff changeset
2086 if (crossed_headers > 1)
kono
parents: 67
diff changeset
2087 {
kono
parents: 67
diff changeset
2088 vect_free_loop_info_assumptions
kono
parents: 67
diff changeset
2089 ((*path)[path->length () - 1]->e->dest->loop_father);
kono
parents: 67
diff changeset
2090 break;
kono
parents: 67
diff changeset
2091 }
kono
parents: 67
diff changeset
2092 }
kono
parents: 67
diff changeset
2093 }
kono
parents: 67
diff changeset
2094 }
kono
parents: 67
diff changeset
2095 }
kono
parents: 67
diff changeset
2096 }
kono
parents: 67
diff changeset
2097
kono
parents: 67
diff changeset
2098
kono
parents: 67
diff changeset
2099 /* Verify that the REGION is a valid jump thread. A jump thread is a special
kono
parents: 67
diff changeset
2100 case of SEME Single Entry Multiple Exits region in which all nodes in the
kono
parents: 67
diff changeset
2101 REGION have exactly one incoming edge. The only exception is the first block
kono
parents: 67
diff changeset
2102 that may not have been connected to the rest of the cfg yet. */
kono
parents: 67
diff changeset
2103
kono
parents: 67
diff changeset
2104 DEBUG_FUNCTION void
kono
parents: 67
diff changeset
2105 verify_jump_thread (basic_block *region, unsigned n_region)
kono
parents: 67
diff changeset
2106 {
kono
parents: 67
diff changeset
2107 for (unsigned i = 0; i < n_region; i++)
kono
parents: 67
diff changeset
2108 gcc_assert (EDGE_COUNT (region[i]->preds) <= 1);
kono
parents: 67
diff changeset
2109 }
kono
parents: 67
diff changeset
2110
kono
parents: 67
diff changeset
2111 /* Return true when BB is one of the first N items in BBS. */
kono
parents: 67
diff changeset
2112
kono
parents: 67
diff changeset
2113 static inline bool
kono
parents: 67
diff changeset
2114 bb_in_bbs (basic_block bb, basic_block *bbs, int n)
kono
parents: 67
diff changeset
2115 {
kono
parents: 67
diff changeset
2116 for (int i = 0; i < n; i++)
kono
parents: 67
diff changeset
2117 if (bb == bbs[i])
kono
parents: 67
diff changeset
2118 return true;
kono
parents: 67
diff changeset
2119
kono
parents: 67
diff changeset
2120 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2121 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2122
111
kono
parents: 67
diff changeset
2123 /* Duplicates a jump-thread path of N_REGION basic blocks.
kono
parents: 67
diff changeset
2124 The ENTRY edge is redirected to the duplicate of the region.
kono
parents: 67
diff changeset
2125
kono
parents: 67
diff changeset
2126 Remove the last conditional statement in the last basic block in the REGION,
kono
parents: 67
diff changeset
2127 and create a single fallthru edge pointing to the same destination as the
kono
parents: 67
diff changeset
2128 EXIT edge.
kono
parents: 67
diff changeset
2129
kono
parents: 67
diff changeset
2130 Returns false if it is unable to copy the region, true otherwise. */
kono
parents: 67
diff changeset
2131
kono
parents: 67
diff changeset
2132 static bool
kono
parents: 67
diff changeset
2133 duplicate_thread_path (edge entry, edge exit, basic_block *region,
kono
parents: 67
diff changeset
2134 unsigned n_region)
kono
parents: 67
diff changeset
2135 {
kono
parents: 67
diff changeset
2136 unsigned i;
kono
parents: 67
diff changeset
2137 struct loop *loop = entry->dest->loop_father;
kono
parents: 67
diff changeset
2138 edge exit_copy;
kono
parents: 67
diff changeset
2139 edge redirected;
kono
parents: 67
diff changeset
2140 int curr_freq;
kono
parents: 67
diff changeset
2141 profile_count curr_count;
kono
parents: 67
diff changeset
2142
kono
parents: 67
diff changeset
2143 if (!can_copy_bbs_p (region, n_region))
kono
parents: 67
diff changeset
2144 return false;
kono
parents: 67
diff changeset
2145
kono
parents: 67
diff changeset
2146 /* Some sanity checking. Note that we do not check for all possible
kono
parents: 67
diff changeset
2147 missuses of the functions. I.e. if you ask to copy something weird,
kono
parents: 67
diff changeset
2148 it will work, but the state of structures probably will not be
kono
parents: 67
diff changeset
2149 correct. */
kono
parents: 67
diff changeset
2150 for (i = 0; i < n_region; i++)
kono
parents: 67
diff changeset
2151 {
kono
parents: 67
diff changeset
2152 /* We do not handle subloops, i.e. all the blocks must belong to the
kono
parents: 67
diff changeset
2153 same loop. */
kono
parents: 67
diff changeset
2154 if (region[i]->loop_father != loop)
kono
parents: 67
diff changeset
2155 return false;
kono
parents: 67
diff changeset
2156 }
kono
parents: 67
diff changeset
2157
kono
parents: 67
diff changeset
2158 initialize_original_copy_tables ();
kono
parents: 67
diff changeset
2159
kono
parents: 67
diff changeset
2160 set_loop_copy (loop, loop);
kono
parents: 67
diff changeset
2161
kono
parents: 67
diff changeset
2162 basic_block *region_copy = XNEWVEC (basic_block, n_region);
kono
parents: 67
diff changeset
2163 copy_bbs (region, n_region, region_copy, &exit, 1, &exit_copy, loop,
kono
parents: 67
diff changeset
2164 split_edge_bb_loc (entry), false);
kono
parents: 67
diff changeset
2165
kono
parents: 67
diff changeset
2166 /* Fix up: copy_bbs redirects all edges pointing to copied blocks. The
kono
parents: 67
diff changeset
2167 following code ensures that all the edges exiting the jump-thread path are
kono
parents: 67
diff changeset
2168 redirected back to the original code: these edges are exceptions
kono
parents: 67
diff changeset
2169 invalidating the property that is propagated by executing all the blocks of
kono
parents: 67
diff changeset
2170 the jump-thread path in order. */
kono
parents: 67
diff changeset
2171
kono
parents: 67
diff changeset
2172 curr_count = entry->count ();
kono
parents: 67
diff changeset
2173 curr_freq = EDGE_FREQUENCY (entry);
kono
parents: 67
diff changeset
2174
kono
parents: 67
diff changeset
2175 for (i = 0; i < n_region; i++)
kono
parents: 67
diff changeset
2176 {
kono
parents: 67
diff changeset
2177 edge e;
kono
parents: 67
diff changeset
2178 edge_iterator ei;
kono
parents: 67
diff changeset
2179 basic_block bb = region_copy[i];
kono
parents: 67
diff changeset
2180
kono
parents: 67
diff changeset
2181 /* Watch inconsistent profile. */
kono
parents: 67
diff changeset
2182 if (curr_count > region[i]->count)
kono
parents: 67
diff changeset
2183 curr_count = region[i]->count;
kono
parents: 67
diff changeset
2184 if (curr_freq > region[i]->frequency)
kono
parents: 67
diff changeset
2185 curr_freq = region[i]->frequency;
kono
parents: 67
diff changeset
2186 /* Scale current BB. */
kono
parents: 67
diff changeset
2187 if (region[i]->count > 0 && curr_count.initialized_p ())
kono
parents: 67
diff changeset
2188 {
kono
parents: 67
diff changeset
2189 /* In the middle of the path we only scale the frequencies.
kono
parents: 67
diff changeset
2190 In last BB we need to update probabilities of outgoing edges
kono
parents: 67
diff changeset
2191 because we know which one is taken at the threaded path. */
kono
parents: 67
diff changeset
2192 if (i + 1 != n_region)
kono
parents: 67
diff changeset
2193 scale_bbs_frequencies_profile_count (region + i, 1,
kono
parents: 67
diff changeset
2194 region[i]->count - curr_count,
kono
parents: 67
diff changeset
2195 region[i]->count);
kono
parents: 67
diff changeset
2196 else
kono
parents: 67
diff changeset
2197 update_bb_profile_for_threading (region[i],
kono
parents: 67
diff changeset
2198 curr_freq, curr_count,
kono
parents: 67
diff changeset
2199 exit);
kono
parents: 67
diff changeset
2200 scale_bbs_frequencies_profile_count (region_copy + i, 1, curr_count,
kono
parents: 67
diff changeset
2201 region_copy[i]->count);
kono
parents: 67
diff changeset
2202 }
kono
parents: 67
diff changeset
2203 else if (region[i]->frequency)
kono
parents: 67
diff changeset
2204 {
kono
parents: 67
diff changeset
2205 if (i + 1 != n_region)
kono
parents: 67
diff changeset
2206 scale_bbs_frequencies_int (region + i, 1,
kono
parents: 67
diff changeset
2207 region[i]->frequency - curr_freq,
kono
parents: 67
diff changeset
2208 region[i]->frequency);
kono
parents: 67
diff changeset
2209 else
kono
parents: 67
diff changeset
2210 update_bb_profile_for_threading (region[i],
kono
parents: 67
diff changeset
2211 curr_freq, curr_count,
kono
parents: 67
diff changeset
2212 exit);
kono
parents: 67
diff changeset
2213 scale_bbs_frequencies_int (region_copy + i, 1, curr_freq,
kono
parents: 67
diff changeset
2214 region_copy[i]->frequency);
kono
parents: 67
diff changeset
2215 }
kono
parents: 67
diff changeset
2216
kono
parents: 67
diff changeset
2217 if (single_succ_p (bb))
kono
parents: 67
diff changeset
2218 {
kono
parents: 67
diff changeset
2219 /* Make sure the successor is the next node in the path. */
kono
parents: 67
diff changeset
2220 gcc_assert (i + 1 == n_region
kono
parents: 67
diff changeset
2221 || region_copy[i + 1] == single_succ_edge (bb)->dest);
kono
parents: 67
diff changeset
2222 if (i + 1 != n_region)
kono
parents: 67
diff changeset
2223 {
kono
parents: 67
diff changeset
2224 curr_freq = EDGE_FREQUENCY (single_succ_edge (bb));
kono
parents: 67
diff changeset
2225 curr_count = single_succ_edge (bb)->count ();
kono
parents: 67
diff changeset
2226 }
kono
parents: 67
diff changeset
2227 continue;
kono
parents: 67
diff changeset
2228 }
kono
parents: 67
diff changeset
2229
kono
parents: 67
diff changeset
2230 /* Special case the last block on the path: make sure that it does not
kono
parents: 67
diff changeset
2231 jump back on the copied path, including back to itself. */
kono
parents: 67
diff changeset
2232 if (i + 1 == n_region)
kono
parents: 67
diff changeset
2233 {
kono
parents: 67
diff changeset
2234 FOR_EACH_EDGE (e, ei, bb->succs)
kono
parents: 67
diff changeset
2235 if (bb_in_bbs (e->dest, region_copy, n_region))
kono
parents: 67
diff changeset
2236 {
kono
parents: 67
diff changeset
2237 basic_block orig = get_bb_original (e->dest);
kono
parents: 67
diff changeset
2238 if (orig)
kono
parents: 67
diff changeset
2239 redirect_edge_and_branch_force (e, orig);
kono
parents: 67
diff changeset
2240 }
kono
parents: 67
diff changeset
2241 continue;
kono
parents: 67
diff changeset
2242 }
kono
parents: 67
diff changeset
2243
kono
parents: 67
diff changeset
2244 /* Redirect all other edges jumping to non-adjacent blocks back to the
kono
parents: 67
diff changeset
2245 original code. */
kono
parents: 67
diff changeset
2246 FOR_EACH_EDGE (e, ei, bb->succs)
kono
parents: 67
diff changeset
2247 if (region_copy[i + 1] != e->dest)
kono
parents: 67
diff changeset
2248 {
kono
parents: 67
diff changeset
2249 basic_block orig = get_bb_original (e->dest);
kono
parents: 67
diff changeset
2250 if (orig)
kono
parents: 67
diff changeset
2251 redirect_edge_and_branch_force (e, orig);
kono
parents: 67
diff changeset
2252 }
kono
parents: 67
diff changeset
2253 else
kono
parents: 67
diff changeset
2254 {
kono
parents: 67
diff changeset
2255 curr_freq = EDGE_FREQUENCY (e);
kono
parents: 67
diff changeset
2256 curr_count = e->count ();
kono
parents: 67
diff changeset
2257 }
kono
parents: 67
diff changeset
2258 }
kono
parents: 67
diff changeset
2259
kono
parents: 67
diff changeset
2260
kono
parents: 67
diff changeset
2261 if (flag_checking)
kono
parents: 67
diff changeset
2262 verify_jump_thread (region_copy, n_region);
kono
parents: 67
diff changeset
2263
kono
parents: 67
diff changeset
2264 /* Remove the last branch in the jump thread path. */
kono
parents: 67
diff changeset
2265 remove_ctrl_stmt_and_useless_edges (region_copy[n_region - 1], exit->dest);
kono
parents: 67
diff changeset
2266
kono
parents: 67
diff changeset
2267 /* And fixup the flags on the single remaining edge. */
kono
parents: 67
diff changeset
2268 edge fix_e = find_edge (region_copy[n_region - 1], exit->dest);
kono
parents: 67
diff changeset
2269 fix_e->flags &= ~(EDGE_TRUE_VALUE | EDGE_FALSE_VALUE | EDGE_ABNORMAL);
kono
parents: 67
diff changeset
2270 fix_e->flags |= EDGE_FALLTHRU;
kono
parents: 67
diff changeset
2271
kono
parents: 67
diff changeset
2272 edge e = make_edge (region_copy[n_region - 1], exit->dest, EDGE_FALLTHRU);
kono
parents: 67
diff changeset
2273
kono
parents: 67
diff changeset
2274 if (e)
kono
parents: 67
diff changeset
2275 {
kono
parents: 67
diff changeset
2276 rescan_loop_exit (e, true, false);
kono
parents: 67
diff changeset
2277 e->probability = profile_probability::always ();
kono
parents: 67
diff changeset
2278 }
kono
parents: 67
diff changeset
2279
kono
parents: 67
diff changeset
2280 /* Redirect the entry and add the phi node arguments. */
kono
parents: 67
diff changeset
2281 if (entry->dest == loop->header)
kono
parents: 67
diff changeset
2282 mark_loop_for_removal (loop);
kono
parents: 67
diff changeset
2283 redirected = redirect_edge_and_branch (entry, get_bb_copy (entry->dest));
kono
parents: 67
diff changeset
2284 gcc_assert (redirected != NULL);
kono
parents: 67
diff changeset
2285 flush_pending_stmts (entry);
kono
parents: 67
diff changeset
2286
kono
parents: 67
diff changeset
2287 /* Add the other PHI node arguments. */
kono
parents: 67
diff changeset
2288 add_phi_args_after_copy (region_copy, n_region, NULL);
kono
parents: 67
diff changeset
2289
kono
parents: 67
diff changeset
2290 free (region_copy);
kono
parents: 67
diff changeset
2291
kono
parents: 67
diff changeset
2292 free_original_copy_tables ();
kono
parents: 67
diff changeset
2293 return true;
kono
parents: 67
diff changeset
2294 }
kono
parents: 67
diff changeset
2295
kono
parents: 67
diff changeset
2296 /* Return true when PATH is a valid jump-thread path. */
kono
parents: 67
diff changeset
2297
kono
parents: 67
diff changeset
2298 static bool
kono
parents: 67
diff changeset
2299 valid_jump_thread_path (vec<jump_thread_edge *> *path)
kono
parents: 67
diff changeset
2300 {
kono
parents: 67
diff changeset
2301 unsigned len = path->length ();
kono
parents: 67
diff changeset
2302
kono
parents: 67
diff changeset
2303 /* Check that the path is connected. */
kono
parents: 67
diff changeset
2304 for (unsigned int j = 0; j < len - 1; j++)
kono
parents: 67
diff changeset
2305 {
kono
parents: 67
diff changeset
2306 edge e = (*path)[j]->e;
kono
parents: 67
diff changeset
2307 if (e->dest != (*path)[j+1]->e->src)
kono
parents: 67
diff changeset
2308 return false;
kono
parents: 67
diff changeset
2309 }
kono
parents: 67
diff changeset
2310 return true;
kono
parents: 67
diff changeset
2311 }
kono
parents: 67
diff changeset
2312
kono
parents: 67
diff changeset
2313 /* Remove any queued jump threads that include edge E.
kono
parents: 67
diff changeset
2314
kono
parents: 67
diff changeset
2315 We don't actually remove them here, just record the edges into ax
kono
parents: 67
diff changeset
2316 hash table. That way we can do the search once per iteration of
kono
parents: 67
diff changeset
2317 DOM/VRP rather than for every case where DOM optimizes away a COND_EXPR. */
kono
parents: 67
diff changeset
2318
kono
parents: 67
diff changeset
2319 void
kono
parents: 67
diff changeset
2320 remove_jump_threads_including (edge_def *e)
kono
parents: 67
diff changeset
2321 {
kono
parents: 67
diff changeset
2322 if (!paths.exists ())
kono
parents: 67
diff changeset
2323 return;
kono
parents: 67
diff changeset
2324
kono
parents: 67
diff changeset
2325 if (!removed_edges)
kono
parents: 67
diff changeset
2326 removed_edges = new hash_table<struct removed_edges> (17);
kono
parents: 67
diff changeset
2327
kono
parents: 67
diff changeset
2328 edge *slot = removed_edges->find_slot (e, INSERT);
kono
parents: 67
diff changeset
2329 *slot = e;
kono
parents: 67
diff changeset
2330 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2331
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2332 /* Walk through all blocks and thread incoming edges to the appropriate
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2333 outgoing edge for each edge pair recorded in THREADED_EDGES.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2334
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2335 It is the caller's responsibility to fix the dominance information
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2336 and rewrite duplicated SSA_NAMEs back into SSA form.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2337
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2338 If MAY_PEEL_LOOP_HEADERS is false, we avoid threading edges through
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2339 loop headers if it does not simplify the loop.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2340
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2341 Returns true if one or more edges were threaded, false otherwise. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2342
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2343 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2344 thread_through_all_blocks (bool may_peel_loop_headers)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2345 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2346 bool retval = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2347 unsigned int i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2348 bitmap_iterator bi;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2349 struct loop *loop;
111
kono
parents: 67
diff changeset
2350 auto_bitmap threaded_blocks;
kono
parents: 67
diff changeset
2351
kono
parents: 67
diff changeset
2352 if (!paths.exists ())
kono
parents: 67
diff changeset
2353 {
kono
parents: 67
diff changeset
2354 retval = false;
kono
parents: 67
diff changeset
2355 goto out;
kono
parents: 67
diff changeset
2356 }
kono
parents: 67
diff changeset
2357
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2358 memset (&thread_stats, 0, sizeof (thread_stats));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2359
111
kono
parents: 67
diff changeset
2360 /* Remove any paths that referenced removed edges. */
kono
parents: 67
diff changeset
2361 if (removed_edges)
kono
parents: 67
diff changeset
2362 for (i = 0; i < paths.length (); )
kono
parents: 67
diff changeset
2363 {
kono
parents: 67
diff changeset
2364 unsigned int j;
kono
parents: 67
diff changeset
2365 vec<jump_thread_edge *> *path = paths[i];
kono
parents: 67
diff changeset
2366
kono
parents: 67
diff changeset
2367 for (j = 0; j < path->length (); j++)
kono
parents: 67
diff changeset
2368 {
kono
parents: 67
diff changeset
2369 edge e = (*path)[j]->e;
kono
parents: 67
diff changeset
2370 if (removed_edges->find_slot (e, NO_INSERT))
kono
parents: 67
diff changeset
2371 break;
kono
parents: 67
diff changeset
2372 }
kono
parents: 67
diff changeset
2373
kono
parents: 67
diff changeset
2374 if (j != path->length ())
kono
parents: 67
diff changeset
2375 {
kono
parents: 67
diff changeset
2376 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
2377 paths.unordered_remove (i);
kono
parents: 67
diff changeset
2378 continue;
kono
parents: 67
diff changeset
2379 }
kono
parents: 67
diff changeset
2380 i++;
kono
parents: 67
diff changeset
2381 }
kono
parents: 67
diff changeset
2382
kono
parents: 67
diff changeset
2383 /* Jump-thread all FSM threads before other jump-threads. */
kono
parents: 67
diff changeset
2384 for (i = 0; i < paths.length ();)
kono
parents: 67
diff changeset
2385 {
kono
parents: 67
diff changeset
2386 vec<jump_thread_edge *> *path = paths[i];
kono
parents: 67
diff changeset
2387 edge entry = (*path)[0]->e;
kono
parents: 67
diff changeset
2388
kono
parents: 67
diff changeset
2389 /* Only code-generate FSM jump-threads in this loop. */
kono
parents: 67
diff changeset
2390 if ((*path)[0]->type != EDGE_FSM_THREAD)
kono
parents: 67
diff changeset
2391 {
kono
parents: 67
diff changeset
2392 i++;
kono
parents: 67
diff changeset
2393 continue;
kono
parents: 67
diff changeset
2394 }
kono
parents: 67
diff changeset
2395
kono
parents: 67
diff changeset
2396 /* Do not jump-thread twice from the same block. */
kono
parents: 67
diff changeset
2397 if (bitmap_bit_p (threaded_blocks, entry->src->index)
kono
parents: 67
diff changeset
2398 /* We may not want to realize this jump thread path
kono
parents: 67
diff changeset
2399 for various reasons. So check it first. */
kono
parents: 67
diff changeset
2400 || !valid_jump_thread_path (path))
kono
parents: 67
diff changeset
2401 {
kono
parents: 67
diff changeset
2402 /* Remove invalid FSM jump-thread paths. */
kono
parents: 67
diff changeset
2403 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
2404 paths.unordered_remove (i);
kono
parents: 67
diff changeset
2405 continue;
kono
parents: 67
diff changeset
2406 }
kono
parents: 67
diff changeset
2407
kono
parents: 67
diff changeset
2408 unsigned len = path->length ();
kono
parents: 67
diff changeset
2409 edge exit = (*path)[len - 1]->e;
kono
parents: 67
diff changeset
2410 basic_block *region = XNEWVEC (basic_block, len - 1);
kono
parents: 67
diff changeset
2411
kono
parents: 67
diff changeset
2412 for (unsigned int j = 0; j < len - 1; j++)
kono
parents: 67
diff changeset
2413 region[j] = (*path)[j]->e->dest;
kono
parents: 67
diff changeset
2414
kono
parents: 67
diff changeset
2415 if (duplicate_thread_path (entry, exit, region, len - 1))
kono
parents: 67
diff changeset
2416 {
kono
parents: 67
diff changeset
2417 /* We do not update dominance info. */
kono
parents: 67
diff changeset
2418 free_dominance_info (CDI_DOMINATORS);
kono
parents: 67
diff changeset
2419 bitmap_set_bit (threaded_blocks, entry->src->index);
kono
parents: 67
diff changeset
2420 retval = true;
kono
parents: 67
diff changeset
2421 thread_stats.num_threaded_edges++;
kono
parents: 67
diff changeset
2422 }
kono
parents: 67
diff changeset
2423
kono
parents: 67
diff changeset
2424 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
2425 paths.unordered_remove (i);
kono
parents: 67
diff changeset
2426 free (region);
kono
parents: 67
diff changeset
2427 }
kono
parents: 67
diff changeset
2428
kono
parents: 67
diff changeset
2429 /* Remove from PATHS all the jump-threads starting with an edge already
kono
parents: 67
diff changeset
2430 jump-threaded. */
kono
parents: 67
diff changeset
2431 for (i = 0; i < paths.length ();)
kono
parents: 67
diff changeset
2432 {
kono
parents: 67
diff changeset
2433 vec<jump_thread_edge *> *path = paths[i];
kono
parents: 67
diff changeset
2434 edge entry = (*path)[0]->e;
kono
parents: 67
diff changeset
2435
kono
parents: 67
diff changeset
2436 /* Do not jump-thread twice from the same block. */
kono
parents: 67
diff changeset
2437 if (bitmap_bit_p (threaded_blocks, entry->src->index))
kono
parents: 67
diff changeset
2438 {
kono
parents: 67
diff changeset
2439 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
2440 paths.unordered_remove (i);
kono
parents: 67
diff changeset
2441 }
kono
parents: 67
diff changeset
2442 else
kono
parents: 67
diff changeset
2443 i++;
kono
parents: 67
diff changeset
2444 }
kono
parents: 67
diff changeset
2445
kono
parents: 67
diff changeset
2446 bitmap_clear (threaded_blocks);
kono
parents: 67
diff changeset
2447
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2448 mark_threaded_blocks (threaded_blocks);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2449
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2450 initialize_original_copy_tables ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2451
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2452 /* First perform the threading requests that do not affect
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2453 loop structure. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2454 EXECUTE_IF_SET_IN_BITMAP (threaded_blocks, 0, i, bi)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2455 {
111
kono
parents: 67
diff changeset
2456 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2457
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2458 if (EDGE_COUNT (bb->preds) > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2459 retval |= thread_block (bb, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2460 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2461
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2462 /* Then perform the threading through loop headers. We start with the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2463 innermost loop, so that the changes in cfg we perform won't affect
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2464 further threading. */
111
kono
parents: 67
diff changeset
2465 FOR_EACH_LOOP (loop, LI_FROM_INNERMOST)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2466 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2467 if (!loop->header
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2468 || !bitmap_bit_p (threaded_blocks, loop->header->index))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2469 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2470
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2471 retval |= thread_through_loop_header (loop, may_peel_loop_headers);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2472 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2473
111
kono
parents: 67
diff changeset
2474 /* All jump threading paths should have been resolved at this
kono
parents: 67
diff changeset
2475 point. Verify that is the case. */
kono
parents: 67
diff changeset
2476 basic_block bb;
kono
parents: 67
diff changeset
2477 FOR_EACH_BB_FN (bb, cfun)
kono
parents: 67
diff changeset
2478 {
kono
parents: 67
diff changeset
2479 edge_iterator ei;
kono
parents: 67
diff changeset
2480 edge e;
kono
parents: 67
diff changeset
2481 FOR_EACH_EDGE (e, ei, bb->preds)
kono
parents: 67
diff changeset
2482 gcc_assert (e->aux == NULL);
kono
parents: 67
diff changeset
2483 }
kono
parents: 67
diff changeset
2484
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2485 statistics_counter_event (cfun, "Jumps threaded",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2486 thread_stats.num_threaded_edges);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2487
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2488 free_original_copy_tables ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2489
111
kono
parents: 67
diff changeset
2490 paths.release ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2491
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2492 if (retval)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2493 loops_state_set (LOOPS_NEED_FIXUP);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2494
111
kono
parents: 67
diff changeset
2495 out:
kono
parents: 67
diff changeset
2496 delete removed_edges;
kono
parents: 67
diff changeset
2497 removed_edges = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2498 return retval;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2499 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2500
111
kono
parents: 67
diff changeset
2501 /* Delete the jump threading path PATH. We have to explicitly delete
kono
parents: 67
diff changeset
2502 each entry in the vector, then the container. */
kono
parents: 67
diff changeset
2503
kono
parents: 67
diff changeset
2504 void
kono
parents: 67
diff changeset
2505 delete_jump_thread_path (vec<jump_thread_edge *> *path)
kono
parents: 67
diff changeset
2506 {
kono
parents: 67
diff changeset
2507 for (unsigned int i = 0; i < path->length (); i++)
kono
parents: 67
diff changeset
2508 delete (*path)[i];
kono
parents: 67
diff changeset
2509 path->release();
kono
parents: 67
diff changeset
2510 delete path;
kono
parents: 67
diff changeset
2511 }
kono
parents: 67
diff changeset
2512
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2513 /* Register a jump threading opportunity. We queue up all the jump
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2514 threading opportunities discovered by a pass and update the CFG
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2515 and SSA form all at once.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2516
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2517 E is the edge we can thread, E2 is the new target edge, i.e., we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2518 are effectively recording that E->dest can be changed to E2->dest
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2519 after fixing the SSA graph. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2520
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2521 void
111
kono
parents: 67
diff changeset
2522 register_jump_thread (vec<jump_thread_edge *> *path)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2523 {
111
kono
parents: 67
diff changeset
2524 if (!dbg_cnt (registered_jump_thread))
kono
parents: 67
diff changeset
2525 {
kono
parents: 67
diff changeset
2526 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
2527 return;
kono
parents: 67
diff changeset
2528 }
kono
parents: 67
diff changeset
2529
kono
parents: 67
diff changeset
2530 /* First make sure there are no NULL outgoing edges on the jump threading
kono
parents: 67
diff changeset
2531 path. That can happen for jumping to a constant address. */
kono
parents: 67
diff changeset
2532 for (unsigned int i = 0; i < path->length (); i++)
kono
parents: 67
diff changeset
2533 {
kono
parents: 67
diff changeset
2534 if ((*path)[i]->e == NULL)
kono
parents: 67
diff changeset
2535 {
kono
parents: 67
diff changeset
2536 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
2537 {
kono
parents: 67
diff changeset
2538 fprintf (dump_file,
kono
parents: 67
diff changeset
2539 "Found NULL edge in jump threading path. Cancelling jump thread:\n");
kono
parents: 67
diff changeset
2540 dump_jump_thread_path (dump_file, *path, false);
kono
parents: 67
diff changeset
2541 }
kono
parents: 67
diff changeset
2542
kono
parents: 67
diff changeset
2543 delete_jump_thread_path (path);
kono
parents: 67
diff changeset
2544 return;
kono
parents: 67
diff changeset
2545 }
kono
parents: 67
diff changeset
2546
kono
parents: 67
diff changeset
2547 /* Only the FSM threader is allowed to thread across
kono
parents: 67
diff changeset
2548 backedges in the CFG. */
kono
parents: 67
diff changeset
2549 if (flag_checking
kono
parents: 67
diff changeset
2550 && (*path)[0]->type != EDGE_FSM_THREAD)
kono
parents: 67
diff changeset
2551 gcc_assert (((*path)[i]->e->flags & EDGE_DFS_BACK) == 0);
kono
parents: 67
diff changeset
2552 }
kono
parents: 67
diff changeset
2553
kono
parents: 67
diff changeset
2554 if (dump_file && (dump_flags & TDF_DETAILS))
kono
parents: 67
diff changeset
2555 dump_jump_thread_path (dump_file, *path, true);
kono
parents: 67
diff changeset
2556
kono
parents: 67
diff changeset
2557 if (!paths.exists ())
kono
parents: 67
diff changeset
2558 paths.create (5);
kono
parents: 67
diff changeset
2559
kono
parents: 67
diff changeset
2560 paths.safe_push (path);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2561 }