]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/lra-lives.c
2015-06-04 Andrew MacLeod <amacleod@redhat.com>
[thirdparty/gcc.git] / gcc / lra-lives.c
1 /* Build live ranges for pseudos.
2 Copyright (C) 2010-2015 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21
22 /* This file contains code to build pseudo live-ranges (analogous
23 structures used in IRA, so read comments about the live-ranges
24 there) and other info necessary for other passes to assign
25 hard-registers to pseudos, coalesce the spilled pseudos, and assign
26 stack memory slots to spilled pseudos. */
27
28 #include "config.h"
29 #include "system.h"
30 #include "coretypes.h"
31 #include "tm.h"
32 #include "hard-reg-set.h"
33 #include "rtl.h"
34 #include "tm_p.h"
35 #include "insn-config.h"
36 #include "recog.h"
37 #include "output.h"
38 #include "regs.h"
39 #include "hashtab.h"
40 #include "hash-set.h"
41 #include "vec.h"
42 #include "input.h"
43 #include "function.h"
44 #include "symtab.h"
45 #include "flags.h"
46 #include "statistics.h"
47 #include "alias.h"
48 #include "inchash.h"
49 #include "tree.h"
50 #include "expmed.h"
51 #include "dojump.h"
52 #include "explow.h"
53 #include "calls.h"
54 #include "emit-rtl.h"
55 #include "varasm.h"
56 #include "stmt.h"
57 #include "expr.h"
58 #include "predict.h"
59 #include "dominance.h"
60 #include "cfg.h"
61 #include "cfganal.h"
62 #include "basic-block.h"
63 #include "except.h"
64 #include "df.h"
65 #include "ira.h"
66 #include "sparseset.h"
67 #include "lra-int.h"
68
69 /* Program points are enumerated by numbers from range
70 0..LRA_LIVE_MAX_POINT-1. There are approximately two times more
71 program points than insns. Program points are places in the
72 program where liveness info can be changed. In most general case
73 (there are more complicated cases too) some program points
74 correspond to places where input operand dies and other ones
75 correspond to places where output operands are born. */
76 int lra_live_max_point;
77
78 /* Accumulated execution frequency of all references for each hard
79 register. */
80 int lra_hard_reg_usage[FIRST_PSEUDO_REGISTER];
81
82 /* A global flag whose true value says to build live ranges for all
83 pseudos, otherwise the live ranges only for pseudos got memory is
84 build. True value means also building copies and setting up hard
85 register preferences. The complete info is necessary only for the
86 assignment pass. The complete info is not needed for the
87 coalescing and spill passes. */
88 static bool complete_info_p;
89
90 /* Pseudos live at current point in the RTL scan. */
91 static sparseset pseudos_live;
92
93 /* Pseudos probably living through calls and setjumps. As setjump is
94 a call too, if a bit in PSEUDOS_LIVE_THROUGH_SETJUMPS is set up
95 then the corresponding bit in PSEUDOS_LIVE_THROUGH_CALLS is set up
96 too. These data are necessary for cases when only one subreg of a
97 multi-reg pseudo is set up after a call. So we decide it is
98 probably live when traversing bb backward. We are sure about
99 living when we see its usage or definition of the pseudo. */
100 static sparseset pseudos_live_through_calls;
101 static sparseset pseudos_live_through_setjumps;
102
103 /* Set of hard regs (except eliminable ones) currently live. */
104 static HARD_REG_SET hard_regs_live;
105
106 /* Set of pseudos and hard registers start living/dying in the current
107 insn. These sets are used to update REG_DEAD and REG_UNUSED notes
108 in the insn. */
109 static sparseset start_living, start_dying;
110
111 /* Set of pseudos and hard regs dead and unused in the current
112 insn. */
113 static sparseset unused_set, dead_set;
114
115 /* Bitmap used for holding intermediate bitmap operation results. */
116 static bitmap_head temp_bitmap;
117
118 /* Pool for pseudo live ranges. */
119 pool_allocator <lra_live_range> lra_live_range::pool ("live ranges", 100);
120
121 /* Free live range list LR. */
122 static void
123 free_live_range_list (lra_live_range_t lr)
124 {
125 lra_live_range_t next;
126
127 while (lr != NULL)
128 {
129 next = lr->next;
130 delete lr;
131 lr = next;
132 }
133 }
134
135 /* Create and return pseudo live range with given attributes. */
136 static lra_live_range_t
137 create_live_range (int regno, int start, int finish, lra_live_range_t next)
138 {
139 lra_live_range_t p = new lra_live_range;
140 p->regno = regno;
141 p->start = start;
142 p->finish = finish;
143 p->next = next;
144 return p;
145 }
146
147 /* Copy live range R and return the result. */
148 static lra_live_range_t
149 copy_live_range (lra_live_range_t r)
150 {
151 return new lra_live_range (*r);
152 }
153
154 /* Copy live range list given by its head R and return the result. */
155 lra_live_range_t
156 lra_copy_live_range_list (lra_live_range_t r)
157 {
158 lra_live_range_t p, first, *chain;
159
160 first = NULL;
161 for (chain = &first; r != NULL; r = r->next)
162 {
163 p = copy_live_range (r);
164 *chain = p;
165 chain = &p->next;
166 }
167 return first;
168 }
169
170 /* Merge *non-intersected* ranges R1 and R2 and returns the result.
171 The function maintains the order of ranges and tries to minimize
172 size of the result range list. Ranges R1 and R2 may not be used
173 after the call. */
174 lra_live_range_t
175 lra_merge_live_ranges (lra_live_range_t r1, lra_live_range_t r2)
176 {
177 lra_live_range_t first, last;
178
179 if (r1 == NULL)
180 return r2;
181 if (r2 == NULL)
182 return r1;
183 for (first = last = NULL; r1 != NULL && r2 != NULL;)
184 {
185 if (r1->start < r2->start)
186 std::swap (r1, r2);
187
188 if (r1->start == r2->finish + 1)
189 {
190 /* Joint ranges: merge r1 and r2 into r1. */
191 r1->start = r2->start;
192 lra_live_range_t temp = r2;
193 r2 = r2->next;
194 delete temp;
195 }
196 else
197 {
198 gcc_assert (r2->finish + 1 < r1->start);
199 /* Add r1 to the result. */
200 if (first == NULL)
201 first = last = r1;
202 else
203 {
204 last->next = r1;
205 last = r1;
206 }
207 r1 = r1->next;
208 }
209 }
210 if (r1 != NULL)
211 {
212 if (first == NULL)
213 first = r1;
214 else
215 last->next = r1;
216 }
217 else
218 {
219 lra_assert (r2 != NULL);
220 if (first == NULL)
221 first = r2;
222 else
223 last->next = r2;
224 }
225 return first;
226 }
227
228 /* Return TRUE if live ranges R1 and R2 intersect. */
229 bool
230 lra_intersected_live_ranges_p (lra_live_range_t r1, lra_live_range_t r2)
231 {
232 /* Remember the live ranges are always kept ordered. */
233 while (r1 != NULL && r2 != NULL)
234 {
235 if (r1->start > r2->finish)
236 r1 = r1->next;
237 else if (r2->start > r1->finish)
238 r2 = r2->next;
239 else
240 return true;
241 }
242 return false;
243 }
244
245 /* The function processing birth of hard register REGNO. It updates
246 living hard regs, START_LIVING, and conflict hard regs for living
247 pseudos. Conflict hard regs for the pic pseudo is not updated if
248 REGNO is REAL_PIC_OFFSET_TABLE_REGNUM and CHECK_PIC_PSEUDO_P is
249 true. */
250 static void
251 make_hard_regno_born (int regno, bool check_pic_pseudo_p ATTRIBUTE_UNUSED)
252 {
253 unsigned int i;
254
255 lra_assert (regno < FIRST_PSEUDO_REGISTER);
256 if (TEST_HARD_REG_BIT (hard_regs_live, regno))
257 return;
258 SET_HARD_REG_BIT (hard_regs_live, regno);
259 sparseset_set_bit (start_living, regno);
260 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
261 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
262 if (! check_pic_pseudo_p
263 || regno != REAL_PIC_OFFSET_TABLE_REGNUM
264 || pic_offset_table_rtx == NULL
265 || i != REGNO (pic_offset_table_rtx))
266 #endif
267 SET_HARD_REG_BIT (lra_reg_info[i].conflict_hard_regs, regno);
268 }
269
270 /* Process the death of hard register REGNO. This updates
271 hard_regs_live and START_DYING. */
272 static void
273 make_hard_regno_dead (int regno)
274 {
275 lra_assert (regno < FIRST_PSEUDO_REGISTER);
276 if (! TEST_HARD_REG_BIT (hard_regs_live, regno))
277 return;
278 sparseset_set_bit (start_dying, regno);
279 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
280 }
281
282 /* Mark pseudo REGNO as living at program point POINT, update conflicting
283 hard registers of the pseudo and START_LIVING, and start a new live
284 range for the pseudo corresponding to REGNO if it is necessary. */
285 static void
286 mark_pseudo_live (int regno, int point)
287 {
288 lra_live_range_t p;
289
290 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
291 lra_assert (! sparseset_bit_p (pseudos_live, regno));
292 sparseset_set_bit (pseudos_live, regno);
293 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs, hard_regs_live);
294
295 if ((complete_info_p || lra_get_regno_hard_regno (regno) < 0)
296 && ((p = lra_reg_info[regno].live_ranges) == NULL
297 || (p->finish != point && p->finish + 1 != point)))
298 lra_reg_info[regno].live_ranges
299 = create_live_range (regno, point, -1, p);
300 sparseset_set_bit (start_living, regno);
301 }
302
303 /* Mark pseudo REGNO as not living at program point POINT and update
304 START_DYING.
305 This finishes the current live range for the pseudo corresponding
306 to REGNO. */
307 static void
308 mark_pseudo_dead (int regno, int point)
309 {
310 lra_live_range_t p;
311
312 lra_assert (regno >= FIRST_PSEUDO_REGISTER);
313 lra_assert (sparseset_bit_p (pseudos_live, regno));
314 sparseset_clear_bit (pseudos_live, regno);
315 sparseset_set_bit (start_dying, regno);
316 if (complete_info_p || lra_get_regno_hard_regno (regno) < 0)
317 {
318 p = lra_reg_info[regno].live_ranges;
319 lra_assert (p != NULL);
320 p->finish = point;
321 }
322 }
323
324 /* The corresponding bitmaps of BB currently being processed. */
325 static bitmap bb_killed_pseudos, bb_gen_pseudos;
326
327 /* Mark register REGNO (pseudo or hard register) in MODE as live at
328 program point POINT. Update BB_GEN_PSEUDOS.
329 Return TRUE if the liveness tracking sets were modified, or FALSE
330 if nothing changed. */
331 static bool
332 mark_regno_live (int regno, machine_mode mode, int point)
333 {
334 int last;
335 bool changed = false;
336
337 if (regno < FIRST_PSEUDO_REGISTER)
338 {
339 for (last = regno + hard_regno_nregs[regno][mode];
340 regno < last;
341 regno++)
342 make_hard_regno_born (regno, false);
343 }
344 else
345 {
346 if (! sparseset_bit_p (pseudos_live, regno))
347 {
348 mark_pseudo_live (regno, point);
349 changed = true;
350 }
351 bitmap_set_bit (bb_gen_pseudos, regno);
352 }
353 return changed;
354 }
355
356
357 /* Mark register REGNO in MODE as dead at program point POINT. Update
358 BB_GEN_PSEUDOS and BB_KILLED_PSEUDOS. Return TRUE if the liveness
359 tracking sets were modified, or FALSE if nothing changed. */
360 static bool
361 mark_regno_dead (int regno, machine_mode mode, int point)
362 {
363 int last;
364 bool changed = false;
365
366 if (regno < FIRST_PSEUDO_REGISTER)
367 {
368 for (last = regno + hard_regno_nregs[regno][mode];
369 regno < last;
370 regno++)
371 make_hard_regno_dead (regno);
372 }
373 else
374 {
375 if (sparseset_bit_p (pseudos_live, regno))
376 {
377 mark_pseudo_dead (regno, point);
378 changed = true;
379 }
380 bitmap_clear_bit (bb_gen_pseudos, regno);
381 bitmap_set_bit (bb_killed_pseudos, regno);
382 }
383 return changed;
384 }
385
386 \f
387
388 /* This page contains code for making global live analysis of pseudos.
389 The code works only when pseudo live info is changed on a BB
390 border. That might be a consequence of some global transformations
391 in LRA, e.g. PIC pseudo reuse or rematerialization. */
392
393 /* Structure describing local BB data used for pseudo
394 live-analysis. */
395 struct bb_data_pseudos
396 {
397 /* Basic block about which the below data are. */
398 basic_block bb;
399 bitmap_head killed_pseudos; /* pseudos killed in the BB. */
400 bitmap_head gen_pseudos; /* pseudos generated in the BB. */
401 };
402
403 /* Array for all BB data. Indexed by the corresponding BB index. */
404 typedef struct bb_data_pseudos *bb_data_t;
405
406 /* All basic block data are referred through the following array. */
407 static bb_data_t bb_data;
408
409 /* Two small functions for access to the bb data. */
410 static inline bb_data_t
411 get_bb_data (basic_block bb)
412 {
413 return &bb_data[(bb)->index];
414 }
415
416 static inline bb_data_t
417 get_bb_data_by_index (int index)
418 {
419 return &bb_data[index];
420 }
421
422 /* Bitmap with all hard regs. */
423 static bitmap_head all_hard_regs_bitmap;
424
425 /* The transfer function used by the DF equation solver to propagate
426 live info through block with BB_INDEX according to the following
427 equation:
428
429 bb.livein = (bb.liveout - bb.kill) OR bb.gen
430 */
431 static bool
432 live_trans_fun (int bb_index)
433 {
434 basic_block bb = get_bb_data_by_index (bb_index)->bb;
435 bitmap bb_liveout = df_get_live_out (bb);
436 bitmap bb_livein = df_get_live_in (bb);
437 bb_data_t bb_info = get_bb_data (bb);
438
439 bitmap_and_compl (&temp_bitmap, bb_liveout, &all_hard_regs_bitmap);
440 return bitmap_ior_and_compl (bb_livein, &bb_info->gen_pseudos,
441 &temp_bitmap, &bb_info->killed_pseudos);
442 }
443
444 /* The confluence function used by the DF equation solver to set up
445 live info for a block BB without predecessor. */
446 static void
447 live_con_fun_0 (basic_block bb)
448 {
449 bitmap_and_into (df_get_live_out (bb), &all_hard_regs_bitmap);
450 }
451
452 /* The confluence function used by the DF equation solver to propagate
453 live info from successor to predecessor on edge E according to the
454 following equation:
455
456 bb.liveout = 0 for entry block | OR (livein of successors)
457 */
458 static bool
459 live_con_fun_n (edge e)
460 {
461 basic_block bb = e->src;
462 basic_block dest = e->dest;
463 bitmap bb_liveout = df_get_live_out (bb);
464 bitmap dest_livein = df_get_live_in (dest);
465
466 return bitmap_ior_and_compl_into (bb_liveout,
467 dest_livein, &all_hard_regs_bitmap);
468 }
469
470 /* Indexes of all function blocks. */
471 static bitmap_head all_blocks;
472
473 /* Allocate and initialize data needed for global pseudo live
474 analysis. */
475 static void
476 initiate_live_solver (void)
477 {
478 bitmap_initialize (&all_hard_regs_bitmap, &reg_obstack);
479 bitmap_set_range (&all_hard_regs_bitmap, 0, FIRST_PSEUDO_REGISTER);
480 bb_data = XNEWVEC (struct bb_data_pseudos, last_basic_block_for_fn (cfun));
481 bitmap_initialize (&all_blocks, &reg_obstack);
482
483 basic_block bb;
484 FOR_ALL_BB_FN (bb, cfun)
485 {
486 bb_data_t bb_info = get_bb_data (bb);
487 bb_info->bb = bb;
488 bitmap_initialize (&bb_info->killed_pseudos, &reg_obstack);
489 bitmap_initialize (&bb_info->gen_pseudos, &reg_obstack);
490 bitmap_set_bit (&all_blocks, bb->index);
491 }
492 }
493
494 /* Free all data needed for global pseudo live analysis. */
495 static void
496 finish_live_solver (void)
497 {
498 basic_block bb;
499
500 bitmap_clear (&all_blocks);
501 FOR_ALL_BB_FN (bb, cfun)
502 {
503 bb_data_t bb_info = get_bb_data (bb);
504 bitmap_clear (&bb_info->killed_pseudos);
505 bitmap_clear (&bb_info->gen_pseudos);
506 }
507 free (bb_data);
508 bitmap_clear (&all_hard_regs_bitmap);
509 }
510
511 \f
512
513 /* Insn currently scanned. */
514 static rtx_insn *curr_insn;
515 /* The insn data. */
516 static lra_insn_recog_data_t curr_id;
517 /* The insn static data. */
518 static struct lra_static_insn_data *curr_static_id;
519
520 /* Return true when one of the predecessor edges of BB is marked with
521 EDGE_ABNORMAL_CALL or EDGE_EH. */
522 static bool
523 bb_has_abnormal_call_pred (basic_block bb)
524 {
525 edge e;
526 edge_iterator ei;
527
528 FOR_EACH_EDGE (e, ei, bb->preds)
529 {
530 if (e->flags & (EDGE_ABNORMAL_CALL | EDGE_EH))
531 return true;
532 }
533 return false;
534 }
535
536 /* Vec containing execution frequencies of program points. */
537 static vec<int> point_freq_vec;
538
539 /* The start of the above vector elements. */
540 int *lra_point_freq;
541
542 /* Increment the current program point POINT to the next point which has
543 execution frequency FREQ. */
544 static void
545 next_program_point (int &point, int freq)
546 {
547 point_freq_vec.safe_push (freq);
548 lra_point_freq = point_freq_vec.address ();
549 point++;
550 }
551
552 /* Update the preference of HARD_REGNO for pseudo REGNO by PROFIT. */
553 void
554 lra_setup_reload_pseudo_preferenced_hard_reg (int regno,
555 int hard_regno, int profit)
556 {
557 lra_assert (regno >= lra_constraint_new_regno_start);
558 if (lra_reg_info[regno].preferred_hard_regno1 == hard_regno)
559 lra_reg_info[regno].preferred_hard_regno_profit1 += profit;
560 else if (lra_reg_info[regno].preferred_hard_regno2 == hard_regno)
561 lra_reg_info[regno].preferred_hard_regno_profit2 += profit;
562 else if (lra_reg_info[regno].preferred_hard_regno1 < 0)
563 {
564 lra_reg_info[regno].preferred_hard_regno1 = hard_regno;
565 lra_reg_info[regno].preferred_hard_regno_profit1 = profit;
566 }
567 else if (lra_reg_info[regno].preferred_hard_regno2 < 0
568 || profit > lra_reg_info[regno].preferred_hard_regno_profit2)
569 {
570 lra_reg_info[regno].preferred_hard_regno2 = hard_regno;
571 lra_reg_info[regno].preferred_hard_regno_profit2 = profit;
572 }
573 else
574 return;
575 /* Keep the 1st hard regno as more profitable. */
576 if (lra_reg_info[regno].preferred_hard_regno1 >= 0
577 && lra_reg_info[regno].preferred_hard_regno2 >= 0
578 && (lra_reg_info[regno].preferred_hard_regno_profit2
579 > lra_reg_info[regno].preferred_hard_regno_profit1))
580 {
581 int temp;
582
583 temp = lra_reg_info[regno].preferred_hard_regno1;
584 lra_reg_info[regno].preferred_hard_regno1
585 = lra_reg_info[regno].preferred_hard_regno2;
586 lra_reg_info[regno].preferred_hard_regno2 = temp;
587 temp = lra_reg_info[regno].preferred_hard_regno_profit1;
588 lra_reg_info[regno].preferred_hard_regno_profit1
589 = lra_reg_info[regno].preferred_hard_regno_profit2;
590 lra_reg_info[regno].preferred_hard_regno_profit2 = temp;
591 }
592 if (lra_dump_file != NULL)
593 {
594 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
595 fprintf (lra_dump_file,
596 " Hard reg %d is preferable by r%d with profit %d\n",
597 hard_regno, regno,
598 lra_reg_info[regno].preferred_hard_regno_profit1);
599 if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
600 fprintf (lra_dump_file,
601 " Hard reg %d is preferable by r%d with profit %d\n",
602 hard_regno, regno,
603 lra_reg_info[regno].preferred_hard_regno_profit2);
604 }
605 }
606
607 /* Check that REGNO living through calls and setjumps, set up conflict
608 regs, and clear corresponding bits in PSEUDOS_LIVE_THROUGH_CALLS and
609 PSEUDOS_LIVE_THROUGH_SETJUMPS. */
610 static inline void
611 check_pseudos_live_through_calls (int regno)
612 {
613 int hr;
614
615 if (! sparseset_bit_p (pseudos_live_through_calls, regno))
616 return;
617 sparseset_clear_bit (pseudos_live_through_calls, regno);
618 IOR_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs,
619 call_used_reg_set);
620
621 for (hr = 0; hr < FIRST_PSEUDO_REGISTER; hr++)
622 if (HARD_REGNO_CALL_PART_CLOBBERED (hr, PSEUDO_REGNO_MODE (regno)))
623 SET_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hr);
624 #ifdef ENABLE_CHECKING
625 lra_reg_info[regno].call_p = true;
626 #endif
627 if (! sparseset_bit_p (pseudos_live_through_setjumps, regno))
628 return;
629 sparseset_clear_bit (pseudos_live_through_setjumps, regno);
630 /* Don't allocate pseudos that cross setjmps or any call, if this
631 function receives a nonlocal goto. */
632 SET_HARD_REG_SET (lra_reg_info[regno].conflict_hard_regs);
633 }
634
635 /* Process insns of the basic block BB to update pseudo live ranges,
636 pseudo hard register conflicts, and insn notes. We do it on
637 backward scan of BB insns. CURR_POINT is the program point where
638 BB ends. The function updates this counter and returns in
639 CURR_POINT the program point where BB starts. The function also
640 does local live info updates and can delete the dead insns if
641 DEAD_INSN_P. It returns true if pseudo live info was
642 changed at the BB start. */
643 static bool
644 process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
645 {
646 int i, regno, freq;
647 unsigned int j;
648 bitmap_iterator bi;
649 bitmap reg_live_out;
650 unsigned int px;
651 rtx_insn *next;
652 rtx link, *link_loc;
653 bool need_curr_point_incr;
654
655 reg_live_out = df_get_live_out (bb);
656 sparseset_clear (pseudos_live);
657 sparseset_clear (pseudos_live_through_calls);
658 sparseset_clear (pseudos_live_through_setjumps);
659 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
660 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
661 EXECUTE_IF_SET_IN_BITMAP (reg_live_out, FIRST_PSEUDO_REGISTER, j, bi)
662 mark_pseudo_live (j, curr_point);
663
664 bb_gen_pseudos = &get_bb_data (bb)->gen_pseudos;
665 bb_killed_pseudos = &get_bb_data (bb)->killed_pseudos;
666 bitmap_clear (bb_gen_pseudos);
667 bitmap_clear (bb_killed_pseudos);
668 freq = REG_FREQ_FROM_BB (bb);
669
670 if (lra_dump_file != NULL)
671 fprintf (lra_dump_file, " BB %d\n", bb->index);
672
673 /* Scan the code of this basic block, noting which pseudos and hard
674 regs are born or die.
675
676 Note that this loop treats uninitialized values as live until the
677 beginning of the block. For example, if an instruction uses
678 (reg:DI foo), and only (subreg:SI (reg:DI foo) 0) is ever set,
679 FOO will remain live until the beginning of the block. Likewise
680 if FOO is not set at all. This is unnecessarily pessimistic, but
681 it probably doesn't matter much in practice. */
682 FOR_BB_INSNS_REVERSE_SAFE (bb, curr_insn, next)
683 {
684 bool call_p;
685 int dst_regno, src_regno;
686 rtx set;
687 struct lra_insn_reg *reg;
688
689 if (!NONDEBUG_INSN_P (curr_insn))
690 continue;
691
692 curr_id = lra_get_insn_recog_data (curr_insn);
693 curr_static_id = curr_id->insn_static_data;
694 if (lra_dump_file != NULL)
695 fprintf (lra_dump_file, " Insn %u: point = %d\n",
696 INSN_UID (curr_insn), curr_point);
697
698 set = single_set (curr_insn);
699
700 if (dead_insn_p && set != NULL_RTX
701 && REG_P (SET_DEST (set)) && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
702 && find_reg_note (curr_insn, REG_EH_REGION, NULL_RTX) == NULL_RTX
703 && ! may_trap_p (PATTERN (curr_insn))
704 /* Don't do premature remove of pic offset pseudo as we can
705 start to use it after some reload generation. */
706 && (pic_offset_table_rtx == NULL_RTX
707 || pic_offset_table_rtx != SET_DEST (set)))
708 {
709 bool remove_p = true;
710
711 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
712 if (reg->type != OP_IN && sparseset_bit_p (pseudos_live, reg->regno))
713 {
714 remove_p = false;
715 break;
716 }
717 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
718 if (reg->type != OP_IN)
719 {
720 remove_p = false;
721 break;
722 }
723 if (remove_p && ! volatile_refs_p (PATTERN (curr_insn)))
724 {
725 dst_regno = REGNO (SET_DEST (set));
726 if (lra_dump_file != NULL)
727 fprintf (lra_dump_file, " Deleting dead insn %u\n",
728 INSN_UID (curr_insn));
729 lra_set_insn_deleted (curr_insn);
730 if (lra_reg_info[dst_regno].nrefs == 0)
731 {
732 /* There might be some debug insns with the pseudo. */
733 unsigned int uid;
734 rtx_insn *insn;
735
736 bitmap_copy (&temp_bitmap, &lra_reg_info[dst_regno].insn_bitmap);
737 EXECUTE_IF_SET_IN_BITMAP (&temp_bitmap, 0, uid, bi)
738 {
739 insn = lra_insn_recog_data[uid]->insn;
740 lra_substitute_pseudo_within_insn (insn, dst_regno,
741 SET_SRC (set));
742 lra_update_insn_regno_info (insn);
743 }
744 }
745 continue;
746 }
747 }
748
749 /* Update max ref width and hard reg usage. */
750 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
751 if (reg->regno >= FIRST_PSEUDO_REGISTER
752 && (GET_MODE_SIZE (reg->biggest_mode)
753 > GET_MODE_SIZE (lra_reg_info[reg->regno].biggest_mode)))
754 lra_reg_info[reg->regno].biggest_mode = reg->biggest_mode;
755 else if (reg->regno < FIRST_PSEUDO_REGISTER)
756 lra_hard_reg_usage[reg->regno] += freq;
757
758 call_p = CALL_P (curr_insn);
759 if (complete_info_p
760 && set != NULL_RTX
761 && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set))
762 /* Check that source regno does not conflict with
763 destination regno to exclude most impossible
764 preferences. */
765 && ((((src_regno = REGNO (SET_SRC (set))) >= FIRST_PSEUDO_REGISTER
766 && ! sparseset_bit_p (pseudos_live, src_regno))
767 || (src_regno < FIRST_PSEUDO_REGISTER
768 && ! TEST_HARD_REG_BIT (hard_regs_live, src_regno)))
769 /* It might be 'inheritance pseudo <- reload pseudo'. */
770 || (src_regno >= lra_constraint_new_regno_start
771 && ((int) REGNO (SET_DEST (set))
772 >= lra_constraint_new_regno_start)
773 /* Remember to skip special cases where src/dest regnos are
774 the same, e.g. insn SET pattern has matching constraints
775 like =r,0. */
776 && src_regno != (int) REGNO (SET_DEST (set)))))
777 {
778 int hard_regno = -1, regno = -1;
779
780 dst_regno = REGNO (SET_DEST (set));
781 if (dst_regno >= lra_constraint_new_regno_start
782 && src_regno >= lra_constraint_new_regno_start)
783 lra_create_copy (dst_regno, src_regno, freq);
784 else if (dst_regno >= lra_constraint_new_regno_start)
785 {
786 if ((hard_regno = src_regno) >= FIRST_PSEUDO_REGISTER)
787 hard_regno = reg_renumber[src_regno];
788 regno = dst_regno;
789 }
790 else if (src_regno >= lra_constraint_new_regno_start)
791 {
792 if ((hard_regno = dst_regno) >= FIRST_PSEUDO_REGISTER)
793 hard_regno = reg_renumber[dst_regno];
794 regno = src_regno;
795 }
796 if (regno >= 0 && hard_regno >= 0)
797 lra_setup_reload_pseudo_preferenced_hard_reg
798 (regno, hard_regno, freq);
799 }
800
801 sparseset_clear (start_living);
802
803 /* Try to avoid unnecessary program point increments, this saves
804 a lot of time in remove_some_program_points_and_update_live_ranges.
805 We only need an increment if something becomes live or dies at this
806 program point. */
807 need_curr_point_incr = false;
808
809 /* Mark each defined value as live. We need to do this for
810 unused values because they still conflict with quantities
811 that are live at the time of the definition. */
812 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
813 if (reg->type != OP_IN)
814 {
815 need_curr_point_incr
816 |= mark_regno_live (reg->regno, reg->biggest_mode,
817 curr_point);
818 check_pseudos_live_through_calls (reg->regno);
819 }
820
821 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
822 if (reg->type != OP_IN)
823 make_hard_regno_born (reg->regno, false);
824
825 sparseset_copy (unused_set, start_living);
826
827 sparseset_clear (start_dying);
828
829 /* See which defined values die here. */
830 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
831 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
832 need_curr_point_incr
833 |= mark_regno_dead (reg->regno, reg->biggest_mode,
834 curr_point);
835
836 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
837 if (reg->type == OP_OUT && ! reg->early_clobber && ! reg->subreg_p)
838 make_hard_regno_dead (reg->regno);
839
840 if (call_p)
841 {
842 if (flag_ipa_ra)
843 {
844 HARD_REG_SET this_call_used_reg_set;
845 get_call_reg_set_usage (curr_insn, &this_call_used_reg_set,
846 call_used_reg_set);
847
848 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
849 IOR_HARD_REG_SET (lra_reg_info[j].actual_call_used_reg_set,
850 this_call_used_reg_set);
851 }
852
853 sparseset_ior (pseudos_live_through_calls,
854 pseudos_live_through_calls, pseudos_live);
855 if (cfun->has_nonlocal_label
856 || find_reg_note (curr_insn, REG_SETJMP,
857 NULL_RTX) != NULL_RTX)
858 sparseset_ior (pseudos_live_through_setjumps,
859 pseudos_live_through_setjumps, pseudos_live);
860 }
861
862 /* Increment the current program point if we must. */
863 if (need_curr_point_incr)
864 next_program_point (curr_point, freq);
865
866 sparseset_clear (start_living);
867
868 need_curr_point_incr = false;
869
870 /* Mark each used value as live. */
871 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
872 if (reg->type == OP_IN)
873 {
874 need_curr_point_incr
875 |= mark_regno_live (reg->regno, reg->biggest_mode,
876 curr_point);
877 check_pseudos_live_through_calls (reg->regno);
878 }
879
880 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
881 if (reg->type == OP_IN)
882 make_hard_regno_born (reg->regno, false);
883
884 if (curr_id->arg_hard_regs != NULL)
885 /* Make argument hard registers live. Don't create conflict
886 of used REAL_PIC_OFFSET_TABLE_REGNUM and the pic pseudo. */
887 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
888 make_hard_regno_born (regno, true);
889
890 sparseset_and_compl (dead_set, start_living, start_dying);
891
892 /* Mark early clobber outputs dead. */
893 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
894 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
895 need_curr_point_incr
896 |= mark_regno_dead (reg->regno, reg->biggest_mode,
897 curr_point);
898
899 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
900 if (reg->type == OP_OUT && reg->early_clobber && ! reg->subreg_p)
901 make_hard_regno_dead (reg->regno);
902
903 if (need_curr_point_incr)
904 next_program_point (curr_point, freq);
905
906 /* Update notes. */
907 for (link_loc = &REG_NOTES (curr_insn); (link = *link_loc) != NULL_RTX;)
908 {
909 if (REG_NOTE_KIND (link) != REG_DEAD
910 && REG_NOTE_KIND (link) != REG_UNUSED)
911 ;
912 else if (REG_P (XEXP (link, 0)))
913 {
914 regno = REGNO (XEXP (link, 0));
915 if ((REG_NOTE_KIND (link) == REG_DEAD
916 && ! sparseset_bit_p (dead_set, regno))
917 || (REG_NOTE_KIND (link) == REG_UNUSED
918 && ! sparseset_bit_p (unused_set, regno)))
919 {
920 *link_loc = XEXP (link, 1);
921 continue;
922 }
923 if (REG_NOTE_KIND (link) == REG_DEAD)
924 sparseset_clear_bit (dead_set, regno);
925 else if (REG_NOTE_KIND (link) == REG_UNUSED)
926 sparseset_clear_bit (unused_set, regno);
927 }
928 link_loc = &XEXP (link, 1);
929 }
930 EXECUTE_IF_SET_IN_SPARSESET (dead_set, j)
931 add_reg_note (curr_insn, REG_DEAD, regno_reg_rtx[j]);
932 EXECUTE_IF_SET_IN_SPARSESET (unused_set, j)
933 add_reg_note (curr_insn, REG_UNUSED, regno_reg_rtx[j]);
934 }
935
936 if (bb_has_eh_pred (bb))
937 for (j = 0; ; ++j)
938 {
939 unsigned int regno = EH_RETURN_DATA_REGNO (j);
940
941 if (regno == INVALID_REGNUM)
942 break;
943 make_hard_regno_born (regno, false);
944 }
945
946 /* Pseudos can't go in stack regs at the start of a basic block that
947 is reached by an abnormal edge. Likewise for call clobbered regs,
948 because caller-save, fixup_abnormal_edges and possibly the table
949 driven EH machinery are not quite ready to handle such pseudos
950 live across such edges. */
951 if (bb_has_abnormal_pred (bb))
952 {
953 #ifdef STACK_REGS
954 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, px)
955 lra_reg_info[px].no_stack_p = true;
956 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
957 make_hard_regno_born (px, false);
958 #endif
959 /* No need to record conflicts for call clobbered regs if we
960 have nonlocal labels around, as we don't ever try to
961 allocate such regs in this case. */
962 if (!cfun->has_nonlocal_label && bb_has_abnormal_call_pred (bb))
963 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
964 if (call_used_regs[px])
965 make_hard_regno_born (px, false);
966 }
967
968 bool live_change_p = false;
969 /* Check if bb border live info was changed. */
970 unsigned int live_pseudos_num = 0;
971 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb),
972 FIRST_PSEUDO_REGISTER, j, bi)
973 {
974 live_pseudos_num++;
975 if (! sparseset_bit_p (pseudos_live, j))
976 {
977 live_change_p = true;
978 if (lra_dump_file != NULL)
979 fprintf (lra_dump_file,
980 " r%d is removed as live at bb%d start\n", j, bb->index);
981 break;
982 }
983 }
984 if (! live_change_p
985 && sparseset_cardinality (pseudos_live) != live_pseudos_num)
986 {
987 live_change_p = true;
988 if (lra_dump_file != NULL)
989 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, j)
990 if (! bitmap_bit_p (df_get_live_in (bb), j))
991 fprintf (lra_dump_file,
992 " r%d is added to live at bb%d start\n", j, bb->index);
993 }
994 /* See if we'll need an increment at the end of this basic block.
995 An increment is needed if the PSEUDOS_LIVE set is not empty,
996 to make sure the finish points are set up correctly. */
997 need_curr_point_incr = (sparseset_cardinality (pseudos_live) > 0);
998
999 EXECUTE_IF_SET_IN_SPARSESET (pseudos_live, i)
1000 mark_pseudo_dead (i, curr_point);
1001
1002 EXECUTE_IF_SET_IN_BITMAP (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, j, bi)
1003 {
1004 if (sparseset_cardinality (pseudos_live_through_calls) == 0)
1005 break;
1006 if (sparseset_bit_p (pseudos_live_through_calls, j))
1007 check_pseudos_live_through_calls (j);
1008 }
1009
1010 if (need_curr_point_incr)
1011 next_program_point (curr_point, freq);
1012
1013 return live_change_p;
1014 }
1015
1016 /* Compress pseudo live ranges by removing program points where
1017 nothing happens. Complexity of many algorithms in LRA is linear
1018 function of program points number. To speed up the code we try to
1019 minimize the number of the program points here. */
1020 static void
1021 remove_some_program_points_and_update_live_ranges (void)
1022 {
1023 unsigned i;
1024 int n, max_regno;
1025 int *map;
1026 lra_live_range_t r, prev_r, next_r;
1027 sbitmap born_or_dead, born, dead;
1028 sbitmap_iterator sbi;
1029 bool born_p, dead_p, prev_born_p, prev_dead_p;
1030
1031 born = sbitmap_alloc (lra_live_max_point);
1032 dead = sbitmap_alloc (lra_live_max_point);
1033 bitmap_clear (born);
1034 bitmap_clear (dead);
1035 max_regno = max_reg_num ();
1036 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1037 {
1038 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1039 {
1040 lra_assert (r->start <= r->finish);
1041 bitmap_set_bit (born, r->start);
1042 bitmap_set_bit (dead, r->finish);
1043 }
1044 }
1045 born_or_dead = sbitmap_alloc (lra_live_max_point);
1046 bitmap_ior (born_or_dead, born, dead);
1047 map = XCNEWVEC (int, lra_live_max_point);
1048 n = -1;
1049 prev_born_p = prev_dead_p = false;
1050 EXECUTE_IF_SET_IN_BITMAP (born_or_dead, 0, i, sbi)
1051 {
1052 born_p = bitmap_bit_p (born, i);
1053 dead_p = bitmap_bit_p (dead, i);
1054 if ((prev_born_p && ! prev_dead_p && born_p && ! dead_p)
1055 || (prev_dead_p && ! prev_born_p && dead_p && ! born_p))
1056 {
1057 map[i] = n;
1058 lra_point_freq[n] = MAX (lra_point_freq[n], lra_point_freq[i]);
1059 }
1060 else
1061 {
1062 map[i] = ++n;
1063 lra_point_freq[n] = lra_point_freq[i];
1064 }
1065 prev_born_p = born_p;
1066 prev_dead_p = dead_p;
1067 }
1068 sbitmap_free (born_or_dead);
1069 sbitmap_free (born);
1070 sbitmap_free (dead);
1071 n++;
1072 if (lra_dump_file != NULL)
1073 fprintf (lra_dump_file, "Compressing live ranges: from %d to %d - %d%%\n",
1074 lra_live_max_point, n, 100 * n / lra_live_max_point);
1075 if (n < lra_live_max_point)
1076 {
1077 lra_live_max_point = n;
1078 for (i = FIRST_PSEUDO_REGISTER; i < (unsigned) max_regno; i++)
1079 {
1080 for (prev_r = NULL, r = lra_reg_info[i].live_ranges;
1081 r != NULL;
1082 r = next_r)
1083 {
1084 next_r = r->next;
1085 r->start = map[r->start];
1086 r->finish = map[r->finish];
1087 if (prev_r == NULL || prev_r->start > r->finish + 1)
1088 {
1089 prev_r = r;
1090 continue;
1091 }
1092 prev_r->start = r->start;
1093 prev_r->next = next_r;
1094 delete r;
1095 }
1096 }
1097 }
1098 free (map);
1099 }
1100
1101 /* Print live ranges R to file F. */
1102 void
1103 lra_print_live_range_list (FILE *f, lra_live_range_t r)
1104 {
1105 for (; r != NULL; r = r->next)
1106 fprintf (f, " [%d..%d]", r->start, r->finish);
1107 fprintf (f, "\n");
1108 }
1109
1110 DEBUG_FUNCTION void
1111 debug (lra_live_range &ref)
1112 {
1113 lra_print_live_range_list (stderr, &ref);
1114 }
1115
1116 DEBUG_FUNCTION void
1117 debug (lra_live_range *ptr)
1118 {
1119 if (ptr)
1120 debug (*ptr);
1121 else
1122 fprintf (stderr, "<nil>\n");
1123 }
1124
1125 /* Print live ranges R to stderr. */
1126 void
1127 lra_debug_live_range_list (lra_live_range_t r)
1128 {
1129 lra_print_live_range_list (stderr, r);
1130 }
1131
1132 /* Print live ranges of pseudo REGNO to file F. */
1133 static void
1134 print_pseudo_live_ranges (FILE *f, int regno)
1135 {
1136 if (lra_reg_info[regno].live_ranges == NULL)
1137 return;
1138 fprintf (f, " r%d:", regno);
1139 lra_print_live_range_list (f, lra_reg_info[regno].live_ranges);
1140 }
1141
1142 /* Print live ranges of pseudo REGNO to stderr. */
1143 void
1144 lra_debug_pseudo_live_ranges (int regno)
1145 {
1146 print_pseudo_live_ranges (stderr, regno);
1147 }
1148
1149 /* Print live ranges of all pseudos to file F. */
1150 static void
1151 print_live_ranges (FILE *f)
1152 {
1153 int i, max_regno;
1154
1155 max_regno = max_reg_num ();
1156 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1157 print_pseudo_live_ranges (f, i);
1158 }
1159
1160 /* Print live ranges of all pseudos to stderr. */
1161 void
1162 lra_debug_live_ranges (void)
1163 {
1164 print_live_ranges (stderr);
1165 }
1166
1167 /* Compress pseudo live ranges. */
1168 static void
1169 compress_live_ranges (void)
1170 {
1171 remove_some_program_points_and_update_live_ranges ();
1172 if (lra_dump_file != NULL)
1173 {
1174 fprintf (lra_dump_file, "Ranges after the compression:\n");
1175 print_live_ranges (lra_dump_file);
1176 }
1177 }
1178
1179 \f
1180
1181 /* The number of the current live range pass. */
1182 int lra_live_range_iter;
1183
1184 /* The function creates live ranges only for memory pseudos (or for
1185 all ones if ALL_P), set up CONFLICT_HARD_REGS for the pseudos. It
1186 also does dead insn elimination if DEAD_INSN_P and global live
1187 analysis only for pseudos and only if the pseudo live info was
1188 changed on a BB border. Return TRUE if the live info was
1189 changed. */
1190 static bool
1191 lra_create_live_ranges_1 (bool all_p, bool dead_insn_p)
1192 {
1193 basic_block bb;
1194 int i, hard_regno, max_regno = max_reg_num ();
1195 int curr_point;
1196 bool bb_live_change_p, have_referenced_pseudos = false;
1197
1198 timevar_push (TV_LRA_CREATE_LIVE_RANGES);
1199
1200 complete_info_p = all_p;
1201 if (lra_dump_file != NULL)
1202 fprintf (lra_dump_file,
1203 "\n********** Pseudo live ranges #%d: **********\n\n",
1204 ++lra_live_range_iter);
1205 memset (lra_hard_reg_usage, 0, sizeof (lra_hard_reg_usage));
1206 for (i = 0; i < max_regno; i++)
1207 {
1208 lra_reg_info[i].live_ranges = NULL;
1209 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
1210 lra_reg_info[i].preferred_hard_regno1 = -1;
1211 lra_reg_info[i].preferred_hard_regno2 = -1;
1212 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
1213 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
1214 #ifdef STACK_REGS
1215 lra_reg_info[i].no_stack_p = false;
1216 #endif
1217 /* The biggest mode is already set but its value might be to
1218 conservative because of recent transformation. Here in this
1219 file we recalculate it again as it costs practically
1220 nothing. */
1221 if (regno_reg_rtx[i] != NULL_RTX)
1222 lra_reg_info[i].biggest_mode = GET_MODE (regno_reg_rtx[i]);
1223 else
1224 lra_reg_info[i].biggest_mode = VOIDmode;
1225 #ifdef ENABLE_CHECKING
1226 lra_reg_info[i].call_p = false;
1227 #endif
1228 if (i >= FIRST_PSEUDO_REGISTER
1229 && lra_reg_info[i].nrefs != 0)
1230 {
1231 if ((hard_regno = reg_renumber[i]) >= 0)
1232 lra_hard_reg_usage[hard_regno] += lra_reg_info[i].freq;
1233 have_referenced_pseudos = true;
1234 }
1235 }
1236 lra_free_copies ();
1237
1238 /* Under some circumstances, we can have functions without pseudo
1239 registers. For such functions, lra_live_max_point will be 0,
1240 see e.g. PR55604, and there's nothing more to do for us here. */
1241 if (! have_referenced_pseudos)
1242 {
1243 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1244 return false;
1245 }
1246
1247 pseudos_live = sparseset_alloc (max_regno);
1248 pseudos_live_through_calls = sparseset_alloc (max_regno);
1249 pseudos_live_through_setjumps = sparseset_alloc (max_regno);
1250 start_living = sparseset_alloc (max_regno);
1251 start_dying = sparseset_alloc (max_regno);
1252 dead_set = sparseset_alloc (max_regno);
1253 unused_set = sparseset_alloc (max_regno);
1254 curr_point = 0;
1255 point_freq_vec.create (get_max_uid () * 2);
1256 lra_point_freq = point_freq_vec.address ();
1257 int *post_order_rev_cfg = XNEWVEC (int, last_basic_block_for_fn (cfun));
1258 int n_blocks_inverted = inverted_post_order_compute (post_order_rev_cfg);
1259 lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
1260 bb_live_change_p = false;
1261 for (i = n_blocks_inverted - 1; i >= 0; --i)
1262 {
1263 bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
1264 if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
1265 == ENTRY_BLOCK_PTR_FOR_FN (cfun))
1266 continue;
1267 if (process_bb_lives (bb, curr_point, dead_insn_p))
1268 bb_live_change_p = true;
1269 }
1270 if (bb_live_change_p)
1271 {
1272 /* We need to clear pseudo live info as some pseudos can
1273 disappear, e.g. pseudos with used equivalences. */
1274 FOR_EACH_BB_FN (bb, cfun)
1275 {
1276 bitmap_clear_range (df_get_live_in (bb), FIRST_PSEUDO_REGISTER,
1277 max_regno - FIRST_PSEUDO_REGISTER);
1278 bitmap_clear_range (df_get_live_out (bb), FIRST_PSEUDO_REGISTER,
1279 max_regno - FIRST_PSEUDO_REGISTER);
1280 }
1281 /* As we did not change CFG since LRA start we can use
1282 DF-infrastructure solver to solve live data flow problem. */
1283 df_simple_dataflow
1284 (DF_BACKWARD, NULL, live_con_fun_0, live_con_fun_n,
1285 live_trans_fun, &all_blocks,
1286 df_get_postorder (DF_BACKWARD), df_get_n_blocks (DF_BACKWARD));
1287 if (lra_dump_file != NULL)
1288 {
1289 fprintf (lra_dump_file,
1290 "Global pseudo live data have been updated:\n");
1291 basic_block bb;
1292 FOR_EACH_BB_FN (bb, cfun)
1293 {
1294 bb_data_t bb_info = get_bb_data (bb);
1295 bitmap bb_livein = df_get_live_in (bb);
1296 bitmap bb_liveout = df_get_live_out (bb);
1297
1298 fprintf (lra_dump_file, "\nBB %d:\n", bb->index);
1299 lra_dump_bitmap_with_title (" gen:",
1300 &bb_info->gen_pseudos, bb->index);
1301 lra_dump_bitmap_with_title (" killed:",
1302 &bb_info->killed_pseudos, bb->index);
1303 lra_dump_bitmap_with_title (" livein:", bb_livein, bb->index);
1304 lra_dump_bitmap_with_title (" liveout:", bb_liveout, bb->index);
1305 }
1306 }
1307 }
1308 free (post_order_rev_cfg);
1309 lra_live_max_point = curr_point;
1310 if (lra_dump_file != NULL)
1311 print_live_ranges (lra_dump_file);
1312 /* Clean up. */
1313 sparseset_free (unused_set);
1314 sparseset_free (dead_set);
1315 sparseset_free (start_dying);
1316 sparseset_free (start_living);
1317 sparseset_free (pseudos_live_through_calls);
1318 sparseset_free (pseudos_live_through_setjumps);
1319 sparseset_free (pseudos_live);
1320 compress_live_ranges ();
1321 timevar_pop (TV_LRA_CREATE_LIVE_RANGES);
1322 return bb_live_change_p;
1323 }
1324
1325 /* The main entry function creates live-ranges and other live info
1326 necessary for the assignment sub-pass. It uses
1327 lra_creates_live_ranges_1 -- so read comments for the
1328 function. */
1329 void
1330 lra_create_live_ranges (bool all_p, bool dead_insn_p)
1331 {
1332 if (! lra_create_live_ranges_1 (all_p, dead_insn_p))
1333 return;
1334 if (lra_dump_file != NULL)
1335 fprintf (lra_dump_file, "Live info was changed -- recalculate it\n");
1336 /* Live info was changed on a bb border. It means that some info,
1337 e.g. about conflict regs, calls crossed, and live ranges may be
1338 wrong. We need this info for allocation. So recalculate it
1339 again but without removing dead insns which can change live info
1340 again. Repetitive live range calculations are expensive therefore
1341 we stop here as we already have correct info although some
1342 improvement in rare cases could be possible on this sub-pass if
1343 we do dead insn elimination again (still the improvement may
1344 happen later). */
1345 lra_clear_live_ranges ();
1346 bool res = lra_create_live_ranges_1 (all_p, false);
1347 lra_assert (! res);
1348 }
1349
1350 /* Finish all live ranges. */
1351 void
1352 lra_clear_live_ranges (void)
1353 {
1354 int i;
1355
1356 for (i = 0; i < max_reg_num (); i++)
1357 free_live_range_list (lra_reg_info[i].live_ranges);
1358 point_freq_vec.release ();
1359 }
1360
1361 /* Initialize live ranges data once per function. */
1362 void
1363 lra_live_ranges_init (void)
1364 {
1365 bitmap_initialize (&temp_bitmap, &reg_obstack);
1366 initiate_live_solver ();
1367 }
1368
1369 /* Finish live ranges data once per function. */
1370 void
1371 lra_live_ranges_finish (void)
1372 {
1373 finish_live_solver ();
1374 bitmap_clear (&temp_bitmap);
1375 lra_live_range::pool.release ();
1376 }