comparison gcc/ira-int.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Integrated Register Allocator (IRA) intercommunication header file. 1 /* Integrated Register Allocator (IRA) intercommunication header file.
2 Copyright (C) 2006, 2007, 2008, 2009, 2010 2 Copyright (C) 2006-2017 Free Software Foundation, Inc.
3 Free Software Foundation, Inc.
4 Contributed by Vladimir Makarov <vmakarov@redhat.com>. 3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5 4
6 This file is part of GCC. 5 This file is part of GCC.
7 6
8 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
17 16
18 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see 18 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */ 19 <http://www.gnu.org/licenses/>. */
21 20
22 #include "cfgloop.h" 21 #ifndef GCC_IRA_INT_H
23 #include "ira.h" 22 #define GCC_IRA_INT_H
24 #include "alloc-pool.h" 23
24 #include "recog.h"
25 25
26 /* To provide consistency in naming, all IRA external variables, 26 /* To provide consistency in naming, all IRA external variables,
27 functions, common typedefs start with prefix ira_. */ 27 functions, common typedefs start with prefix ira_. */
28 28
29 #ifdef ENABLE_CHECKING 29 #if CHECKING_P
30 #define ENABLE_IRA_CHECKING 30 #define ENABLE_IRA_CHECKING
31 #endif 31 #endif
32 32
33 #ifdef ENABLE_IRA_CHECKING 33 #ifdef ENABLE_IRA_CHECKING
34 #define ira_assert(c) gcc_assert (c) 34 #define ira_assert(c) gcc_assert (c)
35 #else 35 #else
36 /* Always define and include C, so that warnings for empty body in an 36 /* Always define and include C, so that warnings for empty body in an
37 ‘if’ statement and unused variable do not occur. */ 37 'if' statement and unused variable do not occur. */
38 #define ira_assert(c) ((void)(0 && (c))) 38 #define ira_assert(c) ((void)(0 && (c)))
39 #endif 39 #endif
40 40
41 /* Compute register frequency from edge frequency FREQ. It is 41 /* Compute register frequency from edge frequency FREQ. It is
42 analogous to REG_FREQ_FROM_BB. When optimizing for size, or 42 analogous to REG_FREQ_FROM_BB. When optimizing for size, or
43 profile driven feedback is available and the function is never 43 profile driven feedback is available and the function is never
44 executed, frequency is always equivalent. Otherwise rescale the 44 executed, frequency is always equivalent. Otherwise rescale the
45 edge frequency. */ 45 edge frequency. */
46 #define REG_FREQ_FROM_EDGE_FREQ(freq) \ 46 #define REG_FREQ_FROM_EDGE_FREQ(freq) \
47 (optimize_size || (flag_branch_probabilities && !ENTRY_BLOCK_PTR->count) \ 47 (optimize_function_for_size_p (cfun) \
48 ? REG_FREQ_MAX : (freq * REG_FREQ_MAX / BB_FREQ_MAX) \ 48 ? REG_FREQ_MAX : (freq * REG_FREQ_MAX / BB_FREQ_MAX) \
49 ? (freq * REG_FREQ_MAX / BB_FREQ_MAX) : 1) 49 ? (freq * REG_FREQ_MAX / BB_FREQ_MAX) : 1)
50
51 /* All natural loops. */
52 extern struct loops ira_loops;
53 50
54 /* A modified value of flag `-fira-verbose' used internally. */ 51 /* A modified value of flag `-fira-verbose' used internally. */
55 extern int internal_flag_ira_verbose; 52 extern int internal_flag_ira_verbose;
56 53
57 /* Dump file of the allocator if it is not NULL. */ 54 /* Dump file of the allocator if it is not NULL. */
59 56
60 /* Typedefs for pointers to allocno live range, allocno, and copy of 57 /* Typedefs for pointers to allocno live range, allocno, and copy of
61 allocnos. */ 58 allocnos. */
62 typedef struct live_range *live_range_t; 59 typedef struct live_range *live_range_t;
63 typedef struct ira_allocno *ira_allocno_t; 60 typedef struct ira_allocno *ira_allocno_t;
61 typedef struct ira_allocno_pref *ira_pref_t;
64 typedef struct ira_allocno_copy *ira_copy_t; 62 typedef struct ira_allocno_copy *ira_copy_t;
65 typedef struct ira_object *ira_object_t; 63 typedef struct ira_object *ira_object_t;
66 64
67 /* Definition of vector of allocnos and copies. */ 65 /* Definition of vector of allocnos and copies. */
68 DEF_VEC_P(ira_allocno_t);
69 DEF_VEC_ALLOC_P(ira_allocno_t, heap);
70 DEF_VEC_P(ira_object_t);
71 DEF_VEC_ALLOC_P(ira_object_t, heap);
72 DEF_VEC_P(ira_copy_t);
73 DEF_VEC_ALLOC_P(ira_copy_t, heap);
74 66
75 /* Typedef for pointer to the subsequent structure. */ 67 /* Typedef for pointer to the subsequent structure. */
76 typedef struct ira_loop_tree_node *ira_loop_tree_node_t; 68 typedef struct ira_loop_tree_node *ira_loop_tree_node_t;
69
70 typedef unsigned short move_table[N_REG_CLASSES];
77 71
78 /* In general case, IRA is a regional allocator. The regions are 72 /* In general case, IRA is a regional allocator. The regions are
79 nested and form a tree. Currently regions are natural loops. The 73 nested and form a tree. Currently regions are natural loops. The
80 following structure describes loop tree node (representing basic 74 following structure describes loop tree node (representing basic
81 block or loop). We need such tree because the loop tree from 75 block or loop). We need such tree because the loop tree from
85 register allocation purposes. */ 79 register allocation purposes. */
86 struct ira_loop_tree_node 80 struct ira_loop_tree_node
87 { 81 {
88 /* The node represents basic block if children == NULL. */ 82 /* The node represents basic block if children == NULL. */
89 basic_block bb; /* NULL for loop. */ 83 basic_block bb; /* NULL for loop. */
90 struct loop *loop; /* NULL for BB. */ 84 /* NULL for BB or for loop tree root if we did not build CFG loop tree. */
85 struct loop *loop;
91 /* NEXT/SUBLOOP_NEXT is the next node/loop-node of the same parent. 86 /* NEXT/SUBLOOP_NEXT is the next node/loop-node of the same parent.
92 SUBLOOP_NEXT is always NULL for BBs. */ 87 SUBLOOP_NEXT is always NULL for BBs. */
93 ira_loop_tree_node_t subloop_next, next; 88 ira_loop_tree_node_t subloop_next, next;
94 /* CHILDREN/SUBLOOPS is the first node/loop-node immediately inside 89 /* CHILDREN/SUBLOOPS is the first node/loop-node immediately inside
95 the node. They are NULL for BBs. */ 90 the node. They are NULL for BBs. */
101 int level; 96 int level;
102 97
103 /* All the following members are defined only for nodes representing 98 /* All the following members are defined only for nodes representing
104 loops. */ 99 loops. */
105 100
101 /* The loop number from CFG loop tree. The root number is 0. */
102 int loop_num;
103
106 /* True if the loop was marked for removal from the register 104 /* True if the loop was marked for removal from the register
107 allocation. */ 105 allocation. */
108 bool to_remove_p; 106 bool to_remove_p;
109 107
110 /* Allocnos in the loop corresponding to their regnos. If it is 108 /* Allocnos in the loop corresponding to their regnos. If it is
120 grandparent) basic block. For example, it is possible for two 118 grandparent) basic block. For example, it is possible for two
121 adjacent loops inside another loop. */ 119 adjacent loops inside another loop. */
122 bool entered_from_non_parent_p; 120 bool entered_from_non_parent_p;
123 121
124 /* Maximal register pressure inside loop for given register class 122 /* Maximal register pressure inside loop for given register class
125 (defined only for the cover classes). */ 123 (defined only for the pressure classes). */
126 int reg_pressure[N_REG_CLASSES]; 124 int reg_pressure[N_REG_CLASSES];
127 125
128 /* Numbers of allocnos referred or living in the loop node (except 126 /* Numbers of allocnos referred or living in the loop node (except
129 for its subloops). */ 127 for its subloops). */
130 bitmap all_allocnos; 128 bitmap all_allocnos;
152 extern ira_loop_tree_node_t ira_bb_nodes; 150 extern ira_loop_tree_node_t ira_bb_nodes;
153 151
154 /* Two access macros to the nodes representing basic blocks. */ 152 /* Two access macros to the nodes representing basic blocks. */
155 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007) 153 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
156 #define IRA_BB_NODE_BY_INDEX(index) __extension__ \ 154 #define IRA_BB_NODE_BY_INDEX(index) __extension__ \
157 (({ ira_loop_tree_node_t _node = (&ira_bb_nodes[index]); \ 155 (({ ira_loop_tree_node_t _node = (&ira_bb_nodes[index]); \
158 if (_node->children != NULL || _node->loop != NULL || _node->bb == NULL)\ 156 if (_node->children != NULL || _node->loop != NULL || _node->bb == NULL)\
159 { \ 157 { \
160 fprintf (stderr, \ 158 fprintf (stderr, \
161 "\n%s: %d: error in %s: it is not a block node\n", \ 159 "\n%s: %d: error in %s: it is not a block node\n", \
162 __FILE__, __LINE__, __FUNCTION__); \ 160 __FILE__, __LINE__, __FUNCTION__); \
174 extern ira_loop_tree_node_t ira_loop_nodes; 172 extern ira_loop_tree_node_t ira_loop_nodes;
175 173
176 /* Two access macros to the nodes representing loops. */ 174 /* Two access macros to the nodes representing loops. */
177 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007) 175 #if defined ENABLE_IRA_CHECKING && (GCC_VERSION >= 2007)
178 #define IRA_LOOP_NODE_BY_INDEX(index) __extension__ \ 176 #define IRA_LOOP_NODE_BY_INDEX(index) __extension__ \
179 (({ ira_loop_tree_node_t const _node = (&ira_loop_nodes[index]);\ 177 (({ ira_loop_tree_node_t const _node = (&ira_loop_nodes[index]); \
180 if (_node->children == NULL || _node->bb != NULL || _node->loop == NULL)\ 178 if (_node->children == NULL || _node->bb != NULL \
179 || (_node->loop == NULL && current_loops != NULL)) \
181 { \ 180 { \
182 fprintf (stderr, \ 181 fprintf (stderr, \
183 "\n%s: %d: error in %s: it is not a loop node\n", \ 182 "\n%s: %d: error in %s: it is not a loop node\n", \
184 __FILE__, __LINE__, __FUNCTION__); \ 183 __FILE__, __LINE__, __FUNCTION__); \
185 gcc_unreachable (); \ 184 gcc_unreachable (); \
191 190
192 #define IRA_LOOP_NODE(loop) IRA_LOOP_NODE_BY_INDEX ((loop)->num) 191 #define IRA_LOOP_NODE(loop) IRA_LOOP_NODE_BY_INDEX ((loop)->num)
193 192
194 193
195 /* The structure describes program points where a given allocno lives. 194 /* The structure describes program points where a given allocno lives.
196 To save memory we store allocno conflicts only for the same cover 195 If the live ranges of two allocnos are intersected, the allocnos
197 class allocnos which is enough to assign hard registers. To find 196 are in conflict. */
198 conflicts for other allocnos (e.g. to assign stack memory slot) we
199 use the live ranges. If the live ranges of two allocnos are
200 intersected, the allocnos are in conflict. */
201 struct live_range 197 struct live_range
202 { 198 {
203 /* Object whose live range is described by given structure. */ 199 /* Object whose live range is described by given structure. */
204 ira_object_t object; 200 ira_object_t object;
205 /* Program point range. */ 201 /* Program point range. */
230 { 226 {
231 /* The allocno associated with this record. */ 227 /* The allocno associated with this record. */
232 ira_allocno_t allocno; 228 ira_allocno_t allocno;
233 /* Vector of accumulated conflicting conflict_redords with NULL end 229 /* Vector of accumulated conflicting conflict_redords with NULL end
234 marker (if OBJECT_CONFLICT_VEC_P is true) or conflict bit vector 230 marker (if OBJECT_CONFLICT_VEC_P is true) or conflict bit vector
235 otherwise. Only ira_objects belonging to allocnos with the 231 otherwise. */
236 same cover class are in the vector or in the bit vector. */
237 void *conflicts_array; 232 void *conflicts_array;
238 /* Pointer to structures describing at what program point the 233 /* Pointer to structures describing at what program point the
239 object lives. We always maintain the list in such way that *the 234 object lives. We always maintain the list in such way that *the
240 ranges in the list are not intersected and ordered by decreasing 235 ranges in the list are not intersected and ordered by decreasing
241 their program points*. */ 236 their program points*. */
254 live ranges. Afterwards, they hold the minimal and maximal ids 249 live ranges. Afterwards, they hold the minimal and maximal ids
255 of other ira_objects that this one can conflict with. */ 250 of other ira_objects that this one can conflict with. */
256 int min, max; 251 int min, max;
257 /* Initial and accumulated hard registers conflicting with this 252 /* Initial and accumulated hard registers conflicting with this
258 object and as a consequences can not be assigned to the allocno. 253 object and as a consequences can not be assigned to the allocno.
259 All non-allocatable hard regs and hard regs of cover classes 254 All non-allocatable hard regs and hard regs of register classes
260 different from given allocno one are included in the sets. */ 255 different from given allocno one are included in the sets. */
261 HARD_REG_SET conflict_hard_regs, total_conflict_hard_regs; 256 HARD_REG_SET conflict_hard_regs, total_conflict_hard_regs;
262 /* Number of accumulated conflicts in the vector of conflicting 257 /* Number of accumulated conflicts in the vector of conflicting
263 objects. */ 258 objects. */
264 int num_accumulated_conflicts; 259 int num_accumulated_conflicts;
283 int num; 278 int num;
284 /* Regno for allocno or cap. */ 279 /* Regno for allocno or cap. */
285 int regno; 280 int regno;
286 /* Mode of the allocno which is the mode of the corresponding 281 /* Mode of the allocno which is the mode of the corresponding
287 pseudo-register. */ 282 pseudo-register. */
288 enum machine_mode mode; 283 ENUM_BITFIELD (machine_mode) mode : 8;
284 /* Widest mode of the allocno which in at least one case could be
285 for paradoxical subregs where wmode > mode. */
286 ENUM_BITFIELD (machine_mode) wmode : 8;
287 /* Register class which should be used for allocation for given
288 allocno. NO_REGS means that we should use memory. */
289 ENUM_BITFIELD (reg_class) aclass : 16;
290 /* During the reload, value TRUE means that we should not reassign a
291 hard register to the allocno got memory earlier. It is set up
292 when we removed memory-memory move insn before each iteration of
293 the reload. */
294 unsigned int dont_reassign_p : 1;
295 #ifdef STACK_REGS
296 /* Set to TRUE if allocno can't be assigned to the stack hard
297 register correspondingly in this region and area including the
298 region and all its subregions recursively. */
299 unsigned int no_stack_reg_p : 1, total_no_stack_reg_p : 1;
300 #endif
301 /* TRUE value means that there is no sense to spill the allocno
302 during coloring because the spill will result in additional
303 reloads in reload pass. */
304 unsigned int bad_spill_p : 1;
305 /* TRUE if a hard register or memory has been assigned to the
306 allocno. */
307 unsigned int assigned_p : 1;
308 /* TRUE if conflicts for given allocno are represented by vector of
309 pointers to the conflicting allocnos. Otherwise, we use a bit
310 vector where a bit with given index represents allocno with the
311 same number. */
312 unsigned int conflict_vec_p : 1;
289 /* Hard register assigned to given allocno. Negative value means 313 /* Hard register assigned to given allocno. Negative value means
290 that memory was allocated to the allocno. During the reload, 314 that memory was allocated to the allocno. During the reload,
291 spilled allocno has value equal to the corresponding stack slot 315 spilled allocno has value equal to the corresponding stack slot
292 number (0, ...) - 2. Value -1 is used for allocnos spilled by the 316 number (0, ...) - 2. Value -1 is used for allocnos spilled by the
293 reload (at this point pseudo-register has only one allocno) which 317 reload (at this point pseudo-register has only one allocno) which
294 did not get stack slot yet. */ 318 did not get stack slot yet. */
295 int hard_regno; 319 signed int hard_regno : 16;
296 /* Final rtx representation of the allocno. */
297 rtx reg;
298 /* Allocnos with the same regno are linked by the following member. 320 /* Allocnos with the same regno are linked by the following member.
299 Allocnos corresponding to inner loops are first in the list (it 321 Allocnos corresponding to inner loops are first in the list (it
300 corresponds to depth-first traverse of the loops). */ 322 corresponds to depth-first traverse of the loops). */
301 ira_allocno_t next_regno_allocno; 323 ira_allocno_t next_regno_allocno;
302 /* There may be different allocnos with the same regno in different 324 /* There may be different allocnos with the same regno in different
310 of the corresponding pseudo-register in this region and in all 332 of the corresponding pseudo-register in this region and in all
311 nested subregions recursively. */ 333 nested subregions recursively. */
312 int nrefs; 334 int nrefs;
313 /* Accumulated frequency of usage of the allocno. */ 335 /* Accumulated frequency of usage of the allocno. */
314 int freq; 336 int freq;
315 /* Register class which should be used for allocation for given
316 allocno. NO_REGS means that we should use memory. */
317 enum reg_class cover_class;
318 /* Minimal accumulated and updated costs of usage register of the 337 /* Minimal accumulated and updated costs of usage register of the
319 cover class for the allocno. */ 338 allocno class. */
320 int cover_class_cost, updated_cover_class_cost; 339 int class_cost, updated_class_cost;
321 /* Minimal accumulated, and updated costs of memory for the allocno. 340 /* Minimal accumulated, and updated costs of memory for the allocno.
322 At the allocation start, the original and updated costs are 341 At the allocation start, the original and updated costs are
323 equal. The updated cost may be changed after finishing 342 equal. The updated cost may be changed after finishing
324 allocation in a region and starting allocation in a subregion. 343 allocation in a region and starting allocation in a subregion.
325 The change reflects the cost of spill/restore code on the 344 The change reflects the cost of spill/restore code on the
330 excess pressure for its class. Excess pressure for a register 349 excess pressure for its class. Excess pressure for a register
331 class at some point means that there are more allocnos of given 350 class at some point means that there are more allocnos of given
332 register class living at the point than number of hard-registers 351 register class living at the point than number of hard-registers
333 of the class available for the allocation. */ 352 of the class available for the allocation. */
334 int excess_pressure_points_num; 353 int excess_pressure_points_num;
354 /* Allocno hard reg preferences. */
355 ira_pref_t allocno_prefs;
335 /* Copies to other non-conflicting allocnos. The copies can 356 /* Copies to other non-conflicting allocnos. The copies can
336 represent move insn or potential move insn usually because of two 357 represent move insn or potential move insn usually because of two
337 operand insn constraints. */ 358 operand insn constraints. */
338 ira_copy_t allocno_copies; 359 ira_copy_t allocno_copies;
339 /* It is a allocno (cap) representing given allocno on upper loop tree 360 /* It is a allocno (cap) representing given allocno on upper loop tree
340 level. */ 361 level. */
341 ira_allocno_t cap; 362 ira_allocno_t cap;
342 /* It is a link to allocno (cap) on lower loop level represented by 363 /* It is a link to allocno (cap) on lower loop level represented by
343 given cap. Null if given allocno is not a cap. */ 364 given cap. Null if given allocno is not a cap. */
344 ira_allocno_t cap_member; 365 ira_allocno_t cap_member;
345 /* Coalesced allocnos form a cyclic list. One allocno given by
346 FIRST_COALESCED_ALLOCNO represents all coalesced allocnos. The
347 list is chained by NEXT_COALESCED_ALLOCNO. */
348 ira_allocno_t first_coalesced_allocno;
349 ira_allocno_t next_coalesced_allocno;
350 /* The number of objects tracked in the following array. */ 366 /* The number of objects tracked in the following array. */
351 int num_objects; 367 int num_objects;
352 /* An array of structures describing conflict information and live 368 /* An array of structures describing conflict information and live
353 ranges for each object associated with the allocno. There may be 369 ranges for each object associated with the allocno. There may be
354 more than one such object in cases where the allocno represents a 370 more than one such object in cases where the allocno represents a
357 /* Accumulated frequency of calls which given allocno 373 /* Accumulated frequency of calls which given allocno
358 intersects. */ 374 intersects. */
359 int call_freq; 375 int call_freq;
360 /* Accumulated number of the intersected calls. */ 376 /* Accumulated number of the intersected calls. */
361 int calls_crossed_num; 377 int calls_crossed_num;
362 /* TRUE if the allocno assigned to memory was a destination of 378 /* The number of calls across which it is live, but which should not
363 removed move (see ira-emit.c) at loop exit because the value of 379 affect register preferences. */
364 the corresponding pseudo-register is not changed inside the 380 int cheap_calls_crossed_num;
365 loop. */ 381 /* Registers clobbered by intersected calls. */
366 unsigned int mem_optimized_dest_p : 1; 382 HARD_REG_SET crossed_calls_clobbered_regs;
367 /* TRUE if the corresponding pseudo-register has disjoint live
368 ranges and the other allocnos of the pseudo-register except this
369 one changed REG. */
370 unsigned int somewhere_renamed_p : 1;
371 /* TRUE if allocno with the same REGNO in a subregion has been
372 renamed, in other words, got a new pseudo-register. */
373 unsigned int child_renamed_p : 1;
374 /* During the reload, value TRUE means that we should not reassign a
375 hard register to the allocno got memory earlier. It is set up
376 when we removed memory-memory move insn before each iteration of
377 the reload. */
378 unsigned int dont_reassign_p : 1;
379 #ifdef STACK_REGS
380 /* Set to TRUE if allocno can't be assigned to the stack hard
381 register correspondingly in this region and area including the
382 region and all its subregions recursively. */
383 unsigned int no_stack_reg_p : 1, total_no_stack_reg_p : 1;
384 #endif
385 /* TRUE value means that there is no sense to spill the allocno
386 during coloring because the spill will result in additional
387 reloads in reload pass. */
388 unsigned int bad_spill_p : 1;
389 /* TRUE value means that the allocno was not removed yet from the
390 conflicting graph during colouring. */
391 unsigned int in_graph_p : 1;
392 /* TRUE if a hard register or memory has been assigned to the
393 allocno. */
394 unsigned int assigned_p : 1;
395 /* TRUE if it is put on the stack to make other allocnos
396 colorable. */
397 unsigned int may_be_spilled_p : 1;
398 /* TRUE if the allocno was removed from the splay tree used to
399 choose allocn for spilling (see ira-color.c::. */
400 unsigned int splay_removed_p : 1;
401 /* Non NULL if we remove restoring value from given allocno to
402 MEM_OPTIMIZED_DEST at loop exit (see ira-emit.c) because the
403 allocno value is not changed inside the loop. */
404 ira_allocno_t mem_optimized_dest;
405 /* Array of usage costs (accumulated and the one updated during 383 /* Array of usage costs (accumulated and the one updated during
406 coloring) for each hard register of the allocno cover class. The 384 coloring) for each hard register of the allocno class. The
407 member value can be NULL if all costs are the same and equal to 385 member value can be NULL if all costs are the same and equal to
408 COVER_CLASS_COST. For example, the costs of two different hard 386 CLASS_COST. For example, the costs of two different hard
409 registers can be different if one hard register is callee-saved 387 registers can be different if one hard register is callee-saved
410 and another one is callee-used and the allocno lives through 388 and another one is callee-used and the allocno lives through
411 calls. Another example can be case when for some insn the 389 calls. Another example can be case when for some insn the
412 corresponding pseudo-register value should be put in specific 390 corresponding pseudo-register value should be put in specific
413 register class (e.g. AREG for x86) which is a strict subset of 391 register class (e.g. AREG for x86) which is a strict subset of
414 the allocno cover class (GENERAL_REGS for x86). We have updated 392 the allocno class (GENERAL_REGS for x86). We have updated costs
415 costs to reflect the situation when the usage cost of a hard 393 to reflect the situation when the usage cost of a hard register
416 register is decreased because the allocno is connected to another 394 is decreased because the allocno is connected to another allocno
417 allocno by a copy and the another allocno has been assigned to 395 by a copy and the another allocno has been assigned to the hard
418 the hard register. */ 396 register. */
419 int *hard_reg_costs, *updated_hard_reg_costs; 397 int *hard_reg_costs, *updated_hard_reg_costs;
420 /* Array of decreasing costs (accumulated and the one updated during 398 /* Array of decreasing costs (accumulated and the one updated during
421 coloring) for allocnos conflicting with given allocno for hard 399 coloring) for allocnos conflicting with given allocno for hard
422 regno of the allocno cover class. The member value can be NULL 400 regno of the allocno class. The member value can be NULL if all
423 if all costs are the same. These costs are used to reflect 401 costs are the same. These costs are used to reflect preferences
424 preferences of other allocnos not assigned yet during assigning 402 of other allocnos not assigned yet during assigning to given
425 to given allocno. */ 403 allocno. */
426 int *conflict_hard_reg_costs, *updated_conflict_hard_reg_costs; 404 int *conflict_hard_reg_costs, *updated_conflict_hard_reg_costs;
427 /* Size (in hard registers) of the same cover class allocnos with 405 /* Different additional data. It is used to decrease size of
428 TRUE in_graph_p value and conflicting with given allocno during 406 allocno data footprint. */
429 each point of graph coloring. */ 407 void *add_data;
430 int left_conflicts_size;
431 /* Number of hard registers of the allocno cover class really
432 available for the allocno allocation. */
433 int available_regs_num;
434 /* Allocnos in a bucket (used in coloring) chained by the following
435 two members. */
436 ira_allocno_t next_bucket_allocno;
437 ira_allocno_t prev_bucket_allocno;
438 /* Used for temporary purposes. */
439 int temp;
440 }; 408 };
409
441 410
442 /* All members of the allocno structures should be accessed only 411 /* All members of the allocno structures should be accessed only
443 through the following macros. */ 412 through the following macros. */
444 #define ALLOCNO_NUM(A) ((A)->num) 413 #define ALLOCNO_NUM(A) ((A)->num)
445 #define ALLOCNO_REGNO(A) ((A)->regno) 414 #define ALLOCNO_REGNO(A) ((A)->regno)
451 #define ALLOCNO_NREFS(A) ((A)->nrefs) 420 #define ALLOCNO_NREFS(A) ((A)->nrefs)
452 #define ALLOCNO_FREQ(A) ((A)->freq) 421 #define ALLOCNO_FREQ(A) ((A)->freq)
453 #define ALLOCNO_HARD_REGNO(A) ((A)->hard_regno) 422 #define ALLOCNO_HARD_REGNO(A) ((A)->hard_regno)
454 #define ALLOCNO_CALL_FREQ(A) ((A)->call_freq) 423 #define ALLOCNO_CALL_FREQ(A) ((A)->call_freq)
455 #define ALLOCNO_CALLS_CROSSED_NUM(A) ((A)->calls_crossed_num) 424 #define ALLOCNO_CALLS_CROSSED_NUM(A) ((A)->calls_crossed_num)
425 #define ALLOCNO_CHEAP_CALLS_CROSSED_NUM(A) ((A)->cheap_calls_crossed_num)
426 #define ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS(A) \
427 ((A)->crossed_calls_clobbered_regs)
456 #define ALLOCNO_MEM_OPTIMIZED_DEST(A) ((A)->mem_optimized_dest) 428 #define ALLOCNO_MEM_OPTIMIZED_DEST(A) ((A)->mem_optimized_dest)
457 #define ALLOCNO_MEM_OPTIMIZED_DEST_P(A) ((A)->mem_optimized_dest_p) 429 #define ALLOCNO_MEM_OPTIMIZED_DEST_P(A) ((A)->mem_optimized_dest_p)
458 #define ALLOCNO_SOMEWHERE_RENAMED_P(A) ((A)->somewhere_renamed_p) 430 #define ALLOCNO_SOMEWHERE_RENAMED_P(A) ((A)->somewhere_renamed_p)
459 #define ALLOCNO_CHILD_RENAMED_P(A) ((A)->child_renamed_p) 431 #define ALLOCNO_CHILD_RENAMED_P(A) ((A)->child_renamed_p)
460 #define ALLOCNO_DONT_REASSIGN_P(A) ((A)->dont_reassign_p) 432 #define ALLOCNO_DONT_REASSIGN_P(A) ((A)->dont_reassign_p)
461 #ifdef STACK_REGS 433 #ifdef STACK_REGS
462 #define ALLOCNO_NO_STACK_REG_P(A) ((A)->no_stack_reg_p) 434 #define ALLOCNO_NO_STACK_REG_P(A) ((A)->no_stack_reg_p)
463 #define ALLOCNO_TOTAL_NO_STACK_REG_P(A) ((A)->total_no_stack_reg_p) 435 #define ALLOCNO_TOTAL_NO_STACK_REG_P(A) ((A)->total_no_stack_reg_p)
464 #endif 436 #endif
465 #define ALLOCNO_BAD_SPILL_P(A) ((A)->bad_spill_p) 437 #define ALLOCNO_BAD_SPILL_P(A) ((A)->bad_spill_p)
466 #define ALLOCNO_IN_GRAPH_P(A) ((A)->in_graph_p)
467 #define ALLOCNO_ASSIGNED_P(A) ((A)->assigned_p) 438 #define ALLOCNO_ASSIGNED_P(A) ((A)->assigned_p)
468 #define ALLOCNO_MAY_BE_SPILLED_P(A) ((A)->may_be_spilled_p)
469 #define ALLOCNO_SPLAY_REMOVED_P(A) ((A)->splay_removed_p)
470 #define ALLOCNO_MODE(A) ((A)->mode) 439 #define ALLOCNO_MODE(A) ((A)->mode)
440 #define ALLOCNO_WMODE(A) ((A)->wmode)
441 #define ALLOCNO_PREFS(A) ((A)->allocno_prefs)
471 #define ALLOCNO_COPIES(A) ((A)->allocno_copies) 442 #define ALLOCNO_COPIES(A) ((A)->allocno_copies)
472 #define ALLOCNO_HARD_REG_COSTS(A) ((A)->hard_reg_costs) 443 #define ALLOCNO_HARD_REG_COSTS(A) ((A)->hard_reg_costs)
473 #define ALLOCNO_UPDATED_HARD_REG_COSTS(A) ((A)->updated_hard_reg_costs) 444 #define ALLOCNO_UPDATED_HARD_REG_COSTS(A) ((A)->updated_hard_reg_costs)
474 #define ALLOCNO_CONFLICT_HARD_REG_COSTS(A) \ 445 #define ALLOCNO_CONFLICT_HARD_REG_COSTS(A) \
475 ((A)->conflict_hard_reg_costs) 446 ((A)->conflict_hard_reg_costs)
476 #define ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS(A) \ 447 #define ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS(A) \
477 ((A)->updated_conflict_hard_reg_costs) 448 ((A)->updated_conflict_hard_reg_costs)
478 #define ALLOCNO_LEFT_CONFLICTS_SIZE(A) ((A)->left_conflicts_size) 449 #define ALLOCNO_CLASS(A) ((A)->aclass)
479 #define ALLOCNO_COVER_CLASS(A) ((A)->cover_class) 450 #define ALLOCNO_CLASS_COST(A) ((A)->class_cost)
480 #define ALLOCNO_COVER_CLASS_COST(A) ((A)->cover_class_cost) 451 #define ALLOCNO_UPDATED_CLASS_COST(A) ((A)->updated_class_cost)
481 #define ALLOCNO_UPDATED_COVER_CLASS_COST(A) ((A)->updated_cover_class_cost)
482 #define ALLOCNO_MEMORY_COST(A) ((A)->memory_cost) 452 #define ALLOCNO_MEMORY_COST(A) ((A)->memory_cost)
483 #define ALLOCNO_UPDATED_MEMORY_COST(A) ((A)->updated_memory_cost) 453 #define ALLOCNO_UPDATED_MEMORY_COST(A) ((A)->updated_memory_cost)
484 #define ALLOCNO_EXCESS_PRESSURE_POINTS_NUM(A) ((A)->excess_pressure_points_num) 454 #define ALLOCNO_EXCESS_PRESSURE_POINTS_NUM(A) \
485 #define ALLOCNO_AVAILABLE_REGS_NUM(A) ((A)->available_regs_num) 455 ((A)->excess_pressure_points_num)
486 #define ALLOCNO_NEXT_BUCKET_ALLOCNO(A) ((A)->next_bucket_allocno)
487 #define ALLOCNO_PREV_BUCKET_ALLOCNO(A) ((A)->prev_bucket_allocno)
488 #define ALLOCNO_TEMP(A) ((A)->temp)
489 #define ALLOCNO_FIRST_COALESCED_ALLOCNO(A) ((A)->first_coalesced_allocno)
490 #define ALLOCNO_NEXT_COALESCED_ALLOCNO(A) ((A)->next_coalesced_allocno)
491 #define ALLOCNO_OBJECT(A,N) ((A)->objects[N]) 456 #define ALLOCNO_OBJECT(A,N) ((A)->objects[N])
492 #define ALLOCNO_NUM_OBJECTS(A) ((A)->num_objects) 457 #define ALLOCNO_NUM_OBJECTS(A) ((A)->num_objects)
493 458 #define ALLOCNO_ADD_DATA(A) ((A)->add_data)
494 #define OBJECT_ALLOCNO(C) ((C)->allocno) 459
495 #define OBJECT_SUBWORD(C) ((C)->subword) 460 /* Typedef for pointer to the subsequent structure. */
496 #define OBJECT_CONFLICT_ARRAY(C) ((C)->conflicts_array) 461 typedef struct ira_emit_data *ira_emit_data_t;
497 #define OBJECT_CONFLICT_VEC(C) ((ira_object_t *)(C)->conflicts_array) 462
498 #define OBJECT_CONFLICT_BITVEC(C) ((IRA_INT_TYPE *)(C)->conflicts_array) 463 /* Allocno bound data used for emit pseudo live range split insns and
499 #define OBJECT_CONFLICT_ARRAY_SIZE(C) ((C)->conflicts_array_size) 464 to flattening IR. */
500 #define OBJECT_CONFLICT_VEC_P(C) ((C)->conflict_vec_p) 465 struct ira_emit_data
501 #define OBJECT_NUM_CONFLICTS(C) ((C)->num_accumulated_conflicts) 466 {
502 #define OBJECT_CONFLICT_HARD_REGS(C) ((C)->conflict_hard_regs) 467 /* TRUE if the allocno assigned to memory was a destination of
503 #define OBJECT_TOTAL_CONFLICT_HARD_REGS(C) ((C)->total_conflict_hard_regs) 468 removed move (see ira-emit.c) at loop exit because the value of
504 #define OBJECT_MIN(C) ((C)->min) 469 the corresponding pseudo-register is not changed inside the
505 #define OBJECT_MAX(C) ((C)->max) 470 loop. */
506 #define OBJECT_CONFLICT_ID(C) ((C)->id) 471 unsigned int mem_optimized_dest_p : 1;
507 #define OBJECT_LIVE_RANGES(A) ((A)->live_ranges) 472 /* TRUE if the corresponding pseudo-register has disjoint live
473 ranges and the other allocnos of the pseudo-register except this
474 one changed REG. */
475 unsigned int somewhere_renamed_p : 1;
476 /* TRUE if allocno with the same REGNO in a subregion has been
477 renamed, in other words, got a new pseudo-register. */
478 unsigned int child_renamed_p : 1;
479 /* Final rtx representation of the allocno. */
480 rtx reg;
481 /* Non NULL if we remove restoring value from given allocno to
482 MEM_OPTIMIZED_DEST at loop exit (see ira-emit.c) because the
483 allocno value is not changed inside the loop. */
484 ira_allocno_t mem_optimized_dest;
485 };
486
487 #define ALLOCNO_EMIT_DATA(a) ((ira_emit_data_t) ALLOCNO_ADD_DATA (a))
488
489 /* Data used to emit live range split insns and to flattening IR. */
490 extern ira_emit_data_t ira_allocno_emit_data;
491
492 /* Abbreviation for frequent emit data access. */
493 static inline rtx
494 allocno_emit_reg (ira_allocno_t a)
495 {
496 return ALLOCNO_EMIT_DATA (a)->reg;
497 }
498
499 #define OBJECT_ALLOCNO(O) ((O)->allocno)
500 #define OBJECT_SUBWORD(O) ((O)->subword)
501 #define OBJECT_CONFLICT_ARRAY(O) ((O)->conflicts_array)
502 #define OBJECT_CONFLICT_VEC(O) ((ira_object_t *)(O)->conflicts_array)
503 #define OBJECT_CONFLICT_BITVEC(O) ((IRA_INT_TYPE *)(O)->conflicts_array)
504 #define OBJECT_CONFLICT_ARRAY_SIZE(O) ((O)->conflicts_array_size)
505 #define OBJECT_CONFLICT_VEC_P(O) ((O)->conflict_vec_p)
506 #define OBJECT_NUM_CONFLICTS(O) ((O)->num_accumulated_conflicts)
507 #define OBJECT_CONFLICT_HARD_REGS(O) ((O)->conflict_hard_regs)
508 #define OBJECT_TOTAL_CONFLICT_HARD_REGS(O) ((O)->total_conflict_hard_regs)
509 #define OBJECT_MIN(O) ((O)->min)
510 #define OBJECT_MAX(O) ((O)->max)
511 #define OBJECT_CONFLICT_ID(O) ((O)->id)
512 #define OBJECT_LIVE_RANGES(O) ((O)->live_ranges)
508 513
509 /* Map regno -> allocnos with given regno (see comments for 514 /* Map regno -> allocnos with given regno (see comments for
510 allocno member `next_regno_allocno'). */ 515 allocno member `next_regno_allocno'). */
511 extern ira_allocno_t *ira_regno_allocno_map; 516 extern ira_allocno_t *ira_regno_allocno_map;
512 517
521 /* Map a conflict id to its corresponding ira_object structure. */ 526 /* Map a conflict id to its corresponding ira_object structure. */
522 extern ira_object_t *ira_object_id_map; 527 extern ira_object_t *ira_object_id_map;
523 528
524 /* The size of the previous array. */ 529 /* The size of the previous array. */
525 extern int ira_objects_num; 530 extern int ira_objects_num;
531
532 /* The following structure represents a hard register preference of
533 allocno. The preference represent move insns or potential move
534 insns usually because of two operand insn constraints. One move
535 operand is a hard register. */
536 struct ira_allocno_pref
537 {
538 /* The unique order number of the preference node starting with 0. */
539 int num;
540 /* Preferred hard register. */
541 int hard_regno;
542 /* Accumulated execution frequency of insns from which the
543 preference created. */
544 int freq;
545 /* Given allocno. */
546 ira_allocno_t allocno;
547 /* All preferences with the same allocno are linked by the following
548 member. */
549 ira_pref_t next_pref;
550 };
551
552 /* Array of references to all allocno preferences. The order number
553 of the preference corresponds to the index in the array. */
554 extern ira_pref_t *ira_prefs;
555
556 /* Size of the previous array. */
557 extern int ira_prefs_num;
526 558
527 /* The following structure represents a copy of two allocnos. The 559 /* The following structure represents a copy of two allocnos. The
528 copies represent move insns or potential move insns usually because 560 copies represent move insns or potential move insns usually because
529 of two operand insn constraints. To remove register shuffle, we 561 of two operand insn constraints. To remove register shuffle, we
530 also create copies between allocno which is output of an insn and 562 also create copies between allocno which is output of an insn and
542 /* It is a move insn which is an origin of the copy. The member 574 /* It is a move insn which is an origin of the copy. The member
543 value for the copy representing two operand insn constraints or 575 value for the copy representing two operand insn constraints or
544 for the copy created to remove register shuffle is NULL. In last 576 for the copy created to remove register shuffle is NULL. In last
545 case the copy frequency is smaller than the corresponding insn 577 case the copy frequency is smaller than the corresponding insn
546 execution frequency. */ 578 execution frequency. */
547 rtx insn; 579 rtx_insn *insn;
548 /* All copies with the same allocno as FIRST are linked by the two 580 /* All copies with the same allocno as FIRST are linked by the two
549 following members. */ 581 following members. */
550 ira_copy_t prev_first_allocno_copy, next_first_allocno_copy; 582 ira_copy_t prev_first_allocno_copy, next_first_allocno_copy;
551 /* All copies with the same allocno as SECOND are linked by the two 583 /* All copies with the same allocno as SECOND are linked by the two
552 following members. */ 584 following members. */
584 616
585 /* Correspondingly overall cost of the allocation, cost of the 617 /* Correspondingly overall cost of the allocation, cost of the
586 allocnos assigned to hard-registers, cost of the allocnos assigned 618 allocnos assigned to hard-registers, cost of the allocnos assigned
587 to memory, cost of loads, stores and register move insns generated 619 to memory, cost of loads, stores and register move insns generated
588 for pseudo-register live range splitting (see ira-emit.c). */ 620 for pseudo-register live range splitting (see ira-emit.c). */
589 extern int ira_overall_cost; 621 extern int64_t ira_overall_cost;
590 extern int ira_reg_cost, ira_mem_cost; 622 extern int64_t ira_reg_cost, ira_mem_cost;
591 extern int ira_load_cost, ira_store_cost, ira_shuffle_cost; 623 extern int64_t ira_load_cost, ira_store_cost, ira_shuffle_cost;
592 extern int ira_move_loops_num, ira_additional_jumps_num; 624 extern int ira_move_loops_num, ira_additional_jumps_num;
625
593 626
594 /* This page contains a bitset implementation called 'min/max sets' used to 627 /* This page contains a bitset implementation called 'min/max sets' used to
595 record conflicts in IRA. 628 record conflicts in IRA.
596 They are named min/maxs set since we keep track of a minimum and a maximum 629 They are named min/maxs set since we keep track of a minimum and a maximum
597 bit number for each set representing the bounds of valid elements. Otherwise, 630 bit number for each set representing the bounds of valid elements. Otherwise,
661 & ((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS))) 694 & ((IRA_INT_TYPE) 1 << ((unsigned) ((I) - (MIN)) % IRA_INT_BITS)))
662 695
663 #endif 696 #endif
664 697
665 /* The iterator for min/max sets. */ 698 /* The iterator for min/max sets. */
666 typedef struct { 699 struct minmax_set_iterator {
667 700
668 /* Array containing the bit vector. */ 701 /* Array containing the bit vector. */
669 IRA_INT_TYPE *vec; 702 IRA_INT_TYPE *vec;
670 703
671 /* The number of the current element in the vector. */ 704 /* The number of the current element in the vector. */
680 /* Index corresponding to the 1st bit of the bit vector. */ 713 /* Index corresponding to the 1st bit of the bit vector. */
681 int start_val; 714 int start_val;
682 715
683 /* The word of the bit vector currently visited. */ 716 /* The word of the bit vector currently visited. */
684 unsigned IRA_INT_TYPE word; 717 unsigned IRA_INT_TYPE word;
685 } minmax_set_iterator; 718 };
686 719
687 /* Initialize the iterator I for bit vector VEC containing minimal and 720 /* Initialize the iterator I for bit vector VEC containing minimal and
688 maximal values MIN and MAX. */ 721 maximal values MIN and MAX. */
689 static inline void 722 static inline void
690 minmax_set_iter_init (minmax_set_iterator *i, IRA_INT_TYPE *vec, int min, 723 minmax_set_iter_init (minmax_set_iterator *i, IRA_INT_TYPE *vec, int min,
740 for (minmax_set_iter_init (&(ITER), (VEC), (MIN), (MAX)); \ 773 for (minmax_set_iter_init (&(ITER), (VEC), (MIN), (MAX)); \
741 minmax_set_iter_cond (&(ITER), &(N)); \ 774 minmax_set_iter_cond (&(ITER), &(N)); \
742 minmax_set_iter_next (&(ITER))) 775 minmax_set_iter_next (&(ITER)))
743 776
744 struct target_ira_int { 777 struct target_ira_int {
778 ~target_ira_int ();
779
780 void free_ira_costs ();
781 void free_register_move_costs ();
782
745 /* Initialized once. It is a maximal possible size of the allocated 783 /* Initialized once. It is a maximal possible size of the allocated
746 struct costs. */ 784 struct costs. */
747 int x_max_struct_costs_size; 785 size_t x_max_struct_costs_size;
748 786
749 /* Allocated and initialized once, and used to initialize cost values 787 /* Allocated and initialized once, and used to initialize cost values
750 for each insn. */ 788 for each insn. */
751 struct costs *x_init_cost; 789 struct costs *x_init_cost;
752 790
754 struct costs *x_temp_costs; 792 struct costs *x_temp_costs;
755 793
756 /* Allocated once, and used for the cost calculation. */ 794 /* Allocated once, and used for the cost calculation. */
757 struct costs *x_op_costs[MAX_RECOG_OPERANDS]; 795 struct costs *x_op_costs[MAX_RECOG_OPERANDS];
758 struct costs *x_this_op_costs[MAX_RECOG_OPERANDS]; 796 struct costs *x_this_op_costs[MAX_RECOG_OPERANDS];
759
760 /* Classes used for cost calculation. They may be different on
761 different iterations of the cost calculations or in different
762 optimization modes. */
763 enum reg_class *x_cost_classes;
764 797
765 /* Hard registers that can not be used for the register allocator for 798 /* Hard registers that can not be used for the register allocator for
766 all functions of the current compilation unit. */ 799 all functions of the current compilation unit. */
767 HARD_REG_SET x_no_unit_alloc_regs; 800 HARD_REG_SET x_no_unit_alloc_regs;
768 801
769 /* Map: hard regs X modes -> set of hard registers for storing value 802 /* Map: hard regs X modes -> set of hard registers for storing value
770 of given mode starting with given hard register. */ 803 of given mode starting with given hard register. */
771 HARD_REG_SET (x_ira_reg_mode_hard_regset 804 HARD_REG_SET (x_ira_reg_mode_hard_regset
772 [FIRST_PSEUDO_REGISTER][NUM_MACHINE_MODES]); 805 [FIRST_PSEUDO_REGISTER][NUM_MACHINE_MODES]);
773 806
774 /* Array based on TARGET_REGISTER_MOVE_COST. Don't use 807 /* Maximum cost of moving from a register in one class to a register
775 ira_register_move_cost directly. Use function of 808 in another class. Based on TARGET_REGISTER_MOVE_COST. */
776 ira_get_may_move_cost instead. */
777 move_table *x_ira_register_move_cost[MAX_MACHINE_MODE]; 809 move_table *x_ira_register_move_cost[MAX_MACHINE_MODE];
778 810
779 /* Similar to may_move_in_cost but it is calculated in IRA instead of 811 /* Similar, but here we don't have to move if the first index is a
780 regclass. Another difference we take only available hard registers 812 subset of the second so in that case the cost is zero. */
781 into account to figure out that one register class is a subset of
782 the another one. Don't use it directly. Use function of
783 ira_get_may_move_cost instead. */
784 move_table *x_ira_may_move_in_cost[MAX_MACHINE_MODE]; 813 move_table *x_ira_may_move_in_cost[MAX_MACHINE_MODE];
785 814
786 /* Similar to may_move_out_cost but it is calculated in IRA instead of 815 /* Similar, but here we don't have to move if the first index is a
787 regclass. Another difference we take only available hard registers 816 superset of the second so in that case the cost is zero. */
788 into account to figure out that one register class is a subset of
789 the another one. Don't use it directly. Use function of
790 ira_get_may_move_cost instead. */
791 move_table *x_ira_may_move_out_cost[MAX_MACHINE_MODE]; 817 move_table *x_ira_may_move_out_cost[MAX_MACHINE_MODE];
792 818
793 /* Register class subset relation: TRUE if the first class is a subset 819 /* Keep track of the last mode we initialized move costs for. */
794 of the second one considering only hard registers available for the 820 int x_last_mode_for_init_move_cost;
795 allocation. */ 821
796 int x_ira_class_subset_p[N_REG_CLASSES][N_REG_CLASSES]; 822 /* Array analog of the macro MEMORY_MOVE_COST but they contain maximal
823 cost not minimal. */
824 short int x_ira_max_memory_move_cost[MAX_MACHINE_MODE][N_REG_CLASSES][2];
825
826 /* Map class->true if class is a possible allocno class, false
827 otherwise. */
828 bool x_ira_reg_allocno_class_p[N_REG_CLASSES];
829
830 /* Map class->true if class is a pressure class, false otherwise. */
831 bool x_ira_reg_pressure_class_p[N_REG_CLASSES];
797 832
798 /* Array of the number of hard registers of given class which are 833 /* Array of the number of hard registers of given class which are
799 available for allocation. The order is defined by the the hard 834 available for allocation. The order is defined by the hard
800 register numbers. */ 835 register numbers. */
801 short x_ira_non_ordered_class_hard_regs[N_REG_CLASSES][FIRST_PSEUDO_REGISTER]; 836 short x_ira_non_ordered_class_hard_regs[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
802 837
803 /* Index (in ira_class_hard_regs; for given register class and hard 838 /* Index (in ira_class_hard_regs; for given register class and hard
804 register (in general case a hard register can belong to several 839 register (in general case a hard register can belong to several
805 register classes;. The index is negative for hard registers 840 register classes;. The index is negative for hard registers
806 unavailable for the allocation. */ 841 unavailable for the allocation. */
807 short x_ira_class_hard_reg_index[N_REG_CLASSES][FIRST_PSEUDO_REGISTER]; 842 short x_ira_class_hard_reg_index[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
808 843
809 /* Array whose values are hard regset of hard registers available for 844 /* Index [CL][M] contains R if R appears somewhere in a register of the form:
810 the allocation of given register class whose HARD_REGNO_MODE_OK 845
811 values for given mode are zero. */ 846 (reg:M R'), R' not in x_ira_prohibited_class_mode_regs[CL][M]
812 HARD_REG_SET x_prohibited_class_mode_regs[N_REG_CLASSES][NUM_MACHINE_MODES]; 847
848 For example, if:
849
850 - (reg:M 2) is valid and occupies two registers;
851 - register 2 belongs to CL; and
852 - register 3 belongs to the same pressure class as CL
853
854 then (reg:M 2) contributes to [CL][M] and registers 2 and 3 will be
855 in the set. */
856 HARD_REG_SET x_ira_useful_class_mode_regs[N_REG_CLASSES][NUM_MACHINE_MODES];
813 857
814 /* The value is number of elements in the subsequent array. */ 858 /* The value is number of elements in the subsequent array. */
815 int x_ira_important_classes_num; 859 int x_ira_important_classes_num;
816 860
817 /* The array containing non-empty classes (including non-empty cover 861 /* The array containing all non-empty classes. Such classes is
818 classes; which are subclasses of cover classes. Such classes is
819 important for calculation of the hard register usage costs. */ 862 important for calculation of the hard register usage costs. */
820 enum reg_class x_ira_important_classes[N_REG_CLASSES]; 863 enum reg_class x_ira_important_classes[N_REG_CLASSES];
864
865 /* The array containing indexes of important classes in the previous
866 array. The array elements are defined only for important
867 classes. */
868 int x_ira_important_class_nums[N_REG_CLASSES];
869
870 /* Map class->true if class is an uniform class, false otherwise. */
871 bool x_ira_uniform_class_p[N_REG_CLASSES];
821 872
822 /* The biggest important class inside of intersection of the two 873 /* The biggest important class inside of intersection of the two
823 classes (that is calculated taking only hard registers available 874 classes (that is calculated taking only hard registers available
824 for allocation into account;. If the both classes contain no hard 875 for allocation into account;. If the both classes contain no hard
825 registers available for allocation, the value is calculated with 876 registers available for allocation, the value is calculated with
826 taking all hard-registers including fixed ones into account. */ 877 taking all hard-registers including fixed ones into account. */
827 enum reg_class x_ira_reg_class_intersect[N_REG_CLASSES][N_REG_CLASSES]; 878 enum reg_class x_ira_reg_class_intersect[N_REG_CLASSES][N_REG_CLASSES];
828 879
829 /* True if the two classes (that is calculated taking only hard
830 registers available for allocation into account; are
831 intersected. */
832 bool x_ira_reg_classes_intersect_p[N_REG_CLASSES][N_REG_CLASSES];
833
834 /* Classes with end marker LIM_REG_CLASSES which are intersected with 880 /* Classes with end marker LIM_REG_CLASSES which are intersected with
835 given class (the first index;. That includes given class itself. 881 given class (the first index). That includes given class itself.
836 This is calculated taking only hard registers available for 882 This is calculated taking only hard registers available for
837 allocation into account. */ 883 allocation into account. */
838 enum reg_class x_ira_reg_class_super_classes[N_REG_CLASSES][N_REG_CLASSES]; 884 enum reg_class x_ira_reg_class_super_classes[N_REG_CLASSES][N_REG_CLASSES];
839 885
840 /* The biggest important class inside of union of the two classes 886 /* The biggest (smallest) important class inside of (covering) union
841 (that is calculated taking only hard registers available for 887 of the two classes (that is calculated taking only hard registers
842 allocation into account;. If the both classes contain no hard 888 available for allocation into account). If the both classes
843 registers available for allocation, the value is calculated with 889 contain no hard registers available for allocation, the value is
844 taking all hard-registers including fixed ones into account. In 890 calculated with taking all hard-registers including fixed ones
845 other words, the value is the corresponding reg_class_subunion 891 into account. In other words, the value is the corresponding
846 value. */ 892 reg_class_subunion (reg_class_superunion) value. */
847 enum reg_class x_ira_reg_class_union[N_REG_CLASSES][N_REG_CLASSES]; 893 enum reg_class x_ira_reg_class_subunion[N_REG_CLASSES][N_REG_CLASSES];
894 enum reg_class x_ira_reg_class_superunion[N_REG_CLASSES][N_REG_CLASSES];
848 895
849 /* For each reg class, table listing all the classes contained in it 896 /* For each reg class, table listing all the classes contained in it
850 (excluding the class itself. Non-allocatable registers are 897 (excluding the class itself. Non-allocatable registers are
851 excluded from the consideration;. */ 898 excluded from the consideration). */
852 enum reg_class x_alloc_reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES]; 899 enum reg_class x_alloc_reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
853 900
854 /* Array whose values are hard regset of hard registers for which 901 /* Array whose values are hard regset of hard registers for which
855 move of the hard register in given mode into itself is 902 move of the hard register in given mode into itself is
856 prohibited. */ 903 prohibited. */
869 916
870 #define ira_reg_mode_hard_regset \ 917 #define ira_reg_mode_hard_regset \
871 (this_target_ira_int->x_ira_reg_mode_hard_regset) 918 (this_target_ira_int->x_ira_reg_mode_hard_regset)
872 #define ira_register_move_cost \ 919 #define ira_register_move_cost \
873 (this_target_ira_int->x_ira_register_move_cost) 920 (this_target_ira_int->x_ira_register_move_cost)
921 #define ira_max_memory_move_cost \
922 (this_target_ira_int->x_ira_max_memory_move_cost)
874 #define ira_may_move_in_cost \ 923 #define ira_may_move_in_cost \
875 (this_target_ira_int->x_ira_may_move_in_cost) 924 (this_target_ira_int->x_ira_may_move_in_cost)
876 #define ira_may_move_out_cost \ 925 #define ira_may_move_out_cost \
877 (this_target_ira_int->x_ira_may_move_out_cost) 926 (this_target_ira_int->x_ira_may_move_out_cost)
878 #define ira_class_subset_p \ 927 #define ira_reg_allocno_class_p \
879 (this_target_ira_int->x_ira_class_subset_p) 928 (this_target_ira_int->x_ira_reg_allocno_class_p)
929 #define ira_reg_pressure_class_p \
930 (this_target_ira_int->x_ira_reg_pressure_class_p)
880 #define ira_non_ordered_class_hard_regs \ 931 #define ira_non_ordered_class_hard_regs \
881 (this_target_ira_int->x_ira_non_ordered_class_hard_regs) 932 (this_target_ira_int->x_ira_non_ordered_class_hard_regs)
882 #define ira_class_hard_reg_index \ 933 #define ira_class_hard_reg_index \
883 (this_target_ira_int->x_ira_class_hard_reg_index) 934 (this_target_ira_int->x_ira_class_hard_reg_index)
884 #define prohibited_class_mode_regs \ 935 #define ira_useful_class_mode_regs \
885 (this_target_ira_int->x_prohibited_class_mode_regs) 936 (this_target_ira_int->x_ira_useful_class_mode_regs)
886 #define ira_important_classes_num \ 937 #define ira_important_classes_num \
887 (this_target_ira_int->x_ira_important_classes_num) 938 (this_target_ira_int->x_ira_important_classes_num)
888 #define ira_important_classes \ 939 #define ira_important_classes \
889 (this_target_ira_int->x_ira_important_classes) 940 (this_target_ira_int->x_ira_important_classes)
941 #define ira_important_class_nums \
942 (this_target_ira_int->x_ira_important_class_nums)
943 #define ira_uniform_class_p \
944 (this_target_ira_int->x_ira_uniform_class_p)
890 #define ira_reg_class_intersect \ 945 #define ira_reg_class_intersect \
891 (this_target_ira_int->x_ira_reg_class_intersect) 946 (this_target_ira_int->x_ira_reg_class_intersect)
892 #define ira_reg_classes_intersect_p \
893 (this_target_ira_int->x_ira_reg_classes_intersect_p)
894 #define ira_reg_class_super_classes \ 947 #define ira_reg_class_super_classes \
895 (this_target_ira_int->x_ira_reg_class_super_classes) 948 (this_target_ira_int->x_ira_reg_class_super_classes)
896 #define ira_reg_class_union \ 949 #define ira_reg_class_subunion \
897 (this_target_ira_int->x_ira_reg_class_union) 950 (this_target_ira_int->x_ira_reg_class_subunion)
951 #define ira_reg_class_superunion \
952 (this_target_ira_int->x_ira_reg_class_superunion)
898 #define ira_prohibited_mode_move_regs \ 953 #define ira_prohibited_mode_move_regs \
899 (this_target_ira_int->x_ira_prohibited_mode_move_regs) 954 (this_target_ira_int->x_ira_prohibited_mode_move_regs)
900 955
901 /* ira.c: */ 956 /* ira.c: */
902 957
903 extern void *ira_allocate (size_t); 958 extern void *ira_allocate (size_t);
904 extern void *ira_reallocate (void *, size_t);
905 extern void ira_free (void *addr); 959 extern void ira_free (void *addr);
906 extern bitmap ira_allocate_bitmap (void); 960 extern bitmap ira_allocate_bitmap (void);
907 extern void ira_free_bitmap (bitmap); 961 extern void ira_free_bitmap (bitmap);
908 extern void ira_print_disposition (FILE *); 962 extern void ira_print_disposition (FILE *);
909 extern void ira_debug_disposition (void); 963 extern void ira_debug_disposition (void);
910 extern void ira_debug_class_cover (void); 964 extern void ira_debug_allocno_classes (void);
911 extern void ira_init_register_move_cost (enum machine_mode); 965 extern void ira_init_register_move_cost (machine_mode);
912 966 extern void ira_setup_alts (rtx_insn *insn, HARD_REG_SET &alts);
913 /* The length of the two following arrays. */ 967 extern int ira_get_dup_out_num (int op_num, HARD_REG_SET &alts);
914 extern int ira_reg_equiv_len;
915
916 /* The element value is TRUE if the corresponding regno value is
917 invariant. */
918 extern bool *ira_reg_equiv_invariant_p;
919
920 /* The element value is equiv constant of given pseudo-register or
921 NULL_RTX. */
922 extern rtx *ira_reg_equiv_const;
923 968
924 /* ira-build.c */ 969 /* ira-build.c */
925 970
926 /* The current loop tree node and its regno allocno map. */ 971 /* The current loop tree node and its regno allocno map. */
927 extern ira_loop_tree_node_t ira_curr_loop_tree_node; 972 extern ira_loop_tree_node_t ira_curr_loop_tree_node;
928 extern ira_allocno_t *ira_curr_regno_allocno_map; 973 extern ira_allocno_t *ira_curr_regno_allocno_map;
929 974
975 extern void ira_debug_pref (ira_pref_t);
976 extern void ira_debug_prefs (void);
977 extern void ira_debug_allocno_prefs (ira_allocno_t);
978
930 extern void ira_debug_copy (ira_copy_t); 979 extern void ira_debug_copy (ira_copy_t);
980 extern void debug (ira_allocno_copy &ref);
981 extern void debug (ira_allocno_copy *ptr);
982
931 extern void ira_debug_copies (void); 983 extern void ira_debug_copies (void);
932 extern void ira_debug_allocno_copies (ira_allocno_t); 984 extern void ira_debug_allocno_copies (ira_allocno_t);
985 extern void debug (ira_allocno &ref);
986 extern void debug (ira_allocno *ptr);
933 987
934 extern void ira_traverse_loop_tree (bool, ira_loop_tree_node_t, 988 extern void ira_traverse_loop_tree (bool, ira_loop_tree_node_t,
935 void (*) (ira_loop_tree_node_t), 989 void (*) (ira_loop_tree_node_t),
936 void (*) (ira_loop_tree_node_t)); 990 void (*) (ira_loop_tree_node_t));
937 extern ira_allocno_t ira_parent_allocno (ira_allocno_t); 991 extern ira_allocno_t ira_parent_allocno (ira_allocno_t);
938 extern ira_allocno_t ira_parent_or_cap_allocno (ira_allocno_t); 992 extern ira_allocno_t ira_parent_or_cap_allocno (ira_allocno_t);
939 extern ira_allocno_t ira_create_allocno (int, bool, ira_loop_tree_node_t); 993 extern ira_allocno_t ira_create_allocno (int, bool, ira_loop_tree_node_t);
940 extern void ira_create_allocno_objects (ira_allocno_t); 994 extern void ira_create_allocno_objects (ira_allocno_t);
941 extern void ira_set_allocno_cover_class (ira_allocno_t, enum reg_class); 995 extern void ira_set_allocno_class (ira_allocno_t, enum reg_class);
942 extern bool ira_conflict_vector_profitable_p (ira_object_t, int); 996 extern bool ira_conflict_vector_profitable_p (ira_object_t, int);
943 extern void ira_allocate_conflict_vec (ira_object_t, int); 997 extern void ira_allocate_conflict_vec (ira_object_t, int);
944 extern void ira_allocate_object_conflicts (ira_object_t, int); 998 extern void ira_allocate_object_conflicts (ira_object_t, int);
945 extern void ior_hard_reg_conflicts (ira_allocno_t, HARD_REG_SET *); 999 extern void ior_hard_reg_conflicts (ira_allocno_t, HARD_REG_SET *);
946 extern void ira_print_expanded_allocno (ira_allocno_t); 1000 extern void ira_print_expanded_allocno (ira_allocno_t);
951 extern live_range_t ira_merge_live_ranges (live_range_t, live_range_t); 1005 extern live_range_t ira_merge_live_ranges (live_range_t, live_range_t);
952 extern bool ira_live_ranges_intersect_p (live_range_t, live_range_t); 1006 extern bool ira_live_ranges_intersect_p (live_range_t, live_range_t);
953 extern void ira_finish_live_range (live_range_t); 1007 extern void ira_finish_live_range (live_range_t);
954 extern void ira_finish_live_range_list (live_range_t); 1008 extern void ira_finish_live_range_list (live_range_t);
955 extern void ira_free_allocno_updated_costs (ira_allocno_t); 1009 extern void ira_free_allocno_updated_costs (ira_allocno_t);
1010 extern ira_pref_t ira_create_pref (ira_allocno_t, int, int);
1011 extern void ira_add_allocno_pref (ira_allocno_t, int, int);
1012 extern void ira_remove_pref (ira_pref_t);
1013 extern void ira_remove_allocno_prefs (ira_allocno_t);
956 extern ira_copy_t ira_create_copy (ira_allocno_t, ira_allocno_t, 1014 extern ira_copy_t ira_create_copy (ira_allocno_t, ira_allocno_t,
957 int, bool, rtx, ira_loop_tree_node_t); 1015 int, bool, rtx_insn *,
958 extern void ira_add_allocno_copy_to_list (ira_copy_t); 1016 ira_loop_tree_node_t);
959 extern void ira_swap_allocno_copy_ends_if_necessary (ira_copy_t);
960 extern ira_copy_t ira_add_allocno_copy (ira_allocno_t, ira_allocno_t, int, 1017 extern ira_copy_t ira_add_allocno_copy (ira_allocno_t, ira_allocno_t, int,
961 bool, rtx, ira_loop_tree_node_t); 1018 bool, rtx_insn *,
962 1019 ira_loop_tree_node_t);
963 extern int *ira_allocate_cost_vector (enum reg_class); 1020
964 extern void ira_free_cost_vector (int *, enum reg_class); 1021 extern int *ira_allocate_cost_vector (reg_class_t);
1022 extern void ira_free_cost_vector (int *, reg_class_t);
965 1023
966 extern void ira_flattening (int, int); 1024 extern void ira_flattening (int, int);
967 extern bool ira_build (bool); 1025 extern bool ira_build (void);
968 extern void ira_destroy (void); 1026 extern void ira_destroy (void);
969 1027
970 /* ira-costs.c */ 1028 /* ira-costs.c */
971 extern void ira_init_costs_once (void); 1029 extern void ira_init_costs_once (void);
972 extern void ira_init_costs (void); 1030 extern void ira_init_costs (void);
973 extern void ira_finish_costs_once (void);
974 extern void ira_costs (void); 1031 extern void ira_costs (void);
975 extern void ira_tune_allocno_costs_and_cover_classes (void); 1032 extern void ira_tune_allocno_costs (void);
976 1033
977 /* ira-lives.c */ 1034 /* ira-lives.c */
978 1035
979 extern void ira_rebuild_start_finish_chains (void); 1036 extern void ira_rebuild_start_finish_chains (void);
980 extern void ira_print_live_range_list (FILE *, live_range_t); 1037 extern void ira_print_live_range_list (FILE *, live_range_t);
1038 extern void debug (live_range &ref);
1039 extern void debug (live_range *ptr);
981 extern void ira_debug_live_range_list (live_range_t); 1040 extern void ira_debug_live_range_list (live_range_t);
982 extern void ira_debug_allocno_live_ranges (ira_allocno_t); 1041 extern void ira_debug_allocno_live_ranges (ira_allocno_t);
983 extern void ira_debug_live_ranges (void); 1042 extern void ira_debug_live_ranges (void);
984 extern void ira_create_allocno_live_ranges (void); 1043 extern void ira_create_allocno_live_ranges (void);
985 extern void ira_compress_allocno_live_ranges (void); 1044 extern void ira_compress_allocno_live_ranges (void);
986 extern void ira_finish_allocno_live_ranges (void); 1045 extern void ira_finish_allocno_live_ranges (void);
1046 extern void ira_implicitly_set_insn_hard_regs (HARD_REG_SET *,
1047 alternative_mask);
987 1048
988 /* ira-conflicts.c */ 1049 /* ira-conflicts.c */
989 extern void ira_debug_conflicts (bool); 1050 extern void ira_debug_conflicts (bool);
990 extern void ira_build_conflicts (void); 1051 extern void ira_build_conflicts (void);
991 1052
992 /* ira-color.c */ 1053 /* ira-color.c */
1054 extern void ira_debug_hard_regs_forest (void);
993 extern int ira_loop_edge_freq (ira_loop_tree_node_t, int, bool); 1055 extern int ira_loop_edge_freq (ira_loop_tree_node_t, int, bool);
994 extern void ira_reassign_conflict_allocnos (int); 1056 extern void ira_reassign_conflict_allocnos (int);
995 extern void ira_initiate_assign (void); 1057 extern void ira_initiate_assign (void);
996 extern void ira_finish_assign (void); 1058 extern void ira_finish_assign (void);
997 extern void ira_color (void); 1059 extern void ira_color (void);
998 1060
999 /* ira-emit.c */ 1061 /* ira-emit.c */
1062 extern void ira_initiate_emit_data (void);
1063 extern void ira_finish_emit_data (void);
1000 extern void ira_emit (bool); 1064 extern void ira_emit (bool);
1001 1065
1002 1066
1003 1067
1004 /* Return cost of moving value of MODE from register of class FROM to 1068 /* Return true if equivalence of pseudo REGNO is not a lvalue. */
1005 register of class TO. */ 1069 static inline bool
1006 static inline int 1070 ira_equiv_no_lvalue_p (int regno)
1007 ira_get_register_move_cost (enum machine_mode mode, 1071 {
1008 enum reg_class from, enum reg_class to) 1072 if (regno >= ira_reg_equiv_len)
1073 return false;
1074 return (ira_reg_equiv[regno].constant != NULL_RTX
1075 || ira_reg_equiv[regno].invariant != NULL_RTX
1076 || (ira_reg_equiv[regno].memory != NULL_RTX
1077 && MEM_READONLY_P (ira_reg_equiv[regno].memory)));
1078 }
1079
1080
1081
1082 /* Initialize register costs for MODE if necessary. */
1083 static inline void
1084 ira_init_register_move_cost_if_necessary (machine_mode mode)
1009 { 1085 {
1010 if (ira_register_move_cost[mode] == NULL) 1086 if (ira_register_move_cost[mode] == NULL)
1011 ira_init_register_move_cost (mode); 1087 ira_init_register_move_cost (mode);
1012 return ira_register_move_cost[mode][from][to];
1013 }
1014
1015 /* Return cost of moving value of MODE from register of class FROM to
1016 register of class TO. Return zero if IN_P is true and FROM is
1017 subset of TO or if IN_P is false and FROM is superset of TO. */
1018 static inline int
1019 ira_get_may_move_cost (enum machine_mode mode,
1020 enum reg_class from, enum reg_class to,
1021 bool in_p)
1022 {
1023 if (ira_register_move_cost[mode] == NULL)
1024 ira_init_register_move_cost (mode);
1025 return (in_p
1026 ? ira_may_move_in_cost[mode][from][to]
1027 : ira_may_move_out_cost[mode][from][to]);
1028 } 1088 }
1029 1089
1030 1090
1031 1091
1032 /* The iterator for all allocnos. */ 1092 /* The iterator for all allocnos. */
1033 typedef struct { 1093 struct ira_allocno_iterator {
1034 /* The number of the current element in IRA_ALLOCNOS. */ 1094 /* The number of the current element in IRA_ALLOCNOS. */
1035 int n; 1095 int n;
1036 } ira_allocno_iterator; 1096 };
1037 1097
1038 /* Initialize the iterator I. */ 1098 /* Initialize the iterator I. */
1039 static inline void 1099 static inline void
1040 ira_allocno_iter_init (ira_allocno_iterator *i) 1100 ira_allocno_iter_init (ira_allocno_iterator *i)
1041 { 1101 {
1065 #define FOR_EACH_ALLOCNO(A, ITER) \ 1125 #define FOR_EACH_ALLOCNO(A, ITER) \
1066 for (ira_allocno_iter_init (&(ITER)); \ 1126 for (ira_allocno_iter_init (&(ITER)); \
1067 ira_allocno_iter_cond (&(ITER), &(A));) 1127 ira_allocno_iter_cond (&(ITER), &(A));)
1068 1128
1069 /* The iterator for all objects. */ 1129 /* The iterator for all objects. */
1070 typedef struct { 1130 struct ira_object_iterator {
1071 /* The number of the current element in ira_object_id_map. */ 1131 /* The number of the current element in ira_object_id_map. */
1072 int n; 1132 int n;
1073 } ira_object_iterator; 1133 };
1074 1134
1075 /* Initialize the iterator I. */ 1135 /* Initialize the iterator I. */
1076 static inline void 1136 static inline void
1077 ira_object_iter_init (ira_object_iterator *i) 1137 ira_object_iter_init (ira_object_iterator *i)
1078 { 1138 {
1102 #define FOR_EACH_OBJECT(OBJ, ITER) \ 1162 #define FOR_EACH_OBJECT(OBJ, ITER) \
1103 for (ira_object_iter_init (&(ITER)); \ 1163 for (ira_object_iter_init (&(ITER)); \
1104 ira_object_iter_cond (&(ITER), &(OBJ));) 1164 ira_object_iter_cond (&(ITER), &(OBJ));)
1105 1165
1106 /* The iterator for objects associated with an allocno. */ 1166 /* The iterator for objects associated with an allocno. */
1107 typedef struct { 1167 struct ira_allocno_object_iterator {
1108 /* The number of the element the allocno's object array. */ 1168 /* The number of the element the allocno's object array. */
1109 int n; 1169 int n;
1110 } ira_allocno_object_iterator; 1170 };
1111 1171
1112 /* Initialize the iterator I. */ 1172 /* Initialize the iterator I. */
1113 static inline void 1173 static inline void
1114 ira_allocno_object_iter_init (ira_allocno_object_iterator *i) 1174 ira_allocno_object_iter_init (ira_allocno_object_iterator *i)
1115 { 1175 {
1121 FALSE. */ 1181 FALSE. */
1122 static inline bool 1182 static inline bool
1123 ira_allocno_object_iter_cond (ira_allocno_object_iterator *i, ira_allocno_t a, 1183 ira_allocno_object_iter_cond (ira_allocno_object_iterator *i, ira_allocno_t a,
1124 ira_object_t *o) 1184 ira_object_t *o)
1125 { 1185 {
1126 *o = ALLOCNO_OBJECT (a, i->n); 1186 int n = i->n++;
1127 return i->n++ < ALLOCNO_NUM_OBJECTS (a); 1187 if (n < ALLOCNO_NUM_OBJECTS (a))
1188 {
1189 *o = ALLOCNO_OBJECT (a, n);
1190 return true;
1191 }
1192 return false;
1128 } 1193 }
1129 1194
1130 /* Loop over all objects associated with allocno A. In each 1195 /* Loop over all objects associated with allocno A. In each
1131 iteration, O is set to the next object. ITER is an instance of 1196 iteration, O is set to the next object. ITER is an instance of
1132 ira_allocno_object_iterator used to iterate the conflicts. */ 1197 ira_allocno_object_iterator used to iterate the conflicts. */
1133 #define FOR_EACH_ALLOCNO_OBJECT(A, O, ITER) \ 1198 #define FOR_EACH_ALLOCNO_OBJECT(A, O, ITER) \
1134 for (ira_allocno_object_iter_init (&(ITER)); \ 1199 for (ira_allocno_object_iter_init (&(ITER)); \
1135 ira_allocno_object_iter_cond (&(ITER), (A), &(O));) 1200 ira_allocno_object_iter_cond (&(ITER), (A), &(O));)
1136 1201
1137 1202
1203 /* The iterator for prefs. */
1204 struct ira_pref_iterator {
1205 /* The number of the current element in IRA_PREFS. */
1206 int n;
1207 };
1208
1209 /* Initialize the iterator I. */
1210 static inline void
1211 ira_pref_iter_init (ira_pref_iterator *i)
1212 {
1213 i->n = 0;
1214 }
1215
1216 /* Return TRUE if we have more prefs to visit, in which case *PREF is
1217 set to the pref to be visited. Otherwise, return FALSE. */
1218 static inline bool
1219 ira_pref_iter_cond (ira_pref_iterator *i, ira_pref_t *pref)
1220 {
1221 int n;
1222
1223 for (n = i->n; n < ira_prefs_num; n++)
1224 if (ira_prefs[n] != NULL)
1225 {
1226 *pref = ira_prefs[n];
1227 i->n = n + 1;
1228 return true;
1229 }
1230 return false;
1231 }
1232
1233 /* Loop over all prefs. In each iteration, P is set to the next
1234 pref. ITER is an instance of ira_pref_iterator used to iterate
1235 the prefs. */
1236 #define FOR_EACH_PREF(P, ITER) \
1237 for (ira_pref_iter_init (&(ITER)); \
1238 ira_pref_iter_cond (&(ITER), &(P));)
1239
1240
1138 /* The iterator for copies. */ 1241 /* The iterator for copies. */
1139 typedef struct { 1242 struct ira_copy_iterator {
1140 /* The number of the current element in IRA_COPIES. */ 1243 /* The number of the current element in IRA_COPIES. */
1141 int n; 1244 int n;
1142 } ira_copy_iterator; 1245 };
1143 1246
1144 /* Initialize the iterator I. */ 1247 /* Initialize the iterator I. */
1145 static inline void 1248 static inline void
1146 ira_copy_iter_init (ira_copy_iterator *i) 1249 ira_copy_iter_init (ira_copy_iterator *i)
1147 { 1250 {
1171 #define FOR_EACH_COPY(C, ITER) \ 1274 #define FOR_EACH_COPY(C, ITER) \
1172 for (ira_copy_iter_init (&(ITER)); \ 1275 for (ira_copy_iter_init (&(ITER)); \
1173 ira_copy_iter_cond (&(ITER), &(C));) 1276 ira_copy_iter_cond (&(ITER), &(C));)
1174 1277
1175 /* The iterator for object conflicts. */ 1278 /* The iterator for object conflicts. */
1176 typedef struct { 1279 struct ira_object_conflict_iterator {
1177 1280
1178 /* TRUE if the conflicts are represented by vector of allocnos. */ 1281 /* TRUE if the conflicts are represented by vector of allocnos. */
1179 bool conflict_vec_p; 1282 bool conflict_vec_p;
1180 1283
1181 /* The conflict vector or conflict bit vector. */ 1284 /* The conflict vector or conflict bit vector. */
1198 int base_conflict_id; 1301 int base_conflict_id;
1199 1302
1200 /* The word of bit vector currently visited. It is defined only if 1303 /* The word of bit vector currently visited. It is defined only if
1201 OBJECT_CONFLICT_VEC_P is FALSE. */ 1304 OBJECT_CONFLICT_VEC_P is FALSE. */
1202 unsigned IRA_INT_TYPE word; 1305 unsigned IRA_INT_TYPE word;
1203 } ira_object_conflict_iterator; 1306 };
1204 1307
1205 /* Initialize the iterator I with ALLOCNO conflicts. */ 1308 /* Initialize the iterator I with ALLOCNO conflicts. */
1206 static inline void 1309 static inline void
1207 ira_object_conflict_iter_init (ira_object_conflict_iterator *i, 1310 ira_object_conflict_iter_init (ira_object_conflict_iterator *i,
1208 ira_object_t obj) 1311 ira_object_t obj)
1235 { 1338 {
1236 ira_object_t obj; 1339 ira_object_t obj;
1237 1340
1238 if (i->conflict_vec_p) 1341 if (i->conflict_vec_p)
1239 { 1342 {
1240 obj = ((ira_object_t *) i->vec)[i->word_num]; 1343 obj = ((ira_object_t *) i->vec)[i->word_num++];
1241 if (obj == NULL) 1344 if (obj == NULL)
1242 return false; 1345 return false;
1243 } 1346 }
1244 else 1347 else
1245 { 1348 {
1349 unsigned IRA_INT_TYPE word = i->word;
1350 unsigned int bit_num = i->bit_num;
1351
1246 /* Skip words that are zeros. */ 1352 /* Skip words that are zeros. */
1247 for (; i->word == 0; i->word = ((IRA_INT_TYPE *) i->vec)[i->word_num]) 1353 for (; word == 0; word = ((IRA_INT_TYPE *) i->vec)[i->word_num])
1248 { 1354 {
1249 i->word_num++; 1355 i->word_num++;
1250 1356
1251 /* If we have reached the end, break. */ 1357 /* If we have reached the end, break. */
1252 if (i->word_num * sizeof (IRA_INT_TYPE) >= i->size) 1358 if (i->word_num * sizeof (IRA_INT_TYPE) >= i->size)
1253 return false; 1359 return false;
1254 1360
1255 i->bit_num = i->word_num * IRA_INT_BITS; 1361 bit_num = i->word_num * IRA_INT_BITS;
1256 } 1362 }
1257 1363
1258 /* Skip bits that are zero. */ 1364 /* Skip bits that are zero. */
1259 for (; (i->word & 1) == 0; i->word >>= 1) 1365 for (; (word & 1) == 0; word >>= 1)
1260 i->bit_num++; 1366 bit_num++;
1261 1367
1262 obj = ira_object_id_map[i->bit_num + i->base_conflict_id]; 1368 obj = ira_object_id_map[bit_num + i->base_conflict_id];
1369 i->bit_num = bit_num + 1;
1370 i->word = word >> 1;
1263 } 1371 }
1264 1372
1265 *pobj = obj; 1373 *pobj = obj;
1266 return true; 1374 return true;
1267 }
1268
1269 /* Advance to the next conflicting allocno. */
1270 static inline void
1271 ira_object_conflict_iter_next (ira_object_conflict_iterator *i)
1272 {
1273 if (i->conflict_vec_p)
1274 i->word_num++;
1275 else
1276 {
1277 i->word >>= 1;
1278 i->bit_num++;
1279 }
1280 } 1375 }
1281 1376
1282 /* Loop over all objects conflicting with OBJ. In each iteration, 1377 /* Loop over all objects conflicting with OBJ. In each iteration,
1283 CONF is set to the next conflicting object. ITER is an instance 1378 CONF is set to the next conflicting object. ITER is an instance
1284 of ira_object_conflict_iterator used to iterate the conflicts. */ 1379 of ira_object_conflict_iterator used to iterate the conflicts. */
1285 #define FOR_EACH_OBJECT_CONFLICT(OBJ, CONF, ITER) \ 1380 #define FOR_EACH_OBJECT_CONFLICT(OBJ, CONF, ITER) \
1286 for (ira_object_conflict_iter_init (&(ITER), (OBJ)); \ 1381 for (ira_object_conflict_iter_init (&(ITER), (OBJ)); \
1287 ira_object_conflict_iter_cond (&(ITER), &(CONF)); \ 1382 ira_object_conflict_iter_cond (&(ITER), &(CONF));)
1288 ira_object_conflict_iter_next (&(ITER)))
1289 1383
1290 1384
1291 1385
1292 /* The function returns TRUE if hard registers starting with 1386 /* The function returns TRUE if at least one hard register from ones
1293 HARD_REGNO and containing value of MODE are not in set 1387 starting with HARD_REGNO and containing value of MODE are in set
1294 HARD_REGSET. */ 1388 HARD_REGSET. */
1295 static inline bool 1389 static inline bool
1296 ira_hard_reg_not_in_set_p (int hard_regno, enum machine_mode mode, 1390 ira_hard_reg_set_intersection_p (int hard_regno, machine_mode mode,
1297 HARD_REG_SET hard_regset) 1391 HARD_REG_SET hard_regset)
1298 { 1392 {
1299 int i; 1393 int i;
1300 1394
1395 gcc_assert (hard_regno >= 0);
1396 for (i = hard_regno_nregs (hard_regno, mode) - 1; i >= 0; i--)
1397 if (TEST_HARD_REG_BIT (hard_regset, hard_regno + i))
1398 return true;
1399 return false;
1400 }
1401
1402 /* Return number of hard registers in hard register SET. */
1403 static inline int
1404 hard_reg_set_size (HARD_REG_SET set)
1405 {
1406 int i, size;
1407
1408 for (size = i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1409 if (TEST_HARD_REG_BIT (set, i))
1410 size++;
1411 return size;
1412 }
1413
1414 /* The function returns TRUE if hard registers starting with
1415 HARD_REGNO and containing value of MODE are fully in set
1416 HARD_REGSET. */
1417 static inline bool
1418 ira_hard_reg_in_set_p (int hard_regno, machine_mode mode,
1419 HARD_REG_SET hard_regset)
1420 {
1421 int i;
1422
1301 ira_assert (hard_regno >= 0); 1423 ira_assert (hard_regno >= 0);
1302 for (i = hard_regno_nregs[hard_regno][mode] - 1; i >= 0; i--) 1424 for (i = hard_regno_nregs (hard_regno, mode) - 1; i >= 0; i--)
1303 if (TEST_HARD_REG_BIT (hard_regset, hard_regno + i)) 1425 if (!TEST_HARD_REG_BIT (hard_regset, hard_regno + i))
1304 return false; 1426 return false;
1305 return true; 1427 return true;
1306 } 1428 }
1307 1429
1308 1430
1309 1431
1310 /* To save memory we use a lazy approach for allocation and 1432 /* To save memory we use a lazy approach for allocation and
1311 initialization of the cost vectors. We do this only when it is 1433 initialization of the cost vectors. We do this only when it is
1312 really necessary. */ 1434 really necessary. */
1313 1435
1314 /* Allocate cost vector *VEC for hard registers of COVER_CLASS and 1436 /* Allocate cost vector *VEC for hard registers of ACLASS and
1315 initialize the elements by VAL if it is necessary */ 1437 initialize the elements by VAL if it is necessary */
1316 static inline void 1438 static inline void
1317 ira_allocate_and_set_costs (int **vec, enum reg_class cover_class, int val) 1439 ira_allocate_and_set_costs (int **vec, reg_class_t aclass, int val)
1318 { 1440 {
1319 int i, *reg_costs; 1441 int i, *reg_costs;
1320 int len; 1442 int len;
1321 1443
1322 if (*vec != NULL) 1444 if (*vec != NULL)
1323 return; 1445 return;
1324 *vec = reg_costs = ira_allocate_cost_vector (cover_class); 1446 *vec = reg_costs = ira_allocate_cost_vector (aclass);
1325 len = ira_class_hard_regs_num[cover_class]; 1447 len = ira_class_hard_regs_num[(int) aclass];
1326 for (i = 0; i < len; i++) 1448 for (i = 0; i < len; i++)
1327 reg_costs[i] = val; 1449 reg_costs[i] = val;
1328 } 1450 }
1329 1451
1330 /* Allocate cost vector *VEC for hard registers of COVER_CLASS and 1452 /* Allocate cost vector *VEC for hard registers of ACLASS and copy
1331 copy values of vector SRC into the vector if it is necessary */ 1453 values of vector SRC into the vector if it is necessary */
1332 static inline void 1454 static inline void
1333 ira_allocate_and_copy_costs (int **vec, enum reg_class cover_class, int *src) 1455 ira_allocate_and_copy_costs (int **vec, enum reg_class aclass, int *src)
1334 { 1456 {
1335 int len; 1457 int len;
1336 1458
1337 if (*vec != NULL || src == NULL) 1459 if (*vec != NULL || src == NULL)
1338 return; 1460 return;
1339 *vec = ira_allocate_cost_vector (cover_class); 1461 *vec = ira_allocate_cost_vector (aclass);
1340 len = ira_class_hard_regs_num[cover_class]; 1462 len = ira_class_hard_regs_num[aclass];
1341 memcpy (*vec, src, sizeof (int) * len); 1463 memcpy (*vec, src, sizeof (int) * len);
1342 } 1464 }
1343 1465
1344 /* Allocate cost vector *VEC for hard registers of COVER_CLASS and 1466 /* Allocate cost vector *VEC for hard registers of ACLASS and add
1345 add values of vector SRC into the vector if it is necessary */ 1467 values of vector SRC into the vector if it is necessary */
1346 static inline void 1468 static inline void
1347 ira_allocate_and_accumulate_costs (int **vec, enum reg_class cover_class, 1469 ira_allocate_and_accumulate_costs (int **vec, enum reg_class aclass, int *src)
1348 int *src)
1349 { 1470 {
1350 int i, len; 1471 int i, len;
1351 1472
1352 if (src == NULL) 1473 if (src == NULL)
1353 return; 1474 return;
1354 len = ira_class_hard_regs_num[cover_class]; 1475 len = ira_class_hard_regs_num[aclass];
1355 if (*vec == NULL) 1476 if (*vec == NULL)
1356 { 1477 {
1357 *vec = ira_allocate_cost_vector (cover_class); 1478 *vec = ira_allocate_cost_vector (aclass);
1358 memset (*vec, 0, sizeof (int) * len); 1479 memset (*vec, 0, sizeof (int) * len);
1359 } 1480 }
1360 for (i = 0; i < len; i++) 1481 for (i = 0; i < len; i++)
1361 (*vec)[i] += src[i]; 1482 (*vec)[i] += src[i];
1362 } 1483 }
1363 1484
1364 /* Allocate cost vector *VEC for hard registers of COVER_CLASS and 1485 /* Allocate cost vector *VEC for hard registers of ACLASS and copy
1365 copy values of vector SRC into the vector or initialize it by VAL 1486 values of vector SRC into the vector or initialize it by VAL (if
1366 (if SRC is null). */ 1487 SRC is null). */
1367 static inline void 1488 static inline void
1368 ira_allocate_and_set_or_copy_costs (int **vec, enum reg_class cover_class, 1489 ira_allocate_and_set_or_copy_costs (int **vec, enum reg_class aclass,
1369 int val, int *src) 1490 int val, int *src)
1370 { 1491 {
1371 int i, *reg_costs; 1492 int i, *reg_costs;
1372 int len; 1493 int len;
1373 1494
1374 if (*vec != NULL) 1495 if (*vec != NULL)
1375 return; 1496 return;
1376 *vec = reg_costs = ira_allocate_cost_vector (cover_class); 1497 *vec = reg_costs = ira_allocate_cost_vector (aclass);
1377 len = ira_class_hard_regs_num[cover_class]; 1498 len = ira_class_hard_regs_num[aclass];
1378 if (src != NULL) 1499 if (src != NULL)
1379 memcpy (reg_costs, src, sizeof (int) * len); 1500 memcpy (reg_costs, src, sizeof (int) * len);
1380 else 1501 else
1381 { 1502 {
1382 for (i = 0; i < len; i++) 1503 for (i = 0; i < len; i++)
1383 reg_costs[i] = val; 1504 reg_costs[i] = val;
1384 } 1505 }
1385 } 1506 }
1507
1508 extern rtx ira_create_new_reg (rtx);
1509 extern int first_moveable_pseudo, last_moveable_pseudo;
1510
1511 #endif /* GCC_IRA_INT_H */