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