1 /* LRA (local register allocator) driver and LRA utilities.
2 Copyright (C) 2010-2014 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5 This file is part of GCC.
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
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
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/>. */
22 /* The Local Register Allocator (LRA) is a replacement of former
23 reload pass. It is focused to simplify code solving the reload
24 pass tasks, to make the code maintenance easier, and to implement new
25 perspective optimizations.
27 The major LRA design solutions are:
28 o division small manageable, separated sub-tasks
29 o reflection of all transformations and decisions in RTL as more
31 o insn constraints as a primary source of the info (minimizing
32 number of target-depended macros/hooks)
34 In brief LRA works by iterative insn process with the final goal is
35 to satisfy all insn and address constraints:
36 o New reload insns (in brief reloads) and reload pseudos might be
38 o Some pseudos might be spilled to assign hard registers to
40 o Changing spilled pseudos to stack memory or their equivalences;
41 o Allocation stack memory changes the address displacement and
42 new iteration is needed.
44 Here is block diagram of LRA passes:
46 ------------------------
47 --------------- | Undo inheritance for | ---------------
48 | Memory-memory | | spilled pseudos, | | New (and old) |
49 | move coalesce |<---| splits for pseudos got |<-- | pseudos |
50 --------------- | the same hard regs, | | assignment |
51 Start | | and optional reloads | ---------------
52 | | ------------------------ ^
53 V | ---------------- |
54 ----------- V | Update virtual | |
55 | Remove |----> ------------>| register | |
56 | scratches | ^ | displacements | |
57 ----------- | ---------------- |
60 ---------------- No ------------ pseudos -------------------
61 | Spilled pseudo | change |Constraints:| or insns | Inheritance/split |
62 | to memory |<-------| RTL |--------->| transformations |
63 | substitution | | transfor- | | in EBB scope |
64 ---------------- | mations | -------------------
67 -------------------------
68 | Hard regs substitution, |
69 | devirtalization, and |------> Finish
70 | restoring scratches got |
72 -------------------------
74 To speed up the process:
75 o We process only insns affected by changes on previous
77 o We don't use DFA-infrastructure because it results in much slower
78 compiler speed than a special IR described below does;
79 o We use a special insn representation for quick access to insn
80 info which is always *synchronized* with the current RTL;
81 o Insn IR is minimized by memory. It is divided on three parts:
82 o one specific for each insn in RTL (only operand locations);
83 o one common for all insns in RTL with the same insn code
84 (different operand attributes from machine descriptions);
85 o one oriented for maintenance of live info (list of pseudos).
87 o all insns where the pseudo is referenced;
88 o live info (conflicting hard regs, live ranges, # of
90 o data used for assigning (preferred hard regs, costs etc).
92 This file contains LRA driver, LRA utility functions and data, and
93 code for dealing with scratches. */
97 #include "coretypes.h"
99 #include "hard-reg-set.h"
103 #include "insn-config.h"
104 #include "insn-codes.h"
107 #include "addresses.h"
109 #include "function.h"
111 #include "basic-block.h"
113 #include "tree-pass.h"
121 /* Hard registers currently not available for allocation. It can
122 changed after some hard registers become not eliminable. */
123 HARD_REG_SET lra_no_alloc_regs
;
125 static int get_new_reg_value (void);
126 static void expand_reg_info (void);
127 static void invalidate_insn_recog_data (int);
128 static int get_insn_freq (rtx_insn
*);
129 static void invalidate_insn_data_regno_info (lra_insn_recog_data_t
,
132 /* Expand all regno related info needed for LRA. */
134 expand_reg_data (int old
)
138 ira_expand_reg_equiv ();
139 for (int i
= (int) max_reg_num () - 1; i
>= old
; i
--)
140 lra_change_class (i
, ALL_REGS
, " Set", true);
143 /* Create and return a new reg of ORIGINAL mode. If ORIGINAL is NULL
144 or of VOIDmode, use MD_MODE for the new reg. Initialize its
145 register class to RCLASS. Print message about assigning class
146 RCLASS containing new register name TITLE unless it is NULL. Use
147 attributes of ORIGINAL if it is a register. The created register
148 will have unique held value. */
150 lra_create_new_reg_with_unique_value (enum machine_mode md_mode
, rtx original
,
151 enum reg_class rclass
, const char *title
)
153 enum machine_mode mode
;
156 if (original
== NULL_RTX
|| (mode
= GET_MODE (original
)) == VOIDmode
)
158 lra_assert (mode
!= VOIDmode
);
159 new_reg
= gen_reg_rtx (mode
);
160 if (original
== NULL_RTX
|| ! REG_P (original
))
162 if (lra_dump_file
!= NULL
)
163 fprintf (lra_dump_file
, " Creating newreg=%i", REGNO (new_reg
));
167 if (ORIGINAL_REGNO (original
) >= FIRST_PSEUDO_REGISTER
)
168 ORIGINAL_REGNO (new_reg
) = ORIGINAL_REGNO (original
);
169 REG_USERVAR_P (new_reg
) = REG_USERVAR_P (original
);
170 REG_POINTER (new_reg
) = REG_POINTER (original
);
171 REG_ATTRS (new_reg
) = REG_ATTRS (original
);
172 if (lra_dump_file
!= NULL
)
173 fprintf (lra_dump_file
, " Creating newreg=%i from oldreg=%i",
174 REGNO (new_reg
), REGNO (original
));
176 if (lra_dump_file
!= NULL
)
179 fprintf (lra_dump_file
, ", assigning class %s to%s%s r%d",
180 reg_class_names
[rclass
], *title
== '\0' ? "" : " ",
181 title
, REGNO (new_reg
));
182 fprintf (lra_dump_file
, "\n");
184 expand_reg_data (max_reg_num ());
185 setup_reg_classes (REGNO (new_reg
), rclass
, NO_REGS
, rclass
);
189 /* Analogous to the previous function but also inherits value of
192 lra_create_new_reg (enum machine_mode md_mode
, rtx original
,
193 enum reg_class rclass
, const char *title
)
198 = lra_create_new_reg_with_unique_value (md_mode
, original
, rclass
, title
);
199 if (original
!= NULL_RTX
&& REG_P (original
))
200 lra_assign_reg_val (REGNO (original
), REGNO (new_reg
));
204 /* Set up for REGNO unique hold value. */
206 lra_set_regno_unique_value (int regno
)
208 lra_reg_info
[regno
].val
= get_new_reg_value ();
211 /* Invalidate INSN related info used by LRA. The info should never be
214 lra_invalidate_insn_data (rtx_insn
*insn
)
216 lra_invalidate_insn_regno_info (insn
);
217 invalidate_insn_recog_data (INSN_UID (insn
));
220 /* Mark INSN deleted and invalidate the insn related info used by
223 lra_set_insn_deleted (rtx_insn
*insn
)
225 lra_invalidate_insn_data (insn
);
226 SET_INSN_DELETED (insn
);
229 /* Delete an unneeded INSN and any previous insns who sole purpose is
230 loading data that is dead in INSN. */
232 lra_delete_dead_insn (rtx_insn
*insn
)
234 rtx_insn
*prev
= prev_real_insn (insn
);
237 /* If the previous insn sets a register that dies in our insn,
239 if (prev
&& GET_CODE (PATTERN (prev
)) == SET
240 && (prev_dest
= SET_DEST (PATTERN (prev
)), REG_P (prev_dest
))
241 && reg_mentioned_p (prev_dest
, PATTERN (insn
))
242 && find_regno_note (insn
, REG_DEAD
, REGNO (prev_dest
))
243 && ! side_effects_p (SET_SRC (PATTERN (prev
))))
244 lra_delete_dead_insn (prev
);
246 lra_set_insn_deleted (insn
);
249 /* Emit insn x = y + z. Return NULL if we failed to do it.
250 Otherwise, return the insn. We don't use gen_add3_insn as it might
253 emit_add3_insn (rtx x
, rtx y
, rtx z
)
257 last
= get_last_insn ();
259 if (have_addptr3_insn (x
, y
, z
))
261 rtx insn
= gen_addptr3_insn (x
, y
, z
);
263 /* If the target provides an "addptr" pattern it hopefully does
264 for a reason. So falling back to the normal add would be
266 lra_assert (insn
!= NULL_RTX
);
271 rtx_insn
*insn
= emit_insn (gen_rtx_SET (VOIDmode
, x
,
272 gen_rtx_PLUS (GET_MODE (y
), y
, z
)));
273 if (recog_memoized (insn
) < 0)
275 delete_insns_since (last
);
281 /* Emit insn x = x + y. Return the insn. We use gen_add2_insn as the
284 emit_add2_insn (rtx x
, rtx y
)
288 insn
= emit_add3_insn (x
, x
, y
);
289 if (insn
== NULL_RTX
)
291 insn
= gen_add2_insn (x
, y
);
292 if (insn
!= NULL_RTX
)
298 /* Target checks operands through operand predicates to recognize an
299 insn. We should have a special precaution to generate add insns
300 which are frequent results of elimination.
302 Emit insns for x = y + z. X can be used to store intermediate
303 values and should be not in Y and Z when we use X to store an
304 intermediate value. Y + Z should form [base] [+ index[ * scale]] [
305 + disp] where base and index are registers, disp and scale are
306 constants. Y should contain base if it is present, Z should
307 contain disp if any. index[*scale] can be part of Y or Z. */
309 lra_emit_add (rtx x
, rtx y
, rtx z
)
313 rtx a1
, a2
, base
, index
, disp
, scale
, index_scale
;
316 rtx add3_insn
= emit_add3_insn (x
, y
, z
);
317 old
= max_reg_num ();
318 if (add3_insn
!= NULL
)
322 disp
= a2
= NULL_RTX
;
323 if (GET_CODE (y
) == PLUS
)
337 index_scale
= scale
= NULL_RTX
;
338 if (GET_CODE (a1
) == MULT
)
341 index
= XEXP (a1
, 0);
342 scale
= XEXP (a1
, 1);
345 else if (a2
!= NULL_RTX
&& GET_CODE (a2
) == MULT
)
348 index
= XEXP (a2
, 0);
349 scale
= XEXP (a2
, 1);
357 if (! (REG_P (base
) || GET_CODE (base
) == SUBREG
)
358 || (index
!= NULL_RTX
359 && ! (REG_P (index
) || GET_CODE (index
) == SUBREG
))
360 || (disp
!= NULL_RTX
&& ! CONSTANT_P (disp
))
361 || (scale
!= NULL_RTX
&& ! CONSTANT_P (scale
)))
363 /* Probably we have no 3 op add. Last chance is to use 2-op
364 add insn. To succeed, don't move Z to X as an address
365 segment always comes in Y. Otherwise, we might fail when
366 adding the address segment to register. */
367 lra_assert (x
!= y
&& x
!= z
);
368 emit_move_insn (x
, y
);
369 rtx insn
= emit_add2_insn (x
, z
);
370 lra_assert (insn
!= NULL_RTX
);
374 if (index_scale
== NULL_RTX
)
376 if (disp
== NULL_RTX
)
378 /* Generate x = index_scale; x = x + base. */
379 lra_assert (index_scale
!= NULL_RTX
&& base
!= NULL_RTX
);
380 emit_move_insn (x
, index_scale
);
381 rtx insn
= emit_add2_insn (x
, base
);
382 lra_assert (insn
!= NULL_RTX
);
384 else if (scale
== NULL_RTX
)
386 /* Try x = base + disp. */
387 lra_assert (base
!= NULL_RTX
);
388 last
= get_last_insn ();
389 rtx_insn
*move_insn
=
390 emit_move_insn (x
, gen_rtx_PLUS (GET_MODE (base
), base
, disp
));
391 if (recog_memoized (move_insn
) < 0)
393 delete_insns_since (last
);
394 /* Generate x = disp; x = x + base. */
395 emit_move_insn (x
, disp
);
396 rtx add2_insn
= emit_add2_insn (x
, base
);
397 lra_assert (add2_insn
!= NULL_RTX
);
399 /* Generate x = x + index. */
400 if (index
!= NULL_RTX
)
402 rtx insn
= emit_add2_insn (x
, index
);
403 lra_assert (insn
!= NULL_RTX
);
408 /* Try x = index_scale; x = x + disp; x = x + base. */
409 last
= get_last_insn ();
410 rtx_insn
*move_insn
= emit_move_insn (x
, index_scale
);
412 if (recog_memoized (move_insn
) >= 0)
414 rtx insn
= emit_add2_insn (x
, disp
);
415 if (insn
!= NULL_RTX
)
417 insn
= emit_add2_insn (x
, disp
);
418 if (insn
!= NULL_RTX
)
424 delete_insns_since (last
);
425 /* Generate x = disp; x = x + base; x = x + index_scale. */
426 emit_move_insn (x
, disp
);
427 rtx insn
= emit_add2_insn (x
, base
);
428 lra_assert (insn
!= NULL_RTX
);
429 insn
= emit_add2_insn (x
, index_scale
);
430 lra_assert (insn
!= NULL_RTX
);
435 /* Functions emit_... can create pseudos -- so expand the pseudo
437 if (old
!= max_reg_num ())
438 expand_reg_data (old
);
441 /* The number of emitted reload insns so far. */
442 int lra_curr_reload_num
;
444 /* Emit x := y, processing special case when y = u + v or y = u + v *
445 scale + w through emit_add (Y can be an address which is base +
446 index reg * scale + displacement in general case). X may be used
447 as intermediate result therefore it should be not in Y. */
449 lra_emit_move (rtx x
, rtx y
)
453 if (GET_CODE (y
) != PLUS
)
455 if (rtx_equal_p (x
, y
))
457 old
= max_reg_num ();
458 emit_move_insn (x
, y
);
460 lra_reg_info
[ORIGINAL_REGNO (x
)].last_reload
= ++lra_curr_reload_num
;
461 /* Function emit_move can create pseudos -- so expand the pseudo
463 if (old
!= max_reg_num ())
464 expand_reg_data (old
);
467 lra_emit_add (x
, XEXP (y
, 0), XEXP (y
, 1));
470 /* Update insn operands which are duplication of operands whose
471 numbers are in array of NOPS (with end marker -1). The insn is
472 represented by its LRA internal representation ID. */
474 lra_update_dups (lra_insn_recog_data_t id
, signed char *nops
)
477 struct lra_static_insn_data
*static_id
= id
->insn_static_data
;
479 for (i
= 0; i
< static_id
->n_dups
; i
++)
480 for (j
= 0; (nop
= nops
[j
]) >= 0; j
++)
481 if (static_id
->dup_num
[i
] == nop
)
482 *id
->dup_loc
[i
] = *id
->operand_loc
[nop
];
487 /* This page contains code dealing with info about registers in the
490 /* Pools for insn reg info. */
491 static alloc_pool insn_reg_pool
;
493 /* Initiate pool for insn reg info. */
495 init_insn_regs (void)
498 = create_alloc_pool ("insn regs", sizeof (struct lra_insn_reg
), 100);
501 /* Create LRA insn related info about a reference to REGNO in INSN with
502 TYPE (in/out/inout), biggest reference mode MODE, flag that it is
503 reference through subreg (SUBREG_P), flag that is early clobbered
504 in the insn (EARLY_CLOBBER), and reference to the next insn reg
506 static struct lra_insn_reg
*
507 new_insn_reg (rtx_insn
*insn
, int regno
, enum op_type type
,
508 enum machine_mode mode
,
509 bool subreg_p
, bool early_clobber
, struct lra_insn_reg
*next
)
511 struct lra_insn_reg
*ir
;
513 ir
= (struct lra_insn_reg
*) pool_alloc (insn_reg_pool
);
515 ir
->biggest_mode
= mode
;
516 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (lra_reg_info
[regno
].biggest_mode
)
517 && NONDEBUG_INSN_P (insn
))
518 lra_reg_info
[regno
].biggest_mode
= mode
;
519 ir
->subreg_p
= subreg_p
;
520 ir
->early_clobber
= early_clobber
;
526 /* Free insn reg info IR. */
528 free_insn_reg (struct lra_insn_reg
*ir
)
530 pool_free (insn_reg_pool
, ir
);
533 /* Free insn reg info list IR. */
535 free_insn_regs (struct lra_insn_reg
*ir
)
537 struct lra_insn_reg
*next_ir
;
539 for (; ir
!= NULL
; ir
= next_ir
)
546 /* Finish pool for insn reg info. */
548 finish_insn_regs (void)
550 free_alloc_pool (insn_reg_pool
);
555 /* This page contains code dealing LRA insn info (or in other words
556 LRA internal insn representation). */
558 /* Map INSN_CODE -> the static insn data. This info is valid during
559 all translation unit. */
560 struct lra_static_insn_data
*insn_code_data
[LAST_INSN_CODE
];
562 /* Debug insns are represented as a special insn with one input
563 operand which is RTL expression in var_location. */
565 /* The following data are used as static insn operand data for all
566 debug insns. If structure lra_operand_data is changed, the
567 initializer should be changed too. */
568 static struct lra_operand_data debug_operand_data
=
570 NULL
, /* alternative */
571 VOIDmode
, /* We are not interesting in the operand mode. */
576 /* The following data are used as static insn data for all debug
577 insns. If structure lra_static_insn_data is changed, the
578 initializer should be changed too. */
579 static struct lra_static_insn_data debug_insn_static_data
=
582 0, /* Duplication operands #. */
583 -1, /* Commutative operand #. */
584 1, /* Operands #. There is only one operand which is debug RTL
586 0, /* Duplications #. */
587 0, /* Alternatives #. We are not interesting in alternatives
588 because we does not proceed debug_insns for reloads. */
589 NULL
, /* Hard registers referenced in machine description. */
590 NULL
/* Descriptions of operands in alternatives. */
593 /* Called once per compiler work to initialize some LRA data related
596 init_insn_code_data_once (void)
598 memset (insn_code_data
, 0, sizeof (insn_code_data
));
601 /* Called once per compiler work to finalize some LRA data related to
604 finish_insn_code_data_once (void)
608 for (i
= 0; i
< LAST_INSN_CODE
; i
++)
610 if (insn_code_data
[i
] != NULL
)
611 free (insn_code_data
[i
]);
615 /* Return static insn data, allocate and setup if necessary. Although
616 dup_num is static data (it depends only on icode), to set it up we
617 need to extract insn first. So recog_data should be valid for
618 normal insn (ICODE >= 0) before the call. */
619 static struct lra_static_insn_data
*
620 get_static_insn_data (int icode
, int nop
, int ndup
, int nalt
)
622 struct lra_static_insn_data
*data
;
625 lra_assert (icode
< LAST_INSN_CODE
);
626 if (icode
>= 0 && (data
= insn_code_data
[icode
]) != NULL
)
628 lra_assert (nop
>= 0 && ndup
>= 0 && nalt
>= 0);
629 n_bytes
= sizeof (struct lra_static_insn_data
)
630 + sizeof (struct lra_operand_data
) * nop
631 + sizeof (int) * ndup
;
632 data
= XNEWVAR (struct lra_static_insn_data
, n_bytes
);
633 data
->operand_alternative
= NULL
;
634 data
->n_operands
= nop
;
636 data
->n_alternatives
= nalt
;
637 data
->operand
= ((struct lra_operand_data
*)
638 ((char *) data
+ sizeof (struct lra_static_insn_data
)));
639 data
->dup_num
= ((int *) ((char *) data
->operand
640 + sizeof (struct lra_operand_data
) * nop
));
645 insn_code_data
[icode
] = data
;
646 for (i
= 0; i
< nop
; i
++)
648 data
->operand
[i
].constraint
649 = insn_data
[icode
].operand
[i
].constraint
;
650 data
->operand
[i
].mode
= insn_data
[icode
].operand
[i
].mode
;
651 data
->operand
[i
].strict_low
= insn_data
[icode
].operand
[i
].strict_low
;
652 data
->operand
[i
].is_operator
653 = insn_data
[icode
].operand
[i
].is_operator
;
654 data
->operand
[i
].type
655 = (data
->operand
[i
].constraint
[0] == '=' ? OP_OUT
656 : data
->operand
[i
].constraint
[0] == '+' ? OP_INOUT
658 data
->operand
[i
].is_address
= false;
660 for (i
= 0; i
< ndup
; i
++)
661 data
->dup_num
[i
] = recog_data
.dup_num
[i
];
666 /* The current length of the following array. */
667 int lra_insn_recog_data_len
;
669 /* Map INSN_UID -> the insn recog data (NULL if unknown). */
670 lra_insn_recog_data_t
*lra_insn_recog_data
;
672 /* Initialize LRA data about insns. */
674 init_insn_recog_data (void)
676 lra_insn_recog_data_len
= 0;
677 lra_insn_recog_data
= NULL
;
681 /* Expand, if necessary, LRA data about insns. */
683 check_and_expand_insn_recog_data (int index
)
687 if (lra_insn_recog_data_len
> index
)
689 old
= lra_insn_recog_data_len
;
690 lra_insn_recog_data_len
= index
* 3 / 2 + 1;
691 lra_insn_recog_data
= XRESIZEVEC (lra_insn_recog_data_t
,
693 lra_insn_recog_data_len
);
694 for (i
= old
; i
< lra_insn_recog_data_len
; i
++)
695 lra_insn_recog_data
[i
] = NULL
;
698 /* Finish LRA DATA about insn. */
700 free_insn_recog_data (lra_insn_recog_data_t data
)
702 if (data
->operand_loc
!= NULL
)
703 free (data
->operand_loc
);
704 if (data
->dup_loc
!= NULL
)
705 free (data
->dup_loc
);
706 if (data
->arg_hard_regs
!= NULL
)
707 free (data
->arg_hard_regs
);
708 if (data
->icode
< 0 && NONDEBUG_INSN_P (data
->insn
))
710 if (data
->insn_static_data
->operand_alternative
!= NULL
)
711 free (const_cast <operand_alternative
*>
712 (data
->insn_static_data
->operand_alternative
));
713 free_insn_regs (data
->insn_static_data
->hard_regs
);
714 free (data
->insn_static_data
);
716 free_insn_regs (data
->regs
);
721 /* Finish LRA data about all insns. */
723 finish_insn_recog_data (void)
726 lra_insn_recog_data_t data
;
728 for (i
= 0; i
< lra_insn_recog_data_len
; i
++)
729 if ((data
= lra_insn_recog_data
[i
]) != NULL
)
730 free_insn_recog_data (data
);
732 free (lra_insn_recog_data
);
735 /* Setup info about operands in alternatives of LRA DATA of insn. */
737 setup_operand_alternative (lra_insn_recog_data_t data
,
738 const operand_alternative
*op_alt
)
741 int icode
= data
->icode
;
742 struct lra_static_insn_data
*static_data
= data
->insn_static_data
;
744 static_data
->commutative
= -1;
745 nop
= static_data
->n_operands
;
746 nalt
= static_data
->n_alternatives
;
747 static_data
->operand_alternative
= op_alt
;
748 for (i
= 0; i
< nop
; i
++)
750 static_data
->operand
[i
].early_clobber
= false;
751 static_data
->operand
[i
].is_address
= false;
752 if (static_data
->operand
[i
].constraint
[0] == '%')
754 /* We currently only support one commutative pair of operands. */
755 if (static_data
->commutative
< 0)
756 static_data
->commutative
= i
;
758 lra_assert (icode
< 0); /* Asm */
759 /* The last operand should not be marked commutative. */
760 lra_assert (i
!= nop
- 1);
763 for (j
= 0; j
< nalt
; j
++)
764 for (i
= 0; i
< nop
; i
++, op_alt
++)
766 static_data
->operand
[i
].early_clobber
|= op_alt
->earlyclobber
;
767 static_data
->operand
[i
].is_address
|= op_alt
->is_address
;
771 /* Recursively process X and collect info about registers, which are
772 not the insn operands, in X with TYPE (in/out/inout) and flag that
773 it is early clobbered in the insn (EARLY_CLOBBER) and add the info
774 to LIST. X is a part of insn given by DATA. Return the result
776 static struct lra_insn_reg
*
777 collect_non_operand_hard_regs (rtx
*x
, lra_insn_recog_data_t data
,
778 struct lra_insn_reg
*list
,
779 enum op_type type
, bool early_clobber
)
781 int i
, j
, regno
, last
;
783 enum machine_mode mode
;
784 struct lra_insn_reg
*curr
;
786 enum rtx_code code
= GET_CODE (op
);
787 const char *fmt
= GET_RTX_FORMAT (code
);
789 for (i
= 0; i
< data
->insn_static_data
->n_operands
; i
++)
790 if (x
== data
->operand_loc
[i
])
791 /* It is an operand loc. Stop here. */
793 for (i
= 0; i
< data
->insn_static_data
->n_dups
; i
++)
794 if (x
== data
->dup_loc
[i
])
795 /* It is a dup loc. Stop here. */
797 mode
= GET_MODE (op
);
801 op
= SUBREG_REG (op
);
802 code
= GET_CODE (op
);
803 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (GET_MODE (op
)))
805 mode
= GET_MODE (op
);
806 if (GET_MODE_SIZE (mode
) > REGMODE_NATURAL_SIZE (mode
))
812 if ((regno
= REGNO (op
)) >= FIRST_PSEUDO_REGISTER
)
814 for (last
= regno
+ hard_regno_nregs
[regno
][mode
];
817 if (! TEST_HARD_REG_BIT (lra_no_alloc_regs
, regno
)
818 || TEST_HARD_REG_BIT (eliminable_regset
, regno
))
820 for (curr
= list
; curr
!= NULL
; curr
= curr
->next
)
821 if (curr
->regno
== regno
&& curr
->subreg_p
== subreg_p
822 && curr
->biggest_mode
== mode
)
824 if (curr
->type
!= type
)
825 curr
->type
= OP_INOUT
;
826 if (curr
->early_clobber
!= early_clobber
)
827 curr
->early_clobber
= true;
832 /* This is a new hard regno or the info can not be
833 integrated into the found structure. */
837 /* This clobber is to inform popping floating
839 && ! (FIRST_STACK_REG
<= regno
840 && regno
<= LAST_STACK_REG
));
842 list
= new_insn_reg (data
->insn
, regno
, type
, mode
, subreg_p
,
843 early_clobber
, list
);
851 list
= collect_non_operand_hard_regs (&SET_DEST (op
), data
,
852 list
, OP_OUT
, false);
853 list
= collect_non_operand_hard_regs (&SET_SRC (op
), data
,
857 /* We treat clobber of non-operand hard registers as early
858 clobber (the behavior is expected from asm). */
859 list
= collect_non_operand_hard_regs (&XEXP (op
, 0), data
,
862 case PRE_INC
: case PRE_DEC
: case POST_INC
: case POST_DEC
:
863 list
= collect_non_operand_hard_regs (&XEXP (op
, 0), data
,
864 list
, OP_INOUT
, false);
866 case PRE_MODIFY
: case POST_MODIFY
:
867 list
= collect_non_operand_hard_regs (&XEXP (op
, 0), data
,
868 list
, OP_INOUT
, false);
869 list
= collect_non_operand_hard_regs (&XEXP (op
, 1), data
,
873 fmt
= GET_RTX_FORMAT (code
);
874 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
877 list
= collect_non_operand_hard_regs (&XEXP (op
, i
), data
,
879 else if (fmt
[i
] == 'E')
880 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
881 list
= collect_non_operand_hard_regs (&XVECEXP (op
, i
, j
), data
,
888 /* Set up and return info about INSN. Set up the info if it is not set up
890 lra_insn_recog_data_t
891 lra_set_insn_recog_data (rtx_insn
*insn
)
893 lra_insn_recog_data_t data
;
896 unsigned int uid
= INSN_UID (insn
);
897 struct lra_static_insn_data
*insn_static_data
;
899 check_and_expand_insn_recog_data (uid
);
900 if (DEBUG_INSN_P (insn
))
904 icode
= INSN_CODE (insn
);
906 /* It might be a new simple insn which is not recognized yet. */
907 INSN_CODE (insn
) = icode
= recog_memoized (insn
);
909 data
= XNEW (struct lra_insn_recog_data
);
910 lra_insn_recog_data
[uid
] = data
;
912 data
->used_insn_alternative
= -1;
915 if (DEBUG_INSN_P (insn
))
917 data
->insn_static_data
= &debug_insn_static_data
;
918 data
->dup_loc
= NULL
;
919 data
->arg_hard_regs
= NULL
;
920 data
->enabled_alternatives
= ALL_ALTERNATIVES
;
921 data
->operand_loc
= XNEWVEC (rtx
*, 1);
922 data
->operand_loc
[0] = &INSN_VAR_LOCATION_LOC (insn
);
928 enum machine_mode operand_mode
[MAX_RECOG_OPERANDS
];
929 const char *constraints
[MAX_RECOG_OPERANDS
];
931 nop
= asm_noperands (PATTERN (insn
));
932 data
->operand_loc
= data
->dup_loc
= NULL
;
936 /* Its is a special insn like USE or CLOBBER. We should
937 recognize any regular insn otherwise LRA can do nothing
939 gcc_assert (GET_CODE (PATTERN (insn
)) == USE
940 || GET_CODE (PATTERN (insn
)) == CLOBBER
941 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
);
942 data
->insn_static_data
= insn_static_data
943 = get_static_insn_data (-1, 0, 0, nalt
);
947 /* expand_asm_operands makes sure there aren't too many
949 lra_assert (nop
<= MAX_RECOG_OPERANDS
);
951 data
->operand_loc
= XNEWVEC (rtx
*, nop
);
952 /* Now get the operand values and constraints out of the
954 decode_asm_operands (PATTERN (insn
), NULL
,
956 constraints
, operand_mode
, NULL
);
959 const char *p
= recog_data
.constraints
[0];
961 for (p
= constraints
[0]; *p
; p
++)
964 data
->insn_static_data
= insn_static_data
965 = get_static_insn_data (-1, nop
, 0, nalt
);
966 for (i
= 0; i
< nop
; i
++)
968 insn_static_data
->operand
[i
].mode
= operand_mode
[i
];
969 insn_static_data
->operand
[i
].constraint
= constraints
[i
];
970 insn_static_data
->operand
[i
].strict_low
= false;
971 insn_static_data
->operand
[i
].is_operator
= false;
972 insn_static_data
->operand
[i
].is_address
= false;
975 for (i
= 0; i
< insn_static_data
->n_operands
; i
++)
976 insn_static_data
->operand
[i
].type
977 = (insn_static_data
->operand
[i
].constraint
[0] == '=' ? OP_OUT
978 : insn_static_data
->operand
[i
].constraint
[0] == '+' ? OP_INOUT
980 data
->enabled_alternatives
= ALL_ALTERNATIVES
;
983 operand_alternative
*op_alt
= XCNEWVEC (operand_alternative
,
985 preprocess_constraints (nop
, nalt
, constraints
, op_alt
);
986 setup_operand_alternative (data
, op_alt
);
992 data
->insn_static_data
= insn_static_data
993 = get_static_insn_data (icode
, insn_data
[icode
].n_operands
,
994 insn_data
[icode
].n_dups
,
995 insn_data
[icode
].n_alternatives
);
996 n
= insn_static_data
->n_operands
;
1001 locs
= XNEWVEC (rtx
*, n
);
1002 memcpy (locs
, recog_data
.operand_loc
, n
* sizeof (rtx
*));
1004 data
->operand_loc
= locs
;
1005 n
= insn_static_data
->n_dups
;
1010 locs
= XNEWVEC (rtx
*, n
);
1011 memcpy (locs
, recog_data
.dup_loc
, n
* sizeof (rtx
*));
1013 data
->dup_loc
= locs
;
1014 data
->enabled_alternatives
= get_enabled_alternatives (insn
);
1015 const operand_alternative
*op_alt
= preprocess_insn_constraints (icode
);
1016 if (!insn_static_data
->operand_alternative
)
1017 setup_operand_alternative (data
, op_alt
);
1018 else if (op_alt
!= insn_static_data
->operand_alternative
)
1019 insn_static_data
->operand_alternative
= op_alt
;
1021 if (GET_CODE (PATTERN (insn
)) == CLOBBER
|| GET_CODE (PATTERN (insn
)) == USE
)
1022 insn_static_data
->hard_regs
= NULL
;
1024 insn_static_data
->hard_regs
1025 = collect_non_operand_hard_regs (&PATTERN (insn
), data
,
1026 NULL
, OP_IN
, false);
1027 data
->arg_hard_regs
= NULL
;
1031 int n_hard_regs
, regno
, arg_hard_regs
[FIRST_PSEUDO_REGISTER
];
1034 /* Finding implicit hard register usage. We believe it will be
1035 not changed whatever transformations are used. Call insns
1036 are such example. */
1037 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1039 link
= XEXP (link
, 1))
1040 if (GET_CODE (XEXP (link
, 0)) == USE
1041 && REG_P (XEXP (XEXP (link
, 0), 0)))
1043 regno
= REGNO (XEXP (XEXP (link
, 0), 0));
1044 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
1045 /* It is an argument register. */
1046 for (i
= (hard_regno_nregs
1047 [regno
][GET_MODE (XEXP (XEXP (link
, 0), 0))]) - 1;
1050 arg_hard_regs
[n_hard_regs
++] = regno
+ i
;
1052 if (n_hard_regs
!= 0)
1054 arg_hard_regs
[n_hard_regs
++] = -1;
1055 data
->arg_hard_regs
= XNEWVEC (int, n_hard_regs
);
1056 memcpy (data
->arg_hard_regs
, arg_hard_regs
,
1057 sizeof (int) * n_hard_regs
);
1060 /* Some output operand can be recognized only from the context not
1061 from the constraints which are empty in this case. Call insn may
1062 contain a hard register in set destination with empty constraint
1063 and extract_insn treats them as an input. */
1064 for (i
= 0; i
< insn_static_data
->n_operands
; i
++)
1068 struct lra_operand_data
*operand
= &insn_static_data
->operand
[i
];
1070 /* ??? Should we treat 'X' the same way. It looks to me that
1071 'X' means anything and empty constraint means we do not
1073 if (operand
->type
!= OP_IN
|| *operand
->constraint
!= '\0'
1074 || operand
->is_operator
)
1076 pat
= PATTERN (insn
);
1077 if (GET_CODE (pat
) == SET
)
1079 if (data
->operand_loc
[i
] != &SET_DEST (pat
))
1082 else if (GET_CODE (pat
) == PARALLEL
)
1084 for (j
= XVECLEN (pat
, 0) - 1; j
>= 0; j
--)
1086 set
= XVECEXP (PATTERN (insn
), 0, j
);
1087 if (GET_CODE (set
) == SET
1088 && &SET_DEST (set
) == data
->operand_loc
[i
])
1096 operand
->type
= OP_OUT
;
1101 /* Return info about insn give by UID. The info should be already set
1103 static lra_insn_recog_data_t
1104 get_insn_recog_data_by_uid (int uid
)
1106 lra_insn_recog_data_t data
;
1108 data
= lra_insn_recog_data
[uid
];
1109 lra_assert (data
!= NULL
);
1113 /* Invalidate all info about insn given by its UID. */
1115 invalidate_insn_recog_data (int uid
)
1117 lra_insn_recog_data_t data
;
1119 data
= lra_insn_recog_data
[uid
];
1120 lra_assert (data
!= NULL
);
1121 free_insn_recog_data (data
);
1122 lra_insn_recog_data
[uid
] = NULL
;
1125 /* Update all the insn info about INSN. It is usually called when
1126 something in the insn was changed. Return the updated info. */
1127 lra_insn_recog_data_t
1128 lra_update_insn_recog_data (rtx_insn
*insn
)
1130 lra_insn_recog_data_t data
;
1132 unsigned int uid
= INSN_UID (insn
);
1133 struct lra_static_insn_data
*insn_static_data
;
1134 HOST_WIDE_INT sp_offset
= 0;
1136 check_and_expand_insn_recog_data (uid
);
1137 if ((data
= lra_insn_recog_data
[uid
]) != NULL
1138 && data
->icode
!= INSN_CODE (insn
))
1140 sp_offset
= data
->sp_offset
;
1141 invalidate_insn_data_regno_info (data
, insn
, get_insn_freq (insn
));
1142 invalidate_insn_recog_data (uid
);
1147 data
= lra_get_insn_recog_data (insn
);
1148 /* Initiate or restore SP offset. */
1149 data
->sp_offset
= sp_offset
;
1152 insn_static_data
= data
->insn_static_data
;
1153 data
->used_insn_alternative
= -1;
1154 if (DEBUG_INSN_P (insn
))
1156 if (data
->icode
< 0)
1159 enum machine_mode operand_mode
[MAX_RECOG_OPERANDS
];
1160 const char *constraints
[MAX_RECOG_OPERANDS
];
1162 nop
= asm_noperands (PATTERN (insn
));
1165 lra_assert (nop
== data
->insn_static_data
->n_operands
);
1166 /* Now get the operand values and constraints out of the
1168 decode_asm_operands (PATTERN (insn
), NULL
,
1170 constraints
, operand_mode
, NULL
);
1171 #ifdef ENABLE_CHECKING
1175 for (i
= 0; i
< nop
; i
++)
1177 (insn_static_data
->operand
[i
].mode
== operand_mode
[i
]
1178 && insn_static_data
->operand
[i
].constraint
== constraints
[i
]
1179 && ! insn_static_data
->operand
[i
].is_operator
);
1183 #ifdef ENABLE_CHECKING
1187 for (i
= 0; i
< insn_static_data
->n_operands
; i
++)
1189 (insn_static_data
->operand
[i
].type
1190 == (insn_static_data
->operand
[i
].constraint
[0] == '=' ? OP_OUT
1191 : insn_static_data
->operand
[i
].constraint
[0] == '+' ? OP_INOUT
1198 insn_extract (insn
);
1199 n
= insn_static_data
->n_operands
;
1201 memcpy (data
->operand_loc
, recog_data
.operand_loc
, n
* sizeof (rtx
*));
1202 n
= insn_static_data
->n_dups
;
1204 memcpy (data
->dup_loc
, recog_data
.dup_loc
, n
* sizeof (rtx
*));
1205 #if HAVE_ATTR_enabled
1206 #ifdef ENABLE_CHECKING
1209 alternative_mask enabled
;
1211 n
= insn_static_data
->n_alternatives
;
1212 enabled
= data
->enabled_alternatives
;
1213 lra_assert (n
>= 0);
1214 /* Cache the insn to prevent extract_insn call from
1215 get_attr_enabled. */
1216 recog_data
.insn
= insn
;
1217 for (i
= 0; i
< n
; i
++)
1219 which_alternative
= i
;
1220 lra_assert (TEST_BIT (enabled
, i
)
1221 == (bool) get_attr_enabled (insn
));
1230 /* Set up that INSN is using alternative ALT now. */
1232 lra_set_used_insn_alternative (rtx_insn
*insn
, int alt
)
1234 lra_insn_recog_data_t data
;
1236 data
= lra_get_insn_recog_data (insn
);
1237 data
->used_insn_alternative
= alt
;
1240 /* Set up that insn with UID is using alternative ALT now. The insn
1241 info should be already set up. */
1243 lra_set_used_insn_alternative_by_uid (int uid
, int alt
)
1245 lra_insn_recog_data_t data
;
1247 check_and_expand_insn_recog_data (uid
);
1248 data
= lra_insn_recog_data
[uid
];
1249 lra_assert (data
!= NULL
);
1250 data
->used_insn_alternative
= alt
;
1255 /* This page contains code dealing with common register info and
1258 /* The size of the following array. */
1259 static int reg_info_size
;
1260 /* Common info about each register. */
1261 struct lra_reg
*lra_reg_info
;
1263 /* Last register value. */
1264 static int last_reg_value
;
1266 /* Return new register value. */
1268 get_new_reg_value (void)
1270 return ++last_reg_value
;
1273 /* Pools for copies. */
1274 static alloc_pool copy_pool
;
1276 /* Vec referring to pseudo copies. */
1277 static vec
<lra_copy_t
> copy_vec
;
1279 /* Initialize I-th element of lra_reg_info. */
1281 initialize_lra_reg_info_element (int i
)
1283 bitmap_initialize (&lra_reg_info
[i
].insn_bitmap
, ®_obstack
);
1285 lra_reg_info
[i
].no_stack_p
= false;
1287 CLEAR_HARD_REG_SET (lra_reg_info
[i
].conflict_hard_regs
);
1288 CLEAR_HARD_REG_SET (lra_reg_info
[i
].actual_call_used_reg_set
);
1289 lra_reg_info
[i
].preferred_hard_regno1
= -1;
1290 lra_reg_info
[i
].preferred_hard_regno2
= -1;
1291 lra_reg_info
[i
].preferred_hard_regno_profit1
= 0;
1292 lra_reg_info
[i
].preferred_hard_regno_profit2
= 0;
1293 lra_reg_info
[i
].biggest_mode
= VOIDmode
;
1294 lra_reg_info
[i
].live_ranges
= NULL
;
1295 lra_reg_info
[i
].nrefs
= lra_reg_info
[i
].freq
= 0;
1296 lra_reg_info
[i
].last_reload
= 0;
1297 lra_reg_info
[i
].restore_regno
= -1;
1298 lra_reg_info
[i
].val
= get_new_reg_value ();
1299 lra_reg_info
[i
].offset
= 0;
1300 lra_reg_info
[i
].copies
= NULL
;
1303 /* Initialize common reg info and copies. */
1305 init_reg_info (void)
1310 reg_info_size
= max_reg_num () * 3 / 2 + 1;
1311 lra_reg_info
= XNEWVEC (struct lra_reg
, reg_info_size
);
1312 for (i
= 0; i
< reg_info_size
; i
++)
1313 initialize_lra_reg_info_element (i
);
1315 = create_alloc_pool ("lra copies", sizeof (struct lra_copy
), 100);
1316 copy_vec
.create (100);
1320 /* Finish common reg info and copies. */
1322 finish_reg_info (void)
1326 for (i
= 0; i
< reg_info_size
; i
++)
1327 bitmap_clear (&lra_reg_info
[i
].insn_bitmap
);
1328 free (lra_reg_info
);
1330 free_alloc_pool (copy_pool
);
1331 copy_vec
.release ();
1334 /* Expand common reg info if it is necessary. */
1336 expand_reg_info (void)
1338 int i
, old
= reg_info_size
;
1340 if (reg_info_size
> max_reg_num ())
1342 reg_info_size
= max_reg_num () * 3 / 2 + 1;
1343 lra_reg_info
= XRESIZEVEC (struct lra_reg
, lra_reg_info
, reg_info_size
);
1344 for (i
= old
; i
< reg_info_size
; i
++)
1345 initialize_lra_reg_info_element (i
);
1348 /* Free all copies. */
1350 lra_free_copies (void)
1354 while (copy_vec
.length () != 0)
1356 cp
= copy_vec
.pop ();
1357 lra_reg_info
[cp
->regno1
].copies
= lra_reg_info
[cp
->regno2
].copies
= NULL
;
1358 pool_free (copy_pool
, cp
);
1362 /* Create copy of two pseudos REGNO1 and REGNO2. The copy execution
1363 frequency is FREQ. */
1365 lra_create_copy (int regno1
, int regno2
, int freq
)
1370 lra_assert (regno1
!= regno2
);
1371 regno1_dest_p
= true;
1372 if (regno1
> regno2
)
1376 regno1_dest_p
= false;
1380 cp
= (lra_copy_t
) pool_alloc (copy_pool
);
1381 copy_vec
.safe_push (cp
);
1382 cp
->regno1_dest_p
= regno1_dest_p
;
1384 cp
->regno1
= regno1
;
1385 cp
->regno2
= regno2
;
1386 cp
->regno1_next
= lra_reg_info
[regno1
].copies
;
1387 lra_reg_info
[regno1
].copies
= cp
;
1388 cp
->regno2_next
= lra_reg_info
[regno2
].copies
;
1389 lra_reg_info
[regno2
].copies
= cp
;
1390 if (lra_dump_file
!= NULL
)
1391 fprintf (lra_dump_file
, " Creating copy r%d%sr%d@%d\n",
1392 regno1
, regno1_dest_p
? "<-" : "->", regno2
, freq
);
1395 /* Return N-th (0, 1, ...) copy. If there is no copy, return
1398 lra_get_copy (int n
)
1400 if (n
>= (int) copy_vec
.length ())
1407 /* This page contains code dealing with info about registers in
1410 /* Process X of insn UID recursively and add info (operand type is
1411 given by TYPE, flag of that it is early clobber is EARLY_CLOBBER)
1412 about registers in X to the insn DATA. */
1414 add_regs_to_insn_regno_info (lra_insn_recog_data_t data
, rtx x
, int uid
,
1415 enum op_type type
, bool early_clobber
)
1419 enum machine_mode mode
;
1422 struct lra_insn_reg
*curr
;
1424 code
= GET_CODE (x
);
1425 mode
= GET_MODE (x
);
1427 if (GET_CODE (x
) == SUBREG
)
1430 code
= GET_CODE (x
);
1431 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (GET_MODE (x
)))
1433 mode
= GET_MODE (x
);
1434 if (GET_MODE_SIZE (mode
) > REGMODE_NATURAL_SIZE (mode
))
1441 if (regno
< FIRST_PSEUDO_REGISTER
1442 && TEST_HARD_REG_BIT (lra_no_alloc_regs
, regno
)
1443 && ! TEST_HARD_REG_BIT (eliminable_regset
, regno
))
1446 if (bitmap_set_bit (&lra_reg_info
[regno
].insn_bitmap
, uid
))
1448 data
->regs
= new_insn_reg (data
->insn
, regno
, type
, mode
, subreg_p
,
1449 early_clobber
, data
->regs
);
1454 for (curr
= data
->regs
; curr
!= NULL
; curr
= curr
->next
)
1455 if (curr
->regno
== regno
)
1457 if (curr
->subreg_p
!= subreg_p
|| curr
->biggest_mode
!= mode
)
1458 /* The info can not be integrated into the found
1460 data
->regs
= new_insn_reg (data
->insn
, regno
, type
, mode
,
1461 subreg_p
, early_clobber
,
1465 if (curr
->type
!= type
)
1466 curr
->type
= OP_INOUT
;
1467 if (curr
->early_clobber
!= early_clobber
)
1468 curr
->early_clobber
= true;
1479 add_regs_to_insn_regno_info (data
, SET_DEST (x
), uid
, OP_OUT
, false);
1480 add_regs_to_insn_regno_info (data
, SET_SRC (x
), uid
, OP_IN
, false);
1483 /* We treat clobber of non-operand hard registers as early
1484 clobber (the behavior is expected from asm). */
1485 add_regs_to_insn_regno_info (data
, XEXP (x
, 0), uid
, OP_OUT
, true);
1487 case PRE_INC
: case PRE_DEC
: case POST_INC
: case POST_DEC
:
1488 add_regs_to_insn_regno_info (data
, XEXP (x
, 0), uid
, OP_INOUT
, false);
1490 case PRE_MODIFY
: case POST_MODIFY
:
1491 add_regs_to_insn_regno_info (data
, XEXP (x
, 0), uid
, OP_INOUT
, false);
1492 add_regs_to_insn_regno_info (data
, XEXP (x
, 1), uid
, OP_IN
, false);
1495 if ((code
!= PARALLEL
&& code
!= EXPR_LIST
) || type
!= OP_OUT
)
1496 /* Some targets place small structures in registers for return
1497 values of functions, and those registers are wrapped in
1498 PARALLEL that we may see as the destination of a SET. Here
1501 (call_insn 13 12 14 2 (set (parallel:BLK [
1502 (expr_list:REG_DEP_TRUE (reg:DI 0 ax)
1504 (expr_list:REG_DEP_TRUE (reg:DI 1 dx)
1505 (const_int 8 [0x8]))
1507 (call (mem:QI (symbol_ref:DI (... */
1509 fmt
= GET_RTX_FORMAT (code
);
1510 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1513 add_regs_to_insn_regno_info (data
, XEXP (x
, i
), uid
, type
, false);
1514 else if (fmt
[i
] == 'E')
1516 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1517 add_regs_to_insn_regno_info (data
, XVECEXP (x
, i
, j
), uid
,
1524 /* Return execution frequency of INSN. */
1526 get_insn_freq (rtx_insn
*insn
)
1528 basic_block bb
= BLOCK_FOR_INSN (insn
);
1530 gcc_checking_assert (bb
!= NULL
);
1531 return REG_FREQ_FROM_BB (bb
);
1534 /* Invalidate all reg info of INSN with DATA and execution frequency
1535 FREQ. Update common info about the invalidated registers. */
1537 invalidate_insn_data_regno_info (lra_insn_recog_data_t data
, rtx_insn
*insn
,
1543 struct lra_insn_reg
*ir
, *next_ir
;
1545 uid
= INSN_UID (insn
);
1546 debug_p
= DEBUG_INSN_P (insn
);
1547 for (ir
= data
->regs
; ir
!= NULL
; ir
= next_ir
)
1552 bitmap_clear_bit (&lra_reg_info
[i
].insn_bitmap
, uid
);
1553 if (i
>= FIRST_PSEUDO_REGISTER
&& ! debug_p
)
1555 lra_reg_info
[i
].nrefs
--;
1556 lra_reg_info
[i
].freq
-= freq
;
1557 lra_assert (lra_reg_info
[i
].nrefs
>= 0 && lra_reg_info
[i
].freq
>= 0);
1563 /* Invalidate all reg info of INSN. Update common info about the
1564 invalidated registers. */
1566 lra_invalidate_insn_regno_info (rtx_insn
*insn
)
1568 invalidate_insn_data_regno_info (lra_get_insn_recog_data (insn
), insn
,
1569 get_insn_freq (insn
));
1572 /* Update common reg info from reg info of insn given by its DATA and
1573 execution frequency FREQ. */
1575 setup_insn_reg_info (lra_insn_recog_data_t data
, int freq
)
1578 struct lra_insn_reg
*ir
;
1580 for (ir
= data
->regs
; ir
!= NULL
; ir
= ir
->next
)
1581 if ((i
= ir
->regno
) >= FIRST_PSEUDO_REGISTER
)
1583 lra_reg_info
[i
].nrefs
++;
1584 lra_reg_info
[i
].freq
+= freq
;
1588 /* Set up insn reg info of INSN. Update common reg info from reg info
1591 lra_update_insn_regno_info (rtx_insn
*insn
)
1594 lra_insn_recog_data_t data
;
1595 struct lra_static_insn_data
*static_data
;
1598 if (! INSN_P (insn
))
1600 data
= lra_get_insn_recog_data (insn
);
1601 static_data
= data
->insn_static_data
;
1602 freq
= get_insn_freq (insn
);
1603 invalidate_insn_data_regno_info (data
, insn
, freq
);
1604 uid
= INSN_UID (insn
);
1605 for (i
= static_data
->n_operands
- 1; i
>= 0; i
--)
1606 add_regs_to_insn_regno_info (data
, *data
->operand_loc
[i
], uid
,
1607 static_data
->operand
[i
].type
,
1608 static_data
->operand
[i
].early_clobber
);
1609 if ((code
= GET_CODE (PATTERN (insn
))) == CLOBBER
|| code
== USE
)
1610 add_regs_to_insn_regno_info (data
, XEXP (PATTERN (insn
), 0), uid
,
1611 code
== USE
? OP_IN
: OP_OUT
, false);
1612 if (NONDEBUG_INSN_P (insn
))
1613 setup_insn_reg_info (data
, freq
);
1616 /* Return reg info of insn given by it UID. */
1617 struct lra_insn_reg
*
1618 lra_get_insn_regs (int uid
)
1620 lra_insn_recog_data_t data
;
1622 data
= get_insn_recog_data_by_uid (uid
);
1628 /* This page contains code dealing with stack of the insns which
1629 should be processed by the next constraint pass. */
1631 /* Bitmap used to put an insn on the stack only in one exemplar. */
1632 static sbitmap lra_constraint_insn_stack_bitmap
;
1634 /* The stack itself. */
1635 vec
<rtx_insn
*> lra_constraint_insn_stack
;
1637 /* Put INSN on the stack. If ALWAYS_UPDATE is true, always update the reg
1638 info for INSN, otherwise only update it if INSN is not already on the
1641 lra_push_insn_1 (rtx_insn
*insn
, bool always_update
)
1643 unsigned int uid
= INSN_UID (insn
);
1645 lra_update_insn_regno_info (insn
);
1646 if (uid
>= SBITMAP_SIZE (lra_constraint_insn_stack_bitmap
))
1647 lra_constraint_insn_stack_bitmap
=
1648 sbitmap_resize (lra_constraint_insn_stack_bitmap
, 3 * uid
/ 2, 0);
1649 if (bitmap_bit_p (lra_constraint_insn_stack_bitmap
, uid
))
1651 bitmap_set_bit (lra_constraint_insn_stack_bitmap
, uid
);
1652 if (! always_update
)
1653 lra_update_insn_regno_info (insn
);
1654 lra_constraint_insn_stack
.safe_push (insn
);
1657 /* Put INSN on the stack. */
1659 lra_push_insn (rtx_insn
*insn
)
1661 lra_push_insn_1 (insn
, false);
1664 /* Put INSN on the stack and update its reg info. */
1666 lra_push_insn_and_update_insn_regno_info (rtx_insn
*insn
)
1668 lra_push_insn_1 (insn
, true);
1671 /* Put insn with UID on the stack. */
1673 lra_push_insn_by_uid (unsigned int uid
)
1675 lra_push_insn (lra_insn_recog_data
[uid
]->insn
);
1678 /* Take the last-inserted insns off the stack and return it. */
1682 rtx_insn
*insn
= lra_constraint_insn_stack
.pop ();
1683 bitmap_clear_bit (lra_constraint_insn_stack_bitmap
, INSN_UID (insn
));
1687 /* Return the current size of the insn stack. */
1689 lra_insn_stack_length (void)
1691 return lra_constraint_insn_stack
.length ();
1694 /* Push insns FROM to TO (excluding it) going in reverse order. */
1696 push_insns (rtx_insn
*from
, rtx_insn
*to
)
1700 if (from
== NULL_RTX
)
1702 for (insn
= from
; insn
!= to
; insn
= PREV_INSN (insn
))
1704 lra_push_insn (insn
);
1707 /* Set up sp offset for insn in range [FROM, LAST]. The offset is
1708 taken from the next BB insn after LAST or zero if there in such
1711 setup_sp_offset (rtx_insn
*from
, rtx_insn
*last
)
1713 rtx_insn
*before
= next_nonnote_insn_bb (last
);
1714 HOST_WIDE_INT offset
= (before
== NULL_RTX
|| ! INSN_P (before
)
1715 ? 0 : lra_get_insn_recog_data (before
)->sp_offset
);
1717 for (rtx_insn
*insn
= from
; insn
!= NEXT_INSN (last
); insn
= NEXT_INSN (insn
))
1718 lra_get_insn_recog_data (insn
)->sp_offset
= offset
;
1721 /* Emit insns BEFORE before INSN and insns AFTER after INSN. Put the
1722 insns onto the stack. Print about emitting the insns with
1725 lra_process_new_insns (rtx_insn
*insn
, rtx_insn
*before
, rtx_insn
*after
,
1730 if (before
== NULL_RTX
&& after
== NULL_RTX
)
1732 if (lra_dump_file
!= NULL
)
1734 dump_insn_slim (lra_dump_file
, insn
);
1735 if (before
!= NULL_RTX
)
1737 fprintf (lra_dump_file
," %s before:\n", title
);
1738 dump_rtl_slim (lra_dump_file
, before
, NULL
, -1, 0);
1740 if (after
!= NULL_RTX
)
1742 fprintf (lra_dump_file
, " %s after:\n", title
);
1743 dump_rtl_slim (lra_dump_file
, after
, NULL
, -1, 0);
1745 fprintf (lra_dump_file
, "\n");
1747 if (before
!= NULL_RTX
)
1749 emit_insn_before (before
, insn
);
1750 push_insns (PREV_INSN (insn
), PREV_INSN (before
));
1751 setup_sp_offset (before
, PREV_INSN (insn
));
1753 if (after
!= NULL_RTX
)
1755 for (last
= after
; NEXT_INSN (last
) != NULL_RTX
; last
= NEXT_INSN (last
))
1757 emit_insn_after (after
, insn
);
1758 push_insns (last
, insn
);
1759 setup_sp_offset (after
, last
);
1765 /* This page contains code dealing with scratches (changing them onto
1766 pseudos and restoring them from the pseudos).
1768 We change scratches into pseudos at the beginning of LRA to
1769 simplify dealing with them (conflicts, hard register assignments).
1771 If the pseudo denoting scratch was spilled it means that we do need
1772 a hard register for it. Such pseudos are transformed back to
1773 scratches at the end of LRA. */
1775 /* Description of location of a former scratch operand. */
1778 rtx_insn
*insn
; /* Insn where the scratch was. */
1779 int nop
; /* Number of the operand which was a scratch. */
1782 typedef struct sloc
*sloc_t
;
1784 /* Locations of the former scratches. */
1785 static vec
<sloc_t
> scratches
;
1787 /* Bitmap of scratch regnos. */
1788 static bitmap_head scratch_bitmap
;
1790 /* Bitmap of scratch operands. */
1791 static bitmap_head scratch_operand_bitmap
;
1793 /* Return true if pseudo REGNO is made of SCRATCH. */
1795 lra_former_scratch_p (int regno
)
1797 return bitmap_bit_p (&scratch_bitmap
, regno
);
1800 /* Return true if the operand NOP of INSN is a former scratch. */
1802 lra_former_scratch_operand_p (rtx_insn
*insn
, int nop
)
1804 return bitmap_bit_p (&scratch_operand_bitmap
,
1805 INSN_UID (insn
) * MAX_RECOG_OPERANDS
+ nop
) != 0;
1808 /* Change scratches onto pseudos and save their location. */
1810 remove_scratches (void)
1813 bool insn_changed_p
;
1818 lra_insn_recog_data_t id
;
1819 struct lra_static_insn_data
*static_id
;
1821 scratches
.create (get_max_uid ());
1822 bitmap_initialize (&scratch_bitmap
, ®_obstack
);
1823 bitmap_initialize (&scratch_operand_bitmap
, ®_obstack
);
1824 FOR_EACH_BB_FN (bb
, cfun
)
1825 FOR_BB_INSNS (bb
, insn
)
1828 id
= lra_get_insn_recog_data (insn
);
1829 static_id
= id
->insn_static_data
;
1830 insn_changed_p
= false;
1831 for (i
= 0; i
< static_id
->n_operands
; i
++)
1832 if (GET_CODE (*id
->operand_loc
[i
]) == SCRATCH
1833 && GET_MODE (*id
->operand_loc
[i
]) != VOIDmode
)
1835 insn_changed_p
= true;
1836 *id
->operand_loc
[i
] = reg
1837 = lra_create_new_reg (static_id
->operand
[i
].mode
,
1838 *id
->operand_loc
[i
], ALL_REGS
, NULL
);
1839 add_reg_note (insn
, REG_UNUSED
, reg
);
1840 lra_update_dup (id
, i
);
1841 loc
= XNEW (struct sloc
);
1844 scratches
.safe_push (loc
);
1845 bitmap_set_bit (&scratch_bitmap
, REGNO (*id
->operand_loc
[i
]));
1846 bitmap_set_bit (&scratch_operand_bitmap
,
1847 INSN_UID (insn
) * MAX_RECOG_OPERANDS
+ i
);
1848 if (lra_dump_file
!= NULL
)
1849 fprintf (lra_dump_file
,
1850 "Removing SCRATCH in insn #%u (nop %d)\n",
1851 INSN_UID (insn
), i
);
1854 /* Because we might use DF right after caller-saves sub-pass
1855 we need to keep DF info up to date. */
1856 df_insn_rescan (insn
);
1860 /* Changes pseudos created by function remove_scratches onto scratches. */
1862 restore_scratches (void)
1867 rtx_insn
*last
= NULL
;
1868 lra_insn_recog_data_t id
= NULL
;
1870 for (i
= 0; scratches
.iterate (i
, &loc
); i
++)
1872 if (last
!= loc
->insn
)
1875 id
= lra_get_insn_recog_data (last
);
1877 if (REG_P (*id
->operand_loc
[loc
->nop
])
1878 && ((regno
= REGNO (*id
->operand_loc
[loc
->nop
]))
1879 >= FIRST_PSEUDO_REGISTER
)
1880 && lra_get_regno_hard_regno (regno
) < 0)
1882 /* It should be only case when scratch register with chosen
1883 constraint 'X' did not get memory or hard register. */
1884 lra_assert (lra_former_scratch_p (regno
));
1885 *id
->operand_loc
[loc
->nop
]
1886 = gen_rtx_SCRATCH (GET_MODE (*id
->operand_loc
[loc
->nop
]));
1887 lra_update_dup (id
, loc
->nop
);
1888 if (lra_dump_file
!= NULL
)
1889 fprintf (lra_dump_file
, "Restoring SCRATCH in insn #%u(nop %d)\n",
1890 INSN_UID (loc
->insn
), loc
->nop
);
1893 for (i
= 0; scratches
.iterate (i
, &loc
); i
++)
1895 scratches
.release ();
1896 bitmap_clear (&scratch_bitmap
);
1897 bitmap_clear (&scratch_operand_bitmap
);
1902 #ifdef ENABLE_CHECKING
1904 /* Function checks RTL for correctness. If FINAL_P is true, it is
1905 done at the end of LRA and the check is more rigorous. */
1907 check_rtl (bool final_p
)
1912 lra_assert (! final_p
|| reload_completed
);
1913 FOR_EACH_BB_FN (bb
, cfun
)
1914 FOR_BB_INSNS (bb
, insn
)
1915 if (NONDEBUG_INSN_P (insn
)
1916 && GET_CODE (PATTERN (insn
)) != USE
1917 && GET_CODE (PATTERN (insn
)) != CLOBBER
1918 && GET_CODE (PATTERN (insn
)) != ASM_INPUT
)
1922 extract_insn (insn
);
1923 lra_assert (constrain_operands (1));
1926 /* LRA code is based on assumption that all addresses can be
1927 correctly decomposed. LRA can generate reloads for
1928 decomposable addresses. The decomposition code checks the
1929 correctness of the addresses. So we don't need to check
1930 the addresses here. Don't call insn_invalid_p here, it can
1931 change the code at this stage. */
1932 if (recog_memoized (insn
) < 0 && asm_noperands (PATTERN (insn
)) < 0)
1933 fatal_insn_not_found (insn
);
1936 #endif /* #ifdef ENABLE_CHECKING */
1938 /* Determine if the current function has an exception receiver block
1939 that reaches the exit block via non-exceptional edges */
1941 has_nonexceptional_receiver (void)
1945 basic_block
*tos
, *worklist
, bb
;
1947 /* If we're not optimizing, then just err on the safe side. */
1951 /* First determine which blocks can reach exit via normal paths. */
1952 tos
= worklist
= XNEWVEC (basic_block
, n_basic_blocks_for_fn (cfun
) + 1);
1954 FOR_EACH_BB_FN (bb
, cfun
)
1955 bb
->flags
&= ~BB_REACHABLE
;
1957 /* Place the exit block on our worklist. */
1958 EXIT_BLOCK_PTR_FOR_FN (cfun
)->flags
|= BB_REACHABLE
;
1959 *tos
++ = EXIT_BLOCK_PTR_FOR_FN (cfun
);
1961 /* Iterate: find everything reachable from what we've already seen. */
1962 while (tos
!= worklist
)
1966 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
1967 if (e
->flags
& EDGE_ABNORMAL
)
1974 basic_block src
= e
->src
;
1976 if (!(src
->flags
& BB_REACHABLE
))
1978 src
->flags
|= BB_REACHABLE
;
1984 /* No exceptional block reached exit unexceptionally. */
1990 /* Process recursively X of INSN and add REG_INC notes if necessary. */
1992 add_auto_inc_notes (rtx_insn
*insn
, rtx x
)
1994 enum rtx_code code
= GET_CODE (x
);
1998 if (code
== MEM
&& auto_inc_p (XEXP (x
, 0)))
2000 add_reg_note (insn
, REG_INC
, XEXP (XEXP (x
, 0), 0));
2004 /* Scan all X sub-expressions. */
2005 fmt
= GET_RTX_FORMAT (code
);
2006 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2009 add_auto_inc_notes (insn
, XEXP (x
, i
));
2010 else if (fmt
[i
] == 'E')
2011 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2012 add_auto_inc_notes (insn
, XVECEXP (x
, i
, j
));
2018 /* Remove all REG_DEAD and REG_UNUSED notes and regenerate REG_INC.
2019 We change pseudos by hard registers without notification of DF and
2020 that can make the notes obsolete. DF-infrastructure does not deal
2021 with REG_INC notes -- so we should regenerate them here. */
2023 update_inc_notes (void)
2029 FOR_EACH_BB_FN (bb
, cfun
)
2030 FOR_BB_INSNS (bb
, insn
)
2031 if (NONDEBUG_INSN_P (insn
))
2033 pnote
= ®_NOTES (insn
);
2036 if (REG_NOTE_KIND (*pnote
) == REG_DEAD
2037 || REG_NOTE_KIND (*pnote
) == REG_UNUSED
2038 || REG_NOTE_KIND (*pnote
) == REG_INC
)
2039 *pnote
= XEXP (*pnote
, 1);
2041 pnote
= &XEXP (*pnote
, 1);
2044 add_auto_inc_notes (insn
, PATTERN (insn
));
2049 /* Set to 1 while in lra. */
2050 int lra_in_progress
;
2052 /* Start of pseudo regnos before the LRA. */
2053 int lra_new_regno_start
;
2055 /* Start of reload pseudo regnos before the new spill pass. */
2056 int lra_constraint_new_regno_start
;
2058 /* Inheritance pseudo regnos before the new spill pass. */
2059 bitmap_head lra_inheritance_pseudos
;
2061 /* Split regnos before the new spill pass. */
2062 bitmap_head lra_split_regs
;
2064 /* Reload pseudo regnos before the new assignmnet pass which still can
2065 be spilled after the assinment pass as memory is also accepted in
2066 insns for the reload pseudos. */
2067 bitmap_head lra_optional_reload_pseudos
;
2069 /* Pseudo regnos used for subreg reloads before the new assignment
2070 pass. Such pseudos still can be spilled after the assinment
2072 bitmap_head lra_subreg_reload_pseudos
;
2074 /* First UID of insns generated before a new spill pass. */
2075 int lra_constraint_new_insn_uid_start
;
2077 /* File used for output of LRA debug information. */
2078 FILE *lra_dump_file
;
2080 /* True if we should try spill into registers of different classes
2081 instead of memory. */
2082 bool lra_reg_spill_p
;
2084 /* Set up value LRA_REG_SPILL_P. */
2086 setup_reg_spill_flag (void)
2090 if (targetm
.spill_class
!= NULL
)
2091 for (cl
= 0; cl
< (int) LIM_REG_CLASSES
; cl
++)
2092 for (mode
= 0; mode
< MAX_MACHINE_MODE
; mode
++)
2093 if (targetm
.spill_class ((enum reg_class
) cl
,
2094 (enum machine_mode
) mode
) != NO_REGS
)
2096 lra_reg_spill_p
= true;
2099 lra_reg_spill_p
= false;
2102 /* True if the current function is too big to use regular algorithms
2103 in LRA. In other words, we should use simpler and faster algorithms
2104 in LRA. It also means we should not worry about generation code
2105 for caller saves. The value is set up in IRA. */
2108 /* Major LRA entry function. F is a file should be used to dump LRA
2114 bool live_p
, scratch_p
, inserted_p
;
2118 timevar_push (TV_LRA
);
2120 /* Make sure that the last insn is a note. Some subsequent passes
2122 emit_note (NOTE_INSN_DELETED
);
2124 COPY_HARD_REG_SET (lra_no_alloc_regs
, ira_no_alloc_regs
);
2129 init_insn_recog_data ();
2131 #ifdef ENABLE_CHECKING
2132 /* Some quick check on RTL generated by previous passes. */
2136 lra_in_progress
= 1;
2138 /* The enable attributes can change their values as LRA starts
2139 although it is a bad practice. To prevent reuse of the outdated
2140 values, clear them. */
2143 lra_live_range_iter
= lra_coalesce_iter
= 0;
2144 lra_constraint_iter
= lra_constraint_iter_after_spill
= 0;
2145 lra_inheritance_iter
= lra_undo_inheritance_iter
= 0;
2147 setup_reg_spill_flag ();
2149 /* Function remove_scratches can creates new pseudos for clobbers --
2150 so set up lra_constraint_new_regno_start before its call to
2151 permit changing reg classes for pseudos created by this
2153 lra_constraint_new_regno_start
= lra_new_regno_start
= max_reg_num ();
2154 remove_scratches ();
2155 scratch_p
= lra_constraint_new_regno_start
!= max_reg_num ();
2157 /* A function that has a non-local label that can reach the exit
2158 block via non-exceptional paths must save all call-saved
2160 if (cfun
->has_nonlocal_label
&& has_nonexceptional_receiver ())
2161 crtl
->saves_all_registers
= 1;
2163 if (crtl
->saves_all_registers
)
2164 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2165 if (! call_used_regs
[i
] && ! fixed_regs
[i
] && ! LOCAL_REGNO (i
))
2166 df_set_regs_ever_live (i
, true);
2168 /* We don't DF from now and avoid its using because it is to
2169 expensive when a lot of RTL changes are made. */
2170 df_set_flags (DF_NO_INSN_RESCAN
);
2171 lra_constraint_insn_stack
.create (get_max_uid ());
2172 lra_constraint_insn_stack_bitmap
= sbitmap_alloc (get_max_uid ());
2173 bitmap_clear (lra_constraint_insn_stack_bitmap
);
2174 lra_live_ranges_init ();
2175 lra_constraints_init ();
2176 lra_curr_reload_num
= 0;
2177 push_insns (get_last_insn (), NULL
);
2178 /* It is needed for the 1st coalescing. */
2179 lra_constraint_new_insn_uid_start
= get_max_uid ();
2180 bitmap_initialize (&lra_inheritance_pseudos
, ®_obstack
);
2181 bitmap_initialize (&lra_split_regs
, ®_obstack
);
2182 bitmap_initialize (&lra_optional_reload_pseudos
, ®_obstack
);
2183 bitmap_initialize (&lra_subreg_reload_pseudos
, ®_obstack
);
2185 if (get_frame_size () != 0 && crtl
->stack_alignment_needed
)
2186 /* If we have a stack frame, we must align it now. The stack size
2187 may be a part of the offset computation for register
2189 assign_stack_local (BLKmode
, 0, crtl
->stack_alignment_needed
);
2195 /* We should try to assign hard registers to scratches even
2196 if there were no RTL transformations in
2198 if (! lra_constraints (lra_constraint_iter
== 0)
2199 && (lra_constraint_iter
> 1
2200 || (! scratch_p
&& ! caller_save_needed
)))
2202 /* Constraint transformations may result in that eliminable
2203 hard regs become uneliminable and pseudos which use them
2204 should be spilled. It is better to do it before pseudo
2207 For example, rs6000 can make
2208 RS6000_PIC_OFFSET_TABLE_REGNUM uneliminable if we started
2209 to use a constant pool. */
2210 lra_eliminate (false, false);
2211 /* Do inheritance only for regular algorithms. */
2214 if (flag_use_caller_save
)
2217 lra_clear_live_ranges ();
2218 /* As a side-effect of lra_create_live_ranges, we calculate
2219 actual_call_used_reg_set, which is needed during
2221 lra_create_live_ranges (true);
2226 lra_clear_live_ranges ();
2227 /* We need live ranges for lra_assign -- so build them. */
2228 lra_create_live_ranges (true);
2230 /* If we don't spill non-reload and non-inheritance pseudos,
2231 there is no sense to run memory-memory move coalescing.
2232 If inheritance pseudos were spilled, the memory-memory
2233 moves involving them will be removed by pass undoing
2239 bool spill_p
= !lra_assign ();
2241 if (lra_undo_inheritance ())
2247 lra_create_live_ranges (true);
2250 if (lra_coalesce ())
2254 lra_clear_live_ranges ();
2257 /* Don't clear optional reloads bitmap until all constraints are
2258 satisfied as we need to differ them from regular reloads. */
2259 bitmap_clear (&lra_optional_reload_pseudos
);
2260 bitmap_clear (&lra_subreg_reload_pseudos
);
2261 bitmap_clear (&lra_inheritance_pseudos
);
2262 bitmap_clear (&lra_split_regs
);
2263 if (! lra_need_for_spills_p ())
2267 /* We need full live info for spilling pseudos into
2268 registers instead of memory. */
2269 lra_create_live_ranges (lra_reg_spill_p
);
2273 /* Assignment of stack slots changes elimination offsets for
2274 some eliminations. So update the offsets here. */
2275 lra_eliminate (false, false);
2276 lra_constraint_new_regno_start
= max_reg_num ();
2277 lra_constraint_new_insn_uid_start
= get_max_uid ();
2278 lra_constraint_iter_after_spill
= 0;
2280 restore_scratches ();
2281 lra_eliminate (true, false);
2282 lra_final_code_change ();
2283 lra_in_progress
= 0;
2285 lra_clear_live_ranges ();
2286 lra_live_ranges_finish ();
2287 lra_constraints_finish ();
2289 sbitmap_free (lra_constraint_insn_stack_bitmap
);
2290 lra_constraint_insn_stack
.release ();
2291 finish_insn_recog_data ();
2292 regstat_free_n_sets_and_refs ();
2294 reload_completed
= 1;
2295 update_inc_notes ();
2297 inserted_p
= fixup_abnormal_edges ();
2299 /* We've possibly turned single trapping insn into multiple ones. */
2300 if (cfun
->can_throw_non_call_exceptions
)
2303 blocks
= sbitmap_alloc (last_basic_block_for_fn (cfun
));
2304 bitmap_ones (blocks
);
2305 find_many_sub_basic_blocks (blocks
);
2306 sbitmap_free (blocks
);
2310 commit_edge_insertions ();
2312 /* Replacing pseudos with their memory equivalents might have
2313 created shared rtx. Subsequent passes would get confused
2314 by this, so unshare everything here. */
2315 unshare_all_rtl_again (get_insns ());
2317 #ifdef ENABLE_CHECKING
2321 timevar_pop (TV_LRA
);
2324 /* Called once per compiler to initialize LRA data once. */
2326 lra_init_once (void)
2328 init_insn_code_data_once ();
2331 /* Called once per compiler to finish LRA data which are initialize
2334 lra_finish_once (void)
2336 finish_insn_code_data_once ();