]> git.pld-linux.org Git - packages/gcc.git/blame - gcc-pr26435-pr20256.patch
- updated to 4.1.2-20060530 (rev. 114228)
[packages/gcc.git] / gcc-pr26435-pr20256.patch
CommitLineData
0d2cf956
PS
1*** gcc/gcc/tree-loop-linear.c (revision 113884)
2--- gcc/gcc/tree-loop-linear.c (working copy)
c19ca6f9
PS
3***************
4*** 1,5 ****
5 /* Linear Loop transforms
6! Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
7 Contributed by Daniel Berlin <dberlin@dberlin.org>.
8
9 This file is part of GCC.
10--- 1,5 ----
11 /* Linear Loop transforms
12! Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
13 Contributed by Daniel Berlin <dberlin@dberlin.org>.
14
15 This file is part of GCC.
16*************** try_interchange_loops (lambda_trans_matr
17*** 243,248 ****
18--- 243,249 ----
19 void
20 linear_transform_loops (struct loops *loops)
21 {
22+ bool modified = false;
23 unsigned int i;
24 VEC(tree,heap) *oldivs = NULL;
25 VEC(tree,heap) *invariants = NULL;
26*************** linear_transform_loops (struct loops *lo
27*** 257,263 ****
28 lambda_loopnest before, after;
29 lambda_trans_matrix trans;
30 bool problem = false;
31- bool need_perfect_nest = false;
32 /* If it's not a loop nest, we don't want it.
33 We also don't handle sibling loops properly,
34 which are loops of the following form:
35--- 258,263 ----
36*************** linear_transform_loops (struct loops *lo
37*** 334,345 ****
38 fprintf (dump_file, "Can't transform loop, transform is illegal:\n");
39 continue;
40 }
41! if (!perfect_nest_p (loop_nest))
42! need_perfect_nest = true;
43! before = gcc_loopnest_to_lambda_loopnest (loops,
44! loop_nest, &oldivs,
45! &invariants,
46! need_perfect_nest);
47 if (!before)
48 continue;
49
50--- 334,342 ----
51 fprintf (dump_file, "Can't transform loop, transform is illegal:\n");
52 continue;
53 }
54!
55! before = gcc_loopnest_to_lambda_loopnest (loops, loop_nest, &oldivs,
56! &invariants);
57 if (!before)
58 continue;
59
60*************** linear_transform_loops (struct loops *lo
61*** 357,362 ****
62--- 354,361 ----
63 }
64 lambda_loopnest_to_gcc_loopnest (loop_nest, oldivs, invariants,
65 after, trans);
66+ modified = true;
67+
68 if (dump_file)
69 fprintf (dump_file, "Successfully transformed loop.\n");
70 free_dependence_relations (dependence_relations);
71*************** linear_transform_loops (struct loops *lo
72*** 365,369 ****
73 VEC_free (tree, heap, oldivs);
74 VEC_free (tree, heap, invariants);
75 scev_reset ();
76! rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_full_phi);
77 }
78--- 364,370 ----
79 VEC_free (tree, heap, oldivs);
80 VEC_free (tree, heap, invariants);
81 scev_reset ();
82!
83! if (modified)
84! rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_full_phi);
85 }
0d2cf956
PS
86*** gcc/gcc/lambda.h (revision 113884)
87--- gcc/gcc/lambda.h (working copy)
c19ca6f9
PS
88***************
89*** 1,5 ****
90 /* Lambda matrix and vector interface.
91! Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
92 Contributed by Daniel Berlin <dberlin@dberlin.org>
93
94 This file is part of GCC.
95--- 1,5 ----
96 /* Lambda matrix and vector interface.
97! Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
98 Contributed by Daniel Berlin <dberlin@dberlin.org>
99
100 This file is part of GCC.
101*************** void print_lambda_body_vector (FILE *, l
102*** 200,207 ****
103 lambda_loopnest gcc_loopnest_to_lambda_loopnest (struct loops *,
104 struct loop *,
105 VEC(tree,heap) **,
106! VEC(tree,heap) **,
107! bool);
108 void lambda_loopnest_to_gcc_loopnest (struct loop *,
109 VEC(tree,heap) *, VEC(tree,heap) *,
110 lambda_loopnest, lambda_trans_matrix);
111--- 200,206 ----
112 lambda_loopnest gcc_loopnest_to_lambda_loopnest (struct loops *,
113 struct loop *,
114 VEC(tree,heap) **,
115! VEC(tree,heap) **);
116 void lambda_loopnest_to_gcc_loopnest (struct loop *,
117 VEC(tree,heap) *, VEC(tree,heap) *,
118 lambda_loopnest, lambda_trans_matrix);
0d2cf956
PS
119*** gcc/gcc/lambda-code.c (revision 113884)
120--- gcc/gcc/lambda-code.c (working copy)
c19ca6f9
PS
121***************
122*** 1,5 ****
123 /* Loop transformation code generation
124! Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
125 Contributed by Daniel Berlin <dberlin@dberlin.org>
126
127 This file is part of GCC.
128--- 1,5 ----
129 /* Loop transformation code generation
130! Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
131 Contributed by Daniel Berlin <dberlin@dberlin.org>
132
133 This file is part of GCC.
134*************** static lambda_lattice lambda_lattice_new
135*** 149,154 ****
136--- 149,155 ----
137 static lambda_lattice lambda_lattice_compute_base (lambda_loopnest);
138
139 static tree find_induction_var_from_exit_cond (struct loop *);
140+ static bool can_convert_to_perfect_nest (struct loop *);
141
142 /* Create a new lambda body vector. */
143
144*************** DEF_VEC_ALLOC_P(lambda_loop,heap);
145*** 1498,1511 ****
146
147 lambda_loopnest
148 gcc_loopnest_to_lambda_loopnest (struct loops *currloops,
149! struct loop * loop_nest,
150 VEC(tree,heap) **inductionvars,
151! VEC(tree,heap) **invariants,
152! bool need_perfect_nest)
153 {
154 lambda_loopnest ret = NULL;
155! struct loop *temp;
156! int depth = 0;
157 size_t i;
158 VEC(lambda_loop,heap) *loops = NULL;
159 VEC(tree,heap) *uboundvars = NULL;
160--- 1499,1511 ----
161
162 lambda_loopnest
163 gcc_loopnest_to_lambda_loopnest (struct loops *currloops,
164! struct loop *loop_nest,
165 VEC(tree,heap) **inductionvars,
166! VEC(tree,heap) **invariants)
167 {
168 lambda_loopnest ret = NULL;
169! struct loop *temp = loop_nest;
170! int depth = depth_of_nest (loop_nest);
171 size_t i;
172 VEC(lambda_loop,heap) *loops = NULL;
173 VEC(tree,heap) *uboundvars = NULL;
174*************** gcc_loopnest_to_lambda_loopnest (struct
175*** 1513,1521 ****
176 VEC(int,heap) *steps = NULL;
177 lambda_loop newloop;
178 tree inductionvar = NULL;
179!
180! depth = depth_of_nest (loop_nest);
181! temp = loop_nest;
182 while (temp)
183 {
184 newloop = gcc_loop_to_lambda_loop (temp, depth, invariants,
185--- 1513,1523 ----
186 VEC(int,heap) *steps = NULL;
187 lambda_loop newloop;
188 tree inductionvar = NULL;
189! bool perfect_nest = perfect_nest_p (loop_nest);
190!
191! if (!perfect_nest && !can_convert_to_perfect_nest (loop_nest))
192! goto fail;
193!
194 while (temp)
195 {
196 newloop = gcc_loop_to_lambda_loop (temp, depth, invariants,
197*************** gcc_loopnest_to_lambda_loopnest (struct
198*** 1523,1534 ****
199 &lboundvars, &uboundvars,
200 &steps);
201 if (!newloop)
202! return NULL;
203 VEC_safe_push (tree, heap, *inductionvars, inductionvar);
204 VEC_safe_push (lambda_loop, heap, loops, newloop);
205 temp = temp->inner;
206 }
207! if (need_perfect_nest)
208 {
209 if (!perfect_nestify (currloops, loop_nest,
210 lboundvars, uboundvars, steps, *inductionvars))
211--- 1525,1538 ----
212 &lboundvars, &uboundvars,
213 &steps);
214 if (!newloop)
215! goto fail;
216!
217 VEC_safe_push (tree, heap, *inductionvars, inductionvar);
218 VEC_safe_push (lambda_loop, heap, loops, newloop);
219 temp = temp->inner;
220 }
221!
222! if (!perfect_nest)
223 {
224 if (!perfect_nestify (currloops, loop_nest,
225 lboundvars, uboundvars, steps, *inductionvars))
226*************** gcc_loopnest_to_lambda_loopnest (struct
227*** 1542,1550 ****
228--- 1546,1557 ----
229 fprintf (dump_file,
230 "Successfully converted loop nest to perfect loop nest.\n");
231 }
232+
233 ret = lambda_loopnest_new (depth, 2 * depth);
234+
235 for (i = 0; VEC_iterate (lambda_loop, loops, i, newloop); i++)
236 LN_LOOPS (ret)[i] = newloop;
237+
238 fail:
239 VEC_free (lambda_loop, heap, loops);
240 VEC_free (tree, heap, uboundvars);
241*************** replace_uses_equiv_to_x_with_y (struct l
242*** 2156,2168 ****
243 {
244 tree use = USE_FROM_PTR (use_p);
245 tree step = NULL_TREE;
246! tree access_fn = NULL_TREE;
247!
248!
249! access_fn = instantiate_parameters
250! (loop, analyze_scalar_evolution (loop, use));
251! if (access_fn != NULL_TREE && access_fn != chrec_dont_know)
252! step = evolution_part_in_loop_num (access_fn, loop->num);
253 if ((step && step != chrec_dont_know
254 && TREE_CODE (step) == INTEGER_CST
255 && int_cst_value (step) == xstep)
256--- 2163,2174 ----
257 {
258 tree use = USE_FROM_PTR (use_p);
259 tree step = NULL_TREE;
260! tree scev = instantiate_parameters (loop,
261! analyze_scalar_evolution (loop, use));
262!
263! if (scev != NULL_TREE && scev != chrec_dont_know)
264! step = evolution_part_in_loop_num (scev, loop->num);
265!
266 if ((step && step != chrec_dont_know
267 && TREE_CODE (step) == INTEGER_CST
268 && int_cst_value (step) == xstep)
269*************** replace_uses_equiv_to_x_with_y (struct l
270*** 2171,2192 ****
271 }
272 }
273
274- /* Return TRUE if STMT uses tree OP in it's uses. */
275-
276- static bool
277- stmt_uses_op (tree stmt, tree op)
278- {
279- ssa_op_iter iter;
280- tree use;
281-
282- FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
283- {
284- if (use == op)
285- return true;
286- }
287- return false;
288- }
289-
290 /* Return true if STMT is an exit PHI for LOOP */
291
292 static bool
293--- 2177,2182 ----
294*************** can_put_in_inner_loop (struct loop *inne
295*** 2236,2250 ****
296
297 }
298
299
300! /* Return TRUE if LOOP is an imperfect nest that we can convert to a perfect
301! one. LOOPIVS is a vector of induction variables, one per loop.
302! ATM, we only handle imperfect nests of depth 2, where all of the statements
303! occur after the inner loop. */
304
305 static bool
306! can_convert_to_perfect_nest (struct loop *loop,
307! VEC(tree,heap) *loopivs)
308 {
309 basic_block *bbs;
310 tree exit_condition, phi;
311--- 2226,2264 ----
312
313 }
314
315+ /* Return true if STMT can be put *after* the inner loop of LOOP. */
316+
317+ static bool
318+ can_put_after_inner_loop (struct loop *loop, tree stmt)
319+ {
320+ imm_use_iterator imm_iter;
321+ use_operand_p use_p;
322+
323+ if (!ZERO_SSA_OPERANDS (stmt, SSA_OP_ALL_VIRTUALS))
324+ return false;
325+
326+ FOR_EACH_IMM_USE_FAST (use_p, imm_iter, TREE_OPERAND (stmt, 0))
327+ {
328+ if (!exit_phi_for_loop_p (loop, USE_STMT (use_p)))
329+ {
330+ basic_block immbb = bb_for_stmt (USE_STMT (use_p));
331+
332+ if (!dominated_by_p (CDI_DOMINATORS,
333+ immbb,
334+ loop->inner->header)
335+ && !can_put_in_inner_loop (loop->inner, stmt))
336+ return false;
337+ }
338+ }
339+ return true;
340+ }
341
342! /* Return TRUE if LOOP is an imperfect nest that we can convert to a
343! perfect one. At the moment, we only handle imperfect nests of
344! depth 2, where all of the statements occur after the inner loop. */
345
346 static bool
347! can_convert_to_perfect_nest (struct loop *loop)
348 {
349 basic_block *bbs;
350 tree exit_condition, phi;
351*************** can_convert_to_perfect_nest (struct loop
352*** 2264,2282 ****
353 {
354 for (bsi = bsi_start (bbs[i]); !bsi_end_p (bsi); bsi_next (&bsi))
355 {
356- size_t j;
357 tree stmt = bsi_stmt (bsi);
358! tree iv;
359!
360 if (stmt == exit_condition
361 || not_interesting_stmt (stmt)
362 || stmt_is_bumper_for_loop (loop, stmt))
363 continue;
364! /* If the statement uses inner loop ivs, we == screwed. */
365! for (j = 1; VEC_iterate (tree, loopivs, j, iv); j++)
366! if (stmt_uses_op (stmt, iv))
367! goto fail;
368!
369 /* If this is a simple operation like a cast that is invariant
370 in the inner loop, only used there, and we can place it
371 there, then it's not going to hurt us.
372--- 2278,2290 ----
373 {
374 for (bsi = bsi_start (bbs[i]); !bsi_end_p (bsi); bsi_next (&bsi))
375 {
376 tree stmt = bsi_stmt (bsi);
377!
378 if (stmt == exit_condition
379 || not_interesting_stmt (stmt)
380 || stmt_is_bumper_for_loop (loop, stmt))
381 continue;
382!
383 /* If this is a simple operation like a cast that is invariant
384 in the inner loop, only used there, and we can place it
385 there, then it's not going to hurt us.
386*************** can_convert_to_perfect_nest (struct loop
387*** 2286,2295 ****
388 theory that we are going to gain a lot more by interchanging
389 the loop than we are by leaving some invariant code there for
390 some other pass to clean up. */
391! if (TREE_CODE (stmt) == MODIFY_EXPR
392! && is_gimple_cast (TREE_OPERAND (stmt, 1))
393! && can_put_in_inner_loop (loop->inner, stmt))
394! continue;
395
396 /* Otherwise, if the bb of a statement we care about isn't
397 dominated by the header of the inner loop, then we can't
398--- 2294,2358 ----
399 theory that we are going to gain a lot more by interchanging
400 the loop than we are by leaving some invariant code there for
401 some other pass to clean up. */
402! if (TREE_CODE (stmt) == MODIFY_EXPR)
403! {
404! use_operand_p use_a, use_b;
405! imm_use_iterator imm_iter;
406! ssa_op_iter op_iter, op_iter1;
407! tree op0 = TREE_OPERAND (stmt, 0);
408! tree scev = instantiate_parameters
409! (loop, analyze_scalar_evolution (loop, op0));
410!
411! /* If the IV is simple, it can be duplicated. */
412! if (!automatically_generated_chrec_p (scev))
413! {
414! tree step = evolution_part_in_loop_num (scev, loop->num);
415! if (step && step != chrec_dont_know
416! && TREE_CODE (step) == INTEGER_CST)
417! continue;
418! }
419!
420! /* The statement should not define a variable used
421! in the inner loop. */
422! if (TREE_CODE (op0) == SSA_NAME)
423! FOR_EACH_IMM_USE_FAST (use_a, imm_iter, op0)
424! if (bb_for_stmt (USE_STMT (use_a))->loop_father
425! == loop->inner)
426! goto fail;
427!
428! FOR_EACH_SSA_USE_OPERAND (use_a, stmt, op_iter, SSA_OP_USE)
429! {
430! tree node, op = USE_FROM_PTR (use_a);
431!
432! /* The variables should not be used in both loops. */
433! FOR_EACH_IMM_USE_FAST (use_b, imm_iter, op)
434! if (bb_for_stmt (USE_STMT (use_b))->loop_father
435! == loop->inner)
436! goto fail;
437!
438! /* The statement should not use the value of a
439! scalar that was modified in the loop. */
440! node = SSA_NAME_DEF_STMT (op);
441! if (TREE_CODE (node) == PHI_NODE)
442! FOR_EACH_PHI_ARG (use_b, node, op_iter1, SSA_OP_USE)
443! {
444! tree arg = USE_FROM_PTR (use_b);
445!
446! if (TREE_CODE (arg) == SSA_NAME)
447! {
448! tree arg_stmt = SSA_NAME_DEF_STMT (arg);
449!
450! if (bb_for_stmt (arg_stmt)->loop_father
451! == loop->inner)
452! goto fail;
453! }
454! }
455! }
456!
457! if (can_put_in_inner_loop (loop->inner, stmt)
458! || can_put_after_inner_loop (loop, stmt))
459! continue;
460! }
461
462 /* Otherwise, if the bb of a statement we care about isn't
463 dominated by the header of the inner loop, then we can't
464*************** perfect_nestify (struct loops *loops,
465*** 2379,2392 ****
466 tree stmt;
467 tree oldivvar, ivvar, ivvarinced;
468 VEC(tree,heap) *phis = NULL;
469!
470! if (!can_convert_to_perfect_nest (loop, loopivs))
471! return false;
472!
473! /* Create the new loop */
474!
475 olddest = loop->single_exit->dest;
476! preheaderbb = loop_split_edge_with (loop->single_exit, NULL);
477 headerbb = create_empty_bb (EXIT_BLOCK_PTR->prev_bb);
478
479 /* Push the exit phi nodes that we are moving. */
480--- 2442,2451 ----
481 tree stmt;
482 tree oldivvar, ivvar, ivvarinced;
483 VEC(tree,heap) *phis = NULL;
484!
485! /* Create the new loop. */
486 olddest = loop->single_exit->dest;
487! preheaderbb = loop_split_edge_with (loop->single_exit, NULL);
488 headerbb = create_empty_bb (EXIT_BLOCK_PTR->prev_bb);
489
490 /* Push the exit phi nodes that we are moving. */
491*************** perfect_nestify (struct loops *loops,
492*** 2552,2561 ****
493 continue;
494 }
495
496! replace_uses_equiv_to_x_with_y (loop, stmt,
497! oldivvar,
498! VEC_index (int, steps, 0),
499! ivvar);
500 bsi_move_before (&bsi, &tobsi);
501
502 /* If the statement has any virtual operands, they may
503--- 2611,2619 ----
504 continue;
505 }
506
507! replace_uses_equiv_to_x_with_y
508! (loop, stmt, oldivvar, VEC_index (int, steps, 0), ivvar);
509!
510 bsi_move_before (&bsi, &tobsi);
511
512 /* If the statement has any virtual operands, they may
513
This page took 0.103134 seconds and 4 git commands to generate.