2008-05-21 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ira.c
blob67a95aac6771b703343d094ab39c8eaf6cbfdd74
1 /* Integrated Register Allocator (IRA) entry point.
2 Copyright (C) 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* The integrated register allocator (IRA) is a
23 regional register allocator performing graph coloring on a top-down
24 traversal of nested regions. Graph coloring in a region is based
25 on Chaitin-Briggs algorithm. It is called integrated because
26 register coalescing, register live range splitting, and choosing a
27 better hard register are done on-the-fly during coloring. Register
28 coalescing and choosing a cheaper hard register is done by hard
29 register preferencing during hard register assigning. The live
30 range splitting is a byproduct of the regional register allocation.
32 Major IRA notions are:
34 o *Region* is a part of CFG where graph coloring based on
35 Chaitin-Briggs algorithm is done. IRA can work on any set of
36 nested CFG regions forming a tree. Currently the regions are
37 the entire function for the root region and natural loops for
38 the other regions. Therefore data structure representing a
39 region is called loop_tree_node.
41 o *Cover class* is a register class belonging to a set of
42 non-intersecting register classes containing all of the
43 hard-registers available for register allocation. The set of
44 all cover classes for a target is defined in the corresponding
45 machine-description file according some criteria. Such notion
46 is needed because Chaitin-Briggs algorithm works on
47 non-intersected register classes.
49 o *Allocno* represents the live range of a pseudo-register in a
50 region. Besides the obvious attributes like the corresponding
51 pseudo-register number, cover class, conflicting allocnos and
52 conflicting hard-registers, there are a few allocno attributes
53 which are important for understanding the allocation algorithm:
55 - *Live ranges*. This is a list of ranges of *program points*
56 where the allocno lives. Program points represent places
57 where a pseudo can be born or become dead (there are
58 approximately two times more program points than the insns)
59 and they are represented by integers starting with 0. The
60 live ranges are used to find conflicts between allocnos of
61 different cover classes. They also play very important role
62 for transformation of IRA internal representation for several
63 regions into one region representation. The later is used
64 during the reload pass work because each allocno represents
65 all corresponding pseudo-register.
67 - *Hard-register costs*. This is a vector of size equal to the
68 number of available hard-registers of the allocno's cover
69 class. The cost of a callee-clobbered hard-register for an
70 allocno is increased by the cost of save/restore code around
71 the calls through the given allocno's life. If the allocno
72 is a move instruction operand and another operand is a
73 hard-register of the allocno's cover class, the cost of the
74 hard-register is decreased by the move cost.
76 When an allocno is assigned, the hard-register with minimal
77 full cost is used. Initially, a hard-register's full cost is
78 the corresponding value from the hard-register's cost vector.
79 If the allocno is connected by a *copy* (see below) to
80 another allocno which has just received a hard-register, the
81 cost of the hard-register is decreased. Before choosing a
82 hard-register for an allocno, the allocno's current costs of
83 the hard-registers are modified by the conflict hard-register
84 costs of all of the conflicting allocnos which are not
85 assigned yet.
87 - *Conflict hard-register costs*. This is a vector of the same
88 size as the hard-register costs vector. To permit an
89 unassigned allocno to get a better hard-register, IRA uses
90 this vector to calculate the final full cost of the
91 available hard-registers. Conflict hard-register costs of an
92 unassigned allocno are also changed with a change of the
93 hard-register cost of the allocno when a copy involving the
94 allocno is processed as described above. This is done to
95 show other unassigned allocnos that a given allocno prefers
96 some hard-registers in order to remove the move instruction
97 corresponding to the copy.
99 o *Cap*. If a pseudo-register does not live in a region but
100 lives in a nested region, IRA creates a special allocno called
101 a cap in the outer region. A region cap is also created for a
102 subregion cap.
104 o *Copy*. Allocnos can be connected by copies. Copies are used
105 to modify hard-register costs for allocnos during coloring.
106 Such modifications reflects a preference to use the same
107 hard-register for the allocnos connected by copies. Usually
108 copies are created for move insns (in this case it results in
109 register coalescing). But IRA also creates copies for operands
110 of an insn which should be assigned to the same hard-register
111 due to constraints in the machine description (it usually
112 results in removing a move generated in the reload to satisfy
113 the constraints) and copies referring to the allocno which is
114 the output operand of an instruction and the allocno which is
115 an input operand dying in the instruction (creation of such
116 copies results in less register shuffling). IRA *does not*
117 create copies between the same register allocnos from different
118 regions because we use another technique for propagating
119 hard-register preference on the borders of regions.
121 Allocnos (including caps) for the upper region in the region tree
122 *accumulate* information important for coloring from allocnos with
123 the same pseudo-register from nested regions. This includes
124 hard-register and memory costs, conflicts with hard-registers,
125 allocno conflicts, allocno copies and more. *Thus, attributes for
126 allocnos in a region have the same values as if the region had no
127 subregions*. It means that attributes for allocnos in the
128 outermost region corresponding to the function have the same values
129 as though the allocation used only one region which is the entire
130 function. It also means that we can look at IRA work as if the
131 first IRA did allocation for all function then it improved the
132 allocation for loops then their subloops and so on.
134 IRA major passes are:
136 o Building IRA internal representation which consists of the
137 following subpasses:
139 * First, IRA builds regions and creates allocnos (file
140 ira-build.c) and initializes most of their attributes.
142 * Then IRA finds a cover class for each allocno and calculates
143 its initial cost of memory and each hard-register of its
144 cover class (file ira-cost.c).
146 * IRA creates all caps (file ira-build.c).
148 * IRA creates live ranges of each allocno, calulates register
149 pressure for each cover class in each region, sets up
150 conflict hard registers for each allocno and call insns the
151 allocno lives through (file ira-lives.c).
153 * Having live-ranges of allocnos and their cover classes, IRA
154 creates conflicting allocnos of the same cover class for each
155 allocno. Conflicting allocnos are stored as a bit vector or
156 array of pointers to the conflicting allocnos whatever is more
157 profitable (file ira-conflicts.c). At this point IRA creates
158 allocno copies and after that accumulates allocno info
159 (conflicts, copies, call insns lived through) in upper level
160 allocnos from lower levels ones.
162 * Having all conflicts and other info for regular allocnos, IRA
163 propagates this info to caps (file ira-build.c) and modifies
164 costs of callee-clobbered hard-registers (file ira-costs.c).
166 o Coloring. Now IRA has all necessary info to start graph coloring
167 process. It is done in each region on top-down traverse of the
168 region tree (file ira-color.c). There are following subpasses:
170 * Optional aggressive coalescing of allocnos in the region.
172 * Putting allocnos onto the coloring stack. IRA uses Briggs
173 optimistic coloring which is a major improvement over
174 Chaitin's coloring. Therefore IRa does not spill allocnos at
175 this point. There is some freedom in order of putting
176 allocnos on the stack which can affect the final result of
177 the allocation. IRA uses some heuristics to improve the order.
179 * Popping the allocnos from the stack and assigning them hard
180 registers. If IRA can not assign a hard register to an
181 allocno and allocno is coalesced, IRA undoes coalescing and
182 put the uncoalesced allocnos onto the satck in hope that some
183 such allocnos will get a hard register separately. If IRA
184 fails to assign hard register or memory is more profitable
185 for it, IRA spills the allocno. IRA assigns allocno the
186 hard-register with minimal full allocation cost which
187 reflects the cost of usage of the hard-register for the
188 allocno and cost of usage of the hard-register for allocnos
189 conflicting with given allocno.
191 * After allono assigning in the region, IRA modifies hard
192 register and memory costs for the corresponding allocnos in
193 the subregions to reflect the cost of possible loads, stores,
194 or moves on the border of the region and its subregions.
195 When default regional allocation algorithm is used
196 (-fira-algorithm=mixed), IRA just propagates the assignment
197 for allocnos if the register pressure in the region for the
198 corresponding cover class is less than number of available
199 hard registers for given cover class.
201 o Spill/restore code moving. When IRA performs allocation
202 traversing regions in top-down order, it does not know what
203 happens below in the region tree. Therefore, sometimes IRA
204 misses opportunities to perform a better allocation. A simple
205 ooptimization tries to improve allocation in a region having
206 subregions and containing in another region. If the
207 corresponding allocnos in the subregion are spilled, it spills
208 the region allocno if it is profitable. The optimization
209 implements a simple iterative algorithm performing profitable
210 transformations while they are still possible. It is fast in
211 practice, so there is no real need for a better time complexity
212 algorithm.
214 o Code change. After coloring, two allocnos representing the same
215 pseudo-register outside and inside a region respectively may be
216 assigned to different locations (hard-registers or memory). In
217 this case IRA creates and uses a new pseudo-register inside the
218 region and add code to move allocno values on the region's
219 borders. This is done during top-down traversal of the regions
220 (file ira-emit.c). In some complicated cases IRA can create a
221 new allocno to move allocno values (e.g. when a swap of values
222 stored in two hard-registers is needed). At this stage, the
223 new allocno marked as spilled. IRA still creates the
224 pseudo-register and the moves on the region borders even when
225 both allocnos were assigned to the same hard-register. If the
226 reload pass spills a pseudo-register for some reason, the
227 effect will be smaller because another allocno will still be in
228 the hard-register. In most cases, this is better then spilling
229 both allocnos. If the reload does not change the allocation
230 for the two pseudo-registers, the trivial move will be removed
231 by post-reload optimizations. IRA does not generate moves for
232 allocnos assigned to the same hard register when the default
233 regional allocation algorithm is used and the register pressure
234 in the region for the corresponding allocno cover class is less
235 than number of available hard registers for given cover class.
236 IRA also does some optimizations to remove redundant stores and
237 to reduce code duplication on the region borders.
239 o Flattening internal representation. After changing code, IRA
240 transforms its internal representation for several regions into
241 one region representation (file ira-build.c). This process is
242 called IR flattening. Such process is more complicated than IR
243 rebuilding would be, but is much faster.
245 o After IR flattening, IRA tries to assign hard registers to all
246 spilled allocnos. It is impelemented by a simple and fast
247 priority coloring algorithm (see function
248 reassign_conflict_allocnos::ira-color.c). Here new allocnos
249 created during the code change pass can be assigned to hard
250 registers.
252 o At the end IRA calls the reload pass. The reload pass
253 communicates with IRA through several functions in file
254 ira-color.c to improve its decisions in
256 * sharing stack slots for the spilled pseudos based on IRA info
257 about pseudo-register conflicts.
259 * reassigning hard-registers to all spilled pseudos at the end
260 of each reload iteration.
262 * choosing a better hard-register to spill based on IRA info
263 about pseudo-register live ranges and the register pressure
264 in places where the pseudo-register lives.
266 IRA uses a lot of data representing the target processors. These
267 data are initilized in file ira.c.
269 If function has no loops (or the loops are ignored when
270 -fira-algorithm=CB is used), we have classic Chaitin-Briggs
271 coloring (only instead of separate pass of coalescing, we use hard
272 register preferencing). In such case, IRA works much faster
273 because many things are not made (like IR flattening, the
274 spill/restore optimization, and the code change).
276 Literature is worth to read for better understanding the code:
278 o Preston Briggs, Keith D. Cooper, Linda Torczon. Improvements to
279 Graph Coloring Register Allocation.
281 o David Callahan, Brian Koblenz. Register allocation via
282 hierarchical graph coloring.
284 o Keith Cooper, Anshuman Dasgupta, Jason Eckhardt. Revisiting Graph
285 Coloring Register Allocation: A Study of the Chaitin-Briggs and
286 Callahan-Koblenz Algorithms.
288 o Guei-Yuan Lueh, Thomas Gross, and Ali-Reza Adl-Tabatabai. Global
289 Register Allocation Based on Graph Fusion.
291 o Vladimir Makarov. The Integrated Register Allocator for GCC.
293 o Vladimir Makarov. The top-down register allocator for irregular
294 register file architectures.
299 #include "config.h"
300 #include "system.h"
301 #include "coretypes.h"
302 #include "tm.h"
303 #include "regs.h"
304 #include "rtl.h"
305 #include "tm_p.h"
306 #include "target.h"
307 #include "flags.h"
308 #include "obstack.h"
309 #include "bitmap.h"
310 #include "hard-reg-set.h"
311 #include "basic-block.h"
312 #include "expr.h"
313 #include "recog.h"
314 #include "params.h"
315 #include "timevar.h"
316 #include "tree-pass.h"
317 #include "output.h"
318 #include "reload.h"
319 #include "errors.h"
320 #include "integrate.h"
321 #include "df.h"
322 #include "ggc.h"
323 #include "ira-int.h"
325 static void setup_reg_mode_hard_regset (void);
326 static void setup_class_hard_regs (void);
327 static void setup_available_class_regs (void);
328 static void setup_alloc_regs (int);
329 static void setup_class_subset_and_memory_move_costs (void);
330 static void setup_reg_subclasses (void);
331 #ifdef IRA_COVER_CLASSES
332 static void setup_cover_and_important_classes (void);
333 static void setup_class_translate (void);
334 static void setup_reg_class_intersect_union (void);
335 #endif
336 static void print_class_cover (FILE *);
337 static void find_reg_class_closure (void);
338 static void setup_reg_class_nregs (void);
339 static void setup_prohibited_class_mode_regs (void);
340 static void free_register_move_costs (void);
341 static void setup_prohibited_mode_move_regs (void);
342 static int insn_contains_asm_1 (rtx *, void *);
343 static int insn_contains_asm (rtx);
344 static void compute_regs_asm_clobbered (char *);
345 static void setup_eliminable_regset (void);
346 static void find_reg_equiv_invariant_const (void);
347 static void setup_reg_renumber (void);
348 static void setup_allocno_assignment_flags (void);
349 static void calculate_allocation_cost (void);
350 #ifdef ENABLE_IRA_CHECKING
351 static void check_allocation (void);
352 #endif
353 static void fix_reg_equiv_init (void);
354 #ifdef ENABLE_IRA_CHECKING
355 static void print_redundant_copies (void);
356 #endif
357 static void setup_preferred_alternate_classes_for_new_pseudos (int);
358 static void expand_reg_info (int);
359 static int chain_freq_compare (const void *, const void *);
360 static int chain_bb_compare (const void *, const void *);
362 static void ira (FILE *);
363 static bool gate_ira (void);
364 static unsigned int rest_of_handle_ira (void);
366 /* A modified value of flag `-fira-verbose' used internally. */
367 int internal_flag_ira_verbose;
369 /* Dump file of the allocator if it is not NULL. */
370 FILE *ira_dump_file;
372 /* Pools for allocnos, copies, allocno live ranges. */
373 alloc_pool allocno_pool, copy_pool, allocno_live_range_pool;
375 /* The number of elements in the following array. */
376 int spilled_reg_stack_slots_num;
378 /* The following array contains info about spilled pseudo-registers
379 stack slots used in current function so far. */
380 struct spilled_reg_stack_slot *spilled_reg_stack_slots;
382 /* Correspondingly overall cost of the allocation, cost of the
383 allocnos assigned to hard-registers, cost of the allocnos assigned
384 to memory, cost of loads, stores and register move insns generated
385 for pseudo-register live range splitting (see ira-emit.c). */
386 int overall_cost;
387 int reg_cost, mem_cost;
388 int load_cost, store_cost, shuffle_cost;
389 int move_loops_num, additional_jumps_num;
391 /* Map: hard regs X modes -> set of hard registers for storing value
392 of given mode starting with given hard register. */
393 HARD_REG_SET reg_mode_hard_regset[FIRST_PSEUDO_REGISTER][NUM_MACHINE_MODES];
395 /* The following two variables are array analog of macros
396 MEMORY_MOVE_COST and REGISTER_MOVE_COST. */
397 short int memory_move_cost[MAX_MACHINE_MODE][N_REG_CLASSES][2];
398 move_table *register_move_cost[MAX_MACHINE_MODE];
400 /* Similar to may_move_in_cost but it is calculated in IRA instead of
401 regclass. Another difference we take only available hard registers
402 into account to figure out that one register class is a subset of
403 the another one. */
404 move_table *register_may_move_in_cost[MAX_MACHINE_MODE];
406 /* Similar to may_move_out_cost but it is calculated in IRA instead of
407 regclass. Another difference we take only available hard registers
408 into account to figure out that one register class is a subset of
409 the another one. */
410 move_table *register_may_move_out_cost[MAX_MACHINE_MODE];
412 /* Register class subset relation: TRUE if the first class is a subset
413 of the second one considering only hard registers available for the
414 allocation. */
415 int class_subset_p[N_REG_CLASSES][N_REG_CLASSES];
417 /* Temporary hard reg set used for different calculation. */
418 static HARD_REG_SET temp_hard_regset;
422 /* The function sets up map REG_MODE_HARD_REGSET. */
423 static void
424 setup_reg_mode_hard_regset (void)
426 int i, m, hard_regno;
428 for (m = 0; m < NUM_MACHINE_MODES; m++)
429 for (hard_regno = 0; hard_regno < FIRST_PSEUDO_REGISTER; hard_regno++)
431 CLEAR_HARD_REG_SET (reg_mode_hard_regset[hard_regno][m]);
432 for (i = hard_regno_nregs[hard_regno][m] - 1; i >= 0; i--)
433 if (hard_regno + i < FIRST_PSEUDO_REGISTER)
434 SET_HARD_REG_BIT (reg_mode_hard_regset[hard_regno][m],
435 hard_regno + i);
441 /* Hard registers that can not be used for the register allocator for
442 all functions of the current compilation unit. */
443 static HARD_REG_SET no_unit_alloc_regs;
445 /* Array of number of hard registers of given class which are
446 available for the allocation. The order is defined by the
447 allocation order. */
448 short class_hard_regs[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
450 /* The number of elements of the above array for given register
451 class. */
452 int class_hard_regs_num[N_REG_CLASSES];
454 /* Index (in class_hard_regs) for given register class and hard
455 register (in general case a hard register can belong to several
456 register classes). The index is negative for hard registers
457 unavailable for the allocation. */
458 short class_hard_reg_index[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
460 /* The function sets up the three arrays declared above. */
461 static void
462 setup_class_hard_regs (void)
464 int cl, i, hard_regno, n;
465 HARD_REG_SET processed_hard_reg_set;
467 ira_assert (SHRT_MAX >= FIRST_PSEUDO_REGISTER);
468 /* We could call ORDER_REGS_FOR_LOCAL_ALLOC here (it is usually
469 putting hard callee-used hard registers first). But our
470 heuristics work better. */
471 for (cl = (int) N_REG_CLASSES - 1; cl >= 0; cl--)
473 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[cl]);
474 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
475 CLEAR_HARD_REG_SET (processed_hard_reg_set);
476 for (n = 0, i = 0; i < FIRST_PSEUDO_REGISTER; i++)
478 #ifdef REG_ALLOC_ORDER
479 hard_regno = reg_alloc_order[i];
480 #else
481 hard_regno = i;
482 #endif
483 if (TEST_HARD_REG_BIT (processed_hard_reg_set, hard_regno))
484 continue;
485 SET_HARD_REG_BIT (processed_hard_reg_set, hard_regno);
486 if (! TEST_HARD_REG_BIT (temp_hard_regset, hard_regno))
487 class_hard_reg_index[cl][hard_regno] = -1;
488 else
490 class_hard_reg_index[cl][hard_regno] = n;
491 class_hard_regs[cl][n++] = hard_regno;
494 class_hard_regs_num[cl] = n;
498 /* Number of given class hard registers available for the register
499 allocation for given classes. */
500 int available_class_regs[N_REG_CLASSES];
502 /* Function setting up AVAILABLE_CLASS_REGS. */
503 static void
504 setup_available_class_regs (void)
506 int i, j;
508 memset (available_class_regs, 0, sizeof (available_class_regs));
509 for (i = 0; i < N_REG_CLASSES; i++)
511 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[i]);
512 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
513 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
514 if (TEST_HARD_REG_BIT (temp_hard_regset, j))
515 available_class_regs[i]++;
519 /* The function setting up different global variables defining info
520 about hard registers for the allocation. It depends on
521 USE_HARD_FRAME_P whose nonzero value means that we can use hard
522 frame pointer for the allocation. */
523 static void
524 setup_alloc_regs (int use_hard_frame_p)
526 COPY_HARD_REG_SET (no_unit_alloc_regs, fixed_reg_set);
527 if (! use_hard_frame_p)
528 SET_HARD_REG_BIT (no_unit_alloc_regs, HARD_FRAME_POINTER_REGNUM);
529 setup_class_hard_regs ();
530 setup_available_class_regs ();
535 /* The function sets up MEMORY_MOVE_COST, REGISTER_MOVE_COST. */
536 static void
537 setup_class_subset_and_memory_move_costs (void)
539 int cl, cl2;
540 enum machine_mode mode;
541 HARD_REG_SET temp_hard_regset2;
543 for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
544 memory_move_cost[mode][NO_REGS][0]
545 = memory_move_cost[mode][NO_REGS][1] = SHRT_MAX;
546 for (cl = (int) N_REG_CLASSES - 1; cl >= 0; cl--)
548 if (cl != (int) NO_REGS)
549 for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
551 memory_move_cost[mode][cl][0] = MEMORY_MOVE_COST (mode, cl, 0);
552 memory_move_cost[mode][cl][1] = MEMORY_MOVE_COST (mode, cl, 1);
553 /* Costs for NO_REGS are used in cost calculation on the
554 1st pass when the preferred register classes are not
555 known yet. In this case we take the best scenario. */
556 if (memory_move_cost[mode][NO_REGS][0]
557 > memory_move_cost[mode][cl][0])
558 memory_move_cost[mode][NO_REGS][0]
559 = memory_move_cost[mode][cl][0];
560 if (memory_move_cost[mode][NO_REGS][1]
561 > memory_move_cost[mode][cl][1])
562 memory_move_cost[mode][NO_REGS][1]
563 = memory_move_cost[mode][cl][1];
565 for (cl2 = (int) N_REG_CLASSES - 1; cl2 >= 0; cl2--)
567 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[cl]);
568 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
569 COPY_HARD_REG_SET (temp_hard_regset2, reg_class_contents[cl2]);
570 AND_COMPL_HARD_REG_SET (temp_hard_regset2, no_unit_alloc_regs);
571 class_subset_p[cl][cl2]
572 = hard_reg_set_subset_p (temp_hard_regset, temp_hard_regset2);
579 /* Define the following macro if allocation through malloc if
580 preferable. */
581 #define IRA_NO_OBSTACK
583 #ifndef IRA_NO_OBSTACK
584 /* Obstack used for storing all dynamic data (except bitmaps) of the
585 IRA. */
586 static struct obstack ira_obstack;
587 #endif
589 /* Obstack used for storing all bitmaps of the IRA. */
590 static struct bitmap_obstack ira_bitmap_obstack;
592 /* The function allocates memory of size LEN for IRA data. */
593 void *
594 ira_allocate (size_t len)
596 void *res;
598 #ifndef IRA_NO_OBSTACK
599 res = obstack_alloc (&ira_obstack, len);
600 #else
601 res = xmalloc (len);
602 #endif
603 return res;
606 /* The function reallocates memory PTR of size LEN for IRA data. */
607 void *
608 ira_reallocate (void *ptr, size_t len)
610 void *res;
612 #ifndef IRA_NO_OBSTACK
613 res = obstack_alloc (&ira_obstack, len);
614 #else
615 res = xrealloc (ptr, len);
616 #endif
617 return res;
620 /* The function free memory ADDR allocated for IRA data. */
621 void
622 ira_free (void *addr ATTRIBUTE_UNUSED)
624 #ifndef IRA_NO_OBSTACK
625 /* do nothing */
626 #else
627 free (addr);
628 #endif
632 /* The function allocates and returns bitmap for IRA. */
633 bitmap
634 ira_allocate_bitmap (void)
636 return BITMAP_ALLOC (&ira_bitmap_obstack);
639 /* The function frees bitmap B allocated for IRA. */
640 void
641 ira_free_bitmap (bitmap b ATTRIBUTE_UNUSED)
643 /* do nothing */
648 /* The function outputs information about allocation of all allocnos
649 into file F. */
650 void
651 print_disposition (FILE *f)
653 int i, n, max_regno;
654 allocno_t a;
655 basic_block bb;
657 fprintf (f, "Disposition:");
658 max_regno = max_reg_num ();
659 for (n = 0, i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
660 for (a = regno_allocno_map[i];
661 a != NULL;
662 a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
664 if (n % 4 == 0)
665 fprintf (f, "\n");
666 n++;
667 fprintf (f, " %4d:r%-4d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
668 if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
669 fprintf (f, "b%-3d", bb->index);
670 else
671 fprintf (f, "l%-3d", ALLOCNO_LOOP_TREE_NODE (a)->loop->num);
672 if (ALLOCNO_HARD_REGNO (a) >= 0)
673 fprintf (f, " %3d", ALLOCNO_HARD_REGNO (a));
674 else
675 fprintf (f, " mem");
677 fprintf (f, "\n");
680 /* The function outputs information about allocation of all allocnos
681 into stderr. */
682 void
683 debug_disposition (void)
685 print_disposition (stderr);
690 /* For each reg class, table listing all the classes contained in it
691 (excluding the class itself. Non-allocatable registers are
692 excluded from the consideration). */
693 static enum reg_class alloc_reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
695 /* The function initializes the table of subclasses of each reg
696 class. */
697 static void
698 setup_reg_subclasses (void)
700 int i, j;
701 HARD_REG_SET temp_hard_regset2;
703 for (i = 0; i < N_REG_CLASSES; i++)
704 for (j = 0; j < N_REG_CLASSES; j++)
705 alloc_reg_class_subclasses[i][j] = LIM_REG_CLASSES;
707 for (i = 0; i < N_REG_CLASSES; i++)
709 if (i == (int) NO_REGS)
710 continue;
712 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[i]);
713 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
714 if (hard_reg_set_equal_p (temp_hard_regset, zero_hard_reg_set))
715 continue;
716 for (j = 0; j < N_REG_CLASSES; j++)
717 if (i != j)
719 enum reg_class *p;
721 COPY_HARD_REG_SET (temp_hard_regset2, reg_class_contents[j]);
722 AND_COMPL_HARD_REG_SET (temp_hard_regset2, no_unit_alloc_regs);
723 if (! hard_reg_set_subset_p (temp_hard_regset,
724 temp_hard_regset2))
725 continue;
726 p = &alloc_reg_class_subclasses[j][0];
727 while (*p != LIM_REG_CLASSES) p++;
728 *p = (enum reg_class) i;
735 /* Number of cover classes. Cover classes is non-intersected register
736 classes containing all hard-registers available for the
737 allocation. */
738 int reg_class_cover_size;
740 /* The array containing cover classes (see also comments for macro
741 IRA_COVER_CLASSES). Only first REG_CLASS_COVER_SIZE elements are
742 used for this. */
743 enum reg_class reg_class_cover[N_REG_CLASSES];
745 /* The value is number of elements in the subsequent array. */
746 int important_classes_num;
748 /* The array containing non-empty classes (including non-empty cover
749 classes) which are subclasses of cover classes. Such classes is
750 important for calculation of the hard register usage costs. */
751 enum reg_class important_classes[N_REG_CLASSES];
753 /* The array containing indexes of important classes in the previous
754 array. The array elements are defined only for important
755 classes. */
756 int important_class_nums[N_REG_CLASSES];
758 #ifdef IRA_COVER_CLASSES
760 /* The function checks IRA_COVER_CLASSES and sets the four global
761 variables defined above. */
762 static void
763 setup_cover_and_important_classes (void)
765 int i, j;
766 enum reg_class cl;
767 static enum reg_class classes[] = IRA_COVER_CLASSES;
768 HARD_REG_SET temp_hard_regset2;
770 reg_class_cover_size = 0;
771 for (i = 0; (cl = classes[i]) != LIM_REG_CLASSES; i++)
773 for (j = 0; j < i; j++)
774 if (reg_classes_intersect_p (cl, classes[j]))
775 gcc_unreachable ();
776 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[cl]);
777 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
778 if (! hard_reg_set_equal_p (temp_hard_regset, zero_hard_reg_set))
779 reg_class_cover[reg_class_cover_size++] = cl;
781 important_classes_num = 0;
782 for (cl = 0; cl < N_REG_CLASSES; cl++)
784 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[cl]);
785 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
786 if (! hard_reg_set_equal_p (temp_hard_regset, zero_hard_reg_set))
787 for (j = 0; j < reg_class_cover_size; j++)
789 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[cl]);
790 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
791 COPY_HARD_REG_SET (temp_hard_regset2,
792 reg_class_contents[reg_class_cover[j]]);
793 AND_COMPL_HARD_REG_SET (temp_hard_regset2, no_unit_alloc_regs);
794 if (cl == reg_class_cover[j]
795 || (hard_reg_set_subset_p (temp_hard_regset, temp_hard_regset2)
796 && ! hard_reg_set_equal_p (temp_hard_regset,
797 temp_hard_regset2)))
799 important_class_nums[cl] = important_classes_num;
800 important_classes[important_classes_num++] = cl;
805 #endif
807 /* Map of all register classes to corresponding cover class containing
808 the given class. If given class is not a subset of a cover class,
809 we translate it into the cheapest cover class. */
810 enum reg_class class_translate[N_REG_CLASSES];
812 #ifdef IRA_COVER_CLASSES
814 /* The function sets up array CLASS_TRANSLATE. */
815 static void
816 setup_class_translate (void)
818 enum reg_class cl, cover_class, best_class, *cl_ptr;
819 enum machine_mode mode;
820 int i, cost, min_cost, best_cost;
822 for (cl = 0; cl < N_REG_CLASSES; cl++)
823 class_translate[cl] = NO_REGS;
824 for (i = 0; i < reg_class_cover_size; i++)
826 cover_class = reg_class_cover[i];
827 for (cl_ptr = &alloc_reg_class_subclasses[cover_class][0];
828 (cl = *cl_ptr) != LIM_REG_CLASSES;
829 cl_ptr++)
831 if (class_translate[cl] == NO_REGS)
832 class_translate[cl] = cover_class;
833 #ifdef ENABLE_IRA_CHECKING
834 else
836 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[cl]);
837 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
838 if (! hard_reg_set_subset_p (temp_hard_regset,
839 zero_hard_reg_set))
840 gcc_unreachable ();
842 #endif
844 class_translate[cover_class] = cover_class;
846 /* For classes which are not fully covered by a cover class (in
847 other words covered by more one cover class), use the cheapest
848 cover class. */
849 for (cl = 0; cl < N_REG_CLASSES; cl++)
851 if (cl == NO_REGS || class_translate[cl] != NO_REGS)
852 continue;
853 best_class = NO_REGS;
854 best_cost = INT_MAX;
855 for (i = 0; i < reg_class_cover_size; i++)
857 cover_class = reg_class_cover[i];
858 COPY_HARD_REG_SET (temp_hard_regset,
859 reg_class_contents[cover_class]);
860 AND_HARD_REG_SET (temp_hard_regset, reg_class_contents[cl]);
861 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
862 if (! hard_reg_set_equal_p (temp_hard_regset, zero_hard_reg_set))
864 min_cost = INT_MAX;
865 for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
867 cost = (memory_move_cost[mode][cl][0]
868 + memory_move_cost[mode][cl][1]);
869 if (min_cost > cost)
870 min_cost = cost;
872 if (best_class == NO_REGS || best_cost > min_cost)
874 best_class = cover_class;
875 best_cost = min_cost;
879 class_translate[cl] = best_class;
882 #endif
884 /* The biggest important class inside of intersection of the two
885 classes (that is calculated taking only hard registers available
886 for allocation into account). If the both classes contain no hard
887 registers available for allocation, the value is calculated with
888 taking all hard-registers including fixed ones into account. */
889 enum reg_class reg_class_intersect[N_REG_CLASSES][N_REG_CLASSES];
891 /* The biggest important class inside of union of the two classes
892 (that is calculated taking only hard registers available for
893 allocation into account). If the both classes contain no hard
894 registers available for allocation, the value is calculated with
895 taking all hard-registers including fixed ones into account. In
896 other words, the value is the corresponding reg_class_subunion
897 value. */
898 enum reg_class reg_class_union[N_REG_CLASSES][N_REG_CLASSES];
900 #ifdef IRA_COVER_CLASSES
902 /* The function sets up REG_CLASS_INTERSECT and REG_CLASS_UNION. */
903 static void
904 setup_reg_class_intersect_union (void)
906 int i, cl1, cl2, cl3;
907 HARD_REG_SET intersection_set, union_set, temp_set2;
909 for (cl1 = 0; cl1 < N_REG_CLASSES; cl1++)
911 for (cl2 = 0; cl2 < N_REG_CLASSES; cl2++)
913 reg_class_intersect[cl1][cl2] = NO_REGS;
914 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[cl1]);
915 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
916 COPY_HARD_REG_SET (temp_set2, reg_class_contents[cl2]);
917 AND_COMPL_HARD_REG_SET (temp_set2, no_unit_alloc_regs);
918 if (hard_reg_set_equal_p (temp_hard_regset, zero_hard_reg_set)
919 && hard_reg_set_equal_p (temp_set2, zero_hard_reg_set))
921 for (i = 0;; i++)
923 cl3 = reg_class_subclasses[cl1][i];
924 if (cl3 == LIM_REG_CLASSES)
925 break;
926 if (reg_class_subset_p (reg_class_intersect[cl1][cl2], cl3))
927 reg_class_intersect[cl1][cl2] = cl3;
929 reg_class_union[cl1][cl2] = reg_class_subunion[cl1][cl2];
930 continue;
932 reg_class_union[cl1][cl2] = NO_REGS;
933 COPY_HARD_REG_SET (intersection_set, reg_class_contents[cl1]);
934 AND_HARD_REG_SET (intersection_set, reg_class_contents[cl2]);
935 AND_COMPL_HARD_REG_SET (intersection_set, no_unit_alloc_regs);
936 COPY_HARD_REG_SET (union_set, reg_class_contents[cl1]);
937 IOR_HARD_REG_SET (union_set, reg_class_contents[cl2]);
938 AND_COMPL_HARD_REG_SET (union_set, no_unit_alloc_regs);
939 for (i = 0; i < important_classes_num; i++)
941 cl3 = important_classes[i];
942 COPY_HARD_REG_SET (temp_hard_regset, reg_class_contents[cl3]);
943 AND_COMPL_HARD_REG_SET (temp_hard_regset, no_unit_alloc_regs);
944 if (hard_reg_set_subset_p (temp_hard_regset, intersection_set))
946 COPY_HARD_REG_SET
947 (temp_set2,
948 reg_class_contents[(int) reg_class_intersect[cl1][cl2]]);
949 AND_COMPL_HARD_REG_SET (temp_set2, no_unit_alloc_regs);
950 if (! hard_reg_set_subset_p (temp_hard_regset, temp_set2))
951 reg_class_intersect[cl1][cl2] = (enum reg_class) cl3;
953 if (hard_reg_set_subset_p (temp_hard_regset, union_set))
955 COPY_HARD_REG_SET
956 (temp_set2,
957 reg_class_contents[(int) reg_class_union[cl1][cl2]]);
958 AND_COMPL_HARD_REG_SET (temp_set2, no_unit_alloc_regs);
959 if (hard_reg_set_subset_p (temp_set2, temp_hard_regset))
960 reg_class_union[cl1][cl2] = (enum reg_class) cl3;
967 #endif
969 /* The function outputs all cover classes and the translation map into
970 file F. */
971 static void
972 print_class_cover (FILE *f)
974 static const char *const reg_class_names[] = REG_CLASS_NAMES;
975 int i;
977 fprintf (f, "Class cover:\n");
978 for (i = 0; i < reg_class_cover_size; i++)
979 fprintf (f, " %s", reg_class_names[reg_class_cover[i]]);
980 fprintf (f, "\nClass translation:\n");
981 for (i = 0; i < N_REG_CLASSES; i++)
982 fprintf (f, " %s -> %s\n", reg_class_names[i],
983 reg_class_names[class_translate[i]]);
986 /* The function outputs all cover classes and the translation map into
987 stderr. */
988 void
989 debug_class_cover (void)
991 print_class_cover (stderr);
994 /* Function setting up different arrays concerning class subsets,
995 cover and important classes. */
996 static void
997 find_reg_class_closure (void)
999 setup_reg_subclasses ();
1000 #ifdef IRA_COVER_CLASSES
1001 setup_cover_and_important_classes ();
1002 setup_class_translate ();
1003 setup_reg_class_intersect_union ();
1004 #endif
1009 /* Map: register class x machine mode -> number of hard registers of
1010 given class needed to store value of given mode. If the number is
1011 different, the size will be negative. */
1012 int reg_class_nregs[N_REG_CLASSES][MAX_MACHINE_MODE];
1014 /* Maximal value of the previous array elements. */
1015 int max_nregs;
1017 /* Function forming REG_CLASS_NREGS map. */
1018 static void
1019 setup_reg_class_nregs (void)
1021 int m;
1022 enum reg_class cl;
1024 max_nregs = -1;
1025 for (cl = 0; cl < N_REG_CLASSES; cl++)
1026 for (m = 0; m < MAX_MACHINE_MODE; m++)
1028 reg_class_nregs[cl][m] = CLASS_MAX_NREGS (cl, m);
1029 if (max_nregs < reg_class_nregs[cl][m])
1030 max_nregs = reg_class_nregs[cl][m];
1036 /* Array whose values are hard regset of hard registers available for
1037 the allocation of given register class whose HARD_REGNO_MODE_OK
1038 values for given mode are zero. */
1039 HARD_REG_SET prohibited_class_mode_regs[N_REG_CLASSES][NUM_MACHINE_MODES];
1041 /* The function setting up PROHIBITED_CLASS_MODE_REGS. */
1042 static void
1043 setup_prohibited_class_mode_regs (void)
1045 int i, j, k, hard_regno;
1046 enum reg_class cl;
1048 for (i = 0; i < reg_class_cover_size; i++)
1050 cl = reg_class_cover[i];
1051 for (j = 0; j < NUM_MACHINE_MODES; j++)
1053 CLEAR_HARD_REG_SET (prohibited_class_mode_regs[cl][j]);
1054 for (k = class_hard_regs_num[cl] - 1; k >= 0; k--)
1056 hard_regno = class_hard_regs[cl][k];
1057 if (! HARD_REGNO_MODE_OK (hard_regno, j))
1058 SET_HARD_REG_BIT (prohibited_class_mode_regs[cl][j],
1059 hard_regno);
1067 /* The function allocates and initializes REGISTER_MOVE_COST,
1068 REGISTER_MAY_MOVE_IN_COST, and REGISTER_MAY_MOVE_OUT_COST for MODE
1069 if it is not done yet. */
1070 void
1071 init_register_move_cost (enum machine_mode mode)
1073 int cl1, cl2;
1075 ira_assert (register_move_cost[mode] == NULL
1076 && register_may_move_in_cost[mode] == NULL
1077 && register_may_move_out_cost[mode] == NULL);
1078 if (move_cost[mode] == NULL)
1079 init_move_cost (mode);
1080 register_move_cost[mode] = move_cost[mode];
1081 /* Don't use ira_allocate because the tables exist out of scope of a
1082 IRA call. */
1083 register_may_move_in_cost[mode]
1084 = (move_table *) xmalloc (sizeof (move_table) * N_REG_CLASSES);
1085 memcpy (register_may_move_in_cost[mode], may_move_in_cost[mode],
1086 sizeof (move_table) * N_REG_CLASSES);
1087 register_may_move_out_cost[mode]
1088 = (move_table *) xmalloc (sizeof (move_table) * N_REG_CLASSES);
1089 memcpy (register_may_move_out_cost[mode], may_move_out_cost[mode],
1090 sizeof (move_table) * N_REG_CLASSES);
1091 for (cl1 = 0; cl1 < N_REG_CLASSES; cl1++)
1093 for (cl2 = 0; cl2 < N_REG_CLASSES; cl2++)
1095 if (class_subset_p[cl1][cl2])
1096 register_may_move_in_cost[mode][cl1][cl2] = 0;
1097 if (class_subset_p[cl2][cl1])
1098 register_may_move_out_cost[mode][cl1][cl2] = 0;
1105 /* Hard regsets whose all bits are correspondingly zero or one. */
1106 HARD_REG_SET zero_hard_reg_set;
1107 HARD_REG_SET one_hard_reg_set;
1109 /* The function called once during compiler work. It sets up
1110 different arrays whose values don't depend on the compiled
1111 function. */
1112 void
1113 init_ira_once (void)
1115 enum machine_mode mode;
1117 CLEAR_HARD_REG_SET (zero_hard_reg_set);
1118 SET_HARD_REG_SET (one_hard_reg_set);
1119 for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
1121 register_move_cost[mode] = NULL;
1122 register_may_move_in_cost[mode] = NULL;
1123 register_may_move_out_cost[mode] = NULL;
1125 init_ira_costs_once ();
1128 /* The function frees register_move_cost, register_may_move_in_cost,
1129 and register_may_move_out_cost for each mode. */
1130 static void
1131 free_register_move_costs (void)
1133 enum machine_mode mode;
1135 for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
1137 if (register_may_move_in_cost[mode] != NULL)
1138 free (register_may_move_in_cost[mode]);
1139 if (register_may_move_out_cost[mode] != NULL)
1140 free (register_may_move_out_cost[mode]);
1141 register_move_cost[mode] = NULL;
1142 register_may_move_in_cost[mode] = NULL;
1143 register_may_move_out_cost[mode] = NULL;
1147 /* The function called every time when register related information is
1148 changed. */
1149 void
1150 init_ira (void)
1152 free_register_move_costs ();
1153 setup_reg_mode_hard_regset ();
1154 setup_alloc_regs (flag_omit_frame_pointer != 0);
1155 setup_class_subset_and_memory_move_costs ();
1156 find_reg_class_closure ();
1157 setup_reg_class_nregs ();
1158 setup_prohibited_class_mode_regs ();
1159 init_ira_costs ();
1162 /* Function called once at the end of compiler work. */
1163 void
1164 finish_ira_once (void)
1166 finish_ira_costs_once ();
1167 free_register_move_costs ();
1172 /* Array whose values are hard regset of hard registers for which
1173 move of the hard register in given mode into itself is
1174 prohibited. */
1175 HARD_REG_SET prohibited_mode_move_regs[NUM_MACHINE_MODES];
1177 /* Flag of that the above array has been initialized. */
1178 static int prohibited_mode_move_regs_initialized_p = FALSE;
1180 /* The function setting up PROHIBITED_MODE_MOVE_REGS. */
1181 static void
1182 setup_prohibited_mode_move_regs (void)
1184 int i, j;
1185 rtx test_reg1, test_reg2, move_pat, move_insn;
1187 if (prohibited_mode_move_regs_initialized_p)
1188 return;
1189 prohibited_mode_move_regs_initialized_p = TRUE;
1190 test_reg1 = gen_rtx_REG (VOIDmode, 0);
1191 test_reg2 = gen_rtx_REG (VOIDmode, 0);
1192 move_pat = gen_rtx_SET (VOIDmode, test_reg1, test_reg2);
1193 move_insn = gen_rtx_INSN (VOIDmode, 0, 0, 0, 0, 0, move_pat, -1, 0);
1194 for (i = 0; i < NUM_MACHINE_MODES; i++)
1196 SET_HARD_REG_SET (prohibited_mode_move_regs[i]);
1197 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
1199 if (! HARD_REGNO_MODE_OK (j, i))
1200 continue;
1201 SET_REGNO (test_reg1, j);
1202 PUT_MODE (test_reg1, i);
1203 SET_REGNO (test_reg2, j);
1204 PUT_MODE (test_reg2, i);
1205 INSN_CODE (move_insn) = -1;
1206 recog_memoized (move_insn);
1207 if (INSN_CODE (move_insn) < 0)
1208 continue;
1209 extract_insn (move_insn);
1210 if (! constrain_operands (1))
1211 continue;
1212 CLEAR_HARD_REG_BIT (prohibited_mode_move_regs[i], j);
1219 /* Function specific hard registers that can not be used for the
1220 register allocation. */
1221 HARD_REG_SET no_alloc_regs;
1223 /* Return TRUE if *LOC contains an asm. */
1224 static int
1225 insn_contains_asm_1 (rtx *loc, void *data ATTRIBUTE_UNUSED)
1227 if ( !*loc)
1228 return 0;
1229 if (GET_CODE (*loc) == ASM_OPERANDS)
1230 return TRUE;
1231 return FALSE;
1235 /* Return true if INSN contains an ASM. */
1236 static int
1237 insn_contains_asm (rtx insn)
1239 return for_each_rtx (&insn, insn_contains_asm_1, NULL);
1242 /* Set up regs_asm_clobbered. */
1243 static void
1244 compute_regs_asm_clobbered (char *regs_asm_clobbered)
1246 basic_block bb;
1248 memset (regs_asm_clobbered, 0, sizeof (char) * FIRST_PSEUDO_REGISTER);
1250 FOR_EACH_BB (bb)
1252 rtx insn;
1253 FOR_BB_INSNS_REVERSE (bb, insn)
1255 struct df_ref **def_rec;
1257 if (insn_contains_asm (insn))
1258 for (def_rec = DF_INSN_DEFS (insn); *def_rec; def_rec++)
1260 struct df_ref *def = *def_rec;
1261 unsigned int dregno = DF_REF_REGNO (def);
1262 if (dregno < FIRST_PSEUDO_REGISTER)
1264 unsigned int i;
1265 enum machine_mode mode = GET_MODE (DF_REF_REAL_REG (def));
1266 unsigned int end = dregno
1267 + hard_regno_nregs[dregno][mode] - 1;
1269 for (i = dregno; i <= end; ++i)
1270 regs_asm_clobbered[i] = 1;
1278 /* The function sets up ELIMINABLE_REGSET, NO_ALLOC_REGS, and
1279 REGS_EVER_LIVE. */
1280 static void
1281 setup_eliminable_regset (void)
1283 int i;
1284 /* Like regs_ever_live, but 1 if a reg is set or clobbered from an
1285 asm. Unlike regs_ever_live, elements of this array corresponding
1286 to eliminable regs (like the frame pointer) are set if an asm
1287 sets them. */
1288 char *regs_asm_clobbered = alloca (FIRST_PSEUDO_REGISTER * sizeof (char));
1289 #ifdef ELIMINABLE_REGS
1290 static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
1291 #endif
1292 int need_fp
1293 = (! flag_omit_frame_pointer
1294 || (current_function_calls_alloca && EXIT_IGNORE_STACK)
1295 || FRAME_POINTER_REQUIRED);
1297 COPY_HARD_REG_SET (no_alloc_regs, no_unit_alloc_regs);
1298 CLEAR_HARD_REG_SET (eliminable_regset);
1300 compute_regs_asm_clobbered (regs_asm_clobbered);
1301 /* Build the regset of all eliminable registers and show we can't
1302 use those that we already know won't be eliminated. */
1303 #ifdef ELIMINABLE_REGS
1304 for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++)
1306 bool cannot_elim
1307 = (! CAN_ELIMINATE (eliminables[i].from, eliminables[i].to)
1308 || (eliminables[i].to == STACK_POINTER_REGNUM && need_fp));
1310 if (! regs_asm_clobbered[eliminables[i].from])
1312 SET_HARD_REG_BIT (eliminable_regset, eliminables[i].from);
1314 if (cannot_elim)
1315 SET_HARD_REG_BIT (no_alloc_regs, eliminables[i].from);
1317 else if (cannot_elim)
1318 error ("%s cannot be used in asm here",
1319 reg_names[eliminables[i].from]);
1320 else
1321 df_set_regs_ever_live (eliminables[i].from, true);
1323 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
1324 if (! regs_asm_clobbered[HARD_FRAME_POINTER_REGNUM])
1326 SET_HARD_REG_BIT (eliminable_regset, HARD_FRAME_POINTER_REGNUM);
1327 if (need_fp)
1328 SET_HARD_REG_BIT (no_alloc_regs, HARD_FRAME_POINTER_REGNUM);
1330 else if (need_fp)
1331 error ("%s cannot be used in asm here",
1332 reg_names[HARD_FRAME_POINTER_REGNUM]);
1333 else
1334 df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM, true);
1335 #endif
1337 #else
1338 if (! regs_asm_clobbered[FRAME_POINTER_REGNUM])
1340 SET_HARD_REG_BIT (eliminable_regset, FRAME_POINTER_REGNUM);
1341 if (need_fp)
1342 SET_HARD_REG_BIT (no_alloc_regs, FRAME_POINTER_REGNUM);
1344 else if (need_fp)
1345 error ("%s cannot be used in asm here", reg_names[FRAME_POINTER_REGNUM]);
1346 else
1347 df_set_regs_ever_live (FRAME_POINTER_REGNUM, true);
1348 #endif
1353 /* The length of the following two arrays. */
1354 int reg_equiv_len;
1356 /* The element value is TRUE if the corresponding regno value is
1357 invariant. */
1358 int *reg_equiv_invariant_p;
1360 /* The element value is equiv constant of given pseudo-register or
1361 NULL_RTX. */
1362 rtx *reg_equiv_const;
1364 /* The function sets up the two array declared above. */
1365 static void
1366 find_reg_equiv_invariant_const (void)
1368 int i, invariant_p;
1369 rtx list, insn, note, constant, x;
1371 for (i = FIRST_PSEUDO_REGISTER; i < reg_equiv_init_size; i++)
1373 constant = NULL_RTX;
1374 invariant_p = FALSE;
1375 for (list = reg_equiv_init[i]; list != NULL_RTX; list = XEXP (list, 1))
1377 insn = XEXP (list, 0);
1378 note = find_reg_note (insn, REG_EQUIV, NULL_RTX);
1380 if (note == NULL_RTX)
1381 continue;
1383 x = XEXP (note, 0);
1385 if (! function_invariant_p (x)
1386 || ! flag_pic
1387 /* A function invariant is often CONSTANT_P but may
1388 include a register. We promise to only pass CONSTANT_P
1389 objects to LEGITIMATE_PIC_OPERAND_P. */
1390 || (CONSTANT_P (x) && LEGITIMATE_PIC_OPERAND_P (x)))
1392 /* It can happen that a REG_EQUIV note contains a MEM
1393 that is not a legitimate memory operand. As later
1394 stages of the reload assume that all addresses found
1395 in the reg_equiv_* arrays were originally legitimate,
1396 we ignore such REG_EQUIV notes. */
1397 if (memory_operand (x, VOIDmode))
1398 invariant_p = MEM_READONLY_P (x);
1399 else if (function_invariant_p (x))
1401 if (GET_CODE (x) == PLUS
1402 || x == frame_pointer_rtx || x == arg_pointer_rtx)
1403 invariant_p = TRUE;
1404 else
1405 constant = x;
1409 reg_equiv_invariant_p[i] = invariant_p;
1410 reg_equiv_const[i] = constant;
1416 /* The function sets up REG_RENUMBER and CALLER_SAVE_NEEDED (used by
1417 the reload) from the allocation found by IRA. */
1418 static void
1419 setup_reg_renumber (void)
1421 int regno, hard_regno;
1422 allocno_t a;
1423 allocno_iterator ai;
1425 caller_save_needed = 0;
1426 FOR_EACH_ALLOCNO (a, ai)
1428 /* There are no caps at this point. */
1429 ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL);
1430 if (! ALLOCNO_ASSIGNED_P (a))
1431 /* It can happen if A is not referenced but partially anticipated
1432 somewhere in a region. */
1433 ALLOCNO_ASSIGNED_P (a) = TRUE;
1434 free_allocno_updated_costs (a);
1435 hard_regno = ALLOCNO_HARD_REGNO (a);
1436 regno = (int) REGNO (ALLOCNO_REG (a));
1437 reg_renumber[regno] = (hard_regno < 0 ? -1 : hard_regno);
1438 if (hard_regno >= 0 && ALLOCNO_CALLS_CROSSED_NUM (a) != 0
1439 && ! hard_reg_not_in_set_p (hard_regno, ALLOCNO_MODE (a),
1440 call_used_reg_set))
1442 ira_assert (!optimize || flag_caller_saves || regno >= reg_equiv_len
1443 || reg_equiv_const[regno]
1444 || reg_equiv_invariant_p[regno]);
1445 caller_save_needed = 1;
1450 /* The function sets up allocno assignment flags for further
1451 allocation improvements. */
1452 static void
1453 setup_allocno_assignment_flags (void)
1455 int hard_regno;
1456 allocno_t a;
1457 allocno_iterator ai;
1459 FOR_EACH_ALLOCNO (a, ai)
1461 if (! ALLOCNO_ASSIGNED_P (a))
1462 /* It can happen if A is not referenced but partially anticipated
1463 somewhere in a region. */
1464 free_allocno_updated_costs (a);
1465 hard_regno = ALLOCNO_HARD_REGNO (a);
1466 /* Don't assign hard registers to allocnos which are destination
1467 of removed store at the end of loop. It has no sense to keep
1468 the same value in different hard registers. It is also
1469 impossible to assign hard registers correctly to such
1470 allocnos because the cost info and info about intersected
1471 calls are incorrect for them. */
1472 ALLOCNO_ASSIGNED_P (a) = (hard_regno >= 0
1473 || ALLOCNO_MEM_OPTIMIZED_DEST_P (a));
1474 ira_assert (hard_regno < 0
1475 || ! hard_reg_not_in_set_p (hard_regno, ALLOCNO_MODE (a),
1476 reg_class_contents
1477 [ALLOCNO_COVER_CLASS (a)]));
1481 /* The function evaluates overall allocation cost and costs for using
1482 hard registers and memory for allocnos. */
1483 static void
1484 calculate_allocation_cost (void)
1486 int hard_regno, cost;
1487 allocno_t a;
1488 allocno_iterator ai;
1490 overall_cost = reg_cost = mem_cost = 0;
1491 FOR_EACH_ALLOCNO (a, ai)
1493 hard_regno = ALLOCNO_HARD_REGNO (a);
1494 ira_assert (hard_regno < 0
1495 || ! hard_reg_not_in_set_p
1496 (hard_regno, ALLOCNO_MODE (a),
1497 reg_class_contents[ALLOCNO_COVER_CLASS (a)]));
1498 if (hard_regno < 0)
1500 cost = ALLOCNO_MEMORY_COST (a);
1501 mem_cost += cost;
1503 else if (ALLOCNO_HARD_REG_COSTS (a) != NULL)
1505 cost = (ALLOCNO_HARD_REG_COSTS (a)
1506 [class_hard_reg_index[ALLOCNO_COVER_CLASS (a)][hard_regno]]);
1507 reg_cost += cost;
1509 else
1511 cost = ALLOCNO_COVER_CLASS_COST (a);
1512 reg_cost += cost;
1514 overall_cost += cost;
1517 if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
1519 fprintf (ira_dump_file,
1520 "+++Costs: overall %d, reg %d, mem %d, ld %d, st %d, move %d\n",
1521 overall_cost, reg_cost, mem_cost,
1522 load_cost, store_cost, shuffle_cost);
1523 fprintf (ira_dump_file, "+++ move loops %d, new jumps %d\n",
1524 move_loops_num, additional_jumps_num);
1529 #ifdef ENABLE_IRA_CHECKING
1530 /* The function checks correctness of the allocation. We do need this
1531 because of complicated code to transform more one region internal
1532 representation into one region representation. */
1533 static void
1534 check_allocation (void)
1536 allocno_t a, conflict_a;
1537 int hard_regno, conflict_hard_regno, nregs, conflict_nregs;
1538 allocno_conflict_iterator aci;
1539 allocno_iterator ai;
1541 FOR_EACH_ALLOCNO (a, ai)
1543 if (ALLOCNO_CAP_MEMBER (a) != NULL
1544 || (hard_regno = ALLOCNO_HARD_REGNO (a)) < 0)
1545 continue;
1546 nregs = hard_regno_nregs[hard_regno][ALLOCNO_MODE (a)];
1547 FOR_EACH_ALLOCNO_CONFLICT (a, conflict_a, aci)
1548 if ((conflict_hard_regno = ALLOCNO_HARD_REGNO (conflict_a)) >= 0)
1550 conflict_nregs
1551 = (hard_regno_nregs
1552 [conflict_hard_regno][ALLOCNO_MODE (conflict_a)]);
1553 if ((conflict_hard_regno <= hard_regno
1554 && hard_regno < conflict_hard_regno + conflict_nregs)
1555 || (hard_regno <= conflict_hard_regno
1556 && conflict_hard_regno < hard_regno + nregs))
1558 fprintf (stderr, "bad allocation for %d and %d\n",
1559 ALLOCNO_REGNO (a), ALLOCNO_REGNO (conflict_a));
1560 gcc_unreachable ();
1565 #endif
1567 /* The function fixes values of array REG_EQUIV_INIT after live range
1568 splitting done by IRA. */
1569 static void
1570 fix_reg_equiv_init (void)
1572 int max_regno = max_reg_num ();
1573 int i, new_regno;
1574 rtx x, prev, next, insn, set;
1576 if (reg_equiv_init_size < max_regno)
1578 reg_equiv_init = ggc_realloc (reg_equiv_init, max_regno * sizeof (rtx));
1579 while (reg_equiv_init_size < max_regno)
1580 reg_equiv_init[reg_equiv_init_size++] = NULL_RTX;
1581 for (i = FIRST_PSEUDO_REGISTER; i < reg_equiv_init_size; i++)
1582 for (prev = NULL_RTX, x = reg_equiv_init[i]; x != NULL_RTX; x = next)
1584 next = XEXP (x, 1);
1585 insn = XEXP (x, 0);
1586 set = single_set (insn);
1587 ira_assert (set != NULL_RTX
1588 && (REG_P (SET_DEST (set)) || REG_P (SET_SRC (set))));
1589 if (REG_P (SET_DEST (set))
1590 && ((int) REGNO (SET_DEST (set)) == i
1591 || (int) ORIGINAL_REGNO (SET_DEST (set)) == i))
1592 new_regno = REGNO (SET_DEST (set));
1593 else if (REG_P (SET_SRC (set))
1594 && ((int) REGNO (SET_SRC (set)) == i
1595 || (int) ORIGINAL_REGNO (SET_SRC (set)) == i))
1596 new_regno = REGNO (SET_SRC (set));
1597 else
1598 gcc_unreachable ();
1599 if (new_regno == i)
1600 prev = x;
1601 else
1603 if (prev == NULL_RTX)
1604 reg_equiv_init[i] = next;
1605 else
1606 XEXP (prev, 1) = next;
1607 XEXP (x, 1) = reg_equiv_init[new_regno];
1608 reg_equiv_init[new_regno] = x;
1614 #ifdef ENABLE_IRA_CHECKING
1615 /* The function prints redundant memory-memory copies. */
1616 static void
1617 print_redundant_copies (void)
1619 int hard_regno;
1620 allocno_t a;
1621 copy_t cp, next_cp;
1622 allocno_iterator ai;
1624 FOR_EACH_ALLOCNO (a, ai)
1626 if (ALLOCNO_CAP_MEMBER (a) != NULL)
1627 /* It is a cap. */
1628 continue;
1629 hard_regno = ALLOCNO_HARD_REGNO (a);
1630 if (hard_regno >= 0)
1631 continue;
1632 for (cp = ALLOCNO_COPIES (a); cp != NULL; cp = next_cp)
1633 if (cp->first == a)
1634 next_cp = cp->next_first_allocno_copy;
1635 else
1637 next_cp = cp->next_second_allocno_copy;
1638 if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL
1639 && cp->insn != NULL_RTX
1640 && ALLOCNO_HARD_REGNO (cp->first) == hard_regno)
1641 fprintf (ira_dump_file,
1642 " Redundant move from %d(freq %d):%d\n",
1643 INSN_UID (cp->insn), cp->freq, hard_regno);
1647 #endif
1649 /* Setup preferred and alternative classes for new pseudo-registers
1650 created by IRA starting with START. */
1651 static void
1652 setup_preferred_alternate_classes_for_new_pseudos (int start)
1654 int i, old_regno;
1655 int max_regno = max_reg_num ();
1657 for (i = start; i < max_regno; i++)
1659 old_regno = ORIGINAL_REGNO (regno_reg_rtx[i]);
1660 ira_assert (i != old_regno);
1661 setup_reg_classes (i, reg_preferred_class (old_regno),
1662 reg_alternate_class (old_regno));
1663 if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
1664 fprintf (ira_dump_file,
1665 " New r%d: setting preferred %s, alternative %s\n",
1666 i, reg_class_names[reg_preferred_class (old_regno)],
1667 reg_class_names[reg_alternate_class (old_regno)]);
1673 /* Regional allocation can create new pseudo-registers. The function
1674 expands some arrays for pseudo-registers. */
1675 static void
1676 expand_reg_info (int old_size)
1678 int i;
1679 int size = max_reg_num ();
1681 resize_reg_info ();
1682 for (i = old_size; i < size; i++)
1684 reg_renumber[i] = -1;
1685 setup_reg_classes (i, GENERAL_REGS, ALL_REGS);
1691 /* This page contains code for sorting the insn chain used by the
1692 reload. In old register allocator, the insn chain order
1693 corresponds to the order of insns in RTL. By putting insns with
1694 higher execution frequency first, the reload has a better chance to
1695 generate less expensive operand reloads for such insns. */
1697 /* Map bb index -> order number in the BB chain in RTL code. */
1698 static int *basic_block_order_nums;
1700 /* The function is used to sort insn chain according insn execution
1701 frequencies. */
1702 static int
1703 chain_freq_compare (const void *v1p, const void *v2p)
1705 const struct insn_chain *c1 = *(struct insn_chain * const *)v1p;
1706 const struct insn_chain *c2 = *(struct insn_chain * const *)v2p;
1707 int diff;
1709 diff = (BASIC_BLOCK (c2->block)->frequency
1710 - BASIC_BLOCK (c1->block)->frequency);
1711 if (diff)
1712 return diff;
1713 return (const char *) v1p - (const char *) v2p;
1716 /* The function is used to sort insn chain according insn original
1717 order. */
1718 static int
1719 chain_bb_compare (const void *v1p, const void *v2p)
1721 const struct insn_chain *c1 = *(struct insn_chain * const *)v1p;
1722 const struct insn_chain *c2 = *(struct insn_chain * const *)v2p;
1723 int diff;
1725 diff = (basic_block_order_nums[c1->block]
1726 - basic_block_order_nums[c2->block]);
1727 if (diff)
1728 return diff;
1729 return (const char *) v1p - (const char *) v2p;
1732 /* The function sorts insn chain according to insn frequencies if
1733 FREQ_P or according to insn original order otherwise. */
1734 void
1735 sort_insn_chain (int freq_p)
1737 struct insn_chain *chain, **chain_arr;
1738 basic_block bb;
1739 int i, n;
1741 for (n = 0, chain = reload_insn_chain; chain != 0; chain = chain->next)
1742 n++;
1743 if (n <= 1)
1744 return;
1745 chain_arr = ira_allocate (n * sizeof (struct insn_chain *));
1746 basic_block_order_nums = ira_allocate (sizeof (int) * last_basic_block);
1747 n = 0;
1748 FOR_EACH_BB (bb)
1750 basic_block_order_nums[bb->index] = n++;
1752 for (n = 0, chain = reload_insn_chain; chain != 0; chain = chain->next)
1753 chain_arr[n++] = chain;
1754 qsort (chain_arr, n, sizeof (struct insn_chain *),
1755 freq_p ? chain_freq_compare : chain_bb_compare);
1756 for (i = 1; i < n - 1; i++)
1758 chain_arr[i]->next = chain_arr[i + 1];
1759 chain_arr[i]->prev = chain_arr[i - 1];
1761 chain_arr[i]->next = NULL;
1762 chain_arr[i]->prev = chain_arr[i - 1];
1763 reload_insn_chain = chain_arr[0];
1764 reload_insn_chain->prev = NULL;
1765 reload_insn_chain->next = chain_arr[1];
1766 ira_free (basic_block_order_nums);
1767 ira_free (chain_arr);
1772 /* All natural loops. */
1773 struct loops ira_loops;
1775 /* This is the main entry of IRA. */
1776 static void
1777 ira (FILE *f)
1779 int overall_cost_before, loops_p, allocated_reg_info_size;
1780 int max_regno_before_ira, max_point_before_emit;
1781 int rebuild_p, saved_flag_ira_algorithm;
1782 basic_block bb;
1784 timevar_push (TV_IRA);
1786 if (flag_ira_verbose < 10)
1788 internal_flag_ira_verbose = flag_ira_verbose;
1789 ira_dump_file = f;
1791 else
1793 internal_flag_ira_verbose = flag_ira_verbose - 10;
1794 ira_dump_file = stderr;
1797 setup_prohibited_mode_move_regs ();
1799 df_note_add_problem ();
1801 if (optimize == 1)
1803 df_live_add_problem ();
1804 df_live_set_all_dirty ();
1806 df_analyze ();
1808 df_clear_flags (DF_NO_INSN_RESCAN);
1810 regstat_init_n_sets_and_refs ();
1811 regstat_compute_ri ();
1813 /* If we are not optimizing, then this is the only place before
1814 register allocation where dataflow is done. And that is needed
1815 to generate these warnings. */
1816 if (warn_clobbered)
1817 generate_setjmp_warnings ();
1819 rebuild_p = update_equiv_regs ();
1821 #ifndef IRA_NO_OBSTACK
1822 gcc_obstack_init (&ira_obstack);
1823 #endif
1824 bitmap_obstack_initialize (&ira_bitmap_obstack);
1825 if (optimize)
1827 max_regno = max_reg_num ();
1828 reg_equiv_len = max_regno;
1829 reg_equiv_invariant_p = ira_allocate (max_regno * sizeof (int));
1830 memset (reg_equiv_invariant_p, 0, max_regno * sizeof (int));
1831 reg_equiv_const = ira_allocate (max_regno * sizeof (rtx));
1832 memset (reg_equiv_const, 0, max_regno * sizeof (rtx));
1833 find_reg_equiv_invariant_const ();
1834 if (rebuild_p)
1836 timevar_push (TV_JUMP);
1837 rebuild_jump_labels (get_insns ());
1838 purge_all_dead_edges ();
1839 timevar_pop (TV_JUMP);
1843 max_regno_before_ira = allocated_reg_info_size = max_reg_num ();
1844 allocate_reg_info ();
1845 setup_eliminable_regset ();
1847 overall_cost = reg_cost = mem_cost = 0;
1848 load_cost = store_cost = shuffle_cost = 0;
1849 move_loops_num = additional_jumps_num = 0;
1851 ira_assert (current_loops == NULL);
1852 flow_loops_find (&ira_loops);
1853 current_loops = &ira_loops;
1854 saved_flag_ira_algorithm = flag_ira_algorithm;
1855 if (optimize && number_of_loops () > (unsigned) IRA_MAX_LOOPS_NUM)
1856 flag_ira_algorithm = IRA_ALGORITHM_CB;
1858 if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
1859 fprintf (ira_dump_file, "Building IRA IR\n");
1860 loops_p = ira_build (optimize
1861 && (flag_ira_algorithm == IRA_ALGORITHM_REGIONAL
1862 || flag_ira_algorithm == IRA_ALGORITHM_MIXED));
1863 if (optimize)
1864 ira_color ();
1865 else
1866 ira_fast_allocation ();
1868 max_point_before_emit = max_point;
1870 ira_emit (loops_p);
1872 if (optimize)
1874 max_regno = max_reg_num ();
1876 if (! loops_p)
1877 initiate_ira_assign ();
1878 else
1880 expand_reg_info (allocated_reg_info_size);
1881 setup_preferred_alternate_classes_for_new_pseudos
1882 (allocated_reg_info_size);
1883 allocated_reg_info_size = max_regno;
1885 if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
1886 fprintf (ira_dump_file, "Flattening IR\n");
1887 ira_flattening (max_regno_before_ira, max_point_before_emit);
1888 /* New insns were generated: add notes and recalculate live
1889 info. */
1890 df_analyze ();
1893 basic_block bb;
1895 FOR_ALL_BB (bb)
1896 bb->loop_father = NULL;
1897 current_loops = NULL;
1900 setup_allocno_assignment_flags ();
1901 initiate_ira_assign ();
1902 reassign_conflict_allocnos (max_regno);
1906 setup_reg_renumber ();
1908 calculate_allocation_cost ();
1910 #ifdef ENABLE_IRA_CHECKING
1911 if (optimize)
1912 check_allocation ();
1913 #endif
1915 delete_trivially_dead_insns (get_insns (), max_reg_num ());
1916 max_regno = max_reg_num ();
1918 /* Determine if the current function is a leaf before running IRA
1919 since this can impact optimizations done by the prologue and
1920 epilogue thus changing register elimination offsets. */
1921 current_function_is_leaf = leaf_function_p ();
1923 /* And the reg_equiv_memory_loc array. */
1924 VEC_safe_grow (rtx, gc, reg_equiv_memory_loc_vec, max_regno);
1925 memset (VEC_address (rtx, reg_equiv_memory_loc_vec), 0,
1926 sizeof (rtx) * max_regno);
1927 reg_equiv_memory_loc = VEC_address (rtx, reg_equiv_memory_loc_vec);
1929 if (max_regno != max_regno_before_ira)
1931 regstat_free_n_sets_and_refs ();
1932 regstat_free_ri ();
1933 regstat_init_n_sets_and_refs ();
1934 regstat_compute_ri ();
1937 allocate_initial_values (reg_equiv_memory_loc);
1939 overall_cost_before = overall_cost;
1940 if (optimize)
1942 fix_reg_equiv_init ();
1944 #ifdef ENABLE_IRA_CHECKING
1945 print_redundant_copies ();
1946 #endif
1948 spilled_reg_stack_slots_num = 0;
1949 spilled_reg_stack_slots
1950 = ira_allocate (max_regno * sizeof (struct spilled_reg_stack_slot));
1951 memset (spilled_reg_stack_slots, 0,
1952 max_regno * sizeof (struct spilled_reg_stack_slot));
1955 timevar_pop (TV_IRA);
1957 timevar_push (TV_RELOAD);
1958 df_set_flags (DF_NO_INSN_RESCAN);
1959 build_insn_chain ();
1961 if (optimize)
1962 sort_insn_chain (TRUE);
1964 reload_completed = !reload (get_insns (), optimize > 0);
1966 timevar_pop (TV_RELOAD);
1968 timevar_push (TV_IRA);
1970 if (optimize)
1972 ira_free (spilled_reg_stack_slots);
1974 finish_ira_assign ();
1977 if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL
1978 && overall_cost_before != overall_cost)
1979 fprintf (ira_dump_file, "+++Overall after reload %d\n", overall_cost);
1980 ira_destroy ();
1982 flow_loops_free (&ira_loops);
1983 free_dominance_info (CDI_DOMINATORS);
1984 FOR_ALL_BB (bb)
1985 bb->loop_father = NULL;
1986 current_loops = NULL;
1988 flag_ira_algorithm = saved_flag_ira_algorithm;
1990 regstat_free_ri ();
1991 regstat_free_n_sets_and_refs ();
1993 if (optimize)
1995 cleanup_cfg (CLEANUP_EXPENSIVE);
1997 ira_free (reg_equiv_invariant_p);
1998 ira_free (reg_equiv_const);
2001 bitmap_obstack_release (&ira_bitmap_obstack);
2002 #ifndef IRA_NO_OBSTACK
2003 obstack_free (&ira_obstack, NULL);
2004 #endif
2006 /* The code after the reload has changed so much that at this point
2007 we might as well just rescan everything. Not that
2008 df_rescan_all_insns is not going to help here because it does not
2009 touch the artificial uses and defs. */
2010 df_finish_pass (true);
2011 if (optimize > 1)
2012 df_live_add_problem ();
2013 df_scan_alloc (NULL);
2014 df_scan_blocks ();
2016 if (optimize)
2017 df_analyze ();
2019 timevar_pop (TV_IRA);
2024 static bool
2025 gate_ira (void)
2027 return flag_ira != 0;
2030 /* Run the integrated register allocator. */
2031 static unsigned int
2032 rest_of_handle_ira (void)
2034 ira (dump_file);
2035 return 0;
2038 struct rtl_opt_pass pass_ira =
2041 RTL_PASS,
2042 "ira", /* name */
2043 gate_ira, /* gate */
2044 rest_of_handle_ira, /* execute */
2045 NULL, /* sub */
2046 NULL, /* next */
2047 0, /* static_pass_number */
2048 0, /* tv_id */
2049 0, /* properties_required */
2050 0, /* properties_provided */
2051 0, /* properties_destroyed */
2052 0, /* todo_flags_start */
2053 TODO_dump_func |
2054 TODO_ggc_collect /* todo_flags_finish */