Mercurial > hg > CbC > CbC_gcc
annotate gcc/tree-scalar-evolution.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
rev | line source |
---|---|
0 | 1 /* Scalar evolution detector. |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
0 | 3 Free Software Foundation, Inc. |
4 Contributed by Sebastian Pop <s.pop@laposte.net> | |
5 | |
6 This file is part of GCC. | |
7 | |
8 GCC is free software; you can redistribute it and/or modify it under | |
9 the terms of the GNU General Public License as published by the Free | |
10 Software Foundation; either version 3, or (at your option) any later | |
11 version. | |
12 | |
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with GCC; see the file COPYING3. If not see | |
20 <http://www.gnu.org/licenses/>. */ | |
21 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
22 /* |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
23 Description: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
24 |
0 | 25 This pass analyzes the evolution of scalar variables in loop |
26 structures. The algorithm is based on the SSA representation, | |
27 and on the loop hierarchy tree. This algorithm is not based on | |
28 the notion of versions of a variable, as it was the case for the | |
29 previous implementations of the scalar evolution algorithm, but | |
30 it assumes that each defined name is unique. | |
31 | |
32 The notation used in this file is called "chains of recurrences", | |
33 and has been proposed by Eugene Zima, Robert Van Engelen, and | |
34 others for describing induction variables in programs. For example | |
35 "b -> {0, +, 2}_1" means that the scalar variable "b" is equal to 0 | |
36 when entering in the loop_1 and has a step 2 in this loop, in other | |
37 words "for (b = 0; b < N; b+=2);". Note that the coefficients of | |
38 this chain of recurrence (or chrec [shrek]) can contain the name of | |
39 other variables, in which case they are called parametric chrecs. | |
40 For example, "b -> {a, +, 2}_1" means that the initial value of "b" | |
41 is the value of "a". In most of the cases these parametric chrecs | |
42 are fully instantiated before their use because symbolic names can | |
43 hide some difficult cases such as self-references described later | |
44 (see the Fibonacci example). | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
45 |
0 | 46 A short sketch of the algorithm is: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
47 |
0 | 48 Given a scalar variable to be analyzed, follow the SSA edge to |
49 its definition: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
50 |
0 | 51 - When the definition is a GIMPLE_ASSIGN: if the right hand side |
52 (RHS) of the definition cannot be statically analyzed, the answer | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
53 of the analyzer is: "don't know". |
0 | 54 Otherwise, for all the variables that are not yet analyzed in the |
55 RHS, try to determine their evolution, and finally try to | |
56 evaluate the operation of the RHS that gives the evolution | |
57 function of the analyzed variable. | |
58 | |
59 - When the definition is a condition-phi-node: determine the | |
60 evolution function for all the branches of the phi node, and | |
61 finally merge these evolutions (see chrec_merge). | |
62 | |
63 - When the definition is a loop-phi-node: determine its initial | |
64 condition, that is the SSA edge defined in an outer loop, and | |
65 keep it symbolic. Then determine the SSA edges that are defined | |
66 in the body of the loop. Follow the inner edges until ending on | |
67 another loop-phi-node of the same analyzed loop. If the reached | |
68 loop-phi-node is not the starting loop-phi-node, then we keep | |
69 this definition under a symbolic form. If the reached | |
70 loop-phi-node is the same as the starting one, then we compute a | |
71 symbolic stride on the return path. The result is then the | |
72 symbolic chrec {initial_condition, +, symbolic_stride}_loop. | |
73 | |
74 Examples: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
75 |
0 | 76 Example 1: Illustration of the basic algorithm. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
77 |
0 | 78 | a = 3 |
79 | loop_1 | |
80 | b = phi (a, c) | |
81 | c = b + 1 | |
82 | if (c > 10) exit_loop | |
83 | endloop | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
84 |
0 | 85 Suppose that we want to know the number of iterations of the |
86 loop_1. The exit_loop is controlled by a COND_EXPR (c > 10). We | |
87 ask the scalar evolution analyzer two questions: what's the | |
88 scalar evolution (scev) of "c", and what's the scev of "10". For | |
89 "10" the answer is "10" since it is a scalar constant. For the | |
90 scalar variable "c", it follows the SSA edge to its definition, | |
91 "c = b + 1", and then asks again what's the scev of "b". | |
92 Following the SSA edge, we end on a loop-phi-node "b = phi (a, | |
93 c)", where the initial condition is "a", and the inner loop edge | |
94 is "c". The initial condition is kept under a symbolic form (it | |
95 may be the case that the copy constant propagation has done its | |
96 work and we end with the constant "3" as one of the edges of the | |
97 loop-phi-node). The update edge is followed to the end of the | |
98 loop, and until reaching again the starting loop-phi-node: b -> c | |
99 -> b. At this point we have drawn a path from "b" to "b" from | |
100 which we compute the stride in the loop: in this example it is | |
101 "+1". The resulting scev for "b" is "b -> {a, +, 1}_1". Now | |
102 that the scev for "b" is known, it is possible to compute the | |
103 scev for "c", that is "c -> {a + 1, +, 1}_1". In order to | |
104 determine the number of iterations in the loop_1, we have to | |
105 instantiate_parameters (loop_1, {a + 1, +, 1}_1), that gives after some | |
106 more analysis the scev {4, +, 1}_1, or in other words, this is | |
107 the function "f (x) = x + 4", where x is the iteration count of | |
108 the loop_1. Now we have to solve the inequality "x + 4 > 10", | |
109 and take the smallest iteration number for which the loop is | |
110 exited: x = 7. This loop runs from x = 0 to x = 7, and in total | |
111 there are 8 iterations. In terms of loop normalization, we have | |
112 created a variable that is implicitly defined, "x" or just "_1", | |
113 and all the other analyzed scalars of the loop are defined in | |
114 function of this variable: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
115 |
0 | 116 a -> 3 |
117 b -> {3, +, 1}_1 | |
118 c -> {4, +, 1}_1 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
119 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
120 or in terms of a C program: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
121 |
0 | 122 | a = 3 |
123 | for (x = 0; x <= 7; x++) | |
124 | { | |
125 | b = x + 3 | |
126 | c = x + 4 | |
127 | } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
128 |
0 | 129 Example 2a: Illustration of the algorithm on nested loops. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
130 |
0 | 131 | loop_1 |
132 | a = phi (1, b) | |
133 | c = a + 2 | |
134 | loop_2 10 times | |
135 | b = phi (c, d) | |
136 | d = b + 3 | |
137 | endloop | |
138 | endloop | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
139 |
0 | 140 For analyzing the scalar evolution of "a", the algorithm follows |
141 the SSA edge into the loop's body: "a -> b". "b" is an inner | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
142 loop-phi-node, and its analysis as in Example 1, gives: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
143 |
0 | 144 b -> {c, +, 3}_2 |
145 d -> {c + 3, +, 3}_2 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
146 |
0 | 147 Following the SSA edge for the initial condition, we end on "c = a |
148 + 2", and then on the starting loop-phi-node "a". From this point, | |
149 the loop stride is computed: back on "c = a + 2" we get a "+2" in | |
150 the loop_1, then on the loop-phi-node "b" we compute the overall | |
151 effect of the inner loop that is "b = c + 30", and we get a "+30" | |
152 in the loop_1. That means that the overall stride in loop_1 is | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
153 equal to "+32", and the result is: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
154 |
0 | 155 a -> {1, +, 32}_1 |
156 c -> {3, +, 32}_1 | |
157 | |
158 Example 2b: Multivariate chains of recurrences. | |
159 | |
160 | loop_1 | |
161 | k = phi (0, k + 1) | |
162 | loop_2 4 times | |
163 | j = phi (0, j + 1) | |
164 | loop_3 4 times | |
165 | i = phi (0, i + 1) | |
166 | A[j + k] = ... | |
167 | endloop | |
168 | endloop | |
169 | endloop | |
170 | |
171 Analyzing the access function of array A with | |
172 instantiate_parameters (loop_1, "j + k"), we obtain the | |
173 instantiation and the analysis of the scalar variables "j" and "k" | |
174 in loop_1. This leads to the scalar evolution {4, +, 1}_1: the end | |
175 value of loop_2 for "j" is 4, and the evolution of "k" in loop_1 is | |
176 {0, +, 1}_1. To obtain the evolution function in loop_3 and | |
177 instantiate the scalar variables up to loop_1, one has to use: | |
178 instantiate_scev (block_before_loop (loop_1), loop_3, "j + k"). | |
179 The result of this call is {{0, +, 1}_1, +, 1}_2. | |
180 | |
181 Example 3: Higher degree polynomials. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
182 |
0 | 183 | loop_1 |
184 | a = phi (2, b) | |
185 | c = phi (5, d) | |
186 | b = a + 1 | |
187 | d = c + a | |
188 | endloop | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
189 |
0 | 190 a -> {2, +, 1}_1 |
191 b -> {3, +, 1}_1 | |
192 c -> {5, +, a}_1 | |
193 d -> {5 + a, +, a}_1 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
194 |
0 | 195 instantiate_parameters (loop_1, {5, +, a}_1) -> {5, +, 2, +, 1}_1 |
196 instantiate_parameters (loop_1, {5 + a, +, a}_1) -> {7, +, 3, +, 1}_1 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
197 |
0 | 198 Example 4: Lucas, Fibonacci, or mixers in general. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
199 |
0 | 200 | loop_1 |
201 | a = phi (1, b) | |
202 | c = phi (3, d) | |
203 | b = c | |
204 | d = c + a | |
205 | endloop | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
206 |
0 | 207 a -> (1, c)_1 |
208 c -> {3, +, a}_1 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
209 |
0 | 210 The syntax "(1, c)_1" stands for a PEELED_CHREC that has the |
211 following semantics: during the first iteration of the loop_1, the | |
212 variable contains the value 1, and then it contains the value "c". | |
213 Note that this syntax is close to the syntax of the loop-phi-node: | |
214 "a -> (1, c)_1" vs. "a = phi (1, c)". | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
215 |
0 | 216 The symbolic chrec representation contains all the semantics of the |
217 original code. What is more difficult is to use this information. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
218 |
0 | 219 Example 5: Flip-flops, or exchangers. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
220 |
0 | 221 | loop_1 |
222 | a = phi (1, b) | |
223 | c = phi (3, d) | |
224 | b = c | |
225 | d = a | |
226 | endloop | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
227 |
0 | 228 a -> (1, c)_1 |
229 c -> (3, a)_1 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
230 |
0 | 231 Based on these symbolic chrecs, it is possible to refine this |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
232 information into the more precise PERIODIC_CHRECs: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
233 |
0 | 234 a -> |1, 3|_1 |
235 c -> |3, 1|_1 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
236 |
0 | 237 This transformation is not yet implemented. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
238 |
0 | 239 Further readings: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
240 |
0 | 241 You can find a more detailed description of the algorithm in: |
242 http://icps.u-strasbg.fr/~pop/DEA_03_Pop.pdf | |
243 http://icps.u-strasbg.fr/~pop/DEA_03_Pop.ps.gz. But note that | |
244 this is a preliminary report and some of the details of the | |
245 algorithm have changed. I'm working on a research report that | |
246 updates the description of the algorithms to reflect the design | |
247 choices used in this implementation. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
248 |
0 | 249 A set of slides show a high level overview of the algorithm and run |
250 an example through the scalar evolution analyzer: | |
251 http://cri.ensmp.fr/~pop/gcc/mar04/slides.pdf | |
252 | |
253 The slides that I have presented at the GCC Summit'04 are available | |
254 at: http://cri.ensmp.fr/~pop/gcc/20040604/gccsummit-lno-spop.pdf | |
255 */ | |
256 | |
257 #include "config.h" | |
258 #include "system.h" | |
259 #include "coretypes.h" | |
260 #include "tm.h" | |
261 #include "ggc.h" | |
262 #include "tree.h" | |
263 #include "basic-block.h" | |
264 #include "diagnostic.h" | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
265 #include "tree-pretty-print.h" |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
266 #include "gimple-pretty-print.h" |
0 | 267 #include "tree-flow.h" |
268 #include "tree-dump.h" | |
269 #include "timevar.h" | |
270 #include "cfgloop.h" | |
271 #include "tree-chrec.h" | |
272 #include "tree-scalar-evolution.h" | |
273 #include "tree-pass.h" | |
274 #include "flags.h" | |
275 #include "params.h" | |
276 | |
277 static tree analyze_scalar_evolution_1 (struct loop *, tree, tree); | |
278 | |
279 /* The cached information about an SSA name VAR, claiming that below | |
280 basic block INSTANTIATED_BELOW, the value of VAR can be expressed | |
281 as CHREC. */ | |
282 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
283 struct GTY(()) scev_info_str { |
0 | 284 basic_block instantiated_below; |
285 tree var; | |
286 tree chrec; | |
287 }; | |
288 | |
289 /* Counters for the scev database. */ | |
290 static unsigned nb_set_scev = 0; | |
291 static unsigned nb_get_scev = 0; | |
292 | |
293 /* The following trees are unique elements. Thus the comparison of | |
294 another element to these elements should be done on the pointer to | |
295 these trees, and not on their value. */ | |
296 | |
297 /* The SSA_NAMEs that are not yet analyzed are qualified with NULL_TREE. */ | |
298 tree chrec_not_analyzed_yet; | |
299 | |
300 /* Reserved to the cases where the analyzer has detected an | |
301 undecidable property at compile time. */ | |
302 tree chrec_dont_know; | |
303 | |
304 /* When the analyzer has detected that a property will never | |
305 happen, then it qualifies it with chrec_known. */ | |
306 tree chrec_known; | |
307 | |
308 static GTY ((param_is (struct scev_info_str))) htab_t scalar_evolution_info; | |
309 | |
310 | |
311 /* Constructs a new SCEV_INFO_STR structure for VAR and INSTANTIATED_BELOW. */ | |
312 | |
313 static inline struct scev_info_str * | |
314 new_scev_info_str (basic_block instantiated_below, tree var) | |
315 { | |
316 struct scev_info_str *res; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
317 |
0 | 318 res = GGC_NEW (struct scev_info_str); |
319 res->var = var; | |
320 res->chrec = chrec_not_analyzed_yet; | |
321 res->instantiated_below = instantiated_below; | |
322 | |
323 return res; | |
324 } | |
325 | |
326 /* Computes a hash function for database element ELT. */ | |
327 | |
328 static hashval_t | |
329 hash_scev_info (const void *elt) | |
330 { | |
331 return SSA_NAME_VERSION (((const struct scev_info_str *) elt)->var); | |
332 } | |
333 | |
334 /* Compares database elements E1 and E2. */ | |
335 | |
336 static int | |
337 eq_scev_info (const void *e1, const void *e2) | |
338 { | |
339 const struct scev_info_str *elt1 = (const struct scev_info_str *) e1; | |
340 const struct scev_info_str *elt2 = (const struct scev_info_str *) e2; | |
341 | |
342 return (elt1->var == elt2->var | |
343 && elt1->instantiated_below == elt2->instantiated_below); | |
344 } | |
345 | |
346 /* Deletes database element E. */ | |
347 | |
348 static void | |
349 del_scev_info (void *e) | |
350 { | |
351 ggc_free (e); | |
352 } | |
353 | |
354 /* Get the scalar evolution of VAR for INSTANTIATED_BELOW basic block. | |
355 A first query on VAR returns chrec_not_analyzed_yet. */ | |
356 | |
357 static tree * | |
358 find_var_scev_info (basic_block instantiated_below, tree var) | |
359 { | |
360 struct scev_info_str *res; | |
361 struct scev_info_str tmp; | |
362 PTR *slot; | |
363 | |
364 tmp.var = var; | |
365 tmp.instantiated_below = instantiated_below; | |
366 slot = htab_find_slot (scalar_evolution_info, &tmp, INSERT); | |
367 | |
368 if (!*slot) | |
369 *slot = new_scev_info_str (instantiated_below, var); | |
370 res = (struct scev_info_str *) *slot; | |
371 | |
372 return &res->chrec; | |
373 } | |
374 | |
375 /* Return true when CHREC contains symbolic names defined in | |
376 LOOP_NB. */ | |
377 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
378 bool |
0 | 379 chrec_contains_symbols_defined_in_loop (const_tree chrec, unsigned loop_nb) |
380 { | |
381 int i, n; | |
382 | |
383 if (chrec == NULL_TREE) | |
384 return false; | |
385 | |
386 if (is_gimple_min_invariant (chrec)) | |
387 return false; | |
388 | |
389 if (TREE_CODE (chrec) == VAR_DECL | |
390 || TREE_CODE (chrec) == PARM_DECL | |
391 || TREE_CODE (chrec) == FUNCTION_DECL | |
392 || TREE_CODE (chrec) == LABEL_DECL | |
393 || TREE_CODE (chrec) == RESULT_DECL | |
394 || TREE_CODE (chrec) == FIELD_DECL) | |
395 return true; | |
396 | |
397 if (TREE_CODE (chrec) == SSA_NAME) | |
398 { | |
399 gimple def = SSA_NAME_DEF_STMT (chrec); | |
400 struct loop *def_loop = loop_containing_stmt (def); | |
401 struct loop *loop = get_loop (loop_nb); | |
402 | |
403 if (def_loop == NULL) | |
404 return false; | |
405 | |
406 if (loop == def_loop || flow_loop_nested_p (loop, def_loop)) | |
407 return true; | |
408 | |
409 return false; | |
410 } | |
411 | |
412 n = TREE_OPERAND_LENGTH (chrec); | |
413 for (i = 0; i < n; i++) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
414 if (chrec_contains_symbols_defined_in_loop (TREE_OPERAND (chrec, i), |
0 | 415 loop_nb)) |
416 return true; | |
417 return false; | |
418 } | |
419 | |
420 /* Return true when PHI is a loop-phi-node. */ | |
421 | |
422 static bool | |
423 loop_phi_node_p (gimple phi) | |
424 { | |
425 /* The implementation of this function is based on the following | |
426 property: "all the loop-phi-nodes of a loop are contained in the | |
427 loop's header basic block". */ | |
428 | |
429 return loop_containing_stmt (phi)->header == gimple_bb (phi); | |
430 } | |
431 | |
432 /* Compute the scalar evolution for EVOLUTION_FN after crossing LOOP. | |
433 In general, in the case of multivariate evolutions we want to get | |
434 the evolution in different loops. LOOP specifies the level for | |
435 which to get the evolution. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
436 |
0 | 437 Example: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
438 |
0 | 439 | for (j = 0; j < 100; j++) |
440 | { | |
441 | for (k = 0; k < 100; k++) | |
442 | { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
443 | i = k + j; - Here the value of i is a function of j, k. |
0 | 444 | } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
445 | ... = i - Here the value of i is a function of j. |
0 | 446 | } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
447 | ... = i - Here the value of i is a scalar. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
448 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
449 Example: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
450 |
0 | 451 | i_0 = ... |
452 | loop_1 10 times | |
453 | i_1 = phi (i_0, i_2) | |
454 | i_2 = i_1 + 2 | |
455 | endloop | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
456 |
0 | 457 This loop has the same effect as: |
458 LOOP_1 has the same effect as: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
459 |
0 | 460 | i_1 = i_0 + 20 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
461 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
462 The overall effect of the loop, "i_0 + 20" in the previous example, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
463 is obtained by passing in the parameters: LOOP = 1, |
0 | 464 EVOLUTION_FN = {i_0, +, 2}_1. |
465 */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
466 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
467 tree |
0 | 468 compute_overall_effect_of_inner_loop (struct loop *loop, tree evolution_fn) |
469 { | |
470 bool val = false; | |
471 | |
472 if (evolution_fn == chrec_dont_know) | |
473 return chrec_dont_know; | |
474 | |
475 else if (TREE_CODE (evolution_fn) == POLYNOMIAL_CHREC) | |
476 { | |
477 struct loop *inner_loop = get_chrec_loop (evolution_fn); | |
478 | |
479 if (inner_loop == loop | |
480 || flow_loop_nested_p (loop, inner_loop)) | |
481 { | |
482 tree nb_iter = number_of_latch_executions (inner_loop); | |
483 | |
484 if (nb_iter == chrec_dont_know) | |
485 return chrec_dont_know; | |
486 else | |
487 { | |
488 tree res; | |
489 | |
490 /* evolution_fn is the evolution function in LOOP. Get | |
491 its value in the nb_iter-th iteration. */ | |
492 res = chrec_apply (inner_loop->num, evolution_fn, nb_iter); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
493 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
494 if (chrec_contains_symbols_defined_in_loop (res, loop->num)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
495 res = instantiate_parameters (loop, res); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
496 |
0 | 497 /* Continue the computation until ending on a parent of LOOP. */ |
498 return compute_overall_effect_of_inner_loop (loop, res); | |
499 } | |
500 } | |
501 else | |
502 return evolution_fn; | |
503 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
504 |
0 | 505 /* If the evolution function is an invariant, there is nothing to do. */ |
506 else if (no_evolution_in_loop_p (evolution_fn, loop->num, &val) && val) | |
507 return evolution_fn; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
508 |
0 | 509 else |
510 return chrec_dont_know; | |
511 } | |
512 | |
513 /* Determine whether the CHREC is always positive/negative. If the expression | |
514 cannot be statically analyzed, return false, otherwise set the answer into | |
515 VALUE. */ | |
516 | |
517 bool | |
518 chrec_is_positive (tree chrec, bool *value) | |
519 { | |
520 bool value0, value1, value2; | |
521 tree end_value, nb_iter; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
522 |
0 | 523 switch (TREE_CODE (chrec)) |
524 { | |
525 case POLYNOMIAL_CHREC: | |
526 if (!chrec_is_positive (CHREC_LEFT (chrec), &value0) | |
527 || !chrec_is_positive (CHREC_RIGHT (chrec), &value1)) | |
528 return false; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
529 |
0 | 530 /* FIXME -- overflows. */ |
531 if (value0 == value1) | |
532 { | |
533 *value = value0; | |
534 return true; | |
535 } | |
536 | |
537 /* Otherwise the chrec is under the form: "{-197, +, 2}_1", | |
538 and the proof consists in showing that the sign never | |
539 changes during the execution of the loop, from 0 to | |
540 loop->nb_iterations. */ | |
541 if (!evolution_function_is_affine_p (chrec)) | |
542 return false; | |
543 | |
544 nb_iter = number_of_latch_executions (get_chrec_loop (chrec)); | |
545 if (chrec_contains_undetermined (nb_iter)) | |
546 return false; | |
547 | |
548 #if 0 | |
549 /* TODO -- If the test is after the exit, we may decrease the number of | |
550 iterations by one. */ | |
551 if (after_exit) | |
552 nb_iter = chrec_fold_minus (type, nb_iter, build_int_cst (type, 1)); | |
553 #endif | |
554 | |
555 end_value = chrec_apply (CHREC_VARIABLE (chrec), chrec, nb_iter); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
556 |
0 | 557 if (!chrec_is_positive (end_value, &value2)) |
558 return false; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
559 |
0 | 560 *value = value0; |
561 return value0 == value1; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
562 |
0 | 563 case INTEGER_CST: |
564 *value = (tree_int_cst_sgn (chrec) == 1); | |
565 return true; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
566 |
0 | 567 default: |
568 return false; | |
569 } | |
570 } | |
571 | |
572 /* Associate CHREC to SCALAR. */ | |
573 | |
574 static void | |
575 set_scalar_evolution (basic_block instantiated_below, tree scalar, tree chrec) | |
576 { | |
577 tree *scalar_info; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
578 |
0 | 579 if (TREE_CODE (scalar) != SSA_NAME) |
580 return; | |
581 | |
582 scalar_info = find_var_scev_info (instantiated_below, scalar); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
583 |
0 | 584 if (dump_file) |
585 { | |
586 if (dump_flags & TDF_DETAILS) | |
587 { | |
588 fprintf (dump_file, "(set_scalar_evolution \n"); | |
589 fprintf (dump_file, " instantiated_below = %d \n", | |
590 instantiated_below->index); | |
591 fprintf (dump_file, " (scalar = "); | |
592 print_generic_expr (dump_file, scalar, 0); | |
593 fprintf (dump_file, ")\n (scalar_evolution = "); | |
594 print_generic_expr (dump_file, chrec, 0); | |
595 fprintf (dump_file, "))\n"); | |
596 } | |
597 if (dump_flags & TDF_STATS) | |
598 nb_set_scev++; | |
599 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
600 |
0 | 601 *scalar_info = chrec; |
602 } | |
603 | |
604 /* Retrieve the chrec associated to SCALAR instantiated below | |
605 INSTANTIATED_BELOW block. */ | |
606 | |
607 static tree | |
608 get_scalar_evolution (basic_block instantiated_below, tree scalar) | |
609 { | |
610 tree res; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
611 |
0 | 612 if (dump_file) |
613 { | |
614 if (dump_flags & TDF_DETAILS) | |
615 { | |
616 fprintf (dump_file, "(get_scalar_evolution \n"); | |
617 fprintf (dump_file, " (scalar = "); | |
618 print_generic_expr (dump_file, scalar, 0); | |
619 fprintf (dump_file, ")\n"); | |
620 } | |
621 if (dump_flags & TDF_STATS) | |
622 nb_get_scev++; | |
623 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
624 |
0 | 625 switch (TREE_CODE (scalar)) |
626 { | |
627 case SSA_NAME: | |
628 res = *find_var_scev_info (instantiated_below, scalar); | |
629 break; | |
630 | |
631 case REAL_CST: | |
632 case FIXED_CST: | |
633 case INTEGER_CST: | |
634 res = scalar; | |
635 break; | |
636 | |
637 default: | |
638 res = chrec_not_analyzed_yet; | |
639 break; | |
640 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
641 |
0 | 642 if (dump_file && (dump_flags & TDF_DETAILS)) |
643 { | |
644 fprintf (dump_file, " (scalar_evolution = "); | |
645 print_generic_expr (dump_file, res, 0); | |
646 fprintf (dump_file, "))\n"); | |
647 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
648 |
0 | 649 return res; |
650 } | |
651 | |
652 /* Helper function for add_to_evolution. Returns the evolution | |
653 function for an assignment of the form "a = b + c", where "a" and | |
654 "b" are on the strongly connected component. CHREC_BEFORE is the | |
655 information that we already have collected up to this point. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
656 TO_ADD is the evolution of "c". |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
657 |
0 | 658 When CHREC_BEFORE has an evolution part in LOOP_NB, add to this |
659 evolution the expression TO_ADD, otherwise construct an evolution | |
660 part for this loop. */ | |
661 | |
662 static tree | |
663 add_to_evolution_1 (unsigned loop_nb, tree chrec_before, tree to_add, | |
664 gimple at_stmt) | |
665 { | |
666 tree type, left, right; | |
667 struct loop *loop = get_loop (loop_nb), *chloop; | |
668 | |
669 switch (TREE_CODE (chrec_before)) | |
670 { | |
671 case POLYNOMIAL_CHREC: | |
672 chloop = get_chrec_loop (chrec_before); | |
673 if (chloop == loop | |
674 || flow_loop_nested_p (chloop, loop)) | |
675 { | |
676 unsigned var; | |
677 | |
678 type = chrec_type (chrec_before); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
679 |
0 | 680 /* When there is no evolution part in this loop, build it. */ |
681 if (chloop != loop) | |
682 { | |
683 var = loop_nb; | |
684 left = chrec_before; | |
685 right = SCALAR_FLOAT_TYPE_P (type) | |
686 ? build_real (type, dconst0) | |
687 : build_int_cst (type, 0); | |
688 } | |
689 else | |
690 { | |
691 var = CHREC_VARIABLE (chrec_before); | |
692 left = CHREC_LEFT (chrec_before); | |
693 right = CHREC_RIGHT (chrec_before); | |
694 } | |
695 | |
696 to_add = chrec_convert (type, to_add, at_stmt); | |
697 right = chrec_convert_rhs (type, right, at_stmt); | |
698 right = chrec_fold_plus (chrec_type (right), right, to_add); | |
699 return build_polynomial_chrec (var, left, right); | |
700 } | |
701 else | |
702 { | |
703 gcc_assert (flow_loop_nested_p (loop, chloop)); | |
704 | |
705 /* Search the evolution in LOOP_NB. */ | |
706 left = add_to_evolution_1 (loop_nb, CHREC_LEFT (chrec_before), | |
707 to_add, at_stmt); | |
708 right = CHREC_RIGHT (chrec_before); | |
709 right = chrec_convert_rhs (chrec_type (left), right, at_stmt); | |
710 return build_polynomial_chrec (CHREC_VARIABLE (chrec_before), | |
711 left, right); | |
712 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
713 |
0 | 714 default: |
715 /* These nodes do not depend on a loop. */ | |
716 if (chrec_before == chrec_dont_know) | |
717 return chrec_dont_know; | |
718 | |
719 left = chrec_before; | |
720 right = chrec_convert_rhs (chrec_type (left), to_add, at_stmt); | |
721 return build_polynomial_chrec (loop_nb, left, right); | |
722 } | |
723 } | |
724 | |
725 /* Add TO_ADD to the evolution part of CHREC_BEFORE in the dimension | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
726 of LOOP_NB. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
727 |
0 | 728 Description (provided for completeness, for those who read code in |
729 a plane, and for my poor 62 bytes brain that would have forgotten | |
730 all this in the next two or three months): | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
731 |
0 | 732 The algorithm of translation of programs from the SSA representation |
733 into the chrecs syntax is based on a pattern matching. After having | |
734 reconstructed the overall tree expression for a loop, there are only | |
735 two cases that can arise: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
736 |
0 | 737 1. a = loop-phi (init, a + expr) |
738 2. a = loop-phi (init, expr) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
739 |
0 | 740 where EXPR is either a scalar constant with respect to the analyzed |
741 loop (this is a degree 0 polynomial), or an expression containing | |
742 other loop-phi definitions (these are higher degree polynomials). | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
743 |
0 | 744 Examples: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
745 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
746 1. |
0 | 747 | init = ... |
748 | loop_1 | |
749 | a = phi (init, a + 5) | |
750 | endloop | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
751 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
752 2. |
0 | 753 | inita = ... |
754 | initb = ... | |
755 | loop_1 | |
756 | a = phi (inita, 2 * b + 3) | |
757 | b = phi (initb, b + 1) | |
758 | endloop | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
759 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
760 For the first case, the semantics of the SSA representation is: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
761 |
0 | 762 | a (x) = init + \sum_{j = 0}^{x - 1} expr (j) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
763 |
0 | 764 that is, there is a loop index "x" that determines the scalar value |
765 of the variable during the loop execution. During the first | |
766 iteration, the value is that of the initial condition INIT, while | |
767 during the subsequent iterations, it is the sum of the initial | |
768 condition with the sum of all the values of EXPR from the initial | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
769 iteration to the before last considered iteration. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
770 |
0 | 771 For the second case, the semantics of the SSA program is: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
772 |
0 | 773 | a (x) = init, if x = 0; |
774 | expr (x - 1), otherwise. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
775 |
0 | 776 The second case corresponds to the PEELED_CHREC, whose syntax is |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
777 close to the syntax of a loop-phi-node: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
778 |
0 | 779 | phi (init, expr) vs. (init, expr)_x |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
780 |
0 | 781 The proof of the translation algorithm for the first case is a |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
782 proof by structural induction based on the degree of EXPR. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
783 |
0 | 784 Degree 0: |
785 When EXPR is a constant with respect to the analyzed loop, or in | |
786 other words when EXPR is a polynomial of degree 0, the evolution of | |
787 the variable A in the loop is an affine function with an initial | |
788 condition INIT, and a step EXPR. In order to show this, we start | |
789 from the semantics of the SSA representation: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
790 |
0 | 791 f (x) = init + \sum_{j = 0}^{x - 1} expr (j) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
792 |
0 | 793 and since "expr (j)" is a constant with respect to "j", |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
794 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
795 f (x) = init + x * expr |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
796 |
0 | 797 Finally, based on the semantics of the pure sum chrecs, by |
798 identification we get the corresponding chrecs syntax: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
799 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
800 f (x) = init * \binom{x}{0} + expr * \binom{x}{1} |
0 | 801 f (x) -> {init, +, expr}_x |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
802 |
0 | 803 Higher degree: |
804 Suppose that EXPR is a polynomial of degree N with respect to the | |
805 analyzed loop_x for which we have already determined that it is | |
806 written under the chrecs syntax: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
807 |
0 | 808 | expr (x) -> {b_0, +, b_1, +, ..., +, b_{n-1}} (x) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
809 |
0 | 810 We start from the semantics of the SSA program: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
811 |
0 | 812 | f (x) = init + \sum_{j = 0}^{x - 1} expr (j) |
813 | | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
814 | f (x) = init + \sum_{j = 0}^{x - 1} |
0 | 815 | (b_0 * \binom{j}{0} + ... + b_{n-1} * \binom{j}{n-1}) |
816 | | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
817 | f (x) = init + \sum_{j = 0}^{x - 1} |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
818 | \sum_{k = 0}^{n - 1} (b_k * \binom{j}{k}) |
0 | 819 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
820 | f (x) = init + \sum_{k = 0}^{n - 1} |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
821 | (b_k * \sum_{j = 0}^{x - 1} \binom{j}{k}) |
0 | 822 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
823 | f (x) = init + \sum_{k = 0}^{n - 1} |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
824 | (b_k * \binom{x}{k + 1}) |
0 | 825 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
826 | f (x) = init + b_0 * \binom{x}{1} + ... |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
827 | + b_{n-1} * \binom{x}{n} |
0 | 828 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
829 | f (x) = init * \binom{x}{0} + b_0 * \binom{x}{1} + ... |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
830 | + b_{n-1} * \binom{x}{n} |
0 | 831 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
832 |
0 | 833 And finally from the definition of the chrecs syntax, we identify: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
834 | f (x) -> {init, +, b_0, +, ..., +, b_{n-1}}_x |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
835 |
0 | 836 This shows the mechanism that stands behind the add_to_evolution |
837 function. An important point is that the use of symbolic | |
838 parameters avoids the need of an analysis schedule. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
839 |
0 | 840 Example: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
841 |
0 | 842 | inita = ... |
843 | initb = ... | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
844 | loop_1 |
0 | 845 | a = phi (inita, a + 2 + b) |
846 | b = phi (initb, b + 1) | |
847 | endloop | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
848 |
0 | 849 When analyzing "a", the algorithm keeps "b" symbolically: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
850 |
0 | 851 | a -> {inita, +, 2 + b}_1 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
852 |
0 | 853 Then, after instantiation, the analyzer ends on the evolution: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
854 |
0 | 855 | a -> {inita, +, 2 + initb, +, 1}_1 |
856 | |
857 */ | |
858 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
859 static tree |
0 | 860 add_to_evolution (unsigned loop_nb, tree chrec_before, enum tree_code code, |
861 tree to_add, gimple at_stmt) | |
862 { | |
863 tree type = chrec_type (to_add); | |
864 tree res = NULL_TREE; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
865 |
0 | 866 if (to_add == NULL_TREE) |
867 return chrec_before; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
868 |
0 | 869 /* TO_ADD is either a scalar, or a parameter. TO_ADD is not |
870 instantiated at this point. */ | |
871 if (TREE_CODE (to_add) == POLYNOMIAL_CHREC) | |
872 /* This should not happen. */ | |
873 return chrec_dont_know; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
874 |
0 | 875 if (dump_file && (dump_flags & TDF_DETAILS)) |
876 { | |
877 fprintf (dump_file, "(add_to_evolution \n"); | |
878 fprintf (dump_file, " (loop_nb = %d)\n", loop_nb); | |
879 fprintf (dump_file, " (chrec_before = "); | |
880 print_generic_expr (dump_file, chrec_before, 0); | |
881 fprintf (dump_file, ")\n (to_add = "); | |
882 print_generic_expr (dump_file, to_add, 0); | |
883 fprintf (dump_file, ")\n"); | |
884 } | |
885 | |
886 if (code == MINUS_EXPR) | |
887 to_add = chrec_fold_multiply (type, to_add, SCALAR_FLOAT_TYPE_P (type) | |
888 ? build_real (type, dconstm1) | |
889 : build_int_cst_type (type, -1)); | |
890 | |
891 res = add_to_evolution_1 (loop_nb, chrec_before, to_add, at_stmt); | |
892 | |
893 if (dump_file && (dump_flags & TDF_DETAILS)) | |
894 { | |
895 fprintf (dump_file, " (res = "); | |
896 print_generic_expr (dump_file, res, 0); | |
897 fprintf (dump_file, "))\n"); | |
898 } | |
899 | |
900 return res; | |
901 } | |
902 | |
903 /* Helper function. */ | |
904 | |
905 static inline tree | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
906 set_nb_iterations_in_loop (struct loop *loop, |
0 | 907 tree res) |
908 { | |
909 if (dump_file && (dump_flags & TDF_DETAILS)) | |
910 { | |
911 fprintf (dump_file, " (set_nb_iterations_in_loop = "); | |
912 print_generic_expr (dump_file, res, 0); | |
913 fprintf (dump_file, "))\n"); | |
914 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
915 |
0 | 916 loop->nb_iterations = res; |
917 return res; | |
918 } | |
919 | |
920 | |
921 | |
922 /* This section selects the loops that will be good candidates for the | |
923 scalar evolution analysis. For the moment, greedily select all the | |
924 loop nests we could analyze. */ | |
925 | |
926 /* For a loop with a single exit edge, return the COND_EXPR that | |
927 guards the exit edge. If the expression is too difficult to | |
928 analyze, then give up. */ | |
929 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
930 gimple |
0 | 931 get_loop_exit_condition (const struct loop *loop) |
932 { | |
933 gimple res = NULL; | |
934 edge exit_edge = single_exit (loop); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
935 |
0 | 936 if (dump_file && (dump_flags & TDF_DETAILS)) |
937 fprintf (dump_file, "(get_loop_exit_condition \n "); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
938 |
0 | 939 if (exit_edge) |
940 { | |
941 gimple stmt; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
942 |
0 | 943 stmt = last_stmt (exit_edge->src); |
944 if (gimple_code (stmt) == GIMPLE_COND) | |
945 res = stmt; | |
946 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
947 |
0 | 948 if (dump_file && (dump_flags & TDF_DETAILS)) |
949 { | |
950 print_gimple_stmt (dump_file, res, 0, 0); | |
951 fprintf (dump_file, ")\n"); | |
952 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
953 |
0 | 954 return res; |
955 } | |
956 | |
957 /* Recursively determine and enqueue the exit conditions for a loop. */ | |
958 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
959 static void |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
960 get_exit_conditions_rec (struct loop *loop, |
0 | 961 VEC(gimple,heap) **exit_conditions) |
962 { | |
963 if (!loop) | |
964 return; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
965 |
0 | 966 /* Recurse on the inner loops, then on the next (sibling) loops. */ |
967 get_exit_conditions_rec (loop->inner, exit_conditions); | |
968 get_exit_conditions_rec (loop->next, exit_conditions); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
969 |
0 | 970 if (single_exit (loop)) |
971 { | |
972 gimple loop_condition = get_loop_exit_condition (loop); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
973 |
0 | 974 if (loop_condition) |
975 VEC_safe_push (gimple, heap, *exit_conditions, loop_condition); | |
976 } | |
977 } | |
978 | |
979 /* Select the candidate loop nests for the analysis. This function | |
980 initializes the EXIT_CONDITIONS array. */ | |
981 | |
982 static void | |
983 select_loops_exit_conditions (VEC(gimple,heap) **exit_conditions) | |
984 { | |
985 struct loop *function_body = current_loops->tree_root; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
986 |
0 | 987 get_exit_conditions_rec (function_body->inner, exit_conditions); |
988 } | |
989 | |
990 | |
991 /* Depth first search algorithm. */ | |
992 | |
993 typedef enum t_bool { | |
994 t_false, | |
995 t_true, | |
996 t_dont_know | |
997 } t_bool; | |
998 | |
999 | |
1000 static t_bool follow_ssa_edge (struct loop *loop, gimple, gimple, tree *, int); | |
1001 | |
1002 /* Follow the ssa edge into the binary expression RHS0 CODE RHS1. | |
1003 Return true if the strongly connected component has been found. */ | |
1004 | |
1005 static t_bool | |
1006 follow_ssa_edge_binary (struct loop *loop, gimple at_stmt, | |
1007 tree type, tree rhs0, enum tree_code code, tree rhs1, | |
1008 gimple halting_phi, tree *evolution_of_loop, int limit) | |
1009 { | |
1010 t_bool res = t_false; | |
1011 tree evol; | |
1012 | |
1013 switch (code) | |
1014 { | |
1015 case POINTER_PLUS_EXPR: | |
1016 case PLUS_EXPR: | |
1017 if (TREE_CODE (rhs0) == SSA_NAME) | |
1018 { | |
1019 if (TREE_CODE (rhs1) == SSA_NAME) | |
1020 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1021 /* Match an assignment under the form: |
0 | 1022 "a = b + c". */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1023 |
0 | 1024 /* We want only assignments of form "name + name" contribute to |
1025 LIMIT, as the other cases do not necessarily contribute to | |
1026 the complexity of the expression. */ | |
1027 limit++; | |
1028 | |
1029 evol = *evolution_of_loop; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1030 res = follow_ssa_edge |
0 | 1031 (loop, SSA_NAME_DEF_STMT (rhs0), halting_phi, &evol, limit); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1032 |
0 | 1033 if (res == t_true) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1034 *evolution_of_loop = add_to_evolution |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1035 (loop->num, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1036 chrec_convert (type, evol, at_stmt), |
0 | 1037 code, rhs1, at_stmt); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1038 |
0 | 1039 else if (res == t_false) |
1040 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1041 res = follow_ssa_edge |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1042 (loop, SSA_NAME_DEF_STMT (rhs1), halting_phi, |
0 | 1043 evolution_of_loop, limit); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1044 |
0 | 1045 if (res == t_true) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1046 *evolution_of_loop = add_to_evolution |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1047 (loop->num, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1048 chrec_convert (type, *evolution_of_loop, at_stmt), |
0 | 1049 code, rhs0, at_stmt); |
1050 | |
1051 else if (res == t_dont_know) | |
1052 *evolution_of_loop = chrec_dont_know; | |
1053 } | |
1054 | |
1055 else if (res == t_dont_know) | |
1056 *evolution_of_loop = chrec_dont_know; | |
1057 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1058 |
0 | 1059 else |
1060 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1061 /* Match an assignment under the form: |
0 | 1062 "a = b + ...". */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1063 res = follow_ssa_edge |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1064 (loop, SSA_NAME_DEF_STMT (rhs0), halting_phi, |
0 | 1065 evolution_of_loop, limit); |
1066 if (res == t_true) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1067 *evolution_of_loop = add_to_evolution |
0 | 1068 (loop->num, chrec_convert (type, *evolution_of_loop, |
1069 at_stmt), | |
1070 code, rhs1, at_stmt); | |
1071 | |
1072 else if (res == t_dont_know) | |
1073 *evolution_of_loop = chrec_dont_know; | |
1074 } | |
1075 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1076 |
0 | 1077 else if (TREE_CODE (rhs1) == SSA_NAME) |
1078 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1079 /* Match an assignment under the form: |
0 | 1080 "a = ... + c". */ |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1081 res = follow_ssa_edge |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1082 (loop, SSA_NAME_DEF_STMT (rhs1), halting_phi, |
0 | 1083 evolution_of_loop, limit); |
1084 if (res == t_true) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1085 *evolution_of_loop = add_to_evolution |
0 | 1086 (loop->num, chrec_convert (type, *evolution_of_loop, |
1087 at_stmt), | |
1088 code, rhs0, at_stmt); | |
1089 | |
1090 else if (res == t_dont_know) | |
1091 *evolution_of_loop = chrec_dont_know; | |
1092 } | |
1093 | |
1094 else | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1095 /* Otherwise, match an assignment under the form: |
0 | 1096 "a = ... + ...". */ |
1097 /* And there is nothing to do. */ | |
1098 res = t_false; | |
1099 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1100 |
0 | 1101 case MINUS_EXPR: |
1102 /* This case is under the form "opnd0 = rhs0 - rhs1". */ | |
1103 if (TREE_CODE (rhs0) == SSA_NAME) | |
1104 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1105 /* Match an assignment under the form: |
0 | 1106 "a = b - ...". */ |
1107 | |
1108 /* We want only assignments of form "name - name" contribute to | |
1109 LIMIT, as the other cases do not necessarily contribute to | |
1110 the complexity of the expression. */ | |
1111 if (TREE_CODE (rhs1) == SSA_NAME) | |
1112 limit++; | |
1113 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1114 res = follow_ssa_edge (loop, SSA_NAME_DEF_STMT (rhs0), halting_phi, |
0 | 1115 evolution_of_loop, limit); |
1116 if (res == t_true) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1117 *evolution_of_loop = add_to_evolution |
0 | 1118 (loop->num, chrec_convert (type, *evolution_of_loop, at_stmt), |
1119 MINUS_EXPR, rhs1, at_stmt); | |
1120 | |
1121 else if (res == t_dont_know) | |
1122 *evolution_of_loop = chrec_dont_know; | |
1123 } | |
1124 else | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1125 /* Otherwise, match an assignment under the form: |
0 | 1126 "a = ... - ...". */ |
1127 /* And there is nothing to do. */ | |
1128 res = t_false; | |
1129 break; | |
1130 | |
1131 default: | |
1132 res = t_false; | |
1133 } | |
1134 | |
1135 return res; | |
1136 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1137 |
0 | 1138 /* Follow the ssa edge into the expression EXPR. |
1139 Return true if the strongly connected component has been found. */ | |
1140 | |
1141 static t_bool | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1142 follow_ssa_edge_expr (struct loop *loop, gimple at_stmt, tree expr, |
0 | 1143 gimple halting_phi, tree *evolution_of_loop, int limit) |
1144 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1145 enum tree_code code = TREE_CODE (expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1146 tree type = TREE_TYPE (expr), rhs0, rhs1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1147 t_bool res; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1148 |
0 | 1149 /* The EXPR is one of the following cases: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1150 - an SSA_NAME, |
0 | 1151 - an INTEGER_CST, |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1152 - a PLUS_EXPR, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1153 - a POINTER_PLUS_EXPR, |
0 | 1154 - a MINUS_EXPR, |
1155 - an ASSERT_EXPR, | |
1156 - other cases are not yet handled. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1157 |
0 | 1158 switch (code) |
1159 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1160 CASE_CONVERT: |
0 | 1161 /* This assignment is under the form "a_1 = (cast) rhs. */ |
1162 res = follow_ssa_edge_expr (loop, at_stmt, TREE_OPERAND (expr, 0), | |
1163 halting_phi, evolution_of_loop, limit); | |
1164 *evolution_of_loop = chrec_convert (type, *evolution_of_loop, at_stmt); | |
1165 break; | |
1166 | |
1167 case INTEGER_CST: | |
1168 /* This assignment is under the form "a_1 = 7". */ | |
1169 res = t_false; | |
1170 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1171 |
0 | 1172 case SSA_NAME: |
1173 /* This assignment is under the form: "a_1 = b_2". */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1174 res = follow_ssa_edge |
0 | 1175 (loop, SSA_NAME_DEF_STMT (expr), halting_phi, evolution_of_loop, limit); |
1176 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1177 |
0 | 1178 case POINTER_PLUS_EXPR: |
1179 case PLUS_EXPR: | |
1180 case MINUS_EXPR: | |
1181 /* This case is under the form "rhs0 +- rhs1". */ | |
1182 rhs0 = TREE_OPERAND (expr, 0); | |
1183 rhs1 = TREE_OPERAND (expr, 1); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1184 type = TREE_TYPE (rhs0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1185 STRIP_USELESS_TYPE_CONVERSION (rhs0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1186 STRIP_USELESS_TYPE_CONVERSION (rhs1); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1187 res = follow_ssa_edge_binary (loop, at_stmt, type, rhs0, code, rhs1, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1188 halting_phi, evolution_of_loop, limit); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1189 break; |
0 | 1190 |
1191 case ASSERT_EXPR: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1192 /* This assignment is of the form: "a_1 = ASSERT_EXPR <a_2, ...>" |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1193 It must be handled as a copy assignment of the form a_1 = a_2. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1194 rhs0 = ASSERT_EXPR_VAR (expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1195 if (TREE_CODE (rhs0) == SSA_NAME) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1196 res = follow_ssa_edge (loop, SSA_NAME_DEF_STMT (rhs0), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1197 halting_phi, evolution_of_loop, limit); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1198 else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1199 res = t_false; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1200 break; |
0 | 1201 |
1202 default: | |
1203 res = t_false; | |
1204 break; | |
1205 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1206 |
0 | 1207 return res; |
1208 } | |
1209 | |
1210 /* Follow the ssa edge into the right hand side of an assignment STMT. | |
1211 Return true if the strongly connected component has been found. */ | |
1212 | |
1213 static t_bool | |
1214 follow_ssa_edge_in_rhs (struct loop *loop, gimple stmt, | |
1215 gimple halting_phi, tree *evolution_of_loop, int limit) | |
1216 { | |
1217 enum tree_code code = gimple_assign_rhs_code (stmt); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1218 tree type = gimple_expr_type (stmt), rhs1, rhs2; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1219 t_bool res; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1220 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1221 switch (code) |
0 | 1222 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1223 CASE_CONVERT: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1224 /* This assignment is under the form "a_1 = (cast) rhs. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1225 res = follow_ssa_edge_expr (loop, stmt, gimple_assign_rhs1 (stmt), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1226 halting_phi, evolution_of_loop, limit); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1227 *evolution_of_loop = chrec_convert (type, *evolution_of_loop, stmt); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1228 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1229 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1230 case POINTER_PLUS_EXPR: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1231 case PLUS_EXPR: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1232 case MINUS_EXPR: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1233 rhs1 = gimple_assign_rhs1 (stmt); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1234 rhs2 = gimple_assign_rhs2 (stmt); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1235 type = TREE_TYPE (rhs1); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1236 res = follow_ssa_edge_binary (loop, stmt, type, rhs1, code, rhs2, |
0 | 1237 halting_phi, evolution_of_loop, limit); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1238 break; |
0 | 1239 |
1240 default: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1241 if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1242 res = follow_ssa_edge_expr (loop, stmt, gimple_assign_rhs1 (stmt), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1243 halting_phi, evolution_of_loop, limit); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1244 else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1245 res = t_false; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1246 break; |
0 | 1247 } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1248 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1249 return res; |
0 | 1250 } |
1251 | |
1252 /* Checks whether the I-th argument of a PHI comes from a backedge. */ | |
1253 | |
1254 static bool | |
1255 backedge_phi_arg_p (gimple phi, int i) | |
1256 { | |
1257 const_edge e = gimple_phi_arg_edge (phi, i); | |
1258 | |
1259 /* We would in fact like to test EDGE_DFS_BACK here, but we do not care | |
1260 about updating it anywhere, and this should work as well most of the | |
1261 time. */ | |
1262 if (e->flags & EDGE_IRREDUCIBLE_LOOP) | |
1263 return true; | |
1264 | |
1265 return false; | |
1266 } | |
1267 | |
1268 /* Helper function for one branch of the condition-phi-node. Return | |
1269 true if the strongly connected component has been found following | |
1270 this path. */ | |
1271 | |
1272 static inline t_bool | |
1273 follow_ssa_edge_in_condition_phi_branch (int i, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1274 struct loop *loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1275 gimple condition_phi, |
0 | 1276 gimple halting_phi, |
1277 tree *evolution_of_branch, | |
1278 tree init_cond, int limit) | |
1279 { | |
1280 tree branch = PHI_ARG_DEF (condition_phi, i); | |
1281 *evolution_of_branch = chrec_dont_know; | |
1282 | |
1283 /* Do not follow back edges (they must belong to an irreducible loop, which | |
1284 we really do not want to worry about). */ | |
1285 if (backedge_phi_arg_p (condition_phi, i)) | |
1286 return t_false; | |
1287 | |
1288 if (TREE_CODE (branch) == SSA_NAME) | |
1289 { | |
1290 *evolution_of_branch = init_cond; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1291 return follow_ssa_edge (loop, SSA_NAME_DEF_STMT (branch), halting_phi, |
0 | 1292 evolution_of_branch, limit); |
1293 } | |
1294 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1295 /* This case occurs when one of the condition branches sets |
0 | 1296 the variable to a constant: i.e. a phi-node like |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1297 "a_2 = PHI <a_7(5), 2(6)>;". |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1298 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1299 FIXME: This case have to be refined correctly: |
0 | 1300 in some cases it is possible to say something better than |
1301 chrec_dont_know, for example using a wrap-around notation. */ | |
1302 return t_false; | |
1303 } | |
1304 | |
1305 /* This function merges the branches of a condition-phi-node in a | |
1306 loop. */ | |
1307 | |
1308 static t_bool | |
1309 follow_ssa_edge_in_condition_phi (struct loop *loop, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1310 gimple condition_phi, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1311 gimple halting_phi, |
0 | 1312 tree *evolution_of_loop, int limit) |
1313 { | |
1314 int i, n; | |
1315 tree init = *evolution_of_loop; | |
1316 tree evolution_of_branch; | |
1317 t_bool res = follow_ssa_edge_in_condition_phi_branch (0, loop, condition_phi, | |
1318 halting_phi, | |
1319 &evolution_of_branch, | |
1320 init, limit); | |
1321 if (res == t_false || res == t_dont_know) | |
1322 return res; | |
1323 | |
1324 *evolution_of_loop = evolution_of_branch; | |
1325 | |
1326 n = gimple_phi_num_args (condition_phi); | |
1327 for (i = 1; i < n; i++) | |
1328 { | |
1329 /* Quickly give up when the evolution of one of the branches is | |
1330 not known. */ | |
1331 if (*evolution_of_loop == chrec_dont_know) | |
1332 return t_true; | |
1333 | |
19
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
1334 /* Increase the limit by the PHI argument number to avoid exponential |
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
1335 time and memory complexity. */ |
0 | 1336 res = follow_ssa_edge_in_condition_phi_branch (i, loop, condition_phi, |
1337 halting_phi, | |
1338 &evolution_of_branch, | |
19
58ad6c70ea60
update gcc from 4.4.0 to 4.4.1.
kent@firefly.cr.ie.u-ryukyu.ac.jp
parents:
0
diff
changeset
|
1339 init, limit + i); |
0 | 1340 if (res == t_false || res == t_dont_know) |
1341 return res; | |
1342 | |
1343 *evolution_of_loop = chrec_merge (*evolution_of_loop, | |
1344 evolution_of_branch); | |
1345 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1346 |
0 | 1347 return t_true; |
1348 } | |
1349 | |
1350 /* Follow an SSA edge in an inner loop. It computes the overall | |
1351 effect of the loop, and following the symbolic initial conditions, | |
1352 it follows the edges in the parent loop. The inner loop is | |
1353 considered as a single statement. */ | |
1354 | |
1355 static t_bool | |
1356 follow_ssa_edge_inner_loop_phi (struct loop *outer_loop, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1357 gimple loop_phi_node, |
0 | 1358 gimple halting_phi, |
1359 tree *evolution_of_loop, int limit) | |
1360 { | |
1361 struct loop *loop = loop_containing_stmt (loop_phi_node); | |
1362 tree ev = analyze_scalar_evolution (loop, PHI_RESULT (loop_phi_node)); | |
1363 | |
1364 /* Sometimes, the inner loop is too difficult to analyze, and the | |
1365 result of the analysis is a symbolic parameter. */ | |
1366 if (ev == PHI_RESULT (loop_phi_node)) | |
1367 { | |
1368 t_bool res = t_false; | |
1369 int i, n = gimple_phi_num_args (loop_phi_node); | |
1370 | |
1371 for (i = 0; i < n; i++) | |
1372 { | |
1373 tree arg = PHI_ARG_DEF (loop_phi_node, i); | |
1374 basic_block bb; | |
1375 | |
1376 /* Follow the edges that exit the inner loop. */ | |
1377 bb = gimple_phi_arg_edge (loop_phi_node, i)->src; | |
1378 if (!flow_bb_inside_loop_p (loop, bb)) | |
1379 res = follow_ssa_edge_expr (outer_loop, loop_phi_node, | |
1380 arg, halting_phi, | |
1381 evolution_of_loop, limit); | |
1382 if (res == t_true) | |
1383 break; | |
1384 } | |
1385 | |
1386 /* If the path crosses this loop-phi, give up. */ | |
1387 if (res == t_true) | |
1388 *evolution_of_loop = chrec_dont_know; | |
1389 | |
1390 return res; | |
1391 } | |
1392 | |
1393 /* Otherwise, compute the overall effect of the inner loop. */ | |
1394 ev = compute_overall_effect_of_inner_loop (loop, ev); | |
1395 return follow_ssa_edge_expr (outer_loop, loop_phi_node, ev, halting_phi, | |
1396 evolution_of_loop, limit); | |
1397 } | |
1398 | |
1399 /* Follow an SSA edge from a loop-phi-node to itself, constructing a | |
1400 path that is analyzed on the return walk. */ | |
1401 | |
1402 static t_bool | |
1403 follow_ssa_edge (struct loop *loop, gimple def, gimple halting_phi, | |
1404 tree *evolution_of_loop, int limit) | |
1405 { | |
1406 struct loop *def_loop; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1407 |
0 | 1408 if (gimple_nop_p (def)) |
1409 return t_false; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1410 |
0 | 1411 /* Give up if the path is longer than the MAX that we allow. */ |
1412 if (limit > PARAM_VALUE (PARAM_SCEV_MAX_EXPR_SIZE)) | |
1413 return t_dont_know; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1414 |
0 | 1415 def_loop = loop_containing_stmt (def); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1416 |
0 | 1417 switch (gimple_code (def)) |
1418 { | |
1419 case GIMPLE_PHI: | |
1420 if (!loop_phi_node_p (def)) | |
1421 /* DEF is a condition-phi-node. Follow the branches, and | |
1422 record their evolutions. Finally, merge the collected | |
1423 information and set the approximation to the main | |
1424 variable. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1425 return follow_ssa_edge_in_condition_phi |
0 | 1426 (loop, def, halting_phi, evolution_of_loop, limit); |
1427 | |
1428 /* When the analyzed phi is the halting_phi, the | |
1429 depth-first search is over: we have found a path from | |
1430 the halting_phi to itself in the loop. */ | |
1431 if (def == halting_phi) | |
1432 return t_true; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1433 |
0 | 1434 /* Otherwise, the evolution of the HALTING_PHI depends |
1435 on the evolution of another loop-phi-node, i.e. the | |
1436 evolution function is a higher degree polynomial. */ | |
1437 if (def_loop == loop) | |
1438 return t_false; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1439 |
0 | 1440 /* Inner loop. */ |
1441 if (flow_loop_nested_p (loop, def_loop)) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1442 return follow_ssa_edge_inner_loop_phi |
0 | 1443 (loop, def, halting_phi, evolution_of_loop, limit + 1); |
1444 | |
1445 /* Outer loop. */ | |
1446 return t_false; | |
1447 | |
1448 case GIMPLE_ASSIGN: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1449 return follow_ssa_edge_in_rhs (loop, def, halting_phi, |
0 | 1450 evolution_of_loop, limit); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1451 |
0 | 1452 default: |
1453 /* At this level of abstraction, the program is just a set | |
1454 of GIMPLE_ASSIGNs and PHI_NODEs. In principle there is no | |
1455 other node to be handled. */ | |
1456 return t_false; | |
1457 } | |
1458 } | |
1459 | |
1460 | |
1461 | |
1462 /* Given a LOOP_PHI_NODE, this function determines the evolution | |
1463 function from LOOP_PHI_NODE to LOOP_PHI_NODE in the loop. */ | |
1464 | |
1465 static tree | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1466 analyze_evolution_in_loop (gimple loop_phi_node, |
0 | 1467 tree init_cond) |
1468 { | |
1469 int i, n = gimple_phi_num_args (loop_phi_node); | |
1470 tree evolution_function = chrec_not_analyzed_yet; | |
1471 struct loop *loop = loop_containing_stmt (loop_phi_node); | |
1472 basic_block bb; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1473 |
0 | 1474 if (dump_file && (dump_flags & TDF_DETAILS)) |
1475 { | |
1476 fprintf (dump_file, "(analyze_evolution_in_loop \n"); | |
1477 fprintf (dump_file, " (loop_phi_node = "); | |
1478 print_gimple_stmt (dump_file, loop_phi_node, 0, 0); | |
1479 fprintf (dump_file, ")\n"); | |
1480 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1481 |
0 | 1482 for (i = 0; i < n; i++) |
1483 { | |
1484 tree arg = PHI_ARG_DEF (loop_phi_node, i); | |
1485 gimple ssa_chain; | |
1486 tree ev_fn; | |
1487 t_bool res; | |
1488 | |
1489 /* Select the edges that enter the loop body. */ | |
1490 bb = gimple_phi_arg_edge (loop_phi_node, i)->src; | |
1491 if (!flow_bb_inside_loop_p (loop, bb)) | |
1492 continue; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1493 |
0 | 1494 if (TREE_CODE (arg) == SSA_NAME) |
1495 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1496 bool val = false; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1497 |
0 | 1498 ssa_chain = SSA_NAME_DEF_STMT (arg); |
1499 | |
1500 /* Pass in the initial condition to the follow edge function. */ | |
1501 ev_fn = init_cond; | |
1502 res = follow_ssa_edge (loop, ssa_chain, loop_phi_node, &ev_fn, 0); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1503 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1504 /* If ev_fn has no evolution in the inner loop, and the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1505 init_cond is not equal to ev_fn, then we have an |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1506 ambiguity between two possible values, as we cannot know |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1507 the number of iterations at this point. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1508 if (TREE_CODE (ev_fn) != POLYNOMIAL_CHREC |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1509 && no_evolution_in_loop_p (ev_fn, loop->num, &val) && val |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1510 && !operand_equal_p (init_cond, ev_fn, 0)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1511 ev_fn = chrec_dont_know; |
0 | 1512 } |
1513 else | |
1514 res = t_false; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1515 |
0 | 1516 /* When it is impossible to go back on the same |
1517 loop_phi_node by following the ssa edges, the | |
1518 evolution is represented by a peeled chrec, i.e. the | |
1519 first iteration, EV_FN has the value INIT_COND, then | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1520 all the other iterations it has the value of ARG. |
0 | 1521 For the moment, PEELED_CHREC nodes are not built. */ |
1522 if (res != t_true) | |
1523 ev_fn = chrec_dont_know; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1524 |
0 | 1525 /* When there are multiple back edges of the loop (which in fact never |
1526 happens currently, but nevertheless), merge their evolutions. */ | |
1527 evolution_function = chrec_merge (evolution_function, ev_fn); | |
1528 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1529 |
0 | 1530 if (dump_file && (dump_flags & TDF_DETAILS)) |
1531 { | |
1532 fprintf (dump_file, " (evolution_function = "); | |
1533 print_generic_expr (dump_file, evolution_function, 0); | |
1534 fprintf (dump_file, "))\n"); | |
1535 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1536 |
0 | 1537 return evolution_function; |
1538 } | |
1539 | |
1540 /* Given a loop-phi-node, return the initial conditions of the | |
1541 variable on entry of the loop. When the CCP has propagated | |
1542 constants into the loop-phi-node, the initial condition is | |
1543 instantiated, otherwise the initial condition is kept symbolic. | |
1544 This analyzer does not analyze the evolution outside the current | |
1545 loop, and leaves this task to the on-demand tree reconstructor. */ | |
1546 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1547 static tree |
0 | 1548 analyze_initial_condition (gimple loop_phi_node) |
1549 { | |
1550 int i, n; | |
1551 tree init_cond = chrec_not_analyzed_yet; | |
1552 struct loop *loop = loop_containing_stmt (loop_phi_node); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1553 |
0 | 1554 if (dump_file && (dump_flags & TDF_DETAILS)) |
1555 { | |
1556 fprintf (dump_file, "(analyze_initial_condition \n"); | |
1557 fprintf (dump_file, " (loop_phi_node = \n"); | |
1558 print_gimple_stmt (dump_file, loop_phi_node, 0, 0); | |
1559 fprintf (dump_file, ")\n"); | |
1560 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1561 |
0 | 1562 n = gimple_phi_num_args (loop_phi_node); |
1563 for (i = 0; i < n; i++) | |
1564 { | |
1565 tree branch = PHI_ARG_DEF (loop_phi_node, i); | |
1566 basic_block bb = gimple_phi_arg_edge (loop_phi_node, i)->src; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1567 |
0 | 1568 /* When the branch is oriented to the loop's body, it does |
1569 not contribute to the initial condition. */ | |
1570 if (flow_bb_inside_loop_p (loop, bb)) | |
1571 continue; | |
1572 | |
1573 if (init_cond == chrec_not_analyzed_yet) | |
1574 { | |
1575 init_cond = branch; | |
1576 continue; | |
1577 } | |
1578 | |
1579 if (TREE_CODE (branch) == SSA_NAME) | |
1580 { | |
1581 init_cond = chrec_dont_know; | |
1582 break; | |
1583 } | |
1584 | |
1585 init_cond = chrec_merge (init_cond, branch); | |
1586 } | |
1587 | |
1588 /* Ooops -- a loop without an entry??? */ | |
1589 if (init_cond == chrec_not_analyzed_yet) | |
1590 init_cond = chrec_dont_know; | |
1591 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1592 /* During early loop unrolling we do not have fully constant propagated IL. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1593 Handle degenerate PHIs here to not miss important unrollings. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1594 if (TREE_CODE (init_cond) == SSA_NAME) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1595 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1596 gimple def = SSA_NAME_DEF_STMT (init_cond); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1597 tree res; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1598 if (gimple_code (def) == GIMPLE_PHI |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1599 && (res = degenerate_phi_result (def)) != NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1600 /* Only allow invariants here, otherwise we may break |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1601 loop-closed SSA form. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1602 && is_gimple_min_invariant (res)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1603 init_cond = res; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1604 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1605 |
0 | 1606 if (dump_file && (dump_flags & TDF_DETAILS)) |
1607 { | |
1608 fprintf (dump_file, " (init_cond = "); | |
1609 print_generic_expr (dump_file, init_cond, 0); | |
1610 fprintf (dump_file, "))\n"); | |
1611 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1612 |
0 | 1613 return init_cond; |
1614 } | |
1615 | |
1616 /* Analyze the scalar evolution for LOOP_PHI_NODE. */ | |
1617 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1618 static tree |
0 | 1619 interpret_loop_phi (struct loop *loop, gimple loop_phi_node) |
1620 { | |
1621 tree res; | |
1622 struct loop *phi_loop = loop_containing_stmt (loop_phi_node); | |
1623 tree init_cond; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1624 |
0 | 1625 if (phi_loop != loop) |
1626 { | |
1627 struct loop *subloop; | |
1628 tree evolution_fn = analyze_scalar_evolution | |
1629 (phi_loop, PHI_RESULT (loop_phi_node)); | |
1630 | |
1631 /* Dive one level deeper. */ | |
1632 subloop = superloop_at_depth (phi_loop, loop_depth (loop) + 1); | |
1633 | |
1634 /* Interpret the subloop. */ | |
1635 res = compute_overall_effect_of_inner_loop (subloop, evolution_fn); | |
1636 return res; | |
1637 } | |
1638 | |
1639 /* Otherwise really interpret the loop phi. */ | |
1640 init_cond = analyze_initial_condition (loop_phi_node); | |
1641 res = analyze_evolution_in_loop (loop_phi_node, init_cond); | |
1642 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1643 /* Verify we maintained the correct initial condition throughout |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1644 possible conversions in the SSA chain. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1645 if (res != chrec_dont_know) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1646 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1647 tree new_init = res; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1648 if (CONVERT_EXPR_P (res) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1649 && TREE_CODE (TREE_OPERAND (res, 0)) == POLYNOMIAL_CHREC) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1650 new_init = fold_convert (TREE_TYPE (res), |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1651 CHREC_LEFT (TREE_OPERAND (res, 0))); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1652 else if (TREE_CODE (res) == POLYNOMIAL_CHREC) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1653 new_init = CHREC_LEFT (res); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1654 STRIP_USELESS_TYPE_CONVERSION (new_init); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1655 gcc_assert (TREE_CODE (new_init) != POLYNOMIAL_CHREC); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1656 if (!operand_equal_p (init_cond, new_init, 0)) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1657 return chrec_dont_know; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1658 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1659 |
0 | 1660 return res; |
1661 } | |
1662 | |
1663 /* This function merges the branches of a condition-phi-node, | |
1664 contained in the outermost loop, and whose arguments are already | |
1665 analyzed. */ | |
1666 | |
1667 static tree | |
1668 interpret_condition_phi (struct loop *loop, gimple condition_phi) | |
1669 { | |
1670 int i, n = gimple_phi_num_args (condition_phi); | |
1671 tree res = chrec_not_analyzed_yet; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1672 |
0 | 1673 for (i = 0; i < n; i++) |
1674 { | |
1675 tree branch_chrec; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1676 |
0 | 1677 if (backedge_phi_arg_p (condition_phi, i)) |
1678 { | |
1679 res = chrec_dont_know; | |
1680 break; | |
1681 } | |
1682 | |
1683 branch_chrec = analyze_scalar_evolution | |
1684 (loop, PHI_ARG_DEF (condition_phi, i)); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1685 |
0 | 1686 res = chrec_merge (res, branch_chrec); |
1687 } | |
1688 | |
1689 return res; | |
1690 } | |
1691 | |
1692 /* Interpret the operation RHS1 OP RHS2. If we didn't | |
1693 analyze this node before, follow the definitions until ending | |
1694 either on an analyzed GIMPLE_ASSIGN, or on a loop-phi-node. On the | |
1695 return path, this function propagates evolutions (ala constant copy | |
1696 propagation). OPND1 is not a GIMPLE expression because we could | |
1697 analyze the effect of an inner loop: see interpret_loop_phi. */ | |
1698 | |
1699 static tree | |
1700 interpret_rhs_expr (struct loop *loop, gimple at_stmt, | |
1701 tree type, tree rhs1, enum tree_code code, tree rhs2) | |
1702 { | |
1703 tree res, chrec1, chrec2; | |
1704 | |
1705 if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS) | |
1706 { | |
1707 if (is_gimple_min_invariant (rhs1)) | |
1708 return chrec_convert (type, rhs1, at_stmt); | |
1709 | |
1710 if (code == SSA_NAME) | |
1711 return chrec_convert (type, analyze_scalar_evolution (loop, rhs1), | |
1712 at_stmt); | |
1713 | |
1714 if (code == ASSERT_EXPR) | |
1715 { | |
1716 rhs1 = ASSERT_EXPR_VAR (rhs1); | |
1717 return chrec_convert (type, analyze_scalar_evolution (loop, rhs1), | |
1718 at_stmt); | |
1719 } | |
1720 | |
1721 return chrec_dont_know; | |
1722 } | |
1723 | |
1724 switch (code) | |
1725 { | |
1726 case POINTER_PLUS_EXPR: | |
1727 chrec1 = analyze_scalar_evolution (loop, rhs1); | |
1728 chrec2 = analyze_scalar_evolution (loop, rhs2); | |
1729 chrec1 = chrec_convert (type, chrec1, at_stmt); | |
1730 chrec2 = chrec_convert (sizetype, chrec2, at_stmt); | |
1731 res = chrec_fold_plus (type, chrec1, chrec2); | |
1732 break; | |
1733 | |
1734 case PLUS_EXPR: | |
1735 chrec1 = analyze_scalar_evolution (loop, rhs1); | |
1736 chrec2 = analyze_scalar_evolution (loop, rhs2); | |
1737 chrec1 = chrec_convert (type, chrec1, at_stmt); | |
1738 chrec2 = chrec_convert (type, chrec2, at_stmt); | |
1739 res = chrec_fold_plus (type, chrec1, chrec2); | |
1740 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1741 |
0 | 1742 case MINUS_EXPR: |
1743 chrec1 = analyze_scalar_evolution (loop, rhs1); | |
1744 chrec2 = analyze_scalar_evolution (loop, rhs2); | |
1745 chrec1 = chrec_convert (type, chrec1, at_stmt); | |
1746 chrec2 = chrec_convert (type, chrec2, at_stmt); | |
1747 res = chrec_fold_minus (type, chrec1, chrec2); | |
1748 break; | |
1749 | |
1750 case NEGATE_EXPR: | |
1751 chrec1 = analyze_scalar_evolution (loop, rhs1); | |
1752 chrec1 = chrec_convert (type, chrec1, at_stmt); | |
1753 /* TYPE may be integer, real or complex, so use fold_convert. */ | |
1754 res = chrec_fold_multiply (type, chrec1, | |
1755 fold_convert (type, integer_minus_one_node)); | |
1756 break; | |
1757 | |
1758 case BIT_NOT_EXPR: | |
1759 /* Handle ~X as -1 - X. */ | |
1760 chrec1 = analyze_scalar_evolution (loop, rhs1); | |
1761 chrec1 = chrec_convert (type, chrec1, at_stmt); | |
1762 res = chrec_fold_minus (type, | |
1763 fold_convert (type, integer_minus_one_node), | |
1764 chrec1); | |
1765 break; | |
1766 | |
1767 case MULT_EXPR: | |
1768 chrec1 = analyze_scalar_evolution (loop, rhs1); | |
1769 chrec2 = analyze_scalar_evolution (loop, rhs2); | |
1770 chrec1 = chrec_convert (type, chrec1, at_stmt); | |
1771 chrec2 = chrec_convert (type, chrec2, at_stmt); | |
1772 res = chrec_fold_multiply (type, chrec1, chrec2); | |
1773 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1774 |
0 | 1775 CASE_CONVERT: |
1776 chrec1 = analyze_scalar_evolution (loop, rhs1); | |
1777 res = chrec_convert (type, chrec1, at_stmt); | |
1778 break; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1779 |
0 | 1780 default: |
1781 res = chrec_dont_know; | |
1782 break; | |
1783 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1784 |
0 | 1785 return res; |
1786 } | |
1787 | |
1788 /* Interpret the expression EXPR. */ | |
1789 | |
1790 static tree | |
1791 interpret_expr (struct loop *loop, gimple at_stmt, tree expr) | |
1792 { | |
1793 enum tree_code code; | |
1794 tree type = TREE_TYPE (expr), op0, op1; | |
1795 | |
1796 if (automatically_generated_chrec_p (expr)) | |
1797 return expr; | |
1798 | |
1799 if (TREE_CODE (expr) == POLYNOMIAL_CHREC) | |
1800 return chrec_dont_know; | |
1801 | |
1802 extract_ops_from_tree (expr, &code, &op0, &op1); | |
1803 | |
1804 return interpret_rhs_expr (loop, at_stmt, type, | |
1805 op0, code, op1); | |
1806 } | |
1807 | |
1808 /* Interpret the rhs of the assignment STMT. */ | |
1809 | |
1810 static tree | |
1811 interpret_gimple_assign (struct loop *loop, gimple stmt) | |
1812 { | |
1813 tree type = TREE_TYPE (gimple_assign_lhs (stmt)); | |
1814 enum tree_code code = gimple_assign_rhs_code (stmt); | |
1815 | |
1816 return interpret_rhs_expr (loop, stmt, type, | |
1817 gimple_assign_rhs1 (stmt), code, | |
1818 gimple_assign_rhs2 (stmt)); | |
1819 } | |
1820 | |
1821 | |
1822 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1823 /* This section contains all the entry points: |
0 | 1824 - number_of_iterations_in_loop, |
1825 - analyze_scalar_evolution, | |
1826 - instantiate_parameters. | |
1827 */ | |
1828 | |
1829 /* Compute and return the evolution function in WRTO_LOOP, the nearest | |
1830 common ancestor of DEF_LOOP and USE_LOOP. */ | |
1831 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1832 static tree |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1833 compute_scalar_evolution_in_loop (struct loop *wrto_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1834 struct loop *def_loop, |
0 | 1835 tree ev) |
1836 { | |
1837 tree res; | |
1838 if (def_loop == wrto_loop) | |
1839 return ev; | |
1840 | |
1841 def_loop = superloop_at_depth (def_loop, loop_depth (wrto_loop) + 1); | |
1842 res = compute_overall_effect_of_inner_loop (def_loop, ev); | |
1843 | |
1844 return analyze_scalar_evolution_1 (wrto_loop, res, chrec_not_analyzed_yet); | |
1845 } | |
1846 | |
1847 /* Helper recursive function. */ | |
1848 | |
1849 static tree | |
1850 analyze_scalar_evolution_1 (struct loop *loop, tree var, tree res) | |
1851 { | |
1852 tree type = TREE_TYPE (var); | |
1853 gimple def; | |
1854 basic_block bb; | |
1855 struct loop *def_loop; | |
1856 | |
1857 if (loop == NULL || TREE_CODE (type) == VECTOR_TYPE) | |
1858 return chrec_dont_know; | |
1859 | |
1860 if (TREE_CODE (var) != SSA_NAME) | |
1861 return interpret_expr (loop, NULL, var); | |
1862 | |
1863 def = SSA_NAME_DEF_STMT (var); | |
1864 bb = gimple_bb (def); | |
1865 def_loop = bb ? bb->loop_father : NULL; | |
1866 | |
1867 if (bb == NULL | |
1868 || !flow_bb_inside_loop_p (loop, bb)) | |
1869 { | |
1870 /* Keep the symbolic form. */ | |
1871 res = var; | |
1872 goto set_and_end; | |
1873 } | |
1874 | |
1875 if (res != chrec_not_analyzed_yet) | |
1876 { | |
1877 if (loop != bb->loop_father) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1878 res = compute_scalar_evolution_in_loop |
0 | 1879 (find_common_loop (loop, bb->loop_father), bb->loop_father, res); |
1880 | |
1881 goto set_and_end; | |
1882 } | |
1883 | |
1884 if (loop != def_loop) | |
1885 { | |
1886 res = analyze_scalar_evolution_1 (def_loop, var, chrec_not_analyzed_yet); | |
1887 res = compute_scalar_evolution_in_loop (loop, def_loop, res); | |
1888 | |
1889 goto set_and_end; | |
1890 } | |
1891 | |
1892 switch (gimple_code (def)) | |
1893 { | |
1894 case GIMPLE_ASSIGN: | |
1895 res = interpret_gimple_assign (loop, def); | |
1896 break; | |
1897 | |
1898 case GIMPLE_PHI: | |
1899 if (loop_phi_node_p (def)) | |
1900 res = interpret_loop_phi (loop, def); | |
1901 else | |
1902 res = interpret_condition_phi (loop, def); | |
1903 break; | |
1904 | |
1905 default: | |
1906 res = chrec_dont_know; | |
1907 break; | |
1908 } | |
1909 | |
1910 set_and_end: | |
1911 | |
1912 /* Keep the symbolic form. */ | |
1913 if (res == chrec_dont_know) | |
1914 res = var; | |
1915 | |
1916 if (loop == def_loop) | |
1917 set_scalar_evolution (block_before_loop (loop), var, res); | |
1918 | |
1919 return res; | |
1920 } | |
1921 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1922 /* Analyzes and returns the scalar evolution of the ssa_name VAR in |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1923 LOOP. LOOP is the loop in which the variable is used. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1924 |
0 | 1925 Example of use: having a pointer VAR to a SSA_NAME node, STMT a |
1926 pointer to the statement that uses this variable, in order to | |
1927 determine the evolution function of the variable, use the following | |
1928 calls: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1929 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1930 loop_p loop = loop_containing_stmt (stmt); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1931 tree chrec_with_symbols = analyze_scalar_evolution (loop, var); |
0 | 1932 tree chrec_instantiated = instantiate_parameters (loop, chrec_with_symbols); |
1933 */ | |
1934 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1935 tree |
0 | 1936 analyze_scalar_evolution (struct loop *loop, tree var) |
1937 { | |
1938 tree res; | |
1939 | |
1940 if (dump_file && (dump_flags & TDF_DETAILS)) | |
1941 { | |
1942 fprintf (dump_file, "(analyze_scalar_evolution \n"); | |
1943 fprintf (dump_file, " (loop_nb = %d)\n", loop->num); | |
1944 fprintf (dump_file, " (scalar = "); | |
1945 print_generic_expr (dump_file, var, 0); | |
1946 fprintf (dump_file, ")\n"); | |
1947 } | |
1948 | |
1949 res = get_scalar_evolution (block_before_loop (loop), var); | |
1950 res = analyze_scalar_evolution_1 (loop, var, res); | |
1951 | |
1952 if (dump_file && (dump_flags & TDF_DETAILS)) | |
1953 fprintf (dump_file, ")\n"); | |
1954 | |
1955 return res; | |
1956 } | |
1957 | |
1958 /* Analyze scalar evolution of use of VERSION in USE_LOOP with respect to | |
1959 WRTO_LOOP (which should be a superloop of USE_LOOP) | |
1960 | |
1961 FOLDED_CASTS is set to true if resolve_mixers used | |
1962 chrec_convert_aggressive (TODO -- not really, we are way too conservative | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1963 at the moment in order to keep things simple). |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1964 |
0 | 1965 To illustrate the meaning of USE_LOOP and WRTO_LOOP, consider the following |
1966 example: | |
1967 | |
1968 for (i = 0; i < 100; i++) -- loop 1 | |
1969 { | |
1970 for (j = 0; j < 100; j++) -- loop 2 | |
1971 { | |
1972 k1 = i; | |
1973 k2 = j; | |
1974 | |
1975 use2 (k1, k2); | |
1976 | |
1977 for (t = 0; t < 100; t++) -- loop 3 | |
1978 use3 (k1, k2); | |
1979 | |
1980 } | |
1981 use1 (k1, k2); | |
1982 } | |
1983 | |
1984 Both k1 and k2 are invariants in loop3, thus | |
1985 analyze_scalar_evolution_in_loop (loop3, loop3, k1) = k1 | |
1986 analyze_scalar_evolution_in_loop (loop3, loop3, k2) = k2 | |
1987 | |
1988 As they are invariant, it does not matter whether we consider their | |
1989 usage in loop 3 or loop 2, hence | |
1990 analyze_scalar_evolution_in_loop (loop2, loop3, k1) = | |
1991 analyze_scalar_evolution_in_loop (loop2, loop2, k1) = i | |
1992 analyze_scalar_evolution_in_loop (loop2, loop3, k2) = | |
1993 analyze_scalar_evolution_in_loop (loop2, loop2, k2) = [0,+,1]_2 | |
1994 | |
1995 Similarly for their evolutions with respect to loop 1. The values of K2 | |
1996 in the use in loop 2 vary independently on loop 1, thus we cannot express | |
1997 the evolution with respect to loop 1: | |
1998 analyze_scalar_evolution_in_loop (loop1, loop3, k1) = | |
1999 analyze_scalar_evolution_in_loop (loop1, loop2, k1) = [0,+,1]_1 | |
2000 analyze_scalar_evolution_in_loop (loop1, loop3, k2) = | |
2001 analyze_scalar_evolution_in_loop (loop1, loop2, k2) = dont_know | |
2002 | |
2003 The value of k2 in the use in loop 1 is known, though: | |
2004 analyze_scalar_evolution_in_loop (loop1, loop1, k1) = [0,+,1]_1 | |
2005 analyze_scalar_evolution_in_loop (loop1, loop1, k2) = 100 | |
2006 */ | |
2007 | |
2008 static tree | |
2009 analyze_scalar_evolution_in_loop (struct loop *wrto_loop, struct loop *use_loop, | |
2010 tree version, bool *folded_casts) | |
2011 { | |
2012 bool val = false; | |
2013 tree ev = version, tmp; | |
2014 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2015 /* We cannot just do |
0 | 2016 |
2017 tmp = analyze_scalar_evolution (use_loop, version); | |
2018 ev = resolve_mixers (wrto_loop, tmp); | |
2019 | |
2020 as resolve_mixers would query the scalar evolution with respect to | |
2021 wrto_loop. For example, in the situation described in the function | |
2022 comment, suppose that wrto_loop = loop1, use_loop = loop3 and | |
2023 version = k2. Then | |
2024 | |
2025 analyze_scalar_evolution (use_loop, version) = k2 | |
2026 | |
2027 and resolve_mixers (loop1, k2) finds that the value of k2 in loop 1 | |
2028 is 100, which is a wrong result, since we are interested in the | |
2029 value in loop 3. | |
2030 | |
2031 Instead, we need to proceed from use_loop to wrto_loop loop by loop, | |
2032 each time checking that there is no evolution in the inner loop. */ | |
2033 | |
2034 if (folded_casts) | |
2035 *folded_casts = false; | |
2036 while (1) | |
2037 { | |
2038 tmp = analyze_scalar_evolution (use_loop, ev); | |
2039 ev = resolve_mixers (use_loop, tmp); | |
2040 | |
2041 if (folded_casts && tmp != ev) | |
2042 *folded_casts = true; | |
2043 | |
2044 if (use_loop == wrto_loop) | |
2045 return ev; | |
2046 | |
2047 /* If the value of the use changes in the inner loop, we cannot express | |
2048 its value in the outer loop (we might try to return interval chrec, | |
2049 but we do not have a user for it anyway) */ | |
2050 if (!no_evolution_in_loop_p (ev, use_loop->num, &val) | |
2051 || !val) | |
2052 return chrec_dont_know; | |
2053 | |
2054 use_loop = loop_outer (use_loop); | |
2055 } | |
2056 } | |
2057 | |
2058 /* Returns from CACHE the value for VERSION instantiated below | |
2059 INSTANTIATED_BELOW block. */ | |
2060 | |
2061 static tree | |
2062 get_instantiated_value (htab_t cache, basic_block instantiated_below, | |
2063 tree version) | |
2064 { | |
2065 struct scev_info_str *info, pattern; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2066 |
0 | 2067 pattern.var = version; |
2068 pattern.instantiated_below = instantiated_below; | |
2069 info = (struct scev_info_str *) htab_find (cache, &pattern); | |
2070 | |
2071 if (info) | |
2072 return info->chrec; | |
2073 else | |
2074 return NULL_TREE; | |
2075 } | |
2076 | |
2077 /* Sets in CACHE the value of VERSION instantiated below basic block | |
2078 INSTANTIATED_BELOW to VAL. */ | |
2079 | |
2080 static void | |
2081 set_instantiated_value (htab_t cache, basic_block instantiated_below, | |
2082 tree version, tree val) | |
2083 { | |
2084 struct scev_info_str *info, pattern; | |
2085 PTR *slot; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2086 |
0 | 2087 pattern.var = version; |
2088 pattern.instantiated_below = instantiated_below; | |
2089 slot = htab_find_slot (cache, &pattern, INSERT); | |
2090 | |
2091 if (!*slot) | |
2092 *slot = new_scev_info_str (instantiated_below, version); | |
2093 info = (struct scev_info_str *) *slot; | |
2094 info->chrec = val; | |
2095 } | |
2096 | |
2097 /* Return the closed_loop_phi node for VAR. If there is none, return | |
2098 NULL_TREE. */ | |
2099 | |
2100 static tree | |
2101 loop_closed_phi_def (tree var) | |
2102 { | |
2103 struct loop *loop; | |
2104 edge exit; | |
2105 gimple phi; | |
2106 gimple_stmt_iterator psi; | |
2107 | |
2108 if (var == NULL_TREE | |
2109 || TREE_CODE (var) != SSA_NAME) | |
2110 return NULL_TREE; | |
2111 | |
2112 loop = loop_containing_stmt (SSA_NAME_DEF_STMT (var)); | |
2113 exit = single_exit (loop); | |
2114 if (!exit) | |
2115 return NULL_TREE; | |
2116 | |
2117 for (psi = gsi_start_phis (exit->dest); !gsi_end_p (psi); gsi_next (&psi)) | |
2118 { | |
2119 phi = gsi_stmt (psi); | |
2120 if (PHI_ARG_DEF_FROM_EDGE (phi, exit) == var) | |
2121 return PHI_RESULT (phi); | |
2122 } | |
2123 | |
2124 return NULL_TREE; | |
2125 } | |
2126 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2127 static tree instantiate_scev_r (basic_block, struct loop *, tree, bool, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2128 htab_t, int); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2129 |
0 | 2130 /* Analyze all the parameters of the chrec, between INSTANTIATE_BELOW |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2131 and EVOLUTION_LOOP, that were left under a symbolic form. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2132 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2133 CHREC is an SSA_NAME to be instantiated. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2134 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2135 CACHE is the cache of already instantiated values. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2136 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2137 FOLD_CONVERSIONS should be set to true when the conversions that |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2138 may wrap in signed/pointer type are folded, as long as the value of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2139 the chrec is preserved. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2140 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2141 SIZE_EXPR is used for computing the size of the expression to be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2142 instantiated, and to stop if it exceeds some limit. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2143 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2144 static tree |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2145 instantiate_scev_name (basic_block instantiate_below, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2146 struct loop *evolution_loop, tree chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2147 bool fold_conversions, htab_t cache, int size_expr) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2148 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2149 tree res; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2150 struct loop *def_loop; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2151 basic_block def_bb = gimple_bb (SSA_NAME_DEF_STMT (chrec)); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2152 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2153 /* A parameter (or loop invariant and we do not want to include |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2154 evolutions in outer loops), nothing to do. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2155 if (!def_bb |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2156 || loop_depth (def_bb->loop_father) == 0 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2157 || dominated_by_p (CDI_DOMINATORS, instantiate_below, def_bb)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2158 return chrec; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2159 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2160 /* We cache the value of instantiated variable to avoid exponential |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2161 time complexity due to reevaluations. We also store the convenient |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2162 value in the cache in order to prevent infinite recursion -- we do |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2163 not want to instantiate the SSA_NAME if it is in a mixer |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2164 structure. This is used for avoiding the instantiation of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2165 recursively defined functions, such as: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2166 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2167 | a_2 -> {0, +, 1, +, a_2}_1 */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2168 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2169 res = get_instantiated_value (cache, instantiate_below, chrec); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2170 if (res) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2171 return res; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2172 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2173 res = chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2174 set_instantiated_value (cache, instantiate_below, chrec, res); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2175 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2176 def_loop = find_common_loop (evolution_loop, def_bb->loop_father); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2177 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2178 /* If the analysis yields a parametric chrec, instantiate the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2179 result again. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2180 res = analyze_scalar_evolution (def_loop, chrec); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2181 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2182 /* Don't instantiate loop-closed-ssa phi nodes. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2183 if (TREE_CODE (res) == SSA_NAME |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2184 && (loop_containing_stmt (SSA_NAME_DEF_STMT (res)) == NULL |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2185 || (loop_depth (loop_containing_stmt (SSA_NAME_DEF_STMT (res))) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2186 > loop_depth (def_loop)))) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2187 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2188 if (res == chrec) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2189 res = loop_closed_phi_def (chrec); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2190 else |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2191 res = chrec; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2192 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2193 if (res == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2194 || !dominated_by_p (CDI_DOMINATORS, instantiate_below, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2195 gimple_bb (SSA_NAME_DEF_STMT (res)))) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2196 res = chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2197 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2198 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2199 else if (res != chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2200 res = instantiate_scev_r (instantiate_below, evolution_loop, res, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2201 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2202 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2203 /* Store the correct value to the cache. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2204 set_instantiated_value (cache, instantiate_below, chrec, res); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2205 return res; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2206 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2207 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2208 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2209 /* Analyze all the parameters of the chrec, between INSTANTIATE_BELOW |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2210 and EVOLUTION_LOOP, that were left under a symbolic form. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2211 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2212 CHREC is a polynomial chain of recurrence to be instantiated. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2213 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2214 CACHE is the cache of already instantiated values. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2215 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2216 FOLD_CONVERSIONS should be set to true when the conversions that |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2217 may wrap in signed/pointer type are folded, as long as the value of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2218 the chrec is preserved. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2219 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2220 SIZE_EXPR is used for computing the size of the expression to be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2221 instantiated, and to stop if it exceeds some limit. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2222 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2223 static tree |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2224 instantiate_scev_poly (basic_block instantiate_below, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2225 struct loop *evolution_loop, tree chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2226 bool fold_conversions, htab_t cache, int size_expr) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2227 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2228 tree op1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2229 tree op0 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2230 CHREC_LEFT (chrec), fold_conversions, cache, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2231 size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2232 if (op0 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2233 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2234 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2235 op1 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2236 CHREC_RIGHT (chrec), fold_conversions, cache, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2237 size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2238 if (op1 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2239 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2240 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2241 if (CHREC_LEFT (chrec) != op0 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2242 || CHREC_RIGHT (chrec) != op1) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2243 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2244 unsigned var = CHREC_VARIABLE (chrec); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2245 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2246 /* When the instantiated stride or base has an evolution in an |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2247 innermost loop, return chrec_dont_know, as this is not a |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2248 valid SCEV representation. In the reduced testcase for |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2249 PR40281 we would have {0, +, {1, +, 1}_2}_1 that has no |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2250 meaning. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2251 if ((tree_is_chrec (op0) && CHREC_VARIABLE (op0) > var) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2252 || (tree_is_chrec (op1) && CHREC_VARIABLE (op1) > var)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2253 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2254 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2255 op1 = chrec_convert_rhs (chrec_type (op0), op1, NULL); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2256 chrec = build_polynomial_chrec (var, op0, op1); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2257 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2258 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2259 return chrec; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2260 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2261 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2262 /* Analyze all the parameters of the chrec, between INSTANTIATE_BELOW |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2263 and EVOLUTION_LOOP, that were left under a symbolic form. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2264 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2265 "C0 CODE C1" is a binary expression of type TYPE to be instantiated. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2266 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2267 CACHE is the cache of already instantiated values. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2268 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2269 FOLD_CONVERSIONS should be set to true when the conversions that |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2270 may wrap in signed/pointer type are folded, as long as the value of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2271 the chrec is preserved. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2272 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2273 SIZE_EXPR is used for computing the size of the expression to be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2274 instantiated, and to stop if it exceeds some limit. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2275 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2276 static tree |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2277 instantiate_scev_binary (basic_block instantiate_below, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2278 struct loop *evolution_loop, tree chrec, enum tree_code code, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2279 tree type, tree c0, tree c1, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2280 bool fold_conversions, htab_t cache, int size_expr) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2281 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2282 tree op1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2283 tree op0 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2284 c0, fold_conversions, cache, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2285 size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2286 if (op0 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2287 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2288 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2289 op1 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2290 c1, fold_conversions, cache, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2291 size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2292 if (op1 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2293 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2294 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2295 if (c0 != op0 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2296 || c1 != op1) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2297 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2298 op0 = chrec_convert (type, op0, NULL); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2299 op1 = chrec_convert_rhs (type, op1, NULL); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2300 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2301 switch (code) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2302 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2303 case POINTER_PLUS_EXPR: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2304 case PLUS_EXPR: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2305 return chrec_fold_plus (type, op0, op1); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2306 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2307 case MINUS_EXPR: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2308 return chrec_fold_minus (type, op0, op1); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2309 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2310 case MULT_EXPR: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2311 return chrec_fold_multiply (type, op0, op1); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2312 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2313 default: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2314 gcc_unreachable (); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2315 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2316 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2317 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2318 return chrec ? chrec : fold_build2 (code, type, c0, c1); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2319 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2320 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2321 /* Analyze all the parameters of the chrec, between INSTANTIATE_BELOW |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2322 and EVOLUTION_LOOP, that were left under a symbolic form. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2323 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2324 "CHREC" that stands for a convert expression "(TYPE) OP" is to be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2325 instantiated. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2326 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2327 CACHE is the cache of already instantiated values. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2328 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2329 FOLD_CONVERSIONS should be set to true when the conversions that |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2330 may wrap in signed/pointer type are folded, as long as the value of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2331 the chrec is preserved. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2332 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2333 SIZE_EXPR is used for computing the size of the expression to be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2334 instantiated, and to stop if it exceeds some limit. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2335 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2336 static tree |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2337 instantiate_scev_convert (basic_block instantiate_below, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2338 struct loop *evolution_loop, tree chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2339 tree type, tree op, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2340 bool fold_conversions, htab_t cache, int size_expr) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2341 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2342 tree op0 = instantiate_scev_r (instantiate_below, evolution_loop, op, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2343 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2344 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2345 if (op0 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2346 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2347 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2348 if (fold_conversions) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2349 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2350 tree tmp = chrec_convert_aggressive (type, op0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2351 if (tmp) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2352 return tmp; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2353 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2354 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2355 if (chrec && op0 == op) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2356 return chrec; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2357 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2358 /* If we used chrec_convert_aggressive, we can no longer assume that |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2359 signed chrecs do not overflow, as chrec_convert does, so avoid |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2360 calling it in that case. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2361 if (fold_conversions) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2362 return fold_convert (type, op0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2363 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2364 return chrec_convert (type, op0, NULL); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2365 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2366 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2367 /* Analyze all the parameters of the chrec, between INSTANTIATE_BELOW |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2368 and EVOLUTION_LOOP, that were left under a symbolic form. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2369 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2370 CHREC is a BIT_NOT_EXPR or a NEGATE_EXPR expression to be instantiated. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2371 Handle ~X as -1 - X. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2372 Handle -X as -1 * X. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2373 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2374 CACHE is the cache of already instantiated values. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2375 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2376 FOLD_CONVERSIONS should be set to true when the conversions that |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2377 may wrap in signed/pointer type are folded, as long as the value of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2378 the chrec is preserved. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2379 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2380 SIZE_EXPR is used for computing the size of the expression to be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2381 instantiated, and to stop if it exceeds some limit. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2382 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2383 static tree |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2384 instantiate_scev_not (basic_block instantiate_below, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2385 struct loop *evolution_loop, tree chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2386 enum tree_code code, tree type, tree op, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2387 bool fold_conversions, htab_t cache, int size_expr) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2388 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2389 tree op0 = instantiate_scev_r (instantiate_below, evolution_loop, op, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2390 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2391 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2392 if (op0 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2393 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2394 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2395 if (op != op0) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2396 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2397 op0 = chrec_convert (type, op0, NULL); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2398 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2399 switch (code) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2400 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2401 case BIT_NOT_EXPR: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2402 return chrec_fold_minus |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2403 (type, fold_convert (type, integer_minus_one_node), op0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2404 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2405 case NEGATE_EXPR: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2406 return chrec_fold_multiply |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2407 (type, fold_convert (type, integer_minus_one_node), op0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2408 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2409 default: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2410 gcc_unreachable (); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2411 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2412 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2413 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2414 return chrec ? chrec : fold_build1 (code, type, op0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2415 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2416 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2417 /* Analyze all the parameters of the chrec, between INSTANTIATE_BELOW |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2418 and EVOLUTION_LOOP, that were left under a symbolic form. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2419 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2420 CHREC is an expression with 3 operands to be instantiated. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2421 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2422 CACHE is the cache of already instantiated values. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2423 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2424 FOLD_CONVERSIONS should be set to true when the conversions that |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2425 may wrap in signed/pointer type are folded, as long as the value of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2426 the chrec is preserved. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2427 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2428 SIZE_EXPR is used for computing the size of the expression to be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2429 instantiated, and to stop if it exceeds some limit. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2430 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2431 static tree |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2432 instantiate_scev_3 (basic_block instantiate_below, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2433 struct loop *evolution_loop, tree chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2434 bool fold_conversions, htab_t cache, int size_expr) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2435 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2436 tree op1, op2; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2437 tree op0 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2438 TREE_OPERAND (chrec, 0), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2439 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2440 if (op0 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2441 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2442 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2443 op1 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2444 TREE_OPERAND (chrec, 1), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2445 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2446 if (op1 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2447 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2448 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2449 op2 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2450 TREE_OPERAND (chrec, 2), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2451 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2452 if (op2 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2453 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2454 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2455 if (op0 == TREE_OPERAND (chrec, 0) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2456 && op1 == TREE_OPERAND (chrec, 1) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2457 && op2 == TREE_OPERAND (chrec, 2)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2458 return chrec; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2459 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2460 return fold_build3 (TREE_CODE (chrec), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2461 TREE_TYPE (chrec), op0, op1, op2); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2462 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2463 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2464 /* Analyze all the parameters of the chrec, between INSTANTIATE_BELOW |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2465 and EVOLUTION_LOOP, that were left under a symbolic form. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2466 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2467 CHREC is an expression with 2 operands to be instantiated. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2468 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2469 CACHE is the cache of already instantiated values. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2470 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2471 FOLD_CONVERSIONS should be set to true when the conversions that |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2472 may wrap in signed/pointer type are folded, as long as the value of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2473 the chrec is preserved. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2474 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2475 SIZE_EXPR is used for computing the size of the expression to be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2476 instantiated, and to stop if it exceeds some limit. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2477 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2478 static tree |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2479 instantiate_scev_2 (basic_block instantiate_below, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2480 struct loop *evolution_loop, tree chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2481 bool fold_conversions, htab_t cache, int size_expr) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2482 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2483 tree op1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2484 tree op0 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2485 TREE_OPERAND (chrec, 0), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2486 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2487 if (op0 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2488 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2489 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2490 op1 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2491 TREE_OPERAND (chrec, 1), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2492 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2493 if (op1 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2494 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2495 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2496 if (op0 == TREE_OPERAND (chrec, 0) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2497 && op1 == TREE_OPERAND (chrec, 1)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2498 return chrec; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2499 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2500 return fold_build2 (TREE_CODE (chrec), TREE_TYPE (chrec), op0, op1); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2501 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2502 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2503 /* Analyze all the parameters of the chrec, between INSTANTIATE_BELOW |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2504 and EVOLUTION_LOOP, that were left under a symbolic form. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2505 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2506 CHREC is an expression with 2 operands to be instantiated. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2507 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2508 CACHE is the cache of already instantiated values. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2509 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2510 FOLD_CONVERSIONS should be set to true when the conversions that |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2511 may wrap in signed/pointer type are folded, as long as the value of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2512 the chrec is preserved. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2513 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2514 SIZE_EXPR is used for computing the size of the expression to be |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2515 instantiated, and to stop if it exceeds some limit. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2516 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2517 static tree |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2518 instantiate_scev_1 (basic_block instantiate_below, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2519 struct loop *evolution_loop, tree chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2520 bool fold_conversions, htab_t cache, int size_expr) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2521 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2522 tree op0 = instantiate_scev_r (instantiate_below, evolution_loop, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2523 TREE_OPERAND (chrec, 0), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2524 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2525 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2526 if (op0 == chrec_dont_know) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2527 return chrec_dont_know; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2528 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2529 if (op0 == TREE_OPERAND (chrec, 0)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2530 return chrec; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2531 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2532 return fold_build1 (TREE_CODE (chrec), TREE_TYPE (chrec), op0); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2533 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2534 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2535 /* Analyze all the parameters of the chrec, between INSTANTIATE_BELOW |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2536 and EVOLUTION_LOOP, that were left under a symbolic form. |
0 | 2537 |
2538 CHREC is the scalar evolution to instantiate. | |
2539 | |
2540 CACHE is the cache of already instantiated values. | |
2541 | |
2542 FOLD_CONVERSIONS should be set to true when the conversions that | |
2543 may wrap in signed/pointer type are folded, as long as the value of | |
2544 the chrec is preserved. | |
2545 | |
2546 SIZE_EXPR is used for computing the size of the expression to be | |
2547 instantiated, and to stop if it exceeds some limit. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2548 |
0 | 2549 static tree |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2550 instantiate_scev_r (basic_block instantiate_below, |
0 | 2551 struct loop *evolution_loop, tree chrec, |
2552 bool fold_conversions, htab_t cache, int size_expr) | |
2553 { | |
2554 /* Give up if the expression is larger than the MAX that we allow. */ | |
2555 if (size_expr++ > PARAM_VALUE (PARAM_SCEV_MAX_EXPR_SIZE)) | |
2556 return chrec_dont_know; | |
2557 | |
2558 if (automatically_generated_chrec_p (chrec) | |
2559 || is_gimple_min_invariant (chrec)) | |
2560 return chrec; | |
2561 | |
2562 switch (TREE_CODE (chrec)) | |
2563 { | |
2564 case SSA_NAME: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2565 return instantiate_scev_name (instantiate_below, evolution_loop, chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2566 fold_conversions, cache, size_expr); |
0 | 2567 |
2568 case POLYNOMIAL_CHREC: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2569 return instantiate_scev_poly (instantiate_below, evolution_loop, chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2570 fold_conversions, cache, size_expr); |
0 | 2571 |
2572 case POINTER_PLUS_EXPR: | |
2573 case PLUS_EXPR: | |
2574 case MINUS_EXPR: | |
2575 case MULT_EXPR: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2576 return instantiate_scev_binary (instantiate_below, evolution_loop, chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2577 TREE_CODE (chrec), chrec_type (chrec), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2578 TREE_OPERAND (chrec, 0), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2579 TREE_OPERAND (chrec, 1), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2580 fold_conversions, cache, size_expr); |
0 | 2581 |
2582 CASE_CONVERT: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2583 return instantiate_scev_convert (instantiate_below, evolution_loop, chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2584 TREE_TYPE (chrec), TREE_OPERAND (chrec, 0), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2585 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2586 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2587 case NEGATE_EXPR: |
0 | 2588 case BIT_NOT_EXPR: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2589 return instantiate_scev_not (instantiate_below, evolution_loop, chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2590 TREE_CODE (chrec), TREE_TYPE (chrec), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2591 TREE_OPERAND (chrec, 0), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2592 fold_conversions, cache, size_expr); |
0 | 2593 |
2594 case SCEV_NOT_KNOWN: | |
2595 return chrec_dont_know; | |
2596 | |
2597 case SCEV_KNOWN: | |
2598 return chrec_known; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2599 |
0 | 2600 default: |
2601 break; | |
2602 } | |
2603 | |
2604 if (VL_EXP_CLASS_P (chrec)) | |
2605 return chrec_dont_know; | |
2606 | |
2607 switch (TREE_CODE_LENGTH (TREE_CODE (chrec))) | |
2608 { | |
2609 case 3: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2610 return instantiate_scev_3 (instantiate_below, evolution_loop, chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2611 fold_conversions, cache, size_expr); |
0 | 2612 |
2613 case 2: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2614 return instantiate_scev_2 (instantiate_below, evolution_loop, chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2615 fold_conversions, cache, size_expr); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2616 |
0 | 2617 case 1: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2618 return instantiate_scev_1 (instantiate_below, evolution_loop, chrec, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2619 fold_conversions, cache, size_expr); |
0 | 2620 |
2621 case 0: | |
2622 return chrec; | |
2623 | |
2624 default: | |
2625 break; | |
2626 } | |
2627 | |
2628 /* Too complicated to handle. */ | |
2629 return chrec_dont_know; | |
2630 } | |
2631 | |
2632 /* Analyze all the parameters of the chrec that were left under a | |
2633 symbolic form. INSTANTIATE_BELOW is the basic block that stops the | |
2634 recursive instantiation of parameters: a parameter is a variable | |
2635 that is defined in a basic block that dominates INSTANTIATE_BELOW or | |
2636 a function parameter. */ | |
2637 | |
2638 tree | |
2639 instantiate_scev (basic_block instantiate_below, struct loop *evolution_loop, | |
2640 tree chrec) | |
2641 { | |
2642 tree res; | |
2643 htab_t cache = htab_create (10, hash_scev_info, eq_scev_info, del_scev_info); | |
2644 | |
2645 if (dump_file && (dump_flags & TDF_DETAILS)) | |
2646 { | |
2647 fprintf (dump_file, "(instantiate_scev \n"); | |
2648 fprintf (dump_file, " (instantiate_below = %d)\n", instantiate_below->index); | |
2649 fprintf (dump_file, " (evolution_loop = %d)\n", evolution_loop->num); | |
2650 fprintf (dump_file, " (chrec = "); | |
2651 print_generic_expr (dump_file, chrec, 0); | |
2652 fprintf (dump_file, ")\n"); | |
2653 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2654 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2655 res = instantiate_scev_r (instantiate_below, evolution_loop, chrec, false, |
0 | 2656 cache, 0); |
2657 | |
2658 if (dump_file && (dump_flags & TDF_DETAILS)) | |
2659 { | |
2660 fprintf (dump_file, " (res = "); | |
2661 print_generic_expr (dump_file, res, 0); | |
2662 fprintf (dump_file, "))\n"); | |
2663 } | |
2664 | |
2665 htab_delete (cache); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2666 |
0 | 2667 return res; |
2668 } | |
2669 | |
2670 /* Similar to instantiate_parameters, but does not introduce the | |
2671 evolutions in outer loops for LOOP invariants in CHREC, and does not | |
2672 care about causing overflows, as long as they do not affect value | |
2673 of an expression. */ | |
2674 | |
2675 tree | |
2676 resolve_mixers (struct loop *loop, tree chrec) | |
2677 { | |
2678 htab_t cache = htab_create (10, hash_scev_info, eq_scev_info, del_scev_info); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2679 tree ret = instantiate_scev_r (block_before_loop (loop), loop, chrec, true, |
0 | 2680 cache, 0); |
2681 htab_delete (cache); | |
2682 return ret; | |
2683 } | |
2684 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2685 /* Entry point for the analysis of the number of iterations pass. |
0 | 2686 This function tries to safely approximate the number of iterations |
2687 the loop will run. When this property is not decidable at compile | |
2688 time, the result is chrec_dont_know. Otherwise the result is | |
2689 a scalar or a symbolic parameter. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2690 |
0 | 2691 Example of analysis: suppose that the loop has an exit condition: |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2692 |
0 | 2693 "if (b > 49) goto end_loop;" |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2694 |
0 | 2695 and that in a previous analysis we have determined that the |
2696 variable 'b' has an evolution function: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2697 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2698 "EF = {23, +, 5}_2". |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2699 |
0 | 2700 When we evaluate the function at the point 5, i.e. the value of the |
2701 variable 'b' after 5 iterations in the loop, we have EF (5) = 48, | |
2702 and EF (6) = 53. In this case the value of 'b' on exit is '53' and | |
2703 the loop body has been executed 6 times. */ | |
2704 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2705 tree |
0 | 2706 number_of_latch_executions (struct loop *loop) |
2707 { | |
2708 tree res, type; | |
2709 edge exit; | |
2710 struct tree_niter_desc niter_desc; | |
2711 | |
2712 /* Determine whether the number_of_iterations_in_loop has already | |
2713 been computed. */ | |
2714 res = loop->nb_iterations; | |
2715 if (res) | |
2716 return res; | |
2717 res = chrec_dont_know; | |
2718 | |
2719 if (dump_file && (dump_flags & TDF_DETAILS)) | |
2720 fprintf (dump_file, "(number_of_iterations_in_loop\n"); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2721 |
0 | 2722 exit = single_exit (loop); |
2723 if (!exit) | |
2724 goto end; | |
2725 | |
2726 if (!number_of_iterations_exit (loop, exit, &niter_desc, false)) | |
2727 goto end; | |
2728 | |
2729 type = TREE_TYPE (niter_desc.niter); | |
2730 if (integer_nonzerop (niter_desc.may_be_zero)) | |
2731 res = build_int_cst (type, 0); | |
2732 else if (integer_zerop (niter_desc.may_be_zero)) | |
2733 res = niter_desc.niter; | |
2734 else | |
2735 res = chrec_dont_know; | |
2736 | |
2737 end: | |
2738 return set_nb_iterations_in_loop (loop, res); | |
2739 } | |
2740 | |
2741 /* Returns the number of executions of the exit condition of LOOP, | |
2742 i.e., the number by one higher than number_of_latch_executions. | |
2743 Note that unlike number_of_latch_executions, this number does | |
2744 not necessarily fit in the unsigned variant of the type of | |
2745 the control variable -- if the number of iterations is a constant, | |
2746 we return chrec_dont_know if adding one to number_of_latch_executions | |
2747 overflows; however, in case the number of iterations is symbolic | |
2748 expression, the caller is responsible for dealing with this | |
2749 the possible overflow. */ | |
2750 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2751 tree |
0 | 2752 number_of_exit_cond_executions (struct loop *loop) |
2753 { | |
2754 tree ret = number_of_latch_executions (loop); | |
2755 tree type = chrec_type (ret); | |
2756 | |
2757 if (chrec_contains_undetermined (ret)) | |
2758 return ret; | |
2759 | |
2760 ret = chrec_fold_plus (type, ret, build_int_cst (type, 1)); | |
2761 if (TREE_CODE (ret) == INTEGER_CST | |
2762 && TREE_OVERFLOW (ret)) | |
2763 return chrec_dont_know; | |
2764 | |
2765 return ret; | |
2766 } | |
2767 | |
2768 /* One of the drivers for testing the scalar evolutions analysis. | |
2769 This function computes the number of iterations for all the loops | |
2770 from the EXIT_CONDITIONS array. */ | |
2771 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2772 static void |
0 | 2773 number_of_iterations_for_all_loops (VEC(gimple,heap) **exit_conditions) |
2774 { | |
2775 unsigned int i; | |
2776 unsigned nb_chrec_dont_know_loops = 0; | |
2777 unsigned nb_static_loops = 0; | |
2778 gimple cond; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2779 |
0 | 2780 for (i = 0; VEC_iterate (gimple, *exit_conditions, i, cond); i++) |
2781 { | |
2782 tree res = number_of_latch_executions (loop_containing_stmt (cond)); | |
2783 if (chrec_contains_undetermined (res)) | |
2784 nb_chrec_dont_know_loops++; | |
2785 else | |
2786 nb_static_loops++; | |
2787 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2788 |
0 | 2789 if (dump_file) |
2790 { | |
2791 fprintf (dump_file, "\n(\n"); | |
2792 fprintf (dump_file, "-----------------------------------------\n"); | |
2793 fprintf (dump_file, "%d\tnb_chrec_dont_know_loops\n", nb_chrec_dont_know_loops); | |
2794 fprintf (dump_file, "%d\tnb_static_loops\n", nb_static_loops); | |
2795 fprintf (dump_file, "%d\tnb_total_loops\n", number_of_loops ()); | |
2796 fprintf (dump_file, "-----------------------------------------\n"); | |
2797 fprintf (dump_file, ")\n\n"); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2798 |
0 | 2799 print_loops (dump_file, 3); |
2800 } | |
2801 } | |
2802 | |
2803 | |
2804 | |
2805 /* Counters for the stats. */ | |
2806 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2807 struct chrec_stats |
0 | 2808 { |
2809 unsigned nb_chrecs; | |
2810 unsigned nb_affine; | |
2811 unsigned nb_affine_multivar; | |
2812 unsigned nb_higher_poly; | |
2813 unsigned nb_chrec_dont_know; | |
2814 unsigned nb_undetermined; | |
2815 }; | |
2816 | |
2817 /* Reset the counters. */ | |
2818 | |
2819 static inline void | |
2820 reset_chrecs_counters (struct chrec_stats *stats) | |
2821 { | |
2822 stats->nb_chrecs = 0; | |
2823 stats->nb_affine = 0; | |
2824 stats->nb_affine_multivar = 0; | |
2825 stats->nb_higher_poly = 0; | |
2826 stats->nb_chrec_dont_know = 0; | |
2827 stats->nb_undetermined = 0; | |
2828 } | |
2829 | |
2830 /* Dump the contents of a CHREC_STATS structure. */ | |
2831 | |
2832 static void | |
2833 dump_chrecs_stats (FILE *file, struct chrec_stats *stats) | |
2834 { | |
2835 fprintf (file, "\n(\n"); | |
2836 fprintf (file, "-----------------------------------------\n"); | |
2837 fprintf (file, "%d\taffine univariate chrecs\n", stats->nb_affine); | |
2838 fprintf (file, "%d\taffine multivariate chrecs\n", stats->nb_affine_multivar); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2839 fprintf (file, "%d\tdegree greater than 2 polynomials\n", |
0 | 2840 stats->nb_higher_poly); |
2841 fprintf (file, "%d\tchrec_dont_know chrecs\n", stats->nb_chrec_dont_know); | |
2842 fprintf (file, "-----------------------------------------\n"); | |
2843 fprintf (file, "%d\ttotal chrecs\n", stats->nb_chrecs); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2844 fprintf (file, "%d\twith undetermined coefficients\n", |
0 | 2845 stats->nb_undetermined); |
2846 fprintf (file, "-----------------------------------------\n"); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2847 fprintf (file, "%d\tchrecs in the scev database\n", |
0 | 2848 (int) htab_elements (scalar_evolution_info)); |
2849 fprintf (file, "%d\tsets in the scev database\n", nb_set_scev); | |
2850 fprintf (file, "%d\tgets in the scev database\n", nb_get_scev); | |
2851 fprintf (file, "-----------------------------------------\n"); | |
2852 fprintf (file, ")\n\n"); | |
2853 } | |
2854 | |
2855 /* Gather statistics about CHREC. */ | |
2856 | |
2857 static void | |
2858 gather_chrec_stats (tree chrec, struct chrec_stats *stats) | |
2859 { | |
2860 if (dump_file && (dump_flags & TDF_STATS)) | |
2861 { | |
2862 fprintf (dump_file, "(classify_chrec "); | |
2863 print_generic_expr (dump_file, chrec, 0); | |
2864 fprintf (dump_file, "\n"); | |
2865 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2866 |
0 | 2867 stats->nb_chrecs++; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2868 |
0 | 2869 if (chrec == NULL_TREE) |
2870 { | |
2871 stats->nb_undetermined++; | |
2872 return; | |
2873 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2874 |
0 | 2875 switch (TREE_CODE (chrec)) |
2876 { | |
2877 case POLYNOMIAL_CHREC: | |
2878 if (evolution_function_is_affine_p (chrec)) | |
2879 { | |
2880 if (dump_file && (dump_flags & TDF_STATS)) | |
2881 fprintf (dump_file, " affine_univariate\n"); | |
2882 stats->nb_affine++; | |
2883 } | |
2884 else if (evolution_function_is_affine_multivariate_p (chrec, 0)) | |
2885 { | |
2886 if (dump_file && (dump_flags & TDF_STATS)) | |
2887 fprintf (dump_file, " affine_multivariate\n"); | |
2888 stats->nb_affine_multivar++; | |
2889 } | |
2890 else | |
2891 { | |
2892 if (dump_file && (dump_flags & TDF_STATS)) | |
2893 fprintf (dump_file, " higher_degree_polynomial\n"); | |
2894 stats->nb_higher_poly++; | |
2895 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2896 |
0 | 2897 break; |
2898 | |
2899 default: | |
2900 break; | |
2901 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2902 |
0 | 2903 if (chrec_contains_undetermined (chrec)) |
2904 { | |
2905 if (dump_file && (dump_flags & TDF_STATS)) | |
2906 fprintf (dump_file, " undetermined\n"); | |
2907 stats->nb_undetermined++; | |
2908 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2909 |
0 | 2910 if (dump_file && (dump_flags & TDF_STATS)) |
2911 fprintf (dump_file, ")\n"); | |
2912 } | |
2913 | |
2914 /* One of the drivers for testing the scalar evolutions analysis. | |
2915 This function analyzes the scalar evolution of all the scalars | |
2916 defined as loop phi nodes in one of the loops from the | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2917 EXIT_CONDITIONS array. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2918 |
0 | 2919 TODO Optimization: A loop is in canonical form if it contains only |
2920 a single scalar loop phi node. All the other scalars that have an | |
2921 evolution in the loop are rewritten in function of this single | |
2922 index. This allows the parallelization of the loop. */ | |
2923 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2924 static void |
0 | 2925 analyze_scalar_evolution_for_all_loop_phi_nodes (VEC(gimple,heap) **exit_conditions) |
2926 { | |
2927 unsigned int i; | |
2928 struct chrec_stats stats; | |
2929 gimple cond, phi; | |
2930 gimple_stmt_iterator psi; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2931 |
0 | 2932 reset_chrecs_counters (&stats); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2933 |
0 | 2934 for (i = 0; VEC_iterate (gimple, *exit_conditions, i, cond); i++) |
2935 { | |
2936 struct loop *loop; | |
2937 basic_block bb; | |
2938 tree chrec; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2939 |
0 | 2940 loop = loop_containing_stmt (cond); |
2941 bb = loop->header; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2942 |
0 | 2943 for (psi = gsi_start_phis (bb); !gsi_end_p (psi); gsi_next (&psi)) |
2944 { | |
2945 phi = gsi_stmt (psi); | |
2946 if (is_gimple_reg (PHI_RESULT (phi))) | |
2947 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2948 chrec = instantiate_parameters |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2949 (loop, |
0 | 2950 analyze_scalar_evolution (loop, PHI_RESULT (phi))); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2951 |
0 | 2952 if (dump_file && (dump_flags & TDF_STATS)) |
2953 gather_chrec_stats (chrec, &stats); | |
2954 } | |
2955 } | |
2956 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2957 |
0 | 2958 if (dump_file && (dump_flags & TDF_STATS)) |
2959 dump_chrecs_stats (dump_file, &stats); | |
2960 } | |
2961 | |
2962 /* Callback for htab_traverse, gathers information on chrecs in the | |
2963 hashtable. */ | |
2964 | |
2965 static int | |
2966 gather_stats_on_scev_database_1 (void **slot, void *stats) | |
2967 { | |
2968 struct scev_info_str *entry = (struct scev_info_str *) *slot; | |
2969 | |
2970 gather_chrec_stats (entry->chrec, (struct chrec_stats *) stats); | |
2971 | |
2972 return 1; | |
2973 } | |
2974 | |
2975 /* Classify the chrecs of the whole database. */ | |
2976 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2977 void |
0 | 2978 gather_stats_on_scev_database (void) |
2979 { | |
2980 struct chrec_stats stats; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2981 |
0 | 2982 if (!dump_file) |
2983 return; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2984 |
0 | 2985 reset_chrecs_counters (&stats); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2986 |
0 | 2987 htab_traverse (scalar_evolution_info, gather_stats_on_scev_database_1, |
2988 &stats); | |
2989 | |
2990 dump_chrecs_stats (dump_file, &stats); | |
2991 } | |
2992 | |
2993 | |
2994 | |
2995 /* Initializer. */ | |
2996 | |
2997 static void | |
2998 initialize_scalar_evolutions_analyzer (void) | |
2999 { | |
3000 /* The elements below are unique. */ | |
3001 if (chrec_dont_know == NULL_TREE) | |
3002 { | |
3003 chrec_not_analyzed_yet = NULL_TREE; | |
3004 chrec_dont_know = make_node (SCEV_NOT_KNOWN); | |
3005 chrec_known = make_node (SCEV_KNOWN); | |
3006 TREE_TYPE (chrec_dont_know) = void_type_node; | |
3007 TREE_TYPE (chrec_known) = void_type_node; | |
3008 } | |
3009 } | |
3010 | |
3011 /* Initialize the analysis of scalar evolutions for LOOPS. */ | |
3012 | |
3013 void | |
3014 scev_initialize (void) | |
3015 { | |
3016 loop_iterator li; | |
3017 struct loop *loop; | |
3018 | |
3019 scalar_evolution_info = htab_create_alloc (100, | |
3020 hash_scev_info, | |
3021 eq_scev_info, | |
3022 del_scev_info, | |
3023 ggc_calloc, | |
3024 ggc_free); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
3025 |
0 | 3026 initialize_scalar_evolutions_analyzer (); |
3027 | |
3028 FOR_EACH_LOOP (li, loop, 0) | |
3029 { | |
3030 loop->nb_iterations = NULL_TREE; | |
3031 } | |
3032 } | |
3033 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3034 /* Cleans up the information cached by the scalar evolutions analysis |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3035 in the hash table. */ |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3036 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3037 void |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3038 scev_reset_htab (void) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3039 { |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3040 if (!scalar_evolution_info) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3041 return; |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3042 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3043 htab_empty (scalar_evolution_info); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3044 } |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3045 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3046 /* Cleans up the information cached by the scalar evolutions analysis |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3047 in the hash table and in the loop->nb_iterations. */ |
0 | 3048 |
3049 void | |
3050 scev_reset (void) | |
3051 { | |
3052 loop_iterator li; | |
3053 struct loop *loop; | |
3054 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3055 scev_reset_htab (); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3056 |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
3057 if (!current_loops) |
0 | 3058 return; |
3059 | |
3060 FOR_EACH_LOOP (li, loop, 0) | |
3061 { | |
3062 loop->nb_iterations = NULL_TREE; | |
3063 } | |
3064 } | |
3065 | |
3066 /* Checks whether use of OP in USE_LOOP behaves as a simple affine iv with | |
3067 respect to WRTO_LOOP and returns its base and step in IV if possible | |
3068 (see analyze_scalar_evolution_in_loop for more details on USE_LOOP | |
3069 and WRTO_LOOP). If ALLOW_NONCONSTANT_STEP is true, we want step to be | |
3070 invariant in LOOP. Otherwise we require it to be an integer constant. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
3071 |
0 | 3072 IV->no_overflow is set to true if we are sure the iv cannot overflow (e.g. |
3073 because it is computed in signed arithmetics). Consequently, adding an | |
3074 induction variable | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
3075 |
0 | 3076 for (i = IV->base; ; i += IV->step) |
3077 | |
3078 is only safe if IV->no_overflow is false, or TYPE_OVERFLOW_UNDEFINED is | |
3079 false for the type of the induction variable, or you can prove that i does | |
3080 not wrap by some other argument. Otherwise, this might introduce undefined | |
3081 behavior, and | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
3082 |
0 | 3083 for (i = iv->base; ; i = (type) ((unsigned type) i + (unsigned type) iv->step)) |
3084 | |
3085 must be used instead. */ | |
3086 | |
3087 bool | |
3088 simple_iv (struct loop *wrto_loop, struct loop *use_loop, tree op, | |
3089 affine_iv *iv, bool allow_nonconstant_step) | |
3090 { | |
3091 tree type, ev; | |
3092 bool folded_casts; | |
3093 | |
3094 iv->base = NULL_TREE; | |
3095 iv->step = NULL_TREE; | |
3096 iv->no_overflow = false; | |
3097 | |
3098 type = TREE_TYPE (op); | |
3099 if (TREE_CODE (type) != INTEGER_TYPE | |
3100 && TREE_CODE (type) != POINTER_TYPE) | |
3101 return false; | |
3102 | |
3103 ev = analyze_scalar_evolution_in_loop (wrto_loop, use_loop, op, | |
3104 &folded_casts); | |
3105 if (chrec_contains_undetermined (ev) | |
3106 || chrec_contains_symbols_defined_in_loop (ev, wrto_loop->num)) | |
3107 return false; | |
3108 | |
3109 if (tree_does_not_contain_chrecs (ev)) | |
3110 { | |
3111 iv->base = ev; | |
3112 iv->step = build_int_cst (TREE_TYPE (ev), 0); | |
3113 iv->no_overflow = true; | |
3114 return true; | |
3115 } | |
3116 | |
3117 if (TREE_CODE (ev) != POLYNOMIAL_CHREC | |
3118 || CHREC_VARIABLE (ev) != (unsigned) wrto_loop->num) | |
3119 return false; | |
3120 | |
3121 iv->step = CHREC_RIGHT (ev); | |
3122 if ((!allow_nonconstant_step && TREE_CODE (iv->step) != INTEGER_CST) | |
3123 || tree_contains_chrecs (iv->step, NULL)) | |
3124 return false; | |
3125 | |
3126 iv->base = CHREC_LEFT (ev); | |
3127 if (tree_contains_chrecs (iv->base, NULL)) | |
3128 return false; | |
3129 | |
3130 iv->no_overflow = !folded_casts && TYPE_OVERFLOW_UNDEFINED (type); | |
3131 | |
3132 return true; | |
3133 } | |
3134 | |
3135 /* Runs the analysis of scalar evolutions. */ | |
3136 | |
3137 void | |
3138 scev_analysis (void) | |
3139 { | |
3140 VEC(gimple,heap) *exit_conditions; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
3141 |
0 | 3142 exit_conditions = VEC_alloc (gimple, heap, 37); |
3143 select_loops_exit_conditions (&exit_conditions); | |
3144 | |
3145 if (dump_file && (dump_flags & TDF_STATS)) | |
3146 analyze_scalar_evolution_for_all_loop_phi_nodes (&exit_conditions); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
3147 |
0 | 3148 number_of_iterations_for_all_loops (&exit_conditions); |
3149 VEC_free (gimple, heap, exit_conditions); | |
3150 } | |
3151 | |
3152 /* Finalize the scalar evolution analysis. */ | |
3153 | |
3154 void | |
3155 scev_finalize (void) | |
3156 { | |
3157 if (!scalar_evolution_info) | |
3158 return; | |
3159 htab_delete (scalar_evolution_info); | |
3160 scalar_evolution_info = NULL; | |
3161 } | |
3162 | |
3163 /* Returns true if the expression EXPR is considered to be too expensive | |
3164 for scev_const_prop. */ | |
3165 | |
3166 bool | |
3167 expression_expensive_p (tree expr) | |
3168 { | |
3169 enum tree_code code; | |
3170 | |
3171 if (is_gimple_val (expr)) | |
3172 return false; | |
3173 | |
3174 code = TREE_CODE (expr); | |
3175 if (code == TRUNC_DIV_EXPR | |
3176 || code == CEIL_DIV_EXPR | |
3177 || code == FLOOR_DIV_EXPR | |
3178 || code == ROUND_DIV_EXPR | |
3179 || code == TRUNC_MOD_EXPR | |
3180 || code == CEIL_MOD_EXPR | |
3181 || code == FLOOR_MOD_EXPR | |
3182 || code == ROUND_MOD_EXPR | |
3183 || code == EXACT_DIV_EXPR) | |
3184 { | |
3185 /* Division by power of two is usually cheap, so we allow it. | |
3186 Forbid anything else. */ | |
3187 if (!integer_pow2p (TREE_OPERAND (expr, 1))) | |
3188 return true; | |
3189 } | |
3190 | |
3191 switch (TREE_CODE_CLASS (code)) | |
3192 { | |
3193 case tcc_binary: | |
3194 case tcc_comparison: | |
3195 if (expression_expensive_p (TREE_OPERAND (expr, 1))) | |
3196 return true; | |
3197 | |
3198 /* Fallthru. */ | |
3199 case tcc_unary: | |
3200 return expression_expensive_p (TREE_OPERAND (expr, 0)); | |
3201 | |
3202 default: | |
3203 return true; | |
3204 } | |
3205 } | |
3206 | |
3207 /* Replace ssa names for that scev can prove they are constant by the | |
3208 appropriate constants. Also perform final value replacement in loops, | |
3209 in case the replacement expressions are cheap. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
3210 |
0 | 3211 We only consider SSA names defined by phi nodes; rest is left to the |
3212 ordinary constant propagation pass. */ | |
3213 | |
3214 unsigned int | |
3215 scev_const_prop (void) | |
3216 { | |
3217 basic_block bb; | |
3218 tree name, type, ev; | |
3219 gimple phi, ass; | |
3220 struct loop *loop, *ex_loop; | |
3221 bitmap ssa_names_to_remove = NULL; | |
3222 unsigned i; | |
3223 loop_iterator li; | |
3224 gimple_stmt_iterator psi; | |
3225 | |
3226 if (number_of_loops () <= 1) | |
3227 return 0; | |
3228 | |
3229 FOR_EACH_BB (bb) | |
3230 { | |
3231 loop = bb->loop_father; | |
3232 | |
3233 for (psi = gsi_start_phis (bb); !gsi_end_p (psi); gsi_next (&psi)) | |
3234 { | |
3235 phi = gsi_stmt (psi); | |
3236 name = PHI_RESULT (phi); | |
3237 | |
3238 if (!is_gimple_reg (name)) | |
3239 continue; | |
3240 | |
3241 type = TREE_TYPE (name); | |
3242 | |
3243 if (!POINTER_TYPE_P (type) | |
3244 && !INTEGRAL_TYPE_P (type)) | |
3245 continue; | |
3246 | |
3247 ev = resolve_mixers (loop, analyze_scalar_evolution (loop, name)); | |
3248 if (!is_gimple_min_invariant (ev) | |
3249 || !may_propagate_copy (name, ev)) | |
3250 continue; | |
3251 | |
3252 /* Replace the uses of the name. */ | |
3253 if (name != ev) | |
3254 replace_uses_by (name, ev); | |
3255 | |
3256 if (!ssa_names_to_remove) | |
3257 ssa_names_to_remove = BITMAP_ALLOC (NULL); | |
3258 bitmap_set_bit (ssa_names_to_remove, SSA_NAME_VERSION (name)); | |
3259 } | |
3260 } | |
3261 | |
3262 /* Remove the ssa names that were replaced by constants. We do not | |
3263 remove them directly in the previous cycle, since this | |
3264 invalidates scev cache. */ | |
3265 if (ssa_names_to_remove) | |
3266 { | |
3267 bitmap_iterator bi; | |
3268 | |
3269 EXECUTE_IF_SET_IN_BITMAP (ssa_names_to_remove, 0, i, bi) | |
3270 { | |
3271 gimple_stmt_iterator psi; | |
3272 name = ssa_name (i); | |
3273 phi = SSA_NAME_DEF_STMT (name); | |
3274 | |
3275 gcc_assert (gimple_code (phi) == GIMPLE_PHI); | |
3276 psi = gsi_for_stmt (phi); | |
3277 remove_phi_node (&psi, true); | |
3278 } | |
3279 | |
3280 BITMAP_FREE (ssa_names_to_remove); | |
3281 scev_reset (); | |
3282 } | |
3283 | |
3284 /* Now the regular final value replacement. */ | |
3285 FOR_EACH_LOOP (li, loop, LI_FROM_INNERMOST) | |
3286 { | |
3287 edge exit; | |
3288 tree def, rslt, niter; | |
3289 gimple_stmt_iterator bsi; | |
3290 | |
3291 /* If we do not know exact number of iterations of the loop, we cannot | |
3292 replace the final value. */ | |
3293 exit = single_exit (loop); | |
3294 if (!exit) | |
3295 continue; | |
3296 | |
3297 niter = number_of_latch_executions (loop); | |
3298 if (niter == chrec_dont_know) | |
3299 continue; | |
3300 | |
3301 /* Ensure that it is possible to insert new statements somewhere. */ | |
3302 if (!single_pred_p (exit->dest)) | |
3303 split_loop_exit_edge (exit); | |
3304 bsi = gsi_after_labels (exit->dest); | |
3305 | |
3306 ex_loop = superloop_at_depth (loop, | |
3307 loop_depth (exit->dest->loop_father) + 1); | |
3308 | |
3309 for (psi = gsi_start_phis (exit->dest); !gsi_end_p (psi); ) | |
3310 { | |
3311 phi = gsi_stmt (psi); | |
3312 rslt = PHI_RESULT (phi); | |
3313 def = PHI_ARG_DEF_FROM_EDGE (phi, exit); | |
3314 if (!is_gimple_reg (def)) | |
3315 { | |
3316 gsi_next (&psi); | |
3317 continue; | |
3318 } | |
3319 | |
3320 if (!POINTER_TYPE_P (TREE_TYPE (def)) | |
3321 && !INTEGRAL_TYPE_P (TREE_TYPE (def))) | |
3322 { | |
3323 gsi_next (&psi); | |
3324 continue; | |
3325 } | |
3326 | |
3327 def = analyze_scalar_evolution_in_loop (ex_loop, loop, def, NULL); | |
3328 def = compute_overall_effect_of_inner_loop (ex_loop, def); | |
3329 if (!tree_does_not_contain_chrecs (def) | |
3330 || chrec_contains_symbols_defined_in_loop (def, ex_loop->num) | |
3331 /* Moving the computation from the loop may prolong life range | |
3332 of some ssa names, which may cause problems if they appear | |
3333 on abnormal edges. */ | |
3334 || contains_abnormal_ssa_name_p (def) | |
3335 /* Do not emit expensive expressions. The rationale is that | |
3336 when someone writes a code like | |
3337 | |
3338 while (n > 45) n -= 45; | |
3339 | |
3340 he probably knows that n is not large, and does not want it | |
3341 to be turned into n %= 45. */ | |
3342 || expression_expensive_p (def)) | |
3343 { | |
3344 gsi_next (&psi); | |
3345 continue; | |
3346 } | |
3347 | |
3348 /* Eliminate the PHI node and replace it by a computation outside | |
3349 the loop. */ | |
3350 def = unshare_expr (def); | |
3351 remove_phi_node (&psi, false); | |
3352 | |
3353 def = force_gimple_operand_gsi (&bsi, def, false, NULL_TREE, | |
3354 true, GSI_SAME_STMT); | |
3355 ass = gimple_build_assign (rslt, def); | |
3356 gsi_insert_before (&bsi, ass, GSI_SAME_STMT); | |
3357 } | |
3358 } | |
3359 return 0; | |
3360 } | |
3361 | |
3362 #include "gt-tree-scalar-evolution.h" |