1 /* LRA (local register allocator) driver and LRA utilities.
2 Copyright (C) 2010-2013 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:
47 --------------- | Undo inheritance | ---------------
48 | Memory-memory | | for spilled pseudos)| | New (and old) |
49 | move coalesce |<---| and splits (for |<-- | pseudos |
50 --------------- | pseudos got the | | assignment |
51 Start | | same hard regs) | ---------------
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
);
129 static void invalidate_insn_data_regno_info (lra_insn_recog_data_t
, rtx
, int);
131 /* Expand all regno related info needed for LRA. */
133 expand_reg_data (void)
137 ira_expand_reg_equiv ();
140 /* Create and return a new reg of ORIGINAL mode. If ORIGINAL is NULL
141 or of VOIDmode, use MD_MODE for the new reg. Initialize its
142 register class to RCLASS. Print message about assigning class
143 RCLASS containing new register name TITLE unless it is NULL. Use
144 attributes of ORIGINAL if it is a register. The created register
145 will have unique held value. */
147 lra_create_new_reg_with_unique_value (enum machine_mode md_mode
, rtx original
,
148 enum reg_class rclass
, const char *title
)
150 enum machine_mode mode
;
153 if (original
== NULL_RTX
|| (mode
= GET_MODE (original
)) == VOIDmode
)
155 lra_assert (mode
!= VOIDmode
);
156 new_reg
= gen_reg_rtx (mode
);
157 if (original
== NULL_RTX
|| ! REG_P (original
))
159 if (lra_dump_file
!= NULL
)
160 fprintf (lra_dump_file
, " Creating newreg=%i", REGNO (new_reg
));
164 if (ORIGINAL_REGNO (original
) >= FIRST_PSEUDO_REGISTER
)
165 ORIGINAL_REGNO (new_reg
) = ORIGINAL_REGNO (original
);
166 REG_USERVAR_P (new_reg
) = REG_USERVAR_P (original
);
167 REG_POINTER (new_reg
) = REG_POINTER (original
);
168 REG_ATTRS (new_reg
) = REG_ATTRS (original
);
169 if (lra_dump_file
!= NULL
)
170 fprintf (lra_dump_file
, " Creating newreg=%i from oldreg=%i",
171 REGNO (new_reg
), REGNO (original
));
173 if (lra_dump_file
!= NULL
)
176 fprintf (lra_dump_file
, ", assigning class %s to%s%s r%d",
177 reg_class_names
[rclass
], *title
== '\0' ? "" : " ",
178 title
, REGNO (new_reg
));
179 fprintf (lra_dump_file
, "\n");
182 setup_reg_classes (REGNO (new_reg
), rclass
, NO_REGS
, rclass
);
186 /* Analogous to the previous function but also inherits value of
189 lra_create_new_reg (enum machine_mode md_mode
, rtx original
,
190 enum reg_class rclass
, const char *title
)
195 = lra_create_new_reg_with_unique_value (md_mode
, original
, rclass
, title
);
196 if (original
!= NULL_RTX
&& REG_P (original
))
197 lra_assign_reg_val (REGNO (original
), REGNO (new_reg
));
201 /* Set up for REGNO unique hold value. */
203 lra_set_regno_unique_value (int regno
)
205 lra_reg_info
[regno
].val
= get_new_reg_value ();
208 /* Invalidate INSN related info used by LRA. */
210 lra_invalidate_insn_data (rtx insn
)
212 lra_invalidate_insn_regno_info (insn
);
213 invalidate_insn_recog_data (INSN_UID (insn
));
216 /* Mark INSN deleted and invalidate the insn related info used by
219 lra_set_insn_deleted (rtx insn
)
221 lra_invalidate_insn_data (insn
);
222 SET_INSN_DELETED (insn
);
225 /* Delete an unneeded INSN and any previous insns who sole purpose is
226 loading data that is dead in INSN. */
228 lra_delete_dead_insn (rtx insn
)
230 rtx prev
= prev_real_insn (insn
);
233 /* If the previous insn sets a register that dies in our insn,
235 if (prev
&& GET_CODE (PATTERN (prev
)) == SET
236 && (prev_dest
= SET_DEST (PATTERN (prev
)), REG_P (prev_dest
))
237 && reg_mentioned_p (prev_dest
, PATTERN (insn
))
238 && find_regno_note (insn
, REG_DEAD
, REGNO (prev_dest
))
239 && ! side_effects_p (SET_SRC (PATTERN (prev
))))
240 lra_delete_dead_insn (prev
);
242 lra_set_insn_deleted (insn
);
245 /* Emit insn x = y + z. Return NULL if we failed to do it.
246 Otherwise, return the insn. We don't use gen_add3_insn as it might
249 emit_add3_insn (rtx x
, rtx y
, rtx z
)
253 last
= get_last_insn ();
254 insn
= emit_insn (gen_rtx_SET (VOIDmode
, x
,
255 gen_rtx_PLUS (GET_MODE (y
), y
, z
)));
256 if (recog_memoized (insn
) < 0)
258 delete_insns_since (last
);
264 /* Emit insn x = x + y. Return the insn. We use gen_add2_insn as the
267 emit_add2_insn (rtx x
, rtx y
)
271 insn
= emit_add3_insn (x
, x
, y
);
272 if (insn
== NULL_RTX
)
274 insn
= gen_add2_insn (x
, y
);
275 if (insn
!= NULL_RTX
)
281 /* Target checks operands through operand predicates to recognize an
282 insn. We should have a special precaution to generate add insns
283 which are frequent results of elimination.
285 Emit insns for x = y + z. X can be used to store intermediate
286 values and should be not in Y and Z when we use X to store an
287 intermediate value. Y + Z should form [base] [+ index[ * scale]] [
288 + disp] where base and index are registers, disp and scale are
289 constants. Y should contain base if it is present, Z should
290 contain disp if any. index[*scale] can be part of Y or Z. */
292 lra_emit_add (rtx x
, rtx y
, rtx z
)
296 rtx a1
, a2
, base
, index
, disp
, scale
, index_scale
;
299 insn
= emit_add3_insn (x
, y
, z
);
300 old
= max_reg_num ();
301 if (insn
!= NULL_RTX
)
305 disp
= a2
= NULL_RTX
;
306 if (GET_CODE (y
) == PLUS
)
320 index_scale
= scale
= NULL_RTX
;
321 if (GET_CODE (a1
) == MULT
)
324 index
= XEXP (a1
, 0);
325 scale
= XEXP (a1
, 1);
328 else if (a2
!= NULL_RTX
&& GET_CODE (a2
) == MULT
)
331 index
= XEXP (a2
, 0);
332 scale
= XEXP (a2
, 1);
341 || (index
!= NULL_RTX
&& ! REG_P (index
))
342 || (disp
!= NULL_RTX
&& ! CONSTANT_P (disp
))
343 || (scale
!= NULL_RTX
&& ! CONSTANT_P (scale
)))
345 /* Probably we have no 3 op add. Last chance is to use 2-op
346 add insn. To succeed, don't move Z to X as an address
347 segment always comes in Y. Otherwise, we might fail when
348 adding the address segment to register. */
349 lra_assert (x
!= y
&& x
!= z
);
350 emit_move_insn (x
, y
);
351 insn
= emit_add2_insn (x
, z
);
352 lra_assert (insn
!= NULL_RTX
);
356 if (index_scale
== NULL_RTX
)
358 if (disp
== NULL_RTX
)
360 /* Generate x = index_scale; x = x + base. */
361 lra_assert (index_scale
!= NULL_RTX
&& base
!= NULL_RTX
);
362 emit_move_insn (x
, index_scale
);
363 insn
= emit_add2_insn (x
, base
);
364 lra_assert (insn
!= NULL_RTX
);
366 else if (scale
== NULL_RTX
)
368 /* Try x = base + disp. */
369 lra_assert (base
!= NULL_RTX
);
370 last
= get_last_insn ();
371 insn
= emit_move_insn (x
, gen_rtx_PLUS (GET_MODE (base
),
373 if (recog_memoized (insn
) < 0)
375 delete_insns_since (last
);
376 /* Generate x = disp; x = x + base. */
377 emit_move_insn (x
, disp
);
378 insn
= emit_add2_insn (x
, base
);
379 lra_assert (insn
!= NULL_RTX
);
381 /* Generate x = x + index. */
382 if (index
!= NULL_RTX
)
384 insn
= emit_add2_insn (x
, index
);
385 lra_assert (insn
!= NULL_RTX
);
390 /* Try x = index_scale; x = x + disp; x = x + base. */
391 last
= get_last_insn ();
392 insn
= emit_move_insn (x
, index_scale
);
394 if (recog_memoized (insn
) >= 0)
396 insn
= emit_add2_insn (x
, disp
);
397 if (insn
!= NULL_RTX
)
399 insn
= emit_add2_insn (x
, disp
);
400 if (insn
!= NULL_RTX
)
406 delete_insns_since (last
);
407 /* Generate x = disp; x = x + base; x = x + index_scale. */
408 emit_move_insn (x
, disp
);
409 insn
= emit_add2_insn (x
, base
);
410 lra_assert (insn
!= NULL_RTX
);
411 insn
= emit_add2_insn (x
, index_scale
);
412 lra_assert (insn
!= NULL_RTX
);
417 /* Functions emit_... can create pseudos -- so expand the pseudo
419 if (old
!= max_reg_num ())
423 /* The number of emitted reload insns so far. */
424 int lra_curr_reload_num
;
426 /* Emit x := y, processing special case when y = u + v or y = u + v *
427 scale + w through emit_add (Y can be an address which is base +
428 index reg * scale + displacement in general case). X may be used
429 as intermediate result therefore it should be not in Y. */
431 lra_emit_move (rtx x
, rtx y
)
435 if (GET_CODE (y
) != PLUS
)
437 if (rtx_equal_p (x
, y
))
439 old
= max_reg_num ();
440 emit_move_insn (x
, y
);
442 lra_reg_info
[ORIGINAL_REGNO (x
)].last_reload
= ++lra_curr_reload_num
;
443 /* Function emit_move can create pseudos -- so expand the pseudo
445 if (old
!= max_reg_num ())
449 lra_emit_add (x
, XEXP (y
, 0), XEXP (y
, 1));
452 /* Update insn operands which are duplication of operands whose
453 numbers are in array of NOPS (with end marker -1). The insn is
454 represented by its LRA internal representation ID. */
456 lra_update_dups (lra_insn_recog_data_t id
, signed char *nops
)
459 struct lra_static_insn_data
*static_id
= id
->insn_static_data
;
461 for (i
= 0; i
< static_id
->n_dups
; i
++)
462 for (j
= 0; (nop
= nops
[j
]) >= 0; j
++)
463 if (static_id
->dup_num
[i
] == nop
)
464 *id
->dup_loc
[i
] = *id
->operand_loc
[nop
];
469 /* This page contains code dealing with info about registers in the
472 /* Pools for insn reg info. */
473 static alloc_pool insn_reg_pool
;
475 /* Initiate pool for insn reg info. */
477 init_insn_regs (void)
480 = create_alloc_pool ("insn regs", sizeof (struct lra_insn_reg
), 100);
483 /* Create LRA insn related info about referenced REGNO with TYPE
484 (in/out/inout), biggest reference mode MODE, flag that it is
485 reference through subreg (SUBREG_P), flag that is early clobbered
486 in the insn (EARLY_CLOBBER), and reference to the next insn reg
488 static struct lra_insn_reg
*
489 new_insn_reg (int regno
, enum op_type type
, enum machine_mode mode
,
490 bool subreg_p
, bool early_clobber
, struct lra_insn_reg
*next
)
492 struct lra_insn_reg
*ir
;
494 ir
= (struct lra_insn_reg
*) pool_alloc (insn_reg_pool
);
496 ir
->biggest_mode
= mode
;
497 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (lra_reg_info
[regno
].biggest_mode
))
498 lra_reg_info
[regno
].biggest_mode
= mode
;
499 ir
->subreg_p
= subreg_p
;
500 ir
->early_clobber
= early_clobber
;
506 /* Free insn reg info IR. */
508 free_insn_reg (struct lra_insn_reg
*ir
)
510 pool_free (insn_reg_pool
, ir
);
513 /* Free insn reg info list IR. */
515 free_insn_regs (struct lra_insn_reg
*ir
)
517 struct lra_insn_reg
*next_ir
;
519 for (; ir
!= NULL
; ir
= next_ir
)
526 /* Finish pool for insn reg info. */
528 finish_insn_regs (void)
530 free_alloc_pool (insn_reg_pool
);
535 /* This page contains code dealing LRA insn info (or in other words
536 LRA internal insn representation). */
538 struct target_lra_int default_target_lra_int
;
539 #if SWITCHABLE_TARGET
540 struct target_lra_int
*this_target_lra_int
= &default_target_lra_int
;
543 /* Map INSN_CODE -> the static insn data. This info is valid during
544 all translation unit. */
545 struct lra_static_insn_data
*insn_code_data
[LAST_INSN_CODE
];
547 /* Debug insns are represented as a special insn with one input
548 operand which is RTL expression in var_location. */
550 /* The following data are used as static insn operand data for all
551 debug insns. If structure lra_operand_data is changed, the
552 initializer should be changed too. */
553 static struct lra_operand_data debug_operand_data
=
555 NULL
, /* alternative */
556 VOIDmode
, /* We are not interesting in the operand mode. */
561 /* The following data are used as static insn data for all debug
562 insns. If structure lra_static_insn_data is changed, the
563 initializer should be changed too. */
564 static struct lra_static_insn_data debug_insn_static_data
=
567 0, /* Duplication operands #. */
568 -1, /* Commutative operand #. */
569 1, /* Operands #. There is only one operand which is debug RTL
571 0, /* Duplications #. */
572 0, /* Alternatives #. We are not interesting in alternatives
573 because we does not proceed debug_insns for reloads. */
574 NULL
, /* Hard registers referenced in machine description. */
575 NULL
/* Descriptions of operands in alternatives. */
578 /* Called once per compiler work to initialize some LRA data related
581 init_insn_code_data_once (void)
583 memset (insn_code_data
, 0, sizeof (insn_code_data
));
584 memset (op_alt_data
, 0, sizeof (op_alt_data
));
587 /* Called once per compiler work to finalize some LRA data related to
590 finish_insn_code_data_once (void)
594 for (i
= 0; i
< LAST_INSN_CODE
; i
++)
596 if (insn_code_data
[i
] != NULL
)
597 free (insn_code_data
[i
]);
598 if (op_alt_data
[i
] != NULL
)
599 free (op_alt_data
[i
]);
603 /* Initialize LRA info about operands in insn alternatives. */
605 init_op_alt_data (void)
609 for (i
= 0; i
< LAST_INSN_CODE
; i
++)
610 if (op_alt_data
[i
] != NULL
)
612 free (op_alt_data
[i
]);
613 op_alt_data
[i
] = NULL
;
617 /* Return static insn data, allocate and setup if necessary. Although
618 dup_num is static data (it depends only on icode), to set it up we
619 need to extract insn first. So recog_data should be valid for
620 normal insn (ICODE >= 0) before the call. */
621 static struct lra_static_insn_data
*
622 get_static_insn_data (int icode
, int nop
, int ndup
, int nalt
)
624 struct lra_static_insn_data
*data
;
627 lra_assert (icode
< LAST_INSN_CODE
);
628 if (icode
>= 0 && (data
= insn_code_data
[icode
]) != NULL
)
630 lra_assert (nop
>= 0 && ndup
>= 0 && nalt
>= 0);
631 n_bytes
= sizeof (struct lra_static_insn_data
)
632 + sizeof (struct lra_operand_data
) * nop
633 + sizeof (int) * ndup
;
634 data
= XNEWVAR (struct lra_static_insn_data
, n_bytes
);
635 data
->n_operands
= nop
;
637 data
->n_alternatives
= nalt
;
638 data
->operand
= ((struct lra_operand_data
*)
639 ((char *) data
+ sizeof (struct lra_static_insn_data
)));
640 data
->dup_num
= ((int *) ((char *) data
->operand
641 + sizeof (struct lra_operand_data
) * nop
));
646 insn_code_data
[icode
] = data
;
647 for (i
= 0; i
< nop
; i
++)
649 data
->operand
[i
].constraint
650 = insn_data
[icode
].operand
[i
].constraint
;
651 data
->operand
[i
].mode
= insn_data
[icode
].operand
[i
].mode
;
652 data
->operand
[i
].strict_low
= insn_data
[icode
].operand
[i
].strict_low
;
653 data
->operand
[i
].is_operator
654 = insn_data
[icode
].operand
[i
].is_operator
;
655 data
->operand
[i
].type
656 = (data
->operand
[i
].constraint
[0] == '=' ? OP_OUT
657 : data
->operand
[i
].constraint
[0] == '+' ? OP_INOUT
659 data
->operand
[i
].is_address
= false;
661 for (i
= 0; i
< ndup
; i
++)
662 data
->dup_num
[i
] = recog_data
.dup_num
[i
];
667 /* The current length of the following array. */
668 int lra_insn_recog_data_len
;
670 /* Map INSN_UID -> the insn recog data (NULL if unknown). */
671 lra_insn_recog_data_t
*lra_insn_recog_data
;
673 /* Initialize LRA data about insns. */
675 init_insn_recog_data (void)
677 lra_insn_recog_data_len
= 0;
678 lra_insn_recog_data
= NULL
;
682 /* Expand, if necessary, LRA data about insns. */
684 check_and_expand_insn_recog_data (int index
)
688 if (lra_insn_recog_data_len
> index
)
690 old
= lra_insn_recog_data_len
;
691 lra_insn_recog_data_len
= index
* 3 / 2 + 1;
692 lra_insn_recog_data
= XRESIZEVEC (lra_insn_recog_data_t
,
694 lra_insn_recog_data_len
);
695 for (i
= old
; i
< lra_insn_recog_data_len
; i
++)
696 lra_insn_recog_data
[i
] = NULL
;
699 /* Finish LRA DATA about insn. */
701 free_insn_recog_data (lra_insn_recog_data_t data
)
703 if (data
->operand_loc
!= NULL
)
704 free (data
->operand_loc
);
705 if (data
->dup_loc
!= NULL
)
706 free (data
->dup_loc
);
707 if (data
->arg_hard_regs
!= NULL
)
708 free (data
->arg_hard_regs
);
709 if (HAVE_ATTR_enabled
&& data
->alternative_enabled_p
!= NULL
)
710 free (data
->alternative_enabled_p
);
711 if (data
->icode
< 0 && NONDEBUG_INSN_P (data
->insn
))
713 if (data
->insn_static_data
->operand_alternative
!= NULL
)
714 free (data
->insn_static_data
->operand_alternative
);
715 free_insn_regs (data
->insn_static_data
->hard_regs
);
716 free (data
->insn_static_data
);
718 free_insn_regs (data
->regs
);
723 /* Finish LRA data about all insns. */
725 finish_insn_recog_data (void)
728 lra_insn_recog_data_t data
;
730 for (i
= 0; i
< lra_insn_recog_data_len
; i
++)
731 if ((data
= lra_insn_recog_data
[i
]) != NULL
)
732 free_insn_recog_data (data
);
734 free (lra_insn_recog_data
);
737 /* Setup info about operands in alternatives of LRA DATA of insn. */
739 setup_operand_alternative (lra_insn_recog_data_t data
)
742 int icode
= data
->icode
;
743 struct lra_static_insn_data
*static_data
= data
->insn_static_data
;
746 && (static_data
->operand_alternative
= op_alt_data
[icode
]) != NULL
)
748 static_data
->commutative
= -1;
749 nop
= static_data
->n_operands
;
752 static_data
->operand_alternative
= NULL
;
755 nalt
= static_data
->n_alternatives
;
756 static_data
->operand_alternative
= XNEWVEC (struct operand_alternative
,
758 memset (static_data
->operand_alternative
, 0,
759 nalt
* nop
* sizeof (struct operand_alternative
));
761 op_alt_data
[icode
] = static_data
->operand_alternative
;
762 for (i
= 0; i
< nop
; i
++)
765 struct operand_alternative
*op_alt_start
, *op_alt
;
766 const char *p
= static_data
->operand
[i
].constraint
;
768 static_data
->operand
[i
].early_clobber
= 0;
769 op_alt_start
= &static_data
->operand_alternative
[i
];
771 for (j
= 0; j
< nalt
; j
++)
773 op_alt
= op_alt_start
+ j
* nop
;
774 op_alt
->cl
= NO_REGS
;
775 op_alt
->constraint
= p
;
776 op_alt
->matches
= -1;
777 op_alt
->matched
= -1;
779 if (*p
== '\0' || *p
== ',')
781 op_alt
->anything_ok
= 1;
791 while (c
!= ',' && c
!= '\0');
792 if (c
== ',' || c
== '\0')
800 case '=': case '+': case '*':
801 case 'E': case 'F': case 'G': case 'H':
802 case 's': case 'i': case 'n':
803 case 'I': case 'J': case 'K': case 'L':
804 case 'M': case 'N': case 'O': case 'P':
805 /* These don't say anything we care about. */
809 /* We currently only support one commutative pair of
811 if (static_data
->commutative
< 0)
812 static_data
->commutative
= i
;
814 lra_assert (data
->icode
< 0); /* Asm */
816 /* The last operand should not be marked
818 lra_assert (i
!= nop
- 1);
822 op_alt
->reject
+= LRA_LOSER_COST_FACTOR
;
825 op_alt
->reject
+= LRA_MAX_REJECT
;
828 op_alt
->earlyclobber
= 1;
829 static_data
->operand
[i
].early_clobber
= 1;
832 case '0': case '1': case '2': case '3': case '4':
833 case '5': case '6': case '7': case '8': case '9':
836 op_alt
->matches
= strtoul (p
, &end
, 10);
837 static_data
->operand_alternative
838 [j
* nop
+ op_alt
->matches
].matched
= i
;
843 case TARGET_MEM_CONSTRAINT
:
844 op_alt
->memory_ok
= 1;
847 op_alt
->decmem_ok
= 1;
850 op_alt
->incmem_ok
= 1;
853 op_alt
->nonoffmem_ok
= 1;
856 op_alt
->offmem_ok
= 1;
859 op_alt
->anything_ok
= 1;
863 static_data
->operand
[i
].is_address
= true;
864 op_alt
->is_address
= 1;
865 op_alt
->cl
= (reg_class_subunion
[(int) op_alt
->cl
]
866 [(int) base_reg_class (VOIDmode
,
874 reg_class_subunion
[(int) op_alt
->cl
][(int) GENERAL_REGS
];
878 if (EXTRA_MEMORY_CONSTRAINT (c
, p
))
880 op_alt
->memory_ok
= 1;
883 if (EXTRA_ADDRESS_CONSTRAINT (c
, p
))
885 static_data
->operand
[i
].is_address
= true;
886 op_alt
->is_address
= 1;
888 = (reg_class_subunion
890 [(int) base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
896 = (reg_class_subunion
899 REG_CLASS_FROM_CONSTRAINT ((unsigned char) c
, p
)]);
902 p
+= CONSTRAINT_LEN (c
, p
);
908 /* Recursively process X and collect info about registers, which are
909 not the insn operands, in X with TYPE (in/out/inout) and flag that
910 it is early clobbered in the insn (EARLY_CLOBBER) and add the info
911 to LIST. X is a part of insn given by DATA. Return the result
913 static struct lra_insn_reg
*
914 collect_non_operand_hard_regs (rtx
*x
, lra_insn_recog_data_t data
,
915 struct lra_insn_reg
*list
,
916 enum op_type type
, bool early_clobber
)
918 int i
, j
, regno
, last
;
920 enum machine_mode mode
;
921 struct lra_insn_reg
*curr
;
923 enum rtx_code code
= GET_CODE (op
);
924 const char *fmt
= GET_RTX_FORMAT (code
);
926 for (i
= 0; i
< data
->insn_static_data
->n_operands
; i
++)
927 if (x
== data
->operand_loc
[i
])
928 /* It is an operand loc. Stop here. */
930 for (i
= 0; i
< data
->insn_static_data
->n_dups
; i
++)
931 if (x
== data
->dup_loc
[i
])
932 /* It is a dup loc. Stop here. */
934 mode
= GET_MODE (op
);
938 op
= SUBREG_REG (op
);
939 code
= GET_CODE (op
);
940 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (GET_MODE (op
)))
942 mode
= GET_MODE (op
);
943 if (GET_MODE_SIZE (mode
) > REGMODE_NATURAL_SIZE (mode
))
949 if ((regno
= REGNO (op
)) >= FIRST_PSEUDO_REGISTER
)
951 for (last
= regno
+ hard_regno_nregs
[regno
][mode
];
954 if (! TEST_HARD_REG_BIT (lra_no_alloc_regs
, regno
)
955 || TEST_HARD_REG_BIT (eliminable_regset
, regno
))
957 for (curr
= list
; curr
!= NULL
; curr
= curr
->next
)
958 if (curr
->regno
== regno
&& curr
->subreg_p
== subreg_p
959 && curr
->biggest_mode
== mode
)
961 if (curr
->type
!= type
)
962 curr
->type
= OP_INOUT
;
963 if (curr
->early_clobber
!= early_clobber
)
964 curr
->early_clobber
= true;
969 /* This is a new hard regno or the info can not be
970 integrated into the found structure. */
974 /* This clobber is to inform popping floating
976 && ! (FIRST_STACK_REG
<= regno
977 && regno
<= LAST_STACK_REG
));
979 list
= new_insn_reg (regno
, type
, mode
, subreg_p
,
980 early_clobber
, list
);
988 list
= collect_non_operand_hard_regs (&SET_DEST (op
), data
,
989 list
, OP_OUT
, false);
990 list
= collect_non_operand_hard_regs (&SET_SRC (op
), data
,
994 /* We treat clobber of non-operand hard registers as early
995 clobber (the behavior is expected from asm). */
996 list
= collect_non_operand_hard_regs (&XEXP (op
, 0), data
,
999 case PRE_INC
: case PRE_DEC
: case POST_INC
: case POST_DEC
:
1000 list
= collect_non_operand_hard_regs (&XEXP (op
, 0), data
,
1001 list
, OP_INOUT
, false);
1003 case PRE_MODIFY
: case POST_MODIFY
:
1004 list
= collect_non_operand_hard_regs (&XEXP (op
, 0), data
,
1005 list
, OP_INOUT
, false);
1006 list
= collect_non_operand_hard_regs (&XEXP (op
, 1), data
,
1007 list
, OP_IN
, false);
1010 fmt
= GET_RTX_FORMAT (code
);
1011 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1014 list
= collect_non_operand_hard_regs (&XEXP (op
, i
), data
,
1015 list
, OP_IN
, false);
1016 else if (fmt
[i
] == 'E')
1017 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
1018 list
= collect_non_operand_hard_regs (&XVECEXP (op
, i
, j
), data
,
1019 list
, OP_IN
, false);
1025 /* Set up and return info about INSN. Set up the info if it is not set up
1027 lra_insn_recog_data_t
1028 lra_set_insn_recog_data (rtx insn
)
1030 lra_insn_recog_data_t data
;
1033 unsigned int uid
= INSN_UID (insn
);
1034 struct lra_static_insn_data
*insn_static_data
;
1036 check_and_expand_insn_recog_data (uid
);
1037 if (DEBUG_INSN_P (insn
))
1041 icode
= INSN_CODE (insn
);
1043 /* It might be a new simple insn which is not recognized yet. */
1044 INSN_CODE (insn
) = icode
= recog_memoized (insn
);
1046 data
= XNEW (struct lra_insn_recog_data
);
1047 lra_insn_recog_data
[uid
] = data
;
1049 data
->used_insn_alternative
= -1;
1050 data
->icode
= icode
;
1052 if (DEBUG_INSN_P (insn
))
1054 data
->insn_static_data
= &debug_insn_static_data
;
1055 data
->dup_loc
= NULL
;
1056 data
->arg_hard_regs
= NULL
;
1057 data
->alternative_enabled_p
= NULL
;
1058 data
->operand_loc
= XNEWVEC (rtx
*, 1);
1059 data
->operand_loc
[0] = &INSN_VAR_LOCATION_LOC (insn
);
1065 enum machine_mode operand_mode
[MAX_RECOG_OPERANDS
];
1066 const char *constraints
[MAX_RECOG_OPERANDS
];
1068 nop
= asm_noperands (PATTERN (insn
));
1069 data
->operand_loc
= data
->dup_loc
= NULL
;
1071 /* Its is a special insn like USE or CLOBBER. */
1072 data
->insn_static_data
= insn_static_data
1073 = get_static_insn_data (-1, 0, 0, 1);
1076 /* expand_asm_operands makes sure there aren't too many
1078 lra_assert (nop
<= MAX_RECOG_OPERANDS
);
1080 data
->operand_loc
= XNEWVEC (rtx
*, nop
);
1081 /* Now get the operand values and constraints out of the
1083 decode_asm_operands (PATTERN (insn
), NULL
,
1085 constraints
, operand_mode
, NULL
);
1089 const char *p
= recog_data
.constraints
[0];
1091 for (p
= constraints
[0]; *p
; p
++)
1094 data
->insn_static_data
= insn_static_data
1095 = get_static_insn_data (-1, nop
, 0, n
);
1096 for (i
= 0; i
< nop
; i
++)
1098 insn_static_data
->operand
[i
].mode
= operand_mode
[i
];
1099 insn_static_data
->operand
[i
].constraint
= constraints
[i
];
1100 insn_static_data
->operand
[i
].strict_low
= false;
1101 insn_static_data
->operand
[i
].is_operator
= false;
1102 insn_static_data
->operand
[i
].is_address
= false;
1105 for (i
= 0; i
< insn_static_data
->n_operands
; i
++)
1106 insn_static_data
->operand
[i
].type
1107 = (insn_static_data
->operand
[i
].constraint
[0] == '=' ? OP_OUT
1108 : insn_static_data
->operand
[i
].constraint
[0] == '+' ? OP_INOUT
1110 data
->alternative_enabled_p
= NULL
;
1114 insn_extract (insn
);
1115 data
->insn_static_data
= insn_static_data
1116 = get_static_insn_data (icode
, insn_data
[icode
].n_operands
,
1117 insn_data
[icode
].n_dups
,
1118 insn_data
[icode
].n_alternatives
);
1119 n
= insn_static_data
->n_operands
;
1124 locs
= XNEWVEC (rtx
*, n
);
1125 memcpy (locs
, recog_data
.operand_loc
, n
* sizeof (rtx
*));
1127 data
->operand_loc
= locs
;
1128 n
= insn_static_data
->n_dups
;
1133 locs
= XNEWVEC (rtx
*, n
);
1134 memcpy (locs
, recog_data
.dup_loc
, n
* sizeof (rtx
*));
1136 data
->dup_loc
= locs
;
1137 if (HAVE_ATTR_enabled
)
1141 n
= insn_static_data
->n_alternatives
;
1142 lra_assert (n
>= 0);
1143 data
->alternative_enabled_p
= bp
= XNEWVEC (bool, n
);
1144 /* Cache the insn because we don't want to call extract_insn
1145 from get_attr_enabled as extract_insn modifies
1146 which_alternative. The attribute enabled should not depend
1147 on insn operands, operand modes, operand types, and operand
1148 constraints. It should depend on the architecture. If it
1149 is not true, we should rewrite this file code to use
1150 extract_insn instead of less expensive insn_extract. */
1151 recog_data
.insn
= insn
;
1152 for (i
= 0; i
< n
; i
++)
1154 which_alternative
= i
;
1155 bp
[i
] = get_attr_enabled (insn
);
1159 if (GET_CODE (PATTERN (insn
)) == CLOBBER
|| GET_CODE (PATTERN (insn
)) == USE
)
1160 insn_static_data
->hard_regs
= NULL
;
1162 insn_static_data
->hard_regs
1163 = collect_non_operand_hard_regs (&PATTERN (insn
), data
,
1164 NULL
, OP_IN
, false);
1165 setup_operand_alternative (data
);
1166 data
->arg_hard_regs
= NULL
;
1170 int n_hard_regs
, regno
, arg_hard_regs
[FIRST_PSEUDO_REGISTER
];
1173 /* Finding implicit hard register usage. We believe it will be
1174 not changed whatever transformations are used. Call insns
1175 are such example. */
1176 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1178 link
= XEXP (link
, 1))
1179 if (GET_CODE (XEXP (link
, 0)) == USE
1180 && REG_P (XEXP (XEXP (link
, 0), 0)))
1182 regno
= REGNO (XEXP (XEXP (link
, 0), 0));
1183 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
1184 /* It is an argument register. */
1185 for (i
= (hard_regno_nregs
1186 [regno
][GET_MODE (XEXP (XEXP (link
, 0), 0))]) - 1;
1189 arg_hard_regs
[n_hard_regs
++] = regno
+ i
;
1191 if (n_hard_regs
!= 0)
1193 arg_hard_regs
[n_hard_regs
++] = -1;
1194 data
->arg_hard_regs
= XNEWVEC (int, n_hard_regs
);
1195 memcpy (data
->arg_hard_regs
, arg_hard_regs
,
1196 sizeof (int) * n_hard_regs
);
1199 /* Some output operand can be recognized only from the context not
1200 from the constraints which are empty in this case. Call insn may
1201 contain a hard register in set destination with empty constraint
1202 and extract_insn treats them as an input. */
1203 for (i
= 0; i
< insn_static_data
->n_operands
; i
++)
1207 struct lra_operand_data
*operand
= &insn_static_data
->operand
[i
];
1209 /* ??? Should we treat 'X' the same way. It looks to me that
1210 'X' means anything and empty constraint means we do not
1212 if (operand
->type
!= OP_IN
|| *operand
->constraint
!= '\0'
1213 || operand
->is_operator
)
1215 pat
= PATTERN (insn
);
1216 if (GET_CODE (pat
) == SET
)
1218 if (data
->operand_loc
[i
] != &SET_DEST (pat
))
1221 else if (GET_CODE (pat
) == PARALLEL
)
1223 for (j
= XVECLEN (pat
, 0) - 1; j
>= 0; j
--)
1225 set
= XVECEXP (PATTERN (insn
), 0, j
);
1226 if (GET_CODE (set
) == SET
1227 && &SET_DEST (set
) == data
->operand_loc
[i
])
1235 operand
->type
= OP_OUT
;
1240 /* Return info about insn give by UID. The info should be already set
1242 static lra_insn_recog_data_t
1243 get_insn_recog_data_by_uid (int uid
)
1245 lra_insn_recog_data_t data
;
1247 data
= lra_insn_recog_data
[uid
];
1248 lra_assert (data
!= NULL
);
1252 /* Invalidate all info about insn given by its UID. */
1254 invalidate_insn_recog_data (int uid
)
1256 lra_insn_recog_data_t data
;
1258 data
= lra_insn_recog_data
[uid
];
1259 lra_assert (data
!= NULL
);
1260 free_insn_recog_data (data
);
1261 lra_insn_recog_data
[uid
] = NULL
;
1264 /* Update all the insn info about INSN. It is usually called when
1265 something in the insn was changed. Return the updated info. */
1266 lra_insn_recog_data_t
1267 lra_update_insn_recog_data (rtx insn
)
1269 lra_insn_recog_data_t data
;
1271 unsigned int uid
= INSN_UID (insn
);
1272 struct lra_static_insn_data
*insn_static_data
;
1274 check_and_expand_insn_recog_data (uid
);
1275 if ((data
= lra_insn_recog_data
[uid
]) != NULL
1276 && data
->icode
!= INSN_CODE (insn
))
1278 invalidate_insn_data_regno_info (data
, insn
, get_insn_freq (insn
));
1279 invalidate_insn_recog_data (uid
);
1283 return lra_get_insn_recog_data (insn
);
1284 insn_static_data
= data
->insn_static_data
;
1285 data
->used_insn_alternative
= -1;
1286 if (DEBUG_INSN_P (insn
))
1288 if (data
->icode
< 0)
1291 enum machine_mode operand_mode
[MAX_RECOG_OPERANDS
];
1292 const char *constraints
[MAX_RECOG_OPERANDS
];
1294 nop
= asm_noperands (PATTERN (insn
));
1297 lra_assert (nop
== data
->insn_static_data
->n_operands
);
1298 /* Now get the operand values and constraints out of the
1300 decode_asm_operands (PATTERN (insn
), NULL
,
1302 constraints
, operand_mode
, NULL
);
1303 #ifdef ENABLE_CHECKING
1307 for (i
= 0; i
< nop
; i
++)
1309 (insn_static_data
->operand
[i
].mode
== operand_mode
[i
]
1310 && insn_static_data
->operand
[i
].constraint
== constraints
[i
]
1311 && ! insn_static_data
->operand
[i
].is_operator
);
1315 #ifdef ENABLE_CHECKING
1319 for (i
= 0; i
< insn_static_data
->n_operands
; i
++)
1321 (insn_static_data
->operand
[i
].type
1322 == (insn_static_data
->operand
[i
].constraint
[0] == '=' ? OP_OUT
1323 : insn_static_data
->operand
[i
].constraint
[0] == '+' ? OP_INOUT
1330 insn_extract (insn
);
1331 n
= insn_static_data
->n_operands
;
1333 memcpy (data
->operand_loc
, recog_data
.operand_loc
, n
* sizeof (rtx
*));
1334 n
= insn_static_data
->n_dups
;
1336 memcpy (data
->dup_loc
, recog_data
.dup_loc
, n
* sizeof (rtx
*));
1337 #if HAVE_ATTR_enabled
1338 #ifdef ENABLE_CHECKING
1343 n
= insn_static_data
->n_alternatives
;
1344 bp
= data
->alternative_enabled_p
;
1345 lra_assert (n
>= 0 && bp
!= NULL
);
1346 /* Cache the insn to prevent extract_insn call from
1347 get_attr_enabled. */
1348 recog_data
.insn
= insn
;
1349 for (i
= 0; i
< n
; i
++)
1351 which_alternative
= i
;
1352 lra_assert (bp
[i
] == get_attr_enabled (insn
));
1361 /* Set up that INSN is using alternative ALT now. */
1363 lra_set_used_insn_alternative (rtx insn
, int alt
)
1365 lra_insn_recog_data_t data
;
1367 data
= lra_get_insn_recog_data (insn
);
1368 data
->used_insn_alternative
= alt
;
1371 /* Set up that insn with UID is using alternative ALT now. The insn
1372 info should be already set up. */
1374 lra_set_used_insn_alternative_by_uid (int uid
, int alt
)
1376 lra_insn_recog_data_t data
;
1378 check_and_expand_insn_recog_data (uid
);
1379 data
= lra_insn_recog_data
[uid
];
1380 lra_assert (data
!= NULL
);
1381 data
->used_insn_alternative
= alt
;
1386 /* This page contains code dealing with common register info and
1389 /* The size of the following array. */
1390 static int reg_info_size
;
1391 /* Common info about each register. */
1392 struct lra_reg
*lra_reg_info
;
1394 /* Last register value. */
1395 static int last_reg_value
;
1397 /* Return new register value. */
1399 get_new_reg_value (void)
1401 return ++last_reg_value
;
1404 /* Pools for copies. */
1405 static alloc_pool copy_pool
;
1407 /* Vec referring to pseudo copies. */
1408 static vec
<lra_copy_t
> copy_vec
;
1410 /* Initialize I-th element of lra_reg_info. */
1412 initialize_lra_reg_info_element (int i
)
1414 bitmap_initialize (&lra_reg_info
[i
].insn_bitmap
, ®_obstack
);
1416 lra_reg_info
[i
].no_stack_p
= false;
1418 CLEAR_HARD_REG_SET (lra_reg_info
[i
].conflict_hard_regs
);
1419 lra_reg_info
[i
].preferred_hard_regno1
= -1;
1420 lra_reg_info
[i
].preferred_hard_regno2
= -1;
1421 lra_reg_info
[i
].preferred_hard_regno_profit1
= 0;
1422 lra_reg_info
[i
].preferred_hard_regno_profit2
= 0;
1423 lra_reg_info
[i
].biggest_mode
= VOIDmode
;
1424 lra_reg_info
[i
].live_ranges
= NULL
;
1425 lra_reg_info
[i
].nrefs
= lra_reg_info
[i
].freq
= 0;
1426 lra_reg_info
[i
].last_reload
= 0;
1427 lra_reg_info
[i
].restore_regno
= -1;
1428 lra_reg_info
[i
].val
= get_new_reg_value ();
1429 lra_reg_info
[i
].offset
= 0;
1430 lra_reg_info
[i
].copies
= NULL
;
1433 /* Initialize common reg info and copies. */
1435 init_reg_info (void)
1440 reg_info_size
= max_reg_num () * 3 / 2 + 1;
1441 lra_reg_info
= XNEWVEC (struct lra_reg
, reg_info_size
);
1442 for (i
= 0; i
< reg_info_size
; i
++)
1443 initialize_lra_reg_info_element (i
);
1445 = create_alloc_pool ("lra copies", sizeof (struct lra_copy
), 100);
1446 copy_vec
.create (100);
1450 /* Finish common reg info and copies. */
1452 finish_reg_info (void)
1456 for (i
= 0; i
< reg_info_size
; i
++)
1457 bitmap_clear (&lra_reg_info
[i
].insn_bitmap
);
1458 free (lra_reg_info
);
1460 free_alloc_pool (copy_pool
);
1461 copy_vec
.release ();
1464 /* Expand common reg info if it is necessary. */
1466 expand_reg_info (void)
1468 int i
, old
= reg_info_size
;
1470 if (reg_info_size
> max_reg_num ())
1472 reg_info_size
= max_reg_num () * 3 / 2 + 1;
1473 lra_reg_info
= XRESIZEVEC (struct lra_reg
, lra_reg_info
, reg_info_size
);
1474 for (i
= old
; i
< reg_info_size
; i
++)
1475 initialize_lra_reg_info_element (i
);
1478 /* Free all copies. */
1480 lra_free_copies (void)
1484 while (copy_vec
.length () != 0)
1486 cp
= copy_vec
.pop ();
1487 lra_reg_info
[cp
->regno1
].copies
= lra_reg_info
[cp
->regno2
].copies
= NULL
;
1488 pool_free (copy_pool
, cp
);
1492 /* Create copy of two pseudos REGNO1 and REGNO2. The copy execution
1493 frequency is FREQ. */
1495 lra_create_copy (int regno1
, int regno2
, int freq
)
1500 lra_assert (regno1
!= regno2
);
1501 regno1_dest_p
= true;
1502 if (regno1
> regno2
)
1506 regno1_dest_p
= false;
1510 cp
= (lra_copy_t
) pool_alloc (copy_pool
);
1511 copy_vec
.safe_push (cp
);
1512 cp
->regno1_dest_p
= regno1_dest_p
;
1514 cp
->regno1
= regno1
;
1515 cp
->regno2
= regno2
;
1516 cp
->regno1_next
= lra_reg_info
[regno1
].copies
;
1517 lra_reg_info
[regno1
].copies
= cp
;
1518 cp
->regno2_next
= lra_reg_info
[regno2
].copies
;
1519 lra_reg_info
[regno2
].copies
= cp
;
1520 if (lra_dump_file
!= NULL
)
1521 fprintf (lra_dump_file
, " Creating copy r%d%sr%d@%d\n",
1522 regno1
, regno1_dest_p
? "<-" : "->", regno2
, freq
);
1525 /* Return N-th (0, 1, ...) copy. If there is no copy, return
1528 lra_get_copy (int n
)
1530 if (n
>= (int) copy_vec
.length ())
1537 /* This page contains code dealing with info about registers in
1540 /* Process X of insn UID recursively and add info (operand type is
1541 given by TYPE, flag of that it is early clobber is EARLY_CLOBBER)
1542 about registers in X to the insn DATA. */
1544 add_regs_to_insn_regno_info (lra_insn_recog_data_t data
, rtx x
, int uid
,
1545 enum op_type type
, bool early_clobber
)
1549 enum machine_mode mode
;
1552 struct lra_insn_reg
*curr
;
1554 code
= GET_CODE (x
);
1555 mode
= GET_MODE (x
);
1557 if (GET_CODE (x
) == SUBREG
)
1560 code
= GET_CODE (x
);
1561 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (GET_MODE (x
)))
1563 mode
= GET_MODE (x
);
1564 if (GET_MODE_SIZE (mode
) > REGMODE_NATURAL_SIZE (mode
))
1571 if (regno
< FIRST_PSEUDO_REGISTER
1572 && TEST_HARD_REG_BIT (lra_no_alloc_regs
, regno
)
1573 && ! TEST_HARD_REG_BIT (eliminable_regset
, regno
))
1576 if (bitmap_set_bit (&lra_reg_info
[regno
].insn_bitmap
, uid
))
1578 data
->regs
= new_insn_reg (regno
, type
, mode
, subreg_p
,
1579 early_clobber
, data
->regs
);
1584 for (curr
= data
->regs
; curr
!= NULL
; curr
= curr
->next
)
1585 if (curr
->regno
== regno
)
1587 if (curr
->subreg_p
!= subreg_p
|| curr
->biggest_mode
!= mode
)
1588 /* The info can not be integrated into the found
1590 data
->regs
= new_insn_reg (regno
, type
, mode
, subreg_p
,
1591 early_clobber
, data
->regs
);
1594 if (curr
->type
!= type
)
1595 curr
->type
= OP_INOUT
;
1596 if (curr
->early_clobber
!= early_clobber
)
1597 curr
->early_clobber
= true;
1608 add_regs_to_insn_regno_info (data
, SET_DEST (x
), uid
, OP_OUT
, false);
1609 add_regs_to_insn_regno_info (data
, SET_SRC (x
), uid
, OP_IN
, false);
1612 /* We treat clobber of non-operand hard registers as early
1613 clobber (the behavior is expected from asm). */
1614 add_regs_to_insn_regno_info (data
, XEXP (x
, 0), uid
, OP_OUT
, true);
1616 case PRE_INC
: case PRE_DEC
: case POST_INC
: case POST_DEC
:
1617 add_regs_to_insn_regno_info (data
, XEXP (x
, 0), uid
, OP_INOUT
, false);
1619 case PRE_MODIFY
: case POST_MODIFY
:
1620 add_regs_to_insn_regno_info (data
, XEXP (x
, 0), uid
, OP_INOUT
, false);
1621 add_regs_to_insn_regno_info (data
, XEXP (x
, 1), uid
, OP_IN
, false);
1624 if ((code
!= PARALLEL
&& code
!= EXPR_LIST
) || type
!= OP_OUT
)
1625 /* Some targets place small structures in registers for return
1626 values of functions, and those registers are wrapped in
1627 PARALLEL that we may see as the destination of a SET. Here
1630 (call_insn 13 12 14 2 (set (parallel:BLK [
1631 (expr_list:REG_DEP_TRUE (reg:DI 0 ax)
1633 (expr_list:REG_DEP_TRUE (reg:DI 1 dx)
1634 (const_int 8 [0x8]))
1636 (call (mem:QI (symbol_ref:DI (... */
1638 fmt
= GET_RTX_FORMAT (code
);
1639 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1642 add_regs_to_insn_regno_info (data
, XEXP (x
, i
), uid
, type
, false);
1643 else if (fmt
[i
] == 'E')
1645 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1646 add_regs_to_insn_regno_info (data
, XVECEXP (x
, i
, j
), uid
,
1653 /* Return execution frequency of INSN. */
1655 get_insn_freq (rtx insn
)
1657 basic_block bb
= BLOCK_FOR_INSN (insn
);
1659 gcc_checking_assert (bb
!= NULL
);
1660 return REG_FREQ_FROM_BB (bb
);
1663 /* Invalidate all reg info of INSN with DATA and execution frequency
1664 FREQ. Update common info about the invalidated registers. */
1666 invalidate_insn_data_regno_info (lra_insn_recog_data_t data
, rtx insn
,
1672 struct lra_insn_reg
*ir
, *next_ir
;
1674 uid
= INSN_UID (insn
);
1675 debug_p
= DEBUG_INSN_P (insn
);
1676 for (ir
= data
->regs
; ir
!= NULL
; ir
= next_ir
)
1681 bitmap_clear_bit (&lra_reg_info
[i
].insn_bitmap
, uid
);
1682 if (i
>= FIRST_PSEUDO_REGISTER
&& ! debug_p
)
1684 lra_reg_info
[i
].nrefs
--;
1685 lra_reg_info
[i
].freq
-= freq
;
1686 lra_assert (lra_reg_info
[i
].nrefs
>= 0 && lra_reg_info
[i
].freq
>= 0);
1692 /* Invalidate all reg info of INSN. Update common info about the
1693 invalidated registers. */
1695 lra_invalidate_insn_regno_info (rtx insn
)
1697 invalidate_insn_data_regno_info (lra_get_insn_recog_data (insn
), insn
,
1698 get_insn_freq (insn
));
1701 /* Update common reg info from reg info of insn given by its DATA and
1702 execution frequency FREQ. */
1704 setup_insn_reg_info (lra_insn_recog_data_t data
, int freq
)
1707 struct lra_insn_reg
*ir
;
1709 for (ir
= data
->regs
; ir
!= NULL
; ir
= ir
->next
)
1710 if ((i
= ir
->regno
) >= FIRST_PSEUDO_REGISTER
)
1712 lra_reg_info
[i
].nrefs
++;
1713 lra_reg_info
[i
].freq
+= freq
;
1717 /* Set up insn reg info of INSN. Update common reg info from reg info
1720 lra_update_insn_regno_info (rtx insn
)
1723 lra_insn_recog_data_t data
;
1724 struct lra_static_insn_data
*static_data
;
1727 if (! INSN_P (insn
))
1729 data
= lra_get_insn_recog_data (insn
);
1730 static_data
= data
->insn_static_data
;
1731 freq
= get_insn_freq (insn
);
1732 invalidate_insn_data_regno_info (data
, insn
, freq
);
1733 uid
= INSN_UID (insn
);
1734 for (i
= static_data
->n_operands
- 1; i
>= 0; i
--)
1735 add_regs_to_insn_regno_info (data
, *data
->operand_loc
[i
], uid
,
1736 static_data
->operand
[i
].type
,
1737 static_data
->operand
[i
].early_clobber
);
1738 if ((code
= GET_CODE (PATTERN (insn
))) == CLOBBER
|| code
== USE
)
1739 add_regs_to_insn_regno_info (data
, XEXP (PATTERN (insn
), 0), uid
,
1740 code
== USE
? OP_IN
: OP_OUT
, false);
1741 if (NONDEBUG_INSN_P (insn
))
1742 setup_insn_reg_info (data
, freq
);
1745 /* Return reg info of insn given by it UID. */
1746 struct lra_insn_reg
*
1747 lra_get_insn_regs (int uid
)
1749 lra_insn_recog_data_t data
;
1751 data
= get_insn_recog_data_by_uid (uid
);
1757 /* This page contains code dealing with stack of the insns which
1758 should be processed by the next constraint pass. */
1760 /* Bitmap used to put an insn on the stack only in one exemplar. */
1761 static sbitmap lra_constraint_insn_stack_bitmap
;
1763 /* The stack itself. */
1764 vec
<rtx
> lra_constraint_insn_stack
;
1766 /* Put INSN on the stack. If ALWAYS_UPDATE is true, always update the reg
1767 info for INSN, otherwise only update it if INSN is not already on the
1770 lra_push_insn_1 (rtx insn
, bool always_update
)
1772 unsigned int uid
= INSN_UID (insn
);
1774 lra_update_insn_regno_info (insn
);
1775 if (uid
>= SBITMAP_SIZE (lra_constraint_insn_stack_bitmap
))
1776 lra_constraint_insn_stack_bitmap
=
1777 sbitmap_resize (lra_constraint_insn_stack_bitmap
, 3 * uid
/ 2, 0);
1778 if (bitmap_bit_p (lra_constraint_insn_stack_bitmap
, uid
))
1780 bitmap_set_bit (lra_constraint_insn_stack_bitmap
, uid
);
1781 if (! always_update
)
1782 lra_update_insn_regno_info (insn
);
1783 lra_constraint_insn_stack
.safe_push (insn
);
1786 /* Put INSN on the stack. */
1788 lra_push_insn (rtx insn
)
1790 lra_push_insn_1 (insn
, false);
1793 /* Put INSN on the stack and update its reg info. */
1795 lra_push_insn_and_update_insn_regno_info (rtx insn
)
1797 lra_push_insn_1 (insn
, true);
1800 /* Put insn with UID on the stack. */
1802 lra_push_insn_by_uid (unsigned int uid
)
1804 lra_push_insn (lra_insn_recog_data
[uid
]->insn
);
1807 /* Take the last-inserted insns off the stack and return it. */
1811 rtx insn
= lra_constraint_insn_stack
.pop ();
1812 bitmap_clear_bit (lra_constraint_insn_stack_bitmap
, INSN_UID (insn
));
1816 /* Return the current size of the insn stack. */
1818 lra_insn_stack_length (void)
1820 return lra_constraint_insn_stack
.length ();
1823 /* Push insns FROM to TO (excluding it) going in reverse order. */
1825 push_insns (rtx from
, rtx to
)
1829 if (from
== NULL_RTX
)
1831 for (insn
= from
; insn
!= to
; insn
= PREV_INSN (insn
))
1833 lra_push_insn (insn
);
1836 /* Emit insns BEFORE before INSN and insns AFTER after INSN. Put the
1837 insns onto the stack. Print about emitting the insns with
1840 lra_process_new_insns (rtx insn
, rtx before
, rtx after
, const char *title
)
1844 if (lra_dump_file
!= NULL
&& (before
!= NULL_RTX
|| after
!= NULL_RTX
))
1846 dump_insn_slim (lra_dump_file
, insn
);
1847 if (before
!= NULL_RTX
)
1849 fprintf (lra_dump_file
," %s before:\n", title
);
1850 dump_rtl_slim (lra_dump_file
, before
, NULL_RTX
, -1, 0);
1852 if (after
!= NULL_RTX
)
1854 fprintf (lra_dump_file
, " %s after:\n", title
);
1855 dump_rtl_slim (lra_dump_file
, after
, NULL_RTX
, -1, 0);
1857 fprintf (lra_dump_file
, "\n");
1859 if (before
!= NULL_RTX
)
1861 emit_insn_before (before
, insn
);
1862 push_insns (PREV_INSN (insn
), PREV_INSN (before
));
1864 if (after
!= NULL_RTX
)
1866 for (last
= after
; NEXT_INSN (last
) != NULL_RTX
; last
= NEXT_INSN (last
))
1868 emit_insn_after (after
, insn
);
1869 push_insns (last
, insn
);
1875 /* This page contains code dealing with scratches (changing them onto
1876 pseudos and restoring them from the pseudos).
1878 We change scratches into pseudos at the beginning of LRA to
1879 simplify dealing with them (conflicts, hard register assignments).
1881 If the pseudo denoting scratch was spilled it means that we do need
1882 a hard register for it. Such pseudos are transformed back to
1883 scratches at the end of LRA. */
1885 /* Description of location of a former scratch operand. */
1888 rtx insn
; /* Insn where the scratch was. */
1889 int nop
; /* Number of the operand which was a scratch. */
1892 typedef struct sloc
*sloc_t
;
1894 /* Locations of the former scratches. */
1895 static vec
<sloc_t
> scratches
;
1897 /* Bitmap of scratch regnos. */
1898 static bitmap_head scratch_bitmap
;
1900 /* Bitmap of scratch operands. */
1901 static bitmap_head scratch_operand_bitmap
;
1903 /* Return true if pseudo REGNO is made of SCRATCH. */
1905 lra_former_scratch_p (int regno
)
1907 return bitmap_bit_p (&scratch_bitmap
, regno
);
1910 /* Return true if the operand NOP of INSN is a former scratch. */
1912 lra_former_scratch_operand_p (rtx insn
, int nop
)
1914 return bitmap_bit_p (&scratch_operand_bitmap
,
1915 INSN_UID (insn
) * MAX_RECOG_OPERANDS
+ nop
) != 0;
1918 /* Change scratches onto pseudos and save their location. */
1920 remove_scratches (void)
1923 bool insn_changed_p
;
1927 lra_insn_recog_data_t id
;
1928 struct lra_static_insn_data
*static_id
;
1930 scratches
.create (get_max_uid ());
1931 bitmap_initialize (&scratch_bitmap
, ®_obstack
);
1932 bitmap_initialize (&scratch_operand_bitmap
, ®_obstack
);
1934 FOR_BB_INSNS (bb
, insn
)
1937 id
= lra_get_insn_recog_data (insn
);
1938 static_id
= id
->insn_static_data
;
1939 insn_changed_p
= false;
1940 for (i
= 0; i
< static_id
->n_operands
; i
++)
1941 if (GET_CODE (*id
->operand_loc
[i
]) == SCRATCH
1942 && GET_MODE (*id
->operand_loc
[i
]) != VOIDmode
)
1944 insn_changed_p
= true;
1945 *id
->operand_loc
[i
] = reg
1946 = lra_create_new_reg (static_id
->operand
[i
].mode
,
1947 *id
->operand_loc
[i
], ALL_REGS
, NULL
);
1948 add_reg_note (insn
, REG_UNUSED
, reg
);
1949 lra_update_dup (id
, i
);
1950 loc
= XNEW (struct sloc
);
1953 scratches
.safe_push (loc
);
1954 bitmap_set_bit (&scratch_bitmap
, REGNO (*id
->operand_loc
[i
]));
1955 bitmap_set_bit (&scratch_operand_bitmap
,
1956 INSN_UID (insn
) * MAX_RECOG_OPERANDS
+ i
);
1957 if (lra_dump_file
!= NULL
)
1958 fprintf (lra_dump_file
,
1959 "Removing SCRATCH in insn #%u (nop %d)\n",
1960 INSN_UID (insn
), i
);
1963 /* Because we might use DF right after caller-saves sub-pass
1964 we need to keep DF info up to date. */
1965 df_insn_rescan (insn
);
1969 /* Changes pseudos created by function remove_scratches onto scratches. */
1971 restore_scratches (void)
1976 rtx last
= NULL_RTX
;
1977 lra_insn_recog_data_t id
= NULL
;
1979 for (i
= 0; scratches
.iterate (i
, &loc
); i
++)
1981 if (last
!= loc
->insn
)
1984 id
= lra_get_insn_recog_data (last
);
1986 if (REG_P (*id
->operand_loc
[loc
->nop
])
1987 && ((regno
= REGNO (*id
->operand_loc
[loc
->nop
]))
1988 >= FIRST_PSEUDO_REGISTER
)
1989 && lra_get_regno_hard_regno (regno
) < 0)
1991 /* It should be only case when scratch register with chosen
1992 constraint 'X' did not get memory or hard register. */
1993 lra_assert (lra_former_scratch_p (regno
));
1994 *id
->operand_loc
[loc
->nop
]
1995 = gen_rtx_SCRATCH (GET_MODE (*id
->operand_loc
[loc
->nop
]));
1996 lra_update_dup (id
, loc
->nop
);
1997 if (lra_dump_file
!= NULL
)
1998 fprintf (lra_dump_file
, "Restoring SCRATCH in insn #%u(nop %d)\n",
1999 INSN_UID (loc
->insn
), loc
->nop
);
2002 for (i
= 0; scratches
.iterate (i
, &loc
); i
++)
2004 scratches
.release ();
2005 bitmap_clear (&scratch_bitmap
);
2006 bitmap_clear (&scratch_operand_bitmap
);
2011 #ifdef ENABLE_CHECKING
2013 /* Function checks RTL for correctness. If FINAL_P is true, it is
2014 done at the end of LRA and the check is more rigorous. */
2016 check_rtl (bool final_p
)
2021 lra_insn_recog_data_t id
;
2023 lra_assert (! final_p
|| reload_completed
);
2025 FOR_BB_INSNS (bb
, insn
)
2026 if (NONDEBUG_INSN_P (insn
)
2027 && GET_CODE (PATTERN (insn
)) != USE
2028 && GET_CODE (PATTERN (insn
)) != CLOBBER
2029 && GET_CODE (PATTERN (insn
)) != ASM_INPUT
)
2033 extract_insn (insn
);
2034 lra_assert (constrain_operands (1));
2037 if (insn_invalid_p (insn
, false))
2038 fatal_insn_not_found (insn
);
2039 if (asm_noperands (PATTERN (insn
)) >= 0)
2041 id
= lra_get_insn_recog_data (insn
);
2042 /* The code is based on assumption that all addresses in
2043 regular instruction are legitimate before LRA. The code in
2044 lra-constraints.c is based on assumption that there is no
2045 subreg of memory as an insn operand. */
2046 for (i
= 0; i
< id
->insn_static_data
->n_operands
; i
++)
2048 rtx op
= *id
->operand_loc
[i
];
2051 && (GET_MODE (op
) != BLKmode
2052 || GET_CODE (XEXP (op
, 0)) != SCRATCH
)
2053 && ! memory_address_p (GET_MODE (op
), XEXP (op
, 0))
2054 /* Some ports don't recognize the following addresses
2055 as legitimate. Although they are legitimate if
2056 they satisfies the constraints and will be checked
2057 by insn constraints which we ignore here. */
2058 && GET_CODE (XEXP (op
, 0)) != UNSPEC
2059 && GET_RTX_CLASS (GET_CODE (XEXP (op
, 0))) != RTX_AUTOINC
)
2060 fatal_insn_not_found (insn
);
2064 #endif /* #ifdef ENABLE_CHECKING */
2066 /* Determine if the current function has an exception receiver block
2067 that reaches the exit block via non-exceptional edges */
2069 has_nonexceptional_receiver (void)
2073 basic_block
*tos
, *worklist
, bb
;
2075 /* If we're not optimizing, then just err on the safe side. */
2079 /* First determine which blocks can reach exit via normal paths. */
2080 tos
= worklist
= XNEWVEC (basic_block
, n_basic_blocks
+ 1);
2083 bb
->flags
&= ~BB_REACHABLE
;
2085 /* Place the exit block on our worklist. */
2086 EXIT_BLOCK_PTR
->flags
|= BB_REACHABLE
;
2087 *tos
++ = EXIT_BLOCK_PTR
;
2089 /* Iterate: find everything reachable from what we've already seen. */
2090 while (tos
!= worklist
)
2094 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
2095 if (e
->flags
& EDGE_ABNORMAL
)
2102 basic_block src
= e
->src
;
2104 if (!(src
->flags
& BB_REACHABLE
))
2106 src
->flags
|= BB_REACHABLE
;
2112 /* No exceptional block reached exit unexceptionally. */
2118 /* Process recursively X of INSN and add REG_INC notes if necessary. */
2120 add_auto_inc_notes (rtx insn
, rtx x
)
2122 enum rtx_code code
= GET_CODE (x
);
2126 if (code
== MEM
&& auto_inc_p (XEXP (x
, 0)))
2128 add_reg_note (insn
, REG_INC
, XEXP (XEXP (x
, 0), 0));
2132 /* Scan all X sub-expressions. */
2133 fmt
= GET_RTX_FORMAT (code
);
2134 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2137 add_auto_inc_notes (insn
, XEXP (x
, i
));
2138 else if (fmt
[i
] == 'E')
2139 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2140 add_auto_inc_notes (insn
, XVECEXP (x
, i
, j
));
2146 /* Remove all REG_DEAD and REG_UNUSED notes and regenerate REG_INC.
2147 We change pseudos by hard registers without notification of DF and
2148 that can make the notes obsolete. DF-infrastructure does not deal
2149 with REG_INC notes -- so we should regenerate them here. */
2151 update_inc_notes (void)
2158 FOR_BB_INSNS (bb
, insn
)
2159 if (NONDEBUG_INSN_P (insn
))
2161 pnote
= ®_NOTES (insn
);
2164 if (REG_NOTE_KIND (*pnote
) == REG_INC
)
2165 *pnote
= XEXP (*pnote
, 1);
2167 pnote
= &XEXP (*pnote
, 1);
2170 add_auto_inc_notes (insn
, PATTERN (insn
));
2175 /* Set to 1 while in lra. */
2176 int lra_in_progress
;
2178 /* Start of pseudo regnos before the LRA. */
2179 int lra_new_regno_start
;
2181 /* Start of reload pseudo regnos before the new spill pass. */
2182 int lra_constraint_new_regno_start
;
2184 /* Inheritance pseudo regnos before the new spill pass. */
2185 bitmap_head lra_inheritance_pseudos
;
2187 /* Split regnos before the new spill pass. */
2188 bitmap_head lra_split_regs
;
2190 /* Reload pseudo regnos before the new assign pass which still can be
2191 spilled after the assinment pass. */
2192 bitmap_head lra_optional_reload_pseudos
;
2194 /* First UID of insns generated before a new spill pass. */
2195 int lra_constraint_new_insn_uid_start
;
2197 /* File used for output of LRA debug information. */
2198 FILE *lra_dump_file
;
2200 /* True if we should try spill into registers of different classes
2201 instead of memory. */
2202 bool lra_reg_spill_p
;
2204 /* Set up value LRA_REG_SPILL_P. */
2206 setup_reg_spill_flag (void)
2210 if (targetm
.spill_class
!= NULL
)
2211 for (cl
= 0; cl
< (int) LIM_REG_CLASSES
; cl
++)
2212 for (mode
= 0; mode
< MAX_MACHINE_MODE
; mode
++)
2213 if (targetm
.spill_class ((enum reg_class
) cl
,
2214 (enum machine_mode
) mode
) != NO_REGS
)
2216 lra_reg_spill_p
= true;
2219 lra_reg_spill_p
= false;
2222 /* True if the current function is too big to use regular algorithms
2223 in LRA. In other words, we should use simpler and faster algorithms
2224 in LRA. It also means we should not worry about generation code
2225 for caller saves. The value is set up in IRA. */
2228 /* Major LRA entry function. F is a file should be used to dump LRA
2234 bool live_p
, scratch_p
, inserted_p
;
2238 timevar_push (TV_LRA
);
2240 /* Make sure that the last insn is a note. Some subsequent passes
2242 emit_note (NOTE_INSN_DELETED
);
2244 COPY_HARD_REG_SET (lra_no_alloc_regs
, ira_no_alloc_regs
);
2249 init_insn_recog_data ();
2251 #ifdef ENABLE_CHECKING
2255 lra_live_range_iter
= lra_coalesce_iter
= 0;
2256 lra_constraint_iter
= lra_constraint_iter_after_spill
= 0;
2257 lra_inheritance_iter
= lra_undo_inheritance_iter
= 0;
2259 setup_reg_spill_flag ();
2261 /* We can not set up reload_in_progress because it prevents new
2263 lra_in_progress
= 1;
2265 /* Function remove_scratches can creates new pseudos for clobbers --
2266 so set up lra_constraint_new_regno_start before its call to
2267 permit changing reg classes for pseudos created by this
2269 lra_constraint_new_regno_start
= lra_new_regno_start
= max_reg_num ();
2270 remove_scratches ();
2271 scratch_p
= lra_constraint_new_regno_start
!= max_reg_num ();
2273 /* A function that has a non-local label that can reach the exit
2274 block via non-exceptional paths must save all call-saved
2276 if (cfun
->has_nonlocal_label
&& has_nonexceptional_receiver ())
2277 crtl
->saves_all_registers
= 1;
2279 if (crtl
->saves_all_registers
)
2280 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2281 if (! call_used_regs
[i
] && ! fixed_regs
[i
] && ! LOCAL_REGNO (i
))
2282 df_set_regs_ever_live (i
, true);
2284 /* We don't DF from now and avoid its using because it is to
2285 expensive when a lot of RTL changes are made. */
2286 df_set_flags (DF_NO_INSN_RESCAN
);
2287 lra_constraint_insn_stack
.create (get_max_uid ());
2288 lra_constraint_insn_stack_bitmap
= sbitmap_alloc (get_max_uid ());
2289 bitmap_clear (lra_constraint_insn_stack_bitmap
);
2290 lra_live_ranges_init ();
2291 lra_constraints_init ();
2292 lra_curr_reload_num
= 0;
2293 push_insns (get_last_insn (), NULL_RTX
);
2294 /* It is needed for the 1st coalescing. */
2295 lra_constraint_new_insn_uid_start
= get_max_uid ();
2296 bitmap_initialize (&lra_inheritance_pseudos
, ®_obstack
);
2297 bitmap_initialize (&lra_split_regs
, ®_obstack
);
2298 bitmap_initialize (&lra_optional_reload_pseudos
, ®_obstack
);
2300 if (get_frame_size () != 0 && crtl
->stack_alignment_needed
)
2301 /* If we have a stack frame, we must align it now. The stack size
2302 may be a part of the offset computation for register
2304 assign_stack_local (BLKmode
, 0, crtl
->stack_alignment_needed
);
2309 /* We should try to assign hard registers to scratches even
2310 if there were no RTL transformations in
2312 if (! lra_constraints (lra_constraint_iter
== 0)
2313 && (lra_constraint_iter
> 1
2314 || (! scratch_p
&& ! caller_save_needed
)))
2316 /* Constraint transformations may result in that eliminable
2317 hard regs become uneliminable and pseudos which use them
2318 should be spilled. It is better to do it before pseudo
2321 For example, rs6000 can make
2322 RS6000_PIC_OFFSET_TABLE_REGNUM uneliminable if we started
2323 to use a constant pool. */
2324 lra_eliminate (false);
2325 /* Do inheritance only for regular algorithms. */
2329 lra_clear_live_ranges ();
2330 /* We need live ranges for lra_assign -- so build them. */
2331 lra_create_live_ranges (true);
2333 /* If we don't spill non-reload and non-inheritance pseudos,
2334 there is no sense to run memory-memory move coalescing.
2335 If inheritance pseudos were spilled, the memory-memory
2336 moves involving them will be removed by pass undoing
2342 bool spill_p
= !lra_assign ();
2344 if (lra_undo_inheritance ())
2350 lra_create_live_ranges (true);
2353 if (lra_coalesce ())
2357 lra_clear_live_ranges ();
2360 bitmap_clear (&lra_optional_reload_pseudos
);
2361 bitmap_clear (&lra_inheritance_pseudos
);
2362 bitmap_clear (&lra_split_regs
);
2363 if (! lra_need_for_spills_p ())
2367 /* We need full live info for spilling pseudos into
2368 registers instead of memory. */
2369 lra_create_live_ranges (lra_reg_spill_p
);
2373 /* Assignment of stack slots changes elimination offsets for
2374 some eliminations. So update the offsets here. */
2375 lra_eliminate (false);
2376 lra_constraint_new_regno_start
= max_reg_num ();
2377 lra_constraint_new_insn_uid_start
= get_max_uid ();
2378 lra_constraint_iter_after_spill
= 0;
2380 restore_scratches ();
2381 lra_eliminate (true);
2382 lra_final_code_change ();
2383 lra_in_progress
= 0;
2385 lra_clear_live_ranges ();
2386 lra_live_ranges_finish ();
2387 lra_constraints_finish ();
2389 sbitmap_free (lra_constraint_insn_stack_bitmap
);
2390 lra_constraint_insn_stack
.release ();
2391 finish_insn_recog_data ();
2392 regstat_free_n_sets_and_refs ();
2394 reload_completed
= 1;
2395 update_inc_notes ();
2397 inserted_p
= fixup_abnormal_edges ();
2399 /* We've possibly turned single trapping insn into multiple ones. */
2400 if (cfun
->can_throw_non_call_exceptions
)
2403 blocks
= sbitmap_alloc (last_basic_block
);
2404 bitmap_ones (blocks
);
2405 find_many_sub_basic_blocks (blocks
);
2406 sbitmap_free (blocks
);
2410 commit_edge_insertions ();
2412 /* Replacing pseudos with their memory equivalents might have
2413 created shared rtx. Subsequent passes would get confused
2414 by this, so unshare everything here. */
2415 unshare_all_rtl_again (get_insns ());
2417 #ifdef ENABLE_CHECKING
2421 timevar_pop (TV_LRA
);
2424 /* Called once per compiler to initialize LRA data once. */
2426 lra_init_once (void)
2428 init_insn_code_data_once ();
2431 /* Initialize LRA whenever register-related information is changed. */
2435 init_op_alt_data ();
2438 /* Called once per compiler to finish LRA data which are initialize
2441 lra_finish_once (void)
2443 finish_insn_code_data_once ();