Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa-loop-ch.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Loop header copying on trees. | 1 /* Loop header copying on trees. |
2 Copyright (C) 2004-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2004-2018 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it | 6 GCC is free software; you can redistribute it and/or modify it |
7 under the terms of the GNU General Public License as published by the | 7 under the terms of the GNU General Public License as published by the |
55 | 55 |
56 /* Loop header copying usually increases size of the code. This used not to | 56 /* Loop header copying usually increases size of the code. This used not to |
57 be true, since quite often it is possible to verify that the condition is | 57 be true, since quite often it is possible to verify that the condition is |
58 satisfied in the first iteration and therefore to eliminate it. Jump | 58 satisfied in the first iteration and therefore to eliminate it. Jump |
59 threading handles these cases now. */ | 59 threading handles these cases now. */ |
60 if (optimize_loop_for_size_p (loop)) | 60 if (optimize_loop_for_size_p (loop) |
61 && !loop->force_vectorize) | |
61 { | 62 { |
62 if (dump_file && (dump_flags & TDF_DETAILS)) | 63 if (dump_file && (dump_flags & TDF_DETAILS)) |
63 fprintf (dump_file, | 64 fprintf (dump_file, |
64 " Not duplicating bb %i: optimizing for size.\n", | 65 " Not duplicating bb %i: optimizing for size.\n", |
65 header->index); | 66 header->index); |
162 "Loop %i is not do-while loop: latch is not empty.\n", | 163 "Loop %i is not do-while loop: latch is not empty.\n", |
163 loop->num); | 164 loop->num); |
164 return false; | 165 return false; |
165 } | 166 } |
166 | 167 |
167 /* If the header contains just a condition, it is not a do-while loop. */ | 168 /* If the latch does not have a single predecessor, it is not a |
168 stmt = last_and_only_stmt (loop->header); | 169 do-while loop. */ |
169 if (stmt | 170 if (!single_pred_p (loop->latch)) |
170 && gimple_code (stmt) == GIMPLE_COND) | 171 { |
171 { | 172 if (dump_file && (dump_flags & TDF_DETAILS)) |
172 if (dump_file && (dump_flags & TDF_DETAILS)) | 173 fprintf (dump_file, |
173 fprintf (dump_file, | 174 "Loop %i is not do-while loop: latch has multiple " |
174 "Loop %i is not do-while loop: " | 175 "predecessors.\n", loop->num); |
175 "header contains just condition.\n", loop->num); | 176 return false; |
176 return false; | 177 } |
177 } | 178 |
179 /* If the latch predecessor doesn't exit the loop, it is not a | |
180 do-while loop. */ | |
181 if (!loop_exits_from_bb_p (loop, single_pred (loop->latch))) | |
182 { | |
183 if (dump_file && (dump_flags & TDF_DETAILS)) | |
184 fprintf (dump_file, | |
185 "Loop %i is not do-while loop: latch predecessor " | |
186 "does not exit loop.\n", loop->num); | |
187 return false; | |
188 } | |
189 | |
178 if (dump_file && (dump_flags & TDF_DETAILS)) | 190 if (dump_file && (dump_flags & TDF_DETAILS)) |
179 fprintf (dump_file, "Loop %i is do-while loop\n", loop->num); | 191 fprintf (dump_file, "Loop %i is do-while loop\n", loop->num); |
180 | 192 |
181 return true; | 193 return true; |
182 } | 194 } |
302 header = loop->header; | 314 header = loop->header; |
303 | 315 |
304 /* If the loop is already a do-while style one (either because it was | 316 /* If the loop is already a do-while style one (either because it was |
305 written as such, or because jump threading transformed it into one), | 317 written as such, or because jump threading transformed it into one), |
306 we might be in fact peeling the first iteration of the loop. This | 318 we might be in fact peeling the first iteration of the loop. This |
307 in general is not a good idea. */ | 319 in general is not a good idea. Also avoid touching infinite loops. */ |
308 if (!process_loop_p (loop)) | 320 if (!loop_has_exit_edges (loop) |
321 || !process_loop_p (loop)) | |
309 continue; | 322 continue; |
310 | 323 |
311 /* Iterate the header copying up to limit; this takes care of the cases | 324 /* Iterate the header copying up to limit; this takes care of the cases |
312 like while (a && b) {...}, where we want to have both of the conditions | 325 like while (a && b) {...}, where we want to have both of the conditions |
313 copied. TODO -- handle while (a || b) - like cases, by not requiring | 326 copied. TODO -- handle while (a || b) - like cases, by not requiring |
325 else | 338 else |
326 exit = EDGE_SUCC (header, 1); | 339 exit = EDGE_SUCC (header, 1); |
327 bbs[n_bbs++] = header; | 340 bbs[n_bbs++] = header; |
328 gcc_assert (bbs_size > n_bbs); | 341 gcc_assert (bbs_size > n_bbs); |
329 header = exit->dest; | 342 header = exit->dest; |
343 /* Make sure to stop copying after we copied the first exit test. | |
344 Without further heuristics we do not want to rotate the loop | |
345 any further. */ | |
346 if (loop_exits_from_bb_p (loop, exit->src)) | |
347 break; | |
330 } | 348 } |
331 | 349 |
332 if (!exit) | 350 if (!exit) |
333 continue; | 351 continue; |
334 | 352 |
389 /* Ensure that the latch and the preheader is simple (we know that they | 407 /* Ensure that the latch and the preheader is simple (we know that they |
390 are not now, since there was the loop exit condition. */ | 408 are not now, since there was the loop exit condition. */ |
391 split_edge (loop_preheader_edge (loop)); | 409 split_edge (loop_preheader_edge (loop)); |
392 split_edge (loop_latch_edge (loop)); | 410 split_edge (loop_latch_edge (loop)); |
393 | 411 |
412 if (dump_file && (dump_flags & TDF_DETAILS)) | |
413 { | |
414 if (do_while_loop_p (loop)) | |
415 fprintf (dump_file, "Loop %d is now do-while loop.\n", loop->num); | |
416 else | |
417 fprintf (dump_file, "Loop %d is still not do-while loop.\n", | |
418 loop->num); | |
419 } | |
420 | |
394 changed = true; | 421 changed = true; |
395 } | 422 } |
396 | 423 |
397 if (changed) | 424 if (changed) |
398 update_ssa (TODO_update_ssa); | 425 update_ssa (TODO_update_ssa); |
406 | 433 |
407 unsigned int | 434 unsigned int |
408 pass_ch::execute (function *fun) | 435 pass_ch::execute (function *fun) |
409 { | 436 { |
410 loop_optimizer_init (LOOPS_HAVE_PREHEADERS | 437 loop_optimizer_init (LOOPS_HAVE_PREHEADERS |
411 | LOOPS_HAVE_SIMPLE_LATCHES); | 438 | LOOPS_HAVE_SIMPLE_LATCHES |
439 | LOOPS_HAVE_RECORDED_EXITS); | |
412 | 440 |
413 unsigned int res = copy_headers (fun); | 441 unsigned int res = copy_headers (fun); |
414 | 442 |
415 loop_optimizer_finalize (); | 443 loop_optimizer_finalize (); |
416 return res; | 444 return res; |