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
);
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 (int old
)
137 ira_expand_reg_equiv ();
138 for (int i
= (int) max_reg_num () - 1; i
>= old
; i
--)
139 lra_change_class (i
, ALL_REGS
, " Set", true);
142 /* Create and return a new reg of ORIGINAL mode. If ORIGINAL is NULL
143 or of VOIDmode, use MD_MODE for the new reg. Initialize its
144 register class to RCLASS. Print message about assigning class
145 RCLASS containing new register name TITLE unless it is NULL. Use
146 attributes of ORIGINAL if it is a register. The created register
147 will have unique held value. */
149 lra_create_new_reg_with_unique_value (enum machine_mode md_mode
, rtx original
,
150 enum reg_class rclass
, const char *title
)
152 enum machine_mode mode
;
155 if (original
== NULL_RTX
|| (mode
= GET_MODE (original
)) == VOIDmode
)
157 lra_assert (mode
!= VOIDmode
);
158 new_reg
= gen_reg_rtx (mode
);
159 if (original
== NULL_RTX
|| ! REG_P (original
))
161 if (lra_dump_file
!= NULL
)
162 fprintf (lra_dump_file
, " Creating newreg=%i", REGNO (new_reg
));
166 if (ORIGINAL_REGNO (original
) >= FIRST_PSEUDO_REGISTER
)
167 ORIGINAL_REGNO (new_reg
) = ORIGINAL_REGNO (original
);
168 REG_USERVAR_P (new_reg
) = REG_USERVAR_P (original
);
169 REG_POINTER (new_reg
) = REG_POINTER (original
);
170 REG_ATTRS (new_reg
) = REG_ATTRS (original
);
171 if (lra_dump_file
!= NULL
)
172 fprintf (lra_dump_file
, " Creating newreg=%i from oldreg=%i",
173 REGNO (new_reg
), REGNO (original
));
175 if (lra_dump_file
!= NULL
)
178 fprintf (lra_dump_file
, ", assigning class %s to%s%s r%d",
179 reg_class_names
[rclass
], *title
== '\0' ? "" : " ",
180 title
, REGNO (new_reg
));
181 fprintf (lra_dump_file
, "\n");
183 expand_reg_data (max_reg_num ());
184 setup_reg_classes (REGNO (new_reg
), rclass
, NO_REGS
, rclass
);
188 /* Analogous to the previous function but also inherits value of
191 lra_create_new_reg (enum machine_mode md_mode
, rtx original
,
192 enum reg_class rclass
, const char *title
)
197 = lra_create_new_reg_with_unique_value (md_mode
, original
, rclass
, title
);
198 if (original
!= NULL_RTX
&& REG_P (original
))
199 lra_assign_reg_val (REGNO (original
), REGNO (new_reg
));
203 /* Set up for REGNO unique hold value. */
205 lra_set_regno_unique_value (int regno
)
207 lra_reg_info
[regno
].val
= get_new_reg_value ();
210 /* Invalidate INSN related info used by LRA. The info should never be
213 lra_invalidate_insn_data (rtx insn
)
215 lra_invalidate_insn_regno_info (insn
);
216 invalidate_insn_recog_data (INSN_UID (insn
));
219 /* Mark INSN deleted and invalidate the insn related info used by
222 lra_set_insn_deleted (rtx insn
)
224 lra_invalidate_insn_data (insn
);
225 SET_INSN_DELETED (insn
);
228 /* Delete an unneeded INSN and any previous insns who sole purpose is
229 loading data that is dead in INSN. */
231 lra_delete_dead_insn (rtx insn
)
233 rtx prev
= prev_real_insn (insn
);
236 /* If the previous insn sets a register that dies in our insn,
238 if (prev
&& GET_CODE (PATTERN (prev
)) == SET
239 && (prev_dest
= SET_DEST (PATTERN (prev
)), REG_P (prev_dest
))
240 && reg_mentioned_p (prev_dest
, PATTERN (insn
))
241 && find_regno_note (insn
, REG_DEAD
, REGNO (prev_dest
))
242 && ! side_effects_p (SET_SRC (PATTERN (prev
))))
243 lra_delete_dead_insn (prev
);
245 lra_set_insn_deleted (insn
);
248 /* Emit insn x = y + z. Return NULL if we failed to do it.
249 Otherwise, return the insn. We don't use gen_add3_insn as it might
252 emit_add3_insn (rtx x
, rtx y
, rtx z
)
256 last
= get_last_insn ();
257 insn
= emit_insn (gen_rtx_SET (VOIDmode
, x
,
258 gen_rtx_PLUS (GET_MODE (y
), y
, z
)));
259 if (recog_memoized (insn
) < 0)
261 delete_insns_since (last
);
267 /* Emit insn x = x + y. Return the insn. We use gen_add2_insn as the
270 emit_add2_insn (rtx x
, rtx y
)
274 insn
= emit_add3_insn (x
, x
, y
);
275 if (insn
== NULL_RTX
)
277 insn
= gen_add2_insn (x
, y
);
278 if (insn
!= NULL_RTX
)
284 /* Target checks operands through operand predicates to recognize an
285 insn. We should have a special precaution to generate add insns
286 which are frequent results of elimination.
288 Emit insns for x = y + z. X can be used to store intermediate
289 values and should be not in Y and Z when we use X to store an
290 intermediate value. Y + Z should form [base] [+ index[ * scale]] [
291 + disp] where base and index are registers, disp and scale are
292 constants. Y should contain base if it is present, Z should
293 contain disp if any. index[*scale] can be part of Y or Z. */
295 lra_emit_add (rtx x
, rtx y
, rtx z
)
299 rtx a1
, a2
, base
, index
, disp
, scale
, index_scale
;
302 insn
= emit_add3_insn (x
, y
, z
);
303 old
= max_reg_num ();
304 if (insn
!= NULL_RTX
)
308 disp
= a2
= NULL_RTX
;
309 if (GET_CODE (y
) == PLUS
)
323 index_scale
= scale
= NULL_RTX
;
324 if (GET_CODE (a1
) == MULT
)
327 index
= XEXP (a1
, 0);
328 scale
= XEXP (a1
, 1);
331 else if (a2
!= NULL_RTX
&& GET_CODE (a2
) == MULT
)
334 index
= XEXP (a2
, 0);
335 scale
= XEXP (a2
, 1);
343 if (! (REG_P (base
) || GET_CODE (base
) == SUBREG
)
344 || (index
!= NULL_RTX
345 && ! (REG_P (index
) || GET_CODE (index
) == SUBREG
))
346 || (disp
!= NULL_RTX
&& ! CONSTANT_P (disp
))
347 || (scale
!= NULL_RTX
&& ! CONSTANT_P (scale
)))
349 /* Probably we have no 3 op add. Last chance is to use 2-op
350 add insn. To succeed, don't move Z to X as an address
351 segment always comes in Y. Otherwise, we might fail when
352 adding the address segment to register. */
353 lra_assert (x
!= y
&& x
!= z
);
354 emit_move_insn (x
, y
);
355 insn
= emit_add2_insn (x
, z
);
356 lra_assert (insn
!= NULL_RTX
);
360 if (index_scale
== NULL_RTX
)
362 if (disp
== NULL_RTX
)
364 /* Generate x = index_scale; x = x + base. */
365 lra_assert (index_scale
!= NULL_RTX
&& base
!= NULL_RTX
);
366 emit_move_insn (x
, index_scale
);
367 insn
= emit_add2_insn (x
, base
);
368 lra_assert (insn
!= NULL_RTX
);
370 else if (scale
== NULL_RTX
)
372 /* Try x = base + disp. */
373 lra_assert (base
!= NULL_RTX
);
374 last
= get_last_insn ();
375 insn
= emit_move_insn (x
, gen_rtx_PLUS (GET_MODE (base
),
377 if (recog_memoized (insn
) < 0)
379 delete_insns_since (last
);
380 /* Generate x = disp; x = x + base. */
381 emit_move_insn (x
, disp
);
382 insn
= emit_add2_insn (x
, base
);
383 lra_assert (insn
!= NULL_RTX
);
385 /* Generate x = x + index. */
386 if (index
!= NULL_RTX
)
388 insn
= emit_add2_insn (x
, index
);
389 lra_assert (insn
!= NULL_RTX
);
394 /* Try x = index_scale; x = x + disp; x = x + base. */
395 last
= get_last_insn ();
396 insn
= emit_move_insn (x
, index_scale
);
398 if (recog_memoized (insn
) >= 0)
400 insn
= emit_add2_insn (x
, disp
);
401 if (insn
!= NULL_RTX
)
403 insn
= emit_add2_insn (x
, disp
);
404 if (insn
!= NULL_RTX
)
410 delete_insns_since (last
);
411 /* Generate x = disp; x = x + base; x = x + index_scale. */
412 emit_move_insn (x
, disp
);
413 insn
= emit_add2_insn (x
, base
);
414 lra_assert (insn
!= NULL_RTX
);
415 insn
= emit_add2_insn (x
, index_scale
);
416 lra_assert (insn
!= NULL_RTX
);
421 /* Functions emit_... can create pseudos -- so expand the pseudo
423 if (old
!= max_reg_num ())
424 expand_reg_data (old
);
427 /* The number of emitted reload insns so far. */
428 int lra_curr_reload_num
;
430 /* Emit x := y, processing special case when y = u + v or y = u + v *
431 scale + w through emit_add (Y can be an address which is base +
432 index reg * scale + displacement in general case). X may be used
433 as intermediate result therefore it should be not in Y. */
435 lra_emit_move (rtx x
, rtx y
)
439 if (GET_CODE (y
) != PLUS
)
441 if (rtx_equal_p (x
, y
))
443 old
= max_reg_num ();
444 emit_move_insn (x
, y
);
446 lra_reg_info
[ORIGINAL_REGNO (x
)].last_reload
= ++lra_curr_reload_num
;
447 /* Function emit_move can create pseudos -- so expand the pseudo
449 if (old
!= max_reg_num ())
450 expand_reg_data (old
);
453 lra_emit_add (x
, XEXP (y
, 0), XEXP (y
, 1));
456 /* Update insn operands which are duplication of operands whose
457 numbers are in array of NOPS (with end marker -1). The insn is
458 represented by its LRA internal representation ID. */
460 lra_update_dups (lra_insn_recog_data_t id
, signed char *nops
)
463 struct lra_static_insn_data
*static_id
= id
->insn_static_data
;
465 for (i
= 0; i
< static_id
->n_dups
; i
++)
466 for (j
= 0; (nop
= nops
[j
]) >= 0; j
++)
467 if (static_id
->dup_num
[i
] == nop
)
468 *id
->dup_loc
[i
] = *id
->operand_loc
[nop
];
473 /* This page contains code dealing with info about registers in the
476 /* Pools for insn reg info. */
477 static alloc_pool insn_reg_pool
;
479 /* Initiate pool for insn reg info. */
481 init_insn_regs (void)
484 = create_alloc_pool ("insn regs", sizeof (struct lra_insn_reg
), 100);
487 /* Create LRA insn related info about a reference to REGNO in INSN with
488 TYPE (in/out/inout), biggest reference mode MODE, flag that it is
489 reference through subreg (SUBREG_P), flag that is early clobbered
490 in the insn (EARLY_CLOBBER), and reference to the next insn reg
492 static struct lra_insn_reg
*
493 new_insn_reg (rtx insn
, int regno
, enum op_type type
, enum machine_mode mode
,
494 bool subreg_p
, bool early_clobber
, struct lra_insn_reg
*next
)
496 struct lra_insn_reg
*ir
;
498 ir
= (struct lra_insn_reg
*) pool_alloc (insn_reg_pool
);
500 ir
->biggest_mode
= mode
;
501 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (lra_reg_info
[regno
].biggest_mode
)
502 && NONDEBUG_INSN_P (insn
))
503 lra_reg_info
[regno
].biggest_mode
= mode
;
504 ir
->subreg_p
= subreg_p
;
505 ir
->early_clobber
= early_clobber
;
511 /* Free insn reg info IR. */
513 free_insn_reg (struct lra_insn_reg
*ir
)
515 pool_free (insn_reg_pool
, ir
);
518 /* Free insn reg info list IR. */
520 free_insn_regs (struct lra_insn_reg
*ir
)
522 struct lra_insn_reg
*next_ir
;
524 for (; ir
!= NULL
; ir
= next_ir
)
531 /* Finish pool for insn reg info. */
533 finish_insn_regs (void)
535 free_alloc_pool (insn_reg_pool
);
540 /* This page contains code dealing LRA insn info (or in other words
541 LRA internal insn representation). */
543 struct target_lra_int default_target_lra_int
;
544 #if SWITCHABLE_TARGET
545 struct target_lra_int
*this_target_lra_int
= &default_target_lra_int
;
548 /* Map INSN_CODE -> the static insn data. This info is valid during
549 all translation unit. */
550 struct lra_static_insn_data
*insn_code_data
[LAST_INSN_CODE
];
552 /* Debug insns are represented as a special insn with one input
553 operand which is RTL expression in var_location. */
555 /* The following data are used as static insn operand data for all
556 debug insns. If structure lra_operand_data is changed, the
557 initializer should be changed too. */
558 static struct lra_operand_data debug_operand_data
=
560 NULL
, /* alternative */
561 VOIDmode
, /* We are not interesting in the operand mode. */
566 /* The following data are used as static insn data for all debug
567 insns. If structure lra_static_insn_data is changed, the
568 initializer should be changed too. */
569 static struct lra_static_insn_data debug_insn_static_data
=
572 0, /* Duplication operands #. */
573 -1, /* Commutative operand #. */
574 1, /* Operands #. There is only one operand which is debug RTL
576 0, /* Duplications #. */
577 0, /* Alternatives #. We are not interesting in alternatives
578 because we does not proceed debug_insns for reloads. */
579 NULL
, /* Hard registers referenced in machine description. */
580 NULL
/* Descriptions of operands in alternatives. */
583 /* Called once per compiler work to initialize some LRA data related
586 init_insn_code_data_once (void)
588 memset (insn_code_data
, 0, sizeof (insn_code_data
));
589 memset (op_alt_data
, 0, sizeof (op_alt_data
));
592 /* Called once per compiler work to finalize some LRA data related to
595 finish_insn_code_data_once (void)
599 for (i
= 0; i
< LAST_INSN_CODE
; i
++)
601 if (insn_code_data
[i
] != NULL
)
602 free (insn_code_data
[i
]);
603 if (op_alt_data
[i
] != NULL
)
604 free (op_alt_data
[i
]);
608 /* Initialize LRA info about operands in insn alternatives. */
610 init_op_alt_data (void)
614 for (i
= 0; i
< LAST_INSN_CODE
; i
++)
615 if (op_alt_data
[i
] != NULL
)
617 free (op_alt_data
[i
]);
618 op_alt_data
[i
] = NULL
;
622 /* Return static insn data, allocate and setup if necessary. Although
623 dup_num is static data (it depends only on icode), to set it up we
624 need to extract insn first. So recog_data should be valid for
625 normal insn (ICODE >= 0) before the call. */
626 static struct lra_static_insn_data
*
627 get_static_insn_data (int icode
, int nop
, int ndup
, int nalt
)
629 struct lra_static_insn_data
*data
;
632 lra_assert (icode
< LAST_INSN_CODE
);
633 if (icode
>= 0 && (data
= insn_code_data
[icode
]) != NULL
)
635 lra_assert (nop
>= 0 && ndup
>= 0 && nalt
>= 0);
636 n_bytes
= sizeof (struct lra_static_insn_data
)
637 + sizeof (struct lra_operand_data
) * nop
638 + sizeof (int) * ndup
;
639 data
= XNEWVAR (struct lra_static_insn_data
, n_bytes
);
640 data
->n_operands
= nop
;
642 data
->n_alternatives
= nalt
;
643 data
->operand
= ((struct lra_operand_data
*)
644 ((char *) data
+ sizeof (struct lra_static_insn_data
)));
645 data
->dup_num
= ((int *) ((char *) data
->operand
646 + sizeof (struct lra_operand_data
) * nop
));
651 insn_code_data
[icode
] = data
;
652 for (i
= 0; i
< nop
; i
++)
654 data
->operand
[i
].constraint
655 = insn_data
[icode
].operand
[i
].constraint
;
656 data
->operand
[i
].mode
= insn_data
[icode
].operand
[i
].mode
;
657 data
->operand
[i
].strict_low
= insn_data
[icode
].operand
[i
].strict_low
;
658 data
->operand
[i
].is_operator
659 = insn_data
[icode
].operand
[i
].is_operator
;
660 data
->operand
[i
].type
661 = (data
->operand
[i
].constraint
[0] == '=' ? OP_OUT
662 : data
->operand
[i
].constraint
[0] == '+' ? OP_INOUT
664 data
->operand
[i
].is_address
= false;
666 for (i
= 0; i
< ndup
; i
++)
667 data
->dup_num
[i
] = recog_data
.dup_num
[i
];
672 /* The current length of the following array. */
673 int lra_insn_recog_data_len
;
675 /* Map INSN_UID -> the insn recog data (NULL if unknown). */
676 lra_insn_recog_data_t
*lra_insn_recog_data
;
678 /* Initialize LRA data about insns. */
680 init_insn_recog_data (void)
682 lra_insn_recog_data_len
= 0;
683 lra_insn_recog_data
= NULL
;
687 /* Expand, if necessary, LRA data about insns. */
689 check_and_expand_insn_recog_data (int index
)
693 if (lra_insn_recog_data_len
> index
)
695 old
= lra_insn_recog_data_len
;
696 lra_insn_recog_data_len
= index
* 3 / 2 + 1;
697 lra_insn_recog_data
= XRESIZEVEC (lra_insn_recog_data_t
,
699 lra_insn_recog_data_len
);
700 for (i
= old
; i
< lra_insn_recog_data_len
; i
++)
701 lra_insn_recog_data
[i
] = NULL
;
704 /* Finish LRA DATA about insn. */
706 free_insn_recog_data (lra_insn_recog_data_t data
)
708 if (data
->operand_loc
!= NULL
)
709 free (data
->operand_loc
);
710 if (data
->dup_loc
!= NULL
)
711 free (data
->dup_loc
);
712 if (data
->arg_hard_regs
!= NULL
)
713 free (data
->arg_hard_regs
);
714 if (HAVE_ATTR_enabled
&& data
->alternative_enabled_p
!= NULL
)
715 free (data
->alternative_enabled_p
);
716 if (data
->icode
< 0 && NONDEBUG_INSN_P (data
->insn
))
718 if (data
->insn_static_data
->operand_alternative
!= NULL
)
719 free (data
->insn_static_data
->operand_alternative
);
720 free_insn_regs (data
->insn_static_data
->hard_regs
);
721 free (data
->insn_static_data
);
723 free_insn_regs (data
->regs
);
728 /* Finish LRA data about all insns. */
730 finish_insn_recog_data (void)
733 lra_insn_recog_data_t data
;
735 for (i
= 0; i
< lra_insn_recog_data_len
; i
++)
736 if ((data
= lra_insn_recog_data
[i
]) != NULL
)
737 free_insn_recog_data (data
);
739 free (lra_insn_recog_data
);
742 /* Setup info about operands in alternatives of LRA DATA of insn. */
744 setup_operand_alternative (lra_insn_recog_data_t data
)
747 int icode
= data
->icode
;
748 struct lra_static_insn_data
*static_data
= data
->insn_static_data
;
751 && (static_data
->operand_alternative
= op_alt_data
[icode
]) != NULL
)
753 static_data
->commutative
= -1;
754 nop
= static_data
->n_operands
;
757 static_data
->operand_alternative
= NULL
;
760 nalt
= static_data
->n_alternatives
;
761 static_data
->operand_alternative
= XNEWVEC (struct operand_alternative
,
763 memset (static_data
->operand_alternative
, 0,
764 nalt
* nop
* sizeof (struct operand_alternative
));
766 op_alt_data
[icode
] = static_data
->operand_alternative
;
767 for (i
= 0; i
< nop
; i
++)
770 struct operand_alternative
*op_alt_start
, *op_alt
;
771 const char *p
= static_data
->operand
[i
].constraint
;
773 static_data
->operand
[i
].early_clobber
= 0;
774 op_alt_start
= &static_data
->operand_alternative
[i
];
776 for (j
= 0; j
< nalt
; j
++)
778 op_alt
= op_alt_start
+ j
* nop
;
779 op_alt
->cl
= NO_REGS
;
780 op_alt
->constraint
= p
;
781 op_alt
->matches
= -1;
782 op_alt
->matched
= -1;
784 if (*p
== '\0' || *p
== ',')
786 op_alt
->anything_ok
= 1;
796 while (c
!= ',' && c
!= '\0');
797 if (c
== ',' || c
== '\0')
805 case '=': case '+': case '*':
806 case 'E': case 'F': case 'G': case 'H':
807 case 's': case 'i': case 'n':
808 case 'I': case 'J': case 'K': case 'L':
809 case 'M': case 'N': case 'O': case 'P':
810 /* These don't say anything we care about. */
814 /* We currently only support one commutative pair of
816 if (static_data
->commutative
< 0)
817 static_data
->commutative
= i
;
819 lra_assert (data
->icode
< 0); /* Asm */
821 /* The last operand should not be marked
823 lra_assert (i
!= nop
- 1);
827 op_alt
->reject
+= LRA_LOSER_COST_FACTOR
;
830 op_alt
->reject
+= LRA_MAX_REJECT
;
833 op_alt
->earlyclobber
= 1;
834 static_data
->operand
[i
].early_clobber
= 1;
837 case '0': case '1': case '2': case '3': case '4':
838 case '5': case '6': case '7': case '8': case '9':
841 op_alt
->matches
= strtoul (p
, &end
, 10);
842 static_data
->operand_alternative
843 [j
* nop
+ op_alt
->matches
].matched
= i
;
848 case TARGET_MEM_CONSTRAINT
:
849 op_alt
->memory_ok
= 1;
852 op_alt
->decmem_ok
= 1;
855 op_alt
->incmem_ok
= 1;
858 op_alt
->nonoffmem_ok
= 1;
861 op_alt
->offmem_ok
= 1;
864 op_alt
->anything_ok
= 1;
868 static_data
->operand
[i
].is_address
= true;
869 op_alt
->is_address
= 1;
870 op_alt
->cl
= (reg_class_subunion
[(int) op_alt
->cl
]
871 [(int) base_reg_class (VOIDmode
,
879 reg_class_subunion
[(int) op_alt
->cl
][(int) GENERAL_REGS
];
883 if (EXTRA_MEMORY_CONSTRAINT (c
, p
))
885 op_alt
->memory_ok
= 1;
888 if (EXTRA_ADDRESS_CONSTRAINT (c
, p
))
890 static_data
->operand
[i
].is_address
= true;
891 op_alt
->is_address
= 1;
893 = (reg_class_subunion
895 [(int) base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
901 = (reg_class_subunion
904 REG_CLASS_FROM_CONSTRAINT ((unsigned char) c
, p
)]);
907 p
+= CONSTRAINT_LEN (c
, p
);
913 /* Recursively process X and collect info about registers, which are
914 not the insn operands, in X with TYPE (in/out/inout) and flag that
915 it is early clobbered in the insn (EARLY_CLOBBER) and add the info
916 to LIST. X is a part of insn given by DATA. Return the result
918 static struct lra_insn_reg
*
919 collect_non_operand_hard_regs (rtx
*x
, lra_insn_recog_data_t data
,
920 struct lra_insn_reg
*list
,
921 enum op_type type
, bool early_clobber
)
923 int i
, j
, regno
, last
;
925 enum machine_mode mode
;
926 struct lra_insn_reg
*curr
;
928 enum rtx_code code
= GET_CODE (op
);
929 const char *fmt
= GET_RTX_FORMAT (code
);
931 for (i
= 0; i
< data
->insn_static_data
->n_operands
; i
++)
932 if (x
== data
->operand_loc
[i
])
933 /* It is an operand loc. Stop here. */
935 for (i
= 0; i
< data
->insn_static_data
->n_dups
; i
++)
936 if (x
== data
->dup_loc
[i
])
937 /* It is a dup loc. Stop here. */
939 mode
= GET_MODE (op
);
943 op
= SUBREG_REG (op
);
944 code
= GET_CODE (op
);
945 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (GET_MODE (op
)))
947 mode
= GET_MODE (op
);
948 if (GET_MODE_SIZE (mode
) > REGMODE_NATURAL_SIZE (mode
))
954 if ((regno
= REGNO (op
)) >= FIRST_PSEUDO_REGISTER
)
956 for (last
= regno
+ hard_regno_nregs
[regno
][mode
];
959 if (! TEST_HARD_REG_BIT (lra_no_alloc_regs
, regno
)
960 || TEST_HARD_REG_BIT (eliminable_regset
, regno
))
962 for (curr
= list
; curr
!= NULL
; curr
= curr
->next
)
963 if (curr
->regno
== regno
&& curr
->subreg_p
== subreg_p
964 && curr
->biggest_mode
== mode
)
966 if (curr
->type
!= type
)
967 curr
->type
= OP_INOUT
;
968 if (curr
->early_clobber
!= early_clobber
)
969 curr
->early_clobber
= true;
974 /* This is a new hard regno or the info can not be
975 integrated into the found structure. */
979 /* This clobber is to inform popping floating
981 && ! (FIRST_STACK_REG
<= regno
982 && regno
<= LAST_STACK_REG
));
984 list
= new_insn_reg (data
->insn
, regno
, type
, mode
, subreg_p
,
985 early_clobber
, list
);
993 list
= collect_non_operand_hard_regs (&SET_DEST (op
), data
,
994 list
, OP_OUT
, false);
995 list
= collect_non_operand_hard_regs (&SET_SRC (op
), data
,
999 /* We treat clobber of non-operand hard registers as early
1000 clobber (the behavior is expected from asm). */
1001 list
= collect_non_operand_hard_regs (&XEXP (op
, 0), data
,
1002 list
, OP_OUT
, true);
1004 case PRE_INC
: case PRE_DEC
: case POST_INC
: case POST_DEC
:
1005 list
= collect_non_operand_hard_regs (&XEXP (op
, 0), data
,
1006 list
, OP_INOUT
, false);
1008 case PRE_MODIFY
: case POST_MODIFY
:
1009 list
= collect_non_operand_hard_regs (&XEXP (op
, 0), data
,
1010 list
, OP_INOUT
, false);
1011 list
= collect_non_operand_hard_regs (&XEXP (op
, 1), data
,
1012 list
, OP_IN
, false);
1015 fmt
= GET_RTX_FORMAT (code
);
1016 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1019 list
= collect_non_operand_hard_regs (&XEXP (op
, i
), data
,
1020 list
, OP_IN
, false);
1021 else if (fmt
[i
] == 'E')
1022 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
1023 list
= collect_non_operand_hard_regs (&XVECEXP (op
, i
, j
), data
,
1024 list
, OP_IN
, false);
1030 /* Set up and return info about INSN. Set up the info if it is not set up
1032 lra_insn_recog_data_t
1033 lra_set_insn_recog_data (rtx insn
)
1035 lra_insn_recog_data_t data
;
1038 unsigned int uid
= INSN_UID (insn
);
1039 struct lra_static_insn_data
*insn_static_data
;
1041 check_and_expand_insn_recog_data (uid
);
1042 if (DEBUG_INSN_P (insn
))
1046 icode
= INSN_CODE (insn
);
1048 /* It might be a new simple insn which is not recognized yet. */
1049 INSN_CODE (insn
) = icode
= recog_memoized (insn
);
1051 data
= XNEW (struct lra_insn_recog_data
);
1052 lra_insn_recog_data
[uid
] = data
;
1054 data
->used_insn_alternative
= -1;
1055 data
->icode
= icode
;
1057 if (DEBUG_INSN_P (insn
))
1059 data
->insn_static_data
= &debug_insn_static_data
;
1060 data
->dup_loc
= NULL
;
1061 data
->arg_hard_regs
= NULL
;
1062 data
->alternative_enabled_p
= NULL
;
1063 data
->operand_loc
= XNEWVEC (rtx
*, 1);
1064 data
->operand_loc
[0] = &INSN_VAR_LOCATION_LOC (insn
);
1070 enum machine_mode operand_mode
[MAX_RECOG_OPERANDS
];
1071 const char *constraints
[MAX_RECOG_OPERANDS
];
1073 nop
= asm_noperands (PATTERN (insn
));
1074 data
->operand_loc
= data
->dup_loc
= NULL
;
1077 /* Its is a special insn like USE or CLOBBER. We should
1078 recognize any regular insn otherwise LRA can do nothing
1080 gcc_assert (GET_CODE (PATTERN (insn
)) == USE
1081 || GET_CODE (PATTERN (insn
)) == CLOBBER
1082 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
);
1083 data
->insn_static_data
= insn_static_data
1084 = get_static_insn_data (-1, 0, 0, 1);
1088 /* expand_asm_operands makes sure there aren't too many
1090 lra_assert (nop
<= MAX_RECOG_OPERANDS
);
1092 data
->operand_loc
= XNEWVEC (rtx
*, nop
);
1093 /* Now get the operand values and constraints out of the
1095 decode_asm_operands (PATTERN (insn
), NULL
,
1097 constraints
, operand_mode
, NULL
);
1101 const char *p
= recog_data
.constraints
[0];
1103 for (p
= constraints
[0]; *p
; p
++)
1106 data
->insn_static_data
= insn_static_data
1107 = get_static_insn_data (-1, nop
, 0, n
);
1108 for (i
= 0; i
< nop
; i
++)
1110 insn_static_data
->operand
[i
].mode
= operand_mode
[i
];
1111 insn_static_data
->operand
[i
].constraint
= constraints
[i
];
1112 insn_static_data
->operand
[i
].strict_low
= false;
1113 insn_static_data
->operand
[i
].is_operator
= false;
1114 insn_static_data
->operand
[i
].is_address
= false;
1117 for (i
= 0; i
< insn_static_data
->n_operands
; i
++)
1118 insn_static_data
->operand
[i
].type
1119 = (insn_static_data
->operand
[i
].constraint
[0] == '=' ? OP_OUT
1120 : insn_static_data
->operand
[i
].constraint
[0] == '+' ? OP_INOUT
1122 data
->alternative_enabled_p
= NULL
;
1126 insn_extract (insn
);
1127 data
->insn_static_data
= insn_static_data
1128 = get_static_insn_data (icode
, insn_data
[icode
].n_operands
,
1129 insn_data
[icode
].n_dups
,
1130 insn_data
[icode
].n_alternatives
);
1131 n
= insn_static_data
->n_operands
;
1136 locs
= XNEWVEC (rtx
*, n
);
1137 memcpy (locs
, recog_data
.operand_loc
, n
* sizeof (rtx
*));
1139 data
->operand_loc
= locs
;
1140 n
= insn_static_data
->n_dups
;
1145 locs
= XNEWVEC (rtx
*, n
);
1146 memcpy (locs
, recog_data
.dup_loc
, n
* sizeof (rtx
*));
1148 data
->dup_loc
= locs
;
1149 if (HAVE_ATTR_enabled
)
1153 n
= insn_static_data
->n_alternatives
;
1154 lra_assert (n
>= 0);
1155 data
->alternative_enabled_p
= bp
= XNEWVEC (bool, n
);
1156 /* Cache the insn because we don't want to call extract_insn
1157 from get_attr_enabled as extract_insn modifies
1158 which_alternative. The attribute enabled should not depend
1159 on insn operands, operand modes, operand types, and operand
1160 constraints. It should depend on the architecture. If it
1161 is not true, we should rewrite this file code to use
1162 extract_insn instead of less expensive insn_extract. */
1163 recog_data
.insn
= insn
;
1164 for (i
= 0; i
< n
; i
++)
1166 which_alternative
= i
;
1167 bp
[i
] = get_attr_enabled (insn
);
1171 if (GET_CODE (PATTERN (insn
)) == CLOBBER
|| GET_CODE (PATTERN (insn
)) == USE
)
1172 insn_static_data
->hard_regs
= NULL
;
1174 insn_static_data
->hard_regs
1175 = collect_non_operand_hard_regs (&PATTERN (insn
), data
,
1176 NULL
, OP_IN
, false);
1177 setup_operand_alternative (data
);
1178 data
->arg_hard_regs
= NULL
;
1182 int n_hard_regs
, regno
, arg_hard_regs
[FIRST_PSEUDO_REGISTER
];
1185 /* Finding implicit hard register usage. We believe it will be
1186 not changed whatever transformations are used. Call insns
1187 are such example. */
1188 for (link
= CALL_INSN_FUNCTION_USAGE (insn
);
1190 link
= XEXP (link
, 1))
1191 if (GET_CODE (XEXP (link
, 0)) == USE
1192 && REG_P (XEXP (XEXP (link
, 0), 0)))
1194 regno
= REGNO (XEXP (XEXP (link
, 0), 0));
1195 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
1196 /* It is an argument register. */
1197 for (i
= (hard_regno_nregs
1198 [regno
][GET_MODE (XEXP (XEXP (link
, 0), 0))]) - 1;
1201 arg_hard_regs
[n_hard_regs
++] = regno
+ i
;
1203 if (n_hard_regs
!= 0)
1205 arg_hard_regs
[n_hard_regs
++] = -1;
1206 data
->arg_hard_regs
= XNEWVEC (int, n_hard_regs
);
1207 memcpy (data
->arg_hard_regs
, arg_hard_regs
,
1208 sizeof (int) * n_hard_regs
);
1211 /* Some output operand can be recognized only from the context not
1212 from the constraints which are empty in this case. Call insn may
1213 contain a hard register in set destination with empty constraint
1214 and extract_insn treats them as an input. */
1215 for (i
= 0; i
< insn_static_data
->n_operands
; i
++)
1219 struct lra_operand_data
*operand
= &insn_static_data
->operand
[i
];
1221 /* ??? Should we treat 'X' the same way. It looks to me that
1222 'X' means anything and empty constraint means we do not
1224 if (operand
->type
!= OP_IN
|| *operand
->constraint
!= '\0'
1225 || operand
->is_operator
)
1227 pat
= PATTERN (insn
);
1228 if (GET_CODE (pat
) == SET
)
1230 if (data
->operand_loc
[i
] != &SET_DEST (pat
))
1233 else if (GET_CODE (pat
) == PARALLEL
)
1235 for (j
= XVECLEN (pat
, 0) - 1; j
>= 0; j
--)
1237 set
= XVECEXP (PATTERN (insn
), 0, j
);
1238 if (GET_CODE (set
) == SET
1239 && &SET_DEST (set
) == data
->operand_loc
[i
])
1247 operand
->type
= OP_OUT
;
1252 /* Return info about insn give by UID. The info should be already set
1254 static lra_insn_recog_data_t
1255 get_insn_recog_data_by_uid (int uid
)
1257 lra_insn_recog_data_t data
;
1259 data
= lra_insn_recog_data
[uid
];
1260 lra_assert (data
!= NULL
);
1264 /* Invalidate all info about insn given by its UID. */
1266 invalidate_insn_recog_data (int uid
)
1268 lra_insn_recog_data_t data
;
1270 data
= lra_insn_recog_data
[uid
];
1271 lra_assert (data
!= NULL
);
1272 free_insn_recog_data (data
);
1273 lra_insn_recog_data
[uid
] = NULL
;
1276 /* Update all the insn info about INSN. It is usually called when
1277 something in the insn was changed. Return the updated info. */
1278 lra_insn_recog_data_t
1279 lra_update_insn_recog_data (rtx insn
)
1281 lra_insn_recog_data_t data
;
1283 unsigned int uid
= INSN_UID (insn
);
1284 struct lra_static_insn_data
*insn_static_data
;
1285 HOST_WIDE_INT sp_offset
= 0;
1287 check_and_expand_insn_recog_data (uid
);
1288 if ((data
= lra_insn_recog_data
[uid
]) != NULL
1289 && data
->icode
!= INSN_CODE (insn
))
1291 sp_offset
= data
->sp_offset
;
1292 invalidate_insn_data_regno_info (data
, insn
, get_insn_freq (insn
));
1293 invalidate_insn_recog_data (uid
);
1298 data
= lra_get_insn_recog_data (insn
);
1299 /* Initiate or restore SP offset. */
1300 data
->sp_offset
= sp_offset
;
1303 insn_static_data
= data
->insn_static_data
;
1304 data
->used_insn_alternative
= -1;
1305 if (DEBUG_INSN_P (insn
))
1307 if (data
->icode
< 0)
1310 enum machine_mode operand_mode
[MAX_RECOG_OPERANDS
];
1311 const char *constraints
[MAX_RECOG_OPERANDS
];
1313 nop
= asm_noperands (PATTERN (insn
));
1316 lra_assert (nop
== data
->insn_static_data
->n_operands
);
1317 /* Now get the operand values and constraints out of the
1319 decode_asm_operands (PATTERN (insn
), NULL
,
1321 constraints
, operand_mode
, NULL
);
1322 #ifdef ENABLE_CHECKING
1326 for (i
= 0; i
< nop
; i
++)
1328 (insn_static_data
->operand
[i
].mode
== operand_mode
[i
]
1329 && insn_static_data
->operand
[i
].constraint
== constraints
[i
]
1330 && ! insn_static_data
->operand
[i
].is_operator
);
1334 #ifdef ENABLE_CHECKING
1338 for (i
= 0; i
< insn_static_data
->n_operands
; i
++)
1340 (insn_static_data
->operand
[i
].type
1341 == (insn_static_data
->operand
[i
].constraint
[0] == '=' ? OP_OUT
1342 : insn_static_data
->operand
[i
].constraint
[0] == '+' ? OP_INOUT
1349 insn_extract (insn
);
1350 n
= insn_static_data
->n_operands
;
1352 memcpy (data
->operand_loc
, recog_data
.operand_loc
, n
* sizeof (rtx
*));
1353 n
= insn_static_data
->n_dups
;
1355 memcpy (data
->dup_loc
, recog_data
.dup_loc
, n
* sizeof (rtx
*));
1356 #if HAVE_ATTR_enabled
1357 #ifdef ENABLE_CHECKING
1362 n
= insn_static_data
->n_alternatives
;
1363 bp
= data
->alternative_enabled_p
;
1364 lra_assert (n
>= 0 && bp
!= NULL
);
1365 /* Cache the insn to prevent extract_insn call from
1366 get_attr_enabled. */
1367 recog_data
.insn
= insn
;
1368 for (i
= 0; i
< n
; i
++)
1370 which_alternative
= i
;
1371 lra_assert (bp
[i
] == get_attr_enabled (insn
));
1380 /* Set up that INSN is using alternative ALT now. */
1382 lra_set_used_insn_alternative (rtx insn
, int alt
)
1384 lra_insn_recog_data_t data
;
1386 data
= lra_get_insn_recog_data (insn
);
1387 data
->used_insn_alternative
= alt
;
1390 /* Set up that insn with UID is using alternative ALT now. The insn
1391 info should be already set up. */
1393 lra_set_used_insn_alternative_by_uid (int uid
, int alt
)
1395 lra_insn_recog_data_t data
;
1397 check_and_expand_insn_recog_data (uid
);
1398 data
= lra_insn_recog_data
[uid
];
1399 lra_assert (data
!= NULL
);
1400 data
->used_insn_alternative
= alt
;
1405 /* This page contains code dealing with common register info and
1408 /* The size of the following array. */
1409 static int reg_info_size
;
1410 /* Common info about each register. */
1411 struct lra_reg
*lra_reg_info
;
1413 /* Last register value. */
1414 static int last_reg_value
;
1416 /* Return new register value. */
1418 get_new_reg_value (void)
1420 return ++last_reg_value
;
1423 /* Pools for copies. */
1424 static alloc_pool copy_pool
;
1426 /* Vec referring to pseudo copies. */
1427 static vec
<lra_copy_t
> copy_vec
;
1429 /* Initialize I-th element of lra_reg_info. */
1431 initialize_lra_reg_info_element (int i
)
1433 bitmap_initialize (&lra_reg_info
[i
].insn_bitmap
, ®_obstack
);
1435 lra_reg_info
[i
].no_stack_p
= false;
1437 CLEAR_HARD_REG_SET (lra_reg_info
[i
].conflict_hard_regs
);
1438 lra_reg_info
[i
].preferred_hard_regno1
= -1;
1439 lra_reg_info
[i
].preferred_hard_regno2
= -1;
1440 lra_reg_info
[i
].preferred_hard_regno_profit1
= 0;
1441 lra_reg_info
[i
].preferred_hard_regno_profit2
= 0;
1442 lra_reg_info
[i
].biggest_mode
= VOIDmode
;
1443 lra_reg_info
[i
].live_ranges
= NULL
;
1444 lra_reg_info
[i
].nrefs
= lra_reg_info
[i
].freq
= 0;
1445 lra_reg_info
[i
].last_reload
= 0;
1446 lra_reg_info
[i
].restore_regno
= -1;
1447 lra_reg_info
[i
].val
= get_new_reg_value ();
1448 lra_reg_info
[i
].offset
= 0;
1449 lra_reg_info
[i
].copies
= NULL
;
1452 /* Initialize common reg info and copies. */
1454 init_reg_info (void)
1459 reg_info_size
= max_reg_num () * 3 / 2 + 1;
1460 lra_reg_info
= XNEWVEC (struct lra_reg
, reg_info_size
);
1461 for (i
= 0; i
< reg_info_size
; i
++)
1462 initialize_lra_reg_info_element (i
);
1464 = create_alloc_pool ("lra copies", sizeof (struct lra_copy
), 100);
1465 copy_vec
.create (100);
1469 /* Finish common reg info and copies. */
1471 finish_reg_info (void)
1475 for (i
= 0; i
< reg_info_size
; i
++)
1476 bitmap_clear (&lra_reg_info
[i
].insn_bitmap
);
1477 free (lra_reg_info
);
1479 free_alloc_pool (copy_pool
);
1480 copy_vec
.release ();
1483 /* Expand common reg info if it is necessary. */
1485 expand_reg_info (void)
1487 int i
, old
= reg_info_size
;
1489 if (reg_info_size
> max_reg_num ())
1491 reg_info_size
= max_reg_num () * 3 / 2 + 1;
1492 lra_reg_info
= XRESIZEVEC (struct lra_reg
, lra_reg_info
, reg_info_size
);
1493 for (i
= old
; i
< reg_info_size
; i
++)
1494 initialize_lra_reg_info_element (i
);
1497 /* Free all copies. */
1499 lra_free_copies (void)
1503 while (copy_vec
.length () != 0)
1505 cp
= copy_vec
.pop ();
1506 lra_reg_info
[cp
->regno1
].copies
= lra_reg_info
[cp
->regno2
].copies
= NULL
;
1507 pool_free (copy_pool
, cp
);
1511 /* Create copy of two pseudos REGNO1 and REGNO2. The copy execution
1512 frequency is FREQ. */
1514 lra_create_copy (int regno1
, int regno2
, int freq
)
1519 lra_assert (regno1
!= regno2
);
1520 regno1_dest_p
= true;
1521 if (regno1
> regno2
)
1525 regno1_dest_p
= false;
1529 cp
= (lra_copy_t
) pool_alloc (copy_pool
);
1530 copy_vec
.safe_push (cp
);
1531 cp
->regno1_dest_p
= regno1_dest_p
;
1533 cp
->regno1
= regno1
;
1534 cp
->regno2
= regno2
;
1535 cp
->regno1_next
= lra_reg_info
[regno1
].copies
;
1536 lra_reg_info
[regno1
].copies
= cp
;
1537 cp
->regno2_next
= lra_reg_info
[regno2
].copies
;
1538 lra_reg_info
[regno2
].copies
= cp
;
1539 if (lra_dump_file
!= NULL
)
1540 fprintf (lra_dump_file
, " Creating copy r%d%sr%d@%d\n",
1541 regno1
, regno1_dest_p
? "<-" : "->", regno2
, freq
);
1544 /* Return N-th (0, 1, ...) copy. If there is no copy, return
1547 lra_get_copy (int n
)
1549 if (n
>= (int) copy_vec
.length ())
1556 /* This page contains code dealing with info about registers in
1559 /* Process X of insn UID recursively and add info (operand type is
1560 given by TYPE, flag of that it is early clobber is EARLY_CLOBBER)
1561 about registers in X to the insn DATA. */
1563 add_regs_to_insn_regno_info (lra_insn_recog_data_t data
, rtx x
, int uid
,
1564 enum op_type type
, bool early_clobber
)
1568 enum machine_mode mode
;
1571 struct lra_insn_reg
*curr
;
1573 code
= GET_CODE (x
);
1574 mode
= GET_MODE (x
);
1576 if (GET_CODE (x
) == SUBREG
)
1579 code
= GET_CODE (x
);
1580 if (GET_MODE_SIZE (mode
) < GET_MODE_SIZE (GET_MODE (x
)))
1582 mode
= GET_MODE (x
);
1583 if (GET_MODE_SIZE (mode
) > REGMODE_NATURAL_SIZE (mode
))
1590 if (regno
< FIRST_PSEUDO_REGISTER
1591 && TEST_HARD_REG_BIT (lra_no_alloc_regs
, regno
)
1592 && ! TEST_HARD_REG_BIT (eliminable_regset
, regno
))
1595 if (bitmap_set_bit (&lra_reg_info
[regno
].insn_bitmap
, uid
))
1597 data
->regs
= new_insn_reg (data
->insn
, regno
, type
, mode
, subreg_p
,
1598 early_clobber
, data
->regs
);
1603 for (curr
= data
->regs
; curr
!= NULL
; curr
= curr
->next
)
1604 if (curr
->regno
== regno
)
1606 if (curr
->subreg_p
!= subreg_p
|| curr
->biggest_mode
!= mode
)
1607 /* The info can not be integrated into the found
1609 data
->regs
= new_insn_reg (data
->insn
, regno
, type
, mode
,
1610 subreg_p
, early_clobber
,
1614 if (curr
->type
!= type
)
1615 curr
->type
= OP_INOUT
;
1616 if (curr
->early_clobber
!= early_clobber
)
1617 curr
->early_clobber
= true;
1628 add_regs_to_insn_regno_info (data
, SET_DEST (x
), uid
, OP_OUT
, false);
1629 add_regs_to_insn_regno_info (data
, SET_SRC (x
), uid
, OP_IN
, false);
1632 /* We treat clobber of non-operand hard registers as early
1633 clobber (the behavior is expected from asm). */
1634 add_regs_to_insn_regno_info (data
, XEXP (x
, 0), uid
, OP_OUT
, true);
1636 case PRE_INC
: case PRE_DEC
: case POST_INC
: case POST_DEC
:
1637 add_regs_to_insn_regno_info (data
, XEXP (x
, 0), uid
, OP_INOUT
, false);
1639 case PRE_MODIFY
: case POST_MODIFY
:
1640 add_regs_to_insn_regno_info (data
, XEXP (x
, 0), uid
, OP_INOUT
, false);
1641 add_regs_to_insn_regno_info (data
, XEXP (x
, 1), uid
, OP_IN
, false);
1644 if ((code
!= PARALLEL
&& code
!= EXPR_LIST
) || type
!= OP_OUT
)
1645 /* Some targets place small structures in registers for return
1646 values of functions, and those registers are wrapped in
1647 PARALLEL that we may see as the destination of a SET. Here
1650 (call_insn 13 12 14 2 (set (parallel:BLK [
1651 (expr_list:REG_DEP_TRUE (reg:DI 0 ax)
1653 (expr_list:REG_DEP_TRUE (reg:DI 1 dx)
1654 (const_int 8 [0x8]))
1656 (call (mem:QI (symbol_ref:DI (... */
1658 fmt
= GET_RTX_FORMAT (code
);
1659 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1662 add_regs_to_insn_regno_info (data
, XEXP (x
, i
), uid
, type
, false);
1663 else if (fmt
[i
] == 'E')
1665 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1666 add_regs_to_insn_regno_info (data
, XVECEXP (x
, i
, j
), uid
,
1673 /* Return execution frequency of INSN. */
1675 get_insn_freq (rtx insn
)
1677 basic_block bb
= BLOCK_FOR_INSN (insn
);
1679 gcc_checking_assert (bb
!= NULL
);
1680 return REG_FREQ_FROM_BB (bb
);
1683 /* Invalidate all reg info of INSN with DATA and execution frequency
1684 FREQ. Update common info about the invalidated registers. */
1686 invalidate_insn_data_regno_info (lra_insn_recog_data_t data
, rtx insn
,
1692 struct lra_insn_reg
*ir
, *next_ir
;
1694 uid
= INSN_UID (insn
);
1695 debug_p
= DEBUG_INSN_P (insn
);
1696 for (ir
= data
->regs
; ir
!= NULL
; ir
= next_ir
)
1701 bitmap_clear_bit (&lra_reg_info
[i
].insn_bitmap
, uid
);
1702 if (i
>= FIRST_PSEUDO_REGISTER
&& ! debug_p
)
1704 lra_reg_info
[i
].nrefs
--;
1705 lra_reg_info
[i
].freq
-= freq
;
1706 lra_assert (lra_reg_info
[i
].nrefs
>= 0 && lra_reg_info
[i
].freq
>= 0);
1712 /* Invalidate all reg info of INSN. Update common info about the
1713 invalidated registers. */
1715 lra_invalidate_insn_regno_info (rtx insn
)
1717 invalidate_insn_data_regno_info (lra_get_insn_recog_data (insn
), insn
,
1718 get_insn_freq (insn
));
1721 /* Update common reg info from reg info of insn given by its DATA and
1722 execution frequency FREQ. */
1724 setup_insn_reg_info (lra_insn_recog_data_t data
, int freq
)
1727 struct lra_insn_reg
*ir
;
1729 for (ir
= data
->regs
; ir
!= NULL
; ir
= ir
->next
)
1730 if ((i
= ir
->regno
) >= FIRST_PSEUDO_REGISTER
)
1732 lra_reg_info
[i
].nrefs
++;
1733 lra_reg_info
[i
].freq
+= freq
;
1737 /* Set up insn reg info of INSN. Update common reg info from reg info
1740 lra_update_insn_regno_info (rtx insn
)
1743 lra_insn_recog_data_t data
;
1744 struct lra_static_insn_data
*static_data
;
1747 if (! INSN_P (insn
))
1749 data
= lra_get_insn_recog_data (insn
);
1750 static_data
= data
->insn_static_data
;
1751 freq
= get_insn_freq (insn
);
1752 invalidate_insn_data_regno_info (data
, insn
, freq
);
1753 uid
= INSN_UID (insn
);
1754 for (i
= static_data
->n_operands
- 1; i
>= 0; i
--)
1755 add_regs_to_insn_regno_info (data
, *data
->operand_loc
[i
], uid
,
1756 static_data
->operand
[i
].type
,
1757 static_data
->operand
[i
].early_clobber
);
1758 if ((code
= GET_CODE (PATTERN (insn
))) == CLOBBER
|| code
== USE
)
1759 add_regs_to_insn_regno_info (data
, XEXP (PATTERN (insn
), 0), uid
,
1760 code
== USE
? OP_IN
: OP_OUT
, false);
1761 if (NONDEBUG_INSN_P (insn
))
1762 setup_insn_reg_info (data
, freq
);
1765 /* Return reg info of insn given by it UID. */
1766 struct lra_insn_reg
*
1767 lra_get_insn_regs (int uid
)
1769 lra_insn_recog_data_t data
;
1771 data
= get_insn_recog_data_by_uid (uid
);
1777 /* This page contains code dealing with stack of the insns which
1778 should be processed by the next constraint pass. */
1780 /* Bitmap used to put an insn on the stack only in one exemplar. */
1781 static sbitmap lra_constraint_insn_stack_bitmap
;
1783 /* The stack itself. */
1784 vec
<rtx
> lra_constraint_insn_stack
;
1786 /* Put INSN on the stack. If ALWAYS_UPDATE is true, always update the reg
1787 info for INSN, otherwise only update it if INSN is not already on the
1790 lra_push_insn_1 (rtx insn
, bool always_update
)
1792 unsigned int uid
= INSN_UID (insn
);
1794 lra_update_insn_regno_info (insn
);
1795 if (uid
>= SBITMAP_SIZE (lra_constraint_insn_stack_bitmap
))
1796 lra_constraint_insn_stack_bitmap
=
1797 sbitmap_resize (lra_constraint_insn_stack_bitmap
, 3 * uid
/ 2, 0);
1798 if (bitmap_bit_p (lra_constraint_insn_stack_bitmap
, uid
))
1800 bitmap_set_bit (lra_constraint_insn_stack_bitmap
, uid
);
1801 if (! always_update
)
1802 lra_update_insn_regno_info (insn
);
1803 lra_constraint_insn_stack
.safe_push (insn
);
1806 /* Put INSN on the stack. */
1808 lra_push_insn (rtx insn
)
1810 lra_push_insn_1 (insn
, false);
1813 /* Put INSN on the stack and update its reg info. */
1815 lra_push_insn_and_update_insn_regno_info (rtx insn
)
1817 lra_push_insn_1 (insn
, true);
1820 /* Put insn with UID on the stack. */
1822 lra_push_insn_by_uid (unsigned int uid
)
1824 lra_push_insn (lra_insn_recog_data
[uid
]->insn
);
1827 /* Take the last-inserted insns off the stack and return it. */
1831 rtx insn
= lra_constraint_insn_stack
.pop ();
1832 bitmap_clear_bit (lra_constraint_insn_stack_bitmap
, INSN_UID (insn
));
1836 /* Return the current size of the insn stack. */
1838 lra_insn_stack_length (void)
1840 return lra_constraint_insn_stack
.length ();
1843 /* Push insns FROM to TO (excluding it) going in reverse order. */
1845 push_insns (rtx from
, rtx to
)
1849 if (from
== NULL_RTX
)
1851 for (insn
= from
; insn
!= to
; insn
= PREV_INSN (insn
))
1853 lra_push_insn (insn
);
1856 /* Set up sp offset for insn in range [FROM, LAST]. The offset is
1857 taken from the next BB insn after LAST or zero if there in such
1860 setup_sp_offset (rtx from
, rtx last
)
1862 rtx before
= next_nonnote_insn_bb (last
);
1863 HOST_WIDE_INT offset
= (before
== NULL_RTX
|| ! INSN_P (before
)
1864 ? 0 : lra_get_insn_recog_data (before
)->sp_offset
);
1866 for (rtx insn
= from
; insn
!= NEXT_INSN (last
); insn
= NEXT_INSN (insn
))
1867 lra_get_insn_recog_data (insn
)->sp_offset
= offset
;
1870 /* Emit insns BEFORE before INSN and insns AFTER after INSN. Put the
1871 insns onto the stack. Print about emitting the insns with
1874 lra_process_new_insns (rtx insn
, rtx before
, rtx after
, const char *title
)
1878 if (before
== NULL_RTX
&& after
== NULL_RTX
)
1880 if (lra_dump_file
!= NULL
)
1882 dump_insn_slim (lra_dump_file
, insn
);
1883 if (before
!= NULL_RTX
)
1885 fprintf (lra_dump_file
," %s before:\n", title
);
1886 dump_rtl_slim (lra_dump_file
, before
, NULL_RTX
, -1, 0);
1888 if (after
!= NULL_RTX
)
1890 fprintf (lra_dump_file
, " %s after:\n", title
);
1891 dump_rtl_slim (lra_dump_file
, after
, NULL_RTX
, -1, 0);
1893 fprintf (lra_dump_file
, "\n");
1895 if (before
!= NULL_RTX
)
1897 emit_insn_before (before
, insn
);
1898 push_insns (PREV_INSN (insn
), PREV_INSN (before
));
1899 setup_sp_offset (before
, PREV_INSN (insn
));
1901 if (after
!= NULL_RTX
)
1903 for (last
= after
; NEXT_INSN (last
) != NULL_RTX
; last
= NEXT_INSN (last
))
1905 emit_insn_after (after
, insn
);
1906 push_insns (last
, insn
);
1907 setup_sp_offset (after
, last
);
1913 /* This page contains code dealing with scratches (changing them onto
1914 pseudos and restoring them from the pseudos).
1916 We change scratches into pseudos at the beginning of LRA to
1917 simplify dealing with them (conflicts, hard register assignments).
1919 If the pseudo denoting scratch was spilled it means that we do need
1920 a hard register for it. Such pseudos are transformed back to
1921 scratches at the end of LRA. */
1923 /* Description of location of a former scratch operand. */
1926 rtx insn
; /* Insn where the scratch was. */
1927 int nop
; /* Number of the operand which was a scratch. */
1930 typedef struct sloc
*sloc_t
;
1932 /* Locations of the former scratches. */
1933 static vec
<sloc_t
> scratches
;
1935 /* Bitmap of scratch regnos. */
1936 static bitmap_head scratch_bitmap
;
1938 /* Bitmap of scratch operands. */
1939 static bitmap_head scratch_operand_bitmap
;
1941 /* Return true if pseudo REGNO is made of SCRATCH. */
1943 lra_former_scratch_p (int regno
)
1945 return bitmap_bit_p (&scratch_bitmap
, regno
);
1948 /* Return true if the operand NOP of INSN is a former scratch. */
1950 lra_former_scratch_operand_p (rtx insn
, int nop
)
1952 return bitmap_bit_p (&scratch_operand_bitmap
,
1953 INSN_UID (insn
) * MAX_RECOG_OPERANDS
+ nop
) != 0;
1956 /* Change scratches onto pseudos and save their location. */
1958 remove_scratches (void)
1961 bool insn_changed_p
;
1965 lra_insn_recog_data_t id
;
1966 struct lra_static_insn_data
*static_id
;
1968 scratches
.create (get_max_uid ());
1969 bitmap_initialize (&scratch_bitmap
, ®_obstack
);
1970 bitmap_initialize (&scratch_operand_bitmap
, ®_obstack
);
1971 FOR_EACH_BB_FN (bb
, cfun
)
1972 FOR_BB_INSNS (bb
, insn
)
1975 id
= lra_get_insn_recog_data (insn
);
1976 static_id
= id
->insn_static_data
;
1977 insn_changed_p
= false;
1978 for (i
= 0; i
< static_id
->n_operands
; i
++)
1979 if (GET_CODE (*id
->operand_loc
[i
]) == SCRATCH
1980 && GET_MODE (*id
->operand_loc
[i
]) != VOIDmode
)
1982 insn_changed_p
= true;
1983 *id
->operand_loc
[i
] = reg
1984 = lra_create_new_reg (static_id
->operand
[i
].mode
,
1985 *id
->operand_loc
[i
], ALL_REGS
, NULL
);
1986 add_reg_note (insn
, REG_UNUSED
, reg
);
1987 lra_update_dup (id
, i
);
1988 loc
= XNEW (struct sloc
);
1991 scratches
.safe_push (loc
);
1992 bitmap_set_bit (&scratch_bitmap
, REGNO (*id
->operand_loc
[i
]));
1993 bitmap_set_bit (&scratch_operand_bitmap
,
1994 INSN_UID (insn
) * MAX_RECOG_OPERANDS
+ i
);
1995 if (lra_dump_file
!= NULL
)
1996 fprintf (lra_dump_file
,
1997 "Removing SCRATCH in insn #%u (nop %d)\n",
1998 INSN_UID (insn
), i
);
2001 /* Because we might use DF right after caller-saves sub-pass
2002 we need to keep DF info up to date. */
2003 df_insn_rescan (insn
);
2007 /* Changes pseudos created by function remove_scratches onto scratches. */
2009 restore_scratches (void)
2014 rtx last
= NULL_RTX
;
2015 lra_insn_recog_data_t id
= NULL
;
2017 for (i
= 0; scratches
.iterate (i
, &loc
); i
++)
2019 if (last
!= loc
->insn
)
2022 id
= lra_get_insn_recog_data (last
);
2024 if (REG_P (*id
->operand_loc
[loc
->nop
])
2025 && ((regno
= REGNO (*id
->operand_loc
[loc
->nop
]))
2026 >= FIRST_PSEUDO_REGISTER
)
2027 && lra_get_regno_hard_regno (regno
) < 0)
2029 /* It should be only case when scratch register with chosen
2030 constraint 'X' did not get memory or hard register. */
2031 lra_assert (lra_former_scratch_p (regno
));
2032 *id
->operand_loc
[loc
->nop
]
2033 = gen_rtx_SCRATCH (GET_MODE (*id
->operand_loc
[loc
->nop
]));
2034 lra_update_dup (id
, loc
->nop
);
2035 if (lra_dump_file
!= NULL
)
2036 fprintf (lra_dump_file
, "Restoring SCRATCH in insn #%u(nop %d)\n",
2037 INSN_UID (loc
->insn
), loc
->nop
);
2040 for (i
= 0; scratches
.iterate (i
, &loc
); i
++)
2042 scratches
.release ();
2043 bitmap_clear (&scratch_bitmap
);
2044 bitmap_clear (&scratch_operand_bitmap
);
2049 #ifdef ENABLE_CHECKING
2051 /* Function checks RTL for correctness. If FINAL_P is true, it is
2052 done at the end of LRA and the check is more rigorous. */
2054 check_rtl (bool final_p
)
2059 lra_assert (! final_p
|| reload_completed
);
2060 FOR_EACH_BB_FN (bb
, cfun
)
2061 FOR_BB_INSNS (bb
, insn
)
2062 if (NONDEBUG_INSN_P (insn
)
2063 && GET_CODE (PATTERN (insn
)) != USE
2064 && GET_CODE (PATTERN (insn
)) != CLOBBER
2065 && GET_CODE (PATTERN (insn
)) != ASM_INPUT
)
2069 extract_insn (insn
);
2070 lra_assert (constrain_operands (1));
2073 /* LRA code is based on assumption that all addresses can be
2074 correctly decomposed. LRA can generate reloads for
2075 decomposable addresses. The decomposition code checks the
2076 correctness of the addresses. So we don't need to check
2077 the addresses here. Don't call insn_invalid_p here, it can
2078 change the code at this stage. */
2079 if (recog_memoized (insn
) < 0 && asm_noperands (PATTERN (insn
)) < 0)
2080 fatal_insn_not_found (insn
);
2083 #endif /* #ifdef ENABLE_CHECKING */
2085 /* Determine if the current function has an exception receiver block
2086 that reaches the exit block via non-exceptional edges */
2088 has_nonexceptional_receiver (void)
2092 basic_block
*tos
, *worklist
, bb
;
2094 /* If we're not optimizing, then just err on the safe side. */
2098 /* First determine which blocks can reach exit via normal paths. */
2099 tos
= worklist
= XNEWVEC (basic_block
, n_basic_blocks_for_fn (cfun
) + 1);
2101 FOR_EACH_BB_FN (bb
, cfun
)
2102 bb
->flags
&= ~BB_REACHABLE
;
2104 /* Place the exit block on our worklist. */
2105 EXIT_BLOCK_PTR_FOR_FN (cfun
)->flags
|= BB_REACHABLE
;
2106 *tos
++ = EXIT_BLOCK_PTR_FOR_FN (cfun
);
2108 /* Iterate: find everything reachable from what we've already seen. */
2109 while (tos
!= worklist
)
2113 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
2114 if (e
->flags
& EDGE_ABNORMAL
)
2121 basic_block src
= e
->src
;
2123 if (!(src
->flags
& BB_REACHABLE
))
2125 src
->flags
|= BB_REACHABLE
;
2131 /* No exceptional block reached exit unexceptionally. */
2137 /* Process recursively X of INSN and add REG_INC notes if necessary. */
2139 add_auto_inc_notes (rtx insn
, rtx x
)
2141 enum rtx_code code
= GET_CODE (x
);
2145 if (code
== MEM
&& auto_inc_p (XEXP (x
, 0)))
2147 add_reg_note (insn
, REG_INC
, XEXP (XEXP (x
, 0), 0));
2151 /* Scan all X sub-expressions. */
2152 fmt
= GET_RTX_FORMAT (code
);
2153 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2156 add_auto_inc_notes (insn
, XEXP (x
, i
));
2157 else if (fmt
[i
] == 'E')
2158 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
2159 add_auto_inc_notes (insn
, XVECEXP (x
, i
, j
));
2165 /* Remove all REG_DEAD and REG_UNUSED notes and regenerate REG_INC.
2166 We change pseudos by hard registers without notification of DF and
2167 that can make the notes obsolete. DF-infrastructure does not deal
2168 with REG_INC notes -- so we should regenerate them here. */
2170 update_inc_notes (void)
2176 FOR_EACH_BB_FN (bb
, cfun
)
2177 FOR_BB_INSNS (bb
, insn
)
2178 if (NONDEBUG_INSN_P (insn
))
2180 pnote
= ®_NOTES (insn
);
2183 if (REG_NOTE_KIND (*pnote
) == REG_DEAD
2184 || REG_NOTE_KIND (*pnote
) == REG_UNUSED
2185 || REG_NOTE_KIND (*pnote
) == REG_INC
)
2186 *pnote
= XEXP (*pnote
, 1);
2188 pnote
= &XEXP (*pnote
, 1);
2191 add_auto_inc_notes (insn
, PATTERN (insn
));
2196 /* Set to 1 while in lra. */
2197 int lra_in_progress
;
2199 /* Start of pseudo regnos before the LRA. */
2200 int lra_new_regno_start
;
2202 /* Start of reload pseudo regnos before the new spill pass. */
2203 int lra_constraint_new_regno_start
;
2205 /* Inheritance pseudo regnos before the new spill pass. */
2206 bitmap_head lra_inheritance_pseudos
;
2208 /* Split regnos before the new spill pass. */
2209 bitmap_head lra_split_regs
;
2211 /* Reload pseudo regnos before the new assignmnet pass which still can
2212 be spilled after the assinment pass as memory is also accepted in
2213 insns for the reload pseudos. */
2214 bitmap_head lra_optional_reload_pseudos
;
2216 /* Pseudo regnos used for subreg reloads before the new assignment
2217 pass. Such pseudos still can be spilled after the assinment
2219 bitmap_head lra_subreg_reload_pseudos
;
2221 /* First UID of insns generated before a new spill pass. */
2222 int lra_constraint_new_insn_uid_start
;
2224 /* File used for output of LRA debug information. */
2225 FILE *lra_dump_file
;
2227 /* True if we should try spill into registers of different classes
2228 instead of memory. */
2229 bool lra_reg_spill_p
;
2231 /* Set up value LRA_REG_SPILL_P. */
2233 setup_reg_spill_flag (void)
2237 if (targetm
.spill_class
!= NULL
)
2238 for (cl
= 0; cl
< (int) LIM_REG_CLASSES
; cl
++)
2239 for (mode
= 0; mode
< MAX_MACHINE_MODE
; mode
++)
2240 if (targetm
.spill_class ((enum reg_class
) cl
,
2241 (enum machine_mode
) mode
) != NO_REGS
)
2243 lra_reg_spill_p
= true;
2246 lra_reg_spill_p
= false;
2249 /* True if the current function is too big to use regular algorithms
2250 in LRA. In other words, we should use simpler and faster algorithms
2251 in LRA. It also means we should not worry about generation code
2252 for caller saves. The value is set up in IRA. */
2255 /* Major LRA entry function. F is a file should be used to dump LRA
2261 bool live_p
, scratch_p
, inserted_p
;
2265 timevar_push (TV_LRA
);
2267 /* Make sure that the last insn is a note. Some subsequent passes
2269 emit_note (NOTE_INSN_DELETED
);
2271 COPY_HARD_REG_SET (lra_no_alloc_regs
, ira_no_alloc_regs
);
2276 init_insn_recog_data ();
2278 #ifdef ENABLE_CHECKING
2279 /* Some quick check on RTL generated by previous passes. */
2283 lra_in_progress
= 1;
2285 lra_live_range_iter
= lra_coalesce_iter
= 0;
2286 lra_constraint_iter
= lra_constraint_iter_after_spill
= 0;
2287 lra_inheritance_iter
= lra_undo_inheritance_iter
= 0;
2289 setup_reg_spill_flag ();
2291 /* Function remove_scratches can creates new pseudos for clobbers --
2292 so set up lra_constraint_new_regno_start before its call to
2293 permit changing reg classes for pseudos created by this
2295 lra_constraint_new_regno_start
= lra_new_regno_start
= max_reg_num ();
2296 remove_scratches ();
2297 scratch_p
= lra_constraint_new_regno_start
!= max_reg_num ();
2299 /* A function that has a non-local label that can reach the exit
2300 block via non-exceptional paths must save all call-saved
2302 if (cfun
->has_nonlocal_label
&& has_nonexceptional_receiver ())
2303 crtl
->saves_all_registers
= 1;
2305 if (crtl
->saves_all_registers
)
2306 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2307 if (! call_used_regs
[i
] && ! fixed_regs
[i
] && ! LOCAL_REGNO (i
))
2308 df_set_regs_ever_live (i
, true);
2310 /* We don't DF from now and avoid its using because it is to
2311 expensive when a lot of RTL changes are made. */
2312 df_set_flags (DF_NO_INSN_RESCAN
);
2313 lra_constraint_insn_stack
.create (get_max_uid ());
2314 lra_constraint_insn_stack_bitmap
= sbitmap_alloc (get_max_uid ());
2315 bitmap_clear (lra_constraint_insn_stack_bitmap
);
2316 lra_live_ranges_init ();
2317 lra_constraints_init ();
2318 lra_curr_reload_num
= 0;
2319 push_insns (get_last_insn (), NULL_RTX
);
2320 /* It is needed for the 1st coalescing. */
2321 lra_constraint_new_insn_uid_start
= get_max_uid ();
2322 bitmap_initialize (&lra_inheritance_pseudos
, ®_obstack
);
2323 bitmap_initialize (&lra_split_regs
, ®_obstack
);
2324 bitmap_initialize (&lra_optional_reload_pseudos
, ®_obstack
);
2325 bitmap_initialize (&lra_subreg_reload_pseudos
, ®_obstack
);
2327 if (get_frame_size () != 0 && crtl
->stack_alignment_needed
)
2328 /* If we have a stack frame, we must align it now. The stack size
2329 may be a part of the offset computation for register
2331 assign_stack_local (BLKmode
, 0, crtl
->stack_alignment_needed
);
2337 /* We should try to assign hard registers to scratches even
2338 if there were no RTL transformations in
2340 if (! lra_constraints (lra_constraint_iter
== 0)
2341 && (lra_constraint_iter
> 1
2342 || (! scratch_p
&& ! caller_save_needed
)))
2344 /* Constraint transformations may result in that eliminable
2345 hard regs become uneliminable and pseudos which use them
2346 should be spilled. It is better to do it before pseudo
2349 For example, rs6000 can make
2350 RS6000_PIC_OFFSET_TABLE_REGNUM uneliminable if we started
2351 to use a constant pool. */
2352 lra_eliminate (false, false);
2353 /* Do inheritance only for regular algorithms. */
2357 lra_clear_live_ranges ();
2358 /* We need live ranges for lra_assign -- so build them. */
2359 lra_create_live_ranges (true);
2361 /* If we don't spill non-reload and non-inheritance pseudos,
2362 there is no sense to run memory-memory move coalescing.
2363 If inheritance pseudos were spilled, the memory-memory
2364 moves involving them will be removed by pass undoing
2370 bool spill_p
= !lra_assign ();
2372 if (lra_undo_inheritance ())
2378 lra_create_live_ranges (true);
2381 if (lra_coalesce ())
2385 lra_clear_live_ranges ();
2388 /* Don't clear optional reloads bitmap until all constraints are
2389 satisfied as we need to differ them from regular reloads. */
2390 bitmap_clear (&lra_optional_reload_pseudos
);
2391 bitmap_clear (&lra_subreg_reload_pseudos
);
2392 bitmap_clear (&lra_inheritance_pseudos
);
2393 bitmap_clear (&lra_split_regs
);
2394 if (! lra_need_for_spills_p ())
2398 /* We need full live info for spilling pseudos into
2399 registers instead of memory. */
2400 lra_create_live_ranges (lra_reg_spill_p
);
2404 /* Assignment of stack slots changes elimination offsets for
2405 some eliminations. So update the offsets here. */
2406 lra_eliminate (false, false);
2407 lra_constraint_new_regno_start
= max_reg_num ();
2408 lra_constraint_new_insn_uid_start
= get_max_uid ();
2409 lra_constraint_iter_after_spill
= 0;
2411 restore_scratches ();
2412 lra_eliminate (true, false);
2413 lra_final_code_change ();
2414 lra_in_progress
= 0;
2416 lra_clear_live_ranges ();
2417 lra_live_ranges_finish ();
2418 lra_constraints_finish ();
2420 sbitmap_free (lra_constraint_insn_stack_bitmap
);
2421 lra_constraint_insn_stack
.release ();
2422 finish_insn_recog_data ();
2423 regstat_free_n_sets_and_refs ();
2425 reload_completed
= 1;
2426 update_inc_notes ();
2428 inserted_p
= fixup_abnormal_edges ();
2430 /* We've possibly turned single trapping insn into multiple ones. */
2431 if (cfun
->can_throw_non_call_exceptions
)
2434 blocks
= sbitmap_alloc (last_basic_block_for_fn (cfun
));
2435 bitmap_ones (blocks
);
2436 find_many_sub_basic_blocks (blocks
);
2437 sbitmap_free (blocks
);
2441 commit_edge_insertions ();
2443 /* Replacing pseudos with their memory equivalents might have
2444 created shared rtx. Subsequent passes would get confused
2445 by this, so unshare everything here. */
2446 unshare_all_rtl_again (get_insns ());
2448 #ifdef ENABLE_CHECKING
2452 timevar_pop (TV_LRA
);
2455 /* Called once per compiler to initialize LRA data once. */
2457 lra_init_once (void)
2459 init_insn_code_data_once ();
2462 /* Initialize LRA whenever register-related information is changed. */
2466 init_op_alt_data ();
2469 /* Called once per compiler to finish LRA data which are initialize
2472 lra_finish_once (void)
2474 finish_insn_code_data_once ();