LCOV - code coverage report
Current view: top level - gcc - ira-costs.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.5 % 1392 1287
Test Date: 2025-03-15 13:07:15 Functions: 97.2 % 36 35
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* IRA hard register and memory cost calculation for allocnos or pseudos.
       2                 :             :    Copyright (C) 2006-2025 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                 :   103654745 : cost_classes_hasher::hash (const cost_classes *hv)
     145                 :             : {
     146                 :   103654745 :   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                 :    95906021 : cost_classes_hasher::equal (const cost_classes *hv1, const cost_classes *hv2)
     152                 :             : {
     153                 :    95906021 :   return (hv1->num == hv2->num
     154                 :    95906021 :           && memcmp (hv1->classes, hv2->classes,
     155                 :    49311115 :                      sizeof (enum reg_class) * hv1->num) == 0);
     156                 :             : }
     157                 :             : 
     158                 :             : /* Delete cost classes info V from the hash table.  */
     159                 :             : inline void
     160                 :     5816876 : cost_classes_hasher::remove (cost_classes *v)
     161                 :             : {
     162                 :     5816876 :   ira_free (v);
     163                 :     5816876 : }
     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                 :     7276719 : complete_cost_classes (cost_classes_t classes_ptr)
     182                 :             : {
     183                 :   254685165 :   for (int i = 0; i < N_REG_CLASSES; i++)
     184                 :   247408446 :     classes_ptr->index[i] = -1;
     185                 :   676734867 :   for (int i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     186                 :   669458148 :     classes_ptr->hard_regno_index[i] = -1;
     187                 :   150641069 :   for (int i = 0; i < classes_ptr->num; i++)
     188                 :             :     {
     189                 :   143364350 :       enum reg_class cl = classes_ptr->classes[i];
     190                 :   143364350 :       classes_ptr->index[cl] = i;
     191                 :  1657173259 :       for (int j = ira_class_hard_regs_num[cl] - 1; j >= 0; j--)
     192                 :             :         {
     193                 :  1513808909 :           unsigned int hard_regno = ira_class_hard_regs[cl][j];
     194                 :  1513808909 :           if (classes_ptr->hard_regno_index[hard_regno] < 0)
     195                 :   288348902 :             classes_ptr->hard_regno_index[hard_regno] = i;
     196                 :             :         }
     197                 :             :     }
     198                 :     7276719 : }
     199                 :             : 
     200                 :             : /* Initialize info about the cost classes for each pseudo.  */
     201                 :             : static void
     202                 :     1459843 : initiate_regno_cost_classes (void)
     203                 :             : {
     204                 :     1459843 :   int size = sizeof (cost_classes_t) * max_reg_num ();
     205                 :             : 
     206                 :     1459843 :   regno_cost_classes = (cost_classes_t *) ira_allocate (size);
     207                 :     1459843 :   memset (regno_cost_classes, 0, size);
     208                 :     1459843 :   memset (cost_classes_aclass_cache, 0,
     209                 :             :           sizeof (cost_classes_t) * N_REG_CLASSES);
     210                 :     1459843 :   memset (cost_classes_mode_cache, 0,
     211                 :             :           sizeof (cost_classes_t) * MAX_MACHINE_MODE);
     212                 :     1459843 :   cost_classes_htab = new hash_table<cost_classes_hasher> (200);
     213                 :     1459843 :   all_cost_classes.num = ira_important_classes_num;
     214                 :    46821896 :   for (int i = 0; i < ira_important_classes_num; i++)
     215                 :    45362053 :     all_cost_classes.classes[i] = ira_important_classes[i];
     216                 :     1459843 :   complete_cost_classes (&all_cost_classes);
     217                 :     1459843 : }
     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                 :     5816876 : setup_cost_classes (cost_classes_t from)
     226                 :             : {
     227                 :     5816876 :   cost_classes_t classes_ptr;
     228                 :             : 
     229                 :     5816876 :   classes_ptr = (cost_classes_t) ira_allocate (sizeof (struct cost_classes));
     230                 :     5816876 :   classes_ptr->num = from->num;
     231                 :   103819173 :   for (int i = 0; i < from->num; i++)
     232                 :    98002297 :     classes_ptr->classes[i] = from->classes[i];
     233                 :     5816876 :   complete_cost_classes (classes_ptr);
     234                 :     5816876 :   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                 :    51161401 : restrict_cost_classes (cost_classes_t full, machine_mode mode,
     242                 :             :                        const_hard_reg_set regs)
     243                 :             : {
     244                 :    51161401 :   static struct cost_classes narrow;
     245                 :    51161401 :   int map[N_REG_CLASSES];
     246                 :    51161401 :   narrow.num = 0;
     247                 :  1492295650 :   for (int i = 0; i < full->num; i++)
     248                 :             :     {
     249                 :             :       /* Assume that we'll drop the class.  */
     250                 :  1441134249 :       map[i] = -1;
     251                 :             : 
     252                 :             :       /* Ignore classes that are too small for the mode.  */
     253                 :  1441134249 :       enum reg_class cl = full->classes[i];
     254                 :  1441134249 :       if (!contains_reg_of_mode[cl][mode])
     255                 :   286907999 :         continue;
     256                 :             : 
     257                 :             :       /* Calculate the set of registers in CL that belong to REGS and
     258                 :             :          are valid for MODE.  */
     259                 :  1173905177 :       HARD_REG_SET valid_for_cl = reg_class_contents[cl] & regs;
     260                 :  2347810354 :       valid_for_cl &= ~(ira_prohibited_class_mode_regs[cl][mode]
     261                 :  1173905177 :                         | ira_no_alloc_regs);
     262                 :  2347810354 :       if (hard_reg_set_empty_p (valid_for_cl))
     263                 :    19678927 :         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                 : 11769082707 :       for (pos = 0; pos < narrow.num; ++pos)
     290                 :             :         {
     291                 : 11017860932 :           enum reg_class cl2 = narrow.classes[pos];
     292                 : 22035721864 :           if (hard_reg_set_subset_p (valid_for_cl, reg_class_contents[cl2]))
     293                 :             :             break;
     294                 :             :         }
     295                 :  1154226250 :       map[i] = pos;
     296                 :  1154226250 :       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                 :   751221775 :           enum reg_class cl2 = ira_allocno_class_translate[cl];
     301                 :   751221775 :           if (ira_class_hard_regs_num[cl] == ira_class_hard_regs_num[cl2])
     302                 :   751221775 :             cl = cl2;
     303                 :   751221775 :           narrow.classes[narrow.num++] = cl;
     304                 :             :         }
     305                 :             :     }
     306                 :    51161401 :   if (narrow.num == full->num)
     307                 :             :     return full;
     308                 :             : 
     309                 :    51160655 :   cost_classes **slot = cost_classes_htab->find_slot (&narrow, INSERT);
     310                 :    51160655 :   if (*slot == NULL)
     311                 :             :     {
     312                 :     3963806 :       cost_classes_t classes = setup_cost_classes (&narrow);
     313                 :             :       /* Map equivalent classes to the representative that we chose above.  */
     314                 :   127296054 :       for (int i = 0; i < ira_important_classes_num; i++)
     315                 :             :         {
     316                 :   123332248 :           enum reg_class cl = ira_important_classes[i];
     317                 :   123332248 :           int index = full->index[cl];
     318                 :   123332248 :           if (index >= 0)
     319                 :   109805555 :             classes->index[cl] = map[index];
     320                 :             :         }
     321                 :     3963806 :       *slot = classes;
     322                 :             :     }
     323                 :    51160655 :   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                 :    46241291 : setup_regno_cost_classes_by_aclass (int regno, enum reg_class aclass)
     334                 :             : {
     335                 :    46241291 :   static struct cost_classes classes;
     336                 :    46241291 :   cost_classes_t classes_ptr;
     337                 :    46241291 :   enum reg_class cl;
     338                 :    46241291 :   int i;
     339                 :    46241291 :   cost_classes **slot;
     340                 :    46241291 :   HARD_REG_SET temp, temp2;
     341                 :    46241291 :   bool exclude_p;
     342                 :             : 
     343                 :    46241291 :   if ((classes_ptr = cost_classes_aclass_cache[aclass]) == NULL)
     344                 :             :     {
     345                 :     3959685 :       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                 :     3959685 :       exclude_p = ira_uniform_class_p[aclass];
     349                 :     3959685 :       classes.num = 0;
     350                 :   127106987 :       for (i = 0; i < ira_important_classes_num; i++)
     351                 :             :         {
     352                 :   123147302 :           cl = ira_important_classes[i];
     353                 :   123147302 :           if (exclude_p)
     354                 :             :             {
     355                 :             :               /* Exclude non-uniform classes which are subsets of
     356                 :             :                  ACLASS.  */
     357                 :    87800265 :               temp2 = reg_class_contents[cl] & ~ira_no_alloc_regs;
     358                 :   175600530 :               if (hard_reg_set_subset_p (temp2, temp) && cl != aclass)
     359                 :    10304493 :                 continue;
     360                 :             :             }
     361                 :   112842809 :           classes.classes[classes.num++] = cl;
     362                 :             :         }
     363                 :     3959685 :       slot = cost_classes_htab->find_slot (&classes, INSERT);
     364                 :     3959685 :       if (*slot == NULL)
     365                 :             :         {
     366                 :     1853070 :           classes_ptr = setup_cost_classes (&classes);
     367                 :     1853070 :           *slot = classes_ptr;
     368                 :             :         }
     369                 :     3959685 :       classes_ptr = cost_classes_aclass_cache[aclass] = (cost_classes_t) *slot;
     370                 :             :     }
     371                 :    46241291 :   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                 :    45640722 :       const HARD_REG_SET *valid_regs = valid_mode_changes_for_regno (regno);
     378                 :    45640722 :       if (!valid_regs)
     379                 :    44239108 :         valid_regs = &reg_class_contents[ALL_REGS];
     380                 :    45640722 :       classes_ptr = restrict_cost_classes (classes_ptr,
     381                 :    45640722 :                                            PSEUDO_REGNO_MODE (regno),
     382                 :             :                                            *valid_regs);
     383                 :             :     }
     384                 :    46241291 :   regno_cost_classes[regno] = classes_ptr;
     385                 :    46241291 : }
     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                 :    63728262 : setup_regno_cost_classes_by_mode (int regno, machine_mode mode)
     395                 :             : {
     396                 :    63728262 :   if (const HARD_REG_SET *valid_regs = valid_mode_changes_for_regno (regno))
     397                 :     1847293 :     regno_cost_classes[regno] = restrict_cost_classes (&all_cost_classes,
     398                 :             :                                                        mode, *valid_regs);
     399                 :             :   else
     400                 :             :     {
     401                 :    61880969 :       if (cost_classes_mode_cache[mode] == NULL)
     402                 :     3673386 :         cost_classes_mode_cache[mode]
     403                 :     3673386 :           = restrict_cost_classes (&all_cost_classes, mode,
     404                 :     3673386 :                                    reg_class_contents[ALL_REGS]);
     405                 :    61880969 :       regno_cost_classes[regno] = cost_classes_mode_cache[mode];
     406                 :             :     }
     407                 :    63728262 : }
     408                 :             : 
     409                 :             : /* Finalize info about the cost classes for each pseudo.  */
     410                 :             : static void
     411                 :     1459843 : finish_regno_cost_classes (void)
     412                 :             : {
     413                 :     1459843 :   ira_free (regno_cost_classes);
     414                 :     1459843 :   delete cost_classes_htab;
     415                 :     1459843 :   cost_classes_htab = NULL;
     416                 :     1459843 : }
     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                 :   358776489 : copy_cost (rtx x, machine_mode mode, reg_class_t rclass, bool to_p,
     425                 :             :            secondary_reload_info *prev_sri)
     426                 :             : {
     427                 :   358776489 :   secondary_reload_info sri;
     428                 :   358776489 :   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                 :   358776489 :   if (GET_CODE (x) == SCRATCH)
     433                 :             :     return 0;
     434                 :             : 
     435                 :             :   /* Get the class we will actually use for a reload.  */
     436                 :   358767258 :   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                 :   358767258 :   sri.prev_sri = prev_sri;
     442                 :   358767258 :   sri.extra_cost = 0;
     443                 :             :   /* PR 68770: Secondary reload might examine the t_icode field.  */
     444                 :   358767258 :   sri.t_icode = CODE_FOR_nothing;
     445                 :             : 
     446                 :   358767258 :   secondary_class = targetm.secondary_reload (to_p, x, rclass, mode, &sri);
     447                 :             : 
     448                 :   358767258 :   if (secondary_class != NO_REGS)
     449                 :             :     {
     450                 :       82856 :       ira_init_register_move_cost_if_necessary (mode);
     451                 :       82856 :       return (ira_register_move_cost[mode][(int) secondary_class][(int) rclass]
     452                 :       82856 :               + sri.extra_cost
     453                 :       82856 :               + 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                 :   358684402 :   if (MEM_P (x) || rclass == NO_REGS)
     460                 :   223077298 :     return sri.extra_cost
     461                 :   223077298 :            + ira_memory_move_cost[mode][(int) rclass][to_p != 0];
     462                 :   135607104 :   else if (REG_P (x))
     463                 :             :     {
     464                 :    43061156 :       reg_class_t x_class = REGNO_REG_CLASS (REGNO (x));
     465                 :             : 
     466                 :    43061156 :       ira_init_register_move_cost_if_necessary (mode);
     467                 :    43061156 :       return (sri.extra_cost
     468                 :    43061156 :               + 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                 :    92545948 :     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                 :   132577472 : 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                 :   132577472 :   int alt;
     504                 :   132577472 :   int i, j, k;
     505                 :   132577472 :   int insn_allows_mem[MAX_RECOG_OPERANDS];
     506                 :   132577472 :   move_table *move_in_cost, *move_out_cost;
     507                 :   132577472 :   short (*mem_cost)[2];
     508                 :   132577472 :   const char *p;
     509                 :             : 
     510                 :   132577472 :   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                 :   437187383 :   for (i = 0; i < n_ops; i++)
     522                 :   304609911 :     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                 :   132577472 :   alternative_mask preferred = get_preferred_alternatives (insn);
     527                 :  1494875930 :   for (alt = 0; alt < n_alts; alt++)
     528                 :             :     {
     529                 :  1362298458 :       enum reg_class classes[MAX_RECOG_OPERANDS];
     530                 :  1362298458 :       int allows_mem[MAX_RECOG_OPERANDS];
     531                 :  1362298458 :       enum reg_class rclass;
     532                 :  1362298458 :       int alt_fail = 0;
     533                 :  1362298458 :       int alt_cost = 0, op_cost_add;
     534                 :             : 
     535                 :  1362298458 :       if (!TEST_BIT (preferred, alt))
     536                 :             :         {
     537                 :  1386709269 :           for (i = 0; i < recog_data.n_operands; i++)
     538                 :  1919562652 :             constraints[i] = skip_alternative (constraints[i]);
     539                 :             : 
     540                 :   889269545 :           continue;
     541                 :             :         }
     542                 :             : 
     543                 :   935370515 :       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                 :  2222297563 :       for (i = 0; i < n_ops; i++)
     559                 :             :         {
     560                 :  1749268650 :           unsigned char c;
     561                 :  1749268650 :           const char *p = constraints[i];
     562                 :  1749268650 :           rtx op = ops[i];
     563                 :  1749268650 :           machine_mode mode = modes[i];
     564                 :  1749268650 :           int allows_addr = 0;
     565                 :  1749268650 :           int win = 0;
     566                 :             : 
     567                 :             :           /* Initially show we know nothing about the register class.  */
     568                 :  1749268650 :           classes[i] = NO_REGS;
     569                 :  1749268650 :           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                 :  1749268650 :           if (*p == 0)
     574                 :             :             {
     575                 :    28214853 :               if (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER)
     576                 :           3 :                 memset (this_op_costs[i], 0, struct_costs_size);
     577                 :    28214853 :               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                 :  1818793502 :           while (*p == '%' || *p == '=' || *p == '+' || *p == '&')
     586                 :    97739705 :             p++;
     587                 :             : 
     588                 :  1721053797 :           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                 :    92381380 :               j = p[0] - '0';
     594                 :    92381380 :               classes[i] = classes[j];
     595                 :    92381380 :               allows_mem[i] = allows_mem[j];
     596                 :    92381380 :               if (allows_mem[i])
     597                 :    43712032 :                 insn_allows_mem[i] = 1;
     598                 :             : 
     599                 :    92381380 :               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                 :    47904929 :                   if (rtx_equal_p (ops[j], op))
     604                 :  1721053797 :                     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                 :    32502653 :                   else if (classes[j] != NO_REGS)
     610                 :             :                     {
     611                 :    32355079 :                       alt_cost += copy_cost (op, mode, classes[j], 1, NULL);
     612                 :    32355079 :                       win = 1;
     613                 :             :                     }
     614                 :             :                 }
     615                 :    44476451 :               else if (! REG_P (ops[j])
     616                 :    44476451 :                        || 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                 :      165946 :                   if (classes[j] == NO_REGS)
     625                 :             :                     {
     626                 :  1721053797 :                       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                 :      157271 :                       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                 :    44310505 :                   struct costs *pp = this_op_costs[i];
     643                 :    44310505 :                   int *pp_costs = pp->cost;
     644                 :    44310505 :                   cost_classes_t cost_classes_ptr
     645                 :    44310505 :                     = regno_cost_classes[REGNO (op)];
     646                 :    44310505 :                   enum reg_class *cost_classes = cost_classes_ptr->classes;
     647                 :    44310505 :                   bool in_p = recog_data.operand_type[i] != OP_OUT;
     648                 :    44310505 :                   bool out_p = recog_data.operand_type[i] != OP_IN;
     649                 :    44310505 :                   enum reg_class op_class = classes[i];
     650                 :             : 
     651                 :    44310505 :                   ira_init_register_move_cost_if_necessary (mode);
     652                 :    44310505 :                   if (! in_p)
     653                 :             :                     {
     654                 :       70649 :                       ira_assert (out_p);
     655                 :       70649 :                       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                 :       70649 :                           move_out_cost = ira_may_move_out_cost[mode];
     667                 :      980098 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     668                 :             :                             {
     669                 :      909449 :                               rclass = cost_classes[k];
     670                 :      909449 :                               pp_costs[k]
     671                 :      909449 :                                 = move_out_cost[op_class][rclass] * frequency;
     672                 :             :                             }
     673                 :             :                         }
     674                 :             :                     }
     675                 :    44239856 :                   else if (! out_p)
     676                 :             :                     {
     677                 :    44239856 :                       ira_assert (in_p);
     678                 :    44239856 :                       if (op_class == NO_REGS)
     679                 :             :                         {
     680                 :      284018 :                           mem_cost = ira_memory_move_cost[mode];
     681                 :     4069335 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     682                 :             :                             {
     683                 :     3785317 :                               rclass = cost_classes[k];
     684                 :     3785317 :                               pp_costs[k] = mem_cost[rclass][1] * frequency;
     685                 :             :                             }
     686                 :             :                         }
     687                 :             :                       else
     688                 :             :                         {
     689                 :    43955838 :                           move_in_cost = ira_may_move_in_cost[mode];
     690                 :   665186349 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     691                 :             :                             {
     692                 :   621230511 :                               rclass = cost_classes[k];
     693                 :   621230511 :                               pp_costs[k]
     694                 :   621230511 :                                 = 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                 :             :                   /* If the alternative actually allows memory, make
     726                 :             :                      things a bit cheaper since we won't need an extra
     727                 :             :                      insn to load it.  */
     728                 :    44310505 :                   pp->mem_cost
     729                 :    44310505 :                     = ((out_p ? ira_memory_move_cost[mode][op_class][0] : 0)
     730                 :    44310505 :                        + (in_p ? ira_memory_move_cost[mode][op_class][1] : 0)
     731                 :    44310505 :                        - allows_mem[i]) * frequency;
     732                 :             : 
     733                 :             :                   /* If we have assigned a class to this allocno in
     734                 :             :                      our first pass, add a cost to this alternative
     735                 :             :                      corresponding to what we would add if this
     736                 :             :                      allocno were not in the appropriate class.  */
     737                 :    44310505 :                   if (pref)
     738                 :             :                     {
     739                 :    16747306 :                       enum reg_class pref_class = pref[COST_INDEX (REGNO (op))];
     740                 :             : 
     741                 :    16747306 :                       if (pref_class == NO_REGS)
     742                 :      579306 :                         alt_cost
     743                 :      579306 :                           += ((out_p
     744                 :             :                                ? ira_memory_move_cost[mode][op_class][0] : 0)
     745                 :             :                               + (in_p
     746                 :             :                                  ? ira_memory_move_cost[mode][op_class][1]
     747                 :             :                                  : 0));
     748                 :    16168000 :                       else if (ira_reg_class_intersect
     749                 :    16168000 :                                [pref_class][op_class] == NO_REGS)
     750                 :      278565 :                         alt_cost
     751                 :      278565 :                           += ira_register_move_cost[mode][pref_class][op_class];
     752                 :             :                     }
     753                 :    44310505 :                   if (REGNO (ops[i]) != REGNO (ops[j])
     754                 :    44310505 :                       && ! find_reg_note (insn, REG_DEAD, op))
     755                 :    12262720 :                     alt_cost += 2;
     756                 :             : 
     757                 :    44310505 :                   p++;
     758                 :             :                 }
     759                 :             :             }
     760                 :             : 
     761                 :             :           /* Scan all the constraint letters.  See if the operand
     762                 :             :              matches any of the constraints.  Collect the valid
     763                 :             :              register classes and see if this operand accepts
     764                 :             :              memory.  */
     765                 :  4152675465 :           while ((c = *p))
     766                 :             :             {
     767                 :  4090211555 :               switch (c)
     768                 :             :                 {
     769                 :   304295962 :                 case '*':
     770                 :             :                   /* Ignore the next letter for this pass.  */
     771                 :   304295962 :                   c = *++p;
     772                 :   304295962 :                   break;
     773                 :             : 
     774                 :           0 :                 case '^':
     775                 :           0 :                   alt_cost += 2;
     776                 :           0 :                   break;
     777                 :             : 
     778                 :   481154106 :                 case '?':
     779                 :   481154106 :                   alt_cost += 2;
     780                 :   481154106 :                   break;
     781                 :             : 
     782                 :    12013634 :                 case 'g':
     783                 :    12013634 :                   if (MEM_P (op)
     784                 :    12013634 :                       || (CONSTANT_P (op)
     785                 :     4688573 :                           && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))))
     786                 :             :                     win = 1;
     787                 :    12013634 :                   insn_allows_mem[i] = allows_mem[i] = 1;
     788                 :    12013634 :                   classes[i] = ira_reg_class_subunion[classes[i]][GENERAL_REGS];
     789                 :    12013634 :                   break;
     790                 :             : 
     791                 :  3292747853 :                 default:
     792                 :  3292747853 :                   enum constraint_num cn = lookup_constraint (p);
     793                 :  3292747853 :                   enum reg_class cl;
     794                 :  3292747853 :                   switch (get_constraint_type (cn))
     795                 :             :                     {
     796                 :  2677876196 :                     case CT_REGISTER:
     797                 :  2677876196 :                       cl = reg_class_for_constraint (cn);
     798                 :   956057560 :                       if (cl != NO_REGS)
     799                 :   945477605 :                         classes[i] = ira_reg_class_subunion[classes[i]][cl];
     800                 :             :                       break;
     801                 :             : 
     802                 :     4637764 :                     case CT_CONST_INT:
     803                 :     4637764 :                       if (CONST_INT_P (op)
     804                 :     4637764 :                           && insn_const_int_ok_for_constraint (INTVAL (op), cn))
     805                 :             :                         win = 1;
     806                 :             :                       break;
     807                 :             : 
     808                 :   263610804 :                     case CT_MEMORY:
     809                 :   263610804 :                     case CT_RELAXED_MEMORY:
     810                 :             :                       /* Every MEM can be reloaded to fit.  */
     811                 :   263610804 :                       insn_allows_mem[i] = allows_mem[i] = 1;
     812                 :   263610804 :                       if (MEM_P (op))
     813                 :    75194537 :                         win = 1;
     814                 :             :                       break;
     815                 :             : 
     816                 :    37602380 :                     case CT_SPECIAL_MEMORY:
     817                 :    37602380 :                       insn_allows_mem[i] = allows_mem[i] = 1;
     818                 :    37602380 :                       if (MEM_P (extract_mem_from_operand (op))
     819                 :    37602380 :                           && constraint_satisfied_p (op, cn))
     820                 :             :                         win = 1;
     821                 :             :                       break;
     822                 :             : 
     823                 :     1085814 :                     case CT_ADDRESS:
     824                 :             :                       /* Every address can be reloaded to fit.  */
     825                 :     1085814 :                       allows_addr = 1;
     826                 :     1085814 :                       if (address_operand (op, GET_MODE (op))
     827                 :     1085814 :                           || constraint_satisfied_p (op, cn))
     828                 :             :                         win = 1;
     829                 :             :                       /* We know this operand is an address, so we
     830                 :             :                          want it to be allocated to a hard register
     831                 :             :                          that can be the base of an address,
     832                 :             :                          i.e. BASE_REG_CLASS.  */
     833                 :     1085814 :                       classes[i]
     834                 :     2171628 :                         = ira_reg_class_subunion[classes[i]]
     835                 :     1085814 :                           [base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
     836                 :     1085814 :                                            ADDRESS, SCRATCH)];
     837                 :     1085814 :                       break;
     838                 :             : 
     839                 :   307934895 :                     case CT_FIXED_FORM:
     840                 :   307934895 :                       if (constraint_satisfied_p (op, cn))
     841                 :  4090211555 :                         win = 1;
     842                 :             :                       break;
     843                 :             :                     }
     844                 :             :                   break;
     845                 :             :                 }
     846                 :  4090211555 :               p += CONSTRAINT_LEN (c, p);
     847                 :  4090211555 :               if (c == ',')
     848                 :             :                 break;
     849                 :             :             }
     850                 :             : 
     851                 :  1721053797 :           constraints[i] = p;
     852                 :             : 
     853                 :  1721053797 :           if (alt_fail)
     854                 :             :             break;
     855                 :             : 
     856                 :             :           /* How we account for this operand now depends on whether it
     857                 :             :              is a pseudo register or not.  If it is, we first check if
     858                 :             :              any register classes are valid.  If not, we ignore this
     859                 :             :              alternative, since we want to assume that all allocnos get
     860                 :             :              allocated for register preferencing.  If some register
     861                 :             :              class is valid, compute the costs of moving the allocno
     862                 :             :              into that class.  */
     863                 :  1721045122 :           if (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER)
     864                 :             :             {
     865                 :   776436293 :               if (classes[i] == NO_REGS && ! allows_mem[i])
     866                 :             :                 {
     867                 :             :                   /* We must always fail if the operand is a REG, but
     868                 :             :                      we did not find a suitable class and memory is
     869                 :             :                      not allowed.
     870                 :             : 
     871                 :             :                      Otherwise we may perform an uninitialized read
     872                 :             :                      from this_op_costs after the `continue' statement
     873                 :             :                      below.  */
     874                 :             :                   alt_fail = 1;
     875                 :             :                 }
     876                 :             :               else
     877                 :             :                 {
     878                 :   583212756 :                   unsigned int regno = REGNO (op);
     879                 :   583212756 :                   struct costs *pp = this_op_costs[i];
     880                 :   583212756 :                   int *pp_costs = pp->cost;
     881                 :   583212756 :                   cost_classes_t cost_classes_ptr = regno_cost_classes[regno];
     882                 :   583212756 :                   enum reg_class *cost_classes = cost_classes_ptr->classes;
     883                 :   583212756 :                   bool in_p = recog_data.operand_type[i] != OP_OUT;
     884                 :   583212756 :                   bool out_p = recog_data.operand_type[i] != OP_IN;
     885                 :   583212756 :                   enum reg_class op_class = classes[i];
     886                 :             : 
     887                 :   583212756 :                   ira_init_register_move_cost_if_necessary (mode);
     888                 :   583212756 :                   if (! in_p)
     889                 :             :                     {
     890                 :   376396501 :                       ira_assert (out_p);
     891                 :   376396501 :                       if (op_class == NO_REGS)
     892                 :             :                         {
     893                 :    69702012 :                           mem_cost = ira_memory_move_cost[mode];
     894                 :  1088133417 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     895                 :             :                             {
     896                 :  1018431405 :                               rclass = cost_classes[k];
     897                 :  1018431405 :                               pp_costs[k] = mem_cost[rclass][0] * frequency;
     898                 :             :                             }
     899                 :             :                         }
     900                 :             :                       else
     901                 :             :                         {
     902                 :   306694489 :                           move_out_cost = ira_may_move_out_cost[mode];
     903                 :  4679439898 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     904                 :             :                             {
     905                 :  4372745409 :                               rclass = cost_classes[k];
     906                 :  4372745409 :                               pp_costs[k]
     907                 :  4372745409 :                                 = move_out_cost[op_class][rclass] * frequency;
     908                 :             :                             }
     909                 :             :                         }
     910                 :             :                     }
     911                 :   206816255 :                   else if (! out_p)
     912                 :             :                     {
     913                 :   206801390 :                       ira_assert (in_p);
     914                 :   206801390 :                       if (op_class == NO_REGS)
     915                 :             :                         {
     916                 :    15450029 :                           mem_cost = ira_memory_move_cost[mode];
     917                 :   228132066 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     918                 :             :                             {
     919                 :   212682037 :                               rclass = cost_classes[k];
     920                 :   212682037 :                               pp_costs[k] = mem_cost[rclass][1] * frequency;
     921                 :             :                             }
     922                 :             :                         }
     923                 :             :                       else
     924                 :             :                         {
     925                 :   191351361 :                           move_in_cost = ira_may_move_in_cost[mode];
     926                 :  2829871188 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     927                 :             :                             {
     928                 :  2638519827 :                               rclass = cost_classes[k];
     929                 :  2638519827 :                               pp_costs[k]
     930                 :  2638519827 :                                 = move_in_cost[rclass][op_class] * frequency;
     931                 :             :                             }
     932                 :             :                         }
     933                 :             :                     }
     934                 :             :                   else
     935                 :             :                     {
     936                 :       14865 :                       if (op_class == NO_REGS)
     937                 :             :                         {
     938                 :           0 :                           mem_cost = ira_memory_move_cost[mode];
     939                 :           0 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     940                 :             :                             {
     941                 :           0 :                               rclass = cost_classes[k];
     942                 :           0 :                               pp_costs[k] = ((mem_cost[rclass][0]
     943                 :           0 :                                               + mem_cost[rclass][1])
     944                 :           0 :                                              * frequency);
     945                 :             :                             }
     946                 :             :                         }
     947                 :             :                       else
     948                 :             :                         {
     949                 :       14865 :                           move_in_cost = ira_may_move_in_cost[mode];
     950                 :       14865 :                           move_out_cost = ira_may_move_out_cost[mode];
     951                 :      173037 :                           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
     952                 :             :                             {
     953                 :      158172 :                               rclass = cost_classes[k];
     954                 :      158172 :                               pp_costs[k] = ((move_in_cost[rclass][op_class]
     955                 :      158172 :                                               + move_out_cost[op_class][rclass])
     956                 :      158172 :                                              * frequency);
     957                 :             :                             }
     958                 :             :                         }
     959                 :             :                     }
     960                 :             : 
     961                 :   583212756 :                   if (op_class == NO_REGS)
     962                 :             :                     /* Although we don't need insn to reload from
     963                 :             :                        memory, still accessing memory is usually more
     964                 :             :                        expensive than a register.  */
     965                 :    85152041 :                     pp->mem_cost = frequency;
     966                 :             :                   else
     967                 :             :                     /* If the alternative actually allows memory, make
     968                 :             :                        things a bit cheaper since we won't need an
     969                 :             :                        extra insn to load it.  */
     970                 :   498060715 :                     pp->mem_cost
     971                 :   498060715 :                       = ((out_p ? ira_memory_move_cost[mode][op_class][0] : 0)
     972                 :   498060715 :                          + (in_p ? ira_memory_move_cost[mode][op_class][1] : 0)
     973                 :   498060715 :                          - allows_mem[i]) * frequency;
     974                 :             :                   /* If we have assigned a class to this allocno in
     975                 :             :                      our first pass, add a cost to this alternative
     976                 :             :                      corresponding to what we would add if this
     977                 :             :                      allocno were not in the appropriate class.  */
     978                 :   583212756 :                   if (pref)
     979                 :             :                     {
     980                 :   211265372 :                       enum reg_class pref_class = pref[COST_INDEX (REGNO (op))];
     981                 :             : 
     982                 :   211265372 :                       if (pref_class == NO_REGS)
     983                 :             :                         {
     984                 :     4115555 :                           if (op_class != NO_REGS)
     985                 :     3310457 :                             alt_cost
     986                 :     3310457 :                               += ((out_p
     987                 :     3310457 :                                    ? ira_memory_move_cost[mode][op_class][0]
     988                 :             :                                    : 0)
     989                 :     3310457 :                                   + (in_p
     990                 :     3310457 :                                      ? ira_memory_move_cost[mode][op_class][1]
     991                 :             :                                      : 0));
     992                 :             :                         }
     993                 :   207149817 :                       else if (op_class == NO_REGS)
     994                 :    28795987 :                         alt_cost
     995                 :    28795987 :                           += ((out_p
     996                 :    28795987 :                                ? ira_memory_move_cost[mode][pref_class][1]
     997                 :             :                                : 0)
     998                 :    28795987 :                               + (in_p
     999                 :    28795987 :                                  ? ira_memory_move_cost[mode][pref_class][0]
    1000                 :             :                                  : 0));
    1001                 :   178353830 :                       else if (ira_reg_class_intersect[pref_class][op_class]
    1002                 :             :                                == NO_REGS)
    1003                 :    38029272 :                         alt_cost += (ira_register_move_cost
    1004                 :    38029272 :                                      [mode][pref_class][op_class]);
    1005                 :             :                     }
    1006                 :             :                 }
    1007                 :             :             }
    1008                 :             : 
    1009                 :             :           /* Otherwise, if this alternative wins, either because we
    1010                 :             :              have already determined that or if we have a hard
    1011                 :             :              register of the proper class, there is no cost for this
    1012                 :             :              alternative.  */
    1013                 :   944608829 :           else if (win || (REG_P (op)
    1014                 :   227777320 :                            && reg_fits_class_p (op, classes[i],
    1015                 :   227777320 :                                                 0, GET_MODE (op))))
    1016                 :             :             ;
    1017                 :             : 
    1018                 :             :           /* If registers are valid, the cost of this alternative
    1019                 :             :              includes copying the object to and/or from a
    1020                 :             :              register.  */
    1021                 :   615444377 :           else if (classes[i] != NO_REGS)
    1022                 :             :             {
    1023                 :   326181271 :               if (recog_data.operand_type[i] != OP_OUT)
    1024                 :   177905834 :                 alt_cost += copy_cost (op, mode, classes[i], 1, NULL);
    1025                 :             : 
    1026                 :   326181271 :               if (recog_data.operand_type[i] != OP_IN)
    1027                 :   148275449 :                 alt_cost += copy_cost (op, mode, classes[i], 0, NULL);
    1028                 :             :             }
    1029                 :             :           /* The only other way this alternative can be used is if
    1030                 :             :              this is a constant that could be placed into memory.  */
    1031                 :   289263106 :           else if (CONSTANT_P (op) && (allows_addr || allows_mem[i]))
    1032                 :    20153716 :             alt_cost += ira_memory_move_cost[mode][classes[i]][1];
    1033                 :             :           else
    1034                 :             :             alt_fail = 1;
    1035                 :             : 
    1036                 :             :           if (alt_fail)
    1037                 :             :             break;
    1038                 :             :         }
    1039                 :             : 
    1040                 :   935370515 :       if (alt_fail)
    1041                 :             :         {
    1042                 :             :           /* The loop above might have exited early once the failure
    1043                 :             :              was seen.  Skip over the constraints for the remaining
    1044                 :             :              operands.  */
    1045                 :   462341602 :           i += 1;
    1046                 :   742271802 :           for (; i < n_ops; ++i)
    1047                 :   559860400 :             constraints[i] = skip_alternative (constraints[i]);
    1048                 :   462341602 :           continue;
    1049                 :             :         }
    1050                 :             : 
    1051                 :   473028913 :       op_cost_add = alt_cost * frequency;
    1052                 :             :       /* Finally, update the costs with the information we've
    1053                 :             :          calculated about this alternative.  */
    1054                 :  1531264214 :       for (i = 0; i < n_ops; i++)
    1055                 :  1058235301 :         if (REG_P (ops[i]) && REGNO (ops[i]) >= FIRST_PSEUDO_REGISTER)
    1056                 :             :           {
    1057                 :   445015873 :             int old_cost;
    1058                 :   445015873 :             bool cost_change_p = false;
    1059                 :   445015873 :             struct costs *pp = op_costs[i], *qq = this_op_costs[i];
    1060                 :   445015873 :             int *pp_costs = pp->cost, *qq_costs = qq->cost;
    1061                 :   445015873 :             int scale = 1 + (recog_data.operand_type[i] == OP_INOUT);
    1062                 :   445015873 :             cost_classes_t cost_classes_ptr
    1063                 :   445015873 :               = regno_cost_classes[REGNO (ops[i])];
    1064                 :             : 
    1065                 :   445015873 :             old_cost = pp->mem_cost;
    1066                 :   445015873 :             pp->mem_cost = MIN (old_cost,
    1067                 :             :                                 (qq->mem_cost + op_cost_add) * scale);
    1068                 :             : 
    1069                 :   445015873 :             if (ira_dump_file != NULL && internal_flag_ira_verbose > 5
    1070                 :           0 :                 && pp->mem_cost < old_cost)
    1071                 :             :               {
    1072                 :           0 :                 cost_change_p = true;
    1073                 :           0 :                 fprintf (ira_dump_file, "        op %d(r=%u) new costs MEM:%d",
    1074                 :             :                          i, REGNO(ops[i]), pp->mem_cost);
    1075                 :             :               }
    1076                 :  6695961380 :             for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    1077                 :             :               {
    1078                 :  6250945507 :                 old_cost = pp_costs[k];
    1079                 :  6250945507 :                 pp_costs[k]
    1080                 :  6250945507 :                   = MIN (old_cost, (qq_costs[k] + op_cost_add) * scale);
    1081                 :  6250945507 :                 if (ira_dump_file != NULL && internal_flag_ira_verbose > 5
    1082                 :           0 :                     && pp_costs[k] < old_cost)
    1083                 :             :                   {
    1084                 :           0 :                     if (!cost_change_p)
    1085                 :           0 :                       fprintf (ira_dump_file, "        op %d(r=%u) new costs",
    1086                 :             :                                i, REGNO(ops[i]));
    1087                 :           0 :                     cost_change_p = true;
    1088                 :           0 :                     fprintf (ira_dump_file, " %s:%d",
    1089                 :           0 :                              reg_class_names[cost_classes_ptr->classes[k]],
    1090                 :             :                              pp_costs[k]);
    1091                 :             :                   }
    1092                 :             :               }
    1093                 :   445015873 :             if (ira_dump_file != NULL && internal_flag_ira_verbose > 5
    1094                 :           0 :                 && cost_change_p)
    1095                 :           0 :               fprintf (ira_dump_file, "\n");
    1096                 :             :           }
    1097                 :             :     }
    1098                 :             : 
    1099                 :   132577472 :   if (allocno_p)
    1100                 :   425545181 :     for (i = 0; i < n_ops; i++)
    1101                 :             :       {
    1102                 :   296493922 :         ira_allocno_t a;
    1103                 :   296493922 :         rtx op = ops[i];
    1104                 :             : 
    1105                 :   296493922 :         if (! REG_P (op) || REGNO (op) < FIRST_PSEUDO_REGISTER)
    1106                 :   172824071 :           continue;
    1107                 :   123669851 :         a = ira_curr_regno_allocno_map [REGNO (op)];
    1108                 :   123669851 :         if (! ALLOCNO_BAD_SPILL_P (a) && insn_allows_mem[i] == 0)
    1109                 :    11737320 :           ALLOCNO_BAD_SPILL_P (a) = true;
    1110                 :             :       }
    1111                 :             : 
    1112                 :   132577472 : }
    1113                 :             : 
    1114                 :             : 
    1115                 :             : 
    1116                 :             : /* Wrapper around REGNO_OK_FOR_INDEX_P, to allow pseudo registers.  */
    1117                 :             : static inline bool
    1118                 :       87831 : ok_for_index_p_nonstrict (rtx reg)
    1119                 :             : {
    1120                 :       87831 :   unsigned regno = REGNO (reg);
    1121                 :             : 
    1122                 :       87831 :   return regno >= FIRST_PSEUDO_REGISTER || REGNO_OK_FOR_INDEX_P (regno);
    1123                 :             : }
    1124                 :             : 
    1125                 :             : /* A version of regno_ok_for_base_p for use here, when all
    1126                 :             :    pseudo-registers should count as OK.  Arguments as for
    1127                 :             :    regno_ok_for_base_p.  */
    1128                 :             : static inline bool
    1129                 :       88559 : ok_for_base_p_nonstrict (rtx reg, machine_mode mode, addr_space_t as,
    1130                 :             :                          enum rtx_code outer_code, enum rtx_code index_code)
    1131                 :             : {
    1132                 :       88559 :   unsigned regno = REGNO (reg);
    1133                 :             : 
    1134                 :         364 :   if (regno >= FIRST_PSEUDO_REGISTER)
    1135                 :             :     return true;
    1136                 :         364 :   return ok_for_base_p_1 (regno, mode, as, outer_code, index_code);
    1137                 :             : }
    1138                 :             : 
    1139                 :             : /* Record the pseudo registers we must reload into hard registers in a
    1140                 :             :    subexpression of a memory address, X.
    1141                 :             : 
    1142                 :             :    If CONTEXT is 0, we are looking at the base part of an address,
    1143                 :             :    otherwise we are looking at the index part.
    1144                 :             : 
    1145                 :             :    MODE and AS are the mode and address space of the memory reference;
    1146                 :             :    OUTER_CODE and INDEX_CODE give the context that the rtx appears in.
    1147                 :             :    These four arguments are passed down to base_reg_class.
    1148                 :             : 
    1149                 :             :    SCALE is twice the amount to multiply the cost by (it is twice so
    1150                 :             :    we can represent half-cost adjustments).  */
    1151                 :             : static void
    1152                 :    88087217 : record_address_regs (machine_mode mode, addr_space_t as, rtx x,
    1153                 :             :                      int context, enum rtx_code outer_code,
    1154                 :             :                      enum rtx_code index_code, int scale)
    1155                 :             : {
    1156                 :    88087217 :   enum rtx_code code = GET_CODE (x);
    1157                 :    88087217 :   enum reg_class rclass;
    1158                 :             : 
    1159                 :    88087217 :   if (context == 1)
    1160                 :             :     rclass = INDEX_REG_CLASS;
    1161                 :             :   else
    1162                 :    81541086 :     rclass = base_reg_class (mode, as, outer_code, index_code);
    1163                 :             : 
    1164                 :    88087217 :   switch (code)
    1165                 :             :     {
    1166                 :             :     case CONST_INT:
    1167                 :             :     case CONST:
    1168                 :             :     case PC:
    1169                 :             :     case SYMBOL_REF:
    1170                 :             :     case LABEL_REF:
    1171                 :             :       return;
    1172                 :             : 
    1173                 :    30770919 :     case PLUS:
    1174                 :             :       /* When we have an address that is a sum, we must determine
    1175                 :             :          whether registers are "base" or "index" regs.  If there is a
    1176                 :             :          sum of two registers, we must choose one to be the "base".
    1177                 :             :          Luckily, we can use the REG_POINTER to make a good choice
    1178                 :             :          most of the time.  We only need to do this on machines that
    1179                 :             :          can have two registers in an address and where the base and
    1180                 :             :          index register classes are different.
    1181                 :             : 
    1182                 :             :          ??? This code used to set REGNO_POINTER_FLAG in some cases,
    1183                 :             :          but that seems bogus since it should only be set when we are
    1184                 :             :          sure the register is being used as a pointer.  */
    1185                 :    30770919 :       {
    1186                 :    30770919 :         rtx arg0 = XEXP (x, 0);
    1187                 :    30770919 :         rtx arg1 = XEXP (x, 1);
    1188                 :    30770919 :         enum rtx_code code0 = GET_CODE (arg0);
    1189                 :    30770919 :         enum rtx_code code1 = GET_CODE (arg1);
    1190                 :             : 
    1191                 :             :         /* Look inside subregs.  */
    1192                 :    30770919 :         if (code0 == SUBREG)
    1193                 :        9925 :           arg0 = SUBREG_REG (arg0), code0 = GET_CODE (arg0);
    1194                 :    30770919 :         if (code1 == SUBREG)
    1195                 :        4071 :           arg1 = SUBREG_REG (arg1), code1 = GET_CODE (arg1);
    1196                 :             : 
    1197                 :             :         /* If index registers do not appear, or coincide with base registers,
    1198                 :             :            just record registers in any non-constant operands.  We
    1199                 :             :            assume here, as well as in the tests below, that all
    1200                 :             :            addresses are in canonical form.  */
    1201                 :    61541838 :         if (MAX_REGS_PER_ADDRESS == 1
    1202                 :    30770919 :             || INDEX_REG_CLASS == base_reg_class (VOIDmode, as, PLUS, SCRATCH))
    1203                 :             :           {
    1204                 :           0 :             record_address_regs (mode, as, arg0, context, PLUS, code1, scale);
    1205                 :           0 :             if (! CONSTANT_P (arg1))
    1206                 :           0 :               record_address_regs (mode, as, arg1, context, PLUS, code0, scale);
    1207                 :             :           }
    1208                 :             : 
    1209                 :             :         /* If the second operand is a constant integer, it doesn't
    1210                 :             :            change what class the first operand must be.  */
    1211                 :    30770919 :         else if (CONST_SCALAR_INT_P (arg1))
    1212                 :    27706259 :           record_address_regs (mode, as, arg0, context, PLUS, code1, scale);
    1213                 :             :         /* If the second operand is a symbolic constant, the first
    1214                 :             :            operand must be an index register.  */
    1215                 :     3064660 :         else if (code1 == SYMBOL_REF || code1 == CONST || code1 == LABEL_REF)
    1216                 :      871228 :           record_address_regs (mode, as, arg0, 1, PLUS, code1, scale);
    1217                 :             :         /* If both operands are registers but one is already a hard
    1218                 :             :            register of index or reg-base class, give the other the
    1219                 :             :            class that the hard register is not.  */
    1220                 :     2193432 :         else if (code0 == REG && code1 == REG
    1221                 :     1071619 :                  && REGNO (arg0) < FIRST_PSEUDO_REGISTER
    1222                 :     2280829 :                  && (ok_for_base_p_nonstrict (arg0, mode, as, PLUS, REG)
    1223                 :       87043 :                      || ok_for_index_p_nonstrict (arg0)))
    1224                 :        1062 :           record_address_regs (mode, as, arg1,
    1225                 :        1062 :                                ok_for_base_p_nonstrict (arg0, mode, as,
    1226                 :             :                                                         PLUS, REG) ? 1 : 0,
    1227                 :             :                                PLUS, REG, scale);
    1228                 :     2193078 :         else if (code0 == REG && code1 == REG
    1229                 :     1071265 :                  && REGNO (arg1) < FIRST_PSEUDO_REGISTER
    1230                 :     2193876 :                  && (ok_for_base_p_nonstrict (arg1, mode, as, PLUS, REG)
    1231                 :         788 :                      || ok_for_index_p_nonstrict (arg1)))
    1232                 :          30 :           record_address_regs (mode, as, arg0,
    1233                 :          30 :                                ok_for_base_p_nonstrict (arg1, mode, as,
    1234                 :             :                                                         PLUS, REG) ? 1 : 0,
    1235                 :             :                                PLUS, REG, scale);
    1236                 :             :         /* If one operand is known to be a pointer, it must be the
    1237                 :             :            base with the other operand the index.  Likewise if the
    1238                 :             :            other operand is a MULT.  */
    1239                 :     2193068 :         else if ((code0 == REG && REG_POINTER (arg0)) || code1 == MULT)
    1240                 :             :           {
    1241                 :      901213 :             record_address_regs (mode, as, arg0, 0, PLUS, code1, scale);
    1242                 :      901213 :             record_address_regs (mode, as, arg1, 1, PLUS, code0, scale);
    1243                 :             :           }
    1244                 :     1291855 :         else if ((code1 == REG && REG_POINTER (arg1)) || code0 == MULT)
    1245                 :             :           {
    1246                 :      972683 :             record_address_regs (mode, as, arg0, 1, PLUS, code1, scale);
    1247                 :      972683 :             record_address_regs (mode, as, arg1, 0, PLUS, code0, scale);
    1248                 :             :           }
    1249                 :             :         /* Otherwise, count equal chances that each might be a base or
    1250                 :             :            index register.  This case should be rare.  */
    1251                 :             :         else
    1252                 :             :           {
    1253                 :      319172 :             record_address_regs (mode, as, arg0, 0, PLUS, code1, scale / 2);
    1254                 :      319172 :             record_address_regs (mode, as, arg0, 1, PLUS, code1, scale / 2);
    1255                 :      319172 :             record_address_regs (mode, as, arg1, 0, PLUS, code0, scale / 2);
    1256                 :      319172 :             record_address_regs (mode, as, arg1, 1, PLUS, code0, scale / 2);
    1257                 :             :           }
    1258                 :             :       }
    1259                 :             :       break;
    1260                 :             : 
    1261                 :             :       /* Double the importance of an allocno that is incremented or
    1262                 :             :          decremented, since it would take two extra insns if it ends
    1263                 :             :          up in the wrong place.  */
    1264                 :      190056 :     case POST_MODIFY:
    1265                 :      190056 :     case PRE_MODIFY:
    1266                 :      190056 :       record_address_regs (mode, as, XEXP (x, 0), 0, code,
    1267                 :      190056 :                            GET_CODE (XEXP (XEXP (x, 1), 1)), 2 * scale);
    1268                 :      190056 :       if (REG_P (XEXP (XEXP (x, 1), 1)))
    1269                 :           0 :         record_address_regs (mode, as, XEXP (XEXP (x, 1), 1), 1, code, REG,
    1270                 :             :                              2 * scale);
    1271                 :             :       break;
    1272                 :             : 
    1273                 :     3290167 :     case POST_INC:
    1274                 :     3290167 :     case PRE_INC:
    1275                 :     3290167 :     case POST_DEC:
    1276                 :     3290167 :     case PRE_DEC:
    1277                 :             :       /* Double the importance of an allocno that is incremented or
    1278                 :             :          decremented, since it would take two extra insns if it ends
    1279                 :             :          up in the wrong place.  */
    1280                 :     3290167 :       record_address_regs (mode, as, XEXP (x, 0), 0, code, SCRATCH, 2 * scale);
    1281                 :     3290167 :       break;
    1282                 :             : 
    1283                 :    42044513 :     case REG:
    1284                 :    42044513 :       {
    1285                 :    42044513 :         struct costs *pp;
    1286                 :    42044513 :         int *pp_costs;
    1287                 :    42044513 :         enum reg_class i;
    1288                 :    42044513 :         int k, regno, add_cost;
    1289                 :    42044513 :         cost_classes_t cost_classes_ptr;
    1290                 :    42044513 :         enum reg_class *cost_classes;
    1291                 :    42044513 :         move_table *move_in_cost;
    1292                 :             : 
    1293                 :    42044513 :         if (REGNO (x) < FIRST_PSEUDO_REGISTER)
    1294                 :             :           break;
    1295                 :             : 
    1296                 :    18310952 :         regno = REGNO (x);
    1297                 :    18310952 :         if (allocno_p)
    1298                 :    18026215 :           ALLOCNO_BAD_SPILL_P (ira_curr_regno_allocno_map[regno]) = true;
    1299                 :    18310952 :         pp = COSTS (costs, COST_INDEX (regno));
    1300                 :    18310952 :         add_cost = (ira_memory_move_cost[Pmode][rclass][1] * scale) / 2;
    1301                 :    18310952 :         if (INT_MAX - add_cost < pp->mem_cost)
    1302                 :           0 :           pp->mem_cost = INT_MAX;
    1303                 :             :         else
    1304                 :    18310952 :           pp->mem_cost += add_cost;
    1305                 :    18310952 :         cost_classes_ptr = regno_cost_classes[regno];
    1306                 :    18310952 :         cost_classes = cost_classes_ptr->classes;
    1307                 :    18310952 :         pp_costs = pp->cost;
    1308                 :    18310952 :         ira_init_register_move_cost_if_necessary (Pmode);
    1309                 :    18310952 :         move_in_cost = ira_may_move_in_cost[Pmode];
    1310                 :   298245925 :         for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    1311                 :             :           {
    1312                 :   279934973 :             i = cost_classes[k];
    1313                 :   279934973 :             add_cost = (move_in_cost[i][rclass] * scale) / 2;
    1314                 :   279934973 :             if (INT_MAX - add_cost < pp_costs[k])
    1315                 :       14447 :               pp_costs[k] = INT_MAX;
    1316                 :             :             else
    1317                 :   279920526 :               pp_costs[k] += add_cost;
    1318                 :             :           }
    1319                 :             :       }
    1320                 :             :       break;
    1321                 :             : 
    1322                 :     2081069 :     default:
    1323                 :     2081069 :       {
    1324                 :     2081069 :         const char *fmt = GET_RTX_FORMAT (code);
    1325                 :     2081069 :         int i;
    1326                 :     5756506 :         for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1327                 :     3675437 :           if (fmt[i] == 'e')
    1328                 :     3657148 :             record_address_regs (mode, as, XEXP (x, i), context, code, SCRATCH,
    1329                 :             :                                  scale);
    1330                 :             :       }
    1331                 :             :     }
    1332                 :             : }
    1333                 :             : 
    1334                 :             : 
    1335                 :             : 
    1336                 :             : /* Calculate the costs of insn operands.  */
    1337                 :             : static void
    1338                 :   133480849 : record_operand_costs (rtx_insn *insn, enum reg_class *pref)
    1339                 :             : {
    1340                 :   133480849 :   const char *constraints[MAX_RECOG_OPERANDS];
    1341                 :   133480849 :   machine_mode modes[MAX_RECOG_OPERANDS];
    1342                 :   133480849 :   rtx set;
    1343                 :   133480849 :   int i;
    1344                 :             : 
    1345                 :   133480849 :   if ((set = single_set (insn)) != NULL_RTX
    1346                 :             :       /* In rare cases the single set insn might have less 2 operands
    1347                 :             :          as the source can be a fixed special reg.  */
    1348                 :   126138179 :       && recog_data.n_operands > 1
    1349                 :   121363232 :       && recog_data.operand[0] == SET_DEST (set)
    1350                 :   233491277 :       && recog_data.operand[1] == SET_SRC (set))
    1351                 :             :     {
    1352                 :    72355449 :       int regno, other_regno;
    1353                 :    72355449 :       rtx dest = SET_DEST (set);
    1354                 :    72355449 :       rtx src = SET_SRC (set);
    1355                 :             : 
    1356                 :    72355449 :       if (GET_CODE (dest) == SUBREG
    1357                 :    74274485 :           && known_eq (GET_MODE_SIZE (GET_MODE (dest)),
    1358                 :             :                        GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))))
    1359                 :             :         dest = SUBREG_REG (dest);
    1360                 :    72355449 :       if (GET_CODE (src) == SUBREG
    1361                 :    75042237 :           && known_eq (GET_MODE_SIZE (GET_MODE (src)),
    1362                 :             :                        GET_MODE_SIZE (GET_MODE (SUBREG_REG (src)))))
    1363                 :             :         src = SUBREG_REG (src);
    1364                 :    33572803 :       if (REG_P (src) && REG_P (dest)
    1365                 :    92357511 :           && (((regno = REGNO (src)) >= FIRST_PSEUDO_REGISTER
    1366                 :    13653310 :                && (other_regno = REGNO (dest)) < FIRST_PSEUDO_REGISTER)
    1367                 :     9272987 :               || ((regno = REGNO (dest)) >= FIRST_PSEUDO_REGISTER
    1368                 :     9244202 :                   && (other_regno = REGNO (src)) < FIRST_PSEUDO_REGISTER)))
    1369                 :             :         {
    1370                 :    17049042 :           machine_mode mode = GET_MODE (SET_SRC (set)), cost_mode = mode;
    1371                 :    17049042 :           machine_mode hard_reg_mode = GET_MODE(regno_reg_rtx[other_regno]);
    1372                 :    34098084 :           poly_int64 pmode_size = GET_MODE_SIZE (mode);
    1373                 :    34098084 :           poly_int64 phard_reg_mode_size = GET_MODE_SIZE (hard_reg_mode);
    1374                 :    17049042 :           HOST_WIDE_INT mode_size, hard_reg_mode_size;
    1375                 :    17049042 :           cost_classes_t cost_classes_ptr = regno_cost_classes[regno];
    1376                 :    17049042 :           enum reg_class *cost_classes = cost_classes_ptr->classes;
    1377                 :    17049042 :           reg_class_t rclass, hard_reg_class, bigger_hard_reg_class;
    1378                 :    17049042 :           int cost_factor = 1, cost, k;
    1379                 :    17049042 :           move_table *move_costs;
    1380                 :    17049042 :           bool dead_p = find_regno_note (insn, REG_DEAD, REGNO (src));
    1381                 :             : 
    1382                 :    17049042 :           hard_reg_class = REGNO_REG_CLASS (other_regno);
    1383                 :    17049042 :           bigger_hard_reg_class = ira_pressure_class_translate[hard_reg_class];
    1384                 :             :           /* Target code may return any cost for mode which does not fit the
    1385                 :             :              hard reg class (e.g. DImode for AREG on i386).  Check this and use
    1386                 :             :              a bigger class to get the right cost.  */
    1387                 :    17049042 :           if (bigger_hard_reg_class != NO_REGS
    1388                 :    17049042 :               && ! ira_hard_reg_in_set_p (other_regno, mode,
    1389                 :             :                                           reg_class_contents[hard_reg_class]))
    1390                 :             :             hard_reg_class = bigger_hard_reg_class;
    1391                 :    17049042 :           ira_init_register_move_cost_if_necessary (mode);
    1392                 :    17049042 :           ira_init_register_move_cost_if_necessary (hard_reg_mode);
    1393                 :             :           /* Use smaller movement cost for natural hard reg mode or its mode as
    1394                 :             :              operand.  */
    1395                 :    17049042 :           if (pmode_size.is_constant (&mode_size)
    1396                 :    17049042 :               && phard_reg_mode_size.is_constant (&hard_reg_mode_size))
    1397                 :             :             {
    1398                 :             :               /* Assume we are moving in the natural modes: */
    1399                 :    17049042 :               cost_factor = mode_size / hard_reg_mode_size;
    1400                 :    17049042 :               if (mode_size % hard_reg_mode_size != 0)
    1401                 :     3785624 :                 cost_factor++;
    1402                 :    17049042 :               if (cost_factor
    1403                 :    17049042 :                   * (ira_register_move_cost
    1404                 :    17049042 :                      [hard_reg_mode][hard_reg_class][hard_reg_class])
    1405                 :             :                   < (ira_register_move_cost
    1406                 :    17049042 :                      [mode][hard_reg_class][hard_reg_class]))
    1407                 :           0 :                 cost_mode = hard_reg_mode;
    1408                 :             :               else
    1409                 :             :                 cost_factor = 1;
    1410                 :             :             }
    1411                 :    17049042 :           move_costs = ira_register_move_cost[cost_mode];
    1412                 :    17049042 :           i = regno == (int) REGNO (src) ? 1 : 0;
    1413                 :   319706444 :           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    1414                 :             :             {
    1415                 :   302657402 :               rclass = cost_classes[k];
    1416                 :   605314804 :               cost = (i == 0
    1417                 :   302657402 :                       ? move_costs[hard_reg_class][rclass]
    1418                 :   191910292 :                       : move_costs[rclass][hard_reg_class]);
    1419                 :   302657402 :               cost *= cost_factor;
    1420                 :   302657402 :               op_costs[i]->cost[k] = cost * frequency;
    1421                 :             :               /* If this insn is a single set copying operand 1 to
    1422                 :             :                  operand 0 and one operand is an allocno with the
    1423                 :             :                  other a hard reg or an allocno that prefers a hard
    1424                 :             :                  register that is in its own register class then we
    1425                 :             :                  may want to adjust the cost of that register class to
    1426                 :             :                  -1.
    1427                 :             : 
    1428                 :             :                  Avoid the adjustment if the source does not die to
    1429                 :             :                  avoid stressing of register allocator by preferencing
    1430                 :             :                  two colliding registers into single class.  */
    1431                 :   302657402 :               if (dead_p
    1432                 :   245762093 :                   && TEST_HARD_REG_BIT (reg_class_contents[rclass], other_regno)
    1433                 :   302657402 :                   && (reg_class_size[(int) rclass]
    1434                 :             :                       == (ira_reg_class_max_nregs
    1435                 :   101503627 :                           [(int) rclass][(int) GET_MODE(src)])))
    1436                 :             :                 {
    1437                 :    12902199 :                   if (reg_class_size[rclass] == 1)
    1438                 :    12759280 :                     op_costs[i]->cost[k] = -frequency;
    1439                 :      142919 :                   else if (in_hard_reg_set_p (reg_class_contents[rclass],
    1440                 :             :                                               GET_MODE(src), other_regno))
    1441                 :      114856 :                     op_costs[i]->cost[k] = -frequency;
    1442                 :             :                 }
    1443                 :             :             }
    1444                 :    17049042 :           op_costs[i]->mem_cost
    1445                 :    17049042 :             = ira_memory_move_cost[mode][hard_reg_class][i] * frequency;
    1446                 :    17049042 :           return;
    1447                 :             :         }
    1448                 :             :     }
    1449                 :             : 
    1450                 :   371790292 :   for (i = 0; i < recog_data.n_operands; i++)
    1451                 :             :     {
    1452                 :   255358485 :       constraints[i] = recog_data.constraints[i];
    1453                 :   255358485 :       modes[i] = recog_data.operand_mode[i];
    1454                 :             :     }
    1455                 :             : 
    1456                 :             :   /* If we get here, we are set up to record the costs of all the
    1457                 :             :      operands for this insn.  Start by initializing the costs.  Then
    1458                 :             :      handle any address registers.  Finally record the desired classes
    1459                 :             :      for any allocnos, doing it twice if some pair of operands are
    1460                 :             :      commutative.  */
    1461                 :   371790292 :   for (i = 0; i < recog_data.n_operands; i++)
    1462                 :             :     {
    1463                 :   255358485 :       rtx op_mem = extract_mem_from_operand (recog_data.operand[i]);
    1464                 :   255358485 :       memcpy (op_costs[i], init_cost, struct_costs_size);
    1465                 :             : 
    1466                 :   255358485 :       if (GET_CODE (recog_data.operand[i]) == SUBREG)
    1467                 :     5043325 :         recog_data.operand[i] = SUBREG_REG (recog_data.operand[i]);
    1468                 :             : 
    1469                 :   255358485 :       if (MEM_P (op_mem))
    1470                 :    41948457 :         record_address_regs (GET_MODE (op_mem),
    1471                 :    41948457 :                              MEM_ADDR_SPACE (op_mem),
    1472                 :             :                              XEXP (op_mem, 0),
    1473                 :             :                              0, MEM, SCRATCH, frequency * 2);
    1474                 :   213410028 :       else if (constraints[i][0] == 'p'
    1475                 :   426816080 :                || (insn_extra_address_constraint
    1476                 :   213406052 :                    (lookup_constraint (constraints[i]))))
    1477                 :     1085803 :         record_address_regs (VOIDmode, ADDR_SPACE_GENERIC,
    1478                 :             :                              recog_data.operand[i], 0, ADDRESS, SCRATCH,
    1479                 :             :                              frequency * 2);
    1480                 :             :     }
    1481                 :             : 
    1482                 :             :   /* Check for commutative in a separate loop so everything will have
    1483                 :             :      been initialized.  We must do this even if one operand is a
    1484                 :             :      constant--see addsi3 in m68k.md.  */
    1485                 :   256258415 :   for (i = 0; i < (int) recog_data.n_operands - 1; i++)
    1486                 :   139826608 :     if (constraints[i][0] == '%')
    1487                 :             :       {
    1488                 :             :         const char *xconstraints[MAX_RECOG_OPERANDS];
    1489                 :             :         int j;
    1490                 :             : 
    1491                 :             :         /* Handle commutative operands by swapping the
    1492                 :             :            constraints.  We assume the modes are the same.  */
    1493                 :    65397091 :         for (j = 0; j < recog_data.n_operands; j++)
    1494                 :    49251426 :           xconstraints[j] = constraints[j];
    1495                 :             : 
    1496                 :    16145665 :         xconstraints[i] = constraints[i+1];
    1497                 :    16145665 :         xconstraints[i+1] = constraints[i];
    1498                 :    16145665 :         record_reg_classes (recog_data.n_alternatives, recog_data.n_operands,
    1499                 :             :                             recog_data.operand, modes,
    1500                 :             :                             xconstraints, insn, pref);
    1501                 :             :       }
    1502                 :   116431807 :   record_reg_classes (recog_data.n_alternatives, recog_data.n_operands,
    1503                 :             :                       recog_data.operand, modes,
    1504                 :             :                       constraints, insn, pref);
    1505                 :             : }
    1506                 :             : 
    1507                 :             : 
    1508                 :             : 
    1509                 :             : /* Process one insn INSN.  Scan it and record each time it would save
    1510                 :             :    code to put a certain allocnos in a certain class.  Return the last
    1511                 :             :    insn processed, so that the scan can be continued from there.  */
    1512                 :             : static rtx_insn *
    1513                 :   259844245 : scan_one_insn (rtx_insn *insn)
    1514                 :             : {
    1515                 :   259844245 :   enum rtx_code pat_code;
    1516                 :   259844245 :   rtx set, note;
    1517                 :   259844245 :   int i, k;
    1518                 :   259844245 :   bool counted_mem;
    1519                 :             : 
    1520                 :   259844245 :   if (!NONDEBUG_INSN_P (insn))
    1521                 :             :     return insn;
    1522                 :             : 
    1523                 :   134839865 :   pat_code = GET_CODE (PATTERN (insn));
    1524                 :   134839865 :   if (pat_code == ASM_INPUT)
    1525                 :             :     return insn;
    1526                 :             : 
    1527                 :             :   /* If INSN is a USE/CLOBBER of a pseudo in a mode M then go ahead
    1528                 :             :      and initialize the register move costs of mode M.
    1529                 :             : 
    1530                 :             :      The pseudo may be related to another pseudo via a copy (implicit or
    1531                 :             :      explicit) and if there are no mode M uses/sets of the original
    1532                 :             :      pseudo, then we may leave the register move costs uninitialized for
    1533                 :             :      mode M. */
    1534                 :   134836071 :   if (pat_code == USE || pat_code == CLOBBER)
    1535                 :             :     {
    1536                 :     1355222 :       rtx x = XEXP (PATTERN (insn), 0);
    1537                 :     1355222 :       if (GET_CODE (x) == REG
    1538                 :     1342043 :           && REGNO (x) >= FIRST_PSEUDO_REGISTER
    1539                 :     1387073 :           && have_regs_of_mode[GET_MODE (x)])
    1540                 :       31850 :         ira_init_register_move_cost_if_necessary (GET_MODE (x));
    1541                 :     1355222 :       return insn;
    1542                 :             :     }
    1543                 :             : 
    1544                 :   133480849 :   counted_mem = false;
    1545                 :   133480849 :   set = single_set (insn);
    1546                 :   133480849 :   extract_insn (insn);
    1547                 :             : 
    1548                 :             :   /* If this insn loads a parameter from its stack slot, then it
    1549                 :             :      represents a savings, rather than a cost, if the parameter is
    1550                 :             :      stored in memory.  Record this fact.
    1551                 :             : 
    1552                 :             :      Similarly if we're loading other constants from memory (constant
    1553                 :             :      pool, TOC references, small data areas, etc) and this is the only
    1554                 :             :      assignment to the destination pseudo.
    1555                 :             : 
    1556                 :             :      Don't do this if SET_SRC (set) isn't a general operand, if it is
    1557                 :             :      a memory requiring special instructions to load it, decreasing
    1558                 :             :      mem_cost might result in it being loaded using the specialized
    1559                 :             :      instruction into a register, then stored into stack and loaded
    1560                 :             :      again from the stack.  See PR52208.
    1561                 :             : 
    1562                 :             :      Don't do this if SET_SRC (set) has side effect.  See PR56124.  */
    1563                 :   126138179 :   if (set != 0 && REG_P (SET_DEST (set)) && MEM_P (SET_SRC (set))
    1564                 :    16737385 :       && (note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != NULL_RTX
    1565                 :     4709034 :       && ((MEM_P (XEXP (note, 0))
    1566                 :     4213194 :            && !side_effects_p (SET_SRC (set)))
    1567                 :      495840 :           || (CONSTANT_P (XEXP (note, 0))
    1568                 :      495832 :               && targetm.legitimate_constant_p (GET_MODE (SET_DEST (set)),
    1569                 :             :                                                 XEXP (note, 0))
    1570                 :      156003 :               && REG_N_SETS (REGNO (SET_DEST (set))) == 1))
    1571                 :     4369197 :       && general_operand (SET_SRC (set), GET_MODE (SET_SRC (set)))
    1572                 :             :       /* LRA does not use equiv with a symbol for PIC code.  */
    1573                 :   137850034 :       && (! ira_use_lra_p || ! pic_offset_table_rtx
    1574                 :      321396 :           || ! contains_symbol_ref_p (XEXP (note, 0))))
    1575                 :             :     {
    1576                 :     4313255 :       enum reg_class cl = GENERAL_REGS;
    1577                 :     4313255 :       rtx reg = SET_DEST (set);
    1578                 :     4313255 :       int num = COST_INDEX (REGNO (reg));
    1579                 :             :       /* Costs for NO_REGS are used in cost calculation on the
    1580                 :             :          1st pass when the preferred register classes are not
    1581                 :             :          known yet.  In this case we take the best scenario when
    1582                 :             :          mode can't be put into GENERAL_REGS.  */
    1583                 :     4313255 :       if (!targetm.hard_regno_mode_ok (ira_class_hard_regs[cl][0],
    1584                 :     4313255 :                                        GET_MODE (reg)))
    1585                 :     1088679 :         cl = NO_REGS;
    1586                 :             : 
    1587                 :     4313255 :       COSTS (costs, num)->mem_cost
    1588                 :     4313255 :         -= ira_memory_move_cost[GET_MODE (reg)][cl][1] * frequency;
    1589                 :     8626510 :       record_address_regs (GET_MODE (SET_SRC (set)),
    1590                 :     8626510 :                            MEM_ADDR_SPACE (SET_SRC (set)),
    1591                 :     4313255 :                            XEXP (SET_SRC (set), 0), 0, MEM, SCRATCH,
    1592                 :             :                            frequency * 2);
    1593                 :     4313255 :       counted_mem = true;
    1594                 :             :     }
    1595                 :             : 
    1596                 :   133480849 :   record_operand_costs (insn, pref);
    1597                 :             : 
    1598                 :   133480849 :   if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    1599                 :             :     {
    1600                 :           0 :       const char *p;
    1601                 :           0 :       fprintf (ira_dump_file, "    Final costs after insn %u", INSN_UID (insn));
    1602                 :           0 :       if (INSN_CODE (insn) >= 0
    1603                 :           0 :           && (p = get_insn_name (INSN_CODE (insn))) != NULL)
    1604                 :           0 :         fprintf (ira_dump_file, " {%s}", p);
    1605                 :           0 :       fprintf (ira_dump_file, " (freq=%d)\n",
    1606                 :           0 :                REG_FREQ_FROM_BB (BLOCK_FOR_INSN (insn)));
    1607                 :           0 :       dump_insn_slim (ira_dump_file, insn);
    1608                 :             :     }
    1609                 :             : 
    1610                 :             :   /* Now add the cost for each operand to the total costs for its
    1611                 :             :      allocno.  */
    1612                 :   422937418 :   for (i = 0; i < recog_data.n_operands; i++)
    1613                 :             :     {
    1614                 :   289456569 :       rtx op = recog_data.operand[i];
    1615                 :             : 
    1616                 :   289456569 :       if (GET_CODE (op) == SUBREG)
    1617                 :       32872 :         op = SUBREG_REG (op);
    1618                 :   289456569 :       if (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER)
    1619                 :             :         {
    1620                 :   117715114 :           int regno = REGNO (op);
    1621                 :   117715114 :           struct costs *p = COSTS (costs, COST_INDEX (regno));
    1622                 :   117715114 :           struct costs *q = op_costs[i];
    1623                 :   117715114 :           int *p_costs = p->cost, *q_costs = q->cost;
    1624                 :   117715114 :           cost_classes_t cost_classes_ptr = regno_cost_classes[regno];
    1625                 :   117715114 :           int add_cost = 0;
    1626                 :             : 
    1627                 :             :           /* If the already accounted for the memory "cost" above, don't
    1628                 :             :              do so again.  */
    1629                 :   117715114 :           if (!counted_mem)
    1630                 :             :             {
    1631                 :   113401859 :               add_cost = q->mem_cost;
    1632                 :   113401859 :               if (add_cost > 0 && INT_MAX - add_cost < p->mem_cost)
    1633                 :           0 :                 p->mem_cost = INT_MAX;
    1634                 :             :               else
    1635                 :   113401859 :                 p->mem_cost += add_cost;
    1636                 :             :             }
    1637                 :   117715114 :           if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    1638                 :             :             {
    1639                 :           0 :               fprintf (ira_dump_file, "        op %d(r=%u) MEM:%d(+%d)",
    1640                 :             :                        i, REGNO(op), p->mem_cost, add_cost);
    1641                 :             :             }
    1642                 :  1763765071 :           for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    1643                 :             :             {
    1644                 :  1646049957 :               add_cost = q_costs[k];
    1645                 :  1646049957 :               if (add_cost > 0 && INT_MAX - add_cost < p_costs[k])
    1646                 :           0 :                 p_costs[k] = INT_MAX;
    1647                 :             :               else
    1648                 :  1646049957 :                 p_costs[k] += add_cost;
    1649                 :  1646049957 :               if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    1650                 :             :                 {
    1651                 :           0 :                   fprintf (ira_dump_file, " %s:%d(+%d)",
    1652                 :           0 :                            reg_class_names[cost_classes_ptr->classes[k]],
    1653                 :           0 :                            p_costs[k], add_cost);
    1654                 :             :                 }
    1655                 :             :             }
    1656                 :   117715114 :           if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    1657                 :           0 :             fprintf (ira_dump_file, "\n");
    1658                 :             :         }
    1659                 :             :     }
    1660                 :             :   return insn;
    1661                 :             : }
    1662                 :             : 
    1663                 :             : 
    1664                 :             : 
    1665                 :             : /* Print allocnos costs to the dump file.  */
    1666                 :             : static void
    1667                 :         127 : print_allocno_costs (void)
    1668                 :             : {
    1669                 :         127 :   int k;
    1670                 :         127 :   ira_allocno_t a;
    1671                 :         127 :   ira_allocno_iterator ai;
    1672                 :             : 
    1673                 :         127 :   ira_assert (allocno_p);
    1674                 :         127 :   fprintf (ira_dump_file, "\n");
    1675                 :        1339 :   FOR_EACH_ALLOCNO (a, ai)
    1676                 :             :     {
    1677                 :        1212 :       int i, rclass;
    1678                 :        1212 :       basic_block bb;
    1679                 :        1212 :       int regno = ALLOCNO_REGNO (a);
    1680                 :        1212 :       cost_classes_t cost_classes_ptr = regno_cost_classes[regno];
    1681                 :        1212 :       enum reg_class *cost_classes = cost_classes_ptr->classes;
    1682                 :             : 
    1683                 :        1212 :       i = ALLOCNO_NUM (a);
    1684                 :        1212 :       fprintf (ira_dump_file, "  a%d(r%d,", i, regno);
    1685                 :        1212 :       if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
    1686                 :           0 :         fprintf (ira_dump_file, "b%d", bb->index);
    1687                 :             :       else
    1688                 :        1212 :         fprintf (ira_dump_file, "l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop_num);
    1689                 :        1212 :       fprintf (ira_dump_file, ") costs:");
    1690                 :       19683 :       for (k = 0; k < cost_classes_ptr->num; k++)
    1691                 :             :         {
    1692                 :       17259 :           rclass = cost_classes[k];
    1693                 :       17259 :           fprintf (ira_dump_file, " %s:%d", reg_class_names[rclass],
    1694                 :       17259 :                    COSTS (costs, i)->cost[k]);
    1695                 :       17259 :           if (flag_ira_region == IRA_REGION_ALL
    1696                 :       17259 :               || flag_ira_region == IRA_REGION_MIXED)
    1697                 :       13660 :             fprintf (ira_dump_file, ",%d",
    1698                 :       13660 :                      COSTS (total_allocno_costs, i)->cost[k]);
    1699                 :             :         }
    1700                 :        1212 :       fprintf (ira_dump_file, " MEM:%i", COSTS (costs, i)->mem_cost);
    1701                 :        1212 :       if (flag_ira_region == IRA_REGION_ALL
    1702                 :        1212 :           || flag_ira_region == IRA_REGION_MIXED)
    1703                 :        1002 :         fprintf (ira_dump_file, ",%d",
    1704                 :        1002 :                  COSTS (total_allocno_costs, i)->mem_cost);
    1705                 :        1212 :       fprintf (ira_dump_file, "\n");
    1706                 :             :     }
    1707                 :         127 : }
    1708                 :             : 
    1709                 :             : /* Print pseudo costs to the dump file.  */
    1710                 :             : static void
    1711                 :          16 : print_pseudo_costs (void)
    1712                 :             : {
    1713                 :          16 :   int regno, k;
    1714                 :          16 :   int rclass;
    1715                 :          16 :   cost_classes_t cost_classes_ptr;
    1716                 :          16 :   enum reg_class *cost_classes;
    1717                 :             : 
    1718                 :          16 :   ira_assert (! allocno_p);
    1719                 :          16 :   fprintf (ira_dump_file, "\n");
    1720                 :         760 :   for (regno = max_reg_num () - 1; regno >= FIRST_PSEUDO_REGISTER; regno--)
    1721                 :             :     {
    1722                 :         744 :       if (REG_N_REFS (regno) <= 0)
    1723                 :         440 :         continue;
    1724                 :         304 :       cost_classes_ptr = regno_cost_classes[regno];
    1725                 :         304 :       cost_classes = cost_classes_ptr->classes;
    1726                 :         304 :       fprintf (ira_dump_file, "  r%d costs:", regno);
    1727                 :        5904 :       for (k = 0; k < cost_classes_ptr->num; k++)
    1728                 :             :         {
    1729                 :        5296 :           rclass = cost_classes[k];
    1730                 :        5296 :           fprintf (ira_dump_file, " %s:%d", reg_class_names[rclass],
    1731                 :        5296 :                    COSTS (costs, regno)->cost[k]);
    1732                 :             :         }
    1733                 :         304 :       fprintf (ira_dump_file, " MEM:%i\n", COSTS (costs, regno)->mem_cost);
    1734                 :             :     }
    1735                 :          16 : }
    1736                 :             : 
    1737                 :             : /* Traverse the BB represented by LOOP_TREE_NODE to update the allocno
    1738                 :             :    costs.  */
    1739                 :             : static void
    1740                 :    23946744 : process_bb_for_costs (basic_block bb)
    1741                 :             : {
    1742                 :    23946744 :   rtx_insn *insn;
    1743                 :             : 
    1744                 :    23946744 :   frequency = REG_FREQ_FROM_BB (bb);
    1745                 :    23946744 :   if (frequency == 0)
    1746                 :           0 :     frequency = 1;
    1747                 :   283790989 :   FOR_BB_INSNS (bb, insn)
    1748                 :   259844245 :     insn = scan_one_insn (insn);
    1749                 :    23946744 : }
    1750                 :             : 
    1751                 :             : /* Traverse the BB represented by LOOP_TREE_NODE to update the allocno
    1752                 :             :    costs.  */
    1753                 :             : static void
    1754                 :    26742190 : process_bb_node_for_costs (ira_loop_tree_node_t loop_tree_node)
    1755                 :             : {
    1756                 :    26742190 :   basic_block bb;
    1757                 :             : 
    1758                 :    26742190 :   bb = loop_tree_node->bb;
    1759                 :    26742190 :   if (bb != NULL)
    1760                 :    23302672 :     process_bb_for_costs (bb);
    1761                 :    26742190 : }
    1762                 :             : 
    1763                 :             : /* Return true if all autoinc rtx in X change only a register and memory is
    1764                 :             :    valid.  */
    1765                 :             : static bool
    1766                 :    29703142 : validate_autoinc_and_mem_addr_p (rtx x)
    1767                 :             : {
    1768                 :    29703142 :   enum rtx_code code = GET_CODE (x);
    1769                 :    29703142 :   if (GET_RTX_CLASS (code) == RTX_AUTOINC)
    1770                 :      118053 :     return REG_P (XEXP (x, 0));
    1771                 :    29585089 :   const char *fmt = GET_RTX_FORMAT (code);
    1772                 :    73640295 :   for (int i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1773                 :    45041332 :     if (fmt[i] == 'e')
    1774                 :             :       {
    1775                 :    24274834 :         if (!validate_autoinc_and_mem_addr_p (XEXP (x, i)))
    1776                 :             :           return false;
    1777                 :             :       }
    1778                 :    20766498 :     else if (fmt[i] == 'E')
    1779                 :             :       {
    1780                 :     2632396 :         for (int j = 0; j < XVECLEN (x, i); j++)
    1781                 :     1795000 :           if (!validate_autoinc_and_mem_addr_p (XVECEXP (x, i, j)))
    1782                 :             :             return false;
    1783                 :             :       }
    1784                 :             :   /* Check memory after checking autoinc to guarantee that autoinc is already
    1785                 :             :      valid for machine-dependent code checking memory address.  */
    1786                 :    28598963 :   return (!MEM_P (x)
    1787                 :    61847891 :           || memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
    1788                 :     5439261 :                                           MEM_ADDR_SPACE (x)));
    1789                 :             : }
    1790                 :             : 
    1791                 :             : /* Check that reg REGNO in INSN can be changed by TO (which is an invariant
    1792                 :             :    equiv when INVARIANT_P is true).  Return true in case the result insn would
    1793                 :             :    be valid one.  */
    1794                 :             : static bool
    1795                 :     4927655 : equiv_can_be_consumed_p (int regno, rtx to, rtx_insn *insn, bool invariant_p)
    1796                 :             : {
    1797                 :     4927655 :   if (invariant_p)
    1798                 :             :     {
    1799                 :             :       /* We use more expensive code for the invariant because we need to
    1800                 :             :          simplify the result insn as the invariant can be arithmetic rtx
    1801                 :             :          inserted into another arithmetic rtx.  */
    1802                 :     1294347 :       rtx pat = PATTERN (insn);
    1803                 :     1294347 :       int code = INSN_CODE (insn);
    1804                 :     1294347 :       PATTERN (insn) = copy_rtx (pat);
    1805                 :     1294347 :       PATTERN (insn)
    1806                 :     1294347 :         = simplify_replace_rtx (PATTERN (insn), regno_reg_rtx[regno], to);
    1807                 :     1294347 :       bool res = !insn_invalid_p (insn, false);
    1808                 :     1294347 :       PATTERN (insn) = pat;
    1809                 :     1294347 :       INSN_CODE (insn) = code;
    1810                 :     1294347 :       return res;
    1811                 :             :     }
    1812                 :     3633308 :   validate_replace_src_group (regno_reg_rtx[regno], to, insn);
    1813                 :             :   /* We can change register to equivalent memory in autoinc rtl.  Some code
    1814                 :             :      including verify_changes assumes that autoinc contains only a register.
    1815                 :             :      So check this first.  */
    1816                 :     3633308 :   bool res = validate_autoinc_and_mem_addr_p (PATTERN (insn));
    1817                 :     3633308 :   if (res)
    1818                 :     2844012 :     res = verify_changes (0);
    1819                 :     3633308 :   cancel_changes (0);
    1820                 :     3633308 :   return res;
    1821                 :             : }
    1822                 :             : 
    1823                 :             : /* Return true if X contains a pseudo with equivalence.  In this case also
    1824                 :             :    return the pseudo through parameter REG.  If the pseudo is a part of subreg,
    1825                 :             :    return the subreg through parameter SUBREG.  */
    1826                 :             : 
    1827                 :             : static bool
    1828                 :   259096644 : get_equiv_regno (rtx x, int &regno, rtx &subreg)
    1829                 :             : {
    1830                 :   259096644 :   subreg = NULL_RTX;
    1831                 :   259096644 :   if (GET_CODE (x) == SUBREG)
    1832                 :             :     {
    1833                 :     2114828 :       subreg = x;
    1834                 :     2114828 :       x = SUBREG_REG (x);
    1835                 :             :     }
    1836                 :   259096644 :   if (REG_P (x)
    1837                 :   259096644 :       && (ira_reg_equiv[REGNO (x)].memory != NULL
    1838                 :    77681988 :           || ira_reg_equiv[REGNO (x)].invariant != NULL
    1839                 :    75710935 :           || ira_reg_equiv[REGNO (x)].constant != NULL))
    1840                 :             :     {
    1841                 :     9636902 :       regno = REGNO (x);
    1842                 :     9636902 :       return true;
    1843                 :             :     }
    1844                 :   249459742 :   RTX_CODE code = GET_CODE (x);
    1845                 :   249459742 :   const char *fmt = GET_RTX_FORMAT (code);
    1846                 :             : 
    1847                 :   583024145 :   for (int i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
    1848                 :   347739288 :     if (fmt[i] == 'e')
    1849                 :             :       {
    1850                 :   191383073 :         if (get_equiv_regno (XEXP (x, i), regno, subreg))
    1851                 :             :           return true;
    1852                 :             :       }
    1853                 :   156356215 :     else if (fmt[i] == 'E')
    1854                 :             :       {
    1855                 :    23157595 :         for (int j = 0; j < XVECLEN (x, i); j++)
    1856                 :    16094403 :           if (get_equiv_regno (XVECEXP (x, i, j), regno, subreg))
    1857                 :             :             return true;
    1858                 :             :       }
    1859                 :             :   return false;
    1860                 :             : }
    1861                 :             : 
    1862                 :             : /* A pass through the current function insns.  Calculate costs of using
    1863                 :             :    equivalences for pseudos and store them in regno_equiv_gains.  */
    1864                 :             : 
    1865                 :             : static void
    1866                 :      927694 : calculate_equiv_gains (void)
    1867                 :             : {
    1868                 :      927694 :   basic_block bb;
    1869                 :      927694 :   int regno, freq, cost;
    1870                 :      927694 :   rtx subreg;
    1871                 :      927694 :   rtx_insn *insn;
    1872                 :      927694 :   machine_mode mode;
    1873                 :      927694 :   enum reg_class rclass;
    1874                 :      927694 :   bitmap_head equiv_pseudos;
    1875                 :             : 
    1876                 :      927694 :   ira_assert (allocno_p);
    1877                 :      927694 :   bitmap_initialize (&equiv_pseudos, &reg_obstack);
    1878                 :    45539721 :   for (regno = max_reg_num () - 1; regno >= FIRST_PSEUDO_REGISTER; regno--)
    1879                 :    44612027 :     if (ira_reg_equiv[regno].init_insns != NULL
    1880                 :     3952053 :         && (ira_reg_equiv[regno].memory != NULL
    1881                 :     1344917 :             || ira_reg_equiv[regno].invariant != NULL
    1882                 :      668130 :             || (ira_reg_equiv[regno].constant != NULL
    1883                 :             :                 /* Ignore complicated constants which probably will be placed
    1884                 :             :                    in memory:  */
    1885                 :      668130 :                 && GET_CODE (ira_reg_equiv[regno].constant) != CONST_DOUBLE
    1886                 :             :                 && GET_CODE (ira_reg_equiv[regno].constant) != CONST_VECTOR
    1887                 :             :                 && GET_CODE (ira_reg_equiv[regno].constant) != LABEL_REF)))
    1888                 :             :       {
    1889                 :             :         rtx_insn_list *x;
    1890                 :     7081095 :         for (x = ira_reg_equiv[regno].init_insns; x != NULL; x = x->next ())
    1891                 :             :           {
    1892                 :     3758369 :             insn = x->insn ();
    1893                 :     3758369 :             rtx set = single_set (insn);
    1894                 :             : 
    1895                 :     3758369 :             if (set == NULL_RTX || SET_DEST (set) != regno_reg_rtx[regno])
    1896                 :             :               break;
    1897                 :     3322726 :             bb = BLOCK_FOR_INSN (insn);
    1898                 :     3322726 :             ira_curr_regno_allocno_map
    1899                 :     3322726 :               = ira_bb_nodes[bb->index].parent->regno_allocno_map;
    1900                 :     3322726 :             mode = PSEUDO_REGNO_MODE (regno);
    1901                 :     3322726 :             rclass = pref[COST_INDEX (regno)];
    1902                 :     3322726 :             ira_init_register_move_cost_if_necessary (mode);
    1903                 :     3322726 :             if (ira_reg_equiv[regno].memory != NULL)
    1904                 :     2171493 :               cost = ira_memory_move_cost[mode][rclass][1];
    1905                 :             :             else
    1906                 :     1151233 :               cost = ira_register_move_cost[mode][rclass][rclass];
    1907                 :     3322726 :             freq = REG_FREQ_FROM_BB (bb);
    1908                 :     3322726 :             regno_equiv_gains[regno] += cost * freq;
    1909                 :             :           }
    1910                 :     3758369 :         if (x != NULL)
    1911                 :             :           /* We found complicated equiv or reverse equiv mem=reg.  Ignore
    1912                 :             :              them.  */
    1913                 :      435643 :           regno_equiv_gains[regno] = 0;
    1914                 :             :         else
    1915                 :     3322726 :           bitmap_set_bit (&equiv_pseudos, regno);
    1916                 :             :       }
    1917                 :             : 
    1918                 :    10616693 :   FOR_EACH_BB_FN (bb, cfun)
    1919                 :             :     {
    1920                 :     9688999 :       freq = REG_FREQ_FROM_BB (bb);
    1921                 :     9688999 :       ira_curr_regno_allocno_map
    1922                 :     9688999 :         = ira_bb_nodes[bb->index].parent->regno_allocno_map;
    1923                 :   119985837 :       FOR_BB_INSNS (bb, insn)
    1924                 :             :         {
    1925                 :   212472434 :           if (!NONDEBUG_INSN_P (insn)
    1926                 :    51619168 :               || !get_equiv_regno (PATTERN (insn), regno, subreg)
    1927                 :   119933740 :               || !bitmap_bit_p (&equiv_pseudos, regno))
    1928                 :   102175596 :             continue;
    1929                 :             : 
    1930                 :     8121242 :           rtx_insn_list *x;
    1931                 :    13048897 :           for (x = ira_reg_equiv[regno].init_insns; x != NULL; x = x->next ())
    1932                 :     8121242 :             if (insn == x->insn ())
    1933                 :             :               break;
    1934                 :     8121242 :           if (x != NULL)
    1935                 :     3193587 :             continue; /* skip equiv init insn */
    1936                 :             : 
    1937                 :     4927655 :           rtx subst = ira_reg_equiv[regno].memory;
    1938                 :             : 
    1939                 :     4927655 :           if (subst == NULL)
    1940                 :     1852172 :             subst = ira_reg_equiv[regno].constant;
    1941                 :     1852172 :           if (subst == NULL)
    1942                 :     1294347 :             subst = ira_reg_equiv[regno].invariant;
    1943                 :     1294347 :           ira_assert (subst != NULL);
    1944                 :     4927655 :           mode = PSEUDO_REGNO_MODE (regno);
    1945                 :     4927655 :           ira_init_register_move_cost_if_necessary (mode);
    1946                 :     4927655 :           bool consumed_p
    1947                 :     9855310 :             = equiv_can_be_consumed_p (regno, subst, insn,
    1948                 :     4927655 :                                        subst == ira_reg_equiv[regno].invariant);
    1949                 :             : 
    1950                 :     4927655 :           rclass = pref[COST_INDEX (regno)];
    1951                 :     4927655 :           if (MEM_P (subst)
    1952                 :             :               /* If it is a change of constant into double for example, the
    1953                 :             :                  result constant probably will be placed in memory.  */
    1954                 :     1852172 :               || (ira_reg_equiv[regno].invariant == NULL
    1955                 :      557825 :                   && subreg != NULL_RTX
    1956                 :        1078 :                   && !INTEGRAL_MODE_P (GET_MODE (subreg))))
    1957                 :     5646138 :             cost = ira_memory_move_cost[mode][rclass][1] + (consumed_p ? 0 : 1);
    1958                 :     1852107 :           else if (consumed_p)
    1959                 :      891905 :             continue;
    1960                 :             :           else
    1961                 :      960202 :             cost = ira_register_move_cost[mode][rclass][rclass];
    1962                 :     4035750 :           regno_equiv_gains[regno] -= cost * freq;
    1963                 :             :         }
    1964                 :             :     }
    1965                 :      927694 :   bitmap_clear (&equiv_pseudos);
    1966                 :      927694 : }
    1967                 :             : 
    1968                 :             : /* Find costs of register classes and memory for allocnos or pseudos
    1969                 :             :    and their best costs.  Set up preferred, alternative and allocno
    1970                 :             :    classes for pseudos.  */
    1971                 :             : static void
    1972                 :     1459843 : find_costs_and_classes (void)
    1973                 :             : {
    1974                 :     1459843 :   int i, k, start, max_cost_classes_num;
    1975                 :     1459843 :   int pass;
    1976                 :     1459843 :   basic_block bb;
    1977                 :     1459843 :   enum reg_class *regno_best_class, new_class;
    1978                 :             : 
    1979                 :     1459843 :   init_recog ();
    1980                 :     1459843 :   regno_best_class
    1981                 :     1459843 :     = (enum reg_class *) ira_allocate (max_reg_num ()
    1982                 :             :                                        * sizeof (enum reg_class));
    1983                 :    65493304 :   for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    1984                 :    64033461 :     regno_best_class[i] = NO_REGS;
    1985                 :     2891508 :   if (!resize_reg_info () && allocno_p
    1986                 :     2891465 :       && pseudo_classes_defined_p && flag_expensive_optimizations)
    1987                 :             :     {
    1988                 :          63 :       ira_allocno_t a;
    1989                 :          63 :       ira_allocno_iterator ai;
    1990                 :             : 
    1991                 :          63 :       pref = pref_buffer;
    1992                 :          63 :       max_cost_classes_num = 1;
    1993                 :        1811 :       FOR_EACH_ALLOCNO (a, ai)
    1994                 :             :         {
    1995                 :        1748 :           pref[ALLOCNO_NUM (a)] = reg_preferred_class (ALLOCNO_REGNO (a));
    1996                 :        1748 :           setup_regno_cost_classes_by_aclass
    1997                 :        1748 :             (ALLOCNO_REGNO (a), pref[ALLOCNO_NUM (a)]);
    1998                 :        1748 :           max_cost_classes_num
    1999                 :        1748 :             = MAX (max_cost_classes_num,
    2000                 :             :                    regno_cost_classes[ALLOCNO_REGNO (a)]->num);
    2001                 :             :         }
    2002                 :          63 :       start = 1;
    2003                 :             :     }
    2004                 :             :   else
    2005                 :             :     {
    2006                 :     1459780 :       pref = NULL;
    2007                 :     1459780 :       max_cost_classes_num = ira_important_classes_num;
    2008                 :    65490130 :       for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    2009                 :    64030350 :         if (regno_reg_rtx[i] != NULL_RTX)
    2010                 :    63728262 :           setup_regno_cost_classes_by_mode (i, PSEUDO_REGNO_MODE (i));
    2011                 :             :         else
    2012                 :      302088 :           setup_regno_cost_classes_by_aclass (i, ALL_REGS);
    2013                 :             :       start = 0;
    2014                 :             :     }
    2015                 :     1459843 :   if (allocno_p)
    2016                 :             :     /* Clear the flag for the next compiled function.  */
    2017                 :     1431622 :     pseudo_classes_defined_p = false;
    2018                 :             :   /* Normally we scan the insns once and determine the best class to
    2019                 :             :      use for each allocno.  However, if -fexpensive-optimizations are
    2020                 :             :      on, we do so twice, the second time using the tentative best
    2021                 :             :      classes to guide the selection.  */
    2022                 :     3875486 :   for (pass = start; pass <= flag_expensive_optimizations; pass++)
    2023                 :             :     {
    2024                 :     2415643 :       if ((!allocno_p || internal_flag_ira_verbose > 0) && ira_dump_file)
    2025                 :         143 :         fprintf (ira_dump_file,
    2026                 :             :                  "\nPass %i for finding pseudo/allocno costs\n\n", pass);
    2027                 :             : 
    2028                 :     2415643 :       if (pass != start)
    2029                 :             :         {
    2030                 :      955800 :           max_cost_classes_num = 1;
    2031                 :    46893255 :           for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    2032                 :             :             {
    2033                 :    45937455 :               setup_regno_cost_classes_by_aclass (i, regno_best_class[i]);
    2034                 :    45937455 :               max_cost_classes_num
    2035                 :    45937455 :                 = MAX (max_cost_classes_num, regno_cost_classes[i]->num);
    2036                 :             :             }
    2037                 :             :         }
    2038                 :             : 
    2039                 :     2415643 :       struct_costs_size
    2040                 :     2415643 :         = sizeof (struct costs) + sizeof (int) * (max_cost_classes_num - 1);
    2041                 :             :       /* Zero out our accumulation of the cost of each class for each
    2042                 :             :          allocno.  */
    2043                 :     2415643 :       memset (costs, 0, cost_elements_num * struct_costs_size);
    2044                 :             : 
    2045                 :     2415643 :       if (allocno_p)
    2046                 :             :         {
    2047                 :             :           /* Scan the instructions and record each time it would save code
    2048                 :             :              to put a certain allocno in a certain class.  */
    2049                 :     2359253 :           ira_traverse_loop_tree (true, ira_loop_tree_root,
    2050                 :             :                                   process_bb_node_for_costs, NULL);
    2051                 :             : 
    2052                 :     2359253 :           memcpy (total_allocno_costs, costs,
    2053                 :     2359253 :                   max_struct_costs_size * ira_allocnos_num);
    2054                 :             :         }
    2055                 :             :       else
    2056                 :             :         {
    2057                 :       56390 :           basic_block bb;
    2058                 :             : 
    2059                 :      700462 :           FOR_EACH_BB_FN (bb, cfun)
    2060                 :      644072 :             process_bb_for_costs (bb);
    2061                 :             :         }
    2062                 :             : 
    2063                 :     2415643 :       if (pass == 0)
    2064                 :     1459780 :         pref = pref_buffer;
    2065                 :             : 
    2066                 :     2415643 :       if (ira_use_lra_p && allocno_p && pass == 1)
    2067                 :             :         /* It is a pass through all insns.  So do it once and only for RA (not
    2068                 :             :            for insn scheduler) when we already found preferable pseudo register
    2069                 :             :            classes on the previous pass.  */
    2070                 :      927694 :         calculate_equiv_gains ();
    2071                 :             : 
    2072                 :             :       /* Now for each allocno look at how desirable each class is and
    2073                 :             :          find which class is preferred.  */
    2074                 :   112386559 :       for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
    2075                 :             :         {
    2076                 :   109970916 :           ira_allocno_t a, parent_a;
    2077                 :   109970916 :           int rclass, a_num, parent_a_num, add_cost;
    2078                 :   109970916 :           ira_loop_tree_node_t parent;
    2079                 :   109970916 :           int best_cost, allocno_cost;
    2080                 :   109970916 :           enum reg_class best, alt_class;
    2081                 :   109970916 :           cost_classes_t cost_classes_ptr = regno_cost_classes[i];
    2082                 :   109970916 :           enum reg_class *cost_classes;
    2083                 :   109970916 :           int *i_costs = temp_costs->cost;
    2084                 :   109970916 :           int i_mem_cost;
    2085                 :   109970916 :           int equiv_savings = regno_equiv_gains[i];
    2086                 :             : 
    2087                 :   109970916 :           if (! allocno_p)
    2088                 :             :             {
    2089                 :     2658684 :               if (regno_reg_rtx[i] == NULL_RTX)
    2090                 :        4454 :                 continue;
    2091                 :     2654230 :               memcpy (temp_costs, COSTS (costs, i), struct_costs_size);
    2092                 :     2654230 :               i_mem_cost = temp_costs->mem_cost;
    2093                 :     2654230 :               cost_classes = cost_classes_ptr->classes;
    2094                 :             :             }
    2095                 :             :           else
    2096                 :             :             {
    2097                 :   107312232 :               if (ira_regno_allocno_map[i] == NULL)
    2098                 :    62575050 :                 continue;
    2099                 :    44737182 :               memset (temp_costs, 0, struct_costs_size);
    2100                 :    44737182 :               i_mem_cost = 0;
    2101                 :    44737182 :               cost_classes = cost_classes_ptr->classes;
    2102                 :             :               /* Find cost of all allocnos with the same regno.  */
    2103                 :    44737182 :               for (a = ira_regno_allocno_map[i];
    2104                 :    99164364 :                    a != NULL;
    2105                 :    54427182 :                    a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
    2106                 :             :                 {
    2107                 :    54427182 :                   int *a_costs, *p_costs;
    2108                 :             : 
    2109                 :    54427182 :                   a_num = ALLOCNO_NUM (a);
    2110                 :    54427182 :                   if ((flag_ira_region == IRA_REGION_ALL
    2111                 :    54427182 :                        || flag_ira_region == IRA_REGION_MIXED)
    2112                 :    42128486 :                       && (parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) != NULL
    2113                 :    15810919 :                       && (parent_a = parent->regno_allocno_map[i]) != NULL
    2114                 :             :                       /* There are no caps yet.  */
    2115                 :    64116733 :                       && bitmap_bit_p (ALLOCNO_LOOP_TREE_NODE
    2116                 :     9689551 :                                        (a)->border_allocnos,
    2117                 :             :                                        ALLOCNO_NUM (a)))
    2118                 :             :                     {
    2119                 :             :                       /* Propagate costs to upper levels in the region
    2120                 :             :                          tree.  */
    2121                 :     9681787 :                       parent_a_num = ALLOCNO_NUM (parent_a);
    2122                 :     9681787 :                       a_costs = COSTS (total_allocno_costs, a_num)->cost;
    2123                 :     9681787 :                       p_costs = COSTS (total_allocno_costs, parent_a_num)->cost;
    2124                 :   142407407 :                       for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    2125                 :             :                         {
    2126                 :   132725620 :                           add_cost = a_costs[k];
    2127                 :   132725620 :                           if (add_cost > 0 && INT_MAX - add_cost < p_costs[k])
    2128                 :           0 :                             p_costs[k] = INT_MAX;
    2129                 :             :                           else
    2130                 :   132725620 :                             p_costs[k] += add_cost;
    2131                 :             :                         }
    2132                 :     9681787 :                       add_cost = COSTS (total_allocno_costs, a_num)->mem_cost;
    2133                 :     9681787 :                       if (add_cost > 0
    2134                 :     4777856 :                           && (INT_MAX - add_cost
    2135                 :             :                               < COSTS (total_allocno_costs,
    2136                 :     4777856 :                                        parent_a_num)->mem_cost))
    2137                 :           0 :                         COSTS (total_allocno_costs, parent_a_num)->mem_cost
    2138                 :           0 :                           = INT_MAX;
    2139                 :             :                       else
    2140                 :     9681787 :                         COSTS (total_allocno_costs, parent_a_num)->mem_cost
    2141                 :     9681787 :                           += add_cost;
    2142                 :             : 
    2143                 :     9681787 :                       if (i >= first_moveable_pseudo && i < last_moveable_pseudo)
    2144                 :           0 :                         COSTS (total_allocno_costs, parent_a_num)->mem_cost = 0;
    2145                 :             :                     }
    2146                 :    54427182 :                   a_costs = COSTS (costs, a_num)->cost;
    2147                 :   815722078 :                   for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    2148                 :             :                     {
    2149                 :   761294896 :                       add_cost = a_costs[k];
    2150                 :   761294896 :                       if (add_cost > 0 && INT_MAX - add_cost < i_costs[k])
    2151                 :           0 :                         i_costs[k] = INT_MAX;
    2152                 :             :                       else
    2153                 :   761294896 :                         i_costs[k] += add_cost;
    2154                 :             :                     }
    2155                 :    54427182 :                   add_cost = COSTS (costs, a_num)->mem_cost;
    2156                 :    54427182 :                   if (add_cost > 0 && INT_MAX - add_cost < i_mem_cost)
    2157                 :             :                     i_mem_cost = INT_MAX;
    2158                 :             :                   else
    2159                 :    54427182 :                     i_mem_cost += add_cost;
    2160                 :             :                 }
    2161                 :             :             }
    2162                 :    47391412 :           if (i >= first_moveable_pseudo && i < last_moveable_pseudo)
    2163                 :             :             i_mem_cost = 0;
    2164                 :    47365512 :           else if (ira_use_lra_p)
    2165                 :             :             {
    2166                 :    47365512 :               if (equiv_savings > 0)
    2167                 :             :                 {
    2168                 :      514244 :                   i_mem_cost = 0;
    2169                 :      514244 :                   if (ira_dump_file != NULL && internal_flag_ira_verbose > 5)
    2170                 :           0 :                     fprintf (ira_dump_file,
    2171                 :             :                              "   Use MEM for r%d as the equiv savings is %d\n",
    2172                 :             :                              i, equiv_savings);
    2173                 :             :                 }
    2174                 :             :             }
    2175                 :           0 :           else if (equiv_savings < 0)
    2176                 :           0 :             i_mem_cost = -equiv_savings;
    2177                 :           0 :           else if (equiv_savings > 0)
    2178                 :             :             {
    2179                 :           0 :               i_mem_cost = 0;
    2180                 :           0 :               for (k = cost_classes_ptr->num - 1; k >= 0; k--)
    2181                 :           0 :                 i_costs[k] += equiv_savings;
    2182                 :             :             }
    2183                 :             : 
    2184                 :    47391412 :           best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1;
    2185                 :    47391412 :           best = ALL_REGS;
    2186                 :    47391412 :           alt_class = NO_REGS;
    2187                 :             :           /* Find best common class for all allocnos with the same
    2188                 :             :              regno.  */
    2189                 :   721360172 :           for (k = 0; k < cost_classes_ptr->num; k++)
    2190                 :             :             {
    2191                 :   673968760 :               rclass = cost_classes[k];
    2192                 :   673968760 :               if (i_costs[k] < best_cost)
    2193                 :             :                 {
    2194                 :             :                   best_cost = i_costs[k];
    2195                 :             :                   best = (enum reg_class) rclass;
    2196                 :             :                 }
    2197                 :   615458868 :               else if (i_costs[k] == best_cost)
    2198                 :   292313580 :                 best = ira_reg_class_subunion[best][rclass];
    2199                 :   673968760 :               if (pass == flag_expensive_optimizations
    2200                 :             :                   /* We still prefer registers to memory even at this
    2201                 :             :                      stage if their costs are the same.  We will make
    2202                 :             :                      a final decision during assigning hard registers
    2203                 :             :                      when we have all info including more accurate
    2204                 :             :                      costs which might be affected by assigning hard
    2205                 :             :                      registers to other pseudos because the pseudos
    2206                 :             :                      involved in moves can be coalesced.  */
    2207                 :   388808824 :                   && i_costs[k] <= i_mem_cost
    2208                 :   266894738 :                   && (reg_class_size[reg_class_subunion[alt_class][rclass]]
    2209                 :   266894738 :                       > reg_class_size[alt_class]))
    2210                 :   673968760 :                 alt_class = reg_class_subunion[alt_class][rclass];
    2211                 :             :             }
    2212                 :    47391412 :           alt_class = ira_allocno_class_translate[alt_class];
    2213                 :    47391412 :           if (best_cost > i_mem_cost
    2214                 :    47391412 :               && ! non_spilled_static_chain_regno_p (i))
    2215                 :      732066 :             regno_aclass[i] = NO_REGS;
    2216                 :    46659346 :           else if (!optimize && !targetm.class_likely_spilled_p (best))
    2217                 :             :             /* Registers in the alternative class are likely to need
    2218                 :             :                longer or slower sequences than registers in the best class.
    2219                 :             :                When optimizing we make some effort to use the best class
    2220                 :             :                over the alternative class where possible, but at -O0 we
    2221                 :             :                effectively give the alternative class equal weight.
    2222                 :             :                We then run the risk of using slower alternative registers
    2223                 :             :                when plenty of registers from the best class are still free.
    2224                 :             :                This is especially true because live ranges tend to be very
    2225                 :             :                short in -O0 code and so register pressure tends to be low.
    2226                 :             : 
    2227                 :             :                Avoid that by ignoring the alternative class if the best
    2228                 :             :                class has plenty of registers.
    2229                 :             : 
    2230                 :             :                The union class arrays give important classes and only
    2231                 :             :                part of it are allocno classes.  So translate them into
    2232                 :             :                allocno classes.  */
    2233                 :     9368072 :             regno_aclass[i] = ira_allocno_class_translate[best];
    2234                 :             :           else
    2235                 :             :             {
    2236                 :             :               /* Make the common class the biggest class of best and
    2237                 :             :                  alt_class.  Translate the common class into an
    2238                 :             :                  allocno class too.  */
    2239                 :    37291274 :               regno_aclass[i] = (ira_allocno_class_translate
    2240                 :    37291274 :                                  [ira_reg_class_superunion[best][alt_class]]);
    2241                 :    37291274 :               ira_assert (regno_aclass[i] != NO_REGS
    2242                 :             :                           && ira_reg_allocno_class_p[regno_aclass[i]]);
    2243                 :             :             }
    2244                 :    47391412 :           if (pic_offset_table_rtx != NULL
    2245                 :    47391412 :               && i == (int) REGNO (pic_offset_table_rtx))
    2246                 :             :             {
    2247                 :             :               /* For some targets, integer pseudos can be assigned to fp
    2248                 :             :                  regs.  As we don't want reload pic offset table pseudo, we
    2249                 :             :                  should avoid using non-integer regs.  */
    2250                 :       80477 :               regno_aclass[i]
    2251                 :       80477 :                 = ira_reg_class_intersect[regno_aclass[i]][GENERAL_REGS];
    2252                 :       80477 :               alt_class = ira_reg_class_intersect[alt_class][GENERAL_REGS];
    2253                 :             :             }
    2254                 :    94782824 :           if ((new_class
    2255                 :    94782824 :                = (reg_class) (targetm.ira_change_pseudo_allocno_class
    2256                 :    47391412 :                               (i, regno_aclass[i], best))) != regno_aclass[i])
    2257                 :             :             {
    2258                 :           0 :               regno_aclass[i] = new_class;
    2259                 :           0 :               if (hard_reg_set_subset_p (reg_class_contents[new_class],
    2260                 :           0 :                                          reg_class_contents[best]))
    2261                 :           0 :                 best = new_class;
    2262                 :           0 :               if (hard_reg_set_subset_p (reg_class_contents[new_class],
    2263                 :           0 :                                          reg_class_contents[alt_class]))
    2264                 :           0 :                 alt_class = new_class;
    2265                 :             :             }
    2266                 :    47391412 :           if (pass == flag_expensive_optimizations)
    2267                 :             :             {
    2268                 :    29920938 :               if (best_cost > i_mem_cost
    2269                 :             :                   /* Do not assign NO_REGS to static chain pointer
    2270                 :             :                      pseudo when non-local goto is used.  */
    2271                 :    29920938 :                   && ! non_spilled_static_chain_regno_p (i))
    2272                 :             :                 best = alt_class = NO_REGS;
    2273                 :    29458972 :               else if (best == alt_class)
    2274                 :    20536001 :                 alt_class = NO_REGS;
    2275                 :    29920938 :               setup_reg_classes (i, best, alt_class, regno_aclass[i]);
    2276                 :    29920938 :               if ((!allocno_p || internal_flag_ira_verbose > 2)
    2277                 :    29920938 :                   && ira_dump_file != NULL)
    2278                 :         969 :                 fprintf (ira_dump_file,
    2279                 :             :                          "    r%d: preferred %s, alternative %s, allocno %s\n",
    2280                 :         969 :                          i, reg_class_names[best], reg_class_names[alt_class],
    2281                 :         969 :                          reg_class_names[regno_aclass[i]]);
    2282                 :             :             }
    2283                 :    47391412 :           regno_best_class[i] = best;
    2284                 :    47391412 :           if (! allocno_p)
    2285                 :             :             {
    2286                 :     5308460 :               pref[i] = (best_cost > i_mem_cost
    2287                 :        2642 :                          && ! non_spilled_static_chain_regno_p (i)
    2288                 :     2654230 :                          ? NO_REGS : best);
    2289                 :     2654230 :               continue;
    2290                 :             :             }
    2291                 :    44737182 :           for (a = ira_regno_allocno_map[i];
    2292                 :    99164364 :                a != NULL;
    2293                 :    54427182 :                a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
    2294                 :             :             {
    2295                 :    54427182 :               enum reg_class aclass = regno_aclass[i];
    2296                 :    54427182 :               int a_num = ALLOCNO_NUM (a);
    2297                 :    54427182 :               int *total_a_costs = COSTS (total_allocno_costs, a_num)->cost;
    2298                 :    54427182 :               int *a_costs = COSTS (costs, a_num)->cost;
    2299                 :             : 
    2300                 :    54427182 :               if (aclass == NO_REGS)
    2301                 :             :                 best = NO_REGS;
    2302                 :             :               else
    2303                 :             :                 {
    2304                 :             :                   /* Finding best class which is subset of the common
    2305                 :             :                      class.  */
    2306                 :             :                   best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1;
    2307                 :             :                   allocno_cost = best_cost;
    2308                 :             :                   best = ALL_REGS;
    2309                 :   803018350 :                   for (k = 0; k < cost_classes_ptr->num; k++)
    2310                 :             :                     {
    2311                 :   749498706 :                       rclass = cost_classes[k];
    2312                 :   749498706 :                       if (! ira_class_subset_p[rclass][aclass])
    2313                 :   359526376 :                         continue;
    2314                 :   389972330 :                       if (total_a_costs[k] < best_cost)
    2315                 :             :                         {
    2316                 :    58189959 :                           best_cost = total_a_costs[k];
    2317                 :    58189959 :                           allocno_cost = a_costs[k];
    2318                 :    58189959 :                           best = (enum reg_class) rclass;
    2319                 :             :                         }
    2320                 :   331782371 :                       else if (total_a_costs[k] == best_cost)
    2321                 :             :                         {
    2322                 :   270361270 :                           best = ira_reg_class_subunion[best][rclass];
    2323                 :   270361270 :                           allocno_cost = MAX (allocno_cost, a_costs[k]);
    2324                 :             :                         }
    2325                 :             :                     }
    2326                 :    53519644 :                   ALLOCNO_CLASS_COST (a) = allocno_cost;
    2327                 :             :                 }
    2328                 :    54427182 :               if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL
    2329                 :        1212 :                   && (pass == 0 || pref[a_num] != best))
    2330                 :             :                 {
    2331                 :         775 :                   fprintf (ira_dump_file, "    a%d (r%d,", a_num, i);
    2332                 :         775 :                   if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
    2333                 :           0 :                     fprintf (ira_dump_file, "b%d", bb->index);
    2334                 :             :                   else
    2335                 :         775 :                     fprintf (ira_dump_file, "l%d",
    2336                 :             :                              ALLOCNO_LOOP_TREE_NODE (a)->loop_num);
    2337                 :         775 :                   fprintf (ira_dump_file, ") best %s, allocno %s\n",
    2338                 :         775 :                            reg_class_names[best],
    2339                 :         775 :                            reg_class_names[aclass]);
    2340                 :             :                 }
    2341                 :    54427182 :               pref[a_num] = best;
    2342                 :    54427182 :               if (pass == flag_expensive_optimizations && best != aclass
    2343                 :     7391906 :                   && ira_class_hard_regs_num[best] > 0
    2344                 :     7391906 :                   && (ira_reg_class_max_nregs[best][ALLOCNO_MODE (a)]
    2345                 :             :                       >= ira_class_hard_regs_num[best]))
    2346                 :             :                 {
    2347                 :     6701234 :                   int ind = cost_classes_ptr->index[aclass];
    2348                 :             : 
    2349                 :     6701234 :                   ira_assert (ind >= 0);
    2350                 :     6701234 :                   ira_init_register_move_cost_if_necessary (ALLOCNO_MODE (a));
    2351                 :     6701234 :                   ira_add_allocno_pref (a, ira_class_hard_regs[best][0],
    2352                 :     6701234 :                                         (a_costs[ind] - ALLOCNO_CLASS_COST (a))
    2353                 :             :                                         / (ira_register_move_cost
    2354                 :     6701234 :                                            [ALLOCNO_MODE (a)][best][aclass]));
    2355                 :   132777721 :                   for (k = 0; k < cost_classes_ptr->num; k++)
    2356                 :   119375253 :                     if (ira_class_subset_p[cost_classes[k]][best])
    2357                 :     6701234 :                       a_costs[k] = a_costs[ind];
    2358                 :             :                 }
    2359                 :             :             }
    2360                 :             :         }
    2361                 :             : 
    2362                 :     2415643 :       if (internal_flag_ira_verbose > 4 && ira_dump_file)
    2363                 :             :         {
    2364                 :         143 :           if (allocno_p)
    2365                 :         127 :             print_allocno_costs ();
    2366                 :             :           else
    2367                 :          16 :             print_pseudo_costs ();
    2368                 :         143 :           fprintf (ira_dump_file,"\n");
    2369                 :             :         }
    2370                 :             :     }
    2371                 :     1459843 :   ira_free (regno_best_class);
    2372                 :     1459843 : }
    2373                 :             : 
    2374                 :             : 
    2375                 :             : 
    2376                 :             : /* Process moves involving hard regs to modify allocno hard register
    2377                 :             :    costs.  We can do this only after determining allocno class.  If a
    2378                 :             :    hard register forms a register class, then moves with the hard
    2379                 :             :    register are already taken into account in class costs for the
    2380                 :             :    allocno.  */
    2381                 :             : static void
    2382                 :    11801851 : process_bb_node_for_hard_reg_moves (ira_loop_tree_node_t loop_tree_node)
    2383                 :             : {
    2384                 :    11801851 :   int i, freq, src_regno, dst_regno, hard_regno, a_regno;
    2385                 :    11801851 :   bool to_p;
    2386                 :    11801851 :   ira_allocno_t a, curr_a;
    2387                 :    11801851 :   ira_loop_tree_node_t curr_loop_tree_node;
    2388                 :    11801851 :   enum reg_class rclass;
    2389                 :    11801851 :   basic_block bb;
    2390                 :    11801851 :   rtx_insn *insn;
    2391                 :    11801851 :   rtx set, src, dst;
    2392                 :             : 
    2393                 :    11801851 :   bb = loop_tree_node->bb;
    2394                 :    11801851 :   if (bb == NULL)
    2395                 :             :     return;
    2396                 :    10237917 :   freq = REG_FREQ_FROM_BB (bb);
    2397                 :     7979452 :   if (freq == 0)
    2398                 :     1909226 :     freq = 1;
    2399                 :   125368371 :   FOR_BB_INSNS (bb, insn)
    2400                 :             :     {
    2401                 :   115130454 :       if (!NONDEBUG_INSN_P (insn))
    2402                 :    59868056 :         continue;
    2403                 :    55262398 :       set = single_set (insn);
    2404                 :    55262398 :       if (set == NULL_RTX)
    2405                 :     3711844 :         continue;
    2406                 :    51550554 :       dst = SET_DEST (set);
    2407                 :    51550554 :       src = SET_SRC (set);
    2408                 :    51550554 :       if (! REG_P (dst) || ! REG_P (src))
    2409                 :    42975440 :         continue;
    2410                 :     8575114 :       dst_regno = REGNO (dst);
    2411                 :     8575114 :       src_regno = REGNO (src);
    2412                 :     8575114 :       if (dst_regno >= FIRST_PSEUDO_REGISTER
    2413                 :     8575114 :           && src_regno < FIRST_PSEUDO_REGISTER)
    2414                 :             :         {
    2415                 :     2918199 :           hard_regno = src_regno;
    2416                 :     2918199 :           a = ira_curr_regno_allocno_map[dst_regno];
    2417                 :     2918199 :           to_p = true;
    2418                 :             :         }
    2419                 :     6794121 :       else if (src_regno >= FIRST_PSEUDO_REGISTER
    2420                 :     5656915 :                && dst_regno < FIRST_PSEUDO_REGISTER)
    2421                 :             :         {
    2422                 :     4519709 :           hard_regno = dst_regno;
    2423                 :     4519709 :           a = ira_curr_regno_allocno_map[src_regno];
    2424                 :     4519709 :           to_p = false;
    2425                 :             :         }
    2426                 :             :       else
    2427                 :     1137206 :         continue;
    2428                 :    14391868 :       if (reg_class_size[(int) REGNO_REG_CLASS (hard_regno)]
    2429                 :             :           == (ira_reg_class_max_nregs
    2430                 :     7437908 :               [REGNO_REG_CLASS (hard_regno)][(int) ALLOCNO_MODE(a)]))
    2431                 :             :         /* If the class can provide only one hard reg to the allocno,
    2432                 :             :            we processed the insn record_operand_costs already and we
    2433                 :             :            actually updated the hard reg cost there.  */
    2434                 :     6953960 :         continue;
    2435                 :      483948 :       rclass = ALLOCNO_CLASS (a);
    2436                 :      483948 :       if (! TEST_HARD_REG_BIT (reg_class_contents[rclass], hard_regno))
    2437                 :       22955 :         continue;
    2438                 :      460993 :       i = ira_class_hard_reg_index[rclass][hard_regno];
    2439                 :      460993 :       if (i < 0)
    2440                 :        7069 :         continue;
    2441                 :      453924 :       a_regno = ALLOCNO_REGNO (a);
    2442                 :      453924 :       for (curr_loop_tree_node = ALLOCNO_LOOP_TREE_NODE (a);
    2443                 :      995495 :            curr_loop_tree_node != NULL;
    2444                 :      541571 :            curr_loop_tree_node = curr_loop_tree_node->parent)
    2445                 :      541571 :         if ((curr_a = curr_loop_tree_node->regno_allocno_map[a_regno]) != NULL)
    2446                 :      471925 :           ira_add_allocno_pref (curr_a, hard_regno, freq);
    2447                 :      453924 :       {
    2448                 :      453924 :         int cost;
    2449                 :      453924 :         enum reg_class hard_reg_class;
    2450                 :      453924 :         machine_mode mode;
    2451                 :             : 
    2452                 :      453924 :         mode = ALLOCNO_MODE (a);
    2453                 :      453924 :         hard_reg_class = REGNO_REG_CLASS (hard_regno);
    2454                 :      453924 :         ira_init_register_move_cost_if_necessary (mode);
    2455                 :      453924 :         cost = (to_p ? ira_register_move_cost[mode][hard_reg_class][rclass]
    2456                 :      262099 :                 : ira_register_move_cost[mode][rclass][hard_reg_class]) * freq;
    2457                 :      453924 :         ira_allocate_and_set_costs (&ALLOCNO_HARD_REG_COSTS (a), rclass,
    2458                 :             :                                     ALLOCNO_CLASS_COST (a));
    2459                 :      453924 :         ira_allocate_and_set_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a),
    2460                 :             :                                     rclass, 0);
    2461                 :      453924 :         ALLOCNO_HARD_REG_COSTS (a)[i] -= cost;
    2462                 :      453924 :         ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[i] -= cost;
    2463                 :      453924 :         ALLOCNO_CLASS_COST (a) = MIN (ALLOCNO_CLASS_COST (a),
    2464                 :             :                                       ALLOCNO_HARD_REG_COSTS (a)[i]);
    2465                 :             :       }
    2466                 :             :     }
    2467                 :             : }
    2468                 :             : 
    2469                 :             : /* After we find hard register and memory costs for allocnos, define
    2470                 :             :    its class and modify hard register cost because insns moving
    2471                 :             :    allocno to/from hard registers.  */
    2472                 :             : static void
    2473                 :     1431622 : setup_allocno_class_and_costs (void)
    2474                 :             : {
    2475                 :     1431622 :   int i, j, n, regno, hard_regno, num;
    2476                 :     1431622 :   int *reg_costs;
    2477                 :     1431622 :   enum reg_class aclass, rclass;
    2478                 :     1431622 :   ira_allocno_t a;
    2479                 :     1431622 :   ira_allocno_iterator ai;
    2480                 :     1431622 :   cost_classes_t cost_classes_ptr;
    2481                 :             : 
    2482                 :     1431622 :   ira_assert (allocno_p);
    2483                 :    35052445 :   FOR_EACH_ALLOCNO (a, ai)
    2484                 :             :     {
    2485                 :    33620823 :       i = ALLOCNO_NUM (a);
    2486                 :    33620823 :       regno = ALLOCNO_REGNO (a);
    2487                 :    33620823 :       aclass = regno_aclass[regno];
    2488                 :    33620823 :       cost_classes_ptr = regno_cost_classes[regno];
    2489                 :    33620823 :       ira_assert (pref[i] == NO_REGS || aclass != NO_REGS);
    2490                 :    33620823 :       ALLOCNO_MEMORY_COST (a) = COSTS (costs, i)->mem_cost;
    2491                 :    33620823 :       ira_set_allocno_class (a, aclass);
    2492                 :    33620823 :       if (aclass == NO_REGS)
    2493                 :      621296 :         continue;
    2494                 :    32999527 :       if (optimize && ALLOCNO_CLASS (a) != pref[i])
    2495                 :             :         {
    2496                 :     5489045 :           n = ira_class_hard_regs_num[aclass];
    2497                 :     5489045 :           ALLOCNO_HARD_REG_COSTS (a)
    2498                 :     5489045 :             = reg_costs = ira_allocate_cost_vector (aclass);
    2499                 :    97755283 :           for (j = n - 1; j >= 0; j--)
    2500                 :             :             {
    2501                 :    92266238 :               hard_regno = ira_class_hard_regs[aclass][j];
    2502                 :    92266238 :               if (TEST_HARD_REG_BIT (reg_class_contents[pref[i]], hard_regno))
    2503                 :    14764756 :                 reg_costs[j] = ALLOCNO_CLASS_COST (a);
    2504                 :             :               else
    2505                 :             :                 {
    2506                 :    77501482 :                   rclass = REGNO_REG_CLASS (hard_regno);
    2507                 :    77501482 :                   num = cost_classes_ptr->index[rclass];
    2508                 :    77501482 :                   if (num < 0)
    2509                 :             :                     {
    2510                 :      275033 :                       num = cost_classes_ptr->hard_regno_index[hard_regno];
    2511                 :      275033 :                       ira_assert (num >= 0);
    2512                 :             :                     }
    2513                 :    77501482 :                   reg_costs[j] = COSTS (costs, i)->cost[num];
    2514                 :             :                 }
    2515                 :             :             }
    2516                 :             :         }
    2517                 :             :     }
    2518                 :     1431622 :   if (optimize)
    2519                 :     1003194 :     ira_traverse_loop_tree (true, ira_loop_tree_root,
    2520                 :             :                             process_bb_node_for_hard_reg_moves, NULL);
    2521                 :     1431622 : }
    2522                 :             : 
    2523                 :             : 
    2524                 :             : 
    2525                 :             : /* Function called once during compiler work.  */
    2526                 :             : void
    2527                 :      205984 : ira_init_costs_once (void)
    2528                 :             : {
    2529                 :      205984 :   int i;
    2530                 :             : 
    2531                 :      205984 :   init_cost = NULL;
    2532                 :     6385504 :   for (i = 0; i < MAX_RECOG_OPERANDS; i++)
    2533                 :             :     {
    2534                 :     6179520 :       op_costs[i] = NULL;
    2535                 :     6179520 :       this_op_costs[i] = NULL;
    2536                 :             :     }
    2537                 :      205984 :   temp_costs = NULL;
    2538                 :      205984 : }
    2539                 :             : 
    2540                 :             : /* Free allocated temporary cost vectors.  */
    2541                 :             : void
    2542                 :      807508 : target_ira_int::free_ira_costs ()
    2543                 :             : {
    2544                 :      807508 :   int i;
    2545                 :             : 
    2546                 :      807508 :   free (x_init_cost);
    2547                 :      807508 :   x_init_cost = NULL;
    2548                 :    25032748 :   for (i = 0; i < MAX_RECOG_OPERANDS; i++)
    2549                 :             :     {
    2550                 :    24225240 :       free (x_op_costs[i]);
    2551                 :    24225240 :       free (x_this_op_costs[i]);
    2552                 :    24225240 :       x_op_costs[i] = x_this_op_costs[i] = NULL;
    2553                 :             :     }
    2554                 :      807508 :   free (x_temp_costs);
    2555                 :      807508 :   x_temp_costs = NULL;
    2556                 :      807508 : }
    2557                 :             : 
    2558                 :             : /* This is called each time register related information is
    2559                 :             :    changed.  */
    2560                 :             : void
    2561                 :      211423 : ira_init_costs (void)
    2562                 :             : {
    2563                 :      211423 :   int i;
    2564                 :             : 
    2565                 :      211423 :   this_target_ira_int->free_ira_costs ();
    2566                 :      211423 :   max_struct_costs_size
    2567                 :      211423 :     = sizeof (struct costs) + sizeof (int) * (ira_important_classes_num - 1);
    2568                 :             :   /* Don't use ira_allocate because vectors live through several IRA
    2569                 :             :      calls.  */
    2570                 :      211423 :   init_cost = (struct costs *) xmalloc (max_struct_costs_size);
    2571                 :      211423 :   init_cost->mem_cost = 1000000;
    2572                 :     6768348 :   for (i = 0; i < ira_important_classes_num; i++)
    2573                 :     6556925 :     init_cost->cost[i] = 1000000;
    2574                 :     6554113 :   for (i = 0; i < MAX_RECOG_OPERANDS; i++)
    2575                 :             :     {
    2576                 :     6342690 :       op_costs[i] = (struct costs *) xmalloc (max_struct_costs_size);
    2577                 :     6342690 :       this_op_costs[i] = (struct costs *) xmalloc (max_struct_costs_size);
    2578                 :             :     }
    2579                 :      211423 :   temp_costs = (struct costs *) xmalloc (max_struct_costs_size);
    2580                 :      211423 : }
    2581                 :             : 
    2582                 :             : 
    2583                 :             : 
    2584                 :             : /* Common initialization function for ira_costs and
    2585                 :             :    ira_set_pseudo_classes.  */
    2586                 :             : static void
    2587                 :     1459843 : init_costs (void)
    2588                 :             : {
    2589                 :     1459843 :   init_subregs_of_mode ();
    2590                 :     2919686 :   costs = (struct costs *) ira_allocate (max_struct_costs_size
    2591                 :     1459843 :                                          * cost_elements_num);
    2592                 :     2919686 :   pref_buffer = (enum reg_class *) ira_allocate (sizeof (enum reg_class)
    2593                 :     1459843 :                                                  * cost_elements_num);
    2594                 :     4379529 :   regno_aclass = (enum reg_class *) ira_allocate (sizeof (enum reg_class)
    2595                 :     1459843 :                                                  * max_reg_num ());
    2596                 :     1459843 :   regno_equiv_gains = (int *) ira_allocate (sizeof (int) * max_reg_num ());
    2597                 :     1459843 :   memset (regno_equiv_gains, 0, sizeof (int) * max_reg_num ());
    2598                 :     1459843 : }
    2599                 :             : 
    2600                 :             : /* Common finalization function for ira_costs and
    2601                 :             :    ira_set_pseudo_classes.  */
    2602                 :             : static void
    2603                 :     1459843 : finish_costs (void)
    2604                 :             : {
    2605                 :     1459843 :   finish_subregs_of_mode ();
    2606                 :     1459843 :   ira_free (regno_equiv_gains);
    2607                 :     1459843 :   ira_free (regno_aclass);
    2608                 :     1459843 :   ira_free (pref_buffer);
    2609                 :     1459843 :   ira_free (costs);
    2610                 :     1459843 : }
    2611                 :             : 
    2612                 :             : /* Entry function which defines register class, memory and hard
    2613                 :             :    register costs for each allocno.  */
    2614                 :             : void
    2615                 :     1431622 : ira_costs (void)
    2616                 :             : {
    2617                 :     1431622 :   allocno_p = true;
    2618                 :     1431622 :   cost_elements_num = ira_allocnos_num;
    2619                 :     1431622 :   init_costs ();
    2620                 :     2863244 :   total_allocno_costs = (struct costs *) ira_allocate (max_struct_costs_size
    2621                 :     1431622 :                                                        * ira_allocnos_num);
    2622                 :     1431622 :   initiate_regno_cost_classes ();
    2623                 :     1431622 :   if (!ira_use_lra_p)
    2624                 :             :     /* Process equivs in reload to update costs through hook
    2625                 :             :        ira_adjust_equiv_reg_cost.  */
    2626                 :           0 :     calculate_elim_costs_all_insns ();
    2627                 :     1431622 :   find_costs_and_classes ();
    2628                 :     1431622 :   setup_allocno_class_and_costs ();
    2629                 :     1431622 :   finish_regno_cost_classes ();
    2630                 :     1431622 :   finish_costs ();
    2631                 :     1431622 :   ira_free (total_allocno_costs);
    2632                 :     1431622 : }
    2633                 :             : 
    2634                 :             : /* Entry function which defines classes for pseudos.
    2635                 :             :    Set pseudo_classes_defined_p only if DEFINE_PSEUDO_CLASSES is true.  */
    2636                 :             : void
    2637                 :       28221 : ira_set_pseudo_classes (bool define_pseudo_classes, FILE *dump_file)
    2638                 :             : {
    2639                 :       28221 :   FILE *saved_file = ira_dump_file;
    2640                 :       28221 :   allocno_p = false;
    2641                 :       28221 :   internal_flag_ira_verbose = flag_ira_verbose;
    2642                 :       28221 :   ira_dump_file = dump_file;
    2643                 :       28221 :   cost_elements_num = max_reg_num ();
    2644                 :       28221 :   init_costs ();
    2645                 :       28221 :   initiate_regno_cost_classes ();
    2646                 :       28221 :   find_costs_and_classes ();
    2647                 :       28221 :   finish_regno_cost_classes ();
    2648                 :       28221 :   if (define_pseudo_classes)
    2649                 :         116 :     pseudo_classes_defined_p = true;
    2650                 :             : 
    2651                 :       28221 :   finish_costs ();
    2652                 :       28221 :   ira_dump_file = saved_file;
    2653                 :       28221 : }
    2654                 :             : 
    2655                 :             : 
    2656                 :             : 
    2657                 :             : /* Change hard register costs for allocnos which lives through
    2658                 :             :    function calls.  This is called only when we found all intersected
    2659                 :             :    calls during building allocno live ranges.  */
    2660                 :             : void
    2661                 :     1431622 : ira_tune_allocno_costs (void)
    2662                 :             : {
    2663                 :     1431622 :   int j, n, regno;
    2664                 :     1431622 :   int cost, min_cost, *reg_costs;
    2665                 :     1431622 :   enum reg_class aclass;
    2666                 :     1431622 :   machine_mode mode;
    2667                 :     1431622 :   ira_allocno_t a;
    2668                 :     1431622 :   ira_allocno_iterator ai;
    2669                 :     1431622 :   ira_allocno_object_iterator oi;
    2670                 :     1431622 :   ira_object_t obj;
    2671                 :     1431622 :   bool skip_p;
    2672                 :             : 
    2673                 :    36497706 :   FOR_EACH_ALLOCNO (a, ai)
    2674                 :             :     {
    2675                 :    35066084 :       aclass = ALLOCNO_CLASS (a);
    2676                 :    35066084 :       if (aclass == NO_REGS)
    2677                 :      633506 :         continue;
    2678                 :    34432578 :       mode = ALLOCNO_MODE (a);
    2679                 :    34432578 :       n = ira_class_hard_regs_num[aclass];
    2680                 :    34432578 :       min_cost = INT_MAX;
    2681                 :    34432578 :       if (ALLOCNO_CALLS_CROSSED_NUM (a)
    2682                 :    34432578 :           != ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a))
    2683                 :             :         {
    2684                 :     3394111 :           ira_allocate_and_set_costs
    2685                 :     3394111 :             (&ALLOCNO_HARD_REG_COSTS (a), aclass,
    2686                 :             :              ALLOCNO_CLASS_COST (a));
    2687                 :     3394111 :           reg_costs = ALLOCNO_HARD_REG_COSTS (a);
    2688                 :    49065480 :           for (j = n - 1; j >= 0; j--)
    2689                 :             :             {
    2690                 :    45671369 :               regno = ira_class_hard_regs[aclass][j];
    2691                 :    45671369 :               skip_p = false;
    2692                 :    82004704 :               FOR_EACH_ALLOCNO_OBJECT (a, obj, oi)
    2693                 :             :                 {
    2694                 :    47062285 :                   if (ira_hard_reg_set_intersection_p (regno, mode,
    2695                 :             :                                                        OBJECT_CONFLICT_HARD_REGS
    2696                 :             :                                                        (obj)))
    2697                 :             :                     {
    2698                 :             :                       skip_p = true;
    2699                 :             :                       break;
    2700                 :             :                     }
    2701                 :             :                 }
    2702                 :    45671369 :               if (skip_p)
    2703                 :    10728950 :                 continue;
    2704                 :    34942419 :               cost = 0;
    2705                 :    34942419 :               if (ira_need_caller_save_p (a, regno))
    2706                 :    17809045 :                 cost += ira_caller_save_cost (a);
    2707                 :             : #ifdef IRA_HARD_REGNO_ADD_COST_MULTIPLIER
    2708                 :             :               {
    2709                 :             :                 auto rclass = REGNO_REG_CLASS (regno);
    2710                 :             :                 cost += ((ira_memory_move_cost[mode][rclass][0]
    2711                 :             :                           + ira_memory_move_cost[mode][rclass][1])
    2712                 :             :                          * ALLOCNO_FREQ (a)
    2713                 :             :                          * IRA_HARD_REGNO_ADD_COST_MULTIPLIER (regno) / 2);
    2714                 :             :               }
    2715                 :             : #endif
    2716                 :    34942419 :               if (INT_MAX - cost < reg_costs[j])
    2717                 :           0 :                 reg_costs[j] = INT_MAX;
    2718                 :             :               else
    2719                 :    34942419 :                 reg_costs[j] += cost;
    2720                 :    34942419 :               if (min_cost > reg_costs[j])
    2721                 :    45671369 :                 min_cost = reg_costs[j];
    2722                 :             :             }
    2723                 :             :         }
    2724                 :     3394111 :       if (min_cost != INT_MAX)
    2725                 :     3381770 :         ALLOCNO_CLASS_COST (a) = min_cost;
    2726                 :             : 
    2727                 :             :       /* Some targets allow pseudos to be allocated to unaligned sequences
    2728                 :             :          of hard registers.  However, selecting an unaligned sequence can
    2729                 :             :          unnecessarily restrict later allocations.  So increase the cost of
    2730                 :             :          unaligned hard regs to encourage the use of aligned hard regs.  */
    2731                 :    34432578 :       {
    2732                 :    34432578 :         const int nregs = ira_reg_class_max_nregs[aclass][ALLOCNO_MODE (a)];
    2733                 :             : 
    2734                 :    34432578 :         if (nregs > 1)
    2735                 :             :           {
    2736                 :     1293460 :             ira_allocate_and_set_costs
    2737                 :     1293460 :               (&ALLOCNO_HARD_REG_COSTS (a), aclass, ALLOCNO_CLASS_COST (a));
    2738                 :     1293460 :             reg_costs = ALLOCNO_HARD_REG_COSTS (a);
    2739                 :    28935045 :             for (j = n - 1; j >= 0; j--)
    2740                 :             :               {
    2741                 :    27641585 :                 regno = ira_non_ordered_class_hard_regs[aclass][j];
    2742                 :    27641585 :                 if ((regno % nregs) != 0)
    2743                 :             :                   {
    2744                 :    13585177 :                     int index = ira_class_hard_reg_index[aclass][regno];
    2745                 :    13585177 :                     ira_assert (index != -1);
    2746                 :    13585177 :                     reg_costs[index] += ALLOCNO_FREQ (a);
    2747                 :             :                   }
    2748                 :             :               }
    2749                 :             :           }
    2750                 :             :       }
    2751                 :             :     }
    2752                 :     1431622 : }
    2753                 :             : 
    2754                 :             : /* A hook from the reload pass.  Add COST to the estimated gain for eliminating
    2755                 :             :    REGNO with its equivalence.  If COST is zero, record that no such
    2756                 :             :    elimination is possible.  */
    2757                 :             : 
    2758                 :             : void
    2759                 :           0 : ira_adjust_equiv_reg_cost (unsigned regno, int cost)
    2760                 :             : {
    2761                 :           0 :   ira_assert (!ira_use_lra_p);
    2762                 :           0 :   if (cost == 0)
    2763                 :           0 :     regno_equiv_gains[regno] = 0;
    2764                 :             :   else
    2765                 :           0 :     regno_equiv_gains[regno] += cost;
    2766                 :           0 : }
    2767                 :             : 
    2768                 :             : void
    2769                 :      255021 : ira_costs_cc_finalize (void)
    2770                 :             : {
    2771                 :      255021 :   this_target_ira_int->free_ira_costs ();
    2772                 :      255021 : }
        

Generated by: LCOV version 2.1-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.