Home | History | Annotate | Line # | Download | only in gcc
ira-int.h revision 1.1.1.1.4.2
      1 /* Integrated Register Allocator (IRA) intercommunication header file.
      2    Copyright (C) 2006, 2007, 2008, 2009
      3    Free Software Foundation, Inc.
      4    Contributed by Vladimir Makarov <vmakarov (at) redhat.com>.
      5 
      6 This file is part of GCC.
      7 
      8 GCC is free software; you can redistribute it and/or modify it under
      9 the terms of the GNU General Public License as published by the Free
     10 Software Foundation; either version 3, or (at your option) any later
     11 version.
     12 
     13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
     15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     16 for more details.
     17 
     18 You should have received a copy of the GNU General Public License
     19 along with GCC; see the file COPYING3.  If not see
     20 <http://www.gnu.org/licenses/>.  */
     21 
     22 #include "cfgloop.h"
     23 #include "ira.h"
     24 #include "alloc-pool.h"
     25 
     26 /* To provide consistency in naming, all IRA external variables,
     27    functions, common typedefs start with prefix ira_.  */
     28 
     29 #ifdef ENABLE_CHECKING
     30 #define ENABLE_IRA_CHECKING
     31 #endif
     32 
     33 #ifdef ENABLE_IRA_CHECKING
     34 #define ira_assert(c) gcc_assert (c)
     35 #else
     36 /* Always define and include C, so that warnings for empty body in an
     37   if statement and unused variable do not occur.  */
     38 #define ira_assert(c) ((void)(0 && (c)))
     39 #endif
     40 
     41 /* Compute register frequency from edge frequency FREQ.  It is
     42    analogous to REG_FREQ_FROM_BB.  When optimizing for size, or
     43    profile driven feedback is available and the function is never
     44    executed, frequency is always equivalent.  Otherwise rescale the
     45    edge frequency.  */
     46 #define REG_FREQ_FROM_EDGE_FREQ(freq)					      \
     47   (optimize_size || (flag_branch_probabilities && !ENTRY_BLOCK_PTR->count)    \
     48    ? REG_FREQ_MAX : (freq * REG_FREQ_MAX / BB_FREQ_MAX)			      \
     49    ? (freq * REG_FREQ_MAX / BB_FREQ_MAX) : 1)
     50 
     51 /* All natural loops.  */
     52 extern struct loops ira_loops;
     53 
     54 /* A modified value of flag `-fira-verbose' used internally.  */
     55 extern int internal_flag_ira_verbose;
     56 
     57 /* Dump file of the allocator if it is not NULL.  */
     58 extern FILE *ira_dump_file;
     59 
     60 /* Typedefs for pointers to allocno live range, allocno, and copy of
     61    allocnos.  */
     62 typedef struct ira_allocno_live_range *allocno_live_range_t;
     63 typedef struct ira_allocno *ira_allocno_t;
     64 typedef struct ira_allocno_copy *ira_copy_t;
     65 
     66 /* Definition of vector of allocnos and copies.  */
     67 DEF_VEC_P(ira_allocno_t);
     68 DEF_VEC_ALLOC_P(ira_allocno_t, heap);
     69 DEF_VEC_P(ira_copy_t);
     70 DEF_VEC_ALLOC_P(ira_copy_t, heap);
     71 
     72 /* Typedef for pointer to the subsequent structure.  */
     73 typedef struct ira_loop_tree_node *ira_loop_tree_node_t;
     74 
     75 /* In general case, IRA is a regional allocator.  The regions are
     76    nested and form a tree.  Currently regions are natural loops.  The
     77    following structure describes loop tree node (representing basic
     78    block or loop).  We need such tree because the loop tree from
     79    cfgloop.h is not convenient for the optimization: basic blocks are
     80    not a part of the tree from cfgloop.h.  We also use the nodes for
     81    storing additional information about basic blocks/loops for the
     82    register allocation purposes.  */
     83 struct ira_loop_tree_node
     84 {
     85   /* The node represents basic block if children == NULL.  */
     86   basic_block bb;    /* NULL for loop.  */
     87   struct loop *loop; /* NULL for BB.  */
     88   /* NEXT/SUBLOOP_NEXT is the next node/loop-node of the same parent.
     89      SUBLOOP_NEXT is always NULL for BBs.  */
     90   ira_loop_tree_node_t subloop_next, next;
     91   /* CHILDREN/SUBLOOPS is the first node/loop-node immediately inside
     92      the node.  They are NULL for BBs.  */
     93   ira_loop_tree_node_t subloops, children;
     94   /* The node immediately containing given node.  */
     95   ira_loop_tree_node_t parent;
     96 
     97   /* Loop level in range [0, ira_loop_tree_height).  */
     98   int level;
     99 
    100   /* All the following members are defined only for nodes representing
    101      loops.  */
    102 
    103   /* True if the loop was marked for removal from the register
    104      allocation.  */
    105   bool to_remove_p;
    106 
    107   /* Allocnos in the loop corresponding to their regnos.  If it is
    108      NULL the loop does not form a separate register allocation region
    109      (e.g. because it has abnormal enter/exit edges and we can not put
    110      code for register shuffling on the edges if a different
    111      allocation is used for a pseudo-register on different sides of
    112      the edges).  Caps are not in the map (remember we can have more
    113      one cap with the same regno in a region).  */
    114   ira_allocno_t *regno_allocno_map;
    115 
    116   /* True if there is an entry to given loop not from its parent (or
    117      grandparent) basic block.  For example, it is possible for two
    118      adjacent loops inside another loop.  */
    119   bool entered_from_non_parent_p;
    120 
    121   /* Maximal register pressure inside loop for given register class
    122      (defined only for the cover classes).  */
    123   int reg_pressure[N_REG_CLASSES];
    124 
    125   /* Numbers of allocnos referred or living in the loop node (except
    126      for its subloops).  */
    127   bitmap all_allocnos;
    128 
    129   /* Numbers of allocnos living at the loop borders.  */
    130   bitmap border_allocnos;
    131 
    132   /* Regnos of pseudos modified in the loop node (including its
    133      subloops).  */
    134   bitmap modified_regnos;
    135 
    136   /* Numbers of copies referred in the corresponding loop.  */
    137   bitmap local_copies;
    138 };
    139 
    140 /* The root of the loop tree corresponding to the all function.  */
    141 extern ira_loop_tree_node_t ira_loop_tree_root;
    142 
    143 /* Height of the loop tree.  */
    144 extern int ira_loop_tree_height;
    145 
    146 /* All nodes representing basic blocks are referred through the
    147    following array.  We can not use basic block member `aux' for this
    148    because it is used for insertion of insns on edges.  */
    149 extern ira_loop_tree_node_t ira_bb_nodes;
    150 
    151 /* Two access macros to the nodes representing basic blocks.  */
    152 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
    153 #define IRA_BB_NODE_BY_INDEX(index) __extension__			\
    154 (({ ira_loop_tree_node_t _node = (&ira_bb_nodes[index]);	\
    155      if (_node->children != NULL || _node->loop != NULL || _node->bb == NULL)\
    156        {								\
    157          fprintf (stderr,						\
    158                   "\n%s: %d: error in %s: it is not a block node\n",	\
    159                   __FILE__, __LINE__, __FUNCTION__);			\
    160          gcc_unreachable ();						\
    161        }								\
    162      _node; }))
    163 #else
    164 #define IRA_BB_NODE_BY_INDEX(index) (&ira_bb_nodes[index])
    165 #endif
    166 
    167 #define IRA_BB_NODE(bb) IRA_BB_NODE_BY_INDEX ((bb)->index)
    168 
    169 /* All nodes representing loops are referred through the following
    170    array.  */
    171 extern ira_loop_tree_node_t ira_loop_nodes;
    172 
    173 /* Two access macros to the nodes representing loops.  */
    174 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
    175 #define IRA_LOOP_NODE_BY_INDEX(index) __extension__			\
    176 (({ ira_loop_tree_node_t const _node = (&ira_loop_nodes[index]);\
    177      if (_node->children == NULL || _node->bb != NULL || _node->loop == 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 
    194 /* The structure describes program points where a given allocno lives.
    195    To save memory we store allocno conflicts only for the same cover
    196    class allocnos which is enough to assign hard registers.  To find
    197    conflicts for other allocnos (e.g. to assign stack memory slot) we
    198    use the live ranges.  If the live ranges of two allocnos are
    199    intersected, the allocnos are in conflict.  */
    200 struct ira_allocno_live_range
    201 {
    202   /* Allocno whose live range is described by given structure.  */
    203   ira_allocno_t allocno;
    204   /* Program point range.  */
    205   int start, finish;
    206   /* Next structure describing program points where the allocno
    207      lives.  */
    208   allocno_live_range_t next;
    209   /* Pointer to structures with the same start/finish.  */
    210   allocno_live_range_t start_next, finish_next;
    211 };
    212 
    213 /* Program points are enumerated by numbers from range
    214    0..IRA_MAX_POINT-1.  There are approximately two times more program
    215    points than insns.  Program points are places in the program where
    216    liveness info can be changed.  In most general case (there are more
    217    complicated cases too) some program points correspond to places
    218    where input operand dies and other ones correspond to places where
    219    output operands are born.  */
    220 extern int ira_max_point;
    221 
    222 /* Arrays of size IRA_MAX_POINT mapping a program point to the allocno
    223    live ranges with given start/finish point.  */
    224 extern allocno_live_range_t *ira_start_point_ranges, *ira_finish_point_ranges;
    225 
    226 /* A structure representing an allocno (allocation entity).  Allocno
    227    represents a pseudo-register in an allocation region.  If
    228    pseudo-register does not live in a region but it lives in the
    229    nested regions, it is represented in the region by special allocno
    230    called *cap*.  There may be more one cap representing the same
    231    pseudo-register in region.  It means that the corresponding
    232    pseudo-register lives in more one non-intersected subregion.  */
    233 struct ira_allocno
    234 {
    235   /* The allocno order number starting with 0.  Each allocno has an
    236      unique number and the number is never changed for the
    237      allocno.  */
    238   int num;
    239   /* Regno for allocno or cap.  */
    240   int regno;
    241   /* Mode of the allocno which is the mode of the corresponding
    242      pseudo-register.  */
    243   enum machine_mode mode;
    244   /* Hard register assigned to given allocno.  Negative value means
    245      that memory was allocated to the allocno.  During the reload,
    246      spilled allocno has value equal to the corresponding stack slot
    247      number (0, ...) - 2.  Value -1 is used for allocnos spilled by the
    248      reload (at this point pseudo-register has only one allocno) which
    249      did not get stack slot yet.  */
    250   int hard_regno;
    251   /* Final rtx representation of the allocno.  */
    252   rtx reg;
    253   /* Allocnos with the same regno are linked by the following member.
    254      Allocnos corresponding to inner loops are first in the list (it
    255      corresponds to depth-first traverse of the loops).  */
    256   ira_allocno_t next_regno_allocno;
    257   /* There may be different allocnos with the same regno in different
    258      regions.  Allocnos are bound to the corresponding loop tree node.
    259      Pseudo-register may have only one regular allocno with given loop
    260      tree node but more than one cap (see comments above).  */
    261   ira_loop_tree_node_t loop_tree_node;
    262   /* Accumulated usage references of the allocno.  Here and below,
    263      word 'accumulated' means info for given region and all nested
    264      subregions.  In this case, 'accumulated' means sum of references
    265      of the corresponding pseudo-register in this region and in all
    266      nested subregions recursively. */
    267   int nrefs;
    268   /* Accumulated frequency of usage of the allocno.  */
    269   int freq;
    270   /* Register class which should be used for allocation for given
    271      allocno.  NO_REGS means that we should use memory.  */
    272   enum reg_class cover_class;
    273   /* Minimal accumulated and updated costs of usage register of the
    274      cover class for the allocno.  */
    275   int cover_class_cost, updated_cover_class_cost;
    276   /* Minimal accumulated, and updated costs of memory for the allocno.
    277      At the allocation start, the original and updated costs are
    278      equal.  The updated cost may be changed after finishing
    279      allocation in a region and starting allocation in a subregion.
    280      The change reflects the cost of spill/restore code on the
    281      subregion border if we assign memory to the pseudo in the
    282      subregion.  */
    283   int memory_cost, updated_memory_cost;
    284   /* Accumulated number of points where the allocno lives and there is
    285      excess pressure for its class.  Excess pressure for a register
    286      class at some point means that there are more allocnos of given
    287      register class living at the point than number of hard-registers
    288      of the class available for the allocation.  */
    289   int excess_pressure_points_num;
    290   /* Copies to other non-conflicting allocnos.  The copies can
    291      represent move insn or potential move insn usually because of two
    292      operand insn constraints.  */
    293   ira_copy_t allocno_copies;
    294   /* It is a allocno (cap) representing given allocno on upper loop tree
    295      level.  */
    296   ira_allocno_t cap;
    297   /* It is a link to allocno (cap) on lower loop level represented by
    298      given cap.  Null if given allocno is not a cap.  */
    299   ira_allocno_t cap_member;
    300   /* Coalesced allocnos form a cyclic list.  One allocno given by
    301      FIRST_COALESCED_ALLOCNO represents all coalesced allocnos.  The
    302      list is chained by NEXT_COALESCED_ALLOCNO.  */
    303   ira_allocno_t first_coalesced_allocno;
    304   ira_allocno_t next_coalesced_allocno;
    305   /* Pointer to structures describing at what program point the
    306      allocno lives.  We always maintain the list in such way that *the
    307      ranges in the list are not intersected and ordered by decreasing
    308      their program points*.  */
    309   allocno_live_range_t live_ranges;
    310   /* Before building conflicts the two member values are
    311      correspondingly minimal and maximal points of the accumulated
    312      allocno live ranges.  After building conflicts the values are
    313      correspondingly minimal and maximal conflict ids of allocnos with
    314      which given allocno can conflict.  */
    315   int min, max;
    316   /* Vector of accumulated conflicting allocnos with NULL end marker
    317      (if CONFLICT_VEC_P is true) or conflict bit vector otherwise.
    318      Only allocnos with the same cover class are in the vector or in
    319      the bit vector.  */
    320   void *conflict_allocno_array;
    321   /* The unique member value represents given allocno in conflict bit
    322      vectors.  */
    323   int conflict_id;
    324   /* Allocated size of the previous array.  */
    325   unsigned int conflict_allocno_array_size;
    326   /* Initial and accumulated hard registers conflicting with this
    327      allocno and as a consequences can not be assigned to the allocno.
    328      All non-allocatable hard regs and hard regs of cover classes
    329      different from given allocno one are included in the sets.  */
    330   HARD_REG_SET conflict_hard_regs, total_conflict_hard_regs;
    331   /* Number of accumulated conflicts in the vector of conflicting
    332      allocnos.  */
    333   int conflict_allocnos_num;
    334   /* Accumulated frequency of calls which given allocno
    335      intersects.  */
    336   int call_freq;
    337   /* Accumulated number of the intersected calls.  */
    338   int calls_crossed_num;
    339   /* TRUE if the allocno assigned to memory was a destination of
    340      removed move (see ira-emit.c) at loop exit because the value of
    341      the corresponding pseudo-register is not changed inside the
    342      loop.  */
    343   unsigned int mem_optimized_dest_p : 1;
    344   /* TRUE if the corresponding pseudo-register has disjoint live
    345      ranges and the other allocnos of the pseudo-register except this
    346      one changed REG.  */
    347   unsigned int somewhere_renamed_p : 1;
    348   /* TRUE if allocno with the same REGNO in a subregion has been
    349      renamed, in other words, got a new pseudo-register.  */
    350   unsigned int child_renamed_p : 1;
    351   /* During the reload, value TRUE means that we should not reassign a
    352      hard register to the allocno got memory earlier.  It is set up
    353      when we removed memory-memory move insn before each iteration of
    354      the reload.  */
    355   unsigned int dont_reassign_p : 1;
    356 #ifdef STACK_REGS
    357   /* Set to TRUE if allocno can't be assigned to the stack hard
    358      register correspondingly in this region and area including the
    359      region and all its subregions recursively.  */
    360   unsigned int no_stack_reg_p : 1, total_no_stack_reg_p : 1;
    361 #endif
    362   /* TRUE value means that there is no sense to spill the allocno
    363      during coloring because the spill will result in additional
    364      reloads in reload pass.  */
    365   unsigned int bad_spill_p : 1;
    366   /* TRUE value means that the allocno was not removed yet from the
    367      conflicting graph during colouring.  */
    368   unsigned int in_graph_p : 1;
    369   /* TRUE if a hard register or memory has been assigned to the
    370      allocno.  */
    371   unsigned int assigned_p : 1;
    372   /* TRUE if it is put on the stack to make other allocnos
    373      colorable.  */
    374   unsigned int may_be_spilled_p : 1;
    375   /* TRUE if the allocno was removed from the splay tree used to
    376      choose allocn for spilling (see ira-color.c::.  */
    377   unsigned int splay_removed_p : 1;
    378   /* TRUE if conflicts for given allocno are represented by vector of
    379      pointers to the conflicting allocnos.  Otherwise, we use a bit
    380      vector where a bit with given index represents allocno with the
    381      same number.  */
    382   unsigned int conflict_vec_p : 1;
    383   /* Non NULL if we remove restoring value from given allocno to
    384      MEM_OPTIMIZED_DEST at loop exit (see ira-emit.c) because the
    385      allocno value is not changed inside the loop.  */
    386   ira_allocno_t mem_optimized_dest;
    387   /* Array of usage costs (accumulated and the one updated during
    388      coloring) for each hard register of the allocno cover class.  The
    389      member value can be NULL if all costs are the same and equal to
    390      COVER_CLASS_COST.  For example, the costs of two different hard
    391      registers can be different if one hard register is callee-saved
    392      and another one is callee-used and the allocno lives through
    393      calls.  Another example can be case when for some insn the
    394      corresponding pseudo-register value should be put in specific
    395      register class (e.g. AREG for x86) which is a strict subset of
    396      the allocno cover class (GENERAL_REGS for x86).  We have updated
    397      costs to reflect the situation when the usage cost of a hard
    398      register is decreased because the allocno is connected to another
    399      allocno by a copy and the another allocno has been assigned to
    400      the hard register.  */
    401   int *hard_reg_costs, *updated_hard_reg_costs;
    402   /* Array of decreasing costs (accumulated and the one updated during
    403      coloring) for allocnos conflicting with given allocno for hard
    404      regno of the allocno cover class.  The member value can be NULL
    405      if all costs are the same.  These costs are used to reflect
    406      preferences of other allocnos not assigned yet during assigning
    407      to given allocno.  */
    408   int *conflict_hard_reg_costs, *updated_conflict_hard_reg_costs;
    409   /* Size (in hard registers) of the same cover class allocnos with
    410      TRUE in_graph_p value and conflicting with given allocno during
    411      each point of graph coloring.  */
    412   int left_conflicts_size;
    413   /* Number of hard registers of the allocno cover class really
    414      available for the allocno allocation.  */
    415   int available_regs_num;
    416   /* Allocnos in a bucket (used in coloring) chained by the following
    417      two members.  */
    418   ira_allocno_t next_bucket_allocno;
    419   ira_allocno_t prev_bucket_allocno;
    420   /* Used for temporary purposes.  */
    421   int temp;
    422 };
    423 
    424 /* All members of the allocno structures should be accessed only
    425    through the following macros.  */
    426 #define ALLOCNO_NUM(A) ((A)->num)
    427 #define ALLOCNO_REGNO(A) ((A)->regno)
    428 #define ALLOCNO_REG(A) ((A)->reg)
    429 #define ALLOCNO_NEXT_REGNO_ALLOCNO(A) ((A)->next_regno_allocno)
    430 #define ALLOCNO_LOOP_TREE_NODE(A) ((A)->loop_tree_node)
    431 #define ALLOCNO_CAP(A) ((A)->cap)
    432 #define ALLOCNO_CAP_MEMBER(A) ((A)->cap_member)
    433 #define ALLOCNO_CONFLICT_ALLOCNO_ARRAY(A) ((A)->conflict_allocno_array)
    434 #define ALLOCNO_CONFLICT_ALLOCNO_ARRAY_SIZE(A) \
    435   ((A)->conflict_allocno_array_size)
    436 #define ALLOCNO_CONFLICT_ALLOCNOS_NUM(A) \
    437   ((A)->conflict_allocnos_num)
    438 #define ALLOCNO_CONFLICT_HARD_REGS(A) ((A)->conflict_hard_regs)
    439 #define ALLOCNO_TOTAL_CONFLICT_HARD_REGS(A) ((A)->total_conflict_hard_regs)
    440 #define ALLOCNO_NREFS(A) ((A)->nrefs)
    441 #define ALLOCNO_FREQ(A) ((A)->freq)
    442 #define ALLOCNO_HARD_REGNO(A) ((A)->hard_regno)
    443 #define ALLOCNO_CALL_FREQ(A) ((A)->call_freq)
    444 #define ALLOCNO_CALLS_CROSSED_NUM(A) ((A)->calls_crossed_num)
    445 #define ALLOCNO_MEM_OPTIMIZED_DEST(A) ((A)->mem_optimized_dest)
    446 #define ALLOCNO_MEM_OPTIMIZED_DEST_P(A) ((A)->mem_optimized_dest_p)
    447 #define ALLOCNO_SOMEWHERE_RENAMED_P(A) ((A)->somewhere_renamed_p)
    448 #define ALLOCNO_CHILD_RENAMED_P(A) ((A)->child_renamed_p)
    449 #define ALLOCNO_DONT_REASSIGN_P(A) ((A)->dont_reassign_p)
    450 #ifdef STACK_REGS
    451 #define ALLOCNO_NO_STACK_REG_P(A) ((A)->no_stack_reg_p)
    452 #define ALLOCNO_TOTAL_NO_STACK_REG_P(A) ((A)->total_no_stack_reg_p)
    453 #endif
    454 #define ALLOCNO_BAD_SPILL_P(A) ((A)->bad_spill_p)
    455 #define ALLOCNO_IN_GRAPH_P(A) ((A)->in_graph_p)
    456 #define ALLOCNO_ASSIGNED_P(A) ((A)->assigned_p)
    457 #define ALLOCNO_MAY_BE_SPILLED_P(A) ((A)->may_be_spilled_p)
    458 #define ALLOCNO_SPLAY_REMOVED_P(A) ((A)->splay_removed_p)
    459 #define ALLOCNO_CONFLICT_VEC_P(A) ((A)->conflict_vec_p)
    460 #define ALLOCNO_MODE(A) ((A)->mode)
    461 #define ALLOCNO_COPIES(A) ((A)->allocno_copies)
    462 #define ALLOCNO_HARD_REG_COSTS(A) ((A)->hard_reg_costs)
    463 #define ALLOCNO_UPDATED_HARD_REG_COSTS(A) ((A)->updated_hard_reg_costs)
    464 #define ALLOCNO_CONFLICT_HARD_REG_COSTS(A) \
    465   ((A)->conflict_hard_reg_costs)
    466 #define ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS(A) \
    467   ((A)->updated_conflict_hard_reg_costs)
    468 #define ALLOCNO_LEFT_CONFLICTS_SIZE(A) ((A)->left_conflicts_size)
    469 #define ALLOCNO_COVER_CLASS(A) ((A)->cover_class)
    470 #define ALLOCNO_COVER_CLASS_COST(A) ((A)->cover_class_cost)
    471 #define ALLOCNO_UPDATED_COVER_CLASS_COST(A) ((A)->updated_cover_class_cost)
    472 #define ALLOCNO_MEMORY_COST(A) ((A)->memory_cost)
    473 #define ALLOCNO_UPDATED_MEMORY_COST(A) ((A)->updated_memory_cost)
    474 #define ALLOCNO_EXCESS_PRESSURE_POINTS_NUM(A) ((A)->excess_pressure_points_num)
    475 #define ALLOCNO_AVAILABLE_REGS_NUM(A) ((A)->available_regs_num)
    476 #define ALLOCNO_NEXT_BUCKET_ALLOCNO(A) ((A)->next_bucket_allocno)
    477 #define ALLOCNO_PREV_BUCKET_ALLOCNO(A) ((A)->prev_bucket_allocno)
    478 #define ALLOCNO_TEMP(A) ((A)->temp)
    479 #define ALLOCNO_FIRST_COALESCED_ALLOCNO(A) ((A)->first_coalesced_allocno)
    480 #define ALLOCNO_NEXT_COALESCED_ALLOCNO(A) ((A)->next_coalesced_allocno)
    481 #define ALLOCNO_LIVE_RANGES(A) ((A)->live_ranges)
    482 #define ALLOCNO_MIN(A) ((A)->min)
    483 #define ALLOCNO_MAX(A) ((A)->max)
    484 #define ALLOCNO_CONFLICT_ID(A) ((A)->conflict_id)
    485 
    486 /* Map regno -> allocnos with given regno (see comments for
    487    allocno member `next_regno_allocno').  */
    488 extern ira_allocno_t *ira_regno_allocno_map;
    489 
    490 /* Array of references to all allocnos.  The order number of the
    491    allocno corresponds to the index in the array.  Removed allocnos
    492    have NULL element value.  */
    493 extern ira_allocno_t *ira_allocnos;
    494 
    495 /* Sizes of the previous array.  */
    496 extern int ira_allocnos_num;
    497 
    498 /* Map conflict id -> allocno with given conflict id (see comments for
    499    allocno member `conflict_id').  */
    500 extern ira_allocno_t *ira_conflict_id_allocno_map;
    501 
    502 /* The following structure represents a copy of two allocnos.  The
    503    copies represent move insns or potential move insns usually because
    504    of two operand insn constraints.  To remove register shuffle, we
    505    also create copies between allocno which is output of an insn and
    506    allocno becoming dead in the insn.  */
    507 struct ira_allocno_copy
    508 {
    509   /* The unique order number of the copy node starting with 0.  */
    510   int num;
    511   /* Allocnos connected by the copy.  The first allocno should have
    512      smaller order number than the second one.  */
    513   ira_allocno_t first, second;
    514   /* Execution frequency of the copy.  */
    515   int freq;
    516   bool constraint_p;
    517   /* It is a move insn which is an origin of the copy.  The member
    518      value for the copy representing two operand insn constraints or
    519      for the copy created to remove register shuffle is NULL.  In last
    520      case the copy frequency is smaller than the corresponding insn
    521      execution frequency.  */
    522   rtx insn;
    523   /* All copies with the same allocno as FIRST are linked by the two
    524      following members.  */
    525   ira_copy_t prev_first_allocno_copy, next_first_allocno_copy;
    526   /* All copies with the same allocno as SECOND are linked by the two
    527      following members.  */
    528   ira_copy_t prev_second_allocno_copy, next_second_allocno_copy;
    529   /* Region from which given copy is originated.  */
    530   ira_loop_tree_node_t loop_tree_node;
    531 };
    532 
    533 /* Array of references to all copies.  The order number of the copy
    534    corresponds to the index in the array.  Removed copies have NULL
    535    element value.  */
    536 extern ira_copy_t *ira_copies;
    537 
    538 /* Size of the previous array.  */
    539 extern int ira_copies_num;
    540 
    541 /* The following structure describes a stack slot used for spilled
    542    pseudo-registers.  */
    543 struct ira_spilled_reg_stack_slot
    544 {
    545   /* pseudo-registers assigned to the stack slot.  */
    546   regset_head spilled_regs;
    547   /* RTL representation of the stack slot.  */
    548   rtx mem;
    549   /* Size of the stack slot.  */
    550   unsigned int width;
    551 };
    552 
    553 /* The number of elements in the following array.  */
    554 extern int ira_spilled_reg_stack_slots_num;
    555 
    556 /* The following array contains info about spilled pseudo-registers
    557    stack slots used in current function so far.  */
    558 extern struct ira_spilled_reg_stack_slot *ira_spilled_reg_stack_slots;
    559 
    560 /* Correspondingly overall cost of the allocation, cost of the
    561    allocnos assigned to hard-registers, cost of the allocnos assigned
    562    to memory, cost of loads, stores and register move insns generated
    563    for pseudo-register live range splitting (see ira-emit.c).  */
    564 extern int ira_overall_cost;
    565 extern int ira_reg_cost, ira_mem_cost;
    566 extern int ira_load_cost, ira_store_cost, ira_shuffle_cost;
    567 extern int ira_move_loops_num, ira_additional_jumps_num;
    568 
    569 /* Maximal value of element of array ira_reg_class_nregs.  */
    570 extern int ira_max_nregs;
    571 
    572 /* The number of bits in each element of array used to implement a bit
    573    vector of allocnos and what type that element has.  We use the
    574    largest integer format on the host machine.  */
    575 #define IRA_INT_BITS HOST_BITS_PER_WIDE_INT
    576 #define IRA_INT_TYPE HOST_WIDE_INT
    577 
    578 /* Set, clear or test bit number I in R, a bit vector of elements with
    579    minimal index and maximal index equal correspondingly to MIN and
    580    MAX.  */
    581 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
    582 
    583 #define SET_ALLOCNO_SET_BIT(R, I, MIN, MAX) __extension__	        \
    584   (({ int _min = (MIN), _max = (MAX), _i = (I);				\
    585      if (_i < _min || _i > _max)					\
    586        {								\
    587          fprintf (stderr,						\
    588                   "\n%s: %d: error in %s: %d not in range [%d,%d]\n",   \
    589                   __FILE__, __LINE__, __FUNCTION__, _i, _min, _max);	\
    590          gcc_unreachable ();						\
    591        }								\
    592      ((R)[(unsigned) (_i - _min) / IRA_INT_BITS]			\
    593       |= ((IRA_INT_TYPE) 1 << ((unsigned) (_i - _min) % IRA_INT_BITS))); }))
    594 
    595 
    596 #define CLEAR_ALLOCNO_SET_BIT(R, I, MIN, MAX) __extension__	        \
    597   (({ int _min = (MIN), _max = (MAX), _i = (I);				\
    598      if (_i < _min || _i > _max)					\
    599        {								\
    600          fprintf (stderr,						\
    601                   "\n%s: %d: error in %s: %d not in range [%d,%d]\n",   \
    602                   __FILE__, __LINE__, __FUNCTION__, _i, _min, _max);	\
    603          gcc_unreachable ();						\
    604        }								\
    605      ((R)[(unsigned) (_i - _min) / IRA_INT_BITS]			\
    606       &= ~((IRA_INT_TYPE) 1 << ((unsigned) (_i - _min) % IRA_INT_BITS))); }))
    607 
    608 #define TEST_ALLOCNO_SET_BIT(R, I, MIN, MAX) __extension__	        \
    609   (({ int _min = (MIN), _max = (MAX), _i = (I);				\
    610      if (_i < _min || _i > _max)					\
    611        {								\
    612          fprintf (stderr,						\
    613                   "\n%s: %d: error in %s: %d not in range [%d,%d]\n",   \
    614                   __FILE__, __LINE__, __FUNCTION__, _i, _min, _max);	\
    615          gcc_unreachable ();						\
    616        }								\
    617      ((R)[(unsigned) (_i - _min) / IRA_INT_BITS]			\
    618       & ((IRA_INT_TYPE) 1 << ((unsigned) (_i - _min) % IRA_INT_BITS))); }))
    619 
    620 #else
    621 
    622 #define SET_ALLOCNO_SET_BIT(R, I, MIN, MAX)			\
    623   ((R)[(unsigned) ((I) - (MIN)) / IRA_INT_BITS]			\
    624    |= ((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
    625 
    626 #define CLEAR_ALLOCNO_SET_BIT(R, I, MIN, MAX)			\
    627   ((R)[(unsigned) ((I) - (MIN)) / IRA_INT_BITS]			\
    628    &= ~((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
    629 
    630 #define TEST_ALLOCNO_SET_BIT(R, I, MIN, MAX)			\
    631   ((R)[(unsigned) ((I) - (MIN)) / IRA_INT_BITS]			\
    632    & ((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
    633 
    634 #endif
    635 
    636 /* The iterator for allocno set implemented ed as allocno bit
    637    vector.  */
    638 typedef struct {
    639 
    640   /* Array containing the allocno bit vector.  */
    641   IRA_INT_TYPE *vec;
    642 
    643   /* The number of the current element in the vector.  */
    644   unsigned int word_num;
    645 
    646   /* The number of bits in the bit vector.  */
    647   unsigned int nel;
    648 
    649   /* The current bit index of the bit vector.  */
    650   unsigned int bit_num;
    651 
    652   /* Index corresponding to the 1st bit of the bit vector.   */
    653   int start_val;
    654 
    655   /* The word of the bit vector currently visited.  */
    656   unsigned IRA_INT_TYPE word;
    657 } ira_allocno_set_iterator;
    658 
    659 /* Initialize the iterator I for allocnos bit vector VEC containing
    660    minimal and maximal values MIN and MAX.  */
    661 static inline void
    662 ira_allocno_set_iter_init (ira_allocno_set_iterator *i,
    663 			   IRA_INT_TYPE *vec, int min, int max)
    664 {
    665   i->vec = vec;
    666   i->word_num = 0;
    667   i->nel = max < min ? 0 : max - min + 1;
    668   i->start_val = min;
    669   i->bit_num = 0;
    670   i->word = i->nel == 0 ? 0 : vec[0];
    671 }
    672 
    673 /* Return TRUE if we have more allocnos to visit, in which case *N is
    674    set to the allocno number to be visited.  Otherwise, return
    675    FALSE.  */
    676 static inline bool
    677 ira_allocno_set_iter_cond (ira_allocno_set_iterator *i, int *n)
    678 {
    679   /* Skip words that are zeros.  */
    680   for (; i->word == 0; i->word = i->vec[i->word_num])
    681     {
    682       i->word_num++;
    683       i->bit_num = i->word_num * IRA_INT_BITS;
    684 
    685       /* If we have reached the end, break.  */
    686       if (i->bit_num >= i->nel)
    687 	return false;
    688     }
    689 
    690   /* Skip bits that are zero.  */
    691   for (; (i->word & 1) == 0; i->word >>= 1)
    692     i->bit_num++;
    693 
    694   *n = (int) i->bit_num + i->start_val;
    695 
    696   return true;
    697 }
    698 
    699 /* Advance to the next allocno in the set.  */
    700 static inline void
    701 ira_allocno_set_iter_next (ira_allocno_set_iterator *i)
    702 {
    703   i->word >>= 1;
    704   i->bit_num++;
    705 }
    706 
    707 /* Loop over all elements of allocno set given by bit vector VEC and
    708    their minimal and maximal values MIN and MAX.  In each iteration, N
    709    is set to the number of next allocno.  ITER is an instance of
    710    ira_allocno_set_iterator used to iterate the allocnos in the set.  */
    711 #define FOR_EACH_ALLOCNO_IN_SET(VEC, MIN, MAX, N, ITER)		\
    712   for (ira_allocno_set_iter_init (&(ITER), (VEC), (MIN), (MAX));	\
    713        ira_allocno_set_iter_cond (&(ITER), &(N));			\
    714        ira_allocno_set_iter_next (&(ITER)))
    715 
    716 /* ira.c: */
    717 
    718 /* Map: hard regs X modes -> set of hard registers for storing value
    719    of given mode starting with given hard register.  */
    720 extern HARD_REG_SET ira_reg_mode_hard_regset
    721                     [FIRST_PSEUDO_REGISTER][NUM_MACHINE_MODES];
    722 
    723 /* Array analogous to macro REGISTER_MOVE_COST.  Don't use
    724    ira_register_move_cost directly.  Use function of
    725    ira_get_may_move_cost instead.  */
    726 extern move_table *ira_register_move_cost[MAX_MACHINE_MODE];
    727 
    728 /* Similar to may_move_in_cost but it is calculated in IRA instead of
    729    regclass.  Another difference we take only available hard registers
    730    into account to figure out that one register class is a subset of
    731    the another one.  Don't use it directly.  Use function of
    732    ira_get_may_move_cost instead.  */
    733 extern move_table *ira_may_move_in_cost[MAX_MACHINE_MODE];
    734 
    735 /* Similar to may_move_out_cost but it is calculated in IRA instead of
    736    regclass.  Another difference we take only available hard registers
    737    into account to figure out that one register class is a subset of
    738    the another one.  Don't use it directly.  Use function of
    739    ira_get_may_move_cost instead.  */
    740 extern move_table *ira_may_move_out_cost[MAX_MACHINE_MODE];
    741 
    742 /* Register class subset relation: TRUE if the first class is a subset
    743    of the second one considering only hard registers available for the
    744    allocation.  */
    745 extern int ira_class_subset_p[N_REG_CLASSES][N_REG_CLASSES];
    746 
    747 /* Index (in ira_class_hard_regs) for given register class and hard
    748    register (in general case a hard register can belong to several
    749    register classes).  The index is negative for hard registers
    750    unavailable for the allocation. */
    751 extern short ira_class_hard_reg_index[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
    752 
    753 /* Array whose values are hard regset of hard registers available for
    754    the allocation of given register class whose HARD_REGNO_MODE_OK
    755    values for given mode are zero.  */
    756 extern HARD_REG_SET prohibited_class_mode_regs
    757                     [N_REG_CLASSES][NUM_MACHINE_MODES];
    758 
    759 /* Array whose values are hard regset of hard registers for which
    760    move of the hard register in given mode into itself is
    761    prohibited.  */
    762 extern HARD_REG_SET ira_prohibited_mode_move_regs[NUM_MACHINE_MODES];
    763 
    764 /* The value is number of elements in the subsequent array.  */
    765 extern int ira_important_classes_num;
    766 
    767 /* The array containing non-empty classes (including non-empty cover
    768    classes) which are subclasses of cover classes.  Such classes is
    769    important for calculation of the hard register usage costs.  */
    770 extern enum reg_class ira_important_classes[N_REG_CLASSES];
    771 
    772 /* The array containing indexes of important classes in the previous
    773    array.  The array elements are defined only for important
    774    classes.  */
    775 extern int ira_important_class_nums[N_REG_CLASSES];
    776 
    777 /* The biggest important class inside of intersection of the two
    778    classes (that is calculated taking only hard registers available
    779    for allocation into account).  If the both classes contain no hard
    780    registers available for allocation, the value is calculated with
    781    taking all hard-registers including fixed ones into account.  */
    782 extern enum reg_class ira_reg_class_intersect[N_REG_CLASSES][N_REG_CLASSES];
    783 
    784 /* True if the two classes (that is calculated taking only hard
    785    registers available for allocation into account) are
    786    intersected.  */
    787 extern bool ira_reg_classes_intersect_p[N_REG_CLASSES][N_REG_CLASSES];
    788 
    789 /* Classes with end marker LIM_REG_CLASSES which are intersected with
    790    given class (the first index).  That includes given class itself.
    791    This is calculated taking only hard registers available for
    792    allocation into account.  */
    793 extern enum reg_class ira_reg_class_super_classes[N_REG_CLASSES][N_REG_CLASSES];
    794 /* The biggest important class inside of union of the two classes
    795    (that is calculated taking only hard registers available for
    796    allocation into account).  If the both classes contain no hard
    797    registers available for allocation, the value is calculated with
    798    taking all hard-registers including fixed ones into account.  In
    799    other words, the value is the corresponding reg_class_subunion
    800    value.  */
    801 extern enum reg_class ira_reg_class_union[N_REG_CLASSES][N_REG_CLASSES];
    802 
    803 extern void *ira_allocate (size_t);
    804 extern void *ira_reallocate (void *, size_t);
    805 extern void ira_free (void *addr);
    806 extern bitmap ira_allocate_bitmap (void);
    807 extern void ira_free_bitmap (bitmap);
    808 extern void ira_print_disposition (FILE *);
    809 extern void ira_debug_disposition (void);
    810 extern void ira_debug_class_cover (void);
    811 extern void ira_init_register_move_cost (enum machine_mode);
    812 
    813 /* The length of the two following arrays.  */
    814 extern int ira_reg_equiv_len;
    815 
    816 /* The element value is TRUE if the corresponding regno value is
    817    invariant.  */
    818 extern bool *ira_reg_equiv_invariant_p;
    819 
    820 /* The element value is equiv constant of given pseudo-register or
    821    NULL_RTX.  */
    822 extern rtx *ira_reg_equiv_const;
    823 
    824 /* ira-build.c */
    825 
    826 /* The current loop tree node and its regno allocno map.  */
    827 extern ira_loop_tree_node_t ira_curr_loop_tree_node;
    828 extern ira_allocno_t *ira_curr_regno_allocno_map;
    829 
    830 extern void ira_debug_copy (ira_copy_t);
    831 extern void ira_debug_copies (void);
    832 extern void ira_debug_allocno_copies (ira_allocno_t);
    833 
    834 extern void ira_traverse_loop_tree (bool, ira_loop_tree_node_t,
    835 				    void (*) (ira_loop_tree_node_t),
    836 				    void (*) (ira_loop_tree_node_t));
    837 extern ira_allocno_t ira_create_allocno (int, bool, ira_loop_tree_node_t);
    838 extern void ira_set_allocno_cover_class (ira_allocno_t, enum reg_class);
    839 extern bool ira_conflict_vector_profitable_p (ira_allocno_t, int);
    840 extern void ira_allocate_allocno_conflict_vec (ira_allocno_t, int);
    841 extern void ira_allocate_allocno_conflicts (ira_allocno_t, int);
    842 extern void ira_add_allocno_conflict (ira_allocno_t, ira_allocno_t);
    843 extern void ira_print_expanded_allocno (ira_allocno_t);
    844 extern allocno_live_range_t ira_create_allocno_live_range
    845 	                    (ira_allocno_t, int, int, allocno_live_range_t);
    846 extern allocno_live_range_t ira_copy_allocno_live_range_list
    847                             (allocno_live_range_t);
    848 extern allocno_live_range_t ira_merge_allocno_live_ranges
    849                             (allocno_live_range_t, allocno_live_range_t);
    850 extern bool ira_allocno_live_ranges_intersect_p (allocno_live_range_t,
    851 						 allocno_live_range_t);
    852 extern void ira_finish_allocno_live_range (allocno_live_range_t);
    853 extern void ira_finish_allocno_live_range_list (allocno_live_range_t);
    854 extern void ira_free_allocno_updated_costs (ira_allocno_t);
    855 extern ira_copy_t ira_create_copy (ira_allocno_t, ira_allocno_t,
    856 				   int, bool, rtx, ira_loop_tree_node_t);
    857 extern void ira_add_allocno_copy_to_list (ira_copy_t);
    858 extern void ira_swap_allocno_copy_ends_if_necessary (ira_copy_t);
    859 extern void ira_remove_allocno_copy_from_list (ira_copy_t);
    860 extern ira_copy_t ira_add_allocno_copy (ira_allocno_t, ira_allocno_t, int,
    861 					bool, rtx, ira_loop_tree_node_t);
    862 
    863 extern int *ira_allocate_cost_vector (enum reg_class);
    864 extern void ira_free_cost_vector (int *, enum reg_class);
    865 
    866 extern void ira_flattening (int, int);
    867 extern bool ira_build (bool);
    868 extern void ira_destroy (void);
    869 
    870 /* ira-costs.c */
    871 extern void ira_init_costs_once (void);
    872 extern void ira_init_costs (void);
    873 extern void ira_finish_costs_once (void);
    874 extern void ira_costs (void);
    875 extern void ira_tune_allocno_costs_and_cover_classes (void);
    876 
    877 /* ira-lives.c */
    878 
    879 extern void ira_rebuild_start_finish_chains (void);
    880 extern void ira_print_live_range_list (FILE *, allocno_live_range_t);
    881 extern void ira_debug_live_range_list (allocno_live_range_t);
    882 extern void ira_debug_allocno_live_ranges (ira_allocno_t);
    883 extern void ira_debug_live_ranges (void);
    884 extern void ira_create_allocno_live_ranges (void);
    885 extern void ira_compress_allocno_live_ranges (void);
    886 extern void ira_finish_allocno_live_ranges (void);
    887 
    888 /* ira-conflicts.c */
    889 extern void ira_debug_conflicts (bool);
    890 extern void ira_build_conflicts (void);
    891 
    892 /* ira-color.c */
    893 extern int ira_loop_edge_freq (ira_loop_tree_node_t, int, bool);
    894 extern void ira_reassign_conflict_allocnos (int);
    895 extern void ira_initiate_assign (void);
    896 extern void ira_finish_assign (void);
    897 extern void ira_color (void);
    898 
    899 /* ira-emit.c */
    900 extern void ira_emit (bool);
    901 
    902 
    903 
    905 /* Return cost of moving value of MODE from register of class FROM to
    906    register of class TO.  */
    907 static inline int
    908 ira_get_register_move_cost (enum machine_mode mode,
    909 			    enum reg_class from, enum reg_class to)
    910 {
    911   if (ira_register_move_cost[mode] == NULL)
    912     ira_init_register_move_cost (mode);
    913   return ira_register_move_cost[mode][from][to];
    914 }
    915 
    916 /* Return cost of moving value of MODE from register of class FROM to
    917    register of class TO.  Return zero if IN_P is true and FROM is
    918    subset of TO or if IN_P is false and FROM is superset of TO.  */
    919 static inline int
    920 ira_get_may_move_cost (enum machine_mode mode,
    921 		       enum reg_class from, enum reg_class to,
    922 		       bool in_p)
    923 {
    924   if (ira_register_move_cost[mode] == NULL)
    925     ira_init_register_move_cost (mode);
    926   return (in_p
    927 	  ? ira_may_move_in_cost[mode][from][to]
    928 	  : ira_may_move_out_cost[mode][from][to]);
    929 }
    930 
    931 
    932 
    934 /* The iterator for all allocnos.  */
    935 typedef struct {
    936   /* The number of the current element in IRA_ALLOCNOS.  */
    937   int n;
    938 } ira_allocno_iterator;
    939 
    940 /* Initialize the iterator I.  */
    941 static inline void
    942 ira_allocno_iter_init (ira_allocno_iterator *i)
    943 {
    944   i->n = 0;
    945 }
    946 
    947 /* Return TRUE if we have more allocnos to visit, in which case *A is
    948    set to the allocno to be visited.  Otherwise, return FALSE.  */
    949 static inline bool
    950 ira_allocno_iter_cond (ira_allocno_iterator *i, ira_allocno_t *a)
    951 {
    952   int n;
    953 
    954   for (n = i->n; n < ira_allocnos_num; n++)
    955     if (ira_allocnos[n] != NULL)
    956       {
    957 	*a = ira_allocnos[n];
    958 	i->n = n + 1;
    959 	return true;
    960       }
    961   return false;
    962 }
    963 
    964 /* Loop over all allocnos.  In each iteration, A is set to the next
    965    allocno.  ITER is an instance of ira_allocno_iterator used to iterate
    966    the allocnos.  */
    967 #define FOR_EACH_ALLOCNO(A, ITER)			\
    968   for (ira_allocno_iter_init (&(ITER));			\
    969        ira_allocno_iter_cond (&(ITER), &(A));)
    970 
    971 
    972 
    973 
    975 /* The iterator for copies.  */
    976 typedef struct {
    977   /* The number of the current element in IRA_COPIES.  */
    978   int n;
    979 } ira_copy_iterator;
    980 
    981 /* Initialize the iterator I.  */
    982 static inline void
    983 ira_copy_iter_init (ira_copy_iterator *i)
    984 {
    985   i->n = 0;
    986 }
    987 
    988 /* Return TRUE if we have more copies to visit, in which case *CP is
    989    set to the copy to be visited.  Otherwise, return FALSE.  */
    990 static inline bool
    991 ira_copy_iter_cond (ira_copy_iterator *i, ira_copy_t *cp)
    992 {
    993   int n;
    994 
    995   for (n = i->n; n < ira_copies_num; n++)
    996     if (ira_copies[n] != NULL)
    997       {
    998 	*cp = ira_copies[n];
    999 	i->n = n + 1;
   1000 	return true;
   1001       }
   1002   return false;
   1003 }
   1004 
   1005 /* Loop over all copies.  In each iteration, C is set to the next
   1006    copy.  ITER is an instance of ira_copy_iterator used to iterate
   1007    the copies.  */
   1008 #define FOR_EACH_COPY(C, ITER)				\
   1009   for (ira_copy_iter_init (&(ITER));			\
   1010        ira_copy_iter_cond (&(ITER), &(C));)
   1011 
   1012 
   1013 
   1014 
   1016 /* The iterator for allocno conflicts.  */
   1017 typedef struct {
   1018 
   1019   /* TRUE if the conflicts are represented by vector of allocnos.  */
   1020   bool allocno_conflict_vec_p;
   1021 
   1022   /* The conflict vector or conflict bit vector.  */
   1023   void *vec;
   1024 
   1025   /* The number of the current element in the vector (of type
   1026      ira_allocno_t or IRA_INT_TYPE).  */
   1027   unsigned int word_num;
   1028 
   1029   /* The bit vector size.  It is defined only if
   1030      ALLOCNO_CONFLICT_VEC_P is FALSE.  */
   1031   unsigned int size;
   1032 
   1033   /* The current bit index of bit vector.  It is defined only if
   1034      ALLOCNO_CONFLICT_VEC_P is FALSE.  */
   1035   unsigned int bit_num;
   1036 
   1037   /* Allocno conflict id corresponding to the 1st bit of the bit
   1038      vector.  It is defined only if ALLOCNO_CONFLICT_VEC_P is
   1039      FALSE.  */
   1040   int base_conflict_id;
   1041 
   1042   /* The word of bit vector currently visited.  It is defined only if
   1043      ALLOCNO_CONFLICT_VEC_P is FALSE.  */
   1044   unsigned IRA_INT_TYPE word;
   1045 } ira_allocno_conflict_iterator;
   1046 
   1047 /* Initialize the iterator I with ALLOCNO conflicts.  */
   1048 static inline void
   1049 ira_allocno_conflict_iter_init (ira_allocno_conflict_iterator *i,
   1050 				ira_allocno_t allocno)
   1051 {
   1052   i->allocno_conflict_vec_p = ALLOCNO_CONFLICT_VEC_P (allocno);
   1053   i->vec = ALLOCNO_CONFLICT_ALLOCNO_ARRAY (allocno);
   1054   i->word_num = 0;
   1055   if (i->allocno_conflict_vec_p)
   1056     i->size = i->bit_num = i->base_conflict_id = i->word = 0;
   1057   else
   1058     {
   1059       if (ALLOCNO_MIN (allocno) > ALLOCNO_MAX (allocno))
   1060 	i->size = 0;
   1061       else
   1062 	i->size = ((ALLOCNO_MAX (allocno) - ALLOCNO_MIN (allocno)
   1063 		    + IRA_INT_BITS)
   1064 		   / IRA_INT_BITS) * sizeof (IRA_INT_TYPE);
   1065       i->bit_num = 0;
   1066       i->base_conflict_id = ALLOCNO_MIN (allocno);
   1067       i->word = (i->size == 0 ? 0 : ((IRA_INT_TYPE *) i->vec)[0]);
   1068     }
   1069 }
   1070 
   1071 /* Return TRUE if we have more conflicting allocnos to visit, in which
   1072    case *A is set to the allocno to be visited.  Otherwise, return
   1073    FALSE.  */
   1074 static inline bool
   1075 ira_allocno_conflict_iter_cond (ira_allocno_conflict_iterator *i,
   1076 				ira_allocno_t *a)
   1077 {
   1078   ira_allocno_t conflict_allocno;
   1079 
   1080   if (i->allocno_conflict_vec_p)
   1081     {
   1082       conflict_allocno = ((ira_allocno_t *) i->vec)[i->word_num];
   1083       if (conflict_allocno == NULL)
   1084 	return false;
   1085       *a = conflict_allocno;
   1086       return true;
   1087     }
   1088   else
   1089     {
   1090       /* Skip words that are zeros.  */
   1091       for (; i->word == 0; i->word = ((IRA_INT_TYPE *) i->vec)[i->word_num])
   1092 	{
   1093 	  i->word_num++;
   1094 
   1095 	  /* If we have reached the end, break.  */
   1096 	  if (i->word_num * sizeof (IRA_INT_TYPE) >= i->size)
   1097 	    return false;
   1098 
   1099 	  i->bit_num = i->word_num * IRA_INT_BITS;
   1100 	}
   1101 
   1102       /* Skip bits that are zero.  */
   1103       for (; (i->word & 1) == 0; i->word >>= 1)
   1104 	i->bit_num++;
   1105 
   1106       *a = ira_conflict_id_allocno_map[i->bit_num + i->base_conflict_id];
   1107 
   1108       return true;
   1109     }
   1110 }
   1111 
   1112 /* Advance to the next conflicting allocno.  */
   1113 static inline void
   1114 ira_allocno_conflict_iter_next (ira_allocno_conflict_iterator *i)
   1115 {
   1116   if (i->allocno_conflict_vec_p)
   1117     i->word_num++;
   1118   else
   1119     {
   1120       i->word >>= 1;
   1121       i->bit_num++;
   1122     }
   1123 }
   1124 
   1125 /* Loop over all allocnos conflicting with ALLOCNO.  In each
   1126    iteration, A is set to the next conflicting allocno.  ITER is an
   1127    instance of ira_allocno_conflict_iterator used to iterate the
   1128    conflicts.  */
   1129 #define FOR_EACH_ALLOCNO_CONFLICT(ALLOCNO, A, ITER)			\
   1130   for (ira_allocno_conflict_iter_init (&(ITER), (ALLOCNO));		\
   1131        ira_allocno_conflict_iter_cond (&(ITER), &(A));			\
   1132        ira_allocno_conflict_iter_next (&(ITER)))
   1133 
   1134 
   1135 
   1137 /* The function returns TRUE if hard registers starting with
   1138    HARD_REGNO and containing value of MODE are not in set
   1139    HARD_REGSET.  */
   1140 static inline bool
   1141 ira_hard_reg_not_in_set_p (int hard_regno, enum machine_mode mode,
   1142 			   HARD_REG_SET hard_regset)
   1143 {
   1144   int i;
   1145 
   1146   ira_assert (hard_regno >= 0);
   1147   for (i = hard_regno_nregs[hard_regno][mode] - 1; i >= 0; i--)
   1148     if (TEST_HARD_REG_BIT (hard_regset, hard_regno + i))
   1149       return false;
   1150   return true;
   1151 }
   1152 
   1153 
   1154 
   1156 /* To save memory we use a lazy approach for allocation and
   1157    initialization of the cost vectors.  We do this only when it is
   1158    really necessary.  */
   1159 
   1160 /* Allocate cost vector *VEC for hard registers of COVER_CLASS and
   1161    initialize the elements by VAL if it is necessary */
   1162 static inline void
   1163 ira_allocate_and_set_costs (int **vec, enum reg_class cover_class, int val)
   1164 {
   1165   int i, *reg_costs;
   1166   int len;
   1167 
   1168   if (*vec != NULL)
   1169     return;
   1170   *vec = reg_costs = ira_allocate_cost_vector (cover_class);
   1171   len = ira_class_hard_regs_num[cover_class];
   1172   for (i = 0; i < len; i++)
   1173     reg_costs[i] = val;
   1174 }
   1175 
   1176 /* Allocate cost vector *VEC for hard registers of COVER_CLASS and
   1177    copy values of vector SRC into the vector if it is necessary */
   1178 static inline void
   1179 ira_allocate_and_copy_costs (int **vec, enum reg_class cover_class, int *src)
   1180 {
   1181   int len;
   1182 
   1183   if (*vec != NULL || src == NULL)
   1184     return;
   1185   *vec = ira_allocate_cost_vector (cover_class);
   1186   len = ira_class_hard_regs_num[cover_class];
   1187   memcpy (*vec, src, sizeof (int) * len);
   1188 }
   1189 
   1190 /* Allocate cost vector *VEC for hard registers of COVER_CLASS and
   1191    add values of vector SRC into the vector if it is necessary */
   1192 static inline void
   1193 ira_allocate_and_accumulate_costs (int **vec, enum reg_class cover_class,
   1194 				   int *src)
   1195 {
   1196   int i, len;
   1197 
   1198   if (src == NULL)
   1199     return;
   1200   len = ira_class_hard_regs_num[cover_class];
   1201   if (*vec == NULL)
   1202     {
   1203       *vec = ira_allocate_cost_vector (cover_class);
   1204       memset (*vec, 0, sizeof (int) * len);
   1205     }
   1206   for (i = 0; i < len; i++)
   1207     (*vec)[i] += src[i];
   1208 }
   1209 
   1210 /* Allocate cost vector *VEC for hard registers of COVER_CLASS and
   1211    copy values of vector SRC into the vector or initialize it by VAL
   1212    (if SRC is null).  */
   1213 static inline void
   1214 ira_allocate_and_set_or_copy_costs (int **vec, enum reg_class cover_class,
   1215 				    int val, int *src)
   1216 {
   1217   int i, *reg_costs;
   1218   int len;
   1219 
   1220   if (*vec != NULL)
   1221     return;
   1222   *vec = reg_costs = ira_allocate_cost_vector (cover_class);
   1223   len = ira_class_hard_regs_num[cover_class];
   1224   if (src != NULL)
   1225     memcpy (reg_costs, src, sizeof (int) * len);
   1226   else
   1227     {
   1228       for (i = 0; i < len; i++)
   1229 	reg_costs[i] = val;
   1230     }
   1231 }
   1232