Home | History | Annotate | Line # | Download | only in gcc
ira-int.h revision 1.3
      1 /* Integrated Register Allocator (IRA) intercommunication header file.
      2    Copyright (C) 2006-2013 Free Software Foundation, Inc.
      3    Contributed by Vladimir Makarov <vmakarov (at) 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 "cfgloop.h"
     22 #include "ira.h"
     23 #include "alloc-pool.h"
     24 
     25 /* To provide consistency in naming, all IRA external variables,
     26    functions, common typedefs start with prefix ira_.  */
     27 
     28 #ifdef ENABLE_CHECKING
     29 #define ENABLE_IRA_CHECKING
     30 #endif
     31 
     32 #ifdef ENABLE_IRA_CHECKING
     33 #define ira_assert(c) gcc_assert (c)
     34 #else
     35 /* Always define and include C, so that warnings for empty body in an
     36   if statement and unused variable do not occur.  */
     37 #define ira_assert(c) ((void)(0 && (c)))
     38 #endif
     39 
     40 /* Compute register frequency from edge frequency FREQ.  It is
     41    analogous to REG_FREQ_FROM_BB.  When optimizing for size, or
     42    profile driven feedback is available and the function is never
     43    executed, frequency is always equivalent.  Otherwise rescale the
     44    edge frequency.  */
     45 #define REG_FREQ_FROM_EDGE_FREQ(freq)					   \
     46   (optimize_size || (flag_branch_probabilities && !ENTRY_BLOCK_PTR->count) \
     47    ? REG_FREQ_MAX : (freq * REG_FREQ_MAX / BB_FREQ_MAX)			   \
     48    ? (freq * REG_FREQ_MAX / BB_FREQ_MAX) : 1)
     49 
     50 /* A modified value of flag `-fira-verbose' used internally.  */
     51 extern int internal_flag_ira_verbose;
     52 
     53 /* Dump file of the allocator if it is not NULL.  */
     54 extern FILE *ira_dump_file;
     55 
     56 /* Typedefs for pointers to allocno live range, allocno, and copy of
     57    allocnos.  */
     58 typedef struct live_range *live_range_t;
     59 typedef struct ira_allocno *ira_allocno_t;
     60 typedef struct ira_allocno_copy *ira_copy_t;
     61 typedef struct ira_object *ira_object_t;
     62 
     63 /* Definition of vector of allocnos and copies.  */
     64 
     65 /* Typedef for pointer to the subsequent structure.  */
     66 typedef struct ira_loop_tree_node *ira_loop_tree_node_t;
     67 
     68 typedef unsigned short move_table[N_REG_CLASSES];
     69 
     70 /* In general case, IRA is a regional allocator.  The regions are
     71    nested and form a tree.  Currently regions are natural loops.  The
     72    following structure describes loop tree node (representing basic
     73    block or loop).  We need such tree because the loop tree from
     74    cfgloop.h is not convenient for the optimization: basic blocks are
     75    not a part of the tree from cfgloop.h.  We also use the nodes for
     76    storing additional information about basic blocks/loops for the
     77    register allocation purposes.  */
     78 struct ira_loop_tree_node
     79 {
     80   /* The node represents basic block if children == NULL.  */
     81   basic_block bb;    /* NULL for loop.  */
     82   /* NULL for BB or for loop tree root if we did not build CFG loop tree.  */
     83   struct loop *loop;
     84   /* NEXT/SUBLOOP_NEXT is the next node/loop-node of the same parent.
     85      SUBLOOP_NEXT is always NULL for BBs.  */
     86   ira_loop_tree_node_t subloop_next, next;
     87   /* CHILDREN/SUBLOOPS is the first node/loop-node immediately inside
     88      the node.  They are NULL for BBs.  */
     89   ira_loop_tree_node_t subloops, children;
     90   /* The node immediately containing given node.  */
     91   ira_loop_tree_node_t parent;
     92 
     93   /* Loop level in range [0, ira_loop_tree_height).  */
     94   int level;
     95 
     96   /* All the following members are defined only for nodes representing
     97      loops.  */
     98 
     99   /* The loop number from CFG loop tree.  The root number is 0.  */
    100   int loop_num;
    101 
    102   /* True if the loop was marked for removal from the register
    103      allocation.  */
    104   bool to_remove_p;
    105 
    106   /* Allocnos in the loop corresponding to their regnos.  If it is
    107      NULL the loop does not form a separate register allocation region
    108      (e.g. because it has abnormal enter/exit edges and we can not put
    109      code for register shuffling on the edges if a different
    110      allocation is used for a pseudo-register on different sides of
    111      the edges).  Caps are not in the map (remember we can have more
    112      one cap with the same regno in a region).  */
    113   ira_allocno_t *regno_allocno_map;
    114 
    115   /* True if there is an entry to given loop not from its parent (or
    116      grandparent) basic block.  For example, it is possible for two
    117      adjacent loops inside another loop.  */
    118   bool entered_from_non_parent_p;
    119 
    120   /* Maximal register pressure inside loop for given register class
    121      (defined only for the pressure classes).  */
    122   int reg_pressure[N_REG_CLASSES];
    123 
    124   /* Numbers of allocnos referred or living in the loop node (except
    125      for its subloops).  */
    126   bitmap all_allocnos;
    127 
    128   /* Numbers of allocnos living at the loop borders.  */
    129   bitmap border_allocnos;
    130 
    131   /* Regnos of pseudos modified in the loop node (including its
    132      subloops).  */
    133   bitmap modified_regnos;
    134 
    135   /* Numbers of copies referred in the corresponding loop.  */
    136   bitmap local_copies;
    137 };
    138 
    139 /* The root of the loop tree corresponding to the all function.  */
    140 extern ira_loop_tree_node_t ira_loop_tree_root;
    141 
    142 /* Height of the loop tree.  */
    143 extern int ira_loop_tree_height;
    144 
    145 /* All nodes representing basic blocks are referred through the
    146    following array.  We can not use basic block member `aux' for this
    147    because it is used for insertion of insns on edges.  */
    148 extern ira_loop_tree_node_t ira_bb_nodes;
    149 
    150 /* Two access macros to the nodes representing basic blocks.  */
    151 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
    152 #define IRA_BB_NODE_BY_INDEX(index) __extension__			\
    153 (({ ira_loop_tree_node_t _node = (&ira_bb_nodes[index]);		\
    154      if (_node->children != NULL || _node->loop != NULL || _node->bb == NULL)\
    155        {								\
    156          fprintf (stderr,						\
    157                   "\n%s: %d: error in %s: it is not a block node\n",	\
    158                   __FILE__, __LINE__, __FUNCTION__);			\
    159          gcc_unreachable ();						\
    160        }								\
    161      _node; }))
    162 #else
    163 #define IRA_BB_NODE_BY_INDEX(index) (&ira_bb_nodes[index])
    164 #endif
    165 
    166 #define IRA_BB_NODE(bb) IRA_BB_NODE_BY_INDEX ((bb)->index)
    167 
    168 /* All nodes representing loops are referred through the following
    169    array.  */
    170 extern ira_loop_tree_node_t ira_loop_nodes;
    171 
    172 /* Two access macros to the nodes representing loops.  */
    173 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
    174 #define IRA_LOOP_NODE_BY_INDEX(index) __extension__			\
    175 (({ ira_loop_tree_node_t const _node = (&ira_loop_nodes[index]);	\
    176      if (_node->children == NULL || _node->bb != NULL			\
    177          || (_node->loop == NULL && current_loops != NULL))		\
    178        {								\
    179          fprintf (stderr,						\
    180                   "\n%s: %d: error in %s: it is not a loop node\n",	\
    181                   __FILE__, __LINE__, __FUNCTION__);			\
    182          gcc_unreachable ();						\
    183        }								\
    184      _node; }))
    185 #else
    186 #define IRA_LOOP_NODE_BY_INDEX(index) (&ira_loop_nodes[index])
    187 #endif
    188 
    189 #define IRA_LOOP_NODE(loop) IRA_LOOP_NODE_BY_INDEX ((loop)->num)
    190 
    191 
    192 /* The structure describes program points where a given allocno lives.
    194    If the live ranges of two allocnos are intersected, the allocnos
    195    are in conflict.  */
    196 struct live_range
    197 {
    198   /* Object whose live range is described by given structure.  */
    199   ira_object_t object;
    200   /* Program point range.  */
    201   int start, finish;
    202   /* Next structure describing program points where the allocno
    203      lives.  */
    204   live_range_t next;
    205   /* Pointer to structures with the same start/finish.  */
    206   live_range_t start_next, finish_next;
    207 };
    208 
    209 /* Program points are enumerated by numbers from range
    210    0..IRA_MAX_POINT-1.  There are approximately two times more program
    211    points than insns.  Program points are places in the program where
    212    liveness info can be changed.  In most general case (there are more
    213    complicated cases too) some program points correspond to places
    214    where input operand dies and other ones correspond to places where
    215    output operands are born.  */
    216 extern int ira_max_point;
    217 
    218 /* Arrays of size IRA_MAX_POINT mapping a program point to the allocno
    219    live ranges with given start/finish point.  */
    220 extern live_range_t *ira_start_point_ranges, *ira_finish_point_ranges;
    221 
    222 /* A structure representing conflict information for an allocno
    223    (or one of its subwords).  */
    224 struct ira_object
    225 {
    226   /* The allocno associated with this record.  */
    227   ira_allocno_t allocno;
    228   /* Vector of accumulated conflicting conflict_redords with NULL end
    229      marker (if OBJECT_CONFLICT_VEC_P is true) or conflict bit vector
    230      otherwise.  */
    231   void *conflicts_array;
    232   /* Pointer to structures describing at what program point the
    233      object lives.  We always maintain the list in such way that *the
    234      ranges in the list are not intersected and ordered by decreasing
    235      their program points*.  */
    236   live_range_t live_ranges;
    237   /* The subword within ALLOCNO which is represented by this object.
    238      Zero means the lowest-order subword (or the entire allocno in case
    239      it is not being tracked in subwords).  */
    240   int subword;
    241   /* Allocated size of the conflicts array.  */
    242   unsigned int conflicts_array_size;
    243   /* A unique number for every instance of this structure, which is used
    244      to represent it in conflict bit vectors.  */
    245   int id;
    246   /* Before building conflicts, MIN and MAX are initialized to
    247      correspondingly minimal and maximal points of the accumulated
    248      live ranges.  Afterwards, they hold the minimal and maximal ids
    249      of other ira_objects that this one can conflict with.  */
    250   int min, max;
    251   /* Initial and accumulated hard registers conflicting with this
    252      object and as a consequences can not be assigned to the allocno.
    253      All non-allocatable hard regs and hard regs of register classes
    254      different from given allocno one are included in the sets.  */
    255   HARD_REG_SET conflict_hard_regs, total_conflict_hard_regs;
    256   /* Number of accumulated conflicts in the vector of conflicting
    257      objects.  */
    258   int num_accumulated_conflicts;
    259   /* TRUE if conflicts are represented by a vector of pointers to
    260      ira_object structures.  Otherwise, we use a bit vector indexed
    261      by conflict ID numbers.  */
    262   unsigned int conflict_vec_p : 1;
    263 };
    264 
    265 /* A structure representing an allocno (allocation entity).  Allocno
    266    represents a pseudo-register in an allocation region.  If
    267    pseudo-register does not live in a region but it lives in the
    268    nested regions, it is represented in the region by special allocno
    269    called *cap*.  There may be more one cap representing the same
    270    pseudo-register in region.  It means that the corresponding
    271    pseudo-register lives in more one non-intersected subregion.  */
    272 struct ira_allocno
    273 {
    274   /* The allocno order number starting with 0.  Each allocno has an
    275      unique number and the number is never changed for the
    276      allocno.  */
    277   int num;
    278   /* Regno for allocno or cap.  */
    279   int regno;
    280   /* Mode of the allocno which is the mode of the corresponding
    281      pseudo-register.  */
    282   ENUM_BITFIELD (machine_mode) mode : 8;
    283   /* Register class which should be used for allocation for given
    284      allocno.  NO_REGS means that we should use memory.  */
    285   ENUM_BITFIELD (reg_class) aclass : 16;
    286   /* During the reload, value TRUE means that we should not reassign a
    287      hard register to the allocno got memory earlier.  It is set up
    288      when we removed memory-memory move insn before each iteration of
    289      the reload.  */
    290   unsigned int dont_reassign_p : 1;
    291 #ifdef STACK_REGS
    292   /* Set to TRUE if allocno can't be assigned to the stack hard
    293      register correspondingly in this region and area including the
    294      region and all its subregions recursively.  */
    295   unsigned int no_stack_reg_p : 1, total_no_stack_reg_p : 1;
    296 #endif
    297   /* TRUE value means that there is no sense to spill the allocno
    298      during coloring because the spill will result in additional
    299      reloads in reload pass.  */
    300   unsigned int bad_spill_p : 1;
    301   /* TRUE if a hard register or memory has been assigned to the
    302      allocno.  */
    303   unsigned int assigned_p : 1;
    304   /* TRUE if conflicts for given allocno are represented by vector of
    305      pointers to the conflicting allocnos.  Otherwise, we use a bit
    306      vector where a bit with given index represents allocno with the
    307      same number.  */
    308   unsigned int conflict_vec_p : 1;
    309   /* Hard register assigned to given allocno.  Negative value means
    310      that memory was allocated to the allocno.  During the reload,
    311      spilled allocno has value equal to the corresponding stack slot
    312      number (0, ...) - 2.  Value -1 is used for allocnos spilled by the
    313      reload (at this point pseudo-register has only one allocno) which
    314      did not get stack slot yet.  */
    315   short int hard_regno;
    316   /* Allocnos with the same regno are linked by the following member.
    317      Allocnos corresponding to inner loops are first in the list (it
    318      corresponds to depth-first traverse of the loops).  */
    319   ira_allocno_t next_regno_allocno;
    320   /* There may be different allocnos with the same regno in different
    321      regions.  Allocnos are bound to the corresponding loop tree node.
    322      Pseudo-register may have only one regular allocno with given loop
    323      tree node but more than one cap (see comments above).  */
    324   ira_loop_tree_node_t loop_tree_node;
    325   /* Accumulated usage references of the allocno.  Here and below,
    326      word 'accumulated' means info for given region and all nested
    327      subregions.  In this case, 'accumulated' means sum of references
    328      of the corresponding pseudo-register in this region and in all
    329      nested subregions recursively. */
    330   int nrefs;
    331   /* Accumulated frequency of usage of the allocno.  */
    332   int freq;
    333   /* Minimal accumulated and updated costs of usage register of the
    334      allocno class.  */
    335   int class_cost, updated_class_cost;
    336   /* Minimal accumulated, and updated costs of memory for the allocno.
    337      At the allocation start, the original and updated costs are
    338      equal.  The updated cost may be changed after finishing
    339      allocation in a region and starting allocation in a subregion.
    340      The change reflects the cost of spill/restore code on the
    341      subregion border if we assign memory to the pseudo in the
    342      subregion.  */
    343   int memory_cost, updated_memory_cost;
    344   /* Accumulated number of points where the allocno lives and there is
    345      excess pressure for its class.  Excess pressure for a register
    346      class at some point means that there are more allocnos of given
    347      register class living at the point than number of hard-registers
    348      of the class available for the allocation.  */
    349   int excess_pressure_points_num;
    350   /* Copies to other non-conflicting allocnos.  The copies can
    351      represent move insn or potential move insn usually because of two
    352      operand insn constraints.  */
    353   ira_copy_t allocno_copies;
    354   /* It is a allocno (cap) representing given allocno on upper loop tree
    355      level.  */
    356   ira_allocno_t cap;
    357   /* It is a link to allocno (cap) on lower loop level represented by
    358      given cap.  Null if given allocno is not a cap.  */
    359   ira_allocno_t cap_member;
    360   /* The number of objects tracked in the following array.  */
    361   int num_objects;
    362   /* An array of structures describing conflict information and live
    363      ranges for each object associated with the allocno.  There may be
    364      more than one such object in cases where the allocno represents a
    365      multi-word register.  */
    366   ira_object_t objects[2];
    367   /* Accumulated frequency of calls which given allocno
    368      intersects.  */
    369   int call_freq;
    370   /* Accumulated number of the intersected calls.  */
    371   int calls_crossed_num;
    372   /* The number of calls across which it is live, but which should not
    373      affect register preferences.  */
    374   int cheap_calls_crossed_num;
    375   /* Array of usage costs (accumulated and the one updated during
    376      coloring) for each hard register of the allocno class.  The
    377      member value can be NULL if all costs are the same and equal to
    378      CLASS_COST.  For example, the costs of two different hard
    379      registers can be different if one hard register is callee-saved
    380      and another one is callee-used and the allocno lives through
    381      calls.  Another example can be case when for some insn the
    382      corresponding pseudo-register value should be put in specific
    383      register class (e.g. AREG for x86) which is a strict subset of
    384      the allocno class (GENERAL_REGS for x86).  We have updated costs
    385      to reflect the situation when the usage cost of a hard register
    386      is decreased because the allocno is connected to another allocno
    387      by a copy and the another allocno has been assigned to the hard
    388      register.  */
    389   int *hard_reg_costs, *updated_hard_reg_costs;
    390   /* Array of decreasing costs (accumulated and the one updated during
    391      coloring) for allocnos conflicting with given allocno for hard
    392      regno of the allocno class.  The member value can be NULL if all
    393      costs are the same.  These costs are used to reflect preferences
    394      of other allocnos not assigned yet during assigning to given
    395      allocno.  */
    396   int *conflict_hard_reg_costs, *updated_conflict_hard_reg_costs;
    397   /* Different additional data.  It is used to decrease size of
    398      allocno data footprint.  */
    399   void *add_data;
    400 };
    401 
    402 
    403 /* All members of the allocno structures should be accessed only
    404    through the following macros.  */
    405 #define ALLOCNO_NUM(A) ((A)->num)
    406 #define ALLOCNO_REGNO(A) ((A)->regno)
    407 #define ALLOCNO_REG(A) ((A)->reg)
    408 #define ALLOCNO_NEXT_REGNO_ALLOCNO(A) ((A)->next_regno_allocno)
    409 #define ALLOCNO_LOOP_TREE_NODE(A) ((A)->loop_tree_node)
    410 #define ALLOCNO_CAP(A) ((A)->cap)
    411 #define ALLOCNO_CAP_MEMBER(A) ((A)->cap_member)
    412 #define ALLOCNO_NREFS(A) ((A)->nrefs)
    413 #define ALLOCNO_FREQ(A) ((A)->freq)
    414 #define ALLOCNO_HARD_REGNO(A) ((A)->hard_regno)
    415 #define ALLOCNO_CALL_FREQ(A) ((A)->call_freq)
    416 #define ALLOCNO_CALLS_CROSSED_NUM(A) ((A)->calls_crossed_num)
    417 #define ALLOCNO_CHEAP_CALLS_CROSSED_NUM(A) ((A)->cheap_calls_crossed_num)
    418 #define ALLOCNO_MEM_OPTIMIZED_DEST(A) ((A)->mem_optimized_dest)
    419 #define ALLOCNO_MEM_OPTIMIZED_DEST_P(A) ((A)->mem_optimized_dest_p)
    420 #define ALLOCNO_SOMEWHERE_RENAMED_P(A) ((A)->somewhere_renamed_p)
    421 #define ALLOCNO_CHILD_RENAMED_P(A) ((A)->child_renamed_p)
    422 #define ALLOCNO_DONT_REASSIGN_P(A) ((A)->dont_reassign_p)
    423 #ifdef STACK_REGS
    424 #define ALLOCNO_NO_STACK_REG_P(A) ((A)->no_stack_reg_p)
    425 #define ALLOCNO_TOTAL_NO_STACK_REG_P(A) ((A)->total_no_stack_reg_p)
    426 #endif
    427 #define ALLOCNO_BAD_SPILL_P(A) ((A)->bad_spill_p)
    428 #define ALLOCNO_ASSIGNED_P(A) ((A)->assigned_p)
    429 #define ALLOCNO_MODE(A) ((A)->mode)
    430 #define ALLOCNO_COPIES(A) ((A)->allocno_copies)
    431 #define ALLOCNO_HARD_REG_COSTS(A) ((A)->hard_reg_costs)
    432 #define ALLOCNO_UPDATED_HARD_REG_COSTS(A) ((A)->updated_hard_reg_costs)
    433 #define ALLOCNO_CONFLICT_HARD_REG_COSTS(A) \
    434   ((A)->conflict_hard_reg_costs)
    435 #define ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS(A) \
    436   ((A)->updated_conflict_hard_reg_costs)
    437 #define ALLOCNO_CLASS(A) ((A)->aclass)
    438 #define ALLOCNO_CLASS_COST(A) ((A)->class_cost)
    439 #define ALLOCNO_UPDATED_CLASS_COST(A) ((A)->updated_class_cost)
    440 #define ALLOCNO_MEMORY_COST(A) ((A)->memory_cost)
    441 #define ALLOCNO_UPDATED_MEMORY_COST(A) ((A)->updated_memory_cost)
    442 #define ALLOCNO_EXCESS_PRESSURE_POINTS_NUM(A) \
    443   ((A)->excess_pressure_points_num)
    444 #define ALLOCNO_OBJECT(A,N) ((A)->objects[N])
    445 #define ALLOCNO_NUM_OBJECTS(A) ((A)->num_objects)
    446 #define ALLOCNO_ADD_DATA(A) ((A)->add_data)
    447 
    448 /* Typedef for pointer to the subsequent structure.  */
    449 typedef struct ira_emit_data *ira_emit_data_t;
    450 
    451 /* Allocno bound data used for emit pseudo live range split insns and
    452    to flattening IR.  */
    453 struct ira_emit_data
    454 {
    455   /* TRUE if the allocno assigned to memory was a destination of
    456      removed move (see ira-emit.c) at loop exit because the value of
    457      the corresponding pseudo-register is not changed inside the
    458      loop.  */
    459   unsigned int mem_optimized_dest_p : 1;
    460   /* TRUE if the corresponding pseudo-register has disjoint live
    461      ranges and the other allocnos of the pseudo-register except this
    462      one changed REG.  */
    463   unsigned int somewhere_renamed_p : 1;
    464   /* TRUE if allocno with the same REGNO in a subregion has been
    465      renamed, in other words, got a new pseudo-register.  */
    466   unsigned int child_renamed_p : 1;
    467   /* Final rtx representation of the allocno.  */
    468   rtx reg;
    469   /* Non NULL if we remove restoring value from given allocno to
    470      MEM_OPTIMIZED_DEST at loop exit (see ira-emit.c) because the
    471      allocno value is not changed inside the loop.  */
    472   ira_allocno_t mem_optimized_dest;
    473 };
    474 
    475 #define ALLOCNO_EMIT_DATA(a) ((ira_emit_data_t) ALLOCNO_ADD_DATA (a))
    476 
    477 /* Data used to emit live range split insns and to flattening IR.  */
    478 extern ira_emit_data_t ira_allocno_emit_data;
    479 
    480 /* Abbreviation for frequent emit data access.  */
    481 static inline rtx
    482 allocno_emit_reg (ira_allocno_t a)
    483 {
    484   return ALLOCNO_EMIT_DATA (a)->reg;
    485 }
    486 
    487 #define OBJECT_ALLOCNO(O) ((O)->allocno)
    488 #define OBJECT_SUBWORD(O) ((O)->subword)
    489 #define OBJECT_CONFLICT_ARRAY(O) ((O)->conflicts_array)
    490 #define OBJECT_CONFLICT_VEC(O) ((ira_object_t *)(O)->conflicts_array)
    491 #define OBJECT_CONFLICT_BITVEC(O) ((IRA_INT_TYPE *)(O)->conflicts_array)
    492 #define OBJECT_CONFLICT_ARRAY_SIZE(O) ((O)->conflicts_array_size)
    493 #define OBJECT_CONFLICT_VEC_P(O) ((O)->conflict_vec_p)
    494 #define OBJECT_NUM_CONFLICTS(O) ((O)->num_accumulated_conflicts)
    495 #define OBJECT_CONFLICT_HARD_REGS(O) ((O)->conflict_hard_regs)
    496 #define OBJECT_TOTAL_CONFLICT_HARD_REGS(O) ((O)->total_conflict_hard_regs)
    497 #define OBJECT_MIN(O) ((O)->min)
    498 #define OBJECT_MAX(O) ((O)->max)
    499 #define OBJECT_CONFLICT_ID(O) ((O)->id)
    500 #define OBJECT_LIVE_RANGES(O) ((O)->live_ranges)
    501 
    502 /* Map regno -> allocnos with given regno (see comments for
    503    allocno member `next_regno_allocno').  */
    504 extern ira_allocno_t *ira_regno_allocno_map;
    505 
    506 /* Array of references to all allocnos.  The order number of the
    507    allocno corresponds to the index in the array.  Removed allocnos
    508    have NULL element value.  */
    509 extern ira_allocno_t *ira_allocnos;
    510 
    511 /* The size of the previous array.  */
    512 extern int ira_allocnos_num;
    513 
    514 /* Map a conflict id to its corresponding ira_object structure.  */
    515 extern ira_object_t *ira_object_id_map;
    516 
    517 /* The size of the previous array.  */
    518 extern int ira_objects_num;
    519 
    520 /* The following structure represents a copy of two allocnos.  The
    521    copies represent move insns or potential move insns usually because
    522    of two operand insn constraints.  To remove register shuffle, we
    523    also create copies between allocno which is output of an insn and
    524    allocno becoming dead in the insn.  */
    525 struct ira_allocno_copy
    526 {
    527   /* The unique order number of the copy node starting with 0.  */
    528   int num;
    529   /* Allocnos connected by the copy.  The first allocno should have
    530      smaller order number than the second one.  */
    531   ira_allocno_t first, second;
    532   /* Execution frequency of the copy.  */
    533   int freq;
    534   bool constraint_p;
    535   /* It is a move insn which is an origin of the copy.  The member
    536      value for the copy representing two operand insn constraints or
    537      for the copy created to remove register shuffle is NULL.  In last
    538      case the copy frequency is smaller than the corresponding insn
    539      execution frequency.  */
    540   rtx insn;
    541   /* All copies with the same allocno as FIRST are linked by the two
    542      following members.  */
    543   ira_copy_t prev_first_allocno_copy, next_first_allocno_copy;
    544   /* All copies with the same allocno as SECOND are linked by the two
    545      following members.  */
    546   ira_copy_t prev_second_allocno_copy, next_second_allocno_copy;
    547   /* Region from which given copy is originated.  */
    548   ira_loop_tree_node_t loop_tree_node;
    549 };
    550 
    551 /* Array of references to all copies.  The order number of the copy
    552    corresponds to the index in the array.  Removed copies have NULL
    553    element value.  */
    554 extern ira_copy_t *ira_copies;
    555 
    556 /* Size of the previous array.  */
    557 extern int ira_copies_num;
    558 
    559 /* The following structure describes a stack slot used for spilled
    560    pseudo-registers.  */
    561 struct ira_spilled_reg_stack_slot
    562 {
    563   /* pseudo-registers assigned to the stack slot.  */
    564   bitmap_head spilled_regs;
    565   /* RTL representation of the stack slot.  */
    566   rtx mem;
    567   /* Size of the stack slot.  */
    568   unsigned int width;
    569 };
    570 
    571 /* The number of elements in the following array.  */
    572 extern int ira_spilled_reg_stack_slots_num;
    573 
    574 /* The following array contains info about spilled pseudo-registers
    575    stack slots used in current function so far.  */
    576 extern struct ira_spilled_reg_stack_slot *ira_spilled_reg_stack_slots;
    577 
    578 /* Correspondingly overall cost of the allocation, cost of the
    579    allocnos assigned to hard-registers, cost of the allocnos assigned
    580    to memory, cost of loads, stores and register move insns generated
    581    for pseudo-register live range splitting (see ira-emit.c).  */
    582 extern int ira_overall_cost;
    583 extern int ira_reg_cost, ira_mem_cost;
    584 extern int ira_load_cost, ira_store_cost, ira_shuffle_cost;
    585 extern int ira_move_loops_num, ira_additional_jumps_num;
    586 
    587 
    588 /* This page contains a bitset implementation called 'min/max sets' used to
    590    record conflicts in IRA.
    591    They are named min/maxs set since we keep track of a minimum and a maximum
    592    bit number for each set representing the bounds of valid elements.  Otherwise,
    593    the implementation resembles sbitmaps in that we store an array of integers
    594    whose bits directly represent the members of the set.  */
    595 
    596 /* The type used as elements in the array, and the number of bits in
    597    this type.  */
    598 
    599 #define IRA_INT_BITS HOST_BITS_PER_WIDE_INT
    600 #define IRA_INT_TYPE HOST_WIDE_INT
    601 
    602 /* Set, clear or test bit number I in R, a bit vector of elements with
    603    minimal index and maximal index equal correspondingly to MIN and
    604    MAX.  */
    605 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
    606 
    607 #define SET_MINMAX_SET_BIT(R, I, MIN, MAX) __extension__	        \
    608   (({ int _min = (MIN), _max = (MAX), _i = (I);				\
    609      if (_i < _min || _i > _max)					\
    610        {								\
    611          fprintf (stderr,						\
    612                   "\n%s: %d: error in %s: %d not in range [%d,%d]\n",   \
    613                   __FILE__, __LINE__, __FUNCTION__, _i, _min, _max);	\
    614          gcc_unreachable ();						\
    615        }								\
    616      ((R)[(unsigned) (_i - _min) / IRA_INT_BITS]			\
    617       |= ((IRA_INT_TYPE) 1 << ((unsigned) (_i - _min) % IRA_INT_BITS))); }))
    618 
    619 
    620 #define CLEAR_MINMAX_SET_BIT(R, I, MIN, MAX) __extension__	        \
    621   (({ int _min = (MIN), _max = (MAX), _i = (I);				\
    622      if (_i < _min || _i > _max)					\
    623        {								\
    624          fprintf (stderr,						\
    625                   "\n%s: %d: error in %s: %d not in range [%d,%d]\n",   \
    626                   __FILE__, __LINE__, __FUNCTION__, _i, _min, _max);	\
    627          gcc_unreachable ();						\
    628        }								\
    629      ((R)[(unsigned) (_i - _min) / IRA_INT_BITS]			\
    630       &= ~((IRA_INT_TYPE) 1 << ((unsigned) (_i - _min) % IRA_INT_BITS))); }))
    631 
    632 #define TEST_MINMAX_SET_BIT(R, I, MIN, MAX) __extension__	        \
    633   (({ int _min = (MIN), _max = (MAX), _i = (I);				\
    634      if (_i < _min || _i > _max)					\
    635        {								\
    636          fprintf (stderr,						\
    637                   "\n%s: %d: error in %s: %d not in range [%d,%d]\n",   \
    638                   __FILE__, __LINE__, __FUNCTION__, _i, _min, _max);	\
    639          gcc_unreachable ();						\
    640        }								\
    641      ((R)[(unsigned) (_i - _min) / IRA_INT_BITS]			\
    642       & ((IRA_INT_TYPE) 1 << ((unsigned) (_i - _min) % IRA_INT_BITS))); }))
    643 
    644 #else
    645 
    646 #define SET_MINMAX_SET_BIT(R, I, MIN, MAX)			\
    647   ((R)[(unsigned) ((I) - (MIN)) / IRA_INT_BITS]			\
    648    |= ((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
    649 
    650 #define CLEAR_MINMAX_SET_BIT(R, I, MIN, MAX)			\
    651   ((R)[(unsigned) ((I) - (MIN)) / IRA_INT_BITS]			\
    652    &= ~((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
    653 
    654 #define TEST_MINMAX_SET_BIT(R, I, MIN, MAX)			\
    655   ((R)[(unsigned) ((I) - (MIN)) / IRA_INT_BITS]			\
    656    & ((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
    657 
    658 #endif
    659 
    660 /* The iterator for min/max sets.  */
    661 typedef struct {
    662 
    663   /* Array containing the bit vector.  */
    664   IRA_INT_TYPE *vec;
    665 
    666   /* The number of the current element in the vector.  */
    667   unsigned int word_num;
    668 
    669   /* The number of bits in the bit vector.  */
    670   unsigned int nel;
    671 
    672   /* The current bit index of the bit vector.  */
    673   unsigned int bit_num;
    674 
    675   /* Index corresponding to the 1st bit of the bit vector.   */
    676   int start_val;
    677 
    678   /* The word of the bit vector currently visited.  */
    679   unsigned IRA_INT_TYPE word;
    680 } minmax_set_iterator;
    681 
    682 /* Initialize the iterator I for bit vector VEC containing minimal and
    683    maximal values MIN and MAX.  */
    684 static inline void
    685 minmax_set_iter_init (minmax_set_iterator *i, IRA_INT_TYPE *vec, int min,
    686 		      int max)
    687 {
    688   i->vec = vec;
    689   i->word_num = 0;
    690   i->nel = max < min ? 0 : max - min + 1;
    691   i->start_val = min;
    692   i->bit_num = 0;
    693   i->word = i->nel == 0 ? 0 : vec[0];
    694 }
    695 
    696 /* Return TRUE if we have more allocnos to visit, in which case *N is
    697    set to the number of the element to be visited.  Otherwise, return
    698    FALSE.  */
    699 static inline bool
    700 minmax_set_iter_cond (minmax_set_iterator *i, int *n)
    701 {
    702   /* Skip words that are zeros.  */
    703   for (; i->word == 0; i->word = i->vec[i->word_num])
    704     {
    705       i->word_num++;
    706       i->bit_num = i->word_num * IRA_INT_BITS;
    707 
    708       /* If we have reached the end, break.  */
    709       if (i->bit_num >= i->nel)
    710 	return false;
    711     }
    712 
    713   /* Skip bits that are zero.  */
    714   for (; (i->word & 1) == 0; i->word >>= 1)
    715     i->bit_num++;
    716 
    717   *n = (int) i->bit_num + i->start_val;
    718 
    719   return true;
    720 }
    721 
    722 /* Advance to the next element in the set.  */
    723 static inline void
    724 minmax_set_iter_next (minmax_set_iterator *i)
    725 {
    726   i->word >>= 1;
    727   i->bit_num++;
    728 }
    729 
    730 /* Loop over all elements of a min/max set given by bit vector VEC and
    731    their minimal and maximal values MIN and MAX.  In each iteration, N
    732    is set to the number of next allocno.  ITER is an instance of
    733    minmax_set_iterator used to iterate over the set.  */
    734 #define FOR_EACH_BIT_IN_MINMAX_SET(VEC, MIN, MAX, N, ITER)	\
    735   for (minmax_set_iter_init (&(ITER), (VEC), (MIN), (MAX));	\
    736        minmax_set_iter_cond (&(ITER), &(N));			\
    737        minmax_set_iter_next (&(ITER)))
    738 
    739 struct target_ira_int {
    741   /* Initialized once.  It is a maximal possible size of the allocated
    742      struct costs.  */
    743   int x_max_struct_costs_size;
    744 
    745   /* Allocated and initialized once, and used to initialize cost values
    746      for each insn.  */
    747   struct costs *x_init_cost;
    748 
    749   /* Allocated once, and used for temporary purposes.  */
    750   struct costs *x_temp_costs;
    751 
    752   /* Allocated once, and used for the cost calculation.  */
    753   struct costs *x_op_costs[MAX_RECOG_OPERANDS];
    754   struct costs *x_this_op_costs[MAX_RECOG_OPERANDS];
    755 
    756   /* Hard registers that can not be used for the register allocator for
    757      all functions of the current compilation unit.  */
    758   HARD_REG_SET x_no_unit_alloc_regs;
    759 
    760   /* Map: hard regs X modes -> set of hard registers for storing value
    761      of given mode starting with given hard register.  */
    762   HARD_REG_SET (x_ira_reg_mode_hard_regset
    763 		[FIRST_PSEUDO_REGISTER][NUM_MACHINE_MODES]);
    764 
    765   /* Maximum cost of moving from a register in one class to a register
    766      in another class.  Based on TARGET_REGISTER_MOVE_COST.  */
    767   move_table *x_ira_register_move_cost[MAX_MACHINE_MODE];
    768 
    769   /* Similar, but here we don't have to move if the first index is a
    770      subset of the second so in that case the cost is zero.  */
    771   move_table *x_ira_may_move_in_cost[MAX_MACHINE_MODE];
    772 
    773   /* Similar, but here we don't have to move if the first index is a
    774      superset of the second so in that case the cost is zero.  */
    775   move_table *x_ira_may_move_out_cost[MAX_MACHINE_MODE];
    776 
    777   /* Keep track of the last mode we initialized move costs for.  */
    778   int x_last_mode_for_init_move_cost;
    779 
    780   /* Array analog of the macro MEMORY_MOVE_COST but they contain maximal
    781      cost not minimal.  */
    782   short int x_ira_max_memory_move_cost[MAX_MACHINE_MODE][N_REG_CLASSES][2];
    783 
    784   /* Map class->true if class is a possible allocno class, false
    785      otherwise. */
    786   bool x_ira_reg_allocno_class_p[N_REG_CLASSES];
    787 
    788   /* Map class->true if class is a pressure class, false otherwise. */
    789   bool x_ira_reg_pressure_class_p[N_REG_CLASSES];
    790 
    791   /* Array of the number of hard registers of given class which are
    792      available for allocation.  The order is defined by the hard
    793      register numbers.  */
    794   short x_ira_non_ordered_class_hard_regs[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
    795 
    796   /* Index (in ira_class_hard_regs; for given register class and hard
    797      register (in general case a hard register can belong to several
    798      register classes;.  The index is negative for hard registers
    799      unavailable for the allocation.  */
    800   short x_ira_class_hard_reg_index[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
    801 
    802   /* Array whose values are hard regset of hard registers available for
    803      the allocation of given register class whose HARD_REGNO_MODE_OK
    804      values for given mode are zero.  */
    805   HARD_REG_SET x_ira_prohibited_class_mode_regs[N_REG_CLASSES][NUM_MACHINE_MODES];
    806 
    807   /* Index [CL][M] contains R if R appears somewhere in a register of the form:
    808 
    809          (reg:M R'), R' not in x_ira_prohibited_class_mode_regs[CL][M]
    810 
    811      For example, if:
    812 
    813      - (reg:M 2) is valid and occupies two registers;
    814      - register 2 belongs to CL; and
    815      - register 3 belongs to the same pressure class as CL
    816 
    817      then (reg:M 2) contributes to [CL][M] and registers 2 and 3 will be
    818      in the set.  */
    819   HARD_REG_SET x_ira_useful_class_mode_regs[N_REG_CLASSES][NUM_MACHINE_MODES];
    820 
    821   /* The value is number of elements in the subsequent array.  */
    822   int x_ira_important_classes_num;
    823 
    824   /* The array containing all non-empty classes.  Such classes is
    825      important for calculation of the hard register usage costs.  */
    826   enum reg_class x_ira_important_classes[N_REG_CLASSES];
    827 
    828   /* The array containing indexes of important classes in the previous
    829      array.  The array elements are defined only for important
    830      classes.  */
    831   int x_ira_important_class_nums[N_REG_CLASSES];
    832 
    833   /* Map class->true if class is an uniform class, false otherwise.  */
    834   bool x_ira_uniform_class_p[N_REG_CLASSES];
    835 
    836   /* The biggest important class inside of intersection of the two
    837      classes (that is calculated taking only hard registers available
    838      for allocation into account;.  If the both classes contain no hard
    839      registers available for allocation, the value is calculated with
    840      taking all hard-registers including fixed ones into account.  */
    841   enum reg_class x_ira_reg_class_intersect[N_REG_CLASSES][N_REG_CLASSES];
    842 
    843   /* Classes with end marker LIM_REG_CLASSES which are intersected with
    844      given class (the first index).  That includes given class itself.
    845      This is calculated taking only hard registers available for
    846      allocation into account.  */
    847   enum reg_class x_ira_reg_class_super_classes[N_REG_CLASSES][N_REG_CLASSES];
    848 
    849   /* The biggest (smallest) important class inside of (covering) union
    850      of the two classes (that is calculated taking only hard registers
    851      available for allocation into account).  If the both classes
    852      contain no hard registers available for allocation, the value is
    853      calculated with taking all hard-registers including fixed ones
    854      into account.  In other words, the value is the corresponding
    855      reg_class_subunion (reg_class_superunion) value.  */
    856   enum reg_class x_ira_reg_class_subunion[N_REG_CLASSES][N_REG_CLASSES];
    857   enum reg_class x_ira_reg_class_superunion[N_REG_CLASSES][N_REG_CLASSES];
    858 
    859   /* For each reg class, table listing all the classes contained in it
    860      (excluding the class itself.  Non-allocatable registers are
    861      excluded from the consideration).  */
    862   enum reg_class x_alloc_reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
    863 
    864   /* Array whose values are hard regset of hard registers for which
    865      move of the hard register in given mode into itself is
    866      prohibited.  */
    867   HARD_REG_SET x_ira_prohibited_mode_move_regs[NUM_MACHINE_MODES];
    868 
    869   /* Flag of that the above array has been initialized.  */
    870   bool x_ira_prohibited_mode_move_regs_initialized_p;
    871 };
    872 
    873 extern struct target_ira_int default_target_ira_int;
    874 #if SWITCHABLE_TARGET
    875 extern struct target_ira_int *this_target_ira_int;
    876 #else
    877 #define this_target_ira_int (&default_target_ira_int)
    878 #endif
    879 
    880 #define ira_reg_mode_hard_regset \
    881   (this_target_ira_int->x_ira_reg_mode_hard_regset)
    882 #define ira_register_move_cost \
    883   (this_target_ira_int->x_ira_register_move_cost)
    884 #define ira_max_memory_move_cost \
    885   (this_target_ira_int->x_ira_max_memory_move_cost)
    886 #define ira_may_move_in_cost \
    887   (this_target_ira_int->x_ira_may_move_in_cost)
    888 #define ira_may_move_out_cost \
    889   (this_target_ira_int->x_ira_may_move_out_cost)
    890 #define ira_reg_allocno_class_p \
    891   (this_target_ira_int->x_ira_reg_allocno_class_p)
    892 #define ira_reg_pressure_class_p \
    893   (this_target_ira_int->x_ira_reg_pressure_class_p)
    894 #define ira_non_ordered_class_hard_regs \
    895   (this_target_ira_int->x_ira_non_ordered_class_hard_regs)
    896 #define ira_class_hard_reg_index \
    897   (this_target_ira_int->x_ira_class_hard_reg_index)
    898 #define ira_prohibited_class_mode_regs \
    899   (this_target_ira_int->x_ira_prohibited_class_mode_regs)
    900 #define ira_useful_class_mode_regs \
    901   (this_target_ira_int->x_ira_useful_class_mode_regs)
    902 #define ira_important_classes_num \
    903   (this_target_ira_int->x_ira_important_classes_num)
    904 #define ira_important_classes \
    905   (this_target_ira_int->x_ira_important_classes)
    906 #define ira_important_class_nums \
    907   (this_target_ira_int->x_ira_important_class_nums)
    908 #define ira_uniform_class_p \
    909   (this_target_ira_int->x_ira_uniform_class_p)
    910 #define ira_reg_class_intersect \
    911   (this_target_ira_int->x_ira_reg_class_intersect)
    912 #define ira_reg_class_super_classes \
    913   (this_target_ira_int->x_ira_reg_class_super_classes)
    914 #define ira_reg_class_subunion \
    915   (this_target_ira_int->x_ira_reg_class_subunion)
    916 #define ira_reg_class_superunion \
    917   (this_target_ira_int->x_ira_reg_class_superunion)
    918 #define ira_prohibited_mode_move_regs \
    919   (this_target_ira_int->x_ira_prohibited_mode_move_regs)
    920 
    921 /* ira.c: */
    923 
    924 extern void *ira_allocate (size_t);
    925 extern void ira_free (void *addr);
    926 extern bitmap ira_allocate_bitmap (void);
    927 extern void ira_free_bitmap (bitmap);
    928 extern void ira_print_disposition (FILE *);
    929 extern void ira_debug_disposition (void);
    930 extern void ira_debug_allocno_classes (void);
    931 extern void ira_init_register_move_cost (enum machine_mode);
    932 
    933 /* ira-build.c */
    934 
    935 /* The current loop tree node and its regno allocno map.  */
    936 extern ira_loop_tree_node_t ira_curr_loop_tree_node;
    937 extern ira_allocno_t *ira_curr_regno_allocno_map;
    938 
    939 extern void ira_debug_copy (ira_copy_t);
    940 extern void ira_debug_copies (void);
    941 extern void ira_debug_allocno_copies (ira_allocno_t);
    942 
    943 extern void ira_traverse_loop_tree (bool, ira_loop_tree_node_t,
    944 				    void (*) (ira_loop_tree_node_t),
    945 				    void (*) (ira_loop_tree_node_t));
    946 extern ira_allocno_t ira_parent_allocno (ira_allocno_t);
    947 extern ira_allocno_t ira_parent_or_cap_allocno (ira_allocno_t);
    948 extern ira_allocno_t ira_create_allocno (int, bool, ira_loop_tree_node_t);
    949 extern void ira_create_allocno_objects (ira_allocno_t);
    950 extern void ira_set_allocno_class (ira_allocno_t, enum reg_class);
    951 extern bool ira_conflict_vector_profitable_p (ira_object_t, int);
    952 extern void ira_allocate_conflict_vec (ira_object_t, int);
    953 extern void ira_allocate_object_conflicts (ira_object_t, int);
    954 extern void ior_hard_reg_conflicts (ira_allocno_t, HARD_REG_SET *);
    955 extern void ira_print_expanded_allocno (ira_allocno_t);
    956 extern void ira_add_live_range_to_object (ira_object_t, int, int);
    957 extern live_range_t ira_create_live_range (ira_object_t, int, int,
    958 					   live_range_t);
    959 extern live_range_t ira_copy_live_range_list (live_range_t);
    960 extern live_range_t ira_merge_live_ranges (live_range_t, live_range_t);
    961 extern bool ira_live_ranges_intersect_p (live_range_t, live_range_t);
    962 extern void ira_finish_live_range (live_range_t);
    963 extern void ira_finish_live_range_list (live_range_t);
    964 extern void ira_free_allocno_updated_costs (ira_allocno_t);
    965 extern ira_copy_t ira_create_copy (ira_allocno_t, ira_allocno_t,
    966 				   int, bool, rtx, ira_loop_tree_node_t);
    967 extern void ira_add_allocno_copy_to_list (ira_copy_t);
    968 extern void ira_swap_allocno_copy_ends_if_necessary (ira_copy_t);
    969 extern ira_copy_t ira_add_allocno_copy (ira_allocno_t, ira_allocno_t, int,
    970 					bool, rtx, ira_loop_tree_node_t);
    971 
    972 extern int *ira_allocate_cost_vector (reg_class_t);
    973 extern void ira_free_cost_vector (int *, reg_class_t);
    974 
    975 extern void ira_flattening (int, int);
    976 extern bool ira_build (void);
    977 extern void ira_destroy (void);
    978 
    979 /* ira-costs.c */
    980 extern void ira_init_costs_once (void);
    981 extern void ira_init_costs (void);
    982 extern void ira_finish_costs_once (void);
    983 extern void ira_costs (void);
    984 extern void ira_tune_allocno_costs (void);
    985 
    986 /* ira-lives.c */
    987 
    988 extern void ira_rebuild_start_finish_chains (void);
    989 extern void ira_print_live_range_list (FILE *, live_range_t);
    990 extern void ira_debug_live_range_list (live_range_t);
    991 extern void ira_debug_allocno_live_ranges (ira_allocno_t);
    992 extern void ira_debug_live_ranges (void);
    993 extern void ira_create_allocno_live_ranges (void);
    994 extern void ira_compress_allocno_live_ranges (void);
    995 extern void ira_finish_allocno_live_ranges (void);
    996 
    997 /* ira-conflicts.c */
    998 extern void ira_debug_conflicts (bool);
    999 extern void ira_build_conflicts (void);
   1000 
   1001 /* ira-color.c */
   1002 extern void ira_debug_hard_regs_forest (void);
   1003 extern int ira_loop_edge_freq (ira_loop_tree_node_t, int, bool);
   1004 extern void ira_reassign_conflict_allocnos (int);
   1005 extern void ira_initiate_assign (void);
   1006 extern void ira_finish_assign (void);
   1007 extern void ira_color (void);
   1008 
   1009 /* ira-emit.c */
   1010 extern void ira_initiate_emit_data (void);
   1011 extern void ira_finish_emit_data (void);
   1012 extern void ira_emit (bool);
   1013 
   1014 
   1015 
   1017 /* Return true if equivalence of pseudo REGNO is not a lvalue.  */
   1018 static inline bool
   1019 ira_equiv_no_lvalue_p (int regno)
   1020 {
   1021   if (regno >= ira_reg_equiv_len)
   1022     return false;
   1023   return (ira_reg_equiv[regno].constant != NULL_RTX
   1024 	  || ira_reg_equiv[regno].invariant != NULL_RTX
   1025 	  || (ira_reg_equiv[regno].memory != NULL_RTX
   1026 	      && MEM_READONLY_P (ira_reg_equiv[regno].memory)));
   1027 }
   1028 
   1029 
   1030 
   1032 /* Initialize register costs for MODE if necessary.  */
   1033 static inline void
   1034 ira_init_register_move_cost_if_necessary (enum machine_mode mode)
   1035 {
   1036   if (ira_register_move_cost[mode] == NULL)
   1037     ira_init_register_move_cost (mode);
   1038 }
   1039 
   1040 
   1041 
   1043 /* The iterator for all allocnos.  */
   1044 typedef struct {
   1045   /* The number of the current element in IRA_ALLOCNOS.  */
   1046   int n;
   1047 } ira_allocno_iterator;
   1048 
   1049 /* Initialize the iterator I.  */
   1050 static inline void
   1051 ira_allocno_iter_init (ira_allocno_iterator *i)
   1052 {
   1053   i->n = 0;
   1054 }
   1055 
   1056 /* Return TRUE if we have more allocnos to visit, in which case *A is
   1057    set to the allocno to be visited.  Otherwise, return FALSE.  */
   1058 static inline bool
   1059 ira_allocno_iter_cond (ira_allocno_iterator *i, ira_allocno_t *a)
   1060 {
   1061   int n;
   1062 
   1063   for (n = i->n; n < ira_allocnos_num; n++)
   1064     if (ira_allocnos[n] != NULL)
   1065       {
   1066 	*a = ira_allocnos[n];
   1067 	i->n = n + 1;
   1068 	return true;
   1069       }
   1070   return false;
   1071 }
   1072 
   1073 /* Loop over all allocnos.  In each iteration, A is set to the next
   1074    allocno.  ITER is an instance of ira_allocno_iterator used to iterate
   1075    the allocnos.  */
   1076 #define FOR_EACH_ALLOCNO(A, ITER)			\
   1077   for (ira_allocno_iter_init (&(ITER));			\
   1078        ira_allocno_iter_cond (&(ITER), &(A));)
   1079 
   1080 /* The iterator for all objects.  */
   1082 typedef struct {
   1083   /* The number of the current element in ira_object_id_map.  */
   1084   int n;
   1085 } ira_object_iterator;
   1086 
   1087 /* Initialize the iterator I.  */
   1088 static inline void
   1089 ira_object_iter_init (ira_object_iterator *i)
   1090 {
   1091   i->n = 0;
   1092 }
   1093 
   1094 /* Return TRUE if we have more objects to visit, in which case *OBJ is
   1095    set to the object to be visited.  Otherwise, return FALSE.  */
   1096 static inline bool
   1097 ira_object_iter_cond (ira_object_iterator *i, ira_object_t *obj)
   1098 {
   1099   int n;
   1100 
   1101   for (n = i->n; n < ira_objects_num; n++)
   1102     if (ira_object_id_map[n] != NULL)
   1103       {
   1104 	*obj = ira_object_id_map[n];
   1105 	i->n = n + 1;
   1106 	return true;
   1107       }
   1108   return false;
   1109 }
   1110 
   1111 /* Loop over all objects.  In each iteration, OBJ is set to the next
   1112    object.  ITER is an instance of ira_object_iterator used to iterate
   1113    the objects.  */
   1114 #define FOR_EACH_OBJECT(OBJ, ITER)			\
   1115   for (ira_object_iter_init (&(ITER));			\
   1116        ira_object_iter_cond (&(ITER), &(OBJ));)
   1117 
   1118 /* The iterator for objects associated with an allocno.  */
   1120 typedef struct {
   1121   /* The number of the element the allocno's object array.  */
   1122   int n;
   1123 } ira_allocno_object_iterator;
   1124 
   1125 /* Initialize the iterator I.  */
   1126 static inline void
   1127 ira_allocno_object_iter_init (ira_allocno_object_iterator *i)
   1128 {
   1129   i->n = 0;
   1130 }
   1131 
   1132 /* Return TRUE if we have more objects to visit in allocno A, in which
   1133    case *O is set to the object to be visited.  Otherwise, return
   1134    FALSE.  */
   1135 static inline bool
   1136 ira_allocno_object_iter_cond (ira_allocno_object_iterator *i, ira_allocno_t a,
   1137 			      ira_object_t *o)
   1138 {
   1139   int n = i->n++;
   1140   if (n < ALLOCNO_NUM_OBJECTS (a))
   1141     {
   1142       *o = ALLOCNO_OBJECT (a, n);
   1143       return true;
   1144     }
   1145   return false;
   1146 }
   1147 
   1148 /* Loop over all objects associated with allocno A.  In each
   1149    iteration, O is set to the next object.  ITER is an instance of
   1150    ira_allocno_object_iterator used to iterate the conflicts.  */
   1151 #define FOR_EACH_ALLOCNO_OBJECT(A, O, ITER)			\
   1152   for (ira_allocno_object_iter_init (&(ITER));			\
   1153        ira_allocno_object_iter_cond (&(ITER), (A), &(O));)
   1154 
   1155 
   1157 /* The iterator for copies.  */
   1158 typedef struct {
   1159   /* The number of the current element in IRA_COPIES.  */
   1160   int n;
   1161 } ira_copy_iterator;
   1162 
   1163 /* Initialize the iterator I.  */
   1164 static inline void
   1165 ira_copy_iter_init (ira_copy_iterator *i)
   1166 {
   1167   i->n = 0;
   1168 }
   1169 
   1170 /* Return TRUE if we have more copies to visit, in which case *CP is
   1171    set to the copy to be visited.  Otherwise, return FALSE.  */
   1172 static inline bool
   1173 ira_copy_iter_cond (ira_copy_iterator *i, ira_copy_t *cp)
   1174 {
   1175   int n;
   1176 
   1177   for (n = i->n; n < ira_copies_num; n++)
   1178     if (ira_copies[n] != NULL)
   1179       {
   1180 	*cp = ira_copies[n];
   1181 	i->n = n + 1;
   1182 	return true;
   1183       }
   1184   return false;
   1185 }
   1186 
   1187 /* Loop over all copies.  In each iteration, C is set to the next
   1188    copy.  ITER is an instance of ira_copy_iterator used to iterate
   1189    the copies.  */
   1190 #define FOR_EACH_COPY(C, ITER)				\
   1191   for (ira_copy_iter_init (&(ITER));			\
   1192        ira_copy_iter_cond (&(ITER), &(C));)
   1193 
   1194 /* The iterator for object conflicts.  */
   1196 typedef struct {
   1197 
   1198   /* TRUE if the conflicts are represented by vector of allocnos.  */
   1199   bool conflict_vec_p;
   1200 
   1201   /* The conflict vector or conflict bit vector.  */
   1202   void *vec;
   1203 
   1204   /* The number of the current element in the vector (of type
   1205      ira_object_t or IRA_INT_TYPE).  */
   1206   unsigned int word_num;
   1207 
   1208   /* The bit vector size.  It is defined only if
   1209      OBJECT_CONFLICT_VEC_P is FALSE.  */
   1210   unsigned int size;
   1211 
   1212   /* The current bit index of bit vector.  It is defined only if
   1213      OBJECT_CONFLICT_VEC_P is FALSE.  */
   1214   unsigned int bit_num;
   1215 
   1216   /* The object id corresponding to the 1st bit of the bit vector.  It
   1217      is defined only if OBJECT_CONFLICT_VEC_P is FALSE.  */
   1218   int base_conflict_id;
   1219 
   1220   /* The word of bit vector currently visited.  It is defined only if
   1221      OBJECT_CONFLICT_VEC_P is FALSE.  */
   1222   unsigned IRA_INT_TYPE word;
   1223 } ira_object_conflict_iterator;
   1224 
   1225 /* Initialize the iterator I with ALLOCNO conflicts.  */
   1226 static inline void
   1227 ira_object_conflict_iter_init (ira_object_conflict_iterator *i,
   1228 			       ira_object_t obj)
   1229 {
   1230   i->conflict_vec_p = OBJECT_CONFLICT_VEC_P (obj);
   1231   i->vec = OBJECT_CONFLICT_ARRAY (obj);
   1232   i->word_num = 0;
   1233   if (i->conflict_vec_p)
   1234     i->size = i->bit_num = i->base_conflict_id = i->word = 0;
   1235   else
   1236     {
   1237       if (OBJECT_MIN (obj) > OBJECT_MAX (obj))
   1238 	i->size = 0;
   1239       else
   1240 	i->size = ((OBJECT_MAX (obj) - OBJECT_MIN (obj)
   1241 		    + IRA_INT_BITS)
   1242 		   / IRA_INT_BITS) * sizeof (IRA_INT_TYPE);
   1243       i->bit_num = 0;
   1244       i->base_conflict_id = OBJECT_MIN (obj);
   1245       i->word = (i->size == 0 ? 0 : ((IRA_INT_TYPE *) i->vec)[0]);
   1246     }
   1247 }
   1248 
   1249 /* Return TRUE if we have more conflicting allocnos to visit, in which
   1250    case *A is set to the allocno to be visited.  Otherwise, return
   1251    FALSE.  */
   1252 static inline bool
   1253 ira_object_conflict_iter_cond (ira_object_conflict_iterator *i,
   1254 			       ira_object_t *pobj)
   1255 {
   1256   ira_object_t obj;
   1257 
   1258   if (i->conflict_vec_p)
   1259     {
   1260       obj = ((ira_object_t *) i->vec)[i->word_num++];
   1261       if (obj == NULL)
   1262 	return false;
   1263     }
   1264   else
   1265     {
   1266       unsigned IRA_INT_TYPE word = i->word;
   1267       unsigned int bit_num = i->bit_num;
   1268 
   1269       /* Skip words that are zeros.  */
   1270       for (; word == 0; word = ((IRA_INT_TYPE *) i->vec)[i->word_num])
   1271 	{
   1272 	  i->word_num++;
   1273 
   1274 	  /* If we have reached the end, break.  */
   1275 	  if (i->word_num * sizeof (IRA_INT_TYPE) >= i->size)
   1276 	    return false;
   1277 
   1278 	  bit_num = i->word_num * IRA_INT_BITS;
   1279 	}
   1280 
   1281       /* Skip bits that are zero.  */
   1282       for (; (word & 1) == 0; word >>= 1)
   1283 	bit_num++;
   1284 
   1285       obj = ira_object_id_map[bit_num + i->base_conflict_id];
   1286       i->bit_num = bit_num + 1;
   1287       i->word = word >> 1;
   1288     }
   1289 
   1290   *pobj = obj;
   1291   return true;
   1292 }
   1293 
   1294 /* Loop over all objects conflicting with OBJ.  In each iteration,
   1295    CONF is set to the next conflicting object.  ITER is an instance
   1296    of ira_object_conflict_iterator used to iterate the conflicts.  */
   1297 #define FOR_EACH_OBJECT_CONFLICT(OBJ, CONF, ITER)			\
   1298   for (ira_object_conflict_iter_init (&(ITER), (OBJ));			\
   1299        ira_object_conflict_iter_cond (&(ITER), &(CONF));)
   1300 
   1301 
   1302 
   1304 /* The function returns TRUE if at least one hard register from ones
   1305    starting with HARD_REGNO and containing value of MODE are in set
   1306    HARD_REGSET.  */
   1307 static inline bool
   1308 ira_hard_reg_set_intersection_p (int hard_regno, enum machine_mode mode,
   1309 				 HARD_REG_SET hard_regset)
   1310 {
   1311   int i;
   1312 
   1313   gcc_assert (hard_regno >= 0);
   1314   for (i = hard_regno_nregs[hard_regno][mode] - 1; i >= 0; i--)
   1315     if (TEST_HARD_REG_BIT (hard_regset, hard_regno + i))
   1316       return true;
   1317   return false;
   1318 }
   1319 
   1320 /* Return number of hard registers in hard register SET.  */
   1321 static inline int
   1322 hard_reg_set_size (HARD_REG_SET set)
   1323 {
   1324   int i, size;
   1325 
   1326   for (size = i = 0; i < FIRST_PSEUDO_REGISTER; i++)
   1327     if (TEST_HARD_REG_BIT (set, i))
   1328       size++;
   1329   return size;
   1330 }
   1331 
   1332 /* The function returns TRUE if hard registers starting with
   1333    HARD_REGNO and containing value of MODE are fully in set
   1334    HARD_REGSET.  */
   1335 static inline bool
   1336 ira_hard_reg_in_set_p (int hard_regno, enum machine_mode mode,
   1337 		       HARD_REG_SET hard_regset)
   1338 {
   1339   int i;
   1340 
   1341   ira_assert (hard_regno >= 0);
   1342   for (i = hard_regno_nregs[hard_regno][mode] - 1; i >= 0; i--)
   1343     if (!TEST_HARD_REG_BIT (hard_regset, hard_regno + i))
   1344       return false;
   1345   return true;
   1346 }
   1347 
   1348 
   1349 
   1351 /* To save memory we use a lazy approach for allocation and
   1352    initialization of the cost vectors.  We do this only when it is
   1353    really necessary.  */
   1354 
   1355 /* Allocate cost vector *VEC for hard registers of ACLASS and
   1356    initialize the elements by VAL if it is necessary */
   1357 static inline void
   1358 ira_allocate_and_set_costs (int **vec, reg_class_t aclass, int val)
   1359 {
   1360   int i, *reg_costs;
   1361   int len;
   1362 
   1363   if (*vec != NULL)
   1364     return;
   1365   *vec = reg_costs = ira_allocate_cost_vector (aclass);
   1366   len = ira_class_hard_regs_num[(int) aclass];
   1367   for (i = 0; i < len; i++)
   1368     reg_costs[i] = val;
   1369 }
   1370 
   1371 /* Allocate cost vector *VEC for hard registers of ACLASS and copy
   1372    values of vector SRC into the vector if it is necessary */
   1373 static inline void
   1374 ira_allocate_and_copy_costs (int **vec, enum reg_class aclass, int *src)
   1375 {
   1376   int len;
   1377 
   1378   if (*vec != NULL || src == NULL)
   1379     return;
   1380   *vec = ira_allocate_cost_vector (aclass);
   1381   len = ira_class_hard_regs_num[aclass];
   1382   memcpy (*vec, src, sizeof (int) * len);
   1383 }
   1384 
   1385 /* Allocate cost vector *VEC for hard registers of ACLASS and add
   1386    values of vector SRC into the vector if it is necessary */
   1387 static inline void
   1388 ira_allocate_and_accumulate_costs (int **vec, enum reg_class aclass, int *src)
   1389 {
   1390   int i, len;
   1391 
   1392   if (src == NULL)
   1393     return;
   1394   len = ira_class_hard_regs_num[aclass];
   1395   if (*vec == NULL)
   1396     {
   1397       *vec = ira_allocate_cost_vector (aclass);
   1398       memset (*vec, 0, sizeof (int) * len);
   1399     }
   1400   for (i = 0; i < len; i++)
   1401     (*vec)[i] += src[i];
   1402 }
   1403 
   1404 /* Allocate cost vector *VEC for hard registers of ACLASS and copy
   1405    values of vector SRC into the vector or initialize it by VAL (if
   1406    SRC is null).  */
   1407 static inline void
   1408 ira_allocate_and_set_or_copy_costs (int **vec, enum reg_class aclass,
   1409 				    int val, int *src)
   1410 {
   1411   int i, *reg_costs;
   1412   int len;
   1413 
   1414   if (*vec != NULL)
   1415     return;
   1416   *vec = reg_costs = ira_allocate_cost_vector (aclass);
   1417   len = ira_class_hard_regs_num[aclass];
   1418   if (src != NULL)
   1419     memcpy (reg_costs, src, sizeof (int) * len);
   1420   else
   1421     {
   1422       for (i = 0; i < len; i++)
   1423 	reg_costs[i] = val;
   1424     }
   1425 }
   1426 
   1427 extern rtx ira_create_new_reg (rtx);
   1428 extern int first_moveable_pseudo, last_moveable_pseudo;
   1429