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