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