Home | History | Annotate | Line # | Download | only in gcc
regrename.cc revision 1.1
      1  1.1  mrg /* Register renaming for the GNU compiler.
      2  1.1  mrg    Copyright (C) 2000-2022 Free Software Foundation, Inc.
      3  1.1  mrg 
      4  1.1  mrg    This file is part of GCC.
      5  1.1  mrg 
      6  1.1  mrg    GCC is free software; you can redistribute it and/or modify it
      7  1.1  mrg    under the terms of the GNU General Public License as published by
      8  1.1  mrg    the Free Software Foundation; either version 3, or (at your option)
      9  1.1  mrg    any later version.
     10  1.1  mrg 
     11  1.1  mrg    GCC is distributed in the hope that it will be useful, but WITHOUT
     12  1.1  mrg    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     13  1.1  mrg    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     14  1.1  mrg    License for more details.
     15  1.1  mrg 
     16  1.1  mrg    You should have received a copy of the GNU General Public License
     17  1.1  mrg    along with GCC; see the file COPYING3.  If not see
     18  1.1  mrg    <http://www.gnu.org/licenses/>.  */
     19  1.1  mrg 
     20  1.1  mrg #include "config.h"
     21  1.1  mrg #include "system.h"
     22  1.1  mrg #include "coretypes.h"
     23  1.1  mrg #include "backend.h"
     24  1.1  mrg #include "target.h"
     25  1.1  mrg #include "rtl.h"
     26  1.1  mrg #include "df.h"
     27  1.1  mrg #include "memmodel.h"
     28  1.1  mrg #include "tm_p.h"
     29  1.1  mrg #include "insn-config.h"
     30  1.1  mrg #include "regs.h"
     31  1.1  mrg #include "emit-rtl.h"
     32  1.1  mrg #include "recog.h"
     33  1.1  mrg #include "addresses.h"
     34  1.1  mrg #include "cfganal.h"
     35  1.1  mrg #include "tree-pass.h"
     36  1.1  mrg #include "function-abi.h"
     37  1.1  mrg #include "regrename.h"
     38  1.1  mrg 
     39  1.1  mrg /* This file implements the RTL register renaming pass of the compiler.  It is
     40  1.1  mrg    a semi-local pass whose goal is to maximize the usage of the register file
     41  1.1  mrg    of the processor by substituting registers for others in the solution given
     42  1.1  mrg    by the register allocator.  The algorithm is as follows:
     43  1.1  mrg 
     44  1.1  mrg      1. Local def/use chains are built: within each basic block, chains are
     45  1.1  mrg 	opened and closed; if a chain isn't closed at the end of the block,
     46  1.1  mrg 	it is dropped.  We pre-open chains if we have already examined a
     47  1.1  mrg 	predecessor block and found chains live at the end which match
     48  1.1  mrg 	live registers at the start of the new block.
     49  1.1  mrg 
     50  1.1  mrg      2. We try to combine the local chains across basic block boundaries by
     51  1.1  mrg         comparing chains that were open at the start or end of a block to
     52  1.1  mrg 	those in successor/predecessor blocks.
     53  1.1  mrg 
     54  1.1  mrg      3. For each chain, the set of possible renaming registers is computed.
     55  1.1  mrg 	This takes into account the renaming of previously processed chains.
     56  1.1  mrg 	Optionally, a preferred class is computed for the renaming register.
     57  1.1  mrg 
     58  1.1  mrg      4. The best renaming register is computed for the chain in the above set,
     59  1.1  mrg 	using a round-robin allocation.  If a preferred class exists, then the
     60  1.1  mrg 	round-robin allocation is done within the class first, if possible.
     61  1.1  mrg 	The round-robin allocation of renaming registers itself is global.
     62  1.1  mrg 
     63  1.1  mrg      5. If a renaming register has been found, it is substituted in the chain.
     64  1.1  mrg 
     65  1.1  mrg   Targets can parameterize the pass by specifying a preferred class for the
     66  1.1  mrg   renaming register for a given (super)class of registers to be renamed.
     67  1.1  mrg 
     68  1.1  mrg   DEBUG_INSNs are treated specially, in particular registers occurring inside
     69  1.1  mrg   them are treated as requiring ALL_REGS as a class.  */
     70  1.1  mrg 
     71  1.1  mrg #if HOST_BITS_PER_WIDE_INT <= MAX_RECOG_OPERANDS
     72  1.1  mrg #error "Use a different bitmap implementation for untracked_operands."
     73  1.1  mrg #endif
     74  1.1  mrg 
     75  1.1  mrg enum scan_actions
     76  1.1  mrg {
     77  1.1  mrg   terminate_write,
     78  1.1  mrg   terminate_dead,
     79  1.1  mrg   mark_all_read,
     80  1.1  mrg   mark_read,
     81  1.1  mrg   mark_write,
     82  1.1  mrg   /* mark_access is for marking the destination regs in
     83  1.1  mrg      REG_FRAME_RELATED_EXPR notes (as if they were read) so that the
     84  1.1  mrg      note is updated properly.  */
     85  1.1  mrg   mark_access
     86  1.1  mrg };
     87  1.1  mrg 
     88  1.1  mrg static const char * const scan_actions_name[] =
     89  1.1  mrg {
     90  1.1  mrg   "terminate_write",
     91  1.1  mrg   "terminate_dead",
     92  1.1  mrg   "mark_all_read",
     93  1.1  mrg   "mark_read",
     94  1.1  mrg   "mark_write",
     95  1.1  mrg   "mark_access"
     96  1.1  mrg };
     97  1.1  mrg 
     98  1.1  mrg /* TICK and THIS_TICK are used to record the last time we saw each
     99  1.1  mrg    register.  */
    100  1.1  mrg static int tick[FIRST_PSEUDO_REGISTER];
    101  1.1  mrg static int this_tick = 0;
    102  1.1  mrg 
    103  1.1  mrg static struct obstack rename_obstack;
    104  1.1  mrg 
    105  1.1  mrg /* If nonnull, the code calling into the register renamer requested
    106  1.1  mrg    information about insn operands, and we store it here.  */
    107  1.1  mrg vec<insn_rr_info> insn_rr;
    108  1.1  mrg 
    109  1.1  mrg static void scan_rtx (rtx_insn *, rtx *, enum reg_class, enum scan_actions,
    110  1.1  mrg 		      enum op_type);
    111  1.1  mrg static bool build_def_use (basic_block);
    112  1.1  mrg 
    113  1.1  mrg /* The id to be given to the next opened chain.  */
    114  1.1  mrg static unsigned current_id;
    115  1.1  mrg 
    116  1.1  mrg /* A mapping of unique id numbers to chains.  */
    117  1.1  mrg static vec<du_head_p> id_to_chain;
    118  1.1  mrg 
    119  1.1  mrg /* List of currently open chains.  */
    120  1.1  mrg static class du_head *open_chains;
    121  1.1  mrg 
    122  1.1  mrg /* Bitmap of open chains.  The bits set always match the list found in
    123  1.1  mrg    open_chains.  */
    124  1.1  mrg static bitmap_head open_chains_set;
    125  1.1  mrg 
    126  1.1  mrg /* Record the registers being tracked in open_chains.  */
    127  1.1  mrg static HARD_REG_SET live_in_chains;
    128  1.1  mrg 
    129  1.1  mrg /* Record the registers that are live but not tracked.  The intersection
    130  1.1  mrg    between this and live_in_chains is empty.  */
    131  1.1  mrg static HARD_REG_SET live_hard_regs;
    132  1.1  mrg 
    133  1.1  mrg /* Set while scanning RTL if INSN_RR is nonnull, i.e. if the current analysis
    134  1.1  mrg    is for a caller that requires operand data.  Used in
    135  1.1  mrg    record_operand_use.  */
    136  1.1  mrg static operand_rr_info *cur_operand;
    137  1.1  mrg 
    138  1.1  mrg /* Set while scanning RTL if a register dies.  Used to tie chains.  */
    139  1.1  mrg static class du_head *terminated_this_insn;
    140  1.1  mrg 
    141  1.1  mrg /* Return the chain corresponding to id number ID.  Take into account that
    142  1.1  mrg    chains may have been merged.  */
    143  1.1  mrg du_head_p
    144  1.1  mrg regrename_chain_from_id (unsigned int id)
    145  1.1  mrg {
    146  1.1  mrg   du_head_p first_chain = id_to_chain[id];
    147  1.1  mrg   du_head_p chain = first_chain;
    148  1.1  mrg   while (chain->id != id)
    149  1.1  mrg     {
    150  1.1  mrg       id = chain->id;
    151  1.1  mrg       chain = id_to_chain[id];
    152  1.1  mrg     }
    153  1.1  mrg   first_chain->id = id;
    154  1.1  mrg   return chain;
    155  1.1  mrg }
    156  1.1  mrg 
    157  1.1  mrg /* Dump all def/use chains, starting at id FROM.  */
    158  1.1  mrg 
    159  1.1  mrg static void
    160  1.1  mrg dump_def_use_chain (int from)
    161  1.1  mrg {
    162  1.1  mrg   du_head_p head;
    163  1.1  mrg   int i;
    164  1.1  mrg   FOR_EACH_VEC_ELT_FROM (id_to_chain, i, head, from)
    165  1.1  mrg     {
    166  1.1  mrg       struct du_chain *this_du = head->first;
    167  1.1  mrg 
    168  1.1  mrg       fprintf (dump_file, "Register %s (%d):",
    169  1.1  mrg 	       reg_names[head->regno], head->nregs);
    170  1.1  mrg       while (this_du)
    171  1.1  mrg 	{
    172  1.1  mrg 	  fprintf (dump_file, " %d [%s]", INSN_UID (this_du->insn),
    173  1.1  mrg 		   reg_class_names[this_du->cl]);
    174  1.1  mrg 	  this_du = this_du->next_use;
    175  1.1  mrg 	}
    176  1.1  mrg       fprintf (dump_file, "\n");
    177  1.1  mrg       head = head->next_chain;
    178  1.1  mrg     }
    179  1.1  mrg }
    180  1.1  mrg 
    181  1.1  mrg static void
    182  1.1  mrg free_chain_data (void)
    183  1.1  mrg {
    184  1.1  mrg   int i;
    185  1.1  mrg   du_head_p ptr;
    186  1.1  mrg   for (i = 0; id_to_chain.iterate (i, &ptr); i++)
    187  1.1  mrg     bitmap_clear (&ptr->conflicts);
    188  1.1  mrg 
    189  1.1  mrg   id_to_chain.release ();
    190  1.1  mrg }
    191  1.1  mrg 
    192  1.1  mrg /* Walk all chains starting with CHAINS and record that they conflict with
    193  1.1  mrg    another chain whose id is ID.  */
    194  1.1  mrg 
    195  1.1  mrg static void
    196  1.1  mrg mark_conflict (class du_head *chains, unsigned id)
    197  1.1  mrg {
    198  1.1  mrg   while (chains)
    199  1.1  mrg     {
    200  1.1  mrg       bitmap_set_bit (&chains->conflicts, id);
    201  1.1  mrg       chains = chains->next_chain;
    202  1.1  mrg     }
    203  1.1  mrg }
    204  1.1  mrg 
    205  1.1  mrg /* Examine cur_operand, and if it is nonnull, record information about the
    206  1.1  mrg    use THIS_DU which is part of the chain HEAD.  */
    207  1.1  mrg 
    208  1.1  mrg static void
    209  1.1  mrg record_operand_use (class du_head *head, struct du_chain *this_du)
    210  1.1  mrg {
    211  1.1  mrg   if (cur_operand == NULL || cur_operand->failed)
    212  1.1  mrg     return;
    213  1.1  mrg   if (head->cannot_rename)
    214  1.1  mrg     {
    215  1.1  mrg       cur_operand->failed = true;
    216  1.1  mrg       return;
    217  1.1  mrg     }
    218  1.1  mrg   gcc_assert (cur_operand->n_chains < MAX_REGS_PER_ADDRESS);
    219  1.1  mrg   cur_operand->heads[cur_operand->n_chains] = head;
    220  1.1  mrg   cur_operand->chains[cur_operand->n_chains++] = this_du;
    221  1.1  mrg }
    222  1.1  mrg 
    223  1.1  mrg /* Create a new chain for THIS_NREGS registers starting at THIS_REGNO,
    224  1.1  mrg    and record its occurrence in *LOC, which is being written to in INSN.
    225  1.1  mrg    This access requires a register of class CL.  */
    226  1.1  mrg 
    227  1.1  mrg static du_head_p
    228  1.1  mrg create_new_chain (unsigned this_regno, unsigned this_nregs, rtx *loc,
    229  1.1  mrg 		  rtx_insn *insn, enum reg_class cl)
    230  1.1  mrg {
    231  1.1  mrg   class du_head *head = XOBNEW (&rename_obstack, class du_head);
    232  1.1  mrg   struct du_chain *this_du;
    233  1.1  mrg   int nregs;
    234  1.1  mrg 
    235  1.1  mrg   memset ((void *)head, 0, sizeof *head);
    236  1.1  mrg   head->next_chain = open_chains;
    237  1.1  mrg   head->regno = this_regno;
    238  1.1  mrg   head->nregs = this_nregs;
    239  1.1  mrg 
    240  1.1  mrg   id_to_chain.safe_push (head);
    241  1.1  mrg   head->id = current_id++;
    242  1.1  mrg 
    243  1.1  mrg   bitmap_initialize (&head->conflicts, &bitmap_default_obstack);
    244  1.1  mrg   bitmap_copy (&head->conflicts, &open_chains_set);
    245  1.1  mrg   mark_conflict (open_chains, head->id);
    246  1.1  mrg 
    247  1.1  mrg   /* Since we're tracking this as a chain now, remove it from the
    248  1.1  mrg      list of conflicting live hard registers and track it in
    249  1.1  mrg      live_in_chains instead.  */
    250  1.1  mrg   nregs = head->nregs;
    251  1.1  mrg   while (nregs-- > 0)
    252  1.1  mrg     {
    253  1.1  mrg       SET_HARD_REG_BIT (live_in_chains, head->regno + nregs);
    254  1.1  mrg       CLEAR_HARD_REG_BIT (live_hard_regs, head->regno + nregs);
    255  1.1  mrg     }
    256  1.1  mrg 
    257  1.1  mrg   head->hard_conflicts = live_hard_regs;
    258  1.1  mrg   bitmap_set_bit (&open_chains_set, head->id);
    259  1.1  mrg 
    260  1.1  mrg   open_chains = head;
    261  1.1  mrg 
    262  1.1  mrg   if (dump_file)
    263  1.1  mrg     {
    264  1.1  mrg       fprintf (dump_file, "Creating chain %s (%d)",
    265  1.1  mrg 	       reg_names[head->regno], head->id);
    266  1.1  mrg       if (insn != NULL_RTX)
    267  1.1  mrg 	fprintf (dump_file, " at insn %d", INSN_UID (insn));
    268  1.1  mrg       fprintf (dump_file, "\n");
    269  1.1  mrg     }
    270  1.1  mrg 
    271  1.1  mrg   if (insn == NULL_RTX)
    272  1.1  mrg     {
    273  1.1  mrg       head->first = head->last = NULL;
    274  1.1  mrg       return head;
    275  1.1  mrg     }
    276  1.1  mrg 
    277  1.1  mrg   this_du = XOBNEW (&rename_obstack, struct du_chain);
    278  1.1  mrg   head->first = head->last = this_du;
    279  1.1  mrg 
    280  1.1  mrg   this_du->next_use = 0;
    281  1.1  mrg   this_du->loc = loc;
    282  1.1  mrg   this_du->insn = insn;
    283  1.1  mrg   this_du->cl = cl;
    284  1.1  mrg   record_operand_use (head, this_du);
    285  1.1  mrg   return head;
    286  1.1  mrg }
    287  1.1  mrg 
    288  1.1  mrg /* For a def-use chain HEAD, find which registers overlap its lifetime and
    289  1.1  mrg    set the corresponding bits in *PSET.  */
    290  1.1  mrg 
    291  1.1  mrg static void
    292  1.1  mrg merge_overlapping_regs (HARD_REG_SET *pset, class du_head *head)
    293  1.1  mrg {
    294  1.1  mrg   bitmap_iterator bi;
    295  1.1  mrg   unsigned i;
    296  1.1  mrg   *pset |= head->hard_conflicts;
    297  1.1  mrg   EXECUTE_IF_SET_IN_BITMAP (&head->conflicts, 0, i, bi)
    298  1.1  mrg     {
    299  1.1  mrg       du_head_p other = regrename_chain_from_id (i);
    300  1.1  mrg       unsigned j = other->nregs;
    301  1.1  mrg       gcc_assert (other != head);
    302  1.1  mrg       while (j-- > 0)
    303  1.1  mrg 	SET_HARD_REG_BIT (*pset, other->regno + j);
    304  1.1  mrg     }
    305  1.1  mrg }
    306  1.1  mrg 
    307  1.1  mrg /* Return true if (reg:MODE REGNO) would be clobbered by a call covered
    308  1.1  mrg    by THIS_HEAD.  */
    309  1.1  mrg 
    310  1.1  mrg static bool
    311  1.1  mrg call_clobbered_in_chain_p (du_head *this_head, machine_mode mode,
    312  1.1  mrg 			   unsigned int regno)
    313  1.1  mrg {
    314  1.1  mrg   return call_clobbered_in_region_p (this_head->call_abis,
    315  1.1  mrg 				     this_head->call_clobber_mask,
    316  1.1  mrg 				     mode, regno);
    317  1.1  mrg }
    318  1.1  mrg 
    319  1.1  mrg /* Check if NEW_REG can be the candidate register to rename for
    320  1.1  mrg    REG in THIS_HEAD chain.  THIS_UNAVAILABLE is a set of unavailable hard
    321  1.1  mrg    registers.  */
    322  1.1  mrg 
    323  1.1  mrg static bool
    324  1.1  mrg check_new_reg_p (int reg ATTRIBUTE_UNUSED, int new_reg,
    325  1.1  mrg 		 class du_head *this_head, HARD_REG_SET this_unavailable)
    326  1.1  mrg {
    327  1.1  mrg   int nregs = this_head->nregs;
    328  1.1  mrg   int i;
    329  1.1  mrg   struct du_chain *tmp;
    330  1.1  mrg 
    331  1.1  mrg   for (i = nregs - 1; i >= 0; --i)
    332  1.1  mrg     if (TEST_HARD_REG_BIT (this_unavailable, new_reg + i)
    333  1.1  mrg 	|| fixed_regs[new_reg + i]
    334  1.1  mrg 	|| global_regs[new_reg + i]
    335  1.1  mrg 	/* Can't use regs which aren't saved by the prologue.  */
    336  1.1  mrg 	|| (! df_regs_ever_live_p (new_reg + i)
    337  1.1  mrg 	    && ! crtl->abi->clobbers_full_reg_p (new_reg + i))
    338  1.1  mrg #ifdef LEAF_REGISTERS
    339  1.1  mrg 	/* We can't use a non-leaf register if we're in a
    340  1.1  mrg 	   leaf function.  */
    341  1.1  mrg 	|| (crtl->is_leaf
    342  1.1  mrg 	    && !LEAF_REGISTERS[new_reg + i])
    343  1.1  mrg #endif
    344  1.1  mrg 	|| ! HARD_REGNO_RENAME_OK (reg + i, new_reg + i))
    345  1.1  mrg       return false;
    346  1.1  mrg 
    347  1.1  mrg   /* See whether it accepts all modes that occur in
    348  1.1  mrg      definition and uses.  */
    349  1.1  mrg   for (tmp = this_head->first; tmp; tmp = tmp->next_use)
    350  1.1  mrg     {
    351  1.1  mrg       /* Completely ignore DEBUG_INSNs, otherwise we can get
    352  1.1  mrg 	 -fcompare-debug failures.  */
    353  1.1  mrg       if (DEBUG_INSN_P (tmp->insn))
    354  1.1  mrg 	continue;
    355  1.1  mrg 
    356  1.1  mrg       if (!targetm.hard_regno_mode_ok (new_reg, GET_MODE (*tmp->loc))
    357  1.1  mrg 	  || call_clobbered_in_chain_p (this_head, GET_MODE (*tmp->loc),
    358  1.1  mrg 					new_reg))
    359  1.1  mrg 	return false;
    360  1.1  mrg     }
    361  1.1  mrg 
    362  1.1  mrg   return true;
    363  1.1  mrg }
    364  1.1  mrg 
    365  1.1  mrg /* For the chain THIS_HEAD, compute and return the best register to
    366  1.1  mrg    rename to.  SUPER_CLASS is the superunion of register classes in
    367  1.1  mrg    the chain.  UNAVAILABLE is a set of registers that cannot be used.
    368  1.1  mrg    OLD_REG is the register currently used for the chain.  BEST_RENAME
    369  1.1  mrg    controls whether the register chosen must be better than the
    370  1.1  mrg    current one or just respect the given constraint.  */
    371  1.1  mrg 
    372  1.1  mrg int
    373  1.1  mrg find_rename_reg (du_head_p this_head, enum reg_class super_class,
    374  1.1  mrg 		 HARD_REG_SET *unavailable, int old_reg, bool best_rename)
    375  1.1  mrg {
    376  1.1  mrg   bool has_preferred_class;
    377  1.1  mrg   enum reg_class preferred_class;
    378  1.1  mrg   int pass;
    379  1.1  mrg   int best_new_reg = old_reg;
    380  1.1  mrg 
    381  1.1  mrg   /* Mark registers that overlap this chain's lifetime as unavailable.  */
    382  1.1  mrg   merge_overlapping_regs (unavailable, this_head);
    383  1.1  mrg 
    384  1.1  mrg   /* Compute preferred rename class of super union of all the classes
    385  1.1  mrg      in the chain.  */
    386  1.1  mrg   preferred_class
    387  1.1  mrg     = (enum reg_class) targetm.preferred_rename_class (super_class);
    388  1.1  mrg 
    389  1.1  mrg   /* Pick and check the register from the tied chain iff the tied chain
    390  1.1  mrg      is not renamed.  */
    391  1.1  mrg   if (this_head->tied_chain && !this_head->tied_chain->renamed
    392  1.1  mrg       && check_new_reg_p (old_reg, this_head->tied_chain->regno,
    393  1.1  mrg 			  this_head, *unavailable))
    394  1.1  mrg     return this_head->tied_chain->regno;
    395  1.1  mrg 
    396  1.1  mrg   /* If the first non-debug insn is a noop move, then do not rename in this
    397  1.1  mrg      chain as doing so would inhibit removal of the noop move.  */
    398  1.1  mrg   for (struct du_chain *tmp = this_head->first; tmp; tmp = tmp->next_use)
    399  1.1  mrg     if (DEBUG_INSN_P (tmp->insn))
    400  1.1  mrg       continue;
    401  1.1  mrg     else if (noop_move_p (tmp->insn))
    402  1.1  mrg       return best_new_reg;
    403  1.1  mrg     else
    404  1.1  mrg       break;
    405  1.1  mrg 
    406  1.1  mrg   /* If PREFERRED_CLASS is not NO_REGS, we iterate in the first pass
    407  1.1  mrg      over registers that belong to PREFERRED_CLASS and try to find the
    408  1.1  mrg      best register within the class.  If that failed, we iterate in
    409  1.1  mrg      the second pass over registers that don't belong to the class.
    410  1.1  mrg      If PREFERRED_CLASS is NO_REGS, we iterate over all registers in
    411  1.1  mrg      ascending order without any preference.  */
    412  1.1  mrg   has_preferred_class = (preferred_class != NO_REGS);
    413  1.1  mrg   for (pass = (has_preferred_class ? 0 : 1); pass < 2; pass++)
    414  1.1  mrg     {
    415  1.1  mrg       int new_reg;
    416  1.1  mrg       for (new_reg = 0; new_reg < FIRST_PSEUDO_REGISTER; new_reg++)
    417  1.1  mrg 	{
    418  1.1  mrg 	  if (has_preferred_class
    419  1.1  mrg 	      && (pass == 0)
    420  1.1  mrg 	      != TEST_HARD_REG_BIT (reg_class_contents[preferred_class],
    421  1.1  mrg 				    new_reg))
    422  1.1  mrg 	    continue;
    423  1.1  mrg 
    424  1.1  mrg 	  if (!check_new_reg_p (old_reg, new_reg, this_head, *unavailable))
    425  1.1  mrg 	    continue;
    426  1.1  mrg 
    427  1.1  mrg 	  if (!best_rename)
    428  1.1  mrg 	    return new_reg;
    429  1.1  mrg 
    430  1.1  mrg 	  /* In the first pass, we force the renaming of registers that
    431  1.1  mrg 	     don't belong to PREFERRED_CLASS to registers that do, even
    432  1.1  mrg 	     though the latters were used not very long ago.  */
    433  1.1  mrg 	  if ((pass == 0
    434  1.1  mrg 	      && !TEST_HARD_REG_BIT (reg_class_contents[preferred_class],
    435  1.1  mrg 				     best_new_reg))
    436  1.1  mrg 	      || tick[best_new_reg] > tick[new_reg])
    437  1.1  mrg 	    best_new_reg = new_reg;
    438  1.1  mrg 	}
    439  1.1  mrg       if (pass == 0 && best_new_reg != old_reg)
    440  1.1  mrg 	break;
    441  1.1  mrg     }
    442  1.1  mrg   return best_new_reg;
    443  1.1  mrg }
    444  1.1  mrg 
    445  1.1  mrg /* Iterate over elements in the chain HEAD in order to:
    446  1.1  mrg    1. Count number of uses, storing it in *PN_USES.
    447  1.1  mrg    2. Narrow the set of registers we can use for renaming, adding
    448  1.1  mrg       unavailable registers to *PUNAVAILABLE, which must be
    449  1.1  mrg       initialized by the caller.
    450  1.1  mrg    3. Compute the superunion of register classes in this chain
    451  1.1  mrg       and return it.  */
    452  1.1  mrg reg_class
    453  1.1  mrg regrename_find_superclass (du_head_p head, int *pn_uses,
    454  1.1  mrg 			   HARD_REG_SET *punavailable)
    455  1.1  mrg {
    456  1.1  mrg   int n_uses = 0;
    457  1.1  mrg   reg_class super_class = NO_REGS;
    458  1.1  mrg   for (du_chain *tmp = head->first; tmp; tmp = tmp->next_use)
    459  1.1  mrg     {
    460  1.1  mrg       if (DEBUG_INSN_P (tmp->insn))
    461  1.1  mrg 	continue;
    462  1.1  mrg       n_uses++;
    463  1.1  mrg       *punavailable |= ~reg_class_contents[tmp->cl];
    464  1.1  mrg       super_class
    465  1.1  mrg 	= reg_class_superunion[(int) super_class][(int) tmp->cl];
    466  1.1  mrg     }
    467  1.1  mrg   *pn_uses = n_uses;
    468  1.1  mrg   return super_class;
    469  1.1  mrg }
    470  1.1  mrg 
    471  1.1  mrg /* Perform register renaming on the current function.  */
    472  1.1  mrg static void
    473  1.1  mrg rename_chains (void)
    474  1.1  mrg {
    475  1.1  mrg   HARD_REG_SET unavailable;
    476  1.1  mrg   du_head_p this_head;
    477  1.1  mrg   int i;
    478  1.1  mrg 
    479  1.1  mrg   memset (tick, 0, sizeof tick);
    480  1.1  mrg 
    481  1.1  mrg   CLEAR_HARD_REG_SET (unavailable);
    482  1.1  mrg   /* Don't clobber traceback for noreturn functions.  */
    483  1.1  mrg   if (frame_pointer_needed)
    484  1.1  mrg     {
    485  1.1  mrg       add_to_hard_reg_set (&unavailable, Pmode, FRAME_POINTER_REGNUM);
    486  1.1  mrg       if (!HARD_FRAME_POINTER_IS_FRAME_POINTER)
    487  1.1  mrg 	add_to_hard_reg_set (&unavailable, Pmode, HARD_FRAME_POINTER_REGNUM);
    488  1.1  mrg     }
    489  1.1  mrg 
    490  1.1  mrg   FOR_EACH_VEC_ELT (id_to_chain, i, this_head)
    491  1.1  mrg     {
    492  1.1  mrg       int best_new_reg;
    493  1.1  mrg       int n_uses;
    494  1.1  mrg       HARD_REG_SET this_unavailable;
    495  1.1  mrg       int reg = this_head->regno;
    496  1.1  mrg 
    497  1.1  mrg       if (this_head->cannot_rename)
    498  1.1  mrg 	continue;
    499  1.1  mrg 
    500  1.1  mrg       if (fixed_regs[reg] || global_regs[reg]
    501  1.1  mrg 	  || (!HARD_FRAME_POINTER_IS_FRAME_POINTER && frame_pointer_needed
    502  1.1  mrg 	      && reg == HARD_FRAME_POINTER_REGNUM)
    503  1.1  mrg 	  || (HARD_FRAME_POINTER_IS_FRAME_POINTER && frame_pointer_needed
    504  1.1  mrg 	      && reg == FRAME_POINTER_REGNUM))
    505  1.1  mrg 	continue;
    506  1.1  mrg 
    507  1.1  mrg       this_unavailable = unavailable;
    508  1.1  mrg 
    509  1.1  mrg       reg_class super_class = regrename_find_superclass (this_head, &n_uses,
    510  1.1  mrg 							 &this_unavailable);
    511  1.1  mrg       if (n_uses < 2)
    512  1.1  mrg 	continue;
    513  1.1  mrg 
    514  1.1  mrg       best_new_reg = find_rename_reg (this_head, super_class,
    515  1.1  mrg 				      &this_unavailable, reg, true);
    516  1.1  mrg 
    517  1.1  mrg       if (dump_file)
    518  1.1  mrg 	{
    519  1.1  mrg 	  fprintf (dump_file, "Register %s in insn %d",
    520  1.1  mrg 		   reg_names[reg], INSN_UID (this_head->first->insn));
    521  1.1  mrg 	  if (this_head->call_abis)
    522  1.1  mrg 	    fprintf (dump_file, " crosses a call");
    523  1.1  mrg 	}
    524  1.1  mrg 
    525  1.1  mrg       if (best_new_reg == reg)
    526  1.1  mrg 	{
    527  1.1  mrg 	  tick[reg] = ++this_tick;
    528  1.1  mrg 	  if (dump_file)
    529  1.1  mrg 	    fprintf (dump_file, "; no available better choice\n");
    530  1.1  mrg 	  continue;
    531  1.1  mrg 	}
    532  1.1  mrg 
    533  1.1  mrg       if (regrename_do_replace (this_head, best_new_reg))
    534  1.1  mrg 	{
    535  1.1  mrg 	  if (dump_file)
    536  1.1  mrg 	    fprintf (dump_file, ", renamed as %s\n", reg_names[best_new_reg]);
    537  1.1  mrg 	  tick[best_new_reg] = ++this_tick;
    538  1.1  mrg 	  df_set_regs_ever_live (best_new_reg, true);
    539  1.1  mrg 	}
    540  1.1  mrg       else
    541  1.1  mrg 	{
    542  1.1  mrg 	  if (dump_file)
    543  1.1  mrg 	    fprintf (dump_file, ", renaming as %s failed\n",
    544  1.1  mrg 		     reg_names[best_new_reg]);
    545  1.1  mrg 	  tick[reg] = ++this_tick;
    546  1.1  mrg 	}
    547  1.1  mrg     }
    548  1.1  mrg }
    549  1.1  mrg 
    550  1.1  mrg /* A structure to record information for each hard register at the start of
    551  1.1  mrg    a basic block.  */
    552  1.1  mrg struct incoming_reg_info {
    553  1.1  mrg   /* Holds the number of registers used in the chain that gave us information
    554  1.1  mrg      about this register.  Zero means no information known yet, while a
    555  1.1  mrg      negative value is used for something that is part of, but not the first
    556  1.1  mrg      register in a multi-register value.  */
    557  1.1  mrg   int nregs;
    558  1.1  mrg   /* Set to true if we have accesses that conflict in the number of registers
    559  1.1  mrg      used.  */
    560  1.1  mrg   bool unusable;
    561  1.1  mrg };
    562  1.1  mrg 
    563  1.1  mrg /* A structure recording information about each basic block.  It is saved
    564  1.1  mrg    and restored around basic block boundaries.
    565  1.1  mrg    A pointer to such a structure is stored in each basic block's aux field
    566  1.1  mrg    during regrename_analyze, except for blocks we know can't be optimized
    567  1.1  mrg    (such as entry and exit blocks).  */
    568  1.1  mrg class bb_rename_info
    569  1.1  mrg {
    570  1.1  mrg public:
    571  1.1  mrg   /* The basic block corresponding to this structure.  */
    572  1.1  mrg   basic_block bb;
    573  1.1  mrg   /* Copies of the global information.  */
    574  1.1  mrg   bitmap_head open_chains_set;
    575  1.1  mrg   bitmap_head incoming_open_chains_set;
    576  1.1  mrg   struct incoming_reg_info incoming[FIRST_PSEUDO_REGISTER];
    577  1.1  mrg };
    578  1.1  mrg 
    579  1.1  mrg /* Initialize a rename_info structure P for basic block BB, which starts a new
    580  1.1  mrg    scan.  */
    581  1.1  mrg static void
    582  1.1  mrg init_rename_info (class bb_rename_info *p, basic_block bb)
    583  1.1  mrg {
    584  1.1  mrg   int i;
    585  1.1  mrg   df_ref def;
    586  1.1  mrg   HARD_REG_SET start_chains_set;
    587  1.1  mrg 
    588  1.1  mrg   p->bb = bb;
    589  1.1  mrg   bitmap_initialize (&p->open_chains_set, &bitmap_default_obstack);
    590  1.1  mrg   bitmap_initialize (&p->incoming_open_chains_set, &bitmap_default_obstack);
    591  1.1  mrg 
    592  1.1  mrg   open_chains = NULL;
    593  1.1  mrg   bitmap_clear (&open_chains_set);
    594  1.1  mrg 
    595  1.1  mrg   CLEAR_HARD_REG_SET (live_in_chains);
    596  1.1  mrg   REG_SET_TO_HARD_REG_SET (live_hard_regs, df_get_live_in (bb));
    597  1.1  mrg   FOR_EACH_ARTIFICIAL_DEF (def, bb->index)
    598  1.1  mrg     if (DF_REF_FLAGS (def) & DF_REF_AT_TOP)
    599  1.1  mrg       SET_HARD_REG_BIT (live_hard_regs, DF_REF_REGNO (def));
    600  1.1  mrg 
    601  1.1  mrg   /* Open chains based on information from (at least one) predecessor
    602  1.1  mrg      block.  This gives us a chance later on to combine chains across
    603  1.1  mrg      basic block boundaries.  Inconsistencies (in access sizes) will
    604  1.1  mrg      be caught normally and dealt with conservatively by disabling the
    605  1.1  mrg      chain for renaming, and there is no risk of losing optimization
    606  1.1  mrg      opportunities by opening chains either: if we did not open the
    607  1.1  mrg      chains, we'd have to track the live register as a hard reg, and
    608  1.1  mrg      we'd be unable to rename it in any case.  */
    609  1.1  mrg   CLEAR_HARD_REG_SET (start_chains_set);
    610  1.1  mrg   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    611  1.1  mrg     {
    612  1.1  mrg       struct incoming_reg_info *iri = p->incoming + i;
    613  1.1  mrg       if (iri->nregs > 0 && !iri->unusable
    614  1.1  mrg 	  && range_in_hard_reg_set_p (live_hard_regs, i, iri->nregs))
    615  1.1  mrg 	{
    616  1.1  mrg 	  SET_HARD_REG_BIT (start_chains_set, i);
    617  1.1  mrg 	  remove_range_from_hard_reg_set (&live_hard_regs, i, iri->nregs);
    618  1.1  mrg 	}
    619  1.1  mrg     }
    620  1.1  mrg   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    621  1.1  mrg     {
    622  1.1  mrg       struct incoming_reg_info *iri = p->incoming + i;
    623  1.1  mrg       if (TEST_HARD_REG_BIT (start_chains_set, i))
    624  1.1  mrg 	{
    625  1.1  mrg 	  du_head_p chain;
    626  1.1  mrg 	  if (dump_file)
    627  1.1  mrg 	    fprintf (dump_file, "opening incoming chain\n");
    628  1.1  mrg 	  chain = create_new_chain (i, iri->nregs, NULL, NULL, NO_REGS);
    629  1.1  mrg 	  bitmap_set_bit (&p->incoming_open_chains_set, chain->id);
    630  1.1  mrg 	}
    631  1.1  mrg     }
    632  1.1  mrg }
    633  1.1  mrg 
    634  1.1  mrg /* Record in RI that the block corresponding to it has an incoming
    635  1.1  mrg    live value, described by CHAIN.  */
    636  1.1  mrg static void
    637  1.1  mrg set_incoming_from_chain (class bb_rename_info *ri, du_head_p chain)
    638  1.1  mrg {
    639  1.1  mrg   int i;
    640  1.1  mrg   int incoming_nregs = ri->incoming[chain->regno].nregs;
    641  1.1  mrg   int nregs;
    642  1.1  mrg 
    643  1.1  mrg   /* If we've recorded the same information before, everything is fine.  */
    644  1.1  mrg   if (incoming_nregs == chain->nregs)
    645  1.1  mrg     {
    646  1.1  mrg       if (dump_file)
    647  1.1  mrg 	fprintf (dump_file, "reg %d/%d already recorded\n",
    648  1.1  mrg 		 chain->regno, chain->nregs);
    649  1.1  mrg       return;
    650  1.1  mrg     }
    651  1.1  mrg 
    652  1.1  mrg   /* If we have no information for any of the involved registers, update
    653  1.1  mrg      the incoming array.  */
    654  1.1  mrg   nregs = chain->nregs;
    655  1.1  mrg   while (nregs-- > 0)
    656  1.1  mrg     if (ri->incoming[chain->regno + nregs].nregs != 0
    657  1.1  mrg 	|| ri->incoming[chain->regno + nregs].unusable)
    658  1.1  mrg       break;
    659  1.1  mrg   if (nregs < 0)
    660  1.1  mrg     {
    661  1.1  mrg       nregs = chain->nregs;
    662  1.1  mrg       ri->incoming[chain->regno].nregs = nregs;
    663  1.1  mrg       while (nregs-- > 1)
    664  1.1  mrg 	ri->incoming[chain->regno + nregs].nregs = -nregs;
    665  1.1  mrg       if (dump_file)
    666  1.1  mrg 	fprintf (dump_file, "recorded reg %d/%d\n",
    667  1.1  mrg 		 chain->regno, chain->nregs);
    668  1.1  mrg       return;
    669  1.1  mrg     }
    670  1.1  mrg 
    671  1.1  mrg   /* There must be some kind of conflict.  Prevent both the old and
    672  1.1  mrg      new ranges from being used.  */
    673  1.1  mrg   if (incoming_nregs < 0)
    674  1.1  mrg     ri->incoming[chain->regno + incoming_nregs].unusable = true;
    675  1.1  mrg   for (i = 0; i < chain->nregs; i++)
    676  1.1  mrg     ri->incoming[chain->regno + i].unusable = true;
    677  1.1  mrg }
    678  1.1  mrg 
    679  1.1  mrg /* Merge the two chains C1 and C2 so that all conflict information is
    680  1.1  mrg    recorded and C1, and the id of C2 is changed to that of C1.  */
    681  1.1  mrg static void
    682  1.1  mrg merge_chains (du_head_p c1, du_head_p c2)
    683  1.1  mrg {
    684  1.1  mrg   if (c1 == c2)
    685  1.1  mrg     return;
    686  1.1  mrg 
    687  1.1  mrg   if (c2->first != NULL)
    688  1.1  mrg     {
    689  1.1  mrg       if (c1->first == NULL)
    690  1.1  mrg 	c1->first = c2->first;
    691  1.1  mrg       else
    692  1.1  mrg 	c1->last->next_use = c2->first;
    693  1.1  mrg       c1->last = c2->last;
    694  1.1  mrg     }
    695  1.1  mrg 
    696  1.1  mrg   c2->first = c2->last = NULL;
    697  1.1  mrg   c2->id = c1->id;
    698  1.1  mrg 
    699  1.1  mrg   c1->hard_conflicts |= c2->hard_conflicts;
    700  1.1  mrg   bitmap_ior_into (&c1->conflicts, &c2->conflicts);
    701  1.1  mrg 
    702  1.1  mrg   c1->call_clobber_mask |= c2->call_clobber_mask;
    703  1.1  mrg   c1->call_abis |= c2->call_abis;
    704  1.1  mrg   c1->cannot_rename |= c2->cannot_rename;
    705  1.1  mrg }
    706  1.1  mrg 
    707  1.1  mrg /* Analyze the current function and build chains for renaming.
    708  1.1  mrg    If INCLUDE_ALL_BLOCKS_P is set to true, process all blocks,
    709  1.1  mrg    ignoring BB_DISABLE_SCHEDULE.  The default value is true.  */
    710  1.1  mrg 
    711  1.1  mrg void
    712  1.1  mrg regrename_analyze (bitmap bb_mask, bool include_all_block_p)
    713  1.1  mrg {
    714  1.1  mrg   class bb_rename_info *rename_info;
    715  1.1  mrg   int i;
    716  1.1  mrg   basic_block bb;
    717  1.1  mrg   int n_bbs;
    718  1.1  mrg   int *inverse_postorder;
    719  1.1  mrg 
    720  1.1  mrg   inverse_postorder = XNEWVEC (int, last_basic_block_for_fn (cfun));
    721  1.1  mrg   n_bbs = pre_and_rev_post_order_compute (NULL, inverse_postorder, false);
    722  1.1  mrg 
    723  1.1  mrg   /* Gather some information about the blocks in this function.  */
    724  1.1  mrg   rename_info = XCNEWVEC (class bb_rename_info, n_basic_blocks_for_fn (cfun));
    725  1.1  mrg   i = 0;
    726  1.1  mrg   FOR_EACH_BB_FN (bb, cfun)
    727  1.1  mrg     {
    728  1.1  mrg       class bb_rename_info *ri = rename_info + i;
    729  1.1  mrg       ri->bb = bb;
    730  1.1  mrg       if (bb_mask != NULL && !bitmap_bit_p (bb_mask, bb->index))
    731  1.1  mrg 	bb->aux = NULL;
    732  1.1  mrg       else
    733  1.1  mrg 	bb->aux = ri;
    734  1.1  mrg       i++;
    735  1.1  mrg     }
    736  1.1  mrg 
    737  1.1  mrg   current_id = 0;
    738  1.1  mrg   id_to_chain.create (0);
    739  1.1  mrg   bitmap_initialize (&open_chains_set, &bitmap_default_obstack);
    740  1.1  mrg 
    741  1.1  mrg   /* The order in which we visit blocks ensures that whenever
    742  1.1  mrg      possible, we only process a block after at least one of its
    743  1.1  mrg      predecessors, which provides a "seeding" effect to make the logic
    744  1.1  mrg      in set_incoming_from_chain and init_rename_info useful.  */
    745  1.1  mrg 
    746  1.1  mrg   for (i = 0; i < n_bbs; i++)
    747  1.1  mrg     {
    748  1.1  mrg       basic_block bb1 = BASIC_BLOCK_FOR_FN (cfun, inverse_postorder[i]);
    749  1.1  mrg       class bb_rename_info *this_info;
    750  1.1  mrg       bool success;
    751  1.1  mrg       edge e;
    752  1.1  mrg       edge_iterator ei;
    753  1.1  mrg       int old_length = id_to_chain.length ();
    754  1.1  mrg 
    755  1.1  mrg       this_info = (class bb_rename_info *) bb1->aux;
    756  1.1  mrg       if (this_info == NULL)
    757  1.1  mrg 	continue;
    758  1.1  mrg 
    759  1.1  mrg       if (dump_file)
    760  1.1  mrg 	fprintf (dump_file, "\nprocessing block %d:\n", bb1->index);
    761  1.1  mrg 
    762  1.1  mrg       if (!include_all_block_p && (bb1->flags & BB_DISABLE_SCHEDULE) != 0)
    763  1.1  mrg 	{
    764  1.1  mrg 	  if (dump_file)
    765  1.1  mrg 	    fprintf (dump_file, "avoid disrupting the sms schedule of bb %d\n",
    766  1.1  mrg 		     bb1->index);
    767  1.1  mrg 	  continue;
    768  1.1  mrg 	}
    769  1.1  mrg 
    770  1.1  mrg       init_rename_info (this_info, bb1);
    771  1.1  mrg 
    772  1.1  mrg       success = build_def_use (bb1);
    773  1.1  mrg       if (!success)
    774  1.1  mrg 	{
    775  1.1  mrg 	  if (dump_file)
    776  1.1  mrg 	    fprintf (dump_file, "failed\n");
    777  1.1  mrg 	  bb1->aux = NULL;
    778  1.1  mrg 	  id_to_chain.truncate (old_length);
    779  1.1  mrg 	  current_id = old_length;
    780  1.1  mrg 	  bitmap_clear (&this_info->incoming_open_chains_set);
    781  1.1  mrg 	  open_chains = NULL;
    782  1.1  mrg 	  if (insn_rr.exists ())
    783  1.1  mrg 	    {
    784  1.1  mrg 	      rtx_insn *insn;
    785  1.1  mrg 	      FOR_BB_INSNS (bb1, insn)
    786  1.1  mrg 		{
    787  1.1  mrg 		  insn_rr_info *p = &insn_rr[INSN_UID (insn)];
    788  1.1  mrg 		  p->op_info = NULL;
    789  1.1  mrg 		}
    790  1.1  mrg 	    }
    791  1.1  mrg 	  continue;
    792  1.1  mrg 	}
    793  1.1  mrg 
    794  1.1  mrg       if (dump_file)
    795  1.1  mrg 	dump_def_use_chain (old_length);
    796  1.1  mrg       bitmap_copy (&this_info->open_chains_set, &open_chains_set);
    797  1.1  mrg 
    798  1.1  mrg       /* Add successor blocks to the worklist if necessary, and record
    799  1.1  mrg 	 data about our own open chains at the end of this block, which
    800  1.1  mrg 	 will be used to pre-open chains when processing the successors.  */
    801  1.1  mrg       FOR_EACH_EDGE (e, ei, bb1->succs)
    802  1.1  mrg 	{
    803  1.1  mrg 	  class bb_rename_info *dest_ri;
    804  1.1  mrg 	  class du_head *chain;
    805  1.1  mrg 
    806  1.1  mrg 	  if (dump_file)
    807  1.1  mrg 	    fprintf (dump_file, "successor block %d\n", e->dest->index);
    808  1.1  mrg 
    809  1.1  mrg 	  if (e->flags & (EDGE_EH | EDGE_ABNORMAL))
    810  1.1  mrg 	    continue;
    811  1.1  mrg 	  dest_ri = (class bb_rename_info *)e->dest->aux;
    812  1.1  mrg 	  if (dest_ri == NULL)
    813  1.1  mrg 	    continue;
    814  1.1  mrg 	  for (chain = open_chains; chain; chain = chain->next_chain)
    815  1.1  mrg 	    set_incoming_from_chain (dest_ri, chain);
    816  1.1  mrg 	}
    817  1.1  mrg     }
    818  1.1  mrg 
    819  1.1  mrg   free (inverse_postorder);
    820  1.1  mrg 
    821  1.1  mrg   /* Now, combine the chains data we have gathered across basic block
    822  1.1  mrg      boundaries.
    823  1.1  mrg 
    824  1.1  mrg      For every basic block, there may be chains open at the start, or at the
    825  1.1  mrg      end.  Rather than exclude them from renaming, we look for open chains
    826  1.1  mrg      with matching registers at the other side of the CFG edge.
    827  1.1  mrg 
    828  1.1  mrg      For a given chain using register R, open at the start of block B, we
    829  1.1  mrg      must find an open chain using R on the other side of every edge leading
    830  1.1  mrg      to B, if the register is live across this edge.  In the code below,
    831  1.1  mrg      N_PREDS_USED counts the number of edges where the register is live, and
    832  1.1  mrg      N_PREDS_JOINED counts those where we found an appropriate chain for
    833  1.1  mrg      joining.
    834  1.1  mrg 
    835  1.1  mrg      We perform the analysis for both incoming and outgoing edges, but we
    836  1.1  mrg      only need to merge once (in the second part, after verifying outgoing
    837  1.1  mrg      edges).  */
    838  1.1  mrg   FOR_EACH_BB_FN (bb, cfun)
    839  1.1  mrg     {
    840  1.1  mrg       class bb_rename_info *bb_ri = (class bb_rename_info *) bb->aux;
    841  1.1  mrg       unsigned j;
    842  1.1  mrg       bitmap_iterator bi;
    843  1.1  mrg 
    844  1.1  mrg       if (bb_ri == NULL)
    845  1.1  mrg 	continue;
    846  1.1  mrg 
    847  1.1  mrg       if (dump_file)
    848  1.1  mrg 	fprintf (dump_file, "processing bb %d in edges\n", bb->index);
    849  1.1  mrg 
    850  1.1  mrg       EXECUTE_IF_SET_IN_BITMAP (&bb_ri->incoming_open_chains_set, 0, j, bi)
    851  1.1  mrg 	{
    852  1.1  mrg 	  edge e;
    853  1.1  mrg 	  edge_iterator ei;
    854  1.1  mrg 	  class du_head *chain = regrename_chain_from_id (j);
    855  1.1  mrg 	  int n_preds_used = 0, n_preds_joined = 0;
    856  1.1  mrg 
    857  1.1  mrg 	  FOR_EACH_EDGE (e, ei, bb->preds)
    858  1.1  mrg 	    {
    859  1.1  mrg 	      class bb_rename_info *src_ri;
    860  1.1  mrg 	      unsigned k;
    861  1.1  mrg 	      bitmap_iterator bi2;
    862  1.1  mrg 	      HARD_REG_SET live;
    863  1.1  mrg 	      bool success = false;
    864  1.1  mrg 
    865  1.1  mrg 	      REG_SET_TO_HARD_REG_SET (live, df_get_live_out (e->src));
    866  1.1  mrg 	      if (!range_overlaps_hard_reg_set_p (live, chain->regno,
    867  1.1  mrg 						  chain->nregs))
    868  1.1  mrg 		continue;
    869  1.1  mrg 	      n_preds_used++;
    870  1.1  mrg 
    871  1.1  mrg 	      if (e->flags & (EDGE_EH | EDGE_ABNORMAL))
    872  1.1  mrg 		continue;
    873  1.1  mrg 
    874  1.1  mrg 	      src_ri = (class bb_rename_info *)e->src->aux;
    875  1.1  mrg 	      if (src_ri == NULL)
    876  1.1  mrg 		continue;
    877  1.1  mrg 
    878  1.1  mrg 	      EXECUTE_IF_SET_IN_BITMAP (&src_ri->open_chains_set,
    879  1.1  mrg 					0, k, bi2)
    880  1.1  mrg 		{
    881  1.1  mrg 		  class du_head *outgoing_chain = regrename_chain_from_id (k);
    882  1.1  mrg 
    883  1.1  mrg 		  if (outgoing_chain->regno == chain->regno
    884  1.1  mrg 		      && outgoing_chain->nregs == chain->nregs)
    885  1.1  mrg 		    {
    886  1.1  mrg 		      n_preds_joined++;
    887  1.1  mrg 		      success = true;
    888  1.1  mrg 		      break;
    889  1.1  mrg 		    }
    890  1.1  mrg 		}
    891  1.1  mrg 	      if (!success && dump_file)
    892  1.1  mrg 		fprintf (dump_file, "failure to match with pred block %d\n",
    893  1.1  mrg 			 e->src->index);
    894  1.1  mrg 	    }
    895  1.1  mrg 	  if (n_preds_joined < n_preds_used)
    896  1.1  mrg 	    {
    897  1.1  mrg 	      if (dump_file)
    898  1.1  mrg 		fprintf (dump_file, "cannot rename chain %d\n", j);
    899  1.1  mrg 	      chain->cannot_rename = 1;
    900  1.1  mrg 	    }
    901  1.1  mrg 	}
    902  1.1  mrg     }
    903  1.1  mrg   FOR_EACH_BB_FN (bb, cfun)
    904  1.1  mrg     {
    905  1.1  mrg       class bb_rename_info *bb_ri = (class bb_rename_info *) bb->aux;
    906  1.1  mrg       unsigned j;
    907  1.1  mrg       bitmap_iterator bi;
    908  1.1  mrg 
    909  1.1  mrg       if (bb_ri == NULL)
    910  1.1  mrg 	continue;
    911  1.1  mrg 
    912  1.1  mrg       if (dump_file)
    913  1.1  mrg 	fprintf (dump_file, "processing bb %d out edges\n", bb->index);
    914  1.1  mrg 
    915  1.1  mrg       EXECUTE_IF_SET_IN_BITMAP (&bb_ri->open_chains_set, 0, j, bi)
    916  1.1  mrg 	{
    917  1.1  mrg 	  edge e;
    918  1.1  mrg 	  edge_iterator ei;
    919  1.1  mrg 	  class du_head *chain = regrename_chain_from_id (j);
    920  1.1  mrg 	  int n_succs_used = 0, n_succs_joined = 0;
    921  1.1  mrg 
    922  1.1  mrg 	  FOR_EACH_EDGE (e, ei, bb->succs)
    923  1.1  mrg 	    {
    924  1.1  mrg 	      bool printed = false;
    925  1.1  mrg 	      class bb_rename_info *dest_ri;
    926  1.1  mrg 	      unsigned k;
    927  1.1  mrg 	      bitmap_iterator bi2;
    928  1.1  mrg 	      HARD_REG_SET live;
    929  1.1  mrg 
    930  1.1  mrg 	      REG_SET_TO_HARD_REG_SET (live, df_get_live_in (e->dest));
    931  1.1  mrg 	      if (!range_overlaps_hard_reg_set_p (live, chain->regno,
    932  1.1  mrg 						  chain->nregs))
    933  1.1  mrg 		continue;
    934  1.1  mrg 
    935  1.1  mrg 	      n_succs_used++;
    936  1.1  mrg 
    937  1.1  mrg 	      dest_ri = (class bb_rename_info *)e->dest->aux;
    938  1.1  mrg 	      if (dest_ri == NULL)
    939  1.1  mrg 		continue;
    940  1.1  mrg 
    941  1.1  mrg 	      EXECUTE_IF_SET_IN_BITMAP (&dest_ri->incoming_open_chains_set,
    942  1.1  mrg 					0, k, bi2)
    943  1.1  mrg 		{
    944  1.1  mrg 		  class du_head *incoming_chain = regrename_chain_from_id (k);
    945  1.1  mrg 
    946  1.1  mrg 		  if (incoming_chain->regno == chain->regno
    947  1.1  mrg 		      && incoming_chain->nregs == chain->nregs)
    948  1.1  mrg 		    {
    949  1.1  mrg 		      if (dump_file)
    950  1.1  mrg 			{
    951  1.1  mrg 			  if (!printed)
    952  1.1  mrg 			    fprintf (dump_file,
    953  1.1  mrg 				     "merging blocks for edge %d -> %d\n",
    954  1.1  mrg 				     e->src->index, e->dest->index);
    955  1.1  mrg 			  printed = true;
    956  1.1  mrg 			  fprintf (dump_file,
    957  1.1  mrg 				   "  merging chains %d (->%d) and %d (->%d) [%s]\n",
    958  1.1  mrg 				   k, incoming_chain->id, j, chain->id,
    959  1.1  mrg 				   reg_names[incoming_chain->regno]);
    960  1.1  mrg 			}
    961  1.1  mrg 
    962  1.1  mrg 		      merge_chains (chain, incoming_chain);
    963  1.1  mrg 		      n_succs_joined++;
    964  1.1  mrg 		      break;
    965  1.1  mrg 		    }
    966  1.1  mrg 		}
    967  1.1  mrg 	    }
    968  1.1  mrg 	  if (n_succs_joined < n_succs_used)
    969  1.1  mrg 	    {
    970  1.1  mrg 	      if (dump_file)
    971  1.1  mrg 		fprintf (dump_file, "cannot rename chain %d\n",
    972  1.1  mrg 			 j);
    973  1.1  mrg 	      chain->cannot_rename = 1;
    974  1.1  mrg 	    }
    975  1.1  mrg 	}
    976  1.1  mrg     }
    977  1.1  mrg 
    978  1.1  mrg   free (rename_info);
    979  1.1  mrg 
    980  1.1  mrg   FOR_EACH_BB_FN (bb, cfun)
    981  1.1  mrg     bb->aux = NULL;
    982  1.1  mrg }
    983  1.1  mrg 
    984  1.1  mrg /* Attempt to replace all uses of the register in the chain beginning with
    985  1.1  mrg    HEAD with REG.  Returns true on success and false if the replacement is
    986  1.1  mrg    rejected because the insns would not validate.  The latter can happen
    987  1.1  mrg    e.g. if a match_parallel predicate enforces restrictions on register
    988  1.1  mrg    numbering in its subpatterns.  */
    989  1.1  mrg 
    990  1.1  mrg bool
    991  1.1  mrg regrename_do_replace (class du_head *head, int reg)
    992  1.1  mrg {
    993  1.1  mrg   struct du_chain *chain;
    994  1.1  mrg   unsigned int base_regno = head->regno;
    995  1.1  mrg   machine_mode mode;
    996  1.1  mrg   rtx last_reg = NULL_RTX, last_repl = NULL_RTX;
    997  1.1  mrg 
    998  1.1  mrg   for (chain = head->first; chain; chain = chain->next_use)
    999  1.1  mrg     {
   1000  1.1  mrg       unsigned int regno = ORIGINAL_REGNO (*chain->loc);
   1001  1.1  mrg       class reg_attrs *attr = REG_ATTRS (*chain->loc);
   1002  1.1  mrg       int reg_ptr = REG_POINTER (*chain->loc);
   1003  1.1  mrg 
   1004  1.1  mrg       if (DEBUG_INSN_P (chain->insn) && REGNO (*chain->loc) != base_regno)
   1005  1.1  mrg 	validate_change (chain->insn, &(INSN_VAR_LOCATION_LOC (chain->insn)),
   1006  1.1  mrg 			 gen_rtx_UNKNOWN_VAR_LOC (), true);
   1007  1.1  mrg       else
   1008  1.1  mrg 	{
   1009  1.1  mrg 	  if (*chain->loc != last_reg)
   1010  1.1  mrg 	    {
   1011  1.1  mrg 	      last_repl = gen_raw_REG (GET_MODE (*chain->loc), reg);
   1012  1.1  mrg 	      if (regno >= FIRST_PSEUDO_REGISTER)
   1013  1.1  mrg 		ORIGINAL_REGNO (last_repl) = regno;
   1014  1.1  mrg 	      REG_ATTRS (last_repl) = attr;
   1015  1.1  mrg 	      REG_POINTER (last_repl) = reg_ptr;
   1016  1.1  mrg 	      last_reg = *chain->loc;
   1017  1.1  mrg 	    }
   1018  1.1  mrg 	  validate_change (chain->insn, chain->loc, last_repl, true);
   1019  1.1  mrg 	}
   1020  1.1  mrg     }
   1021  1.1  mrg 
   1022  1.1  mrg   if (!apply_change_group ())
   1023  1.1  mrg     return false;
   1024  1.1  mrg 
   1025  1.1  mrg   mode = GET_MODE (*head->first->loc);
   1026  1.1  mrg   head->renamed = 1;
   1027  1.1  mrg   head->regno = reg;
   1028  1.1  mrg   head->nregs = hard_regno_nregs (reg, mode);
   1029  1.1  mrg   return true;
   1030  1.1  mrg }
   1031  1.1  mrg 
   1032  1.1  mrg 
   1033  1.1  mrg /* True if we found a register with a size mismatch, which means that we
   1034  1.1  mrg    can't track its lifetime accurately.  If so, we abort the current block
   1035  1.1  mrg    without renaming.  */
   1036  1.1  mrg static bool fail_current_block;
   1037  1.1  mrg 
   1038  1.1  mrg /* Return true if OP is a reg for which all bits are set in PSET, false
   1039  1.1  mrg    if all bits are clear.
   1040  1.1  mrg    In other cases, set fail_current_block and return false.  */
   1041  1.1  mrg 
   1042  1.1  mrg static bool
   1043  1.1  mrg verify_reg_in_set (rtx op, HARD_REG_SET *pset)
   1044  1.1  mrg {
   1045  1.1  mrg   unsigned regno, nregs;
   1046  1.1  mrg   bool all_live, all_dead;
   1047  1.1  mrg   if (!REG_P (op))
   1048  1.1  mrg     return false;
   1049  1.1  mrg 
   1050  1.1  mrg   regno = REGNO (op);
   1051  1.1  mrg   nregs = REG_NREGS (op);
   1052  1.1  mrg   all_live = all_dead = true;
   1053  1.1  mrg   while (nregs-- > 0)
   1054  1.1  mrg     if (TEST_HARD_REG_BIT (*pset, regno + nregs))
   1055  1.1  mrg       all_dead = false;
   1056  1.1  mrg     else
   1057  1.1  mrg       all_live = false;
   1058  1.1  mrg   if (!all_dead && !all_live)
   1059  1.1  mrg     {
   1060  1.1  mrg       fail_current_block = true;
   1061  1.1  mrg       return false;
   1062  1.1  mrg     }
   1063  1.1  mrg   return all_live;
   1064  1.1  mrg }
   1065  1.1  mrg 
   1066  1.1  mrg /* Return true if OP is a reg that is being tracked already in some form.
   1067  1.1  mrg    May set fail_current_block if it sees an unhandled case of overlap.  */
   1068  1.1  mrg 
   1069  1.1  mrg static bool
   1070  1.1  mrg verify_reg_tracked (rtx op)
   1071  1.1  mrg {
   1072  1.1  mrg   return (verify_reg_in_set (op, &live_hard_regs)
   1073  1.1  mrg 	  || verify_reg_in_set (op, &live_in_chains));
   1074  1.1  mrg }
   1075  1.1  mrg 
   1076  1.1  mrg /* Called through note_stores.  DATA points to a rtx_code, either SET or
   1077  1.1  mrg    CLOBBER, which tells us which kind of rtx to look at.  If we have a
   1078  1.1  mrg    match, record the set register in live_hard_regs and in the hard_conflicts
   1079  1.1  mrg    bitmap of open chains.  */
   1080  1.1  mrg 
   1081  1.1  mrg static void
   1082  1.1  mrg note_sets_clobbers (rtx x, const_rtx set, void *data)
   1083  1.1  mrg {
   1084  1.1  mrg   enum rtx_code code = *(enum rtx_code *)data;
   1085  1.1  mrg   class du_head *chain;
   1086  1.1  mrg 
   1087  1.1  mrg   if (GET_CODE (x) == SUBREG)
   1088  1.1  mrg     x = SUBREG_REG (x);
   1089  1.1  mrg   if (!REG_P (x) || GET_CODE (set) != code)
   1090  1.1  mrg     return;
   1091  1.1  mrg   /* There must not be pseudos at this point.  */
   1092  1.1  mrg   gcc_assert (HARD_REGISTER_P (x));
   1093  1.1  mrg   add_to_hard_reg_set (&live_hard_regs, GET_MODE (x), REGNO (x));
   1094  1.1  mrg   for (chain = open_chains; chain; chain = chain->next_chain)
   1095  1.1  mrg     add_to_hard_reg_set (&chain->hard_conflicts, GET_MODE (x), REGNO (x));
   1096  1.1  mrg }
   1097  1.1  mrg 
   1098  1.1  mrg static void
   1099  1.1  mrg scan_rtx_reg (rtx_insn *insn, rtx *loc, enum reg_class cl, enum scan_actions action,
   1100  1.1  mrg 	      enum op_type type)
   1101  1.1  mrg {
   1102  1.1  mrg   class du_head **p;
   1103  1.1  mrg   rtx x = *loc;
   1104  1.1  mrg   unsigned this_regno = REGNO (x);
   1105  1.1  mrg   int this_nregs = REG_NREGS (x);
   1106  1.1  mrg 
   1107  1.1  mrg   if (action == mark_write)
   1108  1.1  mrg     {
   1109  1.1  mrg       if (type == OP_OUT)
   1110  1.1  mrg 	{
   1111  1.1  mrg 	  du_head_p c;
   1112  1.1  mrg 	  rtx pat = PATTERN (insn);
   1113  1.1  mrg 
   1114  1.1  mrg 	  c = create_new_chain (this_regno, this_nregs, loc, insn, cl);
   1115  1.1  mrg 
   1116  1.1  mrg 	  /* We try to tie chains in a move instruction for
   1117  1.1  mrg 	     a single output.  */
   1118  1.1  mrg 	  if (recog_data.n_operands == 2
   1119  1.1  mrg 	      && GET_CODE (pat) == SET
   1120  1.1  mrg 	      && GET_CODE (SET_DEST (pat)) == REG
   1121  1.1  mrg 	      && GET_CODE (SET_SRC (pat)) == REG
   1122  1.1  mrg 	      && terminated_this_insn
   1123  1.1  mrg 	      && terminated_this_insn->nregs
   1124  1.1  mrg 		 == REG_NREGS (recog_data.operand[1]))
   1125  1.1  mrg 	    {
   1126  1.1  mrg 	      gcc_assert (terminated_this_insn->regno
   1127  1.1  mrg 			  == REGNO (recog_data.operand[1]));
   1128  1.1  mrg 
   1129  1.1  mrg 	      c->tied_chain = terminated_this_insn;
   1130  1.1  mrg 	      terminated_this_insn->tied_chain = c;
   1131  1.1  mrg 
   1132  1.1  mrg 	      if (dump_file)
   1133  1.1  mrg 		fprintf (dump_file, "Tying chain %s (%d) with %s (%d)\n",
   1134  1.1  mrg 			 reg_names[c->regno], c->id,
   1135  1.1  mrg 			 reg_names[terminated_this_insn->regno],
   1136  1.1  mrg 			 terminated_this_insn->id);
   1137  1.1  mrg 	    }
   1138  1.1  mrg 	}
   1139  1.1  mrg 
   1140  1.1  mrg       return;
   1141  1.1  mrg     }
   1142  1.1  mrg 
   1143  1.1  mrg   if ((type == OP_OUT) != (action == terminate_write || action == mark_access))
   1144  1.1  mrg     return;
   1145  1.1  mrg 
   1146  1.1  mrg   for (p = &open_chains; *p;)
   1147  1.1  mrg     {
   1148  1.1  mrg       class du_head *head = *p;
   1149  1.1  mrg       class du_head *next = head->next_chain;
   1150  1.1  mrg       int exact_match = (head->regno == this_regno
   1151  1.1  mrg 			 && head->nregs == this_nregs);
   1152  1.1  mrg       int superset = (this_regno <= head->regno
   1153  1.1  mrg 		      && this_regno + this_nregs >= head->regno + head->nregs);
   1154  1.1  mrg       int subset = (this_regno >= head->regno
   1155  1.1  mrg 		      && this_regno + this_nregs <= head->regno + head->nregs);
   1156  1.1  mrg 
   1157  1.1  mrg       if (!bitmap_bit_p (&open_chains_set, head->id)
   1158  1.1  mrg 	  || head->regno + head->nregs <= this_regno
   1159  1.1  mrg 	  || this_regno + this_nregs <= head->regno)
   1160  1.1  mrg 	{
   1161  1.1  mrg 	  p = &head->next_chain;
   1162  1.1  mrg 	  continue;
   1163  1.1  mrg 	}
   1164  1.1  mrg 
   1165  1.1  mrg       if (action == mark_read || action == mark_access)
   1166  1.1  mrg 	{
   1167  1.1  mrg 	  /* ??? Class NO_REGS can happen if the md file makes use of
   1168  1.1  mrg 	     EXTRA_CONSTRAINTS to match registers.  Which is arguably
   1169  1.1  mrg 	     wrong, but there we are.  */
   1170  1.1  mrg 
   1171  1.1  mrg 	  if (cl == NO_REGS || (!exact_match && !DEBUG_INSN_P (insn)))
   1172  1.1  mrg 	    {
   1173  1.1  mrg 	      if (dump_file)
   1174  1.1  mrg 		fprintf (dump_file,
   1175  1.1  mrg 			 "Cannot rename chain %s (%d) at insn %d (%s)\n",
   1176  1.1  mrg 			 reg_names[head->regno], head->id, INSN_UID (insn),
   1177  1.1  mrg 			 scan_actions_name[(int) action]);
   1178  1.1  mrg 	      head->cannot_rename = 1;
   1179  1.1  mrg 	      if (superset)
   1180  1.1  mrg 		{
   1181  1.1  mrg 		  unsigned nregs = this_nregs;
   1182  1.1  mrg 		  head->regno = this_regno;
   1183  1.1  mrg 		  head->nregs = this_nregs;
   1184  1.1  mrg 		  while (nregs-- > 0)
   1185  1.1  mrg 		    SET_HARD_REG_BIT (live_in_chains, head->regno + nregs);
   1186  1.1  mrg 		  if (dump_file)
   1187  1.1  mrg 		    fprintf (dump_file,
   1188  1.1  mrg 			     "Widening register in chain %s (%d) at insn %d\n",
   1189  1.1  mrg 			     reg_names[head->regno], head->id, INSN_UID (insn));
   1190  1.1  mrg 		}
   1191  1.1  mrg 	      else if (!subset)
   1192  1.1  mrg 		{
   1193  1.1  mrg 		  fail_current_block = true;
   1194  1.1  mrg 		  if (dump_file)
   1195  1.1  mrg 		    fprintf (dump_file,
   1196  1.1  mrg 			     "Failing basic block due to unhandled overlap\n");
   1197  1.1  mrg 		}
   1198  1.1  mrg 	    }
   1199  1.1  mrg 	  else
   1200  1.1  mrg 	    {
   1201  1.1  mrg 	      struct du_chain *this_du;
   1202  1.1  mrg 	      this_du = XOBNEW (&rename_obstack, struct du_chain);
   1203  1.1  mrg 	      this_du->next_use = 0;
   1204  1.1  mrg 	      this_du->loc = loc;
   1205  1.1  mrg 	      this_du->insn = insn;
   1206  1.1  mrg 	      this_du->cl = cl;
   1207  1.1  mrg 	      if (head->first == NULL)
   1208  1.1  mrg 		head->first = this_du;
   1209  1.1  mrg 	      else
   1210  1.1  mrg 		head->last->next_use = this_du;
   1211  1.1  mrg 	      record_operand_use (head, this_du);
   1212  1.1  mrg 	      head->last = this_du;
   1213  1.1  mrg 	    }
   1214  1.1  mrg 	  /* Avoid adding the same location in a DEBUG_INSN multiple times,
   1215  1.1  mrg 	     which could happen with non-exact overlap.  */
   1216  1.1  mrg 	  if (DEBUG_INSN_P (insn))
   1217  1.1  mrg 	    return;
   1218  1.1  mrg 	  /* Otherwise, find any other chains that do not match exactly;
   1219  1.1  mrg 	     ensure they all get marked unrenamable.  */
   1220  1.1  mrg 	  p = &head->next_chain;
   1221  1.1  mrg 	  continue;
   1222  1.1  mrg 	}
   1223  1.1  mrg 
   1224  1.1  mrg       /* Whether the terminated chain can be used for renaming
   1225  1.1  mrg 	 depends on the action and this being an exact match.
   1226  1.1  mrg 	 In either case, we remove this element from open_chains.  */
   1227  1.1  mrg 
   1228  1.1  mrg       if ((action == terminate_dead || action == terminate_write)
   1229  1.1  mrg 	  && (superset || subset))
   1230  1.1  mrg 	{
   1231  1.1  mrg 	  unsigned nregs;
   1232  1.1  mrg 
   1233  1.1  mrg 	  if (subset && !superset)
   1234  1.1  mrg 	    head->cannot_rename = 1;
   1235  1.1  mrg 	  bitmap_clear_bit (&open_chains_set, head->id);
   1236  1.1  mrg 
   1237  1.1  mrg 	  nregs = head->nregs;
   1238  1.1  mrg 	  while (nregs-- > 0)
   1239  1.1  mrg 	    {
   1240  1.1  mrg 	      CLEAR_HARD_REG_BIT (live_in_chains, head->regno + nregs);
   1241  1.1  mrg 	      if (subset && !superset
   1242  1.1  mrg 		  && (head->regno + nregs < this_regno
   1243  1.1  mrg 		      || head->regno + nregs >= this_regno + this_nregs))
   1244  1.1  mrg 		SET_HARD_REG_BIT (live_hard_regs, head->regno + nregs);
   1245  1.1  mrg 	    }
   1246  1.1  mrg 
   1247  1.1  mrg 	  if (action == terminate_dead)
   1248  1.1  mrg 	    terminated_this_insn = *p;
   1249  1.1  mrg 	  *p = next;
   1250  1.1  mrg 	  if (dump_file)
   1251  1.1  mrg 	    fprintf (dump_file,
   1252  1.1  mrg 		     "Closing chain %s (%d) at insn %d (%s%s)\n",
   1253  1.1  mrg 		     reg_names[head->regno], head->id, INSN_UID (insn),
   1254  1.1  mrg 		     scan_actions_name[(int) action],
   1255  1.1  mrg 		     superset ? ", superset" : subset ? ", subset" : "");
   1256  1.1  mrg 	}
   1257  1.1  mrg       else if (action == terminate_dead || action == terminate_write)
   1258  1.1  mrg 	{
   1259  1.1  mrg 	  /* In this case, tracking liveness gets too hard.  Fail the
   1260  1.1  mrg 	     entire basic block.  */
   1261  1.1  mrg 	  if (dump_file)
   1262  1.1  mrg 	    fprintf (dump_file,
   1263  1.1  mrg 		     "Failing basic block due to unhandled overlap\n");
   1264  1.1  mrg 	  fail_current_block = true;
   1265  1.1  mrg 	  return;
   1266  1.1  mrg 	}
   1267  1.1  mrg       else
   1268  1.1  mrg 	{
   1269  1.1  mrg 	  head->cannot_rename = 1;
   1270  1.1  mrg 	  if (dump_file)
   1271  1.1  mrg 	    fprintf (dump_file,
   1272  1.1  mrg 		     "Cannot rename chain %s (%d) at insn %d (%s)\n",
   1273  1.1  mrg 		     reg_names[head->regno], head->id, INSN_UID (insn),
   1274  1.1  mrg 		     scan_actions_name[(int) action]);
   1275  1.1  mrg 	  p = &head->next_chain;
   1276  1.1  mrg 	}
   1277  1.1  mrg     }
   1278  1.1  mrg }
   1279  1.1  mrg 
   1280  1.1  mrg /* A wrapper around base_reg_class which returns ALL_REGS if INSN is a
   1281  1.1  mrg    DEBUG_INSN.  The arguments MODE, AS, CODE and INDEX_CODE are as for
   1282  1.1  mrg    base_reg_class.  */
   1283  1.1  mrg 
   1284  1.1  mrg static reg_class
   1285  1.1  mrg base_reg_class_for_rename (rtx_insn *insn, machine_mode mode, addr_space_t as,
   1286  1.1  mrg 			   rtx_code code, rtx_code index_code)
   1287  1.1  mrg {
   1288  1.1  mrg   if (DEBUG_INSN_P (insn))
   1289  1.1  mrg     return ALL_REGS;
   1290  1.1  mrg   return base_reg_class (mode, as, code, index_code);
   1291  1.1  mrg }
   1292  1.1  mrg 
   1293  1.1  mrg /* Adapted from find_reloads_address_1.  CL is INDEX_REG_CLASS or
   1294  1.1  mrg    BASE_REG_CLASS depending on how the register is being considered.  */
   1295  1.1  mrg 
   1296  1.1  mrg static void
   1297  1.1  mrg scan_rtx_address (rtx_insn *insn, rtx *loc, enum reg_class cl,
   1298  1.1  mrg 		  enum scan_actions action, machine_mode mode,
   1299  1.1  mrg 		  addr_space_t as)
   1300  1.1  mrg {
   1301  1.1  mrg   rtx x = *loc;
   1302  1.1  mrg   RTX_CODE code = GET_CODE (x);
   1303  1.1  mrg   const char *fmt;
   1304  1.1  mrg   int i, j;
   1305  1.1  mrg 
   1306  1.1  mrg   if (action == mark_write || action == mark_access)
   1307  1.1  mrg     return;
   1308  1.1  mrg 
   1309  1.1  mrg   switch (code)
   1310  1.1  mrg     {
   1311  1.1  mrg     case PLUS:
   1312  1.1  mrg       {
   1313  1.1  mrg 	rtx orig_op0 = XEXP (x, 0);
   1314  1.1  mrg 	rtx orig_op1 = XEXP (x, 1);
   1315  1.1  mrg 	RTX_CODE code0 = GET_CODE (orig_op0);
   1316  1.1  mrg 	RTX_CODE code1 = GET_CODE (orig_op1);
   1317  1.1  mrg 	rtx op0 = orig_op0;
   1318  1.1  mrg 	rtx op1 = orig_op1;
   1319  1.1  mrg 	rtx *locI = NULL;
   1320  1.1  mrg 	rtx *locB = NULL;
   1321  1.1  mrg 	enum rtx_code index_code = SCRATCH;
   1322  1.1  mrg 
   1323  1.1  mrg 	if (GET_CODE (op0) == SUBREG)
   1324  1.1  mrg 	  {
   1325  1.1  mrg 	    op0 = SUBREG_REG (op0);
   1326  1.1  mrg 	    code0 = GET_CODE (op0);
   1327  1.1  mrg 	  }
   1328  1.1  mrg 
   1329  1.1  mrg 	if (GET_CODE (op1) == SUBREG)
   1330  1.1  mrg 	  {
   1331  1.1  mrg 	    op1 = SUBREG_REG (op1);
   1332  1.1  mrg 	    code1 = GET_CODE (op1);
   1333  1.1  mrg 	  }
   1334  1.1  mrg 
   1335  1.1  mrg 	if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE
   1336  1.1  mrg 	    || code0 == ZERO_EXTEND || code1 == MEM)
   1337  1.1  mrg 	  {
   1338  1.1  mrg 	    locI = &XEXP (x, 0);
   1339  1.1  mrg 	    locB = &XEXP (x, 1);
   1340  1.1  mrg 	    index_code = GET_CODE (*locI);
   1341  1.1  mrg 	  }
   1342  1.1  mrg 	else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE
   1343  1.1  mrg 		 || code1 == ZERO_EXTEND || code0 == MEM)
   1344  1.1  mrg 	  {
   1345  1.1  mrg 	    locI = &XEXP (x, 1);
   1346  1.1  mrg 	    locB = &XEXP (x, 0);
   1347  1.1  mrg 	    index_code = GET_CODE (*locI);
   1348  1.1  mrg 	  }
   1349  1.1  mrg 	else if (code0 == CONST_INT || code0 == CONST
   1350  1.1  mrg 		 || code0 == SYMBOL_REF || code0 == LABEL_REF)
   1351  1.1  mrg 	  {
   1352  1.1  mrg 	    locB = &XEXP (x, 1);
   1353  1.1  mrg 	    index_code = GET_CODE (XEXP (x, 0));
   1354  1.1  mrg 	  }
   1355  1.1  mrg 	else if (code1 == CONST_INT || code1 == CONST
   1356  1.1  mrg 		 || code1 == SYMBOL_REF || code1 == LABEL_REF)
   1357  1.1  mrg 	  {
   1358  1.1  mrg 	    locB = &XEXP (x, 0);
   1359  1.1  mrg 	    index_code = GET_CODE (XEXP (x, 1));
   1360  1.1  mrg 	  }
   1361  1.1  mrg 	else if (code0 == REG && code1 == REG)
   1362  1.1  mrg 	  {
   1363  1.1  mrg 	    int index_op;
   1364  1.1  mrg 	    unsigned regno0 = REGNO (op0), regno1 = REGNO (op1);
   1365  1.1  mrg 
   1366  1.1  mrg 	    if (REGNO_OK_FOR_INDEX_P (regno1)
   1367  1.1  mrg 		&& regno_ok_for_base_p (regno0, mode, as, PLUS, REG))
   1368  1.1  mrg 	      index_op = 1;
   1369  1.1  mrg 	    else if (REGNO_OK_FOR_INDEX_P (regno0)
   1370  1.1  mrg 		     && regno_ok_for_base_p (regno1, mode, as, PLUS, REG))
   1371  1.1  mrg 	      index_op = 0;
   1372  1.1  mrg 	    else if (regno_ok_for_base_p (regno0, mode, as, PLUS, REG)
   1373  1.1  mrg 		     || REGNO_OK_FOR_INDEX_P (regno1))
   1374  1.1  mrg 	      index_op = 1;
   1375  1.1  mrg 	    else if (regno_ok_for_base_p (regno1, mode, as, PLUS, REG))
   1376  1.1  mrg 	      index_op = 0;
   1377  1.1  mrg 	    else
   1378  1.1  mrg 	      index_op = 1;
   1379  1.1  mrg 
   1380  1.1  mrg 	    locI = &XEXP (x, index_op);
   1381  1.1  mrg 	    locB = &XEXP (x, !index_op);
   1382  1.1  mrg 	    index_code = GET_CODE (*locI);
   1383  1.1  mrg 	  }
   1384  1.1  mrg 	else if (code0 == REG)
   1385  1.1  mrg 	  {
   1386  1.1  mrg 	    locI = &XEXP (x, 0);
   1387  1.1  mrg 	    locB = &XEXP (x, 1);
   1388  1.1  mrg 	    index_code = GET_CODE (*locI);
   1389  1.1  mrg 	  }
   1390  1.1  mrg 	else if (code1 == REG)
   1391  1.1  mrg 	  {
   1392  1.1  mrg 	    locI = &XEXP (x, 1);
   1393  1.1  mrg 	    locB = &XEXP (x, 0);
   1394  1.1  mrg 	    index_code = GET_CODE (*locI);
   1395  1.1  mrg 	  }
   1396  1.1  mrg 
   1397  1.1  mrg 	if (locI)
   1398  1.1  mrg 	  {
   1399  1.1  mrg 	    reg_class iclass = DEBUG_INSN_P (insn) ? ALL_REGS : INDEX_REG_CLASS;
   1400  1.1  mrg 	    scan_rtx_address (insn, locI, iclass, action, mode, as);
   1401  1.1  mrg 	  }
   1402  1.1  mrg 	if (locB)
   1403  1.1  mrg 	  {
   1404  1.1  mrg 	    reg_class bclass = base_reg_class_for_rename (insn, mode, as, PLUS,
   1405  1.1  mrg 							  index_code);
   1406  1.1  mrg 	    scan_rtx_address (insn, locB, bclass, action, mode, as);
   1407  1.1  mrg 	  }
   1408  1.1  mrg 	return;
   1409  1.1  mrg       }
   1410  1.1  mrg 
   1411  1.1  mrg     case POST_INC:
   1412  1.1  mrg     case POST_DEC:
   1413  1.1  mrg     case POST_MODIFY:
   1414  1.1  mrg     case PRE_INC:
   1415  1.1  mrg     case PRE_DEC:
   1416  1.1  mrg     case PRE_MODIFY:
   1417  1.1  mrg       /* If the target doesn't claim to handle autoinc, this must be
   1418  1.1  mrg 	 something special, like a stack push.  Kill this chain.  */
   1419  1.1  mrg       if (!AUTO_INC_DEC)
   1420  1.1  mrg 	action = mark_all_read;
   1421  1.1  mrg 
   1422  1.1  mrg       break;
   1423  1.1  mrg 
   1424  1.1  mrg     case MEM:
   1425  1.1  mrg       {
   1426  1.1  mrg 	reg_class bclass = base_reg_class_for_rename (insn, GET_MODE (x),
   1427  1.1  mrg 						      MEM_ADDR_SPACE (x),
   1428  1.1  mrg 						      MEM, SCRATCH);
   1429  1.1  mrg 	scan_rtx_address (insn, &XEXP (x, 0), bclass, action, GET_MODE (x),
   1430  1.1  mrg 			  MEM_ADDR_SPACE (x));
   1431  1.1  mrg       }
   1432  1.1  mrg       return;
   1433  1.1  mrg 
   1434  1.1  mrg     case REG:
   1435  1.1  mrg       scan_rtx_reg (insn, loc, cl, action, OP_IN);
   1436  1.1  mrg       return;
   1437  1.1  mrg 
   1438  1.1  mrg     default:
   1439  1.1  mrg       break;
   1440  1.1  mrg     }
   1441  1.1  mrg 
   1442  1.1  mrg   fmt = GET_RTX_FORMAT (code);
   1443  1.1  mrg   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
   1444  1.1  mrg     {
   1445  1.1  mrg       if (fmt[i] == 'e')
   1446  1.1  mrg 	scan_rtx_address (insn, &XEXP (x, i), cl, action, mode, as);
   1447  1.1  mrg       else if (fmt[i] == 'E')
   1448  1.1  mrg 	for (j = XVECLEN (x, i) - 1; j >= 0; j--)
   1449  1.1  mrg 	  scan_rtx_address (insn, &XVECEXP (x, i, j), cl, action, mode, as);
   1450  1.1  mrg     }
   1451  1.1  mrg }
   1452  1.1  mrg 
   1453  1.1  mrg static void
   1454  1.1  mrg scan_rtx (rtx_insn *insn, rtx *loc, enum reg_class cl, enum scan_actions action,
   1455  1.1  mrg 	  enum op_type type)
   1456  1.1  mrg {
   1457  1.1  mrg   const char *fmt;
   1458  1.1  mrg   rtx x = *loc;
   1459  1.1  mrg   int i, j;
   1460  1.1  mrg 
   1461  1.1  mrg   enum rtx_code code = GET_CODE (x);
   1462  1.1  mrg   switch (code)
   1463  1.1  mrg     {
   1464  1.1  mrg     case CONST:
   1465  1.1  mrg     CASE_CONST_ANY:
   1466  1.1  mrg     case SYMBOL_REF:
   1467  1.1  mrg     case LABEL_REF:
   1468  1.1  mrg     case PC:
   1469  1.1  mrg       return;
   1470  1.1  mrg 
   1471  1.1  mrg     case REG:
   1472  1.1  mrg       scan_rtx_reg (insn, loc, cl, action, type);
   1473  1.1  mrg       return;
   1474  1.1  mrg 
   1475  1.1  mrg     case MEM:
   1476  1.1  mrg       {
   1477  1.1  mrg 	reg_class bclass = base_reg_class_for_rename (insn, GET_MODE (x),
   1478  1.1  mrg 						      MEM_ADDR_SPACE (x),
   1479  1.1  mrg 						      MEM, SCRATCH);
   1480  1.1  mrg 
   1481  1.1  mrg 	scan_rtx_address (insn, &XEXP (x, 0), bclass, action, GET_MODE (x),
   1482  1.1  mrg 			  MEM_ADDR_SPACE (x));
   1483  1.1  mrg       }
   1484  1.1  mrg       return;
   1485  1.1  mrg 
   1486  1.1  mrg     case SET:
   1487  1.1  mrg       scan_rtx (insn, &SET_SRC (x), cl, action, OP_IN);
   1488  1.1  mrg       scan_rtx (insn, &SET_DEST (x), cl, action,
   1489  1.1  mrg 		(GET_CODE (PATTERN (insn)) == COND_EXEC
   1490  1.1  mrg 		 && verify_reg_tracked (SET_DEST (x))) ? OP_INOUT : OP_OUT);
   1491  1.1  mrg       return;
   1492  1.1  mrg 
   1493  1.1  mrg     case STRICT_LOW_PART:
   1494  1.1  mrg       scan_rtx (insn, &XEXP (x, 0), cl, action,
   1495  1.1  mrg 		verify_reg_tracked (XEXP (x, 0)) ? OP_INOUT : OP_OUT);
   1496  1.1  mrg       return;
   1497  1.1  mrg 
   1498  1.1  mrg     case ZERO_EXTRACT:
   1499  1.1  mrg     case SIGN_EXTRACT:
   1500  1.1  mrg       scan_rtx (insn, &XEXP (x, 0), cl, action,
   1501  1.1  mrg 		(type == OP_IN ? OP_IN :
   1502  1.1  mrg 		 verify_reg_tracked (XEXP (x, 0)) ? OP_INOUT : OP_OUT));
   1503  1.1  mrg       scan_rtx (insn, &XEXP (x, 1), cl, action, OP_IN);
   1504  1.1  mrg       scan_rtx (insn, &XEXP (x, 2), cl, action, OP_IN);
   1505  1.1  mrg       return;
   1506  1.1  mrg 
   1507  1.1  mrg     case POST_INC:
   1508  1.1  mrg     case PRE_INC:
   1509  1.1  mrg     case POST_DEC:
   1510  1.1  mrg     case PRE_DEC:
   1511  1.1  mrg     case POST_MODIFY:
   1512  1.1  mrg     case PRE_MODIFY:
   1513  1.1  mrg       /* Should only happen inside MEM.  */
   1514  1.1  mrg       gcc_unreachable ();
   1515  1.1  mrg 
   1516  1.1  mrg     case CLOBBER:
   1517  1.1  mrg       scan_rtx (insn, &SET_DEST (x), cl, action,
   1518  1.1  mrg 		(GET_CODE (PATTERN (insn)) == COND_EXEC
   1519  1.1  mrg 		 && verify_reg_tracked (SET_DEST (x))) ? OP_INOUT : OP_OUT);
   1520  1.1  mrg       return;
   1521  1.1  mrg 
   1522  1.1  mrg     case EXPR_LIST:
   1523  1.1  mrg       scan_rtx (insn, &XEXP (x, 0), cl, action, type);
   1524  1.1  mrg       if (XEXP (x, 1))
   1525  1.1  mrg 	scan_rtx (insn, &XEXP (x, 1), cl, action, type);
   1526  1.1  mrg       return;
   1527  1.1  mrg 
   1528  1.1  mrg     default:
   1529  1.1  mrg       break;
   1530  1.1  mrg     }
   1531  1.1  mrg 
   1532  1.1  mrg   fmt = GET_RTX_FORMAT (code);
   1533  1.1  mrg   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
   1534  1.1  mrg     {
   1535  1.1  mrg       if (fmt[i] == 'e')
   1536  1.1  mrg 	scan_rtx (insn, &XEXP (x, i), cl, action, type);
   1537  1.1  mrg       else if (fmt[i] == 'E')
   1538  1.1  mrg 	for (j = XVECLEN (x, i) - 1; j >= 0; j--)
   1539  1.1  mrg 	  scan_rtx (insn, &XVECEXP (x, i, j), cl, action, type);
   1540  1.1  mrg     }
   1541  1.1  mrg }
   1542  1.1  mrg 
   1543  1.1  mrg /* Hide operands of the current insn (of which there are N_OPS) by
   1544  1.1  mrg    substituting pc for them.
   1545  1.1  mrg    Previous values are stored in the OLD_OPERANDS and OLD_DUPS.
   1546  1.1  mrg    For every bit set in DO_NOT_HIDE, we leave the operand alone.
   1547  1.1  mrg    If INOUT_AND_EC_ONLY is set, we only do this for OP_INOUT type operands
   1548  1.1  mrg    and earlyclobbers.  */
   1549  1.1  mrg 
   1550  1.1  mrg static void
   1551  1.1  mrg hide_operands (int n_ops, rtx *old_operands, rtx *old_dups,
   1552  1.1  mrg 	       unsigned HOST_WIDE_INT do_not_hide, bool inout_and_ec_only)
   1553  1.1  mrg {
   1554  1.1  mrg   int i;
   1555  1.1  mrg   const operand_alternative *op_alt = which_op_alt ();
   1556  1.1  mrg   for (i = 0; i < n_ops; i++)
   1557  1.1  mrg     {
   1558  1.1  mrg       old_operands[i] = recog_data.operand[i];
   1559  1.1  mrg       /* Don't squash match_operator or match_parallel here, since
   1560  1.1  mrg 	 we don't know that all of the contained registers are
   1561  1.1  mrg 	 reachable by proper operands.  */
   1562  1.1  mrg       if (recog_data.constraints[i][0] == '\0')
   1563  1.1  mrg 	continue;
   1564  1.1  mrg       if (do_not_hide & (1 << i))
   1565  1.1  mrg 	continue;
   1566  1.1  mrg       if (!inout_and_ec_only || recog_data.operand_type[i] == OP_INOUT
   1567  1.1  mrg 	  || op_alt[i].earlyclobber)
   1568  1.1  mrg 	*recog_data.operand_loc[i] = pc_rtx;
   1569  1.1  mrg     }
   1570  1.1  mrg   for (i = 0; i < recog_data.n_dups; i++)
   1571  1.1  mrg     {
   1572  1.1  mrg       int opn = recog_data.dup_num[i];
   1573  1.1  mrg       old_dups[i] = *recog_data.dup_loc[i];
   1574  1.1  mrg       if (do_not_hide & (1 << opn))
   1575  1.1  mrg 	continue;
   1576  1.1  mrg       if (!inout_and_ec_only || recog_data.operand_type[opn] == OP_INOUT
   1577  1.1  mrg 	  || op_alt[opn].earlyclobber)
   1578  1.1  mrg 	*recog_data.dup_loc[i] = pc_rtx;
   1579  1.1  mrg     }
   1580  1.1  mrg }
   1581  1.1  mrg 
   1582  1.1  mrg /* Undo the substitution performed by hide_operands.  INSN is the insn we
   1583  1.1  mrg    are processing; the arguments are the same as in hide_operands.  */
   1584  1.1  mrg 
   1585  1.1  mrg static void
   1586  1.1  mrg restore_operands (rtx_insn *insn, int n_ops, rtx *old_operands, rtx *old_dups)
   1587  1.1  mrg {
   1588  1.1  mrg   int i;
   1589  1.1  mrg   for (i = 0; i < recog_data.n_dups; i++)
   1590  1.1  mrg     *recog_data.dup_loc[i] = old_dups[i];
   1591  1.1  mrg   for (i = 0; i < n_ops; i++)
   1592  1.1  mrg     *recog_data.operand_loc[i] = old_operands[i];
   1593  1.1  mrg   if (recog_data.n_dups)
   1594  1.1  mrg     df_insn_rescan (insn);
   1595  1.1  mrg }
   1596  1.1  mrg 
   1597  1.1  mrg /* For each output operand of INSN, call scan_rtx to create a new
   1598  1.1  mrg    open chain.  Do this only for normal or earlyclobber outputs,
   1599  1.1  mrg    depending on EARLYCLOBBER.  If INSN_INFO is nonnull, use it to
   1600  1.1  mrg    record information about the operands in the insn.  */
   1601  1.1  mrg 
   1602  1.1  mrg static void
   1603  1.1  mrg record_out_operands (rtx_insn *insn, bool earlyclobber, insn_rr_info *insn_info)
   1604  1.1  mrg {
   1605  1.1  mrg   int n_ops = recog_data.n_operands;
   1606  1.1  mrg   const operand_alternative *op_alt = which_op_alt ();
   1607  1.1  mrg 
   1608  1.1  mrg   int i;
   1609  1.1  mrg 
   1610  1.1  mrg   for (i = 0; i < n_ops + recog_data.n_dups; i++)
   1611  1.1  mrg     {
   1612  1.1  mrg       int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
   1613  1.1  mrg       rtx *loc = (i < n_ops
   1614  1.1  mrg 		  ? recog_data.operand_loc[opn]
   1615  1.1  mrg 		  : recog_data.dup_loc[i - n_ops]);
   1616  1.1  mrg       rtx op = *loc;
   1617  1.1  mrg       enum reg_class cl = alternative_class (op_alt, opn);
   1618  1.1  mrg 
   1619  1.1  mrg       class du_head *prev_open;
   1620  1.1  mrg 
   1621  1.1  mrg       if (recog_data.operand_type[opn] != OP_OUT
   1622  1.1  mrg 	  || op_alt[opn].earlyclobber != earlyclobber)
   1623  1.1  mrg 	continue;
   1624  1.1  mrg 
   1625  1.1  mrg       if (insn_info)
   1626  1.1  mrg 	cur_operand = insn_info->op_info + i;
   1627  1.1  mrg 
   1628  1.1  mrg       prev_open = open_chains;
   1629  1.1  mrg       if (earlyclobber)
   1630  1.1  mrg 	scan_rtx (insn, loc, cl, terminate_write, OP_OUT);
   1631  1.1  mrg       scan_rtx (insn, loc, cl, mark_write, OP_OUT);
   1632  1.1  mrg 
   1633  1.1  mrg       /* ??? Many targets have output constraints on the SET_DEST
   1634  1.1  mrg 	 of a call insn, which is stupid, since these are certainly
   1635  1.1  mrg 	 ABI defined hard registers.  For these, and for asm operands
   1636  1.1  mrg 	 that originally referenced hard registers, we must record that
   1637  1.1  mrg 	 the chain cannot be renamed.  */
   1638  1.1  mrg       if (CALL_P (insn)
   1639  1.1  mrg 	  || (asm_noperands (PATTERN (insn)) > 0
   1640  1.1  mrg 	      && REG_P (op)
   1641  1.1  mrg 	      && REGNO (op) == ORIGINAL_REGNO (op)))
   1642  1.1  mrg 	{
   1643  1.1  mrg 	  if (prev_open != open_chains)
   1644  1.1  mrg 	    open_chains->cannot_rename = 1;
   1645  1.1  mrg 	}
   1646  1.1  mrg     }
   1647  1.1  mrg   cur_operand = NULL;
   1648  1.1  mrg }
   1649  1.1  mrg 
   1650  1.1  mrg /* Build def/use chain.  */
   1651  1.1  mrg 
   1652  1.1  mrg static bool
   1653  1.1  mrg build_def_use (basic_block bb)
   1654  1.1  mrg {
   1655  1.1  mrg   rtx_insn *insn;
   1656  1.1  mrg   unsigned HOST_WIDE_INT untracked_operands;
   1657  1.1  mrg 
   1658  1.1  mrg   fail_current_block = false;
   1659  1.1  mrg 
   1660  1.1  mrg   for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
   1661  1.1  mrg     {
   1662  1.1  mrg       if (NONDEBUG_INSN_P (insn))
   1663  1.1  mrg 	{
   1664  1.1  mrg 	  int n_ops;
   1665  1.1  mrg 	  rtx note;
   1666  1.1  mrg 	  rtx old_operands[MAX_RECOG_OPERANDS];
   1667  1.1  mrg 	  rtx old_dups[MAX_DUP_OPERANDS];
   1668  1.1  mrg 	  int i;
   1669  1.1  mrg 	  int predicated;
   1670  1.1  mrg 	  enum rtx_code set_code = SET;
   1671  1.1  mrg 	  enum rtx_code clobber_code = CLOBBER;
   1672  1.1  mrg 	  insn_rr_info *insn_info = NULL;
   1673  1.1  mrg 	  terminated_this_insn = NULL;
   1674  1.1  mrg 
   1675  1.1  mrg 	  /* Process the insn, determining its effect on the def-use
   1676  1.1  mrg 	     chains and live hard registers.  We perform the following
   1677  1.1  mrg 	     steps with the register references in the insn, simulating
   1678  1.1  mrg 	     its effect:
   1679  1.1  mrg 	     (1) Deal with earlyclobber operands and CLOBBERs of non-operands
   1680  1.1  mrg 	         by creating chains and marking hard regs live.
   1681  1.1  mrg 	     (2) Any read outside an operand causes any chain it overlaps
   1682  1.1  mrg 	         with to be marked unrenamable.
   1683  1.1  mrg 	     (3) Any read inside an operand is added if there's already
   1684  1.1  mrg 	         an open chain for it.
   1685  1.1  mrg 	     (4) For any REG_DEAD note we find, close open chains that
   1686  1.1  mrg 	         overlap it.
   1687  1.1  mrg 	     (5) For any non-earlyclobber write we find, close open chains
   1688  1.1  mrg 	         that overlap it.
   1689  1.1  mrg 	     (6) For any non-earlyclobber write we find in an operand, make
   1690  1.1  mrg 	         a new chain or mark the hard register as live.
   1691  1.1  mrg 	     (7) For any REG_UNUSED, close any chains we just opened.
   1692  1.1  mrg 	     (8) For any REG_CFA_RESTORE or REG_CFA_REGISTER, kill any chain
   1693  1.1  mrg 	         containing its dest.
   1694  1.1  mrg 
   1695  1.1  mrg 	     We cannot deal with situations where we track a reg in one mode
   1696  1.1  mrg 	     and see a reference in another mode; these will cause the chain
   1697  1.1  mrg 	     to be marked unrenamable or even cause us to abort the entire
   1698  1.1  mrg 	     basic block.  */
   1699  1.1  mrg 
   1700  1.1  mrg 	  extract_constrain_insn (insn);
   1701  1.1  mrg 	  preprocess_constraints (insn);
   1702  1.1  mrg 	  const operand_alternative *op_alt = which_op_alt ();
   1703  1.1  mrg 	  n_ops = recog_data.n_operands;
   1704  1.1  mrg 	  untracked_operands = 0;
   1705  1.1  mrg 
   1706  1.1  mrg 	  if (insn_rr.exists ())
   1707  1.1  mrg 	    {
   1708  1.1  mrg 	      insn_info = &insn_rr[INSN_UID (insn)];
   1709  1.1  mrg 	      insn_info->op_info = XOBNEWVEC (&rename_obstack, operand_rr_info,
   1710  1.1  mrg 					      recog_data.n_operands);
   1711  1.1  mrg 	      memset (insn_info->op_info, 0,
   1712  1.1  mrg 		      sizeof (operand_rr_info) * recog_data.n_operands);
   1713  1.1  mrg 	    }
   1714  1.1  mrg 
   1715  1.1  mrg 	  /* Simplify the code below by promoting OP_OUT to OP_INOUT in
   1716  1.1  mrg 	     predicated instructions, but only for register operands
   1717  1.1  mrg 	     that are already tracked, so that we can create a chain
   1718  1.1  mrg 	     when the first SET makes a register live.  */
   1719  1.1  mrg 
   1720  1.1  mrg 	  predicated = GET_CODE (PATTERN (insn)) == COND_EXEC;
   1721  1.1  mrg 	  for (i = 0; i < n_ops; ++i)
   1722  1.1  mrg 	    {
   1723  1.1  mrg 	      rtx op = recog_data.operand[i];
   1724  1.1  mrg 	      int matches = op_alt[i].matches;
   1725  1.1  mrg 	      if (matches >= 0 || op_alt[i].matched >= 0
   1726  1.1  mrg 	          || (predicated && recog_data.operand_type[i] == OP_OUT))
   1727  1.1  mrg 		{
   1728  1.1  mrg 		  recog_data.operand_type[i] = OP_INOUT;
   1729  1.1  mrg 		  /* A special case to deal with instruction patterns that
   1730  1.1  mrg 		     have matching operands with different modes.  If we're
   1731  1.1  mrg 		     not already tracking such a reg, we won't start here,
   1732  1.1  mrg 		     and we must instead make sure to make the operand visible
   1733  1.1  mrg 		     to the machinery that tracks hard registers.  */
   1734  1.1  mrg 		  machine_mode i_mode = recog_data.operand_mode[i];
   1735  1.1  mrg 		  if (matches >= 0)
   1736  1.1  mrg 		    {
   1737  1.1  mrg 		      machine_mode matches_mode
   1738  1.1  mrg 			= recog_data.operand_mode[matches];
   1739  1.1  mrg 
   1740  1.1  mrg 		      if (maybe_ne (GET_MODE_SIZE (i_mode),
   1741  1.1  mrg 				    GET_MODE_SIZE (matches_mode))
   1742  1.1  mrg 			  && !verify_reg_in_set (op, &live_in_chains))
   1743  1.1  mrg 			{
   1744  1.1  mrg 			  untracked_operands |= 1 << i;
   1745  1.1  mrg 			  untracked_operands |= 1 << matches;
   1746  1.1  mrg 			}
   1747  1.1  mrg 		    }
   1748  1.1  mrg 		}
   1749  1.1  mrg #ifdef STACK_REGS
   1750  1.1  mrg 	      if (regstack_completed
   1751  1.1  mrg 		  && REG_P (op)
   1752  1.1  mrg 		  && IN_RANGE (REGNO (op), FIRST_STACK_REG, LAST_STACK_REG))
   1753  1.1  mrg 		untracked_operands |= 1 << i;
   1754  1.1  mrg #endif
   1755  1.1  mrg 	      /* If there's an in-out operand with a register that is not
   1756  1.1  mrg 		 being tracked at all yet, open a chain.  */
   1757  1.1  mrg 	      if (recog_data.operand_type[i] == OP_INOUT
   1758  1.1  mrg 		  && !(untracked_operands & (1 << i))
   1759  1.1  mrg 		  && REG_P (op)
   1760  1.1  mrg 		  && !verify_reg_tracked (op))
   1761  1.1  mrg 		create_new_chain (REGNO (op), REG_NREGS (op), NULL, NULL,
   1762  1.1  mrg 				  NO_REGS);
   1763  1.1  mrg 	    }
   1764  1.1  mrg 
   1765  1.1  mrg 	  if (fail_current_block)
   1766  1.1  mrg 	    break;
   1767  1.1  mrg 
   1768  1.1  mrg 	  /* Step 1a: Mark hard registers that are clobbered in this insn,
   1769  1.1  mrg 	     outside an operand, as live.  */
   1770  1.1  mrg 	  hide_operands (n_ops, old_operands, old_dups, untracked_operands,
   1771  1.1  mrg 			 false);
   1772  1.1  mrg 	  note_stores (insn, note_sets_clobbers, &clobber_code);
   1773  1.1  mrg 	  restore_operands (insn, n_ops, old_operands, old_dups);
   1774  1.1  mrg 
   1775  1.1  mrg 	  /* Step 1b: Begin new chains for earlyclobbered writes inside
   1776  1.1  mrg 	     operands.  */
   1777  1.1  mrg 	  record_out_operands (insn, true, insn_info);
   1778  1.1  mrg 
   1779  1.1  mrg 	  /* Step 2: Mark chains for which we have reads outside operands
   1780  1.1  mrg 	     as unrenamable.
   1781  1.1  mrg 	     We do this by munging all operands into PC, and closing
   1782  1.1  mrg 	     everything remaining.  */
   1783  1.1  mrg 
   1784  1.1  mrg 	  hide_operands (n_ops, old_operands, old_dups, untracked_operands,
   1785  1.1  mrg 			 false);
   1786  1.1  mrg 	  scan_rtx (insn, &PATTERN (insn), NO_REGS, mark_all_read, OP_IN);
   1787  1.1  mrg 	  restore_operands (insn, n_ops, old_operands, old_dups);
   1788  1.1  mrg 
   1789  1.1  mrg 	  /* Step 2B: Can't rename function call argument registers.  */
   1790  1.1  mrg 	  if (CALL_P (insn) && CALL_INSN_FUNCTION_USAGE (insn))
   1791  1.1  mrg 	    scan_rtx (insn, &CALL_INSN_FUNCTION_USAGE (insn),
   1792  1.1  mrg 		      NO_REGS, mark_all_read, OP_IN);
   1793  1.1  mrg 
   1794  1.1  mrg 	  /* Step 2C: Can't rename asm operands that were originally
   1795  1.1  mrg 	     hard registers.  */
   1796  1.1  mrg 	  if (asm_noperands (PATTERN (insn)) > 0)
   1797  1.1  mrg 	    for (i = 0; i < n_ops; i++)
   1798  1.1  mrg 	      {
   1799  1.1  mrg 		rtx *loc = recog_data.operand_loc[i];
   1800  1.1  mrg 		rtx op = *loc;
   1801  1.1  mrg 
   1802  1.1  mrg 		if (REG_P (op)
   1803  1.1  mrg 		    && REGNO (op) == ORIGINAL_REGNO (op)
   1804  1.1  mrg 		    && (recog_data.operand_type[i] == OP_IN
   1805  1.1  mrg 			|| recog_data.operand_type[i] == OP_INOUT))
   1806  1.1  mrg 		  scan_rtx (insn, loc, NO_REGS, mark_all_read, OP_IN);
   1807  1.1  mrg 	      }
   1808  1.1  mrg 
   1809  1.1  mrg 	  /* Step 3: Append to chains for reads inside operands.  */
   1810  1.1  mrg 	  for (i = 0; i < n_ops + recog_data.n_dups; i++)
   1811  1.1  mrg 	    {
   1812  1.1  mrg 	      int opn = i < n_ops ? i : recog_data.dup_num[i - n_ops];
   1813  1.1  mrg 	      rtx *loc = (i < n_ops
   1814  1.1  mrg 			  ? recog_data.operand_loc[opn]
   1815  1.1  mrg 			  : recog_data.dup_loc[i - n_ops]);
   1816  1.1  mrg 	      enum reg_class cl = alternative_class (op_alt, opn);
   1817  1.1  mrg 	      enum op_type type = recog_data.operand_type[opn];
   1818  1.1  mrg 
   1819  1.1  mrg 	      /* Don't scan match_operand here, since we've no reg class
   1820  1.1  mrg 		 information to pass down.  Any operands that we could
   1821  1.1  mrg 		 substitute in will be represented elsewhere.  */
   1822  1.1  mrg 	      if (recog_data.constraints[opn][0] == '\0'
   1823  1.1  mrg 		  || untracked_operands & (1 << opn))
   1824  1.1  mrg 		continue;
   1825  1.1  mrg 
   1826  1.1  mrg 	      if (insn_info)
   1827  1.1  mrg 		cur_operand = i == opn ? insn_info->op_info + i : NULL;
   1828  1.1  mrg 	      if (op_alt[opn].is_address)
   1829  1.1  mrg 		scan_rtx_address (insn, loc, cl, mark_read,
   1830  1.1  mrg 				  VOIDmode, ADDR_SPACE_GENERIC);
   1831  1.1  mrg 	      else
   1832  1.1  mrg 		scan_rtx (insn, loc, cl, mark_read, type);
   1833  1.1  mrg 	    }
   1834  1.1  mrg 	  cur_operand = NULL;
   1835  1.1  mrg 
   1836  1.1  mrg 	  /* Step 3B: Record updates for regs in REG_INC notes, and
   1837  1.1  mrg 	     source regs in REG_FRAME_RELATED_EXPR notes.  */
   1838  1.1  mrg 	  for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
   1839  1.1  mrg 	    if (REG_NOTE_KIND (note) == REG_INC
   1840  1.1  mrg 		|| REG_NOTE_KIND (note) == REG_FRAME_RELATED_EXPR)
   1841  1.1  mrg 	      scan_rtx (insn, &XEXP (note, 0), ALL_REGS, mark_read,
   1842  1.1  mrg 			OP_INOUT);
   1843  1.1  mrg 
   1844  1.1  mrg 	  /* Step 4: Close chains for registers that die here, unless
   1845  1.1  mrg 	     the register is mentioned in a REG_UNUSED note.  In that
   1846  1.1  mrg 	     case we keep the chain open until step #7 below to ensure
   1847  1.1  mrg 	     it conflicts with other output operands of this insn.
   1848  1.1  mrg 	     See PR 52573.  Arguably the insn should not have both
   1849  1.1  mrg 	     notes; it has proven difficult to fix that without
   1850  1.1  mrg 	     other undesirable side effects.  */
   1851  1.1  mrg 	  for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
   1852  1.1  mrg 	    if (REG_NOTE_KIND (note) == REG_DEAD
   1853  1.1  mrg 		&& !find_regno_note (insn, REG_UNUSED, REGNO (XEXP (note, 0))))
   1854  1.1  mrg 	      {
   1855  1.1  mrg 		remove_from_hard_reg_set (&live_hard_regs,
   1856  1.1  mrg 					  GET_MODE (XEXP (note, 0)),
   1857  1.1  mrg 					  REGNO (XEXP (note, 0)));
   1858  1.1  mrg 		scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
   1859  1.1  mrg 			  OP_IN);
   1860  1.1  mrg 	      }
   1861  1.1  mrg 
   1862  1.1  mrg 	  /* Step 4B: If this is a call, any chain live at this point
   1863  1.1  mrg 	     requires a caller-saved reg.  */
   1864  1.1  mrg 	  if (CALL_P (insn))
   1865  1.1  mrg 	    {
   1866  1.1  mrg 	      function_abi callee_abi = insn_callee_abi (insn);
   1867  1.1  mrg 	      class du_head *p;
   1868  1.1  mrg 	      for (p = open_chains; p; p = p->next_chain)
   1869  1.1  mrg 		{
   1870  1.1  mrg 		  p->call_abis |= (1 << callee_abi.id ());
   1871  1.1  mrg 		  p->call_clobber_mask
   1872  1.1  mrg 		    |= callee_abi.full_and_partial_reg_clobbers ();
   1873  1.1  mrg 		  p->hard_conflicts |= callee_abi.full_reg_clobbers ();
   1874  1.1  mrg 		}
   1875  1.1  mrg 	    }
   1876  1.1  mrg 
   1877  1.1  mrg 	  /* Step 5: Close open chains that overlap writes.  Similar to
   1878  1.1  mrg 	     step 2, we hide in-out operands, since we do not want to
   1879  1.1  mrg 	     close these chains.  We also hide earlyclobber operands,
   1880  1.1  mrg 	     since we've opened chains for them in step 1, and earlier
   1881  1.1  mrg 	     chains they would overlap with must have been closed at
   1882  1.1  mrg 	     the previous insn at the latest, as such operands cannot
   1883  1.1  mrg 	     possibly overlap with any input operands.  */
   1884  1.1  mrg 
   1885  1.1  mrg 	  hide_operands (n_ops, old_operands, old_dups, untracked_operands,
   1886  1.1  mrg 			 true);
   1887  1.1  mrg 	  scan_rtx (insn, &PATTERN (insn), NO_REGS, terminate_write, OP_IN);
   1888  1.1  mrg 	  restore_operands (insn, n_ops, old_operands, old_dups);
   1889  1.1  mrg 
   1890  1.1  mrg 	  /* Step 6a: Mark hard registers that are set in this insn,
   1891  1.1  mrg 	     outside an operand, as live.  */
   1892  1.1  mrg 	  hide_operands (n_ops, old_operands, old_dups, untracked_operands,
   1893  1.1  mrg 			 false);
   1894  1.1  mrg 	  note_stores (insn, note_sets_clobbers, &set_code);
   1895  1.1  mrg 	  restore_operands (insn, n_ops, old_operands, old_dups);
   1896  1.1  mrg 
   1897  1.1  mrg 	  /* Step 6b: Begin new chains for writes inside operands.  */
   1898  1.1  mrg 	  record_out_operands (insn, false, insn_info);
   1899  1.1  mrg 
   1900  1.1  mrg 	  /* Step 6c: Record destination regs in REG_FRAME_RELATED_EXPR
   1901  1.1  mrg 	     notes for update.  */
   1902  1.1  mrg 	  for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
   1903  1.1  mrg 	    if (REG_NOTE_KIND (note) == REG_FRAME_RELATED_EXPR)
   1904  1.1  mrg 	      scan_rtx (insn, &XEXP (note, 0), ALL_REGS, mark_access,
   1905  1.1  mrg 			OP_INOUT);
   1906  1.1  mrg 
   1907  1.1  mrg 	  /* Step 7: Close chains for registers that were never
   1908  1.1  mrg 	     really used here.  */
   1909  1.1  mrg 	  for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
   1910  1.1  mrg 	    if (REG_NOTE_KIND (note) == REG_UNUSED)
   1911  1.1  mrg 	      {
   1912  1.1  mrg 		remove_from_hard_reg_set (&live_hard_regs,
   1913  1.1  mrg 					  GET_MODE (XEXP (note, 0)),
   1914  1.1  mrg 					  REGNO (XEXP (note, 0)));
   1915  1.1  mrg 		scan_rtx (insn, &XEXP (note, 0), NO_REGS, terminate_dead,
   1916  1.1  mrg 			  OP_IN);
   1917  1.1  mrg 	      }
   1918  1.1  mrg 
   1919  1.1  mrg 	  /* Step 8: Kill the chains involving register restores.  Those
   1920  1.1  mrg 	     should restore _that_ register.  Similar for REG_CFA_REGISTER.  */
   1921  1.1  mrg 	  for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
   1922  1.1  mrg 	    if (REG_NOTE_KIND (note) == REG_CFA_RESTORE
   1923  1.1  mrg 		|| REG_NOTE_KIND (note) == REG_CFA_REGISTER)
   1924  1.1  mrg 	      {
   1925  1.1  mrg 		rtx *x = &XEXP (note, 0);
   1926  1.1  mrg 		if (!*x)
   1927  1.1  mrg 		  x = &PATTERN (insn);
   1928  1.1  mrg 		if (GET_CODE (*x) == PARALLEL)
   1929  1.1  mrg 		  x = &XVECEXP (*x, 0, 0);
   1930  1.1  mrg 		if (GET_CODE (*x) == SET)
   1931  1.1  mrg 		  x = &SET_DEST (*x);
   1932  1.1  mrg 		scan_rtx (insn, x, NO_REGS, mark_all_read, OP_IN);
   1933  1.1  mrg 	      }
   1934  1.1  mrg 	}
   1935  1.1  mrg       else if (DEBUG_BIND_INSN_P (insn)
   1936  1.1  mrg 	       && !VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn)))
   1937  1.1  mrg 	{
   1938  1.1  mrg 	  scan_rtx (insn, &INSN_VAR_LOCATION_LOC (insn),
   1939  1.1  mrg 		    ALL_REGS, mark_read, OP_IN);
   1940  1.1  mrg 	}
   1941  1.1  mrg       if (insn == BB_END (bb))
   1942  1.1  mrg 	break;
   1943  1.1  mrg     }
   1944  1.1  mrg 
   1945  1.1  mrg   if (fail_current_block)
   1946  1.1  mrg     return false;
   1947  1.1  mrg 
   1948  1.1  mrg   return true;
   1949  1.1  mrg }
   1950  1.1  mrg 
   1951  1.1  mrg /* Initialize the register renamer.  If INSN_INFO is true, ensure that
   1953  1.1  mrg    insn_rr is nonnull.  */
   1954  1.1  mrg void
   1955  1.1  mrg regrename_init (bool insn_info)
   1956  1.1  mrg {
   1957  1.1  mrg   gcc_obstack_init (&rename_obstack);
   1958  1.1  mrg   insn_rr.create (0);
   1959  1.1  mrg   if (insn_info)
   1960  1.1  mrg     insn_rr.safe_grow_cleared (get_max_uid (), true);
   1961  1.1  mrg }
   1962  1.1  mrg 
   1963  1.1  mrg /* Free all global data used by the register renamer.  */
   1964  1.1  mrg void
   1965  1.1  mrg regrename_finish (void)
   1966  1.1  mrg {
   1967  1.1  mrg   insn_rr.release ();
   1968  1.1  mrg   free_chain_data ();
   1969  1.1  mrg   obstack_free (&rename_obstack, NULL);
   1970  1.1  mrg }
   1971  1.1  mrg 
   1972  1.1  mrg /* Perform register renaming on the current function.  */
   1973  1.1  mrg 
   1974  1.1  mrg static unsigned int
   1975  1.1  mrg regrename_optimize (void)
   1976  1.1  mrg {
   1977  1.1  mrg   df_set_flags (DF_LR_RUN_DCE);
   1978  1.1  mrg   df_note_add_problem ();
   1979  1.1  mrg   df_analyze ();
   1980  1.1  mrg   df_set_flags (DF_DEFER_INSN_RESCAN);
   1981  1.1  mrg 
   1982  1.1  mrg   regrename_init (false);
   1983  1.1  mrg 
   1984  1.1  mrg   regrename_analyze (NULL, false);
   1985  1.1  mrg 
   1986  1.1  mrg   rename_chains ();
   1987  1.1  mrg 
   1988  1.1  mrg   regrename_finish ();
   1989  1.1  mrg 
   1990  1.1  mrg   return 0;
   1991  1.1  mrg }
   1992  1.1  mrg 
   1993  1.1  mrg namespace {
   1995  1.1  mrg 
   1996  1.1  mrg const pass_data pass_data_regrename =
   1997  1.1  mrg {
   1998  1.1  mrg   RTL_PASS, /* type */
   1999  1.1  mrg   "rnreg", /* name */
   2000  1.1  mrg   OPTGROUP_NONE, /* optinfo_flags */
   2001  1.1  mrg   TV_RENAME_REGISTERS, /* tv_id */
   2002  1.1  mrg   0, /* properties_required */
   2003  1.1  mrg   0, /* properties_provided */
   2004  1.1  mrg   0, /* properties_destroyed */
   2005  1.1  mrg   0, /* todo_flags_start */
   2006  1.1  mrg   TODO_df_finish, /* todo_flags_finish */
   2007  1.1  mrg };
   2008  1.1  mrg 
   2009  1.1  mrg class pass_regrename : public rtl_opt_pass
   2010  1.1  mrg {
   2011  1.1  mrg public:
   2012  1.1  mrg   pass_regrename (gcc::context *ctxt)
   2013  1.1  mrg     : rtl_opt_pass (pass_data_regrename, ctxt)
   2014  1.1  mrg   {}
   2015  1.1  mrg 
   2016  1.1  mrg   /* opt_pass methods: */
   2017  1.1  mrg   virtual bool gate (function *)
   2018  1.1  mrg     {
   2019  1.1  mrg       return (optimize > 0 && (flag_rename_registers));
   2020  1.1  mrg     }
   2021  1.1  mrg 
   2022  1.1  mrg   virtual unsigned int execute (function *) { return regrename_optimize (); }
   2023  1.1  mrg 
   2024  1.1  mrg }; // class pass_regrename
   2025  1.1  mrg 
   2026  1.1  mrg } // anon namespace
   2027  1.1  mrg 
   2028  1.1  mrg rtl_opt_pass *
   2029  1.1  mrg make_pass_regrename (gcc::context *ctxt)
   2030  1.1  mrg {
   2031             return new pass_regrename (ctxt);
   2032           }
   2033