Mercurial > hg > CbC > CbC_gcc
annotate gcc/tree-ssa-loop.c @ 144:8f4e72ab4e11
fix segmentation fault caused by nothing next cur_op to end
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 23 Dec 2018 21:23:56 +0900 |
parents | 84e7813d76e9 |
children | 1830386684a0 |
rev | line source |
---|---|
0 | 1 /* Loop optimizations over tree-ssa. |
131 | 2 Copyright (C) 2003-2018 Free Software Foundation, Inc. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
3 |
0 | 4 This file is part of GCC. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
5 |
0 | 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 | |
8 Free Software Foundation; either version 3, or (at your option) any | |
9 later version. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
10 |
0 | 11 GCC is distributed in the hope that it will be useful, but WITHOUT |
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 for more details. | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
15 |
0 | 16 You should have received a copy of the GNU General Public License |
17 along with GCC; see the file COPYING3. If not see | |
18 <http://www.gnu.org/licenses/>. */ | |
19 | |
20 #include "config.h" | |
21 #include "system.h" | |
22 #include "coretypes.h" | |
111 | 23 #include "backend.h" |
0 | 24 #include "tree.h" |
111 | 25 #include "gimple.h" |
26 #include "tree-pass.h" | |
27 #include "memmodel.h" | |
0 | 28 #include "tm_p.h" |
111 | 29 #include "fold-const.h" |
30 #include "gimple-iterator.h" | |
31 #include "tree-ssa-loop-ivopts.h" | |
32 #include "tree-ssa-loop-manip.h" | |
33 #include "tree-ssa-loop-niter.h" | |
34 #include "tree-ssa-loop.h" | |
0 | 35 #include "cfgloop.h" |
36 #include "tree-inline.h" | |
37 #include "tree-scalar-evolution.h" | |
111 | 38 #include "tree-vectorizer.h" |
39 #include "omp-general.h" | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
40 #include "diagnostic-core.h" |
111 | 41 #include "stringpool.h" |
42 #include "attribs.h" | |
0 | 43 |
111 | 44 |
45 /* A pass making sure loops are fixed up. */ | |
0 | 46 |
111 | 47 namespace { |
48 | |
49 const pass_data pass_data_fix_loops = | |
0 | 50 { |
111 | 51 GIMPLE_PASS, /* type */ |
52 "fix_loops", /* name */ | |
53 OPTGROUP_LOOP, /* optinfo_flags */ | |
54 TV_TREE_LOOP, /* tv_id */ | |
55 PROP_cfg, /* properties_required */ | |
56 0, /* properties_provided */ | |
57 0, /* properties_destroyed */ | |
58 0, /* todo_flags_start */ | |
59 0, /* todo_flags_finish */ | |
0 | 60 }; |
61 | |
111 | 62 class pass_fix_loops : public gimple_opt_pass |
0 | 63 { |
111 | 64 public: |
65 pass_fix_loops (gcc::context *ctxt) | |
66 : gimple_opt_pass (pass_data_fix_loops, ctxt) | |
67 {} | |
68 | |
69 /* opt_pass methods: */ | |
70 virtual bool gate (function *) { return flag_tree_loop_optimize; } | |
0 | 71 |
111 | 72 virtual unsigned int execute (function *fn); |
73 }; // class pass_fix_loops | |
0 | 74 |
111 | 75 unsigned int |
76 pass_fix_loops::execute (function *) | |
77 { | |
78 if (loops_state_satisfies_p (LOOPS_NEED_FIXUP)) | |
79 { | |
80 calculate_dominance_info (CDI_DOMINATORS); | |
81 fix_loop_structure (NULL); | |
82 } | |
0 | 83 return 0; |
84 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
85 |
111 | 86 } // anon namespace |
87 | |
88 gimple_opt_pass * | |
89 make_pass_fix_loops (gcc::context *ctxt) | |
90 { | |
91 return new pass_fix_loops (ctxt); | |
92 } | |
93 | |
94 | |
95 /* Gate for loop pass group. The group is controlled by -ftree-loop-optimize | |
96 but we also avoid running it when the IL doesn't contain any loop. */ | |
97 | |
98 static bool | |
99 gate_loop (function *fn) | |
0 | 100 { |
111 | 101 if (!flag_tree_loop_optimize) |
102 return false; | |
103 | |
104 /* For -fdump-passes which runs before loop discovery print the | |
105 state of -ftree-loop-optimize. */ | |
106 if (!loops_for_fn (fn)) | |
107 return true; | |
108 | |
109 return number_of_loops (fn) > 1; | |
110 } | |
111 | |
112 /* The loop superpass. */ | |
113 | |
114 namespace { | |
115 | |
116 const pass_data pass_data_tree_loop = | |
117 { | |
118 GIMPLE_PASS, /* type */ | |
119 "loop", /* name */ | |
120 OPTGROUP_LOOP, /* optinfo_flags */ | |
121 TV_TREE_LOOP, /* tv_id */ | |
122 PROP_cfg, /* properties_required */ | |
123 0, /* properties_provided */ | |
124 0, /* properties_destroyed */ | |
125 0, /* todo_flags_start */ | |
126 0, /* todo_flags_finish */ | |
0 | 127 }; |
128 | |
111 | 129 class pass_tree_loop : public gimple_opt_pass |
0 | 130 { |
111 | 131 public: |
132 pass_tree_loop (gcc::context *ctxt) | |
133 : gimple_opt_pass (pass_data_tree_loop, ctxt) | |
134 {} | |
135 | |
136 /* opt_pass methods: */ | |
137 virtual bool gate (function *fn) { return gate_loop (fn); } | |
0 | 138 |
111 | 139 }; // class pass_tree_loop |
140 | |
141 } // anon namespace | |
142 | |
143 gimple_opt_pass * | |
144 make_pass_tree_loop (gcc::context *ctxt) | |
145 { | |
146 return new pass_tree_loop (ctxt); | |
0 | 147 } |
148 | |
111 | 149 /* Gate for oacc kernels pass group. */ |
150 | |
0 | 151 static bool |
111 | 152 gate_oacc_kernels (function *fn) |
0 | 153 { |
111 | 154 if (!flag_openacc) |
155 return false; | |
156 | |
157 if (!lookup_attribute ("oacc kernels", DECL_ATTRIBUTES (fn->decl))) | |
158 return false; | |
159 | |
160 struct loop *loop; | |
161 FOR_EACH_LOOP (loop, 0) | |
162 if (loop->in_oacc_kernels_region) | |
163 return true; | |
164 | |
165 return false; | |
0 | 166 } |
167 | |
111 | 168 /* The oacc kernels superpass. */ |
169 | |
170 namespace { | |
171 | |
172 const pass_data pass_data_oacc_kernels = | |
173 { | |
174 GIMPLE_PASS, /* type */ | |
175 "oacc_kernels", /* name */ | |
176 OPTGROUP_LOOP, /* optinfo_flags */ | |
177 TV_TREE_LOOP, /* tv_id */ | |
178 PROP_cfg, /* properties_required */ | |
179 0, /* properties_provided */ | |
180 0, /* properties_destroyed */ | |
181 0, /* todo_flags_start */ | |
182 0, /* todo_flags_finish */ | |
183 }; | |
184 | |
185 class pass_oacc_kernels : public gimple_opt_pass | |
0 | 186 { |
111 | 187 public: |
188 pass_oacc_kernels (gcc::context *ctxt) | |
189 : gimple_opt_pass (pass_data_oacc_kernels, ctxt) | |
190 {} | |
191 | |
192 /* opt_pass methods: */ | |
193 virtual bool gate (function *fn) { return gate_oacc_kernels (fn); } | |
194 | |
195 }; // class pass_oacc_kernels | |
196 | |
197 } // anon namespace | |
198 | |
199 gimple_opt_pass * | |
200 make_pass_oacc_kernels (gcc::context *ctxt) | |
201 { | |
202 return new pass_oacc_kernels (ctxt); | |
203 } | |
204 | |
205 /* The ipa oacc superpass. */ | |
206 | |
207 namespace { | |
208 | |
209 const pass_data pass_data_ipa_oacc = | |
210 { | |
211 SIMPLE_IPA_PASS, /* type */ | |
212 "ipa_oacc", /* name */ | |
213 OPTGROUP_LOOP, /* optinfo_flags */ | |
214 TV_TREE_LOOP, /* tv_id */ | |
215 PROP_cfg, /* properties_required */ | |
216 0, /* properties_provided */ | |
217 0, /* properties_destroyed */ | |
218 0, /* todo_flags_start */ | |
219 0, /* todo_flags_finish */ | |
0 | 220 }; |
221 | |
111 | 222 class pass_ipa_oacc : public simple_ipa_opt_pass |
0 | 223 { |
111 | 224 public: |
225 pass_ipa_oacc (gcc::context *ctxt) | |
226 : simple_ipa_opt_pass (pass_data_ipa_oacc, ctxt) | |
227 {} | |
0 | 228 |
111 | 229 /* opt_pass methods: */ |
230 virtual bool gate (function *) | |
231 { | |
232 return (optimize | |
233 && flag_openacc | |
234 /* Don't bother doing anything if the program has errors. */ | |
235 && !seen_error ()); | |
236 } | |
0 | 237 |
111 | 238 }; // class pass_ipa_oacc |
239 | |
240 } // anon namespace | |
241 | |
242 simple_ipa_opt_pass * | |
243 make_pass_ipa_oacc (gcc::context *ctxt) | |
0 | 244 { |
111 | 245 return new pass_ipa_oacc (ctxt); |
0 | 246 } |
247 | |
111 | 248 /* The ipa oacc kernels pass. */ |
249 | |
250 namespace { | |
251 | |
252 const pass_data pass_data_ipa_oacc_kernels = | |
0 | 253 { |
111 | 254 SIMPLE_IPA_PASS, /* type */ |
255 "ipa_oacc_kernels", /* name */ | |
256 OPTGROUP_LOOP, /* optinfo_flags */ | |
257 TV_TREE_LOOP, /* tv_id */ | |
258 PROP_cfg, /* properties_required */ | |
259 0, /* properties_provided */ | |
260 0, /* properties_destroyed */ | |
261 0, /* todo_flags_start */ | |
262 0, /* todo_flags_finish */ | |
0 | 263 }; |
264 | |
111 | 265 class pass_ipa_oacc_kernels : public simple_ipa_opt_pass |
0 | 266 { |
111 | 267 public: |
268 pass_ipa_oacc_kernels (gcc::context *ctxt) | |
269 : simple_ipa_opt_pass (pass_data_ipa_oacc_kernels, ctxt) | |
270 {} | |
271 | |
272 }; // class pass_ipa_oacc_kernels | |
0 | 273 |
111 | 274 } // anon namespace |
275 | |
276 simple_ipa_opt_pass * | |
277 make_pass_ipa_oacc_kernels (gcc::context *ctxt) | |
278 { | |
279 return new pass_ipa_oacc_kernels (ctxt); | |
0 | 280 } |
281 | |
111 | 282 /* The no-loop superpass. */ |
283 | |
284 namespace { | |
285 | |
286 const pass_data pass_data_tree_no_loop = | |
0 | 287 { |
111 | 288 GIMPLE_PASS, /* type */ |
289 "no_loop", /* name */ | |
290 OPTGROUP_NONE, /* optinfo_flags */ | |
291 TV_TREE_NOLOOP, /* tv_id */ | |
292 PROP_cfg, /* properties_required */ | |
293 0, /* properties_provided */ | |
294 0, /* properties_destroyed */ | |
295 0, /* todo_flags_start */ | |
296 0, /* todo_flags_finish */ | |
297 }; | |
298 | |
299 class pass_tree_no_loop : public gimple_opt_pass | |
300 { | |
301 public: | |
302 pass_tree_no_loop (gcc::context *ctxt) | |
303 : gimple_opt_pass (pass_data_tree_no_loop, ctxt) | |
304 {} | |
305 | |
306 /* opt_pass methods: */ | |
307 virtual bool gate (function *fn) { return !gate_loop (fn); } | |
308 | |
309 }; // class pass_tree_no_loop | |
310 | |
311 } // anon namespace | |
312 | |
313 gimple_opt_pass * | |
314 make_pass_tree_no_loop (gcc::context *ctxt) | |
315 { | |
316 return new pass_tree_no_loop (ctxt); | |
0 | 317 } |
318 | |
111 | 319 |
320 /* Loop optimizer initialization. */ | |
321 | |
322 namespace { | |
323 | |
324 const pass_data pass_data_tree_loop_init = | |
325 { | |
326 GIMPLE_PASS, /* type */ | |
327 "loopinit", /* name */ | |
328 OPTGROUP_LOOP, /* optinfo_flags */ | |
329 TV_NONE, /* tv_id */ | |
330 PROP_cfg, /* properties_required */ | |
331 0, /* properties_provided */ | |
332 0, /* properties_destroyed */ | |
333 0, /* todo_flags_start */ | |
334 0, /* todo_flags_finish */ | |
335 }; | |
336 | |
337 class pass_tree_loop_init : public gimple_opt_pass | |
0 | 338 { |
111 | 339 public: |
340 pass_tree_loop_init (gcc::context *ctxt) | |
341 : gimple_opt_pass (pass_data_tree_loop_init, ctxt) | |
342 {} | |
343 | |
344 /* opt_pass methods: */ | |
345 virtual unsigned int execute (function *); | |
346 | |
347 }; // class pass_tree_loop_init | |
348 | |
349 unsigned int | |
350 pass_tree_loop_init::execute (function *fun ATTRIBUTE_UNUSED) | |
351 { | |
352 /* When processing a loop in the loop pipeline, we should be able to assert | |
353 that: | |
354 (loops_state_satisfies_p (LOOPS_NORMAL | LOOPS_HAVE_RECORDED_EXITS | |
355 | LOOP_CLOSED_SSA) | |
356 && scev_initialized_p ()) | |
357 */ | |
358 loop_optimizer_init (LOOPS_NORMAL | |
359 | LOOPS_HAVE_RECORDED_EXITS); | |
360 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa); | |
361 scev_initialize (); | |
362 | |
363 return 0; | |
364 } | |
365 | |
366 } // anon namespace | |
367 | |
368 gimple_opt_pass * | |
369 make_pass_tree_loop_init (gcc::context *ctxt) | |
370 { | |
371 return new pass_tree_loop_init (ctxt); | |
372 } | |
0 | 373 |
374 /* Loop autovectorization. */ | |
375 | |
111 | 376 namespace { |
377 | |
378 const pass_data pass_data_vectorize = | |
379 { | |
380 GIMPLE_PASS, /* type */ | |
381 "vect", /* name */ | |
382 OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */ | |
383 TV_TREE_VECTORIZATION, /* tv_id */ | |
384 ( PROP_cfg | PROP_ssa ), /* properties_required */ | |
385 0, /* properties_provided */ | |
386 0, /* properties_destroyed */ | |
387 0, /* todo_flags_start */ | |
388 0, /* todo_flags_finish */ | |
389 }; | |
390 | |
391 class pass_vectorize : public gimple_opt_pass | |
0 | 392 { |
111 | 393 public: |
394 pass_vectorize (gcc::context *ctxt) | |
395 : gimple_opt_pass (pass_data_vectorize, ctxt) | |
396 {} | |
397 | |
398 /* opt_pass methods: */ | |
399 virtual bool gate (function *fun) | |
400 { | |
401 return flag_tree_loop_vectorize || fun->has_force_vectorize_loops; | |
402 } | |
403 | |
404 virtual unsigned int execute (function *); | |
405 | |
406 }; // class pass_vectorize | |
407 | |
408 unsigned int | |
409 pass_vectorize::execute (function *fun) | |
410 { | |
411 if (number_of_loops (fun) <= 1) | |
0 | 412 return 0; |
413 | |
414 return vectorize_loops (); | |
415 } | |
416 | |
111 | 417 } // anon namespace |
0 | 418 |
111 | 419 gimple_opt_pass * |
420 make_pass_vectorize (gcc::context *ctxt) | |
0 | 421 { |
111 | 422 return new pass_vectorize (ctxt); |
0 | 423 } |
424 | |
425 /* Propagation of constants using scev. */ | |
426 | |
111 | 427 namespace { |
0 | 428 |
111 | 429 const pass_data pass_data_scev_cprop = |
0 | 430 { |
111 | 431 GIMPLE_PASS, /* type */ |
432 "sccp", /* name */ | |
433 OPTGROUP_LOOP, /* optinfo_flags */ | |
434 TV_SCEV_CONST, /* tv_id */ | |
435 ( PROP_cfg | PROP_ssa ), /* properties_required */ | |
436 0, /* properties_provided */ | |
437 0, /* properties_destroyed */ | |
438 0, /* todo_flags_start */ | |
439 ( TODO_cleanup_cfg | |
440 | TODO_update_ssa_only_virtuals ), /* todo_flags_finish */ | |
0 | 441 }; |
442 | |
111 | 443 class pass_scev_cprop : public gimple_opt_pass |
0 | 444 { |
111 | 445 public: |
446 pass_scev_cprop (gcc::context *ctxt) | |
447 : gimple_opt_pass (pass_data_scev_cprop, ctxt) | |
448 {} | |
0 | 449 |
111 | 450 /* opt_pass methods: */ |
451 virtual bool gate (function *) { return flag_tree_scev_cprop; } | |
452 virtual unsigned int execute (function *) { return scev_const_prop (); } | |
0 | 453 |
111 | 454 }; // class pass_scev_cprop |
0 | 455 |
111 | 456 } // anon namespace |
0 | 457 |
111 | 458 gimple_opt_pass * |
459 make_pass_scev_cprop (gcc::context *ctxt) | |
0 | 460 { |
111 | 461 return new pass_scev_cprop (ctxt); |
462 } | |
0 | 463 |
464 /* Induction variable optimizations. */ | |
465 | |
111 | 466 namespace { |
467 | |
468 const pass_data pass_data_iv_optimize = | |
0 | 469 { |
111 | 470 GIMPLE_PASS, /* type */ |
471 "ivopts", /* name */ | |
472 OPTGROUP_LOOP, /* optinfo_flags */ | |
473 TV_TREE_LOOP_IVOPTS, /* tv_id */ | |
474 ( PROP_cfg | PROP_ssa ), /* properties_required */ | |
475 0, /* properties_provided */ | |
476 0, /* properties_destroyed */ | |
477 0, /* todo_flags_start */ | |
478 TODO_update_ssa, /* todo_flags_finish */ | |
479 }; | |
480 | |
481 class pass_iv_optimize : public gimple_opt_pass | |
482 { | |
483 public: | |
484 pass_iv_optimize (gcc::context *ctxt) | |
485 : gimple_opt_pass (pass_data_iv_optimize, ctxt) | |
486 {} | |
487 | |
488 /* opt_pass methods: */ | |
489 virtual bool gate (function *) { return flag_ivopts != 0; } | |
490 virtual unsigned int execute (function *); | |
491 | |
492 }; // class pass_iv_optimize | |
493 | |
494 unsigned int | |
495 pass_iv_optimize::execute (function *fun) | |
496 { | |
497 if (number_of_loops (fun) <= 1) | |
0 | 498 return 0; |
499 | |
500 tree_ssa_iv_optimize (); | |
501 return 0; | |
502 } | |
503 | |
111 | 504 } // anon namespace |
0 | 505 |
111 | 506 gimple_opt_pass * |
507 make_pass_iv_optimize (gcc::context *ctxt) | |
0 | 508 { |
111 | 509 return new pass_iv_optimize (ctxt); |
510 } | |
0 | 511 |
512 /* Loop optimizer finalization. */ | |
513 | |
514 static unsigned int | |
515 tree_ssa_loop_done (void) | |
516 { | |
111 | 517 free_numbers_of_iterations_estimates (cfun); |
0 | 518 scev_finalize (); |
519 loop_optimizer_finalize (); | |
520 return 0; | |
521 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
522 |
111 | 523 namespace { |
524 | |
525 const pass_data pass_data_tree_loop_done = | |
526 { | |
527 GIMPLE_PASS, /* type */ | |
528 "loopdone", /* name */ | |
529 OPTGROUP_LOOP, /* optinfo_flags */ | |
530 TV_NONE, /* tv_id */ | |
531 PROP_cfg, /* properties_required */ | |
532 0, /* properties_provided */ | |
533 0, /* properties_destroyed */ | |
534 0, /* todo_flags_start */ | |
535 TODO_cleanup_cfg, /* todo_flags_finish */ | |
536 }; | |
537 | |
538 class pass_tree_loop_done : public gimple_opt_pass | |
539 { | |
540 public: | |
541 pass_tree_loop_done (gcc::context *ctxt) | |
542 : gimple_opt_pass (pass_data_tree_loop_done, ctxt) | |
543 {} | |
544 | |
545 /* opt_pass methods: */ | |
546 virtual unsigned int execute (function *) { return tree_ssa_loop_done (); } | |
547 | |
548 }; // class pass_tree_loop_done | |
549 | |
550 } // anon namespace | |
551 | |
552 gimple_opt_pass * | |
553 make_pass_tree_loop_done (gcc::context *ctxt) | |
554 { | |
555 return new pass_tree_loop_done (ctxt); | |
556 } | |
557 | |
558 /* Calls CBCK for each index in memory reference ADDR_P. There are two | |
559 kinds situations handled; in each of these cases, the memory reference | |
560 and DATA are passed to the callback: | |
561 | |
562 Access to an array: ARRAY_{RANGE_}REF (base, index). In this case we also | |
563 pass the pointer to the index to the callback. | |
564 | |
565 Pointer dereference: INDIRECT_REF (addr). In this case we also pass the | |
566 pointer to addr to the callback. | |
567 | |
568 If the callback returns false, the whole search stops and false is returned. | |
569 Otherwise the function returns true after traversing through the whole | |
570 reference *ADDR_P. */ | |
571 | |
572 bool | |
573 for_each_index (tree *addr_p, bool (*cbck) (tree, tree *, void *), void *data) | |
0 | 574 { |
111 | 575 tree *nxt, *idx; |
576 | |
577 for (; ; addr_p = nxt) | |
578 { | |
579 switch (TREE_CODE (*addr_p)) | |
580 { | |
581 case SSA_NAME: | |
582 return cbck (*addr_p, addr_p, data); | |
583 | |
584 case MEM_REF: | |
585 nxt = &TREE_OPERAND (*addr_p, 0); | |
586 return cbck (*addr_p, nxt, data); | |
587 | |
588 case BIT_FIELD_REF: | |
589 case VIEW_CONVERT_EXPR: | |
590 case REALPART_EXPR: | |
591 case IMAGPART_EXPR: | |
592 nxt = &TREE_OPERAND (*addr_p, 0); | |
593 break; | |
594 | |
595 case COMPONENT_REF: | |
596 /* If the component has varying offset, it behaves like index | |
597 as well. */ | |
598 idx = &TREE_OPERAND (*addr_p, 2); | |
599 if (*idx | |
600 && !cbck (*addr_p, idx, data)) | |
601 return false; | |
602 | |
603 nxt = &TREE_OPERAND (*addr_p, 0); | |
604 break; | |
605 | |
606 case ARRAY_REF: | |
607 case ARRAY_RANGE_REF: | |
608 nxt = &TREE_OPERAND (*addr_p, 0); | |
609 if (!cbck (*addr_p, &TREE_OPERAND (*addr_p, 1), data)) | |
610 return false; | |
611 break; | |
612 | |
613 case CONSTRUCTOR: | |
614 return true; | |
615 | |
616 case ADDR_EXPR: | |
617 gcc_assert (is_gimple_min_invariant (*addr_p)); | |
618 return true; | |
619 | |
620 case TARGET_MEM_REF: | |
621 idx = &TMR_BASE (*addr_p); | |
622 if (*idx | |
623 && !cbck (*addr_p, idx, data)) | |
624 return false; | |
625 idx = &TMR_INDEX (*addr_p); | |
626 if (*idx | |
627 && !cbck (*addr_p, idx, data)) | |
628 return false; | |
629 idx = &TMR_INDEX2 (*addr_p); | |
630 if (*idx | |
631 && !cbck (*addr_p, idx, data)) | |
632 return false; | |
633 return true; | |
634 | |
635 default: | |
131 | 636 if (DECL_P (*addr_p) |
637 || CONSTANT_CLASS_P (*addr_p)) | |
638 return true; | |
111 | 639 gcc_unreachable (); |
640 } | |
641 } | |
642 } | |
643 | |
644 | |
645 /* The name and the length of the currently generated variable | |
646 for lsm. */ | |
647 #define MAX_LSM_NAME_LENGTH 40 | |
648 static char lsm_tmp_name[MAX_LSM_NAME_LENGTH + 1]; | |
649 static int lsm_tmp_name_length; | |
650 | |
651 /* Adds S to lsm_tmp_name. */ | |
652 | |
653 static void | |
654 lsm_tmp_name_add (const char *s) | |
655 { | |
656 int l = strlen (s) + lsm_tmp_name_length; | |
657 if (l > MAX_LSM_NAME_LENGTH) | |
658 return; | |
659 | |
660 strcpy (lsm_tmp_name + lsm_tmp_name_length, s); | |
661 lsm_tmp_name_length = l; | |
662 } | |
663 | |
664 /* Stores the name for temporary variable that replaces REF to | |
665 lsm_tmp_name. */ | |
666 | |
667 static void | |
668 gen_lsm_tmp_name (tree ref) | |
669 { | |
670 const char *name; | |
671 | |
672 switch (TREE_CODE (ref)) | |
673 { | |
674 case MEM_REF: | |
675 case TARGET_MEM_REF: | |
676 gen_lsm_tmp_name (TREE_OPERAND (ref, 0)); | |
677 lsm_tmp_name_add ("_"); | |
678 break; | |
679 | |
680 case ADDR_EXPR: | |
681 gen_lsm_tmp_name (TREE_OPERAND (ref, 0)); | |
682 break; | |
683 | |
684 case BIT_FIELD_REF: | |
685 case VIEW_CONVERT_EXPR: | |
686 case ARRAY_RANGE_REF: | |
687 gen_lsm_tmp_name (TREE_OPERAND (ref, 0)); | |
688 break; | |
689 | |
690 case REALPART_EXPR: | |
691 gen_lsm_tmp_name (TREE_OPERAND (ref, 0)); | |
692 lsm_tmp_name_add ("_RE"); | |
693 break; | |
694 | |
695 case IMAGPART_EXPR: | |
696 gen_lsm_tmp_name (TREE_OPERAND (ref, 0)); | |
697 lsm_tmp_name_add ("_IM"); | |
698 break; | |
699 | |
700 case COMPONENT_REF: | |
701 gen_lsm_tmp_name (TREE_OPERAND (ref, 0)); | |
702 lsm_tmp_name_add ("_"); | |
703 name = get_name (TREE_OPERAND (ref, 1)); | |
704 if (!name) | |
705 name = "F"; | |
706 lsm_tmp_name_add (name); | |
707 break; | |
708 | |
709 case ARRAY_REF: | |
710 gen_lsm_tmp_name (TREE_OPERAND (ref, 0)); | |
711 lsm_tmp_name_add ("_I"); | |
712 break; | |
713 | |
714 case SSA_NAME: | |
715 case VAR_DECL: | |
716 case PARM_DECL: | |
717 case FUNCTION_DECL: | |
718 case LABEL_DECL: | |
719 name = get_name (ref); | |
720 if (!name) | |
721 name = "D"; | |
722 lsm_tmp_name_add (name); | |
723 break; | |
724 | |
725 case STRING_CST: | |
726 lsm_tmp_name_add ("S"); | |
727 break; | |
728 | |
729 case RESULT_DECL: | |
730 lsm_tmp_name_add ("R"); | |
731 break; | |
732 | |
733 case INTEGER_CST: | |
734 default: | |
735 /* Nothing. */ | |
736 break; | |
737 } | |
738 } | |
739 | |
740 /* Determines name for temporary variable that replaces REF. | |
741 The name is accumulated into the lsm_tmp_name variable. | |
742 N is added to the name of the temporary. */ | |
743 | |
744 char * | |
745 get_lsm_tmp_name (tree ref, unsigned n, const char *suffix) | |
746 { | |
747 char ns[2]; | |
748 | |
749 lsm_tmp_name_length = 0; | |
750 gen_lsm_tmp_name (ref); | |
751 lsm_tmp_name_add ("_lsm"); | |
752 if (n < 10) | |
753 { | |
754 ns[0] = '0' + n; | |
755 ns[1] = 0; | |
756 lsm_tmp_name_add (ns); | |
757 } | |
758 return lsm_tmp_name; | |
759 if (suffix != NULL) | |
760 lsm_tmp_name_add (suffix); | |
761 } | |
762 | |
763 /* Computes an estimated number of insns in LOOP, weighted by WEIGHTS. */ | |
764 | |
765 unsigned | |
766 tree_num_loop_insns (struct loop *loop, eni_weights *weights) | |
767 { | |
768 basic_block *body = get_loop_body (loop); | |
769 gimple_stmt_iterator gsi; | |
770 unsigned size = 0, i; | |
771 | |
772 for (i = 0; i < loop->num_nodes; i++) | |
773 for (gsi = gsi_start_bb (body[i]); !gsi_end_p (gsi); gsi_next (&gsi)) | |
774 size += estimate_num_insns (gsi_stmt (gsi), weights); | |
775 free (body); | |
776 | |
777 return size; | |
778 } | |
779 | |
780 | |
781 |