LCOV - code coverage report
Current view: top level - gcc - ira-costs.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.6 % 1413 1308
Test Date: 2026-07-11 15:47:05 Functions: 97.2 % 36 35
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* IRA hard register and memory cost calculation for allocnos or pseudos.
       2              :    Copyright (C) 2006-2026 Free Software Foundation, Inc.
       3              :    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify it under
       8              : the terms of the GNU General Public License as published by the Free
       9              : Software Foundation; either version 3, or (at your option) any later
      10              : version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15              : for more details.
      16              : 
      17              : You should have received a copy of the GNU General Public License
      18              : along with GCC; see the file COPYING3.  If not see
      19              : <http://www.gnu.org/licenses/>.  */
      20              : 
      21              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "backend.h"
      25              : #include "target.h"
      26              : #include "rtl.h"
      27              : #include "tree.h"
      28              : #include "predict.h"
      29              : #include "memmodel.h"
      30              : #include "tm_p.h"
      31              : #include "insn-config.h"
      32              : #include "regs.h"
      33              : #include "regset.h"
      34              : #include "ira.h"
      35              : #include "ira-int.h"
      36              : #include "addresses.h"
      37              : #include "reload.h"
      38              : #include "print-rtl.h"
      39              : 
      40              : /* The flags is set up every time when we calculate pseudo register
      41              :    classes through function ira_set_pseudo_classes.  */
      42              : static bool pseudo_classes_defined_p = false;
      43              : 
      44              : /* TRUE if we work with allocnos.  Otherwise we work with pseudos.  */
      45              : static bool allocno_p;
      46              : 
      47              : /* Number of elements in array `costs'.  */
      48              : static int cost_elements_num;
      49              : 
      50              : /* The `costs' struct records the cost of using hard registers of each
      51              :    class considered for the calculation and of using memory for each
      52              :    allocno or pseudo.  */
      53              : struct costs
      54              : {
      55              :   int mem_cost;
      56              :   /* Costs for register classes start here.  We process only some
      57              :      allocno classes.  */
      58              :   int cost[1];
      59              : };
      60              : 
      61              : #define max_struct_costs_size \
      62              :   (this_target_ira_int->x_max_struct_costs_size)
      63              : #define init_cost \
      64              :   (this_target_ira_int->x_init_cost)
      65              : #define temp_costs \
      66              :   (this_target_ira_int->x_temp_costs)
      67              : #define op_costs \
      68              :   (this_target_ira_int->x_op_costs)
      69              : #define this_op_costs \
      70              :   (this_target_ira_int->x_this_op_costs)
      71              : 
      72              : /* Costs of each class for each allocno or pseudo.  */
      73              : static struct costs *costs;
      74              : 
      75              : /* Accumulated costs of each class for each allocno.  */
      76              : static struct costs *total_allocno_costs;
      77              : 
      78              : /* It is the current size of struct costs.  */
      79              : static size_t struct_costs_size;
      80              : 
      81              : /* Return pointer to structure containing costs of allocno or pseudo
      82              :    with given NUM in array ARR.  */
      83              : #define COSTS(arr, num) \
      84              :   ((struct costs *) ((char *) (arr) + (num) * struct_costs_size))
      85              : 
      86              : /* Return index in COSTS when processing reg with REGNO.  */
      87              : #define COST_INDEX(regno) (allocno_p                                         \
      88              :                            ? ALLOCNO_NUM (ira_curr_regno_allocno_map[regno]) \
      89              :                            : (int) regno)
      90              : 
      91              : /* Record register class preferences of each allocno or pseudo.  Null
      92              :    value means no preferences.  It happens on the 1st iteration of the
      93              :    cost calculation.  */
      94              : static enum reg_class *pref;
      95              : 
      96              : /* Allocated buffers for pref.  */
      97              : static enum reg_class *pref_buffer;
      98              : 
      99              : /* Record allocno class of each allocno with the same regno.  */
     100              : static enum reg_class *regno_aclass;
     101              : 
     102              : /* Record cost gains for not allocating a register with an invariant
     103              :    equivalence.  */
     104              : static int *regno_equiv_gains;
     105              : 
     106              : /* Execution frequency of the current insn.  */
     107              : static int frequency;
     108              : 
     109              : 
     110              : 
     111              : /* Info about reg classes whose costs are calculated for a pseudo.  */
     112              : struct cost_classes
     113              : {
     114              :   /* Number of the cost classes in the subsequent array.  */
     115              :   int num;
     116              :   /* Container of the cost classes.  */
     117              :   enum reg_class classes[N_REG_CLASSES];
     118              :   /* Map reg class -> index of the reg class in the previous array.
     119              :      -1 if it is not a cost class.  */
     120              :   int index[N_REG_CLASSES];
     121              :   /* Map hard regno index of first class in array CLASSES containing
     122              :      the hard regno, -1 otherwise.  */
     123              :   int hard_regno_index[FIRST_PSEUDO_REGISTER];
     124              : };
     125              : 
     126              : /* Types of pointers to the structure above.  */
     127              : typedef struct cost_classes *cost_classes_t;
     128              : typedef const struct cost_classes *const_cost_classes_t;
     129              : 
     130              : /* Info about cost classes for each pseudo.  */
     131              : static cost_classes_t *regno_cost_classes;
     132              : 
     133              : /* Helper for cost_classes hashing.  */
     134              : 
     135              : struct cost_classes_hasher : pointer_hash <cost_classes>
     136              : {
     137              :   static inline hashval_t hash (const cost_classes *);
     138              :   static inline bool equal (const cost_classes *, const cost_classes *);
     139              :   static inline void remove (cost_classes *);
     140              : };
     141              : 
     142              : /* Returns hash value for cost classes info HV.  */
     143              : inline hashval_t
     144    110747854 : cost_classes_hasher::hash (const cost_classes *hv)
     145              : {
     146    110747854 :   return iterative_hash (&hv->classes, sizeof (enum reg_class) * hv->num, 0);
     147              : }
     148              : 
     149              : /* Compares cost classes info HV1 and HV2.  */
     150              : inline bool
     151    102645405 : cost_classes_hasher::equal (const cost_classes *hv1, const cost_classes *hv2)
     152              : {
     153    102645405 :   return (hv1->num == hv2->num
     154    102645405 :           && memcmp (hv1->classes, hv2->classes,
     155     52904943 :                      sizeof (enum reg_class) * hv1->num) == 0);
     156              : }
     157              : 
     158              : /* Delete cost classes info V from the hash table.  */
     159              : inline void
     160      6096465 : cost_classes_hasher::remove (cost_classes *v)
     161              : {
     162      6096465 :   ira_free (v);
     163      6096465 : }
     164              : 
     165              : /* Hash table of unique cost classes.  */
     166              : static hash_table<cost_classes_hasher> *cost_classes_htab;
     167              : 
     168              : /* Map allocno class -> cost classes for pseudo of given allocno
     169              :    class.  */
     170              : static cost_classes_t cost_classes_aclass_cache[N_REG_CLASSES];
     171              : 
     172              : /* Map mode -> cost classes for pseudo of give mode.  */
     173              : static cost_classes_t cost_classes_mode_cache[MAX_MACHINE_MODE];
     174              : 
     175              : /* Cost classes that include all classes in ira_important_classes.  */
     176              : static cost_classes all_cost_classes;
     177              : 
     178              : /* Use the array of classes in CLASSES_PTR to fill out the rest of
     179              :    the structure.  */
     180              : static void
     181      7631222 : complete_cost_classes (cost_classes_t classes_ptr)
     182              : {
     183    267092770 :   for (int i = 0; i < N_REG_CLASSES; i++)
     184    259461548 :     classes_ptr->index[i] = -1;
     185    709703646 :   for (int i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     186    702072424 :     classes_ptr->hard_regno_index[i] = -1;
     187    158010085 :   for (int i = 0; i < classes_ptr->num; i++)
     188              :     {
     189    150378863 :       enum reg_class cl = classes_ptr->classes[i];
     190    150378863 :       classes_ptr->index[cl] = i;
     191   1740386536 :       for (int j = ira_class_hard_regs_num[cl] - 1; j >= 0; j--)
     192              :         {
     193   1590007673 :           unsigned int hard_regno = ira_class_hard_regs[cl][j];
     194   1590007673 :           if (classes_ptr->hard_regno_index[hard_regno] < 0)
     195    302623682 :             classes_ptr->hard_regno_index[hard_regno] = i;
     196              :         }
     197              :     }
     198      7631222 : }
     199              : 
     200              : /* Initialize info about the cost classes for each pseudo.  */
     201              : static void
     202      1534757 : initiate_regno_cost_classes (void)
     203              : {
     204      1534757 :   int size = sizeof (cost_classes_t) * max_reg_num ();
     205              : 
     206      1534757 :   regno_cost_classes = (cost_classes_t *) ira_allocate (size);
     207      1534757 :   memset (regno_cost_classes, 0, size);
     208      1534757 :   memset (cost_classes_aclass_cache, 0,
     209              :           sizeof (cost_classes_t) * N_REG_CLASSES);
     210      1534757 :   memset (cost_classes_mode_cache, 0,
     211              :           sizeof (cost_classes_t) * MAX_MACHINE_MODE);
     212      1534757 :   cost_classes_htab = new hash_table<cost_classes_hasher> (200);
     213      1534757 :   all_cost_classes.num = ira_important_classes_num;
     214     49217007 :   for (int i = 0; i < ira_important_classes_num; i++)
     215     47682250 :     all_cost_classes.classes[i] = ira_important_classes[i];
     216      1534757 :   complete_cost_classes (&all_cost_classes);
     217      1534757 : }
     218              : 
     219              : /* Create new cost classes from cost classes FROM and set up members
     220              :    index and hard_regno_index.  Return the new classes.  The function
     221              :    implements some common code of two functions
     222              :    setup_regno_cost_classes_by_aclass and
     223              :    setup_regno_cost_classes_by_mode.  */
     224              : static cost_classes_t
     225      6096465 : setup_cost_classes (cost_classes_t from)
     226              : {
     227      6096465 :   cost_classes_t classes_ptr;
     228              : 
     229      6096465 :   classes_ptr = (cost_classes_t) ira_allocate (sizeof (struct cost_classes));
     230      6096465 :   classes_ptr->num = from->num;
     231    108793078 :   for (int i = 0; i < from->num; i++)
     232    102696613 :     classes_ptr->classes[i] = from->classes[i];
     233      6096465 :   complete_cost_classes (classes_ptr);
     234      6096465 :   return classes_ptr;
     235              : }
     236              : 
     237              : /* Return a version of FULL that only considers registers in REGS that are
     238              :    valid for mode MODE.  Both FULL and the returned class are globally
     239              :    allocated.  */
     240              : static cost_classes_t
     241     54867634 : restrict_cost_classes (cost_classes_t full, machine_mode mode,
     242              :                        const_hard_reg_set regs)
     243              : {
     244     54867634 :   static struct cost_classes narrow;
     245     54867634 :   int map[N_REG_CLASSES];
     246     54867634 :   narrow.num = 0;
     247   1597937730 :   for (int i = 0; i < full->num; i++)
     248              :     {
     249              :       /* Assume that we'll drop the class.  */
     250   1543070096 :       map[i] = -1;
     251              : 
     252              :       /* Ignore classes that are too small for the mode.  */
     253   1543070096 :       enum reg_class cl = full->classes[i];
     254   1543070096 :       if (!contains_reg_of_mode[cl][mode])
     255    307879907 :         continue;
     256              : 
     257              :       /* Calculate the set of registers in CL that belong to REGS and
     258              :          are valid for MODE.  */
     259   1254080200 :       HARD_REG_SET valid_for_cl = reg_class_contents[cl] & regs;
     260   2508160400 :       valid_for_cl &= ~(ira_prohibited_class_mode_regs[cl][mode]
     261   1254080200 :                         | ira_no_alloc_regs);
     262   2508160400 :       if (hard_reg_set_empty_p (valid_for_cl))
     263     18890011 :         continue;
     264              : 
     265              :       /* Don't use this class if the set of valid registers is a subset
     266              :          of an existing class.  For example, suppose we have two classes
     267              :          GR_REGS and FR_REGS and a union class GR_AND_FR_REGS.  Suppose
     268              :          that the mode changes allowed by FR_REGS are not as general as
     269              :          the mode changes allowed by GR_REGS.
     270              : 
     271              :          In this situation, the mode changes for GR_AND_FR_REGS could
     272              :          either be seen as the union or the intersection of the mode
     273              :          changes allowed by the two subclasses.  The justification for
     274              :          the union-based definition would be that, if you want a mode
     275              :          change that's only allowed by GR_REGS, you can pick a register
     276              :          from the GR_REGS subclass.  The justification for the
     277              :          intersection-based definition would be that every register
     278              :          from the class would allow the mode change.
     279              : 
     280              :          However, if we have a register that needs to be in GR_REGS,
     281              :          using GR_AND_FR_REGS with the intersection-based definition
     282              :          would be too pessimistic, since it would bring in restrictions
     283              :          that only apply to FR_REGS.  Conversely, if we have a register
     284              :          that needs to be in FR_REGS, using GR_AND_FR_REGS with the
     285              :          union-based definition would lose the extra restrictions
     286              :          placed on FR_REGS.  GR_AND_FR_REGS is therefore only useful
     287              :          for cases where GR_REGS and FP_REGS are both valid.  */
     288              :       int pos;
     289  12587019140 :       for (pos = 0; pos < narrow.num; ++pos)
     290              :         {
     291  11783026961 :           enum reg_class cl2 = narrow.classes[pos];
     292  23566053922 :           if (hard_reg_set_subset_p (valid_for_cl, reg_class_contents[cl2]))
     293              :             break;
     294              :         }
     295   1235190189 :       map[i] = pos;
     296   1235190189 :       if (pos == narrow.num)
     297              :         {
     298              :           /* If several classes are equivalent, prefer to use the one
     299              :              that was chosen as the allocno class.  */
     300    803992179 :           enum reg_class cl2 = ira_allocno_class_translate[cl];
     301    803992179 :           if (ira_class_hard_regs_num[cl] == ira_class_hard_regs_num[cl2])
     302    803992179 :             cl = cl2;
     303    803992179 :           narrow.classes[narrow.num++] = cl;
     304              :         }
     305              :     }
     306     54867634 :   if (narrow.num == full->num)
     307              :     return full;
     308              : 
     309     54866798 :   cost_classes **slot = cost_classes_htab->find_slot (&narrow, INSERT);
     310     54866798 :   if (*slot == NULL)
     311              :     {
     312      4153556 :       cost_classes_t classes = setup_cost_classes (&narrow);
     313              :       /* Map equivalent classes to the representative that we chose above.  */
     314    133361088 :       for (int i = 0; i < ira_important_classes_num; i++)
     315              :         {
     316    129207532 :           enum reg_class cl = ira_important_classes[i];
     317    129207532 :           int index = full->index[cl];
     318    129207532 :           if (index >= 0)
     319    114954339 :             classes->index[cl] = map[index];
     320              :         }
     321      4153556 :       *slot = classes;
     322              :     }
     323     54866798 :   return *slot;
     324              : }
     325              : 
     326              : /* Setup cost classes for pseudo REGNO whose allocno class is ACLASS.
     327              :    This function is used when we know an initial approximation of
     328              :    allocno class of the pseudo already, e.g. on the second iteration
     329              :    of class cost calculation or after class cost calculation in
     330              :    register-pressure sensitive insn scheduling or register-pressure
     331              :    sensitive loop-invariant motion.  */
     332              : static void
     333     49790896 : setup_regno_cost_classes_by_aclass (int regno, enum reg_class aclass)
     334              : {
     335     49790896 :   static struct cost_classes classes;
     336     49790896 :   cost_classes_t classes_ptr;
     337     49790896 :   enum reg_class cl;
     338     49790896 :   int i;
     339     49790896 :   cost_classes **slot;
     340     49790896 :   HARD_REG_SET temp, temp2;
     341     49790896 :   bool exclude_p;
     342              : 
     343     49790896 :   if ((classes_ptr = cost_classes_aclass_cache[aclass]) == NULL)
     344              :     {
     345      4126732 :       temp = reg_class_contents[aclass] & ~ira_no_alloc_regs;
     346              :       /* We exclude classes from consideration which are subsets of
     347              :          ACLASS only if ACLASS is an uniform class.  */
     348      4126732 :       exclude_p = ira_uniform_class_p[aclass];
     349      4126732 :       classes.num = 0;
     350    132455129 :       for (i = 0; i < ira_important_classes_num; i++)
     351              :         {
     352    128328397 :           cl = ira_important_classes[i];
     353    128328397 :           if (exclude_p)
     354              :             {
     355              :               /* Exclude non-uniform classes which are subsets of
     356              :                  ACLASS.  */
     357     91573526 :               temp2 = reg_class_contents[cl] & ~ira_no_alloc_regs;
     358    183147052 :               if (hard_reg_set_subset_p (temp2, temp) && cl != aclass)
     359     10795584 :                 continue;
     360              :             }
     361    117532813 :           classes.classes[classes.num++] = cl;
     362              :         }
     363      4126732 :       slot = cost_classes_htab->find_slot (&classes, INSERT);
     364      4126732 :       if (*slot == NULL)
     365              :         {
     366      1942909 :           classes_ptr = setup_cost_classes (&classes);
     367      1942909 :           *slot = classes_ptr;
     368              :         }
     369      4126732 :       classes_ptr = cost_classes_aclass_cache[aclass] = (cost_classes_t) *slot;
     370              :     }
     371     49790896 :   if (regno_reg_rtx[regno] != NULL_RTX)
     372              :     {
     373              :       /* Restrict the classes to those that are valid for REGNO's mode
     374              :          (which might for example exclude singleton classes if the mode
     375              :          requires two registers).  Also restrict the classes to those that
     376              :          are valid for subregs of REGNO.  */
     377     49187316 :       const HARD_REG_SET *valid_regs = valid_mode_changes_for_regno (regno);
     378     49187316 :       if (!valid_regs)
     379     47753901 :         valid_regs = &reg_class_contents[ALL_REGS];
     380     49187316 :       classes_ptr = restrict_cost_classes (classes_ptr,
     381     49187316 :                                            PSEUDO_REGNO_MODE (regno),
     382              :                                            *valid_regs);
     383              :     }
     384     49790896 :   regno_cost_classes[regno] = classes_ptr;
     385     49790896 : }
     386              : 
     387              : /* Setup cost classes for pseudo REGNO with MODE.  Usage of MODE can
     388              :    decrease number of cost classes for the pseudo, if hard registers
     389              :    of some important classes cannot hold a value of MODE.  So the
     390              :    pseudo cannot get hard register of some important classes and cost
     391              :    calculation for such important classes is only wasting CPU
     392              :    time.  */
     393              : static void
     394     68034086 : setup_regno_cost_classes_by_mode (int regno, machine_mode mode)
     395              : {
     396     68034086 :   if (const HARD_REG_SET *valid_regs = valid_mode_changes_for_regno (regno))
     397      1881009 :     regno_cost_classes[regno] = restrict_cost_classes (&all_cost_classes,
     398              :                                                        mode, *valid_regs);
     399              :   else
     400              :     {
     401     66153077 :       if (cost_classes_mode_cache[mode] == NULL)
     402      3799309 :         cost_classes_mode_cache[mode]
     403      3799309 :           = restrict_cost_classes (&all_cost_classes, mode,
     404      3799309 :                                    reg_class_contents[ALL_REGS]);
     405     66153077 :       regno_cost_classes[regno] = cost_classes_mode_cache[mode];
     406              :     }
     407     68034086 : }
     408              : 
     409              : /* Finalize info about the cost classes for each pseudo.  */
     410              : static void
     411      1534757 : finish_regno_cost_classes (void)
     412              : {
     413      1534757 :   ira_free (regno_cost_classes);
     414      1534757 :   delete cost_classes_htab;
     415      1534757 :   cost_classes_htab = NULL;
     416      1534757 : }
     417              : 
     418              : 
     419              : 
     420              : /* Compute the cost of loading X into (if TO_P is TRUE) or from (if
     421              :    TO_P is FALSE) a register of class RCLASS in mode MODE.  X must not
     422              :    be a pseudo register.  */
     423              : static int
     424    384655318 : copy_cost (rtx x, machine_mode mode, reg_class_t rclass, bool to_p,
     425              :            secondary_reload_info *prev_sri)
     426              : {
     427    384655318 :   secondary_reload_info sri;
     428    384655318 :   reg_class_t secondary_class = NO_REGS;
     429              : 
     430              :   /* If X is a SCRATCH, there is actually nothing to move since we are
     431              :      assuming optimal allocation.  */
     432    384655318 :   if (GET_CODE (x) == SCRATCH)
     433              :     return 0;
     434              : 
     435              :   /* Get the class we will actually use for a reload.  */
     436    384645773 :   rclass = targetm.preferred_reload_class (x, rclass);
     437              : 
     438              :   /* If we need a secondary reload for an intermediate, the cost is
     439              :      that to load the input into the intermediate register, then to
     440              :      copy it.  */
     441    384645773 :   sri.prev_sri = prev_sri;
     442    384645773 :   sri.extra_cost = 0;
     443              :   /* PR 68770: Secondary reload might examine the t_icode field.  */
     444    384645773 :   sri.t_icode = CODE_FOR_nothing;
     445              : 
     446    384645773 :   secondary_class = targetm.secondary_reload (to_p, x, rclass, mode, &sri);
     447              : 
     448    384645773 :   if (secondary_class != NO_REGS)
     449              :     {
     450       173868 :       ira_init_register_move_cost_if_necessary (mode);
     451       173868 :       return (ira_register_move_cost[mode][(int) secondary_class][(int) rclass]
     452       173868 :               + sri.extra_cost
     453       173868 :               + copy_cost (x, mode, secondary_class, to_p, &sri));
     454              :     }
     455              : 
     456              :   /* For memory, use the memory move cost, for (hard) registers, use
     457              :      the cost to move between the register classes, and use 2 for
     458              :      everything else (constants).  */
     459    384471905 :   if (MEM_P (x) || rclass == NO_REGS)
     460    239891074 :     return sri.extra_cost
     461    239891074 :            + ira_memory_move_cost[mode][(int) rclass][to_p != 0];
     462    144580831 :   else if (REG_P (x))
     463              :     {
     464     46916580 :       reg_class_t x_class = REGNO_REG_CLASS (REGNO (x));
     465              : 
     466     46916580 :       ira_init_register_move_cost_if_necessary (mode);
     467     46916580 :       return (sri.extra_cost
     468     46916580 :               + ira_register_move_cost[mode][(int) x_class][(int) rclass]);
     469              :     }
     470              :   else
     471              :     /* If this is a constant, we may eventually want to call rtx_cost
     472              :        here.  */
     473     97664251 :     return sri.extra_cost + COSTS_N_INSNS (1);
     474              : }
     475              : 
     476              : 
     477              : 
     478              : /* Record the cost of using memory or hard registers of various
     479              :    classes for the operands in INSN.
     480              : 
     481              :    N_ALTS is the number of alternatives.
     482              :    N_OPS is the number of operands.
     483              :    OPS is an array of the operands.
     484              :    MODES are the modes of the operands, in case any are VOIDmode.
     485              :    CONSTRAINTS are the constraints to use for the operands.  This array
     486              :    is modified by this procedure.
     487              : 
     488              :    This procedure works alternative by alternative.  For each
     489              :    alternative we assume that we will be able to allocate all allocnos
     490              :    to their ideal register class and calculate the cost of using that
     491              :    alternative.  Then we compute, for each operand that is a
     492              :    pseudo-register, the cost of having the allocno allocated to each
     493              :    register class and using it in that alternative.  To this cost is
     494              :    added the cost of the alternative.
     495              : 
     496              :    The cost of each class for this insn is its lowest cost among all
     497              :    the alternatives.  */
     498              : static void
     499    141444082 : record_reg_classes (int n_alts, int n_ops, rtx *ops,
     500              :                     machine_mode *modes, const char **constraints,
     501              :                     rtx_insn *insn, enum reg_class *pref)
     502              : {
     503    141444082 :   int alt;
     504    141444082 :   int i, j, k;
     505    141444082 :   int insn_allows_mem[MAX_RECOG_OPERANDS];
     506    141444082 :   move_table *move_in_cost, *move_out_cost;
     507    141444082 :   short (*mem_cost)[2];
     508    141444082 :   const char *p;
     509              : 
     510    141444082 :   if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
     511              :     {
     512            0 :       fprintf (ira_dump_file, "    Processing insn %u", INSN_UID (insn));
     513            0 :       if (INSN_CODE (insn) >= 0
     514            0 :           && (p = get_insn_name (INSN_CODE (insn))) != NULL)
     515            0 :         fprintf (ira_dump_file, " {%s}", p);
     516            0 :       fprintf (ira_dump_file, " (freq=%d)\n",
     517            0 :                REG_FREQ_FROM_BB (BLOCK_FOR_INSN (insn)));
     518            0 :       dump_insn_slim (ira_dump_file, insn);
     519              :   }
     520              : 
     521    465943164 :   for (i = 0; i < n_ops; i++)
     522    324499082 :     insn_allows_mem[i] = 0;
     523              : 
     524              :   /* Process each alternative, each time minimizing an operand's cost
     525              :      with the cost for each operand in that alternative.  */
     526    141444082 :   alternative_mask preferred = get_preferred_alternatives (insn);
     527   1628675362 :   for (alt = 0; alt < n_alts; alt++)
     528              :     {
     529   1487231280 :       enum reg_class classes[MAX_RECOG_OPERANDS];
     530   1487231280 :       int allows_mem[MAX_RECOG_OPERANDS];
     531   1487231280 :       enum reg_class rclass;
     532   1487231280 :       int alt_fail = 0;
     533   1487231280 :       int alt_cost = 0, op_cost_add;
     534              : 
     535   1487231280 :       if (!TEST_BIT (preferred, alt))
     536              :         {
     537   1615696509 :           for (i = 0; i < recog_data.n_operands; i++)
     538   2251622114 :             constraints[i] = skip_alternative (constraints[i]);
     539              : 
     540    984309253 :           continue;
     541              :         }
     542              : 
     543    997345828 :       if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
     544              :         {
     545            0 :           fprintf (ira_dump_file, "      Alt %d:", alt);
     546            0 :           for (i = 0; i < n_ops; i++)
     547              :             {
     548            0 :               p = constraints[i];
     549            0 :               if (*p == '\0')
     550            0 :                 continue;
     551            0 :               fprintf (ira_dump_file, "  (%d) ", i);
     552            0 :               for (; *p != '\0' && *p != ',' && *p != '#'; p++)
     553            0 :                 fputc (*p, ira_dump_file);
     554              :             }
     555            0 :           fprintf (ira_dump_file, "\n");
     556              :         }
     557              : 
     558   2365806607 :       for (i = 0; i < n_ops; i++)
     559              :         {
     560   1862884580 :           unsigned char c;
     561   1862884580 :           const char *p = constraints[i];
     562   1862884580 :           rtx op = ops[i];
     563   1862884580 :           machine_mode mode = modes[i];
     564   1862884580 :           int allows_addr = 0;
     565   1862884580 :           int win = 0;
     566              : 
     567              :           /* Initially show we know nothing about the register class.  */
     568   1862884580 :           classes[i] = NO_REGS;
     569   1862884580 :           allows_mem[i] = 0;
     570              : 
     571              :           /* If this operand has no constraints at all, we can
     572              :              conclude nothing about it since anything is valid.  */
     573   1862884580 :           if (*p == 0)
     574              :             {
     575     30082956 :               if (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER)
     576            3 :                 memset (this_op_costs[i], 0, struct_costs_size);
     577     30082956 :               continue;
     578              :             }
     579              : 
     580              :           /* If this alternative is only relevant when this operand
     581              :              matches a previous operand, we do different things
     582              :              depending on whether this operand is a allocno-reg or not.
     583              :              We must process any modifiers for the operand before we
     584              :              can make this test.  */
     585   1935853690 :           while (*p == '%' || *p == '=' || *p == '+' || *p == '&')
     586    103052066 :             p++;
     587              : 
     588   1832801624 :           if (p[0] >= '0' && p[0] <= '0' + i)
     589              :             {
     590              :               /* Copy class and whether memory is allowed from the
     591              :                  matching alternative.  Then perform any needed cost
     592              :                  computations and/or adjustments.  */
     593     97665867 :               j = p[0] - '0';
     594     97665867 :               classes[i] = classes[j];
     595     97665867 :               allows_mem[i] = allows_mem[j];
     596     97665867 :               if (allows_mem[i])
     597     46320549 :                 insn_allows_mem[i] = 1;
     598              : 
     599     97665867 :               if (! REG_P (op) || REGNO (op) < FIRST_PSEUDO_REGISTER)
     600              :                 {
     601              :                   /* If this matches the other operand, we have no
     602              :                      added cost and we win.  */
     603     50093165 :                   if (rtx_equal_p (ops[j], op))
     604   1832801624 :                     win = 1;
     605              :                   /* If we can put the other operand into a register,
     606              :                      add to the cost of this alternative the cost to
     607              :                      copy this operand to the register used for the
     608              :                      other operand.  */
     609     34337661 :                   else if (classes[j] != NO_REGS)
     610              :                     {
     611     34165848 :                       alt_cost += copy_cost (op, mode, classes[j], 1, NULL);
     612     34165848 :                       win = 1;
     613              :                     }
     614              :                 }
     615     47572702 :               else if (! REG_P (ops[j])
     616     47572702 :                        || REGNO (ops[j]) < FIRST_PSEUDO_REGISTER)
     617              :                 {
     618              :                   /* This op is an allocno but the one it matches is
     619              :                      not.  */
     620              : 
     621              :                   /* If we can't put the other operand into a
     622              :                      register, this alternative can't be used.  */
     623              : 
     624       161153 :                   if (classes[j] == NO_REGS)
     625              :                     {
     626   1832801624 :                       alt_fail = 1;
     627              :                     }
     628              :                   else
     629              :                     /* Otherwise, add to the cost of this alternative the cost
     630              :                        to copy the other operand to the hard register used for
     631              :                        this operand.  */
     632              :                     {
     633       151187 :                       alt_cost += copy_cost (ops[j], mode, classes[j], 1, NULL);
     634              :                     }
     635              :                 }
     636              :               else
     637              :                 {
     638              :                   /* The costs of this operand are not the same as the
     639              :                      other operand since move costs are not symmetric.
     640              :                      Moreover, if we cannot tie them, this alternative
     641              :                      needs to do a copy, which is one insn.  */
     642     47411549 :                   struct costs *pp = this_op_costs[i];
     643     47411549 :                   int *pp_costs = pp->cost;
     644     47411549 :                   cost_classes_t cost_classes_ptr
     645     47411549 :                     = regno_cost_classes[REGNO (op)];
     646     47411549 :                   enum reg_class *cost_classes = cost_classes_ptr->classes;
     647     47411549 :                   bool in_p = recog_data.operand_type[i] != OP_OUT;
     648     47411549 :                   bool out_p = recog_data.operand_type[i] != OP_IN;
     649     47411549 :                   enum reg_class op_class = classes[i];
     650              : 
     651     47411549 :                   ira_init_register_move_cost_if_necessary (mode);
     652     47411549 :                   if (! in_p)
     653              :                     {
     654        59787 :                       ira_assert (out_p);
     655        59787 :                       if (op_class == NO_REGS)
     656              :                         {
     657            0 :                           mem_cost = ira_memory_move_cost[mode];
     658            0 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     659              :                             {
     660            0 :                               rclass = cost_classes[k];
     661            0 :                               pp_costs[k] = mem_cost[rclass][0] * frequency;
     662              :                             }
     663              :                         }
     664              :                       else
     665              :                         {
     666        59787 :                           move_out_cost = ira_may_move_out_cost[mode];
     667       828106 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     668              :                             {
     669       768319 :                               rclass = cost_classes[k];
     670       768319 :                               pp_costs[k]
     671       768319 :                                 = move_out_cost[op_class][rclass] * frequency;
     672              :                             }
     673              :                         }
     674              :                     }
     675     47351762 :                   else if (! out_p)
     676              :                     {
     677     47351762 :                       ira_assert (in_p);
     678     47351762 :                       if (op_class == NO_REGS)
     679              :                         {
     680       396592 :                           mem_cost = ira_memory_move_cost[mode];
     681      5805693 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     682              :                             {
     683      5409101 :                               rclass = cost_classes[k];
     684      5409101 :                               pp_costs[k] = mem_cost[rclass][1] * frequency;
     685              :                             }
     686              :                         }
     687              :                       else
     688              :                         {
     689     46955170 :                           move_in_cost = ira_may_move_in_cost[mode];
     690    707785237 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     691              :                             {
     692    660830067 :                               rclass = cost_classes[k];
     693    660830067 :                               pp_costs[k]
     694    660830067 :                                 = move_in_cost[rclass][op_class] * frequency;
     695              :                             }
     696              :                         }
     697              :                     }
     698              :                   else
     699              :                     {
     700            0 :                       if (op_class == NO_REGS)
     701              :                         {
     702            0 :                           mem_cost = ira_memory_move_cost[mode];
     703            0 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     704              :                             {
     705            0 :                               rclass = cost_classes[k];
     706            0 :                               pp_costs[k] = ((mem_cost[rclass][0]
     707            0 :                                               + mem_cost[rclass][1])
     708            0 :                                              * frequency);
     709              :                             }
     710              :                         }
     711              :                       else
     712              :                         {
     713            0 :                           move_in_cost = ira_may_move_in_cost[mode];
     714            0 :                           move_out_cost = ira_may_move_out_cost[mode];
     715            0 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     716              :                             {
     717            0 :                               rclass = cost_classes[k];
     718            0 :                               pp_costs[k] = ((move_in_cost[rclass][op_class]
     719            0 :                                               + move_out_cost[op_class][rclass])
     720            0 :                                              * frequency);
     721              :                             }
     722              :                         }
     723              :                     }
     724              : 
     725     47411549 :                   if (op_class == NO_REGS)
     726              :                     /* Although we don't need insn to reload from
     727              :                        memory, still accessing memory is usually more
     728              :                        expensive than a register.  */
     729       396592 :                     pp->mem_cost = frequency;
     730              :                   else
     731              :                     /* If the alternative actually allows memory, make
     732              :                        things a bit cheaper since we won't need an
     733              :                        extra insn to load it.  */
     734     47014957 :                     pp->mem_cost
     735     47014957 :                       = ((out_p
     736     47014957 :                           ? ira_memory_move_cost[mode][op_class][0] : 0)
     737     47014957 :                          + (in_p
     738     47014957 :                             ? ira_memory_move_cost[mode][op_class][1] : 0)
     739     47014957 :                          - allows_mem[i]) * frequency;
     740              : 
     741              :                   /* If we have assigned a class to this allocno in
     742              :                      our first pass, add a cost to this alternative
     743              :                      corresponding to what we would add if this
     744              :                      allocno were not in the appropriate class.  */
     745     47411549 :                   if (pref)
     746              :                     {
     747     18059080 :                       enum reg_class pref_class = pref[COST_INDEX (REGNO (op))];
     748              : 
     749     18059080 :                       if (pref_class == NO_REGS)
     750              :                         {
     751       651777 :                           if (op_class != NO_REGS)
     752       648983 :                             alt_cost
     753       648983 :                               += ((out_p
     754       648983 :                                    ? ira_memory_move_cost[mode][op_class][0]
     755              :                                    : 0)
     756       648983 :                                   + (in_p
     757       648983 :                                      ? ira_memory_move_cost[mode][op_class][1]
     758              :                                      : 0));
     759              :                         }
     760     17407303 :                       else if (op_class == NO_REGS)
     761       157621 :                         alt_cost
     762       157621 :                           += ((out_p
     763       157621 :                                ? ira_memory_move_cost[mode][pref_class][0]
     764              :                                : 0)
     765       157621 :                               + (in_p
     766       157621 :                                  ? ira_memory_move_cost[mode][pref_class][1]
     767              :                                  : 0));
     768     17249682 :                       else if (ira_reg_class_intersect
     769     17249682 :                                [pref_class][op_class] == NO_REGS)
     770       150380 :                         alt_cost += (ira_register_move_cost
     771       150380 :                                      [mode][pref_class][op_class]);
     772              :                     }
     773     47411549 :                   if (REGNO (ops[i]) != REGNO (ops[j])
     774     47411549 :                       && ! find_reg_note (insn, REG_DEAD, op))
     775     13244872 :                     alt_cost += 2;
     776              : 
     777     47411549 :                   p++;
     778              :                 }
     779              :             }
     780              : 
     781              :           /* Scan all the constraint letters.  See if the operand
     782              :              matches any of the constraints.  Collect the valid
     783              :              register classes and see if this operand accepts
     784              :              memory.  */
     785   4424354034 :           while ((c = *p))
     786              :             {
     787   4357888862 :               switch (c)
     788              :                 {
     789    324361203 :                 case '*':
     790              :                   /* Ignore the next letter for this pass.  */
     791    324361203 :                   c = *++p;
     792    324361203 :                   break;
     793              : 
     794            0 :                 case '^':
     795            0 :                   alt_cost += 2;
     796            0 :                   break;
     797              : 
     798    516209503 :                 case '?':
     799    516209503 :                   alt_cost += 2;
     800    516209503 :                   break;
     801              : 
     802     12828592 :                 case 'g':
     803     12828592 :                   if (MEM_P (op)
     804     12828592 :                       || (CONSTANT_P (op)
     805      5191695 :                           && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))))
     806              :                     win = 1;
     807     12828592 :                   insn_allows_mem[i] = allows_mem[i] = 1;
     808     12828592 :                   classes[i] = ira_reg_class_subunion[classes[i]][GENERAL_REGS];
     809     12828592 :                   break;
     810              : 
     811   3504489564 :                 default:
     812   3504489564 :                   enum constraint_num cn = lookup_constraint (p);
     813   3504489564 :                   enum reg_class cl;
     814   3504489564 :                   switch (get_constraint_type (cn))
     815              :                     {
     816   2849188412 :                     case CT_REGISTER:
     817   2849188412 :                       cl = reg_class_for_constraint (cn);
     818   1017469997 :                       if (cl != NO_REGS)
     819   1006920163 :                         classes[i] = ira_reg_class_subunion[classes[i]][cl];
     820              :                       break;
     821              : 
     822      4936228 :                     case CT_CONST_INT:
     823      4936228 :                       if (CONST_INT_P (op)
     824      4936228 :                           && insn_const_int_ok_for_constraint (INTVAL (op), cn))
     825              :                         win = 1;
     826              :                       break;
     827              : 
     828    280109142 :                     case CT_MEMORY:
     829    280109142 :                     case CT_RELAXED_MEMORY:
     830              :                       /* Every MEM can be reloaded to fit.  */
     831    280109142 :                       insn_allows_mem[i] = allows_mem[i] = 1;
     832    280109142 :                       if (MEM_P (op))
     833     80669996 :                         win = 1;
     834              :                       break;
     835              : 
     836     40516493 :                     case CT_SPECIAL_MEMORY:
     837     40516493 :                       insn_allows_mem[i] = allows_mem[i] = 1;
     838     40516493 :                       if (MEM_P (extract_mem_from_operand (op))
     839     40516493 :                           && constraint_satisfied_p (op, cn))
     840              :                         win = 1;
     841              :                       break;
     842              : 
     843      1140255 :                     case CT_ADDRESS:
     844              :                       /* Every address can be reloaded to fit.  */
     845      1140255 :                       allows_addr = 1;
     846      1140255 :                       if (address_operand (op, GET_MODE (op))
     847      1140255 :                           || constraint_satisfied_p (op, cn))
     848              :                         win = 1;
     849              :                       /* We know this operand is an address, so we
     850              :                          want it to be allocated to a hard register
     851              :                          that can be the base of an address,
     852              :                          i.e. BASE_REG_CLASS.  */
     853      1140255 :                       classes[i]
     854      2280510 :                         = ira_reg_class_subunion[classes[i]]
     855      1140255 :                           [base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
     856      1140255 :                                            ADDRESS, SCRATCH)];
     857      1140255 :                       break;
     858              : 
     859    328599034 :                     case CT_FIXED_FORM:
     860    328599034 :                       if (constraint_satisfied_p (op, cn))
     861   4357888862 :                         win = 1;
     862              :                       break;
     863              :                     }
     864              :                   break;
     865              :                 }
     866   4357888862 :               p += CONSTRAINT_LEN (c, p);
     867   4357888862 :               if (c == ',')
     868              :                 break;
     869              :             }
     870              : 
     871   1832801624 :           constraints[i] = p;
     872              : 
     873   1832801624 :           if (alt_fail)
     874              :             break;
     875              : 
     876              :           /* How we account for this operand now depends on whether it
     877              :              is a pseudo register or not.  If it is, we first check if
     878              :              any register classes are valid.  If not, we ignore this
     879              :              alternative, since we want to assume that all allocnos get
     880              :              allocated for register preferencing.  If some register
     881              :              class is valid, compute the costs of moving the allocno
     882              :              into that class.  */
     883   1832791658 :           if (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER)
     884              :             {
     885    827277596 :               if (classes[i] == NO_REGS && ! allows_mem[i])
     886              :                 {
     887              :                   /* We must always fail if the operand is a REG, but
     888              :                      we did not find a suitable class and memory is
     889              :                      not allowed.
     890              : 
     891              :                      Otherwise we may perform an uninitialized read
     892              :                      from this_op_costs after the `continue' statement
     893              :                      below.  */
     894              :                   alt_fail = 1;
     895              :                 }
     896              :               else
     897              :                 {
     898    620838392 :                   unsigned int regno = REGNO (op);
     899    620838392 :                   struct costs *pp = this_op_costs[i];
     900    620838392 :                   int *pp_costs = pp->cost;
     901    620838392 :                   cost_classes_t cost_classes_ptr = regno_cost_classes[regno];
     902    620838392 :                   enum reg_class *cost_classes = cost_classes_ptr->classes;
     903    620838392 :                   bool in_p = recog_data.operand_type[i] != OP_OUT;
     904    620838392 :                   bool out_p = recog_data.operand_type[i] != OP_IN;
     905    620838392 :                   enum reg_class op_class = classes[i];
     906              : 
     907    620838392 :                   ira_init_register_move_cost_if_necessary (mode);
     908    620838392 :                   if (! in_p)
     909              :                     {
     910    396878328 :                       ira_assert (out_p);
     911    396878328 :                       if (op_class == NO_REGS)
     912              :                         {
     913     72788668 :                           mem_cost = ira_memory_move_cost[mode];
     914   1127057295 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     915              :                             {
     916   1054268627 :                               rclass = cost_classes[k];
     917   1054268627 :                               pp_costs[k] = mem_cost[rclass][0] * frequency;
     918              :                             }
     919              :                         }
     920              :                       else
     921              :                         {
     922    324089660 :                           move_out_cost = ira_may_move_out_cost[mode];
     923   4920764074 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     924              :                             {
     925   4596674414 :                               rclass = cost_classes[k];
     926   4596674414 :                               pp_costs[k]
     927   4596674414 :                                 = move_out_cost[op_class][rclass] * frequency;
     928              :                             }
     929              :                         }
     930              :                     }
     931    223960064 :                   else if (! out_p)
     932              :                     {
     933    223946723 :                       ira_assert (in_p);
     934    223946723 :                       if (op_class == NO_REGS)
     935              :                         {
     936     16684648 :                           mem_cost = ira_memory_move_cost[mode];
     937    245761836 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     938              :                             {
     939    229077188 :                               rclass = cost_classes[k];
     940    229077188 :                               pp_costs[k] = mem_cost[rclass][1] * frequency;
     941              :                             }
     942              :                         }
     943              :                       else
     944              :                         {
     945    207262075 :                           move_in_cost = ira_may_move_in_cost[mode];
     946   3043421577 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     947              :                             {
     948   2836159502 :                               rclass = cost_classes[k];
     949   2836159502 :                               pp_costs[k]
     950   2836159502 :                                 = move_in_cost[rclass][op_class] * frequency;
     951              :                             }
     952              :                         }
     953              :                     }
     954              :                   else
     955              :                     {
     956        13341 :                       if (op_class == NO_REGS)
     957              :                         {
     958            0 :                           mem_cost = ira_memory_move_cost[mode];
     959            0 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     960              :                             {
     961            0 :                               rclass = cost_classes[k];
     962            0 :                               pp_costs[k] = ((mem_cost[rclass][0]
     963            0 :                                               + mem_cost[rclass][1])
     964            0 :                                              * frequency);
     965              :                             }
     966              :                         }
     967              :                       else
     968              :                         {
     969        13341 :                           move_in_cost = ira_may_move_in_cost[mode];
     970        13341 :                           move_out_cost = ira_may_move_out_cost[mode];
     971       157166 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     972              :                             {
     973       143825 :                               rclass = cost_classes[k];
     974       143825 :                               pp_costs[k] = ((move_in_cost[rclass][op_class]
     975       143825 :                                               + move_out_cost[op_class][rclass])
     976       143825 :                                              * frequency);
     977              :                             }
     978              :                         }
     979              :                     }
     980              : 
     981    620838392 :                   if (op_class == NO_REGS)
     982              :                     /* Although we don't need insn to reload from
     983              :                        memory, still accessing memory is usually more
     984              :                        expensive than a register.  */
     985     89473316 :                     pp->mem_cost = frequency;
     986              :                   else
     987              :                     /* If the alternative actually allows memory, make
     988              :                        things a bit cheaper since we won't need an
     989              :                        extra insn to load it.  */
     990    531365076 :                     pp->mem_cost
     991    531365076 :                       = ((out_p ? ira_memory_move_cost[mode][op_class][0] : 0)
     992    531365076 :                          + (in_p ? ira_memory_move_cost[mode][op_class][1] : 0)
     993    531365076 :                          - allows_mem[i]) * frequency;
     994              :                   /* If we have assigned a class to this allocno in
     995              :                      our first pass, add a cost to this alternative
     996              :                      corresponding to what we would add if this
     997              :                      allocno were not in the appropriate class.  */
     998    620838392 :                   if (pref)
     999              :                     {
    1000    226911394 :                       enum reg_class pref_class = pref[COST_INDEX (REGNO (op))];
    1001              : 
    1002    226911394 :                       if (pref_class == NO_REGS)
    1003              :                         {
    1004      4444444 :                           if (op_class != NO_REGS)
    1005      3596574 :                             alt_cost
    1006      3596574 :                               += ((out_p
    1007      3596574 :                                    ? ira_memory_move_cost[mode][op_class][0]
    1008              :                                    : 0)
    1009      3596574 :                                   + (in_p
    1010      3596574 :                                      ? ira_memory_move_cost[mode][op_class][1]
    1011              :                                      : 0));
    1012              :                         }
    1013    222466950 :                       else if (op_class == NO_REGS)
    1014     30460465 :                         alt_cost
    1015     30460465 :                           += ((out_p
    1016     30460465 :                                ? ira_memory_move_cost[mode][pref_class][0]
    1017              :                                : 0)
    1018     30460465 :                               + (in_p
    1019     30460465 :                                  ? ira_memory_move_cost[mode][pref_class][1]
    1020              :                                  : 0));
    1021    192006485 :                       else if (ira_reg_class_intersect[pref_class][op_class]
    1022              :                                == NO_REGS)
    1023     40909315 :                         alt_cost += (ira_register_move_cost
    1024     40909315 :                                      [mode][pref_class][op_class]);
    1025              :                     }
    1026              :                 }
    1027              :             }
    1028              : 
    1029              :           /* Otherwise, if this alternative wins, either because we
    1030              :              have already determined that or if we have a hard
    1031              :              register of the proper class, there is no cost for this
    1032              :              alternative.  */
    1033   1005514062 :           else if (win || (REG_P (op)
    1034    240800098 :                            && reg_fits_class_p (op, classes[i],
    1035    240800098 :                                                 0, GET_MODE (op))))
    1036              :             ;
    1037              : 
    1038              :           /* If registers are valid, the cost of this alternative
    1039              :              includes copying the object to and/or from a
    1040              :              register.  */
    1041    659448891 :           else if (classes[i] != NO_REGS)
    1042              :             {
    1043    350164391 :               if (recog_data.operand_type[i] != OP_OUT)
    1044    186974493 :                 alt_cost += copy_cost (op, mode, classes[i], 1, NULL);
    1045              : 
    1046    350164391 :               if (recog_data.operand_type[i] != OP_IN)
    1047    163189922 :                 alt_cost += copy_cost (op, mode, classes[i], 0, NULL);
    1048              :             }
    1049              :           /* The only other way this alternative can be used is if
    1050              :              this is a constant that could be placed into memory.  */
    1051    309284500 :           else if (CONSTANT_P (op) && (allows_addr || allows_mem[i]))
    1052     21309869 :             alt_cost += ira_memory_move_cost[mode][classes[i]][1];
    1053              :           else
    1054              :             alt_fail = 1;
    1055              : 
    1056              :           if (alt_fail)
    1057              :             break;
    1058              :         }
    1059              : 
    1060    997345828 :       if (alt_fail)
    1061              :         {
    1062              :           /* The loop above might have exited early once the failure
    1063              :              was seen.  Skip over the constraints for the remaining
    1064              :              operands.  */
    1065    494423801 :           i += 1;
    1066    793262650 :           for (; i < n_ops; ++i)
    1067    597677698 :             constraints[i] = skip_alternative (constraints[i]);
    1068    494423801 :           continue;
    1069              :         }
    1070              : 
    1071    502922027 :       op_cost_add = alt_cost * frequency;
    1072              :       /* Finally, update the costs with the information we've
    1073              :          calculated about this alternative.  */
    1074   1627124009 :       for (i = 0; i < n_ops; i++)
    1075   1124201982 :         if (REG_P (ops[i]) && REGNO (ops[i]) >= FIRST_PSEUDO_REGISTER)
    1076              :           {
    1077    474554111 :             int old_cost;
    1078    474554111 :             bool cost_change_p = false;
    1079    474554111 :             struct costs *pp = op_costs[i], *qq = this_op_costs[i];
    1080    474554111 :             int *pp_costs = pp->cost, *qq_costs = qq->cost;
    1081    474554111 :             int scale = 1 + (recog_data.operand_type[i] == OP_INOUT);
    1082    474554111 :             cost_classes_t cost_classes_ptr
    1083    474554111 :               = regno_cost_classes[REGNO (ops[i])];
    1084              : 
    1085    474554111 :             old_cost = pp->mem_cost;
    1086    474554111 :             pp->mem_cost = MIN (old_cost,
    1087              :                                 (qq->mem_cost + op_cost_add) * scale);
    1088              : 
    1089    474554111 :             if (ira_dump_file != NULL && internal_flag_ira_verbose > 5
    1090            0 :                 && pp->mem_cost < old_cost)
    1091              :               {
    1092            0 :                 cost_change_p = true;
    1093            0 :                 fprintf (ira_dump_file, "        op %d(r=%u) new costs MEM:%d",
    1094              :                          i, REGNO(ops[i]), pp->mem_cost);
    1095              :               }
    1096   7097746922 :             for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    1097              :               {
    1098   6623192811 :                 old_cost = pp_costs[k];
    1099   6623192811 :                 pp_costs[k]
    1100   6623192811 :                   = MIN (old_cost, (qq_costs[k] + op_cost_add) * scale);
    1101   6623192811 :                 if (ira_dump_file != NULL && internal_flag_ira_verbose > 5
    1102            0 :                     && pp_costs[k] < old_cost)
    1103              :                   {
    1104            0 :                     if (!cost_change_p)
    1105            0 :                       fprintf (ira_dump_file, "        op %d(r=%u) new costs",
    1106              :                                i, REGNO(ops[i]));
    1107            0 :                     cost_change_p = true;
    1108            0 :                     fprintf (ira_dump_file, " %s:%d",
    1109            0 :                              reg_class_names[cost_classes_ptr->classes[k]],
    1110              :                              pp_costs[k]);
    1111              :                   }
    1112              :               }
    1113    474554111 :             if (ira_dump_file != NULL && internal_flag_ira_verbose > 5
    1114            0 :                 && cost_change_p)
    1115            0 :               fprintf (ira_dump_file, "\n");
    1116              :           }
    1117              :     }
    1118              : 
    1119    141444082 :   if (allocno_p)
    1120    453482077 :     for (i = 0; i < n_ops; i++)
    1121              :       {
    1122    315806481 :         ira_allocno_t a;
    1123    315806481 :         rtx op = ops[i];
    1124              : 
    1125    315806481 :         if (! REG_P (op) || REGNO (op) < FIRST_PSEUDO_REGISTER)
    1126    183779441 :           continue;
    1127    132027040 :         a = ira_curr_regno_allocno_map [REGNO (op)];
    1128    132027040 :         if (! ALLOCNO_BAD_SPILL_P (a) && insn_allows_mem[i] == 0)
    1129     12235091 :           ALLOCNO_BAD_SPILL_P (a) = true;
    1130              :       }
    1131              : 
    1132    141444082 : }
    1133              : 
    1134              : 
    1135              : 
    1136              : /* Wrapper around REGNO_OK_FOR_INDEX_P, to allow pseudo registers.  */
    1137              : static inline bool
    1138       135525 : ok_for_index_p_nonstrict (rtx reg)
    1139              : {
    1140       135525 :   unsigned regno = REGNO (reg);
    1141              : 
    1142       135525 :   return regno >= FIRST_PSEUDO_REGISTER || REGNO_OK_FOR_INDEX_P (regno);
    1143              : }
    1144              : 
    1145              : /* A version of regno_ok_for_base_p for use here, when all
    1146              :    pseudo-registers should count as OK.  Arguments as for
    1147              :    regno_ok_for_base_p.  */
    1148              : static inline bool
    1149       137173 : ok_for_base_p_nonstrict (rtx reg, machine_mode mode, addr_space_t as,
    1150              :                          enum rtx_code outer_code, enum rtx_code index_code)
    1151              : {
    1152       137173 :   unsigned regno = REGNO (reg);
    1153              : 
    1154          824 :   if (regno >= FIRST_PSEUDO_REGISTER)
    1155              :     return true;
    1156          824 :   return ok_for_base_p_1 (regno, mode, as, outer_code, index_code);
    1157              : }
    1158              : 
    1159              : /* Record the pseudo registers we must reload into hard registers in a
    1160              :    subexpression of a memory address, X.
    1161              : 
    1162              :    If CONTEXT is 0, we are looking at the base part of an address,
    1163              :    otherwise we are looking at the index part.
    1164              : 
    1165              :    MODE and AS are the mode and address space of the memory reference;
    1166              :    OUTER_CODE and INDEX_CODE give the context that the rtx appears in.
    1167              :    These four arguments are passed down to base_reg_class.
    1168              : 
    1169              :    SCALE is twice the amount to multiply the cost by (it is twice so
    1170              :    we can represent half-cost adjustments).  */
    1171              : static void
    1172     94269742 : record_address_regs (machine_mode mode, addr_space_t as, rtx x,
    1173              :                      int context, enum rtx_code outer_code,
    1174              :                      enum rtx_code index_code, int scale)
    1175              : {
    1176     94269742 :   enum rtx_code code = GET_CODE (x);
    1177     94269742 :   enum reg_class rclass;
    1178              : 
    1179     94269742 :   if (context == 1)
    1180              :     rclass = INDEX_REG_CLASS;
    1181              :   else
    1182     87177360 :     rclass = base_reg_class (mode, as, outer_code, index_code);
    1183              : 
    1184     94269742 :   switch (code)
    1185              :     {
    1186              :     case CONST_INT:
    1187              :     case CONST:
    1188              :     case PC:
    1189              :     case SYMBOL_REF:
    1190              :     case LABEL_REF:
    1191              :       return;
    1192              : 
    1193     33148300 :     case PLUS:
    1194              :       /* When we have an address that is a sum, we must determine
    1195              :          whether registers are "base" or "index" regs.  If there is a
    1196              :          sum of two registers, we must choose one to be the "base".
    1197              :          Luckily, we can use the REG_POINTER to make a good choice
    1198              :          most of the time.  We only need to do this on machines that
    1199              :          can have two registers in an address and where the base and
    1200              :          index register classes are different.
    1201              : 
    1202              :          ??? This code used to set REGNO_POINTER_FLAG in some cases,
    1203              :          but that seems bogus since it should only be set when we are
    1204              :          sure the register is being used as a pointer.  */
    1205     33148300 :       {
    1206     33148300 :         rtx arg0 = XEXP (x, 0);
    1207     33148300 :         rtx arg1 = XEXP (x, 1);
    1208     33148300 :         enum rtx_code code0 = GET_CODE (arg0);
    1209     33148300 :         enum rtx_code code1 = GET_CODE (arg1);
    1210              : 
    1211              :         /* Look inside subregs.  */
    1212     33148300 :         if (code0 == SUBREG)
    1213        11922 :           arg0 = SUBREG_REG (arg0), code0 = GET_CODE (arg0);
    1214     33148300 :         if (code1 == SUBREG)
    1215         5547 :           arg1 = SUBREG_REG (arg1), code1 = GET_CODE (arg1);
    1216              : 
    1217              :         /* If index registers do not appear, or coincide with base registers,
    1218              :            just record registers in any non-constant operands.  We
    1219              :            assume here, as well as in the tests below, that all
    1220              :            addresses are in canonical form.  */
    1221     66296600 :         if (MAX_REGS_PER_ADDRESS == 1
    1222     33148300 :             || INDEX_REG_CLASS == base_reg_class (VOIDmode, as, PLUS, SCRATCH))
    1223              :           {
    1224            0 :             record_address_regs (mode, as, arg0, context, PLUS, code1, scale);
    1225            0 :             if (! CONSTANT_P (arg1))
    1226            0 :               record_address_regs (mode, as, arg1, context, PLUS, code0, scale);
    1227              :           }
    1228              : 
    1229              :         /* If the second operand is a constant integer, it doesn't
    1230              :            change what class the first operand must be.  */
    1231     33148300 :         else if (CONST_SCALAR_INT_P (arg1))
    1232     29750841 :           record_address_regs (mode, as, arg0, context, PLUS, code1, scale);
    1233              :         /* If the second operand is a symbolic constant, the first
    1234              :            operand must be an index register.  */
    1235      3397459 :         else if (code1 == SYMBOL_REF || code1 == CONST || code1 == LABEL_REF)
    1236       912265 :           record_address_regs (mode, as, arg0, 1, PLUS, code1, scale);
    1237              :         /* If both operands are registers but one is already a hard
    1238              :            register of index or reg-base class, give the other the
    1239              :            class that the hard register is not.  */
    1240      2485194 :         else if (code0 == REG && code1 == REG
    1241      1293716 :                  && REGNO (arg0) < FIRST_PSEUDO_REGISTER
    1242      2620949 :                  && (ok_for_base_p_nonstrict (arg0, mode, as, PLUS, REG)
    1243       134939 :                      || ok_for_index_p_nonstrict (arg0)))
    1244         2448 :           record_address_regs (mode, as, arg1,
    1245         2448 :                                ok_for_base_p_nonstrict (arg0, mode, as,
    1246              :                                                         PLUS, REG) ? 1 : 0,
    1247              :                                PLUS, REG, scale);
    1248      2484378 :         else if (code0 == REG && code1 == REG
    1249      1292900 :                  && REGNO (arg1) < FIRST_PSEUDO_REGISTER
    1250      2484972 :                  && (ok_for_base_p_nonstrict (arg1, mode, as, PLUS, REG)
    1251          586 :                      || ok_for_index_p_nonstrict (arg1)))
    1252           24 :           record_address_regs (mode, as, arg0,
    1253           24 :                                ok_for_base_p_nonstrict (arg1, mode, as,
    1254              :                                                         PLUS, REG) ? 1 : 0,
    1255              :                                PLUS, REG, scale);
    1256              :         /* If one operand is known to be a pointer, it must be the
    1257              :            base with the other operand the index.  Likewise if the
    1258              :            other operand is a MULT.  */
    1259      2484370 :         else if ((code0 == REG && REG_POINTER (arg0)) || code1 == MULT)
    1260              :           {
    1261      1075692 :             record_address_regs (mode, as, arg0, 0, PLUS, code1, scale);
    1262      1075692 :             record_address_regs (mode, as, arg1, 1, PLUS, code0, scale);
    1263              :           }
    1264      1408678 :         else if ((code1 == REG && REG_POINTER (arg1)) || code0 == MULT)
    1265              :           {
    1266      1030302 :             record_address_regs (mode, as, arg0, 1, PLUS, code1, scale);
    1267      1030302 :             record_address_regs (mode, as, arg1, 0, PLUS, code0, scale);
    1268              :           }
    1269              :         /* Otherwise, count equal chances that each might be a base or
    1270              :            index register.  This case should be rare.  */
    1271              :         else
    1272              :           {
    1273       378376 :             record_address_regs (mode, as, arg0, 0, PLUS, code1, scale / 2);
    1274       378376 :             record_address_regs (mode, as, arg0, 1, PLUS, code1, scale / 2);
    1275       378376 :             record_address_regs (mode, as, arg1, 0, PLUS, code0, scale / 2);
    1276       378376 :             record_address_regs (mode, as, arg1, 1, PLUS, code0, scale / 2);
    1277              :           }
    1278              :       }
    1279              :       break;
    1280              : 
    1281              :       /* Double the importance of an allocno that is incremented or
    1282              :          decremented, since it would take two extra insns if it ends
    1283              :          up in the wrong place.  */
    1284       166601 :     case POST_MODIFY:
    1285       166601 :     case PRE_MODIFY:
    1286       166601 :       record_address_regs (mode, as, XEXP (x, 0), 0, code,
    1287       166601 :                            GET_CODE (XEXP (XEXP (x, 1), 1)), 2 * scale);
    1288       166601 :       if (REG_P (XEXP (XEXP (x, 1), 1)))
    1289            0 :         record_address_regs (mode, as, XEXP (XEXP (x, 1), 1), 1, code, REG,
    1290              :                              2 * scale);
    1291              :       break;
    1292              : 
    1293      3375344 :     case POST_INC:
    1294      3375344 :     case PRE_INC:
    1295      3375344 :     case POST_DEC:
    1296      3375344 :     case PRE_DEC:
    1297              :       /* Double the importance of an allocno that is incremented or
    1298              :          decremented, since it would take two extra insns if it ends
    1299              :          up in the wrong place.  */
    1300      3375344 :       record_address_regs (mode, as, XEXP (x, 0), 0, code, SCRATCH, 2 * scale);
    1301      3375344 :       break;
    1302              : 
    1303     45212523 :     case REG:
    1304     45212523 :       {
    1305     45212523 :         struct costs *pp;
    1306     45212523 :         int *pp_costs;
    1307     45212523 :         enum reg_class i;
    1308     45212523 :         int k, regno, add_cost;
    1309     45212523 :         cost_classes_t cost_classes_ptr;
    1310     45212523 :         enum reg_class *cost_classes;
    1311     45212523 :         move_table *move_in_cost;
    1312              : 
    1313     45212523 :         if (REGNO (x) < FIRST_PSEUDO_REGISTER)
    1314              :           break;
    1315              : 
    1316     20491833 :         regno = REGNO (x);
    1317     20491833 :         if (allocno_p)
    1318     20171686 :           ALLOCNO_BAD_SPILL_P (ira_curr_regno_allocno_map[regno]) = true;
    1319     20491833 :         pp = COSTS (costs, COST_INDEX (regno));
    1320     20491833 :         add_cost = (ira_memory_move_cost[Pmode][rclass][1] * scale) / 2;
    1321     20491833 :         if (INT_MAX - add_cost < pp->mem_cost)
    1322            0 :           pp->mem_cost = INT_MAX;
    1323              :         else
    1324     20491833 :           pp->mem_cost += add_cost;
    1325     20491833 :         cost_classes_ptr = regno_cost_classes[regno];
    1326     20491833 :         cost_classes = cost_classes_ptr->classes;
    1327     20491833 :         pp_costs = pp->cost;
    1328     20491833 :         ira_init_register_move_cost_if_necessary (Pmode);
    1329     20491833 :         move_in_cost = ira_may_move_in_cost[Pmode];
    1330    332661095 :         for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    1331              :           {
    1332    312169262 :             i = cost_classes[k];
    1333    312169262 :             add_cost = (move_in_cost[i][rclass] * scale) / 2;
    1334    312169262 :             if (INT_MAX - add_cost < pp_costs[k])
    1335        14447 :               pp_costs[k] = INT_MAX;
    1336              :             else
    1337    312154815 :               pp_costs[k] += add_cost;
    1338              :           }
    1339              :       }
    1340              :       break;
    1341              : 
    1342      2193004 :     default:
    1343      2193004 :       {
    1344      2193004 :         const char *fmt = GET_RTX_FORMAT (code);
    1345      2193004 :         int i;
    1346      6074016 :         for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1347      3881012 :           if (fmt[i] == 'e')
    1348      3864893 :             record_address_regs (mode, as, XEXP (x, i), context, code, SCRATCH,
    1349              :                                  scale);
    1350              :       }
    1351              :     }
    1352              : }
    1353              : 
    1354              : 
    1355              : 
    1356              : /* Calculate the costs of insn operands.  */
    1357              : static void
    1358    142644493 : record_operand_costs (rtx_insn *insn, enum reg_class *pref)
    1359              : {
    1360    142644493 :   const char *constraints[MAX_RECOG_OPERANDS];
    1361    142644493 :   machine_mode modes[MAX_RECOG_OPERANDS];
    1362    142644493 :   rtx set;
    1363    142644493 :   int i;
    1364              : 
    1365    142644493 :   if ((set = single_set (insn)) != NULL_RTX
    1366              :       /* In rare cases the single set insn might have less 2 operands
    1367              :          as the source can be a fixed special reg.  */
    1368    134826242 :       && recog_data.n_operands > 1
    1369    129731744 :       && recog_data.operand[0] == SET_DEST (set)
    1370    249103791 :       && recog_data.operand[1] == SET_SRC (set))
    1371              :     {
    1372     77121095 :       int regno, other_regno;
    1373     77121095 :       rtx dest = SET_DEST (set);
    1374     77121095 :       rtx src = SET_SRC (set);
    1375              : 
    1376     77121095 :       if (GET_CODE (dest) == SUBREG
    1377     79193617 :           && known_eq (GET_MODE_SIZE (GET_MODE (dest)),
    1378              :                        GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))))
    1379              :         dest = SUBREG_REG (dest);
    1380     77121095 :       if (GET_CODE (src) == SUBREG
    1381     80106231 :           && known_eq (GET_MODE_SIZE (GET_MODE (src)),
    1382              :                        GET_MODE_SIZE (GET_MODE (SUBREG_REG (src)))))
    1383              :         src = SUBREG_REG (src);
    1384     36402915 :       if (REG_P (src) && REG_P (dest)
    1385     98880977 :           && (((regno = REGNO (src)) >= FIRST_PSEUDO_REGISTER
    1386     15157450 :                && (other_regno = REGNO (dest)) < FIRST_PSEUDO_REGISTER)
    1387     10189355 :               || ((regno = REGNO (dest)) >= FIRST_PSEUDO_REGISTER
    1388     10160738 :                   && (other_regno = REGNO (src)) < FIRST_PSEUDO_REGISTER)))
    1389              :         {
    1390     18144342 :           machine_mode mode = GET_MODE (SET_SRC (set)), cost_mode = mode;
    1391     18144342 :           machine_mode hard_reg_mode = GET_MODE(regno_reg_rtx[other_regno]);
    1392     36288684 :           poly_int64 pmode_size = GET_MODE_SIZE (mode);
    1393     36288684 :           poly_int64 phard_reg_mode_size = GET_MODE_SIZE (hard_reg_mode);
    1394     18144342 :           HOST_WIDE_INT mode_size, hard_reg_mode_size;
    1395     18144342 :           cost_classes_t cost_classes_ptr = regno_cost_classes[regno];
    1396     18144342 :           enum reg_class *cost_classes = cost_classes_ptr->classes;
    1397     18144342 :           reg_class_t rclass, hard_reg_class, bigger_hard_reg_class;
    1398     18144342 :           int cost_factor = 1, cost, k;
    1399     18144342 :           move_table *move_costs;
    1400     18144342 :           bool dead_p = find_regno_note (insn, REG_DEAD, REGNO (src));
    1401              : 
    1402     18144342 :           hard_reg_class = REGNO_REG_CLASS (other_regno);
    1403     18144342 :           bigger_hard_reg_class = ira_pressure_class_translate[hard_reg_class];
    1404              :           /* Target code may return any cost for mode which does not fit the
    1405              :              hard reg class (e.g. DImode for AREG on i386).  Check this and use
    1406              :              a bigger class to get the right cost.  */
    1407     18144342 :           if (bigger_hard_reg_class != NO_REGS
    1408     18144342 :               && ! ira_hard_reg_in_set_p (other_regno, mode,
    1409              :                                           reg_class_contents[hard_reg_class]))
    1410              :             hard_reg_class = bigger_hard_reg_class;
    1411     18144342 :           ira_init_register_move_cost_if_necessary (mode);
    1412     18144342 :           ira_init_register_move_cost_if_necessary (hard_reg_mode);
    1413              :           /* Use smaller movement cost for natural hard reg mode or its mode as
    1414              :              operand.  */
    1415     18144342 :           if (pmode_size.is_constant (&mode_size)
    1416     18144342 :               && phard_reg_mode_size.is_constant (&hard_reg_mode_size))
    1417              :             {
    1418              :               /* Assume we are moving in the natural modes: */
    1419     18144342 :               cost_factor = mode_size / hard_reg_mode_size;
    1420     18144342 :               if (mode_size % hard_reg_mode_size != 0)
    1421      3819985 :                 cost_factor++;
    1422     18144342 :               if (cost_factor
    1423     18144342 :                   * (ira_register_move_cost
    1424     18144342 :                      [hard_reg_mode][hard_reg_class][hard_reg_class])
    1425              :                   < (ira_register_move_cost
    1426     18144342 :                      [mode][hard_reg_class][hard_reg_class]))
    1427            0 :                 cost_mode = hard_reg_mode;
    1428              :               else
    1429              :                 cost_factor = 1;
    1430              :             }
    1431     18144342 :           move_costs = ira_register_move_cost[cost_mode];
    1432     18144342 :           i = regno == (int) REGNO (src) ? 1 : 0;
    1433    340804112 :           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    1434              :             {
    1435    322659770 :               rclass = cost_classes[k];
    1436    645319540 :               cost = (i == 0
    1437    322659770 :                       ? move_costs[hard_reg_class][rclass]
    1438    207519829 :                       : move_costs[rclass][hard_reg_class]);
    1439    322659770 :               cost *= cost_factor;
    1440    322659770 :               op_costs[i]->cost[k] = cost * frequency;
    1441              :               /* If this insn is a single set copying operand 1 to
    1442              :                  operand 0 and one operand is an allocno with the
    1443              :                  other a hard reg or an allocno that prefers a hard
    1444              :                  register that is in its own register class then we
    1445              :                  may want to adjust the cost of that register class to
    1446              :                  -1.
    1447              : 
    1448              :                  Avoid the adjustment if the source does not die to
    1449              :                  avoid stressing of register allocator by preferencing
    1450              :                  two colliding registers into single class.  */
    1451    322659770 :               if (dead_p
    1452    260909742 :                   && TEST_HARD_REG_BIT (reg_class_contents[rclass], other_regno)
    1453    322659770 :                   && (reg_class_size[(int) rclass]
    1454              :                       == (ira_reg_class_max_nregs
    1455    107974216 :                           [(int) rclass][(int) GET_MODE(src)])))
    1456              :                 {
    1457     13726800 :                   if (reg_class_size[rclass] == 1)
    1458     13571186 :                     op_costs[i]->cost[k] = -frequency;
    1459       155614 :                   else if (in_hard_reg_set_p (reg_class_contents[rclass],
    1460              :                                               GET_MODE(src), other_regno))
    1461       127328 :                     op_costs[i]->cost[k] = -frequency;
    1462              :                 }
    1463              :             }
    1464     18144342 :           op_costs[i]->mem_cost
    1465     18144342 :             = ira_memory_move_cost[mode][hard_reg_class][i] * frequency;
    1466     18144342 :           return;
    1467              :         }
    1468              :     }
    1469              : 
    1470    397322220 :   for (i = 0; i < recog_data.n_operands; i++)
    1471              :     {
    1472    272822069 :       constraints[i] = recog_data.constraints[i];
    1473    272822069 :       modes[i] = recog_data.operand_mode[i];
    1474              :     }
    1475              : 
    1476              :   /* If we get here, we are set up to record the costs of all the
    1477              :      operands for this insn.  Start by initializing the costs.  Then
    1478              :      handle any address registers.  Finally record the desired classes
    1479              :      for any allocnos, doing it twice if some pair of operands are
    1480              :      commutative.  */
    1481    397322220 :   for (i = 0; i < recog_data.n_operands; i++)
    1482              :     {
    1483    272822069 :       rtx op_mem = extract_mem_from_operand (recog_data.operand[i]);
    1484    272822069 :       memcpy (op_costs[i], init_cost, struct_costs_size);
    1485              : 
    1486    272822069 :       if (GET_CODE (recog_data.operand[i]) == SUBREG)
    1487      5271324 :         recog_data.operand[i] = SUBREG_REG (recog_data.operand[i]);
    1488              : 
    1489    272822069 :       if (MEM_P (op_mem))
    1490     44847847 :         record_address_regs (GET_MODE (op_mem),
    1491     44847847 :                              MEM_ADDR_SPACE (op_mem),
    1492              :                              XEXP (op_mem, 0),
    1493              :                              0, MEM, SCRATCH, frequency * 2);
    1494    227974222 :       else if (constraints[i][0] == 'p'
    1495    455944342 :                || (insn_extra_address_constraint
    1496    227970120 :                    (lookup_constraint (constraints[i]))))
    1497      1140244 :         record_address_regs (VOIDmode, ADDR_SPACE_GENERIC,
    1498              :                              recog_data.operand[i], 0, ADDRESS, SCRATCH,
    1499              :                              frequency * 2);
    1500              :     }
    1501              : 
    1502              :   /* Check for commutative in a separate loop so everything will have
    1503              :      been initialized.  We must do this even if one operand is a
    1504              :      constant--see addsi3 in m68k.md.  */
    1505    273753662 :   for (i = 0; i < (int) recog_data.n_operands - 1; i++)
    1506    149253511 :     if (constraints[i][0] == '%')
    1507              :       {
    1508              :         const char *xconstraints[MAX_RECOG_OPERANDS];
    1509              :         int j;
    1510              : 
    1511              :         /* Handle commutative operands by swapping the
    1512              :            constraints.  We assume the modes are the same.  */
    1513     68620944 :         for (j = 0; j < recog_data.n_operands; j++)
    1514     51677013 :           xconstraints[j] = constraints[j];
    1515              : 
    1516     16943931 :         xconstraints[i] = constraints[i+1];
    1517     16943931 :         xconstraints[i+1] = constraints[i];
    1518     16943931 :         record_reg_classes (recog_data.n_alternatives, recog_data.n_operands,
    1519              :                             recog_data.operand, modes,
    1520              :                             xconstraints, insn, pref);
    1521              :       }
    1522    124500151 :   record_reg_classes (recog_data.n_alternatives, recog_data.n_operands,
    1523              :                       recog_data.operand, modes,
    1524              :                       constraints, insn, pref);
    1525              : }
    1526              : 
    1527              : 
    1528              : 
    1529              : /* Process one insn INSN.  Scan it and record each time it would save
    1530              :    code to put a certain allocnos in a certain class.  Return the last
    1531              :    insn processed, so that the scan can be continued from there.  */
    1532              : static rtx_insn *
    1533    296046215 : scan_one_insn (rtx_insn *insn)
    1534              : {
    1535    296046215 :   enum rtx_code pat_code;
    1536    296046215 :   rtx set, note;
    1537    296046215 :   int i, k;
    1538    296046215 :   bool counted_mem;
    1539              : 
    1540    296046215 :   if (!NONDEBUG_INSN_P (insn))
    1541              :     return insn;
    1542              : 
    1543    144052321 :   pat_code = GET_CODE (PATTERN (insn));
    1544    144052321 :   if (pat_code == ASM_INPUT)
    1545              :     return insn;
    1546              : 
    1547              :   /* If INSN is a USE/CLOBBER of a pseudo in a mode M then go ahead
    1548              :      and initialize the register move costs of mode M.
    1549              : 
    1550              :      The pseudo may be related to another pseudo via a copy (implicit or
    1551              :      explicit) and if there are no mode M uses/sets of the original
    1552              :      pseudo, then we may leave the register move costs uninitialized for
    1553              :      mode M. */
    1554    144048483 :   if (pat_code == USE || pat_code == CLOBBER)
    1555              :     {
    1556      1403990 :       rtx x = XEXP (PATTERN (insn), 0);
    1557      1403990 :       if (GET_CODE (x) == REG
    1558      1390587 :           && REGNO (x) >= FIRST_PSEUDO_REGISTER
    1559      1439277 :           && have_regs_of_mode[GET_MODE (x)])
    1560        35286 :         ira_init_register_move_cost_if_necessary (GET_MODE (x));
    1561      1403990 :       return insn;
    1562              :     }
    1563              : 
    1564    142644493 :   counted_mem = false;
    1565    142644493 :   set = single_set (insn);
    1566    142644493 :   extract_insn (insn);
    1567              : 
    1568              :   /* If this insn loads a parameter from its stack slot, then it
    1569              :      represents a savings, rather than a cost, if the parameter is
    1570              :      stored in memory.  Record this fact.
    1571              : 
    1572              :      Similarly if we're loading other constants from memory (constant
    1573              :      pool, TOC references, small data areas, etc) and this is the only
    1574              :      assignment to the destination pseudo.
    1575              : 
    1576              :      Don't do this if SET_SRC (set) isn't a general operand, if it is
    1577              :      a memory requiring special instructions to load it, decreasing
    1578              :      mem_cost might result in it being loaded using the specialized
    1579              :      instruction into a register, then stored into stack and loaded
    1580              :      again from the stack.  See PR52208.
    1581              : 
    1582              :      Don't do this if SET_SRC (set) has side effect.  See PR56124.  */
    1583    134826242 :   if (set != 0 && REG_P (SET_DEST (set)) && MEM_P (SET_SRC (set))
    1584     17424763 :       && (note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != NULL_RTX
    1585      4843775 :       && ((MEM_P (XEXP (note, 0))
    1586      4387233 :            && !side_effects_p (SET_SRC (set)))
    1587       456542 :           || (CONSTANT_P (XEXP (note, 0))
    1588       456534 :               && targetm.legitimate_constant_p (GET_MODE (SET_DEST (set)),
    1589              :                                                 XEXP (note, 0))
    1590       155785 :               && REG_N_SETS (REGNO (SET_DEST (set))) == 1))
    1591      4543018 :       && general_operand (SET_SRC (set), GET_MODE (SET_SRC (set)))
    1592              :       /* LRA does not use equiv with a symbol for PIC code.  */
    1593    147187466 :       && (! ira_use_lra_p || ! pic_offset_table_rtx
    1594       334092 :           || ! contains_symbol_ref_p (XEXP (note, 0))))
    1595              :     {
    1596      4485391 :       enum reg_class cl = GENERAL_REGS;
    1597      4485391 :       rtx reg = SET_DEST (set);
    1598      4485391 :       int num = COST_INDEX (REGNO (reg));
    1599              :       /* Costs for NO_REGS are used in cost calculation on the
    1600              :          1st pass when the preferred register classes are not
    1601              :          known yet.  In this case we take the best scenario when
    1602              :          mode can't be put into GENERAL_REGS.  */
    1603      4485391 :       if (!targetm.hard_regno_mode_ok (ira_class_hard_regs[cl][0],
    1604      4485391 :                                        GET_MODE (reg)))
    1605      1155545 :         cl = NO_REGS;
    1606              : 
    1607      4485391 :       COSTS (costs, num)->mem_cost
    1608      4485391 :         -= ira_memory_move_cost[GET_MODE (reg)][cl][1] * frequency;
    1609      8970782 :       record_address_regs (GET_MODE (SET_SRC (set)),
    1610      8970782 :                            MEM_ADDR_SPACE (SET_SRC (set)),
    1611      4485391 :                            XEXP (SET_SRC (set), 0), 0, MEM, SCRATCH,
    1612              :                            frequency * 2);
    1613      4485391 :       counted_mem = true;
    1614              :     }
    1615              : 
    1616    142644493 :   record_operand_costs (insn, pref);
    1617              : 
    1618    142644493 :   if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    1619              :     {
    1620            0 :       const char *p;
    1621            0 :       fprintf (ira_dump_file, "    Final costs after insn %u", INSN_UID (insn));
    1622            0 :       if (INSN_CODE (insn) >= 0
    1623            0 :           && (p = get_insn_name (INSN_CODE (insn))) != NULL)
    1624            0 :         fprintf (ira_dump_file, " {%s}", p);
    1625            0 :       fprintf (ira_dump_file, " (freq=%d)\n",
    1626            0 :                REG_FREQ_FROM_BB (BLOCK_FOR_INSN (insn)));
    1627            0 :       dump_insn_slim (ira_dump_file, insn);
    1628              :     }
    1629              : 
    1630              :   /* Now add the cost for each operand to the total costs for its
    1631              :      allocno.  */
    1632    451755246 :   for (i = 0; i < recog_data.n_operands; i++)
    1633              :     {
    1634    309110753 :       rtx op = recog_data.operand[i];
    1635              : 
    1636    309110753 :       if (GET_CODE (op) == SUBREG)
    1637        63272 :         op = SUBREG_REG (op);
    1638    309110753 :       if (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER)
    1639              :         {
    1640    125857435 :           int regno = REGNO (op);
    1641    125857435 :           struct costs *p = COSTS (costs, COST_INDEX (regno));
    1642    125857435 :           struct costs *q = op_costs[i];
    1643    125857435 :           int *p_costs = p->cost, *q_costs = q->cost;
    1644    125857435 :           cost_classes_t cost_classes_ptr = regno_cost_classes[regno];
    1645    125857435 :           int add_cost = 0;
    1646              : 
    1647              :           /* If the already accounted for the memory "cost" above, don't
    1648              :              do so again.  */
    1649    125857435 :           if (!counted_mem)
    1650              :             {
    1651    121372044 :               add_cost = q->mem_cost;
    1652    121372044 :               if (add_cost > 0 && INT_MAX - add_cost < p->mem_cost)
    1653            0 :                 p->mem_cost = INT_MAX;
    1654              :               else
    1655    121372044 :                 p->mem_cost += add_cost;
    1656              :             }
    1657    125857435 :           if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    1658              :             {
    1659            0 :               fprintf (ira_dump_file, "        op %d(r=%u) MEM:%d(+%d)",
    1660              :                        i, REGNO(op), p->mem_cost, add_cost);
    1661              :             }
    1662   1872300671 :           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    1663              :             {
    1664   1746443236 :               add_cost = q_costs[k];
    1665   1746443236 :               if (add_cost > 0 && INT_MAX - add_cost < p_costs[k])
    1666            0 :                 p_costs[k] = INT_MAX;
    1667              :               else
    1668   1746443236 :                 p_costs[k] += add_cost;
    1669   1746443236 :               if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    1670              :                 {
    1671            0 :                   fprintf (ira_dump_file, " %s:%d(+%d)",
    1672            0 :                            reg_class_names[cost_classes_ptr->classes[k]],
    1673            0 :                            p_costs[k], add_cost);
    1674              :                 }
    1675              :             }
    1676    125857435 :           if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    1677            0 :             fprintf (ira_dump_file, "\n");
    1678              :         }
    1679              :     }
    1680              :   return insn;
    1681              : }
    1682              : 
    1683              : 
    1684              : 
    1685              : /* Print allocnos costs to the dump file.  */
    1686              : static void
    1687          127 : print_allocno_costs (void)
    1688              : {
    1689          127 :   int k;
    1690          127 :   ira_allocno_t a;
    1691          127 :   ira_allocno_iterator ai;
    1692              : 
    1693          127 :   ira_assert (allocno_p);
    1694          127 :   fprintf (ira_dump_file, "\n");
    1695         1341 :   FOR_EACH_ALLOCNO (a, ai)
    1696              :     {
    1697         1214 :       int i, rclass;
    1698         1214 :       basic_block bb;
    1699         1214 :       int regno = ALLOCNO_REGNO (a);
    1700         1214 :       cost_classes_t cost_classes_ptr = regno_cost_classes[regno];
    1701         1214 :       enum reg_class *cost_classes = cost_classes_ptr->classes;
    1702              : 
    1703         1214 :       i = ALLOCNO_NUM (a);
    1704         1214 :       fprintf (ira_dump_file, "  a%d(r%d,", i, regno);
    1705         1214 :       if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
    1706            0 :         fprintf (ira_dump_file, "b%d", bb->index);
    1707              :       else
    1708         1214 :         fprintf (ira_dump_file, "l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop_num);
    1709         1214 :       fprintf (ira_dump_file, ") costs:");
    1710        19725 :       for (k = 0; k < cost_classes_ptr->num; k++)
    1711              :         {
    1712        17297 :           rclass = cost_classes[k];
    1713        17297 :           fprintf (ira_dump_file, " %s:%d", reg_class_names[rclass],
    1714        17297 :                    COSTS (costs, i)->cost[k]);
    1715        17297 :           if (flag_ira_region == IRA_REGION_ALL
    1716        17297 :               || flag_ira_region == IRA_REGION_MIXED)
    1717        13698 :             fprintf (ira_dump_file, ",%d",
    1718        13698 :                      COSTS (total_allocno_costs, i)->cost[k]);
    1719              :         }
    1720         1214 :       fprintf (ira_dump_file, " MEM:%i", COSTS (costs, i)->mem_cost);
    1721         1214 :       if (flag_ira_region == IRA_REGION_ALL
    1722         1214 :           || flag_ira_region == IRA_REGION_MIXED)
    1723         1004 :         fprintf (ira_dump_file, ",%d",
    1724         1004 :                  COSTS (total_allocno_costs, i)->mem_cost);
    1725         1214 :       fprintf (ira_dump_file, "\n");
    1726              :     }
    1727          127 : }
    1728              : 
    1729              : /* Print pseudo costs to the dump file.  */
    1730              : static void
    1731           16 : print_pseudo_costs (void)
    1732              : {
    1733           16 :   int regno, k;
    1734           16 :   int rclass;
    1735           16 :   cost_classes_t cost_classes_ptr;
    1736           16 :   enum reg_class *cost_classes;
    1737              : 
    1738           16 :   ira_assert (! allocno_p);
    1739           16 :   fprintf (ira_dump_file, "\n");
    1740          764 :   for (regno = max_reg_num () - 1; regno >= FIRST_PSEUDO_REGISTER; regno--)
    1741              :     {
    1742          748 :       if (REG_N_REFS (regno) <= 0)
    1743          444 :         continue;
    1744          304 :       cost_classes_ptr = regno_cost_classes[regno];
    1745          304 :       cost_classes = cost_classes_ptr->classes;
    1746          304 :       fprintf (ira_dump_file, "  r%d costs:", regno);
    1747         5904 :       for (k = 0; k < cost_classes_ptr->num; k++)
    1748              :         {
    1749         5296 :           rclass = cost_classes[k];
    1750         5296 :           fprintf (ira_dump_file, " %s:%d", reg_class_names[rclass],
    1751         5296 :                    COSTS (costs, regno)->cost[k]);
    1752              :         }
    1753          304 :       fprintf (ira_dump_file, " MEM:%i\n", COSTS (costs, regno)->mem_cost);
    1754              :     }
    1755           16 : }
    1756              : 
    1757              : /* Traverse the BB represented by LOOP_TREE_NODE to update the allocno
    1758              :    costs.  */
    1759              : static void
    1760     25848084 : process_bb_for_costs (basic_block bb)
    1761              : {
    1762     25848084 :   rtx_insn *insn;
    1763              : 
    1764     25848084 :   frequency = REG_FREQ_FROM_BB (bb);
    1765     25848084 :   if (frequency == 0)
    1766            0 :     frequency = 1;
    1767    321894299 :   FOR_BB_INSNS (bb, insn)
    1768    296046215 :     insn = scan_one_insn (insn);
    1769     25848084 : }
    1770              : 
    1771              : /* Traverse the BB represented by LOOP_TREE_NODE to update the allocno
    1772              :    costs.  */
    1773              : static void
    1774     28823194 : process_bb_node_for_costs (ira_loop_tree_node_t loop_tree_node)
    1775              : {
    1776     28823194 :   basic_block bb;
    1777              : 
    1778     28823194 :   bb = loop_tree_node->bb;
    1779     28823194 :   if (bb != NULL)
    1780     25167050 :     process_bb_for_costs (bb);
    1781     28823194 : }
    1782              : 
    1783              : /* Return true if all autoinc rtx in X change only a register and memory is
    1784              :    valid.  */
    1785              : static bool
    1786     53863353 : validate_autoinc_and_mem_addr_p (rtx x)
    1787              : {
    1788     53863353 :   enum rtx_code code = GET_CODE (x);
    1789     53863353 :   if (GET_RTX_CLASS (code) == RTX_AUTOINC)
    1790       384297 :     return REG_P (XEXP (x, 0));
    1791     53479056 :   const char *fmt = GET_RTX_FORMAT (code);
    1792    132604942 :   for (int i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1793     80477665 :     if (fmt[i] == 'e')
    1794              :       {
    1795     43828677 :         if (!validate_autoinc_and_mem_addr_p (XEXP (x, i)))
    1796              :           return false;
    1797              :       }
    1798     36648988 :     else if (fmt[i] == 'E')
    1799              :       {
    1800      3025738 :         for (int j = 0; j < XVECLEN (x, i); j++)
    1801      2048273 :           if (!validate_autoinc_and_mem_addr_p (XVECEXP (x, i, j)))
    1802              :             return false;
    1803              :       }
    1804              :   /* Check memory after checking autoinc to guarantee that autoinc is already
    1805              :      valid for machine-dependent code checking memory address.  */
    1806     52127277 :   return (!MEM_P (x)
    1807    111267726 :           || memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
    1808      8156780 :                                           MEM_ADDR_SPACE (x)));
    1809              : }
    1810              : 
    1811              : /* Check that reg REGNO in INSN can be changed by TO (which is an invariant
    1812              :    equiv when INVARIANT_P is true).  Return true in case the result insn would
    1813              :    be valid one.  */
    1814              : static bool
    1815      7986403 : equiv_can_be_consumed_p (int regno, rtx to, rtx_insn *insn, bool invariant_p)
    1816              : {
    1817      7986403 :   validate_replace_src_group (regno_reg_rtx[regno], to, insn);
    1818              :   /* We can change register to equivalent memory in autoinc rtl.  Some code
    1819              :      including verify_changes assumes that autoinc contains only a register.
    1820              :      So check this first.  */
    1821      7986403 :   bool res = validate_autoinc_and_mem_addr_p (PATTERN (insn));
    1822      7986403 :   if (res)
    1823      6842795 :     res = verify_changes (0);
    1824      7986403 :   cancel_changes (0);
    1825      7986403 :   if (!res && invariant_p)
    1826              :     {
    1827              :       /* Here we use more expensive code for the invariant because we need to
    1828              :          simplify the result insn as the invariant can be arithmetic rtx
    1829              :          inserted into another arithmetic rtx, e.g. into memory address.  */
    1830       601643 :       rtx pat = PATTERN (insn);
    1831       601643 :       int code = INSN_CODE (insn);
    1832       601643 :       PATTERN (insn) = copy_rtx (pat);
    1833      1203286 :       PATTERN (insn)
    1834       601643 :         = simplify_replace_rtx (PATTERN (insn), regno_reg_rtx[regno], to);
    1835       601643 :       res = !insn_invalid_p (insn, false);
    1836       601643 :       PATTERN (insn) = pat;
    1837       601643 :       INSN_CODE (insn) = code;
    1838              :     }
    1839      7986403 :   return res;
    1840              : }
    1841              : 
    1842              : /* Return true if X contains a pseudo with equivalence.  In this case also
    1843              :    return the pseudo through parameter REG.  If the pseudo is a part of subreg,
    1844              :    return the subreg through parameter SUBREG.  */
    1845              : 
    1846              : static bool
    1847    279098067 : get_equiv_regno (rtx x, int &regno, rtx &subreg)
    1848              : {
    1849    279098067 :   subreg = NULL_RTX;
    1850    279098067 :   if (GET_CODE (x) == SUBREG)
    1851              :     {
    1852      2237786 :       subreg = x;
    1853      2237786 :       x = SUBREG_REG (x);
    1854              :     }
    1855    279098067 :   if (REG_P (x)
    1856    279098067 :       && (ira_reg_equiv[REGNO (x)].memory != NULL
    1857     83707053 :           || ira_reg_equiv[REGNO (x)].invariant != NULL
    1858     81246539 :           || ira_reg_equiv[REGNO (x)].constant != NULL))
    1859              :     {
    1860     10480705 :       regno = REGNO (x);
    1861     10480705 :       return true;
    1862              :     }
    1863    268617362 :   RTX_CODE code = GET_CODE (x);
    1864    268617362 :   const char *fmt = GET_RTX_FORMAT (code);
    1865              : 
    1866    627716355 :   for (int i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1867    374584889 :     if (fmt[i] == 'e')
    1868              :       {
    1869    206720805 :         if (get_equiv_regno (XEXP (x, i), regno, subreg))
    1870              :           return true;
    1871              :       }
    1872    167864084 :     else if (fmt[i] == 'E')
    1873              :       {
    1874     24129258 :         for (int j = 0; j < XVECLEN (x, i); j++)
    1875     16807859 :           if (get_equiv_regno (XVECEXP (x, i, j), regno, subreg))
    1876              :             return true;
    1877              :       }
    1878              :   return false;
    1879              : }
    1880              : 
    1881              : /* A pass through the current function insns.  Calculate costs of using
    1882              :    equivalences for pseudos and store them in regno_equiv_gains.  */
    1883              : 
    1884              : static void
    1885       976444 : calculate_equiv_gains (void)
    1886              : {
    1887       976444 :   basic_block bb;
    1888       976444 :   int regno, freq, cost;
    1889       976444 :   rtx subreg;
    1890       976444 :   rtx_insn *insn;
    1891       976444 :   machine_mode mode;
    1892       976444 :   enum reg_class rclass;
    1893       976444 :   bitmap_head equiv_pseudos;
    1894              : 
    1895       976444 :   ira_assert (allocno_p);
    1896       976444 :   bitmap_initialize (&equiv_pseudos, &reg_obstack);
    1897     49036666 :   for (regno = max_reg_num () - 1; regno >= FIRST_PSEUDO_REGISTER; regno--)
    1898     48060222 :     if (ira_reg_equiv[regno].init_insns != NULL
    1899      4230696 :         && (ira_reg_equiv[regno].memory != NULL
    1900      1496533 :             || ira_reg_equiv[regno].invariant != NULL
    1901       657740 :             || (ira_reg_equiv[regno].constant != NULL
    1902              :                 /* Ignore complicated constants which probably will be placed
    1903              :                    in memory:  */
    1904       657740 :                 && GET_CODE (ira_reg_equiv[regno].constant) != CONST_DOUBLE
    1905              :                 && GET_CODE (ira_reg_equiv[regno].constant) != CONST_VECTOR
    1906              :                 && GET_CODE (ira_reg_equiv[regno].constant) != LABEL_REF)))
    1907              :       {
    1908              :         rtx_insn_list *x;
    1909      7611284 :         for (x = ira_reg_equiv[regno].init_insns; x != NULL; x = x->next ())
    1910              :           {
    1911      4061534 :             insn = x->insn ();
    1912      4061534 :             rtx set = single_set (insn);
    1913              : 
    1914      4061534 :             if (set == NULL_RTX || SET_DEST (set) != regno_reg_rtx[regno])
    1915              :               break;
    1916      3549750 :             bb = BLOCK_FOR_INSN (insn);
    1917      3549750 :             ira_curr_regno_allocno_map
    1918      3549750 :               = ira_bb_nodes[bb->index].parent->regno_allocno_map;
    1919      3549750 :             mode = PSEUDO_REGNO_MODE (regno);
    1920      3549750 :             rclass = pref[COST_INDEX (regno)];
    1921      3549750 :             ira_init_register_move_cost_if_necessary (mode);
    1922      3549750 :             if (ira_reg_equiv[regno].memory != NULL)
    1923      2222379 :               cost = ira_memory_move_cost[mode][rclass][1];
    1924              :             else
    1925      1327371 :               cost = ira_register_move_cost[mode][rclass][rclass];
    1926      3549750 :             freq = REG_FREQ_FROM_BB (bb);
    1927      3549750 :             regno_equiv_gains[regno] += cost * freq;
    1928              :           }
    1929      4061534 :         if (x != NULL)
    1930              :           /* We found complicated equiv or reverse equiv mem=reg.  Ignore
    1931              :              them.  */
    1932       511784 :           regno_equiv_gains[regno] = 0;
    1933              :         else
    1934      3549750 :           bitmap_set_bit (&equiv_pseudos, regno);
    1935              :       }
    1936              : 
    1937     11514749 :   FOR_EACH_BB_FN (bb, cfun)
    1938              :     {
    1939     10538305 :       freq = REG_FREQ_FROM_BB (bb);
    1940     10538305 :       ira_curr_regno_allocno_map
    1941     10538305 :         = ira_bb_nodes[bb->index].parent->regno_allocno_map;
    1942    138049209 :       FOR_BB_INSNS (bb, insn)
    1943              :         {
    1944    246196693 :           if (!NONDEBUG_INSN_P (insn)
    1945     55569403 :               || !get_equiv_regno (PATTERN (insn), regno, subreg)
    1946    137991609 :               || !bitmap_bit_p (&equiv_pseudos, regno))
    1947    118685789 :             continue;
    1948              : 
    1949      8825115 :           if (ira_reg_equiv[regno].invariant != NULL)
    1950              :             {
    1951      2460514 :               rtx_insn_list *x = ira_reg_equiv[regno].init_insns;
    1952      4082316 :               for (; x != NULL; x = x->next ())
    1953      2460514 :                 if (insn == x->insn ())
    1954              :                   break;
    1955      2460514 :               if (x != NULL)
    1956       838712 :                 continue; /* skip equiv init insn for invariant */
    1957              :             }
    1958              : 
    1959      7986403 :           rtx subst = ira_reg_equiv[regno].memory;
    1960              : 
    1961      7986403 :           if (subst == NULL)
    1962      2704196 :             subst = ira_reg_equiv[regno].constant;
    1963      2704196 :           if (subst == NULL)
    1964      1621802 :             subst = ira_reg_equiv[regno].invariant;
    1965      1621802 :           ira_assert (subst != NULL);
    1966      7986403 :           mode = PSEUDO_REGNO_MODE (regno);
    1967      7986403 :           ira_init_register_move_cost_if_necessary (mode);
    1968      7986403 :           bool consumed_p
    1969     15972806 :             = equiv_can_be_consumed_p (regno, subst, insn,
    1970      7986403 :                                        subst == ira_reg_equiv[regno].invariant);
    1971              : 
    1972      7986403 :           rclass = pref[COST_INDEX (regno)];
    1973      7986403 :           if (MEM_P (subst)
    1974              :               /* If it is a change of constant into double for example, the
    1975              :                  result constant probably will be placed in memory.  */
    1976      2704196 :               || (ira_reg_equiv[regno].invariant == NULL
    1977      1082394 :                   && subreg != NULL_RTX
    1978         1236 :                   && !INTEGRAL_MODE_P (GET_MODE (subreg))))
    1979      7923431 :             cost = ira_memory_move_cost[mode][rclass][1] + (consumed_p ? 0 : 1);
    1980      2704133 :           else if (consumed_p)
    1981      1610285 :             continue;
    1982              :           else
    1983      1093848 :             cost = ira_register_move_cost[mode][rclass][rclass];
    1984      6376118 :           regno_equiv_gains[regno] -= cost * freq;
    1985              :         }
    1986              :     }
    1987       976444 :   bitmap_clear (&equiv_pseudos);
    1988       976444 : }
    1989              : 
    1990              : /* Find costs of register classes and memory for allocnos or pseudos
    1991              :    and their best costs.  Set up preferred, alternative and allocno
    1992              :    classes for pseudos.  */
    1993              : static void
    1994      1534757 : find_costs_and_classes (void)
    1995              : {
    1996      1534757 :   int i, k, start, max_cost_classes_num;
    1997      1534757 :   int pass;
    1998      1534757 :   basic_block bb;
    1999      1534757 :   enum reg_class *regno_best_class, new_class;
    2000              : 
    2001      1534757 :   init_recog ();
    2002      1534757 :   regno_best_class
    2003      1534757 :     = (enum reg_class *) ira_allocate (max_reg_num ()
    2004              :                                        * sizeof (enum reg_class));
    2005     69875435 :   for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    2006     68340678 :     regno_best_class[i] = NO_REGS;
    2007      3039750 :   if (!resize_reg_info () && allocno_p
    2008      3039707 :       && pseudo_classes_defined_p && flag_expensive_optimizations)
    2009              :     {
    2010           48 :       ira_allocno_t a;
    2011           48 :       ira_allocno_iterator ai;
    2012              : 
    2013           48 :       pref = pref_buffer;
    2014           48 :       max_cost_classes_num = 1;
    2015         1637 :       FOR_EACH_ALLOCNO (a, ai)
    2016              :         {
    2017         1589 :           pref[ALLOCNO_NUM (a)] = reg_preferred_class (ALLOCNO_REGNO (a));
    2018         1589 :           setup_regno_cost_classes_by_aclass
    2019         1589 :             (ALLOCNO_REGNO (a), pref[ALLOCNO_NUM (a)]);
    2020         1589 :           max_cost_classes_num
    2021         1589 :             = MAX (max_cost_classes_num,
    2022              :                    regno_cost_classes[ALLOCNO_REGNO (a)]->num);
    2023              :         }
    2024           48 :       start = 1;
    2025              :     }
    2026              :   else
    2027              :     {
    2028      1534709 :       pref = NULL;
    2029      1534709 :       max_cost_classes_num = ira_important_classes_num;
    2030     69872677 :       for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    2031     68337968 :         if (regno_reg_rtx[i] != NULL_RTX)
    2032     68034086 :           setup_regno_cost_classes_by_mode (i, PSEUDO_REGNO_MODE (i));
    2033              :         else
    2034       303882 :           setup_regno_cost_classes_by_aclass (i, ALL_REGS);
    2035              :       start = 0;
    2036              :     }
    2037      1534757 :   if (allocno_p)
    2038              :     /* Clear the flag for the next compiled function.  */
    2039      1504950 :     pseudo_classes_defined_p = false;
    2040              :   /* Normally we scan the insns once and determine the best class to
    2041              :      use for each allocno.  However, if -fexpensive-optimizations are
    2042              :      on, we do so twice, the second time using the tentative best
    2043              :      classes to guide the selection.  */
    2044      4075665 :   for (pass = start; pass <= flag_expensive_optimizations; pass++)
    2045              :     {
    2046      2540908 :       if ((!allocno_p || internal_flag_ira_verbose > 0) && ira_dump_file)
    2047          143 :         fprintf (ira_dump_file,
    2048              :                  "\nPass %i for finding pseudo/allocno costs\n\n", pass);
    2049              : 
    2050      2540908 :       if (pass != start)
    2051              :         {
    2052      1006151 :           max_cost_classes_num = 1;
    2053     50491576 :           for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    2054              :             {
    2055     49485425 :               setup_regno_cost_classes_by_aclass (i, regno_best_class[i]);
    2056     49485425 :               max_cost_classes_num
    2057     49485425 :                 = MAX (max_cost_classes_num, regno_cost_classes[i]->num);
    2058              :             }
    2059              :         }
    2060              : 
    2061      2540908 :       struct_costs_size
    2062      2540908 :         = sizeof (struct costs) + sizeof (int) * (max_cost_classes_num - 1);
    2063              :       /* Zero out our accumulation of the cost of each class for each
    2064              :          allocno.  */
    2065      2540908 :       memset (costs, 0, cost_elements_num * struct_costs_size);
    2066              : 
    2067      2540908 :       if (allocno_p)
    2068              :         {
    2069              :           /* Scan the instructions and record each time it would save code
    2070              :              to put a certain allocno in a certain class.  */
    2071      2481346 :           ira_traverse_loop_tree (true, ira_loop_tree_root,
    2072              :                                   process_bb_node_for_costs, NULL);
    2073              : 
    2074      2481346 :           memcpy (total_allocno_costs, costs,
    2075      2481346 :                   max_struct_costs_size * ira_allocnos_num);
    2076              :         }
    2077              :       else
    2078              :         {
    2079        59562 :           basic_block bb;
    2080              : 
    2081       740596 :           FOR_EACH_BB_FN (bb, cfun)
    2082       681034 :             process_bb_for_costs (bb);
    2083              :         }
    2084              : 
    2085      2540908 :       if (pass == 0)
    2086      1534709 :         pref = pref_buffer;
    2087              : 
    2088      2540908 :       if (ira_use_lra_p && allocno_p && pass == 1)
    2089              :         /* It is a pass through all insns.  So do it once and only for RA (not
    2090              :            for insn scheduler) when we already found preferable pseudo register
    2091              :            classes on the previous pass.  */
    2092       976444 :         calculate_equiv_gains ();
    2093              : 
    2094              :       /* Now for each allocno look at how desirable each class is and
    2095              :          find which class is preferred.  */
    2096    120367011 :       for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    2097              :         {
    2098    117826103 :           ira_allocno_t a, parent_a;
    2099    117826103 :           int rclass, a_num, parent_a_num, add_cost;
    2100    117826103 :           ira_loop_tree_node_t parent;
    2101    117826103 :           int best_cost, allocno_cost;
    2102    117826103 :           enum reg_class best, alt_class;
    2103    117826103 :           cost_classes_t cost_classes_ptr = regno_cost_classes[i];
    2104    117826103 :           enum reg_class *cost_classes;
    2105    117826103 :           int *i_costs = temp_costs->cost;
    2106    117826103 :           int i_mem_cost;
    2107    117826103 :           int equiv_savings = regno_equiv_gains[i];
    2108              : 
    2109    117826103 :           if (! allocno_p)
    2110              :             {
    2111      2857434 :               if (regno_reg_rtx[i] == NULL_RTX)
    2112         4694 :                 continue;
    2113      2852740 :               memcpy (temp_costs, COSTS (costs, i), struct_costs_size);
    2114      2852740 :               i_mem_cost = temp_costs->mem_cost;
    2115      2852740 :               cost_classes = cost_classes_ptr->classes;
    2116              :             }
    2117              :           else
    2118              :             {
    2119    114968669 :               if (ira_regno_allocno_map[i] == NULL)
    2120     67554178 :                 continue;
    2121     47414491 :               memset (temp_costs, 0, struct_costs_size);
    2122     47414491 :               i_mem_cost = 0;
    2123     47414491 :               cost_classes = cost_classes_ptr->classes;
    2124              :               /* Find cost of all allocnos with the same regno.  */
    2125     47414491 :               for (a = ira_regno_allocno_map[i];
    2126    105498343 :                    a != NULL;
    2127     58083852 :                    a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
    2128              :                 {
    2129     58083852 :                   int *a_costs, *p_costs;
    2130              : 
    2131     58083852 :                   a_num = ALLOCNO_NUM (a);
    2132     58083852 :                   if ((flag_ira_region == IRA_REGION_ALL
    2133     58083852 :                        || flag_ira_region == IRA_REGION_MIXED)
    2134     45375248 :                       && (parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) != NULL
    2135     17480428 :                       && (parent_a = parent->regno_allocno_map[i]) != NULL
    2136              :                       /* There are no caps yet.  */
    2137     68752780 :                       && bitmap_bit_p (ALLOCNO_LOOP_TREE_NODE
    2138     10668928 :                                        (a)->border_allocnos,
    2139              :                                        ALLOCNO_NUM (a)))
    2140              :                     {
    2141              :                       /* Propagate costs to upper levels in the region
    2142              :                          tree.  */
    2143     10661816 :                       parent_a_num = ALLOCNO_NUM (parent_a);
    2144     10661816 :                       a_costs = COSTS (total_allocno_costs, a_num)->cost;
    2145     10661816 :                       p_costs = COSTS (total_allocno_costs, parent_a_num)->cost;
    2146    154185097 :                       for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    2147              :                         {
    2148    143523281 :                           add_cost = a_costs[k];
    2149    143523281 :                           if (add_cost > 0 && INT_MAX - add_cost < p_costs[k])
    2150            0 :                             p_costs[k] = INT_MAX;
    2151              :                           else
    2152    143523281 :                             p_costs[k] += add_cost;
    2153              :                         }
    2154     10661816 :                       add_cost = COSTS (total_allocno_costs, a_num)->mem_cost;
    2155     10661816 :                       if (add_cost > 0
    2156      5137560 :                           && (INT_MAX - add_cost
    2157              :                               < COSTS (total_allocno_costs,
    2158      5137560 :                                        parent_a_num)->mem_cost))
    2159            0 :                         COSTS (total_allocno_costs, parent_a_num)->mem_cost
    2160            0 :                           = INT_MAX;
    2161              :                       else
    2162     10661816 :                         COSTS (total_allocno_costs, parent_a_num)->mem_cost
    2163     10661816 :                           += add_cost;
    2164              : 
    2165     10661816 :                       if (i >= first_moveable_pseudo && i < last_moveable_pseudo)
    2166            0 :                         COSTS (total_allocno_costs, parent_a_num)->mem_cost = 0;
    2167              :                     }
    2168     58083852 :                   a_costs = COSTS (costs, a_num)->cost;
    2169    864291313 :                   for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    2170              :                     {
    2171    806207461 :                       add_cost = a_costs[k];
    2172    806207461 :                       if (add_cost > 0 && INT_MAX - add_cost < i_costs[k])
    2173            0 :                         i_costs[k] = INT_MAX;
    2174              :                       else
    2175    806207461 :                         i_costs[k] += add_cost;
    2176              :                     }
    2177     58083852 :                   add_cost = COSTS (costs, a_num)->mem_cost;
    2178     58083852 :                   if (add_cost > 0 && INT_MAX - add_cost < i_mem_cost)
    2179              :                     i_mem_cost = INT_MAX;
    2180              :                   else
    2181     58083852 :                     i_mem_cost += add_cost;
    2182              :                 }
    2183              :             }
    2184     50267231 :           if (i >= first_moveable_pseudo && i < last_moveable_pseudo)
    2185              :             i_mem_cost = 0;
    2186     50239800 :           else if (ira_use_lra_p)
    2187              :             {
    2188     50239800 :               rtx x;
    2189     50239800 :               if (equiv_savings > 0
    2190              :                   /* During LRA constraint pass, some equivalences are
    2191              :                      invalidated.  Align IRA with LRA here and do not consider
    2192              :                      those equivalences since otherwise those pseudos are
    2193              :                      spilled.  */
    2194     50239800 :                   && (!pic_offset_table_rtx
    2195         6351 :                       || (x = ira_reg_equiv[i].constant) == NULL
    2196          759 :                       || ((!CONST_POOL_OK_P (PSEUDO_REGNO_MODE (i), x)
    2197          759 :                            || targetm.preferred_reload_class
    2198          759 :                               (x, reg_allocno_class (i)) != NO_REGS)
    2199          759 :                           && !contains_symbol_ref_p (x))))
    2200              :                 {
    2201       539095 :                   i_mem_cost = 0;
    2202       539095 :                   if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    2203            0 :                     fprintf (ira_dump_file,
    2204              :                              "   Use MEM for r%d as the equiv savings is %d\n",
    2205              :                              i, equiv_savings);
    2206              :                 }
    2207              :             }
    2208            0 :           else if (equiv_savings < 0)
    2209            0 :             i_mem_cost = -equiv_savings;
    2210            0 :           else if (equiv_savings > 0)
    2211              :             {
    2212            0 :               i_mem_cost = 0;
    2213            0 :               for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    2214            0 :                 i_costs[k] += equiv_savings;
    2215              :             }
    2216              : 
    2217     50267231 :           best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1;
    2218     50267231 :           best = ALL_REGS;
    2219     50267231 :           alt_class = NO_REGS;
    2220              :           /* Find best common class for all allocnos with the same
    2221              :              regno.  */
    2222    761678926 :           for (k = 0; k < cost_classes_ptr->num; k++)
    2223              :             {
    2224    711411695 :               rclass = cost_classes[k];
    2225    711411695 :               if (i_costs[k] < best_cost)
    2226              :                 {
    2227              :                   best_cost = i_costs[k];
    2228              :                   best = (enum reg_class) rclass;
    2229              :                 }
    2230    649623699 :               else if (i_costs[k] == best_cost)
    2231    307596620 :                 best = ira_reg_class_subunion[best][rclass];
    2232    711411695 :               if (pass == flag_expensive_optimizations
    2233              :                   /* We still prefer registers to memory even at this
    2234              :                      stage if their costs are the same.  We will make
    2235              :                      a final decision during assigning hard registers
    2236              :                      when we have all info including more accurate
    2237              :                      costs which might be affected by assigning hard
    2238              :                      registers to other pseudos because the pseudos
    2239              :                      involved in moves can be coalesced.  */
    2240    406855011 :                   && i_costs[k] <= i_mem_cost
    2241    280719507 :                   && (reg_class_size[reg_class_subunion[alt_class][rclass]]
    2242    280719507 :                       > reg_class_size[alt_class]))
    2243    711411695 :                 alt_class = reg_class_subunion[alt_class][rclass];
    2244              :             }
    2245     50267231 :           alt_class = ira_allocno_class_translate[alt_class];
    2246     50267231 :           if (best_cost > i_mem_cost
    2247     50267231 :               && ! non_spilled_static_chain_regno_p (i))
    2248       783819 :             regno_aclass[i] = NO_REGS;
    2249     49483412 :           else if (!optimize && !targetm.class_likely_spilled_p (best))
    2250              :             /* Registers in the alternative class are likely to need
    2251              :                longer or slower sequences than registers in the best class.
    2252              :                When optimizing we make some effort to use the best class
    2253              :                over the alternative class where possible, but at -O0 we
    2254              :                effectively give the alternative class equal weight.
    2255              :                We then run the risk of using slower alternative registers
    2256              :                when plenty of registers from the best class are still free.
    2257              :                This is especially true because live ranges tend to be very
    2258              :                short in -O0 code and so register pressure tends to be low.
    2259              : 
    2260              :                Avoid that by ignoring the alternative class if the best
    2261              :                class has plenty of registers.
    2262              : 
    2263              :                The union class arrays give important classes and only
    2264              :                part of it are allocno classes.  So translate them into
    2265              :                allocno classes.  */
    2266      9658884 :             regno_aclass[i] = ira_allocno_class_translate[best];
    2267              :           else
    2268              :             {
    2269              :               /* Make the common class the biggest class of best and
    2270              :                  alt_class.  Translate the common class into an
    2271              :                  allocno class too.  */
    2272     39824528 :               regno_aclass[i] = (ira_allocno_class_translate
    2273     39824528 :                                  [ira_reg_class_superunion[best][alt_class]]);
    2274     39824528 :               ira_assert (regno_aclass[i] != NO_REGS
    2275              :                           && ira_reg_allocno_class_p[regno_aclass[i]]);
    2276              :             }
    2277     50267231 :           if (pic_offset_table_rtx != NULL
    2278     50267231 :               && i == (int) REGNO (pic_offset_table_rtx))
    2279              :             {
    2280              :               /* For some targets, integer pseudos can be assigned to fp
    2281              :                  regs.  As we don't want reload pic offset table pseudo, we
    2282              :                  should avoid using non-integer regs.  */
    2283        82283 :               regno_aclass[i]
    2284        82283 :                 = ira_reg_class_intersect[regno_aclass[i]][GENERAL_REGS];
    2285        82283 :               alt_class = ira_reg_class_intersect[alt_class][GENERAL_REGS];
    2286              :             }
    2287    100534462 :           if ((new_class
    2288    100534462 :                = (reg_class) (targetm.ira_change_pseudo_allocno_class
    2289     50267231 :                               (i, regno_aclass[i], best))) != regno_aclass[i])
    2290              :             {
    2291            0 :               regno_aclass[i] = new_class;
    2292            0 :               if (hard_reg_set_subset_p (reg_class_contents[new_class],
    2293            0 :                                          reg_class_contents[best]))
    2294            0 :                 best = new_class;
    2295            0 :               if (hard_reg_set_subset_p (reg_class_contents[new_class],
    2296            0 :                                          reg_class_contents[alt_class]))
    2297            0 :                 alt_class = new_class;
    2298              :             }
    2299     50267231 :           if (pass == flag_expensive_optimizations)
    2300              :             {
    2301     31598601 :               if (best_cost > i_mem_cost
    2302              :                   /* Do not assign NO_REGS to static chain pointer
    2303              :                      pseudo when non-local goto is used.  */
    2304     31598601 :                   && ! non_spilled_static_chain_regno_p (i))
    2305              :                 best = alt_class = NO_REGS;
    2306     31104709 :               else if (best == alt_class)
    2307     21881373 :                 alt_class = NO_REGS;
    2308     31598601 :               setup_reg_classes (i, best, alt_class, regno_aclass[i]);
    2309     31598601 :               if ((!allocno_p || internal_flag_ira_verbose > 2)
    2310     31598601 :                   && ira_dump_file != NULL)
    2311          969 :                 fprintf (ira_dump_file,
    2312              :                          "    r%d: preferred %s, alternative %s, allocno %s\n",
    2313          969 :                          i, reg_class_names[best], reg_class_names[alt_class],
    2314          969 :                          reg_class_names[regno_aclass[i]]);
    2315              :             }
    2316     50267231 :           regno_best_class[i] = best;
    2317     50267231 :           if (! allocno_p)
    2318              :             {
    2319      5705480 :               pref[i] = (best_cost > i_mem_cost
    2320         2852 :                          && ! non_spilled_static_chain_regno_p (i)
    2321      2852740 :                          ? NO_REGS : best);
    2322      2852740 :               continue;
    2323              :             }
    2324     47414491 :           for (a = ira_regno_allocno_map[i];
    2325    105498343 :                a != NULL;
    2326     58083852 :                a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
    2327              :             {
    2328     58083852 :               enum reg_class aclass = regno_aclass[i];
    2329     58083852 :               int a_num = ALLOCNO_NUM (a);
    2330     58083852 :               int *total_a_costs = COSTS (total_allocno_costs, a_num)->cost;
    2331     58083852 :               int *a_costs = COSTS (costs, a_num)->cost;
    2332              : 
    2333     58083852 :               if (aclass == NO_REGS)
    2334              :                 best = NO_REGS;
    2335              :               else
    2336              :                 {
    2337              :                   /* Finding best class which is subset of the common
    2338              :                      class.  */
    2339              :                   best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1;
    2340              :                   allocno_cost = best_cost;
    2341              :                   best = ALL_REGS;
    2342    850396228 :                   for (k = 0; k < cost_classes_ptr->num; k++)
    2343              :                     {
    2344    793314843 :                       rclass = cost_classes[k];
    2345    793314843 :                       if (! ira_class_subset_p[rclass][aclass])
    2346    380699239 :                         continue;
    2347    412615604 :                       if (total_a_costs[k] < best_cost)
    2348              :                         {
    2349     61934021 :                           best_cost = total_a_costs[k];
    2350     61934021 :                           allocno_cost = a_costs[k];
    2351     61934021 :                           best = (enum reg_class) rclass;
    2352              :                         }
    2353    350681583 :                       else if (total_a_costs[k] == best_cost)
    2354              :                         {
    2355    287140744 :                           best = ira_reg_class_subunion[best][rclass];
    2356    287140744 :                           allocno_cost = MAX (allocno_cost, a_costs[k]);
    2357              :                         }
    2358              :                     }
    2359     57081385 :                   ALLOCNO_CLASS_COST (a) = allocno_cost;
    2360              :                 }
    2361     58083852 :               if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL
    2362         1214 :                   && (pass == 0 || pref[a_num] != best))
    2363              :                 {
    2364          777 :                   fprintf (ira_dump_file, "    a%d (r%d,", a_num, i);
    2365          777 :                   if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
    2366            0 :                     fprintf (ira_dump_file, "b%d", bb->index);
    2367              :                   else
    2368          777 :                     fprintf (ira_dump_file, "l%d",
    2369              :                              ALLOCNO_LOOP_TREE_NODE (a)->loop_num);
    2370          777 :                   fprintf (ira_dump_file, ") best %s, allocno %s\n",
    2371          777 :                            reg_class_names[best],
    2372          777 :                            reg_class_names[aclass]);
    2373              :                 }
    2374     58083852 :               pref[a_num] = best;
    2375     58083852 :               if (pass == flag_expensive_optimizations && best != aclass
    2376      7680949 :                   && ira_class_hard_regs_num[best] > 0
    2377      7680949 :                   && (ira_reg_class_max_nregs[best][ALLOCNO_MODE (a)]
    2378              :                       >= ira_class_hard_regs_num[best]))
    2379              :                 {
    2380      6954440 :                   int ind = cost_classes_ptr->index[aclass];
    2381              : 
    2382      6954440 :                   ira_assert (ind >= 0);
    2383      6954440 :                   ira_init_register_move_cost_if_necessary (ALLOCNO_MODE (a));
    2384      6954440 :                   ira_add_allocno_pref (a, ira_class_hard_regs[best][0],
    2385      6954440 :                                         (a_costs[ind] - ALLOCNO_CLASS_COST (a))
    2386              :                                         / (ira_register_move_cost
    2387      6954440 :                                            [ALLOCNO_MODE (a)][best][aclass]));
    2388    137906107 :                   for (k = 0; k < cost_classes_ptr->num; k++)
    2389    123997227 :                     if (ira_class_subset_p[cost_classes[k]][best])
    2390      6954440 :                       a_costs[k] = a_costs[ind];
    2391              :                 }
    2392              :             }
    2393              :         }
    2394              : 
    2395      2540908 :       if (internal_flag_ira_verbose > 4 && ira_dump_file)
    2396              :         {
    2397          143 :           if (allocno_p)
    2398          127 :             print_allocno_costs ();
    2399              :           else
    2400           16 :             print_pseudo_costs ();
    2401          143 :           fprintf (ira_dump_file,"\n");
    2402              :         }
    2403              :     }
    2404      1534757 :   ira_free (regno_best_class);
    2405      1534757 : }
    2406              : 
    2407              : 
    2408              : 
    2409              : /* Process moves involving hard regs to modify allocno hard register
    2410              :    costs.  We can do this only after determining allocno class.  If a
    2411              :    hard register forms a register class, then moves with the hard
    2412              :    register are already taken into account in class costs for the
    2413              :    allocno.  */
    2414              : static void
    2415     12794030 : process_bb_node_for_hard_reg_moves (ira_loop_tree_node_t loop_tree_node)
    2416              : {
    2417     12794030 :   int i, freq, src_regno, dst_regno, hard_regno, a_regno;
    2418     12794030 :   bool to_p;
    2419     12794030 :   ira_allocno_t a, curr_a;
    2420     12794030 :   ira_loop_tree_node_t curr_loop_tree_node;
    2421     12794030 :   enum reg_class rclass;
    2422     12794030 :   basic_block bb;
    2423     12794030 :   rtx_insn *insn;
    2424     12794030 :   rtx set, src, dst;
    2425              : 
    2426     12794030 :   bb = loop_tree_node->bb;
    2427     12794030 :   if (bb == NULL)
    2428              :     return;
    2429     11127503 :   freq = REG_FREQ_FROM_BB (bb);
    2430      8704116 :   if (freq == 0)
    2431      2053720 :     freq = 1;
    2432    143779512 :   FOR_BB_INSNS (bb, insn)
    2433              :     {
    2434    132652009 :       if (!NONDEBUG_INSN_P (insn))
    2435     73278159 :         continue;
    2436     59373850 :       set = single_set (insn);
    2437     59373850 :       if (set == NULL_RTX)
    2438      3933616 :         continue;
    2439     55440234 :       dst = SET_DEST (set);
    2440     55440234 :       src = SET_SRC (set);
    2441     55440234 :       if (! REG_P (dst) || ! REG_P (src))
    2442     46152859 :         continue;
    2443      9287375 :       dst_regno = REGNO (dst);
    2444      9287375 :       src_regno = REGNO (src);
    2445      9287375 :       if (dst_regno >= FIRST_PSEUDO_REGISTER
    2446      9287375 :           && src_regno < FIRST_PSEUDO_REGISTER)
    2447              :         {
    2448      3017473 :           hard_regno = src_regno;
    2449      3017473 :           a = ira_curr_regno_allocno_map[dst_regno];
    2450      3017473 :           to_p = true;
    2451              :         }
    2452      7655091 :       else if (src_regno >= FIRST_PSEUDO_REGISTER
    2453      6269902 :                && dst_regno < FIRST_PSEUDO_REGISTER)
    2454              :         {
    2455      4884713 :           hard_regno = dst_regno;
    2456      4884713 :           a = ira_curr_regno_allocno_map[src_regno];
    2457      4884713 :           to_p = false;
    2458              :         }
    2459              :       else
    2460      1385189 :         continue;
    2461     15326089 :       if (reg_class_size[(int) REGNO_REG_CLASS (hard_regno)]
    2462              :           == (ira_reg_class_max_nregs
    2463      7902186 :               [REGNO_REG_CLASS (hard_regno)][(int) ALLOCNO_MODE(a)]))
    2464              :         /* If the class can provide only one hard reg to the allocno,
    2465              :            we processed the insn record_operand_costs already and we
    2466              :            actually updated the hard reg cost there.  */
    2467      7423903 :         continue;
    2468       478283 :       rclass = ALLOCNO_CLASS (a);
    2469       478283 :       if (! TEST_HARD_REG_BIT (reg_class_contents[rclass], hard_regno))
    2470        23402 :         continue;
    2471       454881 :       i = ira_class_hard_reg_index[rclass][hard_regno];
    2472       454881 :       if (i < 0)
    2473         7108 :         continue;
    2474       447773 :       a_regno = ALLOCNO_REGNO (a);
    2475       447773 :       for (curr_loop_tree_node = ALLOCNO_LOOP_TREE_NODE (a);
    2476       985103 :            curr_loop_tree_node != NULL;
    2477       537330 :            curr_loop_tree_node = curr_loop_tree_node->parent)
    2478       537330 :         if ((curr_a = curr_loop_tree_node->regno_allocno_map[a_regno]) != NULL)
    2479       466713 :           ira_add_allocno_pref (curr_a, hard_regno, freq);
    2480       447773 :       {
    2481       447773 :         int cost;
    2482       447773 :         enum reg_class hard_reg_class;
    2483       447773 :         machine_mode mode;
    2484              : 
    2485       447773 :         mode = ALLOCNO_MODE (a);
    2486       447773 :         hard_reg_class = REGNO_REG_CLASS (hard_regno);
    2487       447773 :         ira_init_register_move_cost_if_necessary (mode);
    2488       447773 :         cost = (to_p ? ira_register_move_cost[mode][hard_reg_class][rclass]
    2489       248800 :                 : ira_register_move_cost[mode][rclass][hard_reg_class]) * freq;
    2490       447773 :         ira_allocate_and_set_costs (&ALLOCNO_HARD_REG_COSTS (a), rclass,
    2491              :                                     ALLOCNO_CLASS_COST (a));
    2492       447773 :         ira_allocate_and_set_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a),
    2493              :                                     rclass, 0);
    2494       447773 :         ALLOCNO_HARD_REG_COSTS (a)[i] -= cost;
    2495       447773 :         ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[i] -= cost;
    2496       447773 :         ALLOCNO_CLASS_COST (a) = MIN (ALLOCNO_CLASS_COST (a),
    2497              :                                       ALLOCNO_HARD_REG_COSTS (a)[i]);
    2498              :       }
    2499              :     }
    2500              : }
    2501              : 
    2502              : /* After we find hard register and memory costs for allocnos, define
    2503              :    its class and modify hard register cost because insns moving
    2504              :    allocno to/from hard registers.  */
    2505              : static void
    2506      1504950 : setup_allocno_class_and_costs (void)
    2507              : {
    2508      1504950 :   int i, j, n, regno, hard_regno, num;
    2509      1504950 :   int *reg_costs;
    2510      1504950 :   enum reg_class aclass, rclass;
    2511      1504950 :   ira_allocno_t a;
    2512      1504950 :   ira_allocno_iterator ai;
    2513      1504950 :   cost_classes_t cost_classes_ptr;
    2514              : 
    2515      1504950 :   ira_assert (allocno_p);
    2516     37205581 :   FOR_EACH_ALLOCNO (a, ai)
    2517              :     {
    2518     35700631 :       i = ALLOCNO_NUM (a);
    2519     35700631 :       regno = ALLOCNO_REGNO (a);
    2520     35700631 :       aclass = regno_aclass[regno];
    2521     35700631 :       cost_classes_ptr = regno_cost_classes[regno];
    2522     35700631 :       ira_assert (pref[i] == NO_REGS || aclass != NO_REGS);
    2523     35700631 :       ALLOCNO_MEMORY_COST (a) = COSTS (costs, i)->mem_cost;
    2524     35700631 :       ira_set_allocno_class (a, aclass);
    2525     35700631 :       if (aclass == NO_REGS)
    2526       696358 :         continue;
    2527     35004273 :       if (optimize && ALLOCNO_CLASS (a) != pref[i])
    2528              :         {
    2529      5711603 :           n = ira_class_hard_regs_num[aclass];
    2530      5711603 :           ALLOCNO_HARD_REG_COSTS (a)
    2531      5711603 :             = reg_costs = ira_allocate_cost_vector (aclass);
    2532    102030025 :           for (j = n - 1; j >= 0; j--)
    2533              :             {
    2534     96318422 :               hard_regno = ira_class_hard_regs[aclass][j];
    2535     96318422 :               if (TEST_HARD_REG_BIT (reg_class_contents[pref[i]], hard_regno))
    2536     15479124 :                 reg_costs[j] = ALLOCNO_CLASS_COST (a);
    2537              :               else
    2538              :                 {
    2539     80839298 :                   rclass = REGNO_REG_CLASS (hard_regno);
    2540     80839298 :                   num = cost_classes_ptr->index[rclass];
    2541     80839298 :                   if (num < 0)
    2542              :                     {
    2543       280206 :                       num = cost_classes_ptr->hard_regno_index[hard_regno];
    2544       280206 :                       ira_assert (num >= 0);
    2545              :                     }
    2546     80839298 :                   reg_costs[j] = COSTS (costs, i)->cost[num];
    2547              :                 }
    2548              :             }
    2549              :         }
    2550              :     }
    2551      1504950 :   if (optimize)
    2552      1057059 :     ira_traverse_loop_tree (true, ira_loop_tree_root,
    2553              :                             process_bb_node_for_hard_reg_moves, NULL);
    2554      1504950 : }
    2555              : 
    2556              : 
    2557              : 
    2558              : /* Function called once during compiler work.  */
    2559              : void
    2560       214556 : ira_init_costs_once (void)
    2561              : {
    2562       214556 :   int i;
    2563              : 
    2564       214556 :   init_cost = NULL;
    2565      6651236 :   for (i = 0; i < MAX_RECOG_OPERANDS; i++)
    2566              :     {
    2567      6436680 :       op_costs[i] = NULL;
    2568      6436680 :       this_op_costs[i] = NULL;
    2569              :     }
    2570       214556 :   temp_costs = NULL;
    2571       214556 : }
    2572              : 
    2573              : /* Free allocated temporary cost vectors.  */
    2574              : void
    2575       802629 : target_ira_int::free_ira_costs ()
    2576              : {
    2577       802629 :   int i;
    2578              : 
    2579       802629 :   free (x_init_cost);
    2580       802629 :   x_init_cost = NULL;
    2581     24881499 :   for (i = 0; i < MAX_RECOG_OPERANDS; i++)
    2582              :     {
    2583     24078870 :       free (x_op_costs[i]);
    2584     24078870 :       free (x_this_op_costs[i]);
    2585     24078870 :       x_op_costs[i] = x_this_op_costs[i] = NULL;
    2586              :     }
    2587       802629 :   free (x_temp_costs);
    2588       802629 :   x_temp_costs = NULL;
    2589       802629 : }
    2590              : 
    2591              : /* This is called each time register related information is
    2592              :    changed.  */
    2593              : void
    2594       218792 : ira_init_costs (void)
    2595              : {
    2596       218792 :   int i;
    2597              : 
    2598       218792 :   this_target_ira_int->free_ira_costs ();
    2599       218792 :   max_struct_costs_size
    2600       218792 :     = sizeof (struct costs) + sizeof (int) * (ira_important_classes_num - 1);
    2601              :   /* Don't use ira_allocate because vectors live through several IRA
    2602              :      calls.  */
    2603       218792 :   init_cost = (struct costs *) xmalloc (max_struct_costs_size);
    2604       218792 :   init_cost->mem_cost = 1000000;
    2605      7005085 :   for (i = 0; i < ira_important_classes_num; i++)
    2606      6786293 :     init_cost->cost[i] = 1000000;
    2607      6782552 :   for (i = 0; i < MAX_RECOG_OPERANDS; i++)
    2608              :     {
    2609      6563760 :       op_costs[i] = (struct costs *) xmalloc (max_struct_costs_size);
    2610      6563760 :       this_op_costs[i] = (struct costs *) xmalloc (max_struct_costs_size);
    2611              :     }
    2612       218792 :   temp_costs = (struct costs *) xmalloc (max_struct_costs_size);
    2613       218792 : }
    2614              : 
    2615              : 
    2616              : 
    2617              : /* Common initialization function for ira_costs and
    2618              :    ira_set_pseudo_classes.  */
    2619              : static void
    2620      1534757 : init_costs (void)
    2621              : {
    2622      1534757 :   init_subregs_of_mode ();
    2623      3069514 :   costs = (struct costs *) ira_allocate (max_struct_costs_size
    2624      1534757 :                                          * cost_elements_num);
    2625      3069514 :   pref_buffer = (enum reg_class *) ira_allocate (sizeof (enum reg_class)
    2626      1534757 :                                                  * cost_elements_num);
    2627      4604271 :   regno_aclass = (enum reg_class *) ira_allocate (sizeof (enum reg_class)
    2628      1534757 :                                                  * max_reg_num ());
    2629      1534757 :   regno_equiv_gains = (int *) ira_allocate (sizeof (int) * max_reg_num ());
    2630      1534757 :   memset (regno_equiv_gains, 0, sizeof (int) * max_reg_num ());
    2631      1534757 : }
    2632              : 
    2633              : /* Common finalization function for ira_costs and
    2634              :    ira_set_pseudo_classes.  */
    2635              : static void
    2636      1534757 : finish_costs (void)
    2637              : {
    2638      1534757 :   finish_subregs_of_mode ();
    2639      1534757 :   ira_free (regno_equiv_gains);
    2640      1534757 :   ira_free (regno_aclass);
    2641      1534757 :   ira_free (pref_buffer);
    2642      1534757 :   ira_free (costs);
    2643      1534757 : }
    2644              : 
    2645              : /* Entry function which defines register class, memory and hard
    2646              :    register costs for each allocno.  */
    2647              : void
    2648      1504950 : ira_costs (void)
    2649              : {
    2650      1504950 :   allocno_p = true;
    2651      1504950 :   cost_elements_num = ira_allocnos_num;
    2652      1504950 :   init_costs ();
    2653      3009900 :   total_allocno_costs = (struct costs *) ira_allocate (max_struct_costs_size
    2654      1504950 :                                                        * ira_allocnos_num);
    2655      1504950 :   initiate_regno_cost_classes ();
    2656      1504950 :   if (!ira_use_lra_p)
    2657              :     /* Process equivs in reload to update costs through hook
    2658              :        ira_adjust_equiv_reg_cost.  */
    2659            0 :     calculate_elim_costs_all_insns ();
    2660      1504950 :   find_costs_and_classes ();
    2661      1504950 :   setup_allocno_class_and_costs ();
    2662      1504950 :   finish_regno_cost_classes ();
    2663      1504950 :   finish_costs ();
    2664      1504950 :   ira_free (total_allocno_costs);
    2665      1504950 : }
    2666              : 
    2667              : /* Entry function which defines classes for pseudos.
    2668              :    Set pseudo_classes_defined_p only if DEFINE_PSEUDO_CLASSES is true.  */
    2669              : void
    2670        29807 : ira_set_pseudo_classes (bool define_pseudo_classes, FILE *dump_file)
    2671              : {
    2672        29807 :   FILE *saved_file = ira_dump_file;
    2673        29807 :   allocno_p = false;
    2674        29807 :   internal_flag_ira_verbose = flag_ira_verbose;
    2675        29807 :   ira_dump_file = dump_file;
    2676        29807 :   cost_elements_num = max_reg_num ();
    2677        29807 :   init_costs ();
    2678        29807 :   initiate_regno_cost_classes ();
    2679        29807 :   find_costs_and_classes ();
    2680        29807 :   finish_regno_cost_classes ();
    2681        29807 :   if (define_pseudo_classes)
    2682          101 :     pseudo_classes_defined_p = true;
    2683              : 
    2684        29807 :   finish_costs ();
    2685        29807 :   ira_dump_file = saved_file;
    2686        29807 : }
    2687              : 
    2688              : 
    2689              : 
    2690              : /* Change hard register costs for allocnos which lives through
    2691              :    function calls.  This is called only when we found all intersected
    2692              :    calls during building allocno live ranges.  */
    2693              : void
    2694      1504950 : ira_tune_allocno_costs (void)
    2695              : {
    2696      1504950 :   int j, n, regno;
    2697      1504950 :   int cost, min_cost, *reg_costs;
    2698      1504950 :   enum reg_class aclass;
    2699      1504950 :   machine_mode mode;
    2700      1504950 :   ira_allocno_t a;
    2701      1504950 :   ira_allocno_iterator ai;
    2702      1504950 :   ira_allocno_object_iterator oi;
    2703      1504950 :   ira_object_t obj;
    2704      1504950 :   bool skip_p;
    2705              : 
    2706     38438235 :   FOR_EACH_ALLOCNO (a, ai)
    2707              :     {
    2708     36933285 :       aclass = ALLOCNO_CLASS (a);
    2709     36933285 :       if (aclass == NO_REGS)
    2710       666236 :         continue;
    2711     36267049 :       mode = ALLOCNO_MODE (a);
    2712     36267049 :       n = ira_class_hard_regs_num[aclass];
    2713     36267049 :       min_cost = INT_MAX;
    2714     36267049 :       if (ALLOCNO_CALLS_CROSSED_NUM (a)
    2715     36267049 :           != ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a))
    2716              :         {
    2717      3635915 :           ira_allocate_and_set_costs
    2718      3635915 :             (&ALLOCNO_HARD_REG_COSTS (a), aclass,
    2719              :              ALLOCNO_CLASS_COST (a));
    2720      3635915 :           reg_costs = ALLOCNO_HARD_REG_COSTS (a);
    2721     52855782 :           for (j = n - 1; j >= 0; j--)
    2722              :             {
    2723     49219867 :               regno = ira_class_hard_regs[aclass][j];
    2724     49219867 :               skip_p = false;
    2725     88498937 :               FOR_EACH_ALLOCNO_OBJECT (a, obj, oi)
    2726              :                 {
    2727     50629643 :                   if (ira_hard_reg_set_intersection_p (regno, mode,
    2728              :                                                        OBJECT_CONFLICT_HARD_REGS
    2729              :                                                        (obj)))
    2730              :                     {
    2731              :                       skip_p = true;
    2732              :                       break;
    2733              :                     }
    2734              :                 }
    2735     49219867 :               if (skip_p)
    2736     11350573 :                 continue;
    2737     37869294 :               cost = 0;
    2738     37869294 :               if (ira_need_caller_save_p (a, regno))
    2739     19534377 :                 cost += ira_caller_save_cost (a);
    2740              : #ifdef IRA_HARD_REGNO_ADD_COST_MULTIPLIER
    2741              :               {
    2742              :                 auto rclass = REGNO_REG_CLASS (regno);
    2743              :                 cost += ((ira_memory_move_cost[mode][rclass][0]
    2744              :                           + ira_memory_move_cost[mode][rclass][1])
    2745              :                          * ALLOCNO_FREQ (a)
    2746              :                          * IRA_HARD_REGNO_ADD_COST_MULTIPLIER (regno) / 2);
    2747              :               }
    2748              : #endif
    2749     37869294 :               if (INT_MAX - cost < reg_costs[j])
    2750            0 :                 reg_costs[j] = INT_MAX;
    2751              :               else
    2752     37869294 :                 reg_costs[j] += cost;
    2753     37869294 :               if (min_cost > reg_costs[j])
    2754     49219867 :                 min_cost = reg_costs[j];
    2755              :             }
    2756              :         }
    2757      3635915 :       if (min_cost != INT_MAX)
    2758      3619786 :         ALLOCNO_CLASS_COST (a) = min_cost;
    2759              : 
    2760              :       /* Some targets allow pseudos to be allocated to unaligned sequences
    2761              :          of hard registers.  However, selecting an unaligned sequence can
    2762              :          unnecessarily restrict later allocations.  So increase the cost of
    2763              :          unaligned hard regs to encourage the use of aligned hard regs.  */
    2764     36267049 :       {
    2765     36267049 :         const int nregs = ira_reg_class_max_nregs[aclass][ALLOCNO_MODE (a)];
    2766              : 
    2767     36267049 :         if (nregs > 1)
    2768              :           {
    2769      1322643 :             ira_allocate_and_set_costs
    2770      1322643 :               (&ALLOCNO_HARD_REG_COSTS (a), aclass, ALLOCNO_CLASS_COST (a));
    2771      1322643 :             reg_costs = ALLOCNO_HARD_REG_COSTS (a);
    2772     29600054 :             for (j = n - 1; j >= 0; j--)
    2773              :               {
    2774     28277411 :                 regno = ira_non_ordered_class_hard_regs[aclass][j];
    2775     28277411 :                 if ((regno % nregs) != 0)
    2776              :                   {
    2777     13900064 :                     int index = ira_class_hard_reg_index[aclass][regno];
    2778     13900064 :                     ira_assert (index != -1);
    2779     13900064 :                     reg_costs[index] += ALLOCNO_FREQ (a);
    2780              :                   }
    2781              :               }
    2782              :           }
    2783              :       }
    2784              :     }
    2785      1504950 : }
    2786              : 
    2787              : /* A hook from the reload pass.  Add COST to the estimated gain for eliminating
    2788              :    REGNO with its equivalence.  If COST is zero, record that no such
    2789              :    elimination is possible.  */
    2790              : 
    2791              : void
    2792            0 : ira_adjust_equiv_reg_cost (unsigned regno, int cost)
    2793              : {
    2794            0 :   ira_assert (!ira_use_lra_p);
    2795            0 :   if (cost == 0)
    2796            0 :     regno_equiv_gains[regno] = 0;
    2797              :   else
    2798            0 :     regno_equiv_gains[regno] += cost;
    2799            0 : }
    2800              : 
    2801              : void
    2802       262609 : ira_costs_cc_finalize (void)
    2803              : {
    2804       262609 :   this_target_ira_int->free_ira_costs ();
    2805       262609 : }
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.