Branch data Line data Source code
1 : : /* Integrated Register Allocator (IRA) entry point.
2 : : Copyright (C) 2006-2025 Free Software Foundation, Inc.
3 : : Contributed by Vladimir Makarov <vmakarov@redhat.com>.
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify it under
8 : : the terms of the GNU General Public License as published by the Free
9 : : Software Foundation; either version 3, or (at your option) any later
10 : : version.
11 : :
12 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : : for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : : /* The integrated register allocator (IRA) is a
22 : : regional register allocator performing graph coloring on a top-down
23 : : traversal of nested regions. Graph coloring in a region is based
24 : : on Chaitin-Briggs algorithm. It is called integrated because
25 : : register coalescing, register live range splitting, and choosing a
26 : : better hard register are done on-the-fly during coloring. Register
27 : : coalescing and choosing a cheaper hard register is done by hard
28 : : register preferencing during hard register assigning. The live
29 : : range splitting is a byproduct of the regional register allocation.
30 : :
31 : : Major IRA notions are:
32 : :
33 : : o *Region* is a part of CFG where graph coloring based on
34 : : Chaitin-Briggs algorithm is done. IRA can work on any set of
35 : : nested CFG regions forming a tree. Currently the regions are
36 : : the entire function for the root region and natural loops for
37 : : the other regions. Therefore data structure representing a
38 : : region is called loop_tree_node.
39 : :
40 : : o *Allocno class* is a register class used for allocation of
41 : : given allocno. It means that only hard register of given
42 : : register class can be assigned to given allocno. In reality,
43 : : even smaller subset of (*profitable*) hard registers can be
44 : : assigned. In rare cases, the subset can be even smaller
45 : : because our modification of Chaitin-Briggs algorithm requires
46 : : that sets of hard registers can be assigned to allocnos forms a
47 : : forest, i.e. the sets can be ordered in a way where any
48 : : previous set is not intersected with given set or is a superset
49 : : of given set.
50 : :
51 : : o *Pressure class* is a register class belonging to a set of
52 : : register classes containing all of the hard-registers available
53 : : for register allocation. The set of all pressure classes for a
54 : : target is defined in the corresponding machine-description file
55 : : according some criteria. Register pressure is calculated only
56 : : for pressure classes and it affects some IRA decisions as
57 : : forming allocation regions.
58 : :
59 : : o *Allocno* represents the live range of a pseudo-register in a
60 : : region. Besides the obvious attributes like the corresponding
61 : : pseudo-register number, allocno class, conflicting allocnos and
62 : : conflicting hard-registers, there are a few allocno attributes
63 : : which are important for understanding the allocation algorithm:
64 : :
65 : : - *Live ranges*. This is a list of ranges of *program points*
66 : : where the allocno lives. Program points represent places
67 : : where a pseudo can be born or become dead (there are
68 : : approximately two times more program points than the insns)
69 : : and they are represented by integers starting with 0. The
70 : : live ranges are used to find conflicts between allocnos.
71 : : They also play very important role for the transformation of
72 : : the IRA internal representation of several regions into a one
73 : : region representation. The later is used during the reload
74 : : pass work because each allocno represents all of the
75 : : corresponding pseudo-registers.
76 : :
77 : : - *Hard-register costs*. This is a vector of size equal to the
78 : : number of available hard-registers of the allocno class. The
79 : : cost of a callee-clobbered hard-register for an allocno is
80 : : increased by the cost of save/restore code around the calls
81 : : through the given allocno's life. If the allocno is a move
82 : : instruction operand and another operand is a hard-register of
83 : : the allocno class, the cost of the hard-register is decreased
84 : : by the move cost.
85 : :
86 : : When an allocno is assigned, the hard-register with minimal
87 : : full cost is used. Initially, a hard-register's full cost is
88 : : the corresponding value from the hard-register's cost vector.
89 : : If the allocno is connected by a *copy* (see below) to
90 : : another allocno which has just received a hard-register, the
91 : : cost of the hard-register is decreased. Before choosing a
92 : : hard-register for an allocno, the allocno's current costs of
93 : : the hard-registers are modified by the conflict hard-register
94 : : costs of all of the conflicting allocnos which are not
95 : : assigned yet.
96 : :
97 : : - *Conflict hard-register costs*. This is a vector of the same
98 : : size as the hard-register costs vector. To permit an
99 : : unassigned allocno to get a better hard-register, IRA uses
100 : : this vector to calculate the final full cost of the
101 : : available hard-registers. Conflict hard-register costs of an
102 : : unassigned allocno are also changed with a change of the
103 : : hard-register cost of the allocno when a copy involving the
104 : : allocno is processed as described above. This is done to
105 : : show other unassigned allocnos that a given allocno prefers
106 : : some hard-registers in order to remove the move instruction
107 : : corresponding to the copy.
108 : :
109 : : o *Cap*. If a pseudo-register does not live in a region but
110 : : lives in a nested region, IRA creates a special allocno called
111 : : a cap in the outer region. A region cap is also created for a
112 : : subregion cap.
113 : :
114 : : o *Copy*. Allocnos can be connected by copies. Copies are used
115 : : to modify hard-register costs for allocnos during coloring.
116 : : Such modifications reflects a preference to use the same
117 : : hard-register for the allocnos connected by copies. Usually
118 : : copies are created for move insns (in this case it results in
119 : : register coalescing). But IRA also creates copies for operands
120 : : of an insn which should be assigned to the same hard-register
121 : : due to constraints in the machine description (it usually
122 : : results in removing a move generated in reload to satisfy
123 : : the constraints) and copies referring to the allocno which is
124 : : the output operand of an instruction and the allocno which is
125 : : an input operand dying in the instruction (creation of such
126 : : copies results in less register shuffling). IRA *does not*
127 : : create copies between the same register allocnos from different
128 : : regions because we use another technique for propagating
129 : : hard-register preference on the borders of regions.
130 : :
131 : : Allocnos (including caps) for the upper region in the region tree
132 : : *accumulate* information important for coloring from allocnos with
133 : : the same pseudo-register from nested regions. This includes
134 : : hard-register and memory costs, conflicts with hard-registers,
135 : : allocno conflicts, allocno copies and more. *Thus, attributes for
136 : : allocnos in a region have the same values as if the region had no
137 : : subregions*. It means that attributes for allocnos in the
138 : : outermost region corresponding to the function have the same values
139 : : as though the allocation used only one region which is the entire
140 : : function. It also means that we can look at IRA work as if the
141 : : first IRA did allocation for all function then it improved the
142 : : allocation for loops then their subloops and so on.
143 : :
144 : : IRA major passes are:
145 : :
146 : : o Building IRA internal representation which consists of the
147 : : following subpasses:
148 : :
149 : : * First, IRA builds regions and creates allocnos (file
150 : : ira-build.cc) and initializes most of their attributes.
151 : :
152 : : * Then IRA finds an allocno class for each allocno and
153 : : calculates its initial (non-accumulated) cost of memory and
154 : : each hard-register of its allocno class (file ira-cost.c).
155 : :
156 : : * IRA creates live ranges of each allocno, calculates register
157 : : pressure for each pressure class in each region, sets up
158 : : conflict hard registers for each allocno and info about calls
159 : : the allocno lives through (file ira-lives.cc).
160 : :
161 : : * IRA removes low register pressure loops from the regions
162 : : mostly to speed IRA up (file ira-build.cc).
163 : :
164 : : * IRA propagates accumulated allocno info from lower region
165 : : allocnos to corresponding upper region allocnos (file
166 : : ira-build.cc).
167 : :
168 : : * IRA creates all caps (file ira-build.cc).
169 : :
170 : : * Having live-ranges of allocnos and their classes, IRA creates
171 : : conflicting allocnos for each allocno. Conflicting allocnos
172 : : are stored as a bit vector or array of pointers to the
173 : : conflicting allocnos whatever is more profitable (file
174 : : ira-conflicts.cc). At this point IRA creates allocno copies.
175 : :
176 : : o Coloring. Now IRA has all necessary info to start graph coloring
177 : : process. It is done in each region on top-down traverse of the
178 : : region tree (file ira-color.cc). There are following subpasses:
179 : :
180 : : * Finding profitable hard registers of corresponding allocno
181 : : class for each allocno. For example, only callee-saved hard
182 : : registers are frequently profitable for allocnos living
183 : : through colors. If the profitable hard register set of
184 : : allocno does not form a tree based on subset relation, we use
185 : : some approximation to form the tree. This approximation is
186 : : used to figure out trivial colorability of allocnos. The
187 : : approximation is a pretty rare case.
188 : :
189 : : * Putting allocnos onto the coloring stack. IRA uses Briggs
190 : : optimistic coloring which is a major improvement over
191 : : Chaitin's coloring. Therefore IRA does not spill allocnos at
192 : : this point. There is some freedom in the order of putting
193 : : allocnos on the stack which can affect the final result of
194 : : the allocation. IRA uses some heuristics to improve the
195 : : order. The major one is to form *threads* from colorable
196 : : allocnos and push them on the stack by threads. Thread is a
197 : : set of non-conflicting colorable allocnos connected by
198 : : copies. The thread contains allocnos from the colorable
199 : : bucket or colorable allocnos already pushed onto the coloring
200 : : stack. Pushing thread allocnos one after another onto the
201 : : stack increases chances of removing copies when the allocnos
202 : : get the same hard reg.
203 : :
204 : : We also use a modification of Chaitin-Briggs algorithm which
205 : : works for intersected register classes of allocnos. To
206 : : figure out trivial colorability of allocnos, the mentioned
207 : : above tree of hard register sets is used. To get an idea how
208 : : the algorithm works in i386 example, let us consider an
209 : : allocno to which any general hard register can be assigned.
210 : : If the allocno conflicts with eight allocnos to which only
211 : : EAX register can be assigned, given allocno is still
212 : : trivially colorable because all conflicting allocnos might be
213 : : assigned only to EAX and all other general hard registers are
214 : : still free.
215 : :
216 : : To get an idea of the used trivial colorability criterion, it
217 : : is also useful to read article "Graph-Coloring Register
218 : : Allocation for Irregular Architectures" by Michael D. Smith
219 : : and Glen Holloway. Major difference between the article
220 : : approach and approach used in IRA is that Smith's approach
221 : : takes register classes only from machine description and IRA
222 : : calculate register classes from intermediate code too
223 : : (e.g. an explicit usage of hard registers in RTL code for
224 : : parameter passing can result in creation of additional
225 : : register classes which contain or exclude the hard
226 : : registers). That makes IRA approach useful for improving
227 : : coloring even for architectures with regular register files
228 : : and in fact some benchmarking shows the improvement for
229 : : regular class architectures is even bigger than for irregular
230 : : ones. Another difference is that Smith's approach chooses
231 : : intersection of classes of all insn operands in which a given
232 : : pseudo occurs. IRA can use bigger classes if it is still
233 : : more profitable than memory usage.
234 : :
235 : : * Popping the allocnos from the stack and assigning them hard
236 : : registers. If IRA cannot assign a hard register to an
237 : : allocno and the allocno is coalesced, IRA undoes the
238 : : coalescing and puts the uncoalesced allocnos onto the stack in
239 : : the hope that some such allocnos will get a hard register
240 : : separately. If IRA fails to assign hard register or memory
241 : : is more profitable for it, IRA spills the allocno. IRA
242 : : assigns the allocno the hard-register with minimal full
243 : : allocation cost which reflects the cost of usage of the
244 : : hard-register for the allocno and cost of usage of the
245 : : hard-register for allocnos conflicting with given allocno.
246 : :
247 : : * Chaitin-Briggs coloring assigns as many pseudos as possible
248 : : to hard registers. After coloring we try to improve
249 : : allocation with cost point of view. We improve the
250 : : allocation by spilling some allocnos and assigning the freed
251 : : hard registers to other allocnos if it decreases the overall
252 : : allocation cost.
253 : :
254 : : * After allocno assigning in the region, IRA modifies the hard
255 : : register and memory costs for the corresponding allocnos in
256 : : the subregions to reflect the cost of possible loads, stores,
257 : : or moves on the border of the region and its subregions.
258 : : When default regional allocation algorithm is used
259 : : (-fira-algorithm=mixed), IRA just propagates the assignment
260 : : for allocnos if the register pressure in the region for the
261 : : corresponding pressure class is less than number of available
262 : : hard registers for given pressure class.
263 : :
264 : : o Spill/restore code moving. When IRA performs an allocation
265 : : by traversing regions in top-down order, it does not know what
266 : : happens below in the region tree. Therefore, sometimes IRA
267 : : misses opportunities to perform a better allocation. A simple
268 : : optimization tries to improve allocation in a region having
269 : : subregions and containing in another region. If the
270 : : corresponding allocnos in the subregion are spilled, it spills
271 : : the region allocno if it is profitable. The optimization
272 : : implements a simple iterative algorithm performing profitable
273 : : transformations while they are still possible. It is fast in
274 : : practice, so there is no real need for a better time complexity
275 : : algorithm.
276 : :
277 : : o Code change. After coloring, two allocnos representing the
278 : : same pseudo-register outside and inside a region respectively
279 : : may be assigned to different locations (hard-registers or
280 : : memory). In this case IRA creates and uses a new
281 : : pseudo-register inside the region and adds code to move allocno
282 : : values on the region's borders. This is done during top-down
283 : : traversal of the regions (file ira-emit.cc). In some
284 : : complicated cases IRA can create a new allocno to move allocno
285 : : values (e.g. when a swap of values stored in two hard-registers
286 : : is needed). At this stage, the new allocno is marked as
287 : : spilled. IRA still creates the pseudo-register and the moves
288 : : on the region borders even when both allocnos were assigned to
289 : : the same hard-register. If the reload pass spills a
290 : : pseudo-register for some reason, the effect will be smaller
291 : : because another allocno will still be in the hard-register. In
292 : : most cases, this is better then spilling both allocnos. If
293 : : reload does not change the allocation for the two
294 : : pseudo-registers, the trivial move will be removed by
295 : : post-reload optimizations. IRA does not generate moves for
296 : : allocnos assigned to the same hard register when the default
297 : : regional allocation algorithm is used and the register pressure
298 : : in the region for the corresponding pressure class is less than
299 : : number of available hard registers for given pressure class.
300 : : IRA also does some optimizations to remove redundant stores and
301 : : to reduce code duplication on the region borders.
302 : :
303 : : o Flattening internal representation. After changing code, IRA
304 : : transforms its internal representation for several regions into
305 : : one region representation (file ira-build.cc). This process is
306 : : called IR flattening. Such process is more complicated than IR
307 : : rebuilding would be, but is much faster.
308 : :
309 : : o After IR flattening, IRA tries to assign hard registers to all
310 : : spilled allocnos. This is implemented by a simple and fast
311 : : priority coloring algorithm (see function
312 : : ira_reassign_conflict_allocnos::ira-color.cc). Here new allocnos
313 : : created during the code change pass can be assigned to hard
314 : : registers.
315 : :
316 : : o At the end IRA calls the reload pass. The reload pass
317 : : communicates with IRA through several functions in file
318 : : ira-color.cc to improve its decisions in
319 : :
320 : : * sharing stack slots for the spilled pseudos based on IRA info
321 : : about pseudo-register conflicts.
322 : :
323 : : * reassigning hard-registers to all spilled pseudos at the end
324 : : of each reload iteration.
325 : :
326 : : * choosing a better hard-register to spill based on IRA info
327 : : about pseudo-register live ranges and the register pressure
328 : : in places where the pseudo-register lives.
329 : :
330 : : IRA uses a lot of data representing the target processors. These
331 : : data are initialized in file ira.cc.
332 : :
333 : : If function has no loops (or the loops are ignored when
334 : : -fira-algorithm=CB is used), we have classic Chaitin-Briggs
335 : : coloring (only instead of separate pass of coalescing, we use hard
336 : : register preferencing). In such case, IRA works much faster
337 : : because many things are not made (like IR flattening, the
338 : : spill/restore optimization, and the code change).
339 : :
340 : : Literature is worth to read for better understanding the code:
341 : :
342 : : o Preston Briggs, Keith D. Cooper, Linda Torczon. Improvements to
343 : : Graph Coloring Register Allocation.
344 : :
345 : : o David Callahan, Brian Koblenz. Register allocation via
346 : : hierarchical graph coloring.
347 : :
348 : : o Keith Cooper, Anshuman Dasgupta, Jason Eckhardt. Revisiting Graph
349 : : Coloring Register Allocation: A Study of the Chaitin-Briggs and
350 : : Callahan-Koblenz Algorithms.
351 : :
352 : : o Guei-Yuan Lueh, Thomas Gross, and Ali-Reza Adl-Tabatabai. Global
353 : : Register Allocation Based on Graph Fusion.
354 : :
355 : : o Michael D. Smith and Glenn Holloway. Graph-Coloring Register
356 : : Allocation for Irregular Architectures
357 : :
358 : : o Vladimir Makarov. The Integrated Register Allocator for GCC.
359 : :
360 : : o Vladimir Makarov. The top-down register allocator for irregular
361 : : register file architectures.
362 : :
363 : : */
364 : :
365 : :
366 : : #include "config.h"
367 : : #include "system.h"
368 : : #include "coretypes.h"
369 : : #include "backend.h"
370 : : #include "target.h"
371 : : #include "rtl.h"
372 : : #include "tree.h"
373 : : #include "df.h"
374 : : #include "memmodel.h"
375 : : #include "tm_p.h"
376 : : #include "insn-config.h"
377 : : #include "regs.h"
378 : : #include "ira.h"
379 : : #include "ira-int.h"
380 : : #include "diagnostic-core.h"
381 : : #include "cfgrtl.h"
382 : : #include "cfgbuild.h"
383 : : #include "cfgcleanup.h"
384 : : #include "expr.h"
385 : : #include "tree-pass.h"
386 : : #include "output.h"
387 : : #include "reload.h"
388 : : #include "cfgloop.h"
389 : : #include "lra.h"
390 : : #include "dce.h"
391 : : #include "dbgcnt.h"
392 : : #include "rtl-iter.h"
393 : : #include "shrink-wrap.h"
394 : : #include "print-rtl.h"
395 : :
396 : : struct target_ira default_target_ira;
397 : : class target_ira_int default_target_ira_int;
398 : : #if SWITCHABLE_TARGET
399 : : struct target_ira *this_target_ira = &default_target_ira;
400 : : class target_ira_int *this_target_ira_int = &default_target_ira_int;
401 : : #endif
402 : :
403 : : /* A modified value of flag `-fira-verbose' used internally. */
404 : : int internal_flag_ira_verbose;
405 : :
406 : : /* Dump file of the allocator if it is not NULL. */
407 : : FILE *ira_dump_file;
408 : :
409 : : /* The number of elements in the following array. */
410 : : int ira_spilled_reg_stack_slots_num;
411 : :
412 : : /* The following array contains info about spilled pseudo-registers
413 : : stack slots used in current function so far. */
414 : : class ira_spilled_reg_stack_slot *ira_spilled_reg_stack_slots;
415 : :
416 : : /* Correspondingly overall cost of the allocation, overall cost before
417 : : reload, cost of the allocnos assigned to hard-registers, cost of
418 : : the allocnos assigned to memory, cost of loads, stores and register
419 : : move insns generated for pseudo-register live range splitting (see
420 : : ira-emit.cc). */
421 : : int64_t ira_overall_cost, overall_cost_before;
422 : : int64_t ira_reg_cost, ira_mem_cost;
423 : : int64_t ira_load_cost, ira_store_cost, ira_shuffle_cost;
424 : : int ira_move_loops_num, ira_additional_jumps_num;
425 : :
426 : : /* All registers that can be eliminated. */
427 : :
428 : : HARD_REG_SET eliminable_regset;
429 : :
430 : : /* Value of max_reg_num () before IRA work start. This value helps
431 : : us to recognize a situation when new pseudos were created during
432 : : IRA work. */
433 : : static int max_regno_before_ira;
434 : :
435 : : /* Temporary hard reg set used for a different calculation. */
436 : : static HARD_REG_SET temp_hard_regset;
437 : :
438 : : #define last_mode_for_init_move_cost \
439 : : (this_target_ira_int->x_last_mode_for_init_move_cost)
440 : :
441 : :
442 : : /* The function sets up the map IRA_REG_MODE_HARD_REGSET. */
443 : : static void
444 : 211419 : setup_reg_mode_hard_regset (void)
445 : : {
446 : 211419 : int i, m, hard_regno;
447 : :
448 : 27695889 : for (m = 0; m < NUM_MACHINE_MODES; m++)
449 : 2556055710 : for (hard_regno = 0; hard_regno < FIRST_PSEUDO_REGISTER; hard_regno++)
450 : : {
451 : 2528571240 : CLEAR_HARD_REG_SET (ira_reg_mode_hard_regset[hard_regno][m]);
452 : 8903151440 : for (i = hard_regno_nregs (hard_regno, (machine_mode) m) - 1;
453 : 8903151440 : i >= 0; i--)
454 : 6374580200 : if (hard_regno + i < FIRST_PSEUDO_REGISTER)
455 : 5472837332 : SET_HARD_REG_BIT (ira_reg_mode_hard_regset[hard_regno][m],
456 : : hard_regno + i);
457 : : }
458 : 211419 : }
459 : :
460 : :
461 : : #define no_unit_alloc_regs \
462 : : (this_target_ira_int->x_no_unit_alloc_regs)
463 : :
464 : : /* The function sets up the three arrays declared above. */
465 : : static void
466 : 211419 : setup_class_hard_regs (void)
467 : : {
468 : 211419 : int cl, i, hard_regno, n;
469 : 211419 : HARD_REG_SET processed_hard_reg_set;
470 : :
471 : 211419 : ira_assert (SHRT_MAX >= FIRST_PSEUDO_REGISTER);
472 : 7399665 : for (cl = (int) N_REG_CLASSES - 1; cl >= 0; cl--)
473 : : {
474 : 7188246 : temp_hard_regset = reg_class_contents[cl] & ~no_unit_alloc_regs;
475 : 7188246 : CLEAR_HARD_REG_SET (processed_hard_reg_set);
476 : 668506878 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
477 : : {
478 : 661318632 : ira_non_ordered_class_hard_regs[cl][i] = -1;
479 : 661318632 : ira_class_hard_reg_index[cl][i] = -1;
480 : : }
481 : 668506878 : for (n = 0, i = 0; i < FIRST_PSEUDO_REGISTER; i++)
482 : : {
483 : : #ifdef REG_ALLOC_ORDER
484 : 661318632 : hard_regno = reg_alloc_order[i];
485 : : #else
486 : : hard_regno = i;
487 : : #endif
488 : 661318632 : if (TEST_HARD_REG_BIT (processed_hard_reg_set, hard_regno))
489 : 28752984 : continue;
490 : 632565648 : SET_HARD_REG_BIT (processed_hard_reg_set, hard_regno);
491 : 632565648 : if (! TEST_HARD_REG_BIT (temp_hard_regset, hard_regno))
492 : 559734025 : ira_class_hard_reg_index[cl][hard_regno] = -1;
493 : : else
494 : : {
495 : 72831623 : ira_class_hard_reg_index[cl][hard_regno] = n;
496 : 72831623 : ira_class_hard_regs[cl][n++] = hard_regno;
497 : : }
498 : : }
499 : 7188246 : ira_class_hard_regs_num[cl] = n;
500 : 668506878 : for (n = 0, i = 0; i < FIRST_PSEUDO_REGISTER; i++)
501 : 661318632 : if (TEST_HARD_REG_BIT (temp_hard_regset, i))
502 : 72831623 : ira_non_ordered_class_hard_regs[cl][n++] = i;
503 : 7188246 : ira_assert (ira_class_hard_regs_num[cl] == n);
504 : : }
505 : 211419 : }
506 : :
507 : : /* Set up global variables defining info about hard registers for the
508 : : allocation. These depend on USE_HARD_FRAME_P whose TRUE value means
509 : : that we can use the hard frame pointer for the allocation. */
510 : : static void
511 : 211419 : setup_alloc_regs (bool use_hard_frame_p)
512 : : {
513 : : #ifdef ADJUST_REG_ALLOC_ORDER
514 : 211419 : ADJUST_REG_ALLOC_ORDER;
515 : : #endif
516 : 211419 : no_unit_alloc_regs = fixed_nonglobal_reg_set;
517 : 211419 : if (! use_hard_frame_p)
518 : 67256 : add_to_hard_reg_set (&no_unit_alloc_regs, Pmode,
519 : : HARD_FRAME_POINTER_REGNUM);
520 : 211419 : setup_class_hard_regs ();
521 : 211419 : }
522 : :
523 : :
524 : :
525 : : #define alloc_reg_class_subclasses \
526 : : (this_target_ira_int->x_alloc_reg_class_subclasses)
527 : :
528 : : /* Initialize the table of subclasses of each reg class. */
529 : : static void
530 : 211419 : setup_reg_subclasses (void)
531 : : {
532 : 211419 : int i, j;
533 : 211419 : HARD_REG_SET temp_hard_regset2;
534 : :
535 : 7399665 : for (i = 0; i < N_REG_CLASSES; i++)
536 : 251588610 : for (j = 0; j < N_REG_CLASSES; j++)
537 : 244400364 : alloc_reg_class_subclasses[i][j] = LIM_REG_CLASSES;
538 : :
539 : 7399665 : for (i = 0; i < N_REG_CLASSES; i++)
540 : : {
541 : 7188246 : if (i == (int) NO_REGS)
542 : 211419 : continue;
543 : :
544 : 6976827 : temp_hard_regset = reg_class_contents[i] & ~no_unit_alloc_regs;
545 : 13953654 : if (hard_reg_set_empty_p (temp_hard_regset))
546 : 419862 : continue;
547 : 229493775 : for (j = 0; j < N_REG_CLASSES; j++)
548 : 222936810 : if (i != j)
549 : : {
550 : 216379845 : enum reg_class *p;
551 : :
552 : 216379845 : temp_hard_regset2 = reg_class_contents[j] & ~no_unit_alloc_regs;
553 : 432759690 : if (! hard_reg_set_subset_p (temp_hard_regset,
554 : : temp_hard_regset2))
555 : 164881565 : continue;
556 : 51498280 : p = &alloc_reg_class_subclasses[j][0];
557 : 495343758 : while (*p != LIM_REG_CLASSES) p++;
558 : 51498280 : *p = (enum reg_class) i;
559 : : }
560 : : }
561 : 211419 : }
562 : :
563 : :
564 : :
565 : : /* Set up IRA_MEMORY_MOVE_COST and IRA_MAX_MEMORY_MOVE_COST. */
566 : : static void
567 : 211419 : setup_class_subset_and_memory_move_costs (void)
568 : : {
569 : 211419 : int cl, cl2, mode, cost;
570 : 211419 : HARD_REG_SET temp_hard_regset2;
571 : :
572 : 27695889 : for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
573 : 27484470 : ira_memory_move_cost[mode][NO_REGS][0]
574 : 27484470 : = ira_memory_move_cost[mode][NO_REGS][1] = SHRT_MAX;
575 : 7399665 : for (cl = (int) N_REG_CLASSES - 1; cl >= 0; cl--)
576 : : {
577 : 7188246 : if (cl != (int) NO_REGS)
578 : 913964337 : for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
579 : : {
580 : 1813975020 : ira_max_memory_move_cost[mode][cl][0]
581 : 906987510 : = ira_memory_move_cost[mode][cl][0]
582 : 906987510 : = memory_move_cost ((machine_mode) mode,
583 : : (reg_class_t) cl, false);
584 : 1813975020 : ira_max_memory_move_cost[mode][cl][1]
585 : 906987510 : = ira_memory_move_cost[mode][cl][1]
586 : 906987510 : = memory_move_cost ((machine_mode) mode,
587 : : (reg_class_t) cl, true);
588 : : /* Costs for NO_REGS are used in cost calculation on the
589 : : 1st pass when the preferred register classes are not
590 : : known yet. In this case we take the best scenario. */
591 : 906987510 : if (!targetm.hard_regno_mode_ok (ira_class_hard_regs[cl][0],
592 : : (machine_mode) mode))
593 : 679802497 : continue;
594 : :
595 : 227185013 : if (ira_memory_move_cost[mode][NO_REGS][0]
596 : 227185013 : > ira_memory_move_cost[mode][cl][0])
597 : 12775240 : ira_max_memory_move_cost[mode][NO_REGS][0]
598 : 12775240 : = ira_memory_move_cost[mode][NO_REGS][0]
599 : 12775240 : = ira_memory_move_cost[mode][cl][0];
600 : 227185013 : if (ira_memory_move_cost[mode][NO_REGS][1]
601 : 227185013 : > ira_memory_move_cost[mode][cl][1])
602 : 12764158 : ira_max_memory_move_cost[mode][NO_REGS][1]
603 : 12764158 : = ira_memory_move_cost[mode][NO_REGS][1]
604 : 12764158 : = ira_memory_move_cost[mode][cl][1];
605 : : }
606 : : }
607 : 7399665 : for (cl = (int) N_REG_CLASSES - 1; cl >= 0; cl--)
608 : 251588610 : for (cl2 = (int) N_REG_CLASSES - 1; cl2 >= 0; cl2--)
609 : : {
610 : 244400364 : temp_hard_regset = reg_class_contents[cl] & ~no_unit_alloc_regs;
611 : 244400364 : temp_hard_regset2 = reg_class_contents[cl2] & ~no_unit_alloc_regs;
612 : 244400364 : ira_class_subset_p[cl][cl2]
613 : 244400364 : = hard_reg_set_subset_p (temp_hard_regset, temp_hard_regset2);
614 : 244400364 : if (! hard_reg_set_empty_p (temp_hard_regset2)
615 : 467337174 : && hard_reg_set_subset_p (reg_class_contents[cl2],
616 : : reg_class_contents[cl]))
617 : 6894839160 : for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
618 : : {
619 : 6842206800 : cost = ira_memory_move_cost[mode][cl2][0];
620 : 6842206800 : if (cost > ira_max_memory_move_cost[mode][cl][0])
621 : 111773275 : ira_max_memory_move_cost[mode][cl][0] = cost;
622 : 6842206800 : cost = ira_memory_move_cost[mode][cl2][1];
623 : 6842206800 : if (cost > ira_max_memory_move_cost[mode][cl][1])
624 : 111822205 : ira_max_memory_move_cost[mode][cl][1] = cost;
625 : : }
626 : : }
627 : 7399665 : for (cl = (int) N_REG_CLASSES - 1; cl >= 0; cl--)
628 : 941660226 : for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
629 : : {
630 : 934471980 : ira_memory_move_cost[mode][cl][0]
631 : 934471980 : = ira_max_memory_move_cost[mode][cl][0];
632 : 934471980 : ira_memory_move_cost[mode][cl][1]
633 : 934471980 : = ira_max_memory_move_cost[mode][cl][1];
634 : : }
635 : 211419 : setup_reg_subclasses ();
636 : 211419 : }
637 : :
638 : :
639 : :
640 : : /* Define the following macro if allocation through malloc if
641 : : preferable. */
642 : : #define IRA_NO_OBSTACK
643 : :
644 : : #ifndef IRA_NO_OBSTACK
645 : : /* Obstack used for storing all dynamic data (except bitmaps) of the
646 : : IRA. */
647 : : static struct obstack ira_obstack;
648 : : #endif
649 : :
650 : : /* Obstack used for storing all bitmaps of the IRA. */
651 : : static struct bitmap_obstack ira_bitmap_obstack;
652 : :
653 : : /* Allocate memory of size LEN for IRA data. */
654 : : void *
655 : 199331637 : ira_allocate (size_t len)
656 : : {
657 : 199331637 : void *res;
658 : :
659 : : #ifndef IRA_NO_OBSTACK
660 : : res = obstack_alloc (&ira_obstack, len);
661 : : #else
662 : 199331637 : res = xmalloc (len);
663 : : #endif
664 : 199331637 : return res;
665 : : }
666 : :
667 : : /* Free memory ADDR allocated for IRA data. */
668 : : void
669 : 199331637 : ira_free (void *addr ATTRIBUTE_UNUSED)
670 : : {
671 : : #ifndef IRA_NO_OBSTACK
672 : : /* do nothing */
673 : : #else
674 : 199331637 : free (addr);
675 : : #endif
676 : 199331637 : }
677 : :
678 : :
679 : : /* Allocate and returns bitmap for IRA. */
680 : : bitmap
681 : 10179976 : ira_allocate_bitmap (void)
682 : : {
683 : 10179976 : return BITMAP_ALLOC (&ira_bitmap_obstack);
684 : : }
685 : :
686 : : /* Free bitmap B allocated for IRA. */
687 : : void
688 : 10179976 : ira_free_bitmap (bitmap b ATTRIBUTE_UNUSED)
689 : : {
690 : : /* do nothing */
691 : 10179976 : }
692 : :
693 : :
694 : :
695 : : /* Output information about allocation of all allocnos (except for
696 : : caps) into file F. */
697 : : void
698 : 95 : ira_print_disposition (FILE *f)
699 : : {
700 : 95 : int i, n, max_regno;
701 : 95 : ira_allocno_t a;
702 : 95 : basic_block bb;
703 : :
704 : 95 : fprintf (f, "Disposition:");
705 : 95 : max_regno = max_reg_num ();
706 : 1976 : for (n = 0, i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
707 : 1786 : for (a = ira_regno_allocno_map[i];
708 : 2383 : a != NULL;
709 : 597 : a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
710 : : {
711 : 597 : if (n % 4 == 0)
712 : 180 : fprintf (f, "\n");
713 : 597 : n++;
714 : 597 : fprintf (f, " %4d:r%-4d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
715 : 597 : if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
716 : 0 : fprintf (f, "b%-3d", bb->index);
717 : : else
718 : 597 : fprintf (f, "l%-3d", ALLOCNO_LOOP_TREE_NODE (a)->loop_num);
719 : 597 : if (ALLOCNO_HARD_REGNO (a) >= 0)
720 : 596 : fprintf (f, " %3d", ALLOCNO_HARD_REGNO (a));
721 : : else
722 : 1 : fprintf (f, " mem");
723 : : }
724 : 95 : fprintf (f, "\n");
725 : 95 : }
726 : :
727 : : /* Outputs information about allocation of all allocnos into
728 : : stderr. */
729 : : void
730 : 0 : ira_debug_disposition (void)
731 : : {
732 : 0 : ira_print_disposition (stderr);
733 : 0 : }
734 : :
735 : :
736 : :
737 : : /* Set up ira_stack_reg_pressure_class which is the biggest pressure
738 : : register class containing stack registers or NO_REGS if there are
739 : : no stack registers. To find this class, we iterate through all
740 : : register pressure classes and choose the first register pressure
741 : : class containing all the stack registers and having the biggest
742 : : size. */
743 : : static void
744 : 211419 : setup_stack_reg_pressure_class (void)
745 : : {
746 : 211419 : ira_stack_reg_pressure_class = NO_REGS;
747 : : #ifdef STACK_REGS
748 : 211419 : {
749 : 211419 : int i, best, size;
750 : 211419 : enum reg_class cl;
751 : 211419 : HARD_REG_SET temp_hard_regset2;
752 : :
753 : 211419 : CLEAR_HARD_REG_SET (temp_hard_regset);
754 : 1902771 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
755 : 1691352 : SET_HARD_REG_BIT (temp_hard_regset, i);
756 : : best = 0;
757 : 1058861 : for (i = 0; i < ira_pressure_classes_num; i++)
758 : : {
759 : 847442 : cl = ira_pressure_classes[i];
760 : 847442 : temp_hard_regset2 = temp_hard_regset & reg_class_contents[cl];
761 : 847442 : size = hard_reg_set_size (temp_hard_regset2);
762 : 847442 : if (best < size)
763 : : {
764 : 210770 : best = size;
765 : 210770 : ira_stack_reg_pressure_class = cl;
766 : : }
767 : : }
768 : : }
769 : : #endif
770 : 211419 : }
771 : :
772 : : /* Find pressure classes which are register classes for which we
773 : : calculate register pressure in IRA, register pressure sensitive
774 : : insn scheduling, and register pressure sensitive loop invariant
775 : : motion.
776 : :
777 : : To make register pressure calculation easy, we always use
778 : : non-intersected register pressure classes. A move of hard
779 : : registers from one register pressure class is not more expensive
780 : : than load and store of the hard registers. Most likely an allocno
781 : : class will be a subset of a register pressure class and in many
782 : : cases a register pressure class. That makes usage of register
783 : : pressure classes a good approximation to find a high register
784 : : pressure. */
785 : : static void
786 : 211419 : setup_pressure_classes (void)
787 : : {
788 : 211419 : int cost, i, n, curr;
789 : 211419 : int cl, cl2;
790 : 211419 : enum reg_class pressure_classes[N_REG_CLASSES];
791 : 211419 : int m;
792 : 211419 : HARD_REG_SET temp_hard_regset2;
793 : 211419 : bool insert_p;
794 : :
795 : 211419 : if (targetm.compute_pressure_classes)
796 : 0 : n = targetm.compute_pressure_classes (pressure_classes);
797 : : else
798 : : {
799 : : n = 0;
800 : 7399665 : for (cl = 0; cl < N_REG_CLASSES; cl++)
801 : : {
802 : 7188246 : if (ira_class_hard_regs_num[cl] == 0)
803 : 631281 : continue;
804 : 6556965 : if (ira_class_hard_regs_num[cl] != 1
805 : : /* A register class without subclasses may contain a few
806 : : hard registers and movement between them is costly
807 : : (e.g. SPARC FPCC registers). We still should consider it
808 : : as a candidate for a pressure class. */
809 : 4656197 : && alloc_reg_class_subclasses[cl][0] < cl)
810 : : {
811 : : /* Check that the moves between any hard registers of the
812 : : current class are not more expensive for a legal mode
813 : : than load/store of the hard registers of the current
814 : : class. Such class is a potential candidate to be a
815 : : register pressure class. */
816 : 223827054 : for (m = 0; m < NUM_MACHINE_MODES; m++)
817 : : {
818 : 222559182 : temp_hard_regset
819 : 222559182 : = (reg_class_contents[cl]
820 : 222559182 : & ~(no_unit_alloc_regs
821 : 222559182 : | ira_prohibited_class_mode_regs[cl][m]));
822 : 445118364 : if (hard_reg_set_empty_p (temp_hard_regset))
823 : 166483557 : continue;
824 : 56075625 : ira_init_register_move_cost_if_necessary ((machine_mode) m);
825 : 56075625 : cost = ira_register_move_cost[m][cl][cl];
826 : 56075625 : if (cost <= ira_max_memory_move_cost[m][cl][1]
827 : 52901839 : || cost <= ira_max_memory_move_cost[m][cl][0])
828 : : break;
829 : : }
830 : 4441658 : if (m >= NUM_MACHINE_MODES)
831 : 1267872 : continue;
832 : : }
833 : 5289093 : curr = 0;
834 : 5289093 : insert_p = true;
835 : 5289093 : temp_hard_regset = reg_class_contents[cl] & ~no_unit_alloc_regs;
836 : : /* Remove so far added pressure classes which are subset of the
837 : : current candidate class. Prefer GENERAL_REGS as a pressure
838 : : register class to another class containing the same
839 : : allocatable hard registers. We do this because machine
840 : : dependent cost hooks might give wrong costs for the latter
841 : : class but always give the right cost for the former class
842 : : (GENERAL_REGS). */
843 : 18978949 : for (i = 0; i < n; i++)
844 : : {
845 : 13689856 : cl2 = pressure_classes[i];
846 : 13689856 : temp_hard_regset2 = (reg_class_contents[cl2]
847 : 13689856 : & ~no_unit_alloc_regs);
848 : 13689856 : if (hard_reg_set_subset_p (temp_hard_regset, temp_hard_regset2)
849 : 14818997 : && (temp_hard_regset != temp_hard_regset2
850 : 1062136 : || cl2 == (int) GENERAL_REGS))
851 : : {
852 : 701151 : pressure_classes[curr++] = (enum reg_class) cl2;
853 : 701151 : insert_p = false;
854 : 701151 : continue;
855 : : }
856 : 16306775 : if (hard_reg_set_subset_p (temp_hard_regset2, temp_hard_regset)
857 : 16729205 : && (temp_hard_regset2 != temp_hard_regset
858 : 427990 : || cl == (int) GENERAL_REGS))
859 : 3318070 : continue;
860 : 9670635 : if (temp_hard_regset2 == temp_hard_regset)
861 : 422430 : insert_p = false;
862 : 9670635 : pressure_classes[curr++] = (enum reg_class) cl2;
863 : : }
864 : : /* If the current candidate is a subset of a so far added
865 : : pressure class, don't add it to the list of the pressure
866 : : classes. */
867 : 5289093 : if (insert_p)
868 : 4165512 : pressure_classes[curr++] = (enum reg_class) cl;
869 : : n = curr;
870 : : }
871 : : }
872 : : #ifdef ENABLE_IRA_CHECKING
873 : 211419 : {
874 : 211419 : HARD_REG_SET ignore_hard_regs;
875 : :
876 : : /* Check pressure classes correctness: here we check that hard
877 : : registers from all register pressure classes contains all hard
878 : : registers available for the allocation. */
879 : 845676 : CLEAR_HARD_REG_SET (temp_hard_regset);
880 : 211419 : CLEAR_HARD_REG_SET (temp_hard_regset2);
881 : 211419 : ignore_hard_regs = no_unit_alloc_regs;
882 : 7399665 : for (cl = 0; cl < LIM_REG_CLASSES; cl++)
883 : : {
884 : : /* For some targets (like MIPS with MD_REGS), there are some
885 : : classes with hard registers available for allocation but
886 : : not able to hold value of any mode. */
887 : 208052435 : for (m = 0; m < NUM_MACHINE_MODES; m++)
888 : 207421154 : if (contains_reg_of_mode[cl][m])
889 : : break;
890 : 7188246 : if (m >= NUM_MACHINE_MODES)
891 : : {
892 : 631281 : ignore_hard_regs |= reg_class_contents[cl];
893 : 631281 : continue;
894 : : }
895 : 30740834 : for (i = 0; i < n; i++)
896 : 25031311 : if ((int) pressure_classes[i] == cl)
897 : : break;
898 : 6556965 : temp_hard_regset2 |= reg_class_contents[cl];
899 : 6556965 : if (i < n)
900 : 7188246 : temp_hard_regset |= reg_class_contents[cl];
901 : : }
902 : 19661967 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
903 : : /* Some targets (like SPARC with ICC reg) have allocatable regs
904 : : for which no reg class is defined. */
905 : 19450548 : if (REGNO_REG_CLASS (i) == NO_REGS)
906 : 422838 : SET_HARD_REG_BIT (ignore_hard_regs, i);
907 : 211419 : temp_hard_regset &= ~ignore_hard_regs;
908 : 211419 : temp_hard_regset2 &= ~ignore_hard_regs;
909 : 422838 : ira_assert (hard_reg_set_subset_p (temp_hard_regset2, temp_hard_regset));
910 : : }
911 : : #endif
912 : 211419 : ira_pressure_classes_num = 0;
913 : 1058861 : for (i = 0; i < n; i++)
914 : : {
915 : 847442 : cl = (int) pressure_classes[i];
916 : 847442 : ira_reg_pressure_class_p[cl] = true;
917 : 847442 : ira_pressure_classes[ira_pressure_classes_num++] = (enum reg_class) cl;
918 : : }
919 : 211419 : setup_stack_reg_pressure_class ();
920 : 211419 : }
921 : :
922 : : /* Set up IRA_UNIFORM_CLASS_P. Uniform class is a register class
923 : : whose register move cost between any registers of the class is the
924 : : same as for all its subclasses. We use the data to speed up the
925 : : 2nd pass of calculations of allocno costs. */
926 : : static void
927 : 211419 : setup_uniform_class_p (void)
928 : : {
929 : 211419 : int i, cl, cl2, m;
930 : :
931 : 7399665 : for (cl = 0; cl < N_REG_CLASSES; cl++)
932 : : {
933 : 7188246 : ira_uniform_class_p[cl] = false;
934 : 7188246 : if (ira_class_hard_regs_num[cl] == 0)
935 : 631281 : continue;
936 : : /* We cannot use alloc_reg_class_subclasses here because move
937 : : cost hooks does not take into account that some registers are
938 : : unavailable for the subtarget. E.g. for i686, INT_SSE_REGS
939 : : is element of alloc_reg_class_subclasses for GENERAL_REGS
940 : : because SSE regs are unavailable. */
941 : 25572541 : for (i = 0; (cl2 = reg_class_subclasses[cl][i]) != LIM_REG_CLASSES; i++)
942 : : {
943 : 20283449 : if (ira_class_hard_regs_num[cl2] == 0)
944 : 343 : continue;
945 : 2517604599 : for (m = 0; m < NUM_MACHINE_MODES; m++)
946 : 2498589366 : if (contains_reg_of_mode[cl][m] && contains_reg_of_mode[cl2][m])
947 : : {
948 : 572845402 : ira_init_register_move_cost_if_necessary ((machine_mode) m);
949 : 572845402 : if (ira_register_move_cost[m][cl][cl]
950 : 572845402 : != ira_register_move_cost[m][cl2][cl2])
951 : : break;
952 : : }
953 : 20283106 : if (m < NUM_MACHINE_MODES)
954 : : break;
955 : : }
956 : 6556965 : if (cl2 == LIM_REG_CLASSES)
957 : 5289092 : ira_uniform_class_p[cl] = true;
958 : : }
959 : 211419 : }
960 : :
961 : : /* Set up IRA_ALLOCNO_CLASSES, IRA_ALLOCNO_CLASSES_NUM,
962 : : IRA_IMPORTANT_CLASSES, and IRA_IMPORTANT_CLASSES_NUM.
963 : :
964 : : Target may have many subtargets and not all target hard registers can
965 : : be used for allocation, e.g. x86 port in 32-bit mode cannot use
966 : : hard registers introduced in x86-64 like r8-r15). Some classes
967 : : might have the same allocatable hard registers, e.g. INDEX_REGS
968 : : and GENERAL_REGS in x86 port in 32-bit mode. To decrease different
969 : : calculations efforts we introduce allocno classes which contain
970 : : unique non-empty sets of allocatable hard-registers.
971 : :
972 : : Pseudo class cost calculation in ira-costs.cc is very expensive.
973 : : Therefore we are trying to decrease number of classes involved in
974 : : such calculation. Register classes used in the cost calculation
975 : : are called important classes. They are allocno classes and other
976 : : non-empty classes whose allocatable hard register sets are inside
977 : : of an allocno class hard register set. From the first sight, it
978 : : looks like that they are just allocno classes. It is not true. In
979 : : example of x86-port in 32-bit mode, allocno classes will contain
980 : : GENERAL_REGS but not LEGACY_REGS (because allocatable hard
981 : : registers are the same for the both classes). The important
982 : : classes will contain GENERAL_REGS and LEGACY_REGS. It is done
983 : : because a machine description insn constraint may refers for
984 : : LEGACY_REGS and code in ira-costs.cc is mostly base on investigation
985 : : of the insn constraints. */
986 : : static void
987 : 211419 : setup_allocno_and_important_classes (void)
988 : : {
989 : 211419 : int i, j, n, cl;
990 : 211419 : bool set_p;
991 : 211419 : HARD_REG_SET temp_hard_regset2;
992 : 211419 : static enum reg_class classes[LIM_REG_CLASSES + 1];
993 : :
994 : 211419 : n = 0;
995 : : /* Collect classes which contain unique sets of allocatable hard
996 : : registers. Prefer GENERAL_REGS to other classes containing the
997 : : same set of hard registers. */
998 : 7399665 : for (i = 0; i < LIM_REG_CLASSES; i++)
999 : : {
1000 : 7188246 : temp_hard_regset = reg_class_contents[i] & ~no_unit_alloc_regs;
1001 : 93538715 : for (j = 0; j < n; j++)
1002 : : {
1003 : 88042956 : cl = classes[j];
1004 : 88042956 : temp_hard_regset2 = reg_class_contents[cl] & ~no_unit_alloc_regs;
1005 : 176085912 : if (temp_hard_regset == temp_hard_regset2)
1006 : : break;
1007 : : }
1008 : 7188246 : if (j >= n || targetm.additional_allocno_class_p (i))
1009 : 5495759 : classes[n++] = (enum reg_class) i;
1010 : 1692487 : else if (i == GENERAL_REGS)
1011 : : /* Prefer general regs. For i386 example, it means that
1012 : : we prefer GENERAL_REGS over INDEX_REGS or LEGACY_REGS
1013 : : (all of them consists of the same available hard
1014 : : registers). */
1015 : 5560 : classes[j] = (enum reg_class) i;
1016 : : }
1017 : 211419 : classes[n] = LIM_REG_CLASSES;
1018 : :
1019 : : /* Set up classes which can be used for allocnos as classes
1020 : : containing non-empty unique sets of allocatable hard
1021 : : registers. */
1022 : 211419 : ira_allocno_classes_num = 0;
1023 : 5707178 : for (i = 0; (cl = classes[i]) != LIM_REG_CLASSES; i++)
1024 : 5495759 : if (ira_class_hard_regs_num[cl] > 0)
1025 : 5284340 : ira_allocno_classes[ira_allocno_classes_num++] = (enum reg_class) cl;
1026 : 211419 : ira_important_classes_num = 0;
1027 : : /* Add non-allocno classes containing to non-empty set of
1028 : : allocatable hard regs. */
1029 : 7399665 : for (cl = 0; cl < N_REG_CLASSES; cl++)
1030 : 7188246 : if (ira_class_hard_regs_num[cl] > 0)
1031 : : {
1032 : 6556965 : temp_hard_regset = reg_class_contents[cl] & ~no_unit_alloc_regs;
1033 : 6556965 : set_p = false;
1034 : 101776174 : for (j = 0; j < ira_allocno_classes_num; j++)
1035 : : {
1036 : 100503549 : temp_hard_regset2 = (reg_class_contents[ira_allocno_classes[j]]
1037 : 100503549 : & ~no_unit_alloc_regs);
1038 : 100503549 : if ((enum reg_class) cl == ira_allocno_classes[j])
1039 : : break;
1040 : 95219209 : else if (hard_reg_set_subset_p (temp_hard_regset,
1041 : : temp_hard_regset2))
1042 : 6617665 : set_p = true;
1043 : : }
1044 : 6556965 : if (set_p && j >= ira_allocno_classes_num)
1045 : 1272625 : ira_important_classes[ira_important_classes_num++]
1046 : 1272625 : = (enum reg_class) cl;
1047 : : }
1048 : : /* Now add allocno classes to the important classes. */
1049 : 5495759 : for (j = 0; j < ira_allocno_classes_num; j++)
1050 : 5284340 : ira_important_classes[ira_important_classes_num++]
1051 : 5284340 : = ira_allocno_classes[j];
1052 : 7399665 : for (cl = 0; cl < N_REG_CLASSES; cl++)
1053 : : {
1054 : 7188246 : ira_reg_allocno_class_p[cl] = false;
1055 : 7188246 : ira_reg_pressure_class_p[cl] = false;
1056 : : }
1057 : 5495759 : for (j = 0; j < ira_allocno_classes_num; j++)
1058 : 5284340 : ira_reg_allocno_class_p[ira_allocno_classes[j]] = true;
1059 : 211419 : setup_pressure_classes ();
1060 : 211419 : setup_uniform_class_p ();
1061 : 211419 : }
1062 : :
1063 : : /* Setup translation in CLASS_TRANSLATE of all classes into a class
1064 : : given by array CLASSES of length CLASSES_NUM. The function is used
1065 : : make translation any reg class to an allocno class or to an
1066 : : pressure class. This translation is necessary for some
1067 : : calculations when we can use only allocno or pressure classes and
1068 : : such translation represents an approximate representation of all
1069 : : classes.
1070 : :
1071 : : The translation in case when allocatable hard register set of a
1072 : : given class is subset of allocatable hard register set of a class
1073 : : in CLASSES is pretty simple. We use smallest classes from CLASSES
1074 : : containing a given class. If allocatable hard register set of a
1075 : : given class is not a subset of any corresponding set of a class
1076 : : from CLASSES, we use the cheapest (with load/store point of view)
1077 : : class from CLASSES whose set intersects with given class set. */
1078 : : static void
1079 : 422838 : setup_class_translate_array (enum reg_class *class_translate,
1080 : : int classes_num, enum reg_class *classes)
1081 : : {
1082 : 422838 : int cl, mode;
1083 : 422838 : enum reg_class aclass, best_class, *cl_ptr;
1084 : 422838 : int i, cost, min_cost, best_cost;
1085 : :
1086 : 14799330 : for (cl = 0; cl < N_REG_CLASSES; cl++)
1087 : 14376492 : class_translate[cl] = NO_REGS;
1088 : :
1089 : 6554620 : for (i = 0; i < classes_num; i++)
1090 : : {
1091 : 6131782 : aclass = classes[i];
1092 : 45018672 : for (cl_ptr = &alloc_reg_class_subclasses[aclass][0];
1093 : 45018672 : (cl = *cl_ptr) != LIM_REG_CLASSES;
1094 : : cl_ptr++)
1095 : 38886890 : if (class_translate[cl] == NO_REGS)
1096 : 5990052 : class_translate[cl] = aclass;
1097 : 6131782 : class_translate[aclass] = aclass;
1098 : : }
1099 : : /* For classes which are not fully covered by one of given classes
1100 : : (in other words covered by more one given class), use the
1101 : : cheapest class. */
1102 : 14799330 : for (cl = 0; cl < N_REG_CLASSES; cl++)
1103 : : {
1104 : 14376492 : if (cl == NO_REGS || class_translate[cl] != NO_REGS)
1105 : 12477729 : continue;
1106 : : best_class = NO_REGS;
1107 : : best_cost = INT_MAX;
1108 : 18189862 : for (i = 0; i < classes_num; i++)
1109 : : {
1110 : 16291099 : aclass = classes[i];
1111 : 16291099 : temp_hard_regset = (reg_class_contents[aclass]
1112 : 16291099 : & reg_class_contents[cl]
1113 : 16291099 : & ~no_unit_alloc_regs);
1114 : 32582198 : if (! hard_reg_set_empty_p (temp_hard_regset))
1115 : : {
1116 : : min_cost = INT_MAX;
1117 : 360778323 : for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
1118 : : {
1119 : 358024290 : cost = (ira_memory_move_cost[mode][aclass][0]
1120 : 358024290 : + ira_memory_move_cost[mode][aclass][1]);
1121 : 358024290 : if (min_cost > cost)
1122 : : min_cost = cost;
1123 : : }
1124 : 2754033 : if (best_class == NO_REGS || best_cost > min_cost)
1125 : : {
1126 : 16291099 : best_class = aclass;
1127 : 16291099 : best_cost = min_cost;
1128 : : }
1129 : : }
1130 : : }
1131 : 1898763 : class_translate[cl] = best_class;
1132 : : }
1133 : 422838 : }
1134 : :
1135 : : /* Set up array IRA_ALLOCNO_CLASS_TRANSLATE and
1136 : : IRA_PRESSURE_CLASS_TRANSLATE. */
1137 : : static void
1138 : 211419 : setup_class_translate (void)
1139 : : {
1140 : 211419 : setup_class_translate_array (ira_allocno_class_translate,
1141 : 211419 : ira_allocno_classes_num, ira_allocno_classes);
1142 : 211419 : setup_class_translate_array (ira_pressure_class_translate,
1143 : 211419 : ira_pressure_classes_num, ira_pressure_classes);
1144 : 211419 : }
1145 : :
1146 : : /* Order numbers of allocno classes in original target allocno class
1147 : : array, -1 for non-allocno classes. */
1148 : : static int allocno_class_order[N_REG_CLASSES];
1149 : :
1150 : : /* The function used to sort the important classes. */
1151 : : static int
1152 : 176245994 : comp_reg_classes_func (const void *v1p, const void *v2p)
1153 : : {
1154 : 176245994 : enum reg_class cl1 = *(const enum reg_class *) v1p;
1155 : 176245994 : enum reg_class cl2 = *(const enum reg_class *) v2p;
1156 : 176245994 : enum reg_class tcl1, tcl2;
1157 : 176245994 : int diff;
1158 : :
1159 : 176245994 : tcl1 = ira_allocno_class_translate[cl1];
1160 : 176245994 : tcl2 = ira_allocno_class_translate[cl2];
1161 : 176245994 : if (tcl1 != NO_REGS && tcl2 != NO_REGS
1162 : 176245994 : && (diff = allocno_class_order[tcl1] - allocno_class_order[tcl2]) != 0)
1163 : : return diff;
1164 : 7989162 : return (int) cl1 - (int) cl2;
1165 : : }
1166 : :
1167 : : /* For correct work of function setup_reg_class_relation we need to
1168 : : reorder important classes according to the order of their allocno
1169 : : classes. It places important classes containing the same
1170 : : allocatable hard register set adjacent to each other and allocno
1171 : : class with the allocatable hard register set right after the other
1172 : : important classes with the same set.
1173 : :
1174 : : In example from comments of function
1175 : : setup_allocno_and_important_classes, it places LEGACY_REGS and
1176 : : GENERAL_REGS close to each other and GENERAL_REGS is after
1177 : : LEGACY_REGS. */
1178 : : static void
1179 : 211419 : reorder_important_classes (void)
1180 : : {
1181 : 211419 : int i;
1182 : :
1183 : 7399665 : for (i = 0; i < N_REG_CLASSES; i++)
1184 : 7188246 : allocno_class_order[i] = -1;
1185 : 5495759 : for (i = 0; i < ira_allocno_classes_num; i++)
1186 : 5284340 : allocno_class_order[ira_allocno_classes[i]] = i;
1187 : 211419 : qsort (ira_important_classes, ira_important_classes_num,
1188 : : sizeof (enum reg_class), comp_reg_classes_func);
1189 : 6979803 : for (i = 0; i < ira_important_classes_num; i++)
1190 : 6556965 : ira_important_class_nums[ira_important_classes[i]] = i;
1191 : 211419 : }
1192 : :
1193 : : /* Set up IRA_REG_CLASS_SUBUNION, IRA_REG_CLASS_SUPERUNION,
1194 : : IRA_REG_CLASS_SUPER_CLASSES, IRA_REG_CLASSES_INTERSECT, and
1195 : : IRA_REG_CLASSES_INTERSECT_P. For the meaning of the relations,
1196 : : please see corresponding comments in ira-int.h. */
1197 : : static void
1198 : 211419 : setup_reg_class_relations (void)
1199 : : {
1200 : 211419 : int i, cl1, cl2, cl3;
1201 : 211419 : HARD_REG_SET intersection_set, union_set, temp_set2;
1202 : 211419 : bool important_class_p[N_REG_CLASSES];
1203 : :
1204 : 211419 : memset (important_class_p, 0, sizeof (important_class_p));
1205 : 6768384 : for (i = 0; i < ira_important_classes_num; i++)
1206 : 6556965 : important_class_p[ira_important_classes[i]] = true;
1207 : 7399665 : for (cl1 = 0; cl1 < N_REG_CLASSES; cl1++)
1208 : : {
1209 : 7188246 : ira_reg_class_super_classes[cl1][0] = LIM_REG_CLASSES;
1210 : 251588610 : for (cl2 = 0; cl2 < N_REG_CLASSES; cl2++)
1211 : : {
1212 : 244400364 : ira_reg_classes_intersect_p[cl1][cl2] = false;
1213 : 244400364 : ira_reg_class_intersect[cl1][cl2] = NO_REGS;
1214 : 244400364 : ira_reg_class_subset[cl1][cl2] = NO_REGS;
1215 : 244400364 : temp_hard_regset = reg_class_contents[cl1] & ~no_unit_alloc_regs;
1216 : 244400364 : temp_set2 = reg_class_contents[cl2] & ~no_unit_alloc_regs;
1217 : 244400364 : if (hard_reg_set_empty_p (temp_hard_regset)
1218 : 265863918 : && hard_reg_set_empty_p (temp_set2))
1219 : : {
1220 : : /* The both classes have no allocatable hard registers
1221 : : -- take all class hard registers into account and use
1222 : : reg_class_subunion and reg_class_superunion. */
1223 : 744424 : for (i = 0;; i++)
1224 : : {
1225 : 2705289 : cl3 = reg_class_subclasses[cl1][i];
1226 : 2705289 : if (cl3 == LIM_REG_CLASSES)
1227 : : break;
1228 : 744424 : if (reg_class_subset_p (ira_reg_class_intersect[cl1][cl2],
1229 : : (enum reg_class) cl3))
1230 : 698026 : ira_reg_class_intersect[cl1][cl2] = (enum reg_class) cl3;
1231 : : }
1232 : 1960865 : ira_reg_class_subunion[cl1][cl2] = reg_class_subunion[cl1][cl2];
1233 : 1960865 : ira_reg_class_superunion[cl1][cl2] = reg_class_superunion[cl1][cl2];
1234 : 1960865 : continue;
1235 : : }
1236 : : ira_reg_classes_intersect_p[cl1][cl2]
1237 : 242439499 : = hard_reg_set_intersect_p (temp_hard_regset, temp_set2);
1238 : 222936810 : if (important_class_p[cl1] && important_class_p[cl2]
1239 : 445873620 : && hard_reg_set_subset_p (temp_hard_regset, temp_set2))
1240 : : {
1241 : : /* CL1 and CL2 are important classes and CL1 allocatable
1242 : : hard register set is inside of CL2 allocatable hard
1243 : : registers -- make CL1 a superset of CL2. */
1244 : 58055245 : enum reg_class *p;
1245 : :
1246 : 58055245 : p = &ira_reg_class_super_classes[cl1][0];
1247 : 350399686 : while (*p != LIM_REG_CLASSES)
1248 : 292344441 : p++;
1249 : 58055245 : *p++ = (enum reg_class) cl2;
1250 : 58055245 : *p = LIM_REG_CLASSES;
1251 : : }
1252 : 242439499 : ira_reg_class_subunion[cl1][cl2] = NO_REGS;
1253 : 242439499 : ira_reg_class_superunion[cl1][cl2] = NO_REGS;
1254 : 242439499 : intersection_set = (reg_class_contents[cl1]
1255 : 242439499 : & reg_class_contents[cl2]
1256 : 242439499 : & ~no_unit_alloc_regs);
1257 : 242439499 : union_set = ((reg_class_contents[cl1] | reg_class_contents[cl2])
1258 : 242439499 : & ~no_unit_alloc_regs);
1259 : 8485382465 : for (cl3 = 0; cl3 < N_REG_CLASSES; cl3++)
1260 : : {
1261 : 8242942966 : temp_hard_regset = reg_class_contents[cl3] & ~no_unit_alloc_regs;
1262 : 16485885932 : if (hard_reg_set_empty_p (temp_hard_regset))
1263 : 723015975 : continue;
1264 : :
1265 : 7519926991 : if (hard_reg_set_subset_p (temp_hard_regset, intersection_set))
1266 : : {
1267 : : /* CL3 allocatable hard register set is inside of
1268 : : intersection of allocatable hard register sets
1269 : : of CL1 and CL2. */
1270 : 642744127 : if (important_class_p[cl3])
1271 : : {
1272 : 642744127 : temp_set2
1273 : 642744127 : = (reg_class_contents
1274 : 642744127 : [ira_reg_class_intersect[cl1][cl2]]);
1275 : 642744127 : temp_set2 &= ~no_unit_alloc_regs;
1276 : 642744127 : if (! hard_reg_set_subset_p (temp_hard_regset, temp_set2)
1277 : : /* If the allocatable hard register sets are
1278 : : the same, prefer GENERAL_REGS or the
1279 : : smallest class for debugging
1280 : : purposes. */
1281 : 747187995 : || (temp_hard_regset == temp_set2
1282 : 100289805 : && (cl3 == GENERAL_REGS
1283 : 99617039 : || ((ira_reg_class_intersect[cl1][cl2]
1284 : : != GENERAL_REGS)
1285 : 33333374 : && hard_reg_set_subset_p
1286 : 33333374 : (reg_class_contents[cl3],
1287 : : reg_class_contents
1288 : : [(int)
1289 : : ira_reg_class_intersect[cl1][cl2]])))))
1290 : 564556157 : ira_reg_class_intersect[cl1][cl2] = (enum reg_class) cl3;
1291 : : }
1292 : 642744127 : temp_set2
1293 : 642744127 : = (reg_class_contents[ira_reg_class_subset[cl1][cl2]]
1294 : 642744127 : & ~no_unit_alloc_regs);
1295 : 642744127 : if (! hard_reg_set_subset_p (temp_hard_regset, temp_set2)
1296 : : /* Ignore unavailable hard registers and prefer
1297 : : smallest class for debugging purposes. */
1298 : 747187995 : || (temp_hard_regset == temp_set2
1299 : 100289805 : && hard_reg_set_subset_p
1300 : 100289805 : (reg_class_contents[cl3],
1301 : : reg_class_contents
1302 : : [(int) ira_reg_class_subset[cl1][cl2]])))
1303 : 597226221 : ira_reg_class_subset[cl1][cl2] = (enum reg_class) cl3;
1304 : : }
1305 : 7519926991 : if (important_class_p[cl3]
1306 : 15039853982 : && hard_reg_set_subset_p (temp_hard_regset, union_set))
1307 : : {
1308 : : /* CL3 allocatable hard register set is inside of
1309 : : union of allocatable hard register sets of CL1
1310 : : and CL2. */
1311 : 3347631635 : temp_set2
1312 : 3347631635 : = (reg_class_contents[ira_reg_class_subunion[cl1][cl2]]
1313 : 3347631635 : & ~no_unit_alloc_regs);
1314 : 3347631635 : if (ira_reg_class_subunion[cl1][cl2] == NO_REGS
1315 : 6452823771 : || (hard_reg_set_subset_p (temp_set2, temp_hard_regset)
1316 : :
1317 : 1034005848 : && (temp_set2 != temp_hard_regset
1318 : 430760404 : || cl3 == GENERAL_REGS
1319 : : /* If the allocatable hard register sets are the
1320 : : same, prefer GENERAL_REGS or the smallest
1321 : : class for debugging purposes. */
1322 : 427218720 : || (ira_reg_class_subunion[cl1][cl2] != GENERAL_REGS
1323 : 28441597 : && hard_reg_set_subset_p
1324 : 28441597 : (reg_class_contents[cl3],
1325 : : reg_class_contents
1326 : : [(int) ira_reg_class_subunion[cl1][cl2]])))))
1327 : 871380278 : ira_reg_class_subunion[cl1][cl2] = (enum reg_class) cl3;
1328 : : }
1329 : 15039853982 : if (hard_reg_set_subset_p (union_set, temp_hard_regset))
1330 : : {
1331 : : /* CL3 allocatable hard register set contains union
1332 : : of allocatable hard register sets of CL1 and
1333 : : CL2. */
1334 : 1395196675 : temp_set2
1335 : 1395196675 : = (reg_class_contents[ira_reg_class_superunion[cl1][cl2]]
1336 : 1395196675 : & ~no_unit_alloc_regs);
1337 : 1395196675 : if (ira_reg_class_superunion[cl1][cl2] == NO_REGS
1338 : 2547953851 : || (hard_reg_set_subset_p (temp_hard_regset, temp_set2)
1339 : :
1340 : 198387516 : && (temp_set2 != temp_hard_regset
1341 : 197511142 : || cl3 == GENERAL_REGS
1342 : : /* If the allocatable hard register sets are the
1343 : : same, prefer GENERAL_REGS or the smallest
1344 : : class for debugging purposes. */
1345 : 195972170 : || (ira_reg_class_superunion[cl1][cl2] != GENERAL_REGS
1346 : 19516300 : && hard_reg_set_subset_p
1347 : 19516300 : (reg_class_contents[cl3],
1348 : : reg_class_contents
1349 : : [(int) ira_reg_class_superunion[cl1][cl2]])))))
1350 : 258886914 : ira_reg_class_superunion[cl1][cl2] = (enum reg_class) cl3;
1351 : : }
1352 : : }
1353 : : }
1354 : : }
1355 : 211419 : }
1356 : :
1357 : : /* Output all uniform and important classes into file F. */
1358 : : static void
1359 : 0 : print_uniform_and_important_classes (FILE *f)
1360 : : {
1361 : 0 : int i, cl;
1362 : :
1363 : 0 : fprintf (f, "Uniform classes:\n");
1364 : 0 : for (cl = 0; cl < N_REG_CLASSES; cl++)
1365 : 0 : if (ira_uniform_class_p[cl])
1366 : 0 : fprintf (f, " %s", reg_class_names[cl]);
1367 : 0 : fprintf (f, "\nImportant classes:\n");
1368 : 0 : for (i = 0; i < ira_important_classes_num; i++)
1369 : 0 : fprintf (f, " %s", reg_class_names[ira_important_classes[i]]);
1370 : 0 : fprintf (f, "\n");
1371 : 0 : }
1372 : :
1373 : : /* Output all possible allocno or pressure classes and their
1374 : : translation map into file F. */
1375 : : static void
1376 : 0 : print_translated_classes (FILE *f, bool pressure_p)
1377 : : {
1378 : 0 : int classes_num = (pressure_p
1379 : 0 : ? ira_pressure_classes_num : ira_allocno_classes_num);
1380 : 0 : enum reg_class *classes = (pressure_p
1381 : 0 : ? ira_pressure_classes : ira_allocno_classes);
1382 : 0 : enum reg_class *class_translate = (pressure_p
1383 : : ? ira_pressure_class_translate
1384 : : : ira_allocno_class_translate);
1385 : 0 : int i;
1386 : :
1387 : 0 : fprintf (f, "%s classes:\n", pressure_p ? "Pressure" : "Allocno");
1388 : 0 : for (i = 0; i < classes_num; i++)
1389 : 0 : fprintf (f, " %s", reg_class_names[classes[i]]);
1390 : 0 : fprintf (f, "\nClass translation:\n");
1391 : 0 : for (i = 0; i < N_REG_CLASSES; i++)
1392 : 0 : fprintf (f, " %s -> %s\n", reg_class_names[i],
1393 : 0 : reg_class_names[class_translate[i]]);
1394 : 0 : }
1395 : :
1396 : : /* Output all possible allocno and translation classes and the
1397 : : translation maps into stderr. */
1398 : : void
1399 : 0 : ira_debug_allocno_classes (void)
1400 : : {
1401 : 0 : print_uniform_and_important_classes (stderr);
1402 : 0 : print_translated_classes (stderr, false);
1403 : 0 : print_translated_classes (stderr, true);
1404 : 0 : }
1405 : :
1406 : : /* Set up different arrays concerning class subsets, allocno and
1407 : : important classes. */
1408 : : static void
1409 : 211419 : find_reg_classes (void)
1410 : : {
1411 : 211419 : setup_allocno_and_important_classes ();
1412 : 211419 : setup_class_translate ();
1413 : 211419 : reorder_important_classes ();
1414 : 211419 : setup_reg_class_relations ();
1415 : 211419 : }
1416 : :
1417 : :
1418 : :
1419 : : /* Set up array ira_hard_regno_allocno_class. */
1420 : : static void
1421 : 211419 : setup_hard_regno_aclass (void)
1422 : : {
1423 : 211419 : int i;
1424 : :
1425 : 19661967 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1426 : : {
1427 : 38901096 : ira_hard_regno_allocno_class[i]
1428 : 29324604 : = (TEST_HARD_REG_BIT (no_unit_alloc_regs, i)
1429 : 19450548 : ? NO_REGS
1430 : 9874056 : : ira_allocno_class_translate[REGNO_REG_CLASS (i)]);
1431 : : }
1432 : 211419 : }
1433 : :
1434 : :
1435 : :
1436 : : /* Form IRA_REG_CLASS_MAX_NREGS and IRA_REG_CLASS_MIN_NREGS maps. */
1437 : : static void
1438 : 211419 : setup_reg_class_nregs (void)
1439 : : {
1440 : 211419 : int i, cl, cl2, m;
1441 : :
1442 : 27695889 : for (m = 0; m < MAX_MACHINE_MODE; m++)
1443 : : {
1444 : 961956450 : for (cl = 0; cl < N_REG_CLASSES; cl++)
1445 : 1868943960 : ira_reg_class_max_nregs[cl][m]
1446 : 1868943960 : = ira_reg_class_min_nregs[cl][m]
1447 : 934471980 : = targetm.class_max_nregs ((reg_class_t) cl, (machine_mode) m);
1448 : 961956450 : for (cl = 0; cl < N_REG_CLASSES; cl++)
1449 : 6694776400 : for (i = 0;
1450 : 7629248380 : (cl2 = alloc_reg_class_subclasses[cl][i]) != LIM_REG_CLASSES;
1451 : : i++)
1452 : 6694776400 : if (ira_reg_class_min_nregs[cl2][m]
1453 : 6694776400 : < ira_reg_class_min_nregs[cl][m])
1454 : 56345682 : ira_reg_class_min_nregs[cl][m] = ira_reg_class_min_nregs[cl2][m];
1455 : : }
1456 : 211419 : }
1457 : :
1458 : :
1459 : :
1460 : : /* Set up IRA_PROHIBITED_CLASS_MODE_REGS, IRA_EXCLUDE_CLASS_MODE_REGS, and
1461 : : IRA_CLASS_SINGLETON. This function is called once IRA_CLASS_HARD_REGS has
1462 : : been initialized. */
1463 : : static void
1464 : 211419 : setup_prohibited_and_exclude_class_mode_regs (void)
1465 : : {
1466 : 211419 : int j, k, hard_regno, cl, last_hard_regno, count;
1467 : :
1468 : 7399665 : for (cl = (int) N_REG_CLASSES - 1; cl >= 0; cl--)
1469 : : {
1470 : 7188246 : temp_hard_regset = reg_class_contents[cl] & ~no_unit_alloc_regs;
1471 : 941660226 : for (j = 0; j < NUM_MACHINE_MODES; j++)
1472 : : {
1473 : 934471980 : count = 0;
1474 : 934471980 : last_hard_regno = -1;
1475 : 3737887920 : CLEAR_HARD_REG_SET (ira_prohibited_class_mode_regs[cl][j]);
1476 : 934471980 : CLEAR_HARD_REG_SET (ira_exclude_class_mode_regs[cl][j]);
1477 : 10402582970 : for (k = ira_class_hard_regs_num[cl] - 1; k >= 0; k--)
1478 : : {
1479 : 9468110990 : hard_regno = ira_class_hard_regs[cl][k];
1480 : 9468110990 : if (!targetm.hard_regno_mode_ok (hard_regno, (machine_mode) j))
1481 : 7245467727 : SET_HARD_REG_BIT (ira_prohibited_class_mode_regs[cl][j],
1482 : : hard_regno);
1483 : 2222643263 : else if (in_hard_reg_set_p (temp_hard_regset,
1484 : : (machine_mode) j, hard_regno))
1485 : : {
1486 : 2128609529 : last_hard_regno = hard_regno;
1487 : 2128609529 : count++;
1488 : : }
1489 : : else
1490 : : {
1491 : 94033734 : SET_HARD_REG_BIT (ira_exclude_class_mode_regs[cl][j], hard_regno);
1492 : : }
1493 : : }
1494 : 980713120 : ira_class_singleton[cl][j] = (count == 1 ? last_hard_regno : -1);
1495 : : }
1496 : : }
1497 : 211419 : }
1498 : :
1499 : : /* Clarify IRA_PROHIBITED_CLASS_MODE_REGS by excluding hard registers
1500 : : spanning from one register pressure class to another one. It is
1501 : : called after defining the pressure classes. */
1502 : : static void
1503 : 211419 : clarify_prohibited_class_mode_regs (void)
1504 : : {
1505 : 211419 : int j, k, hard_regno, cl, pclass, nregs;
1506 : :
1507 : 7399665 : for (cl = (int) N_REG_CLASSES - 1; cl >= 0; cl--)
1508 : 941660226 : for (j = 0; j < NUM_MACHINE_MODES; j++)
1509 : : {
1510 : 934471980 : CLEAR_HARD_REG_SET (ira_useful_class_mode_regs[cl][j]);
1511 : 10402582970 : for (k = ira_class_hard_regs_num[cl] - 1; k >= 0; k--)
1512 : : {
1513 : 9468110990 : hard_regno = ira_class_hard_regs[cl][k];
1514 : 9468110990 : if (TEST_HARD_REG_BIT (ira_prohibited_class_mode_regs[cl][j], hard_regno))
1515 : 7245467727 : continue;
1516 : 2222643263 : nregs = hard_regno_nregs (hard_regno, (machine_mode) j);
1517 : 2222643263 : if (hard_regno + nregs > FIRST_PSEUDO_REGISTER)
1518 : : {
1519 : 6690 : SET_HARD_REG_BIT (ira_prohibited_class_mode_regs[cl][j],
1520 : : hard_regno);
1521 : 6690 : continue;
1522 : : }
1523 : 2222636573 : pclass = ira_pressure_class_translate[REGNO_REG_CLASS (hard_regno)];
1524 : 4883338788 : for (nregs-- ;nregs >= 0; nregs--)
1525 : 2710086684 : if (((enum reg_class) pclass
1526 : 2710086684 : != ira_pressure_class_translate[REGNO_REG_CLASS
1527 : 2710086684 : (hard_regno + nregs)]))
1528 : : {
1529 : 49384469 : SET_HARD_REG_BIT (ira_prohibited_class_mode_regs[cl][j],
1530 : : hard_regno);
1531 : 49384469 : break;
1532 : : }
1533 : 2222636573 : if (!TEST_HARD_REG_BIT (ira_prohibited_class_mode_regs[cl][j],
1534 : : hard_regno))
1535 : 2173252104 : add_to_hard_reg_set (&ira_useful_class_mode_regs[cl][j],
1536 : : (machine_mode) j, hard_regno);
1537 : : }
1538 : : }
1539 : 211419 : }
1540 : :
1541 : : /* Allocate and initialize IRA_REGISTER_MOVE_COST, IRA_MAY_MOVE_IN_COST
1542 : : and IRA_MAY_MOVE_OUT_COST for MODE. */
1543 : : void
1544 : 9864992 : ira_init_register_move_cost (machine_mode mode)
1545 : : {
1546 : 9864992 : static unsigned short last_move_cost[N_REG_CLASSES][N_REG_CLASSES];
1547 : 9864992 : bool all_match = true;
1548 : 9864992 : unsigned int i, cl1, cl2;
1549 : 9864992 : HARD_REG_SET ok_regs;
1550 : :
1551 : 9864992 : ira_assert (ira_register_move_cost[mode] == NULL
1552 : : && ira_may_move_in_cost[mode] == NULL
1553 : : && ira_may_move_out_cost[mode] == NULL);
1554 : 917444256 : CLEAR_HARD_REG_SET (ok_regs);
1555 : 917444256 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1556 : 907579264 : if (targetm.hard_regno_mode_ok (i, mode))
1557 : 412638088 : SET_HARD_REG_BIT (ok_regs, i);
1558 : :
1559 : : /* Note that we might be asked about the move costs of modes that
1560 : : cannot be stored in any hard register, for example if an inline
1561 : : asm tries to create a register operand with an impossible mode.
1562 : : We therefore can't assert have_regs_of_mode[mode] here. */
1563 : 345274720 : for (cl1 = 0; cl1 < N_REG_CLASSES; cl1++)
1564 : 11739340480 : for (cl2 = 0; cl2 < N_REG_CLASSES; cl2++)
1565 : : {
1566 : 11403930752 : int cost;
1567 : 11403930752 : if (!hard_reg_set_intersect_p (ok_regs, reg_class_contents[cl1])
1568 : 18850632240 : || !hard_reg_set_intersect_p (ok_regs, reg_class_contents[cl2]))
1569 : : {
1570 : 5958298850 : if ((ira_reg_class_max_nregs[cl1][mode]
1571 : 5958298850 : > ira_class_hard_regs_num[cl1])
1572 : 4228454430 : || (ira_reg_class_max_nregs[cl2][mode]
1573 : 4228454430 : > ira_class_hard_regs_num[cl2]))
1574 : : cost = 65535;
1575 : : else
1576 : 2909646576 : cost = (ira_memory_move_cost[mode][cl1][0]
1577 : 2909646576 : + ira_memory_move_cost[mode][cl2][1]) * 2;
1578 : : }
1579 : : else
1580 : : {
1581 : 5445631902 : cost = register_move_cost (mode, (enum reg_class) cl1,
1582 : : (enum reg_class) cl2);
1583 : 5445631902 : ira_assert (cost < 65535);
1584 : : }
1585 : 11403930752 : all_match &= (last_move_cost[cl1][cl2] == cost);
1586 : 11403930752 : last_move_cost[cl1][cl2] = cost;
1587 : : }
1588 : 9864992 : if (all_match && last_mode_for_init_move_cost != -1)
1589 : : {
1590 : 4095680 : ira_register_move_cost[mode]
1591 : 4095680 : = ira_register_move_cost[last_mode_for_init_move_cost];
1592 : 4095680 : ira_may_move_in_cost[mode]
1593 : 4095680 : = ira_may_move_in_cost[last_mode_for_init_move_cost];
1594 : 4095680 : ira_may_move_out_cost[mode]
1595 : 4095680 : = ira_may_move_out_cost[last_mode_for_init_move_cost];
1596 : 4095680 : return;
1597 : : }
1598 : 5769312 : last_mode_for_init_move_cost = mode;
1599 : 5769312 : ira_register_move_cost[mode] = XNEWVEC (move_table, N_REG_CLASSES);
1600 : 5769312 : ira_may_move_in_cost[mode] = XNEWVEC (move_table, N_REG_CLASSES);
1601 : 5769312 : ira_may_move_out_cost[mode] = XNEWVEC (move_table, N_REG_CLASSES);
1602 : 201925920 : for (cl1 = 0; cl1 < N_REG_CLASSES; cl1++)
1603 : 6865481280 : for (cl2 = 0; cl2 < N_REG_CLASSES; cl2++)
1604 : : {
1605 : 6669324672 : int cost;
1606 : 6669324672 : enum reg_class *p1, *p2;
1607 : :
1608 : 6669324672 : if (last_move_cost[cl1][cl2] == 65535)
1609 : : {
1610 : 1665268692 : ira_register_move_cost[mode][cl1][cl2] = 65535;
1611 : 1665268692 : ira_may_move_in_cost[mode][cl1][cl2] = 65535;
1612 : 1665268692 : ira_may_move_out_cost[mode][cl1][cl2] = 65535;
1613 : : }
1614 : : else
1615 : : {
1616 : 5004055980 : cost = last_move_cost[cl1][cl2];
1617 : :
1618 : 41929702975 : for (p2 = ®_class_subclasses[cl2][0];
1619 : 41929702975 : *p2 != LIM_REG_CLASSES; p2++)
1620 : 36925646995 : if (ira_class_hard_regs_num[*p2] > 0
1621 : 36245347322 : && (ira_reg_class_max_nregs[*p2][mode]
1622 : : <= ira_class_hard_regs_num[*p2]))
1623 : 29724975182 : cost = MAX (cost, ira_register_move_cost[mode][cl1][*p2]);
1624 : :
1625 : 41929702975 : for (p1 = ®_class_subclasses[cl1][0];
1626 : 41929702975 : *p1 != LIM_REG_CLASSES; p1++)
1627 : 36925646995 : if (ira_class_hard_regs_num[*p1] > 0
1628 : 36245347322 : && (ira_reg_class_max_nregs[*p1][mode]
1629 : : <= ira_class_hard_regs_num[*p1]))
1630 : 29724975182 : cost = MAX (cost, ira_register_move_cost[mode][*p1][cl2]);
1631 : :
1632 : 5004055980 : ira_assert (cost <= 65535);
1633 : 5004055980 : ira_register_move_cost[mode][cl1][cl2] = cost;
1634 : :
1635 : 5004055980 : if (ira_class_subset_p[cl1][cl2])
1636 : 1510574780 : ira_may_move_in_cost[mode][cl1][cl2] = 0;
1637 : : else
1638 : 3493481200 : ira_may_move_in_cost[mode][cl1][cl2] = cost;
1639 : :
1640 : 5004055980 : if (ira_class_subset_p[cl2][cl1])
1641 : 1510574780 : ira_may_move_out_cost[mode][cl1][cl2] = 0;
1642 : : else
1643 : 3493481200 : ira_may_move_out_cost[mode][cl1][cl2] = cost;
1644 : : }
1645 : : }
1646 : : }
1647 : :
1648 : :
1649 : :
1650 : : /* This is called once during compiler work. It sets up
1651 : : different arrays whose values don't depend on the compiled
1652 : : function. */
1653 : : void
1654 : 206001 : ira_init_once (void)
1655 : : {
1656 : 206001 : ira_init_costs_once ();
1657 : 206001 : lra_init_once ();
1658 : :
1659 : 206001 : ira_use_lra_p = targetm.lra_p ();
1660 : 206001 : }
1661 : :
1662 : : /* Free ira_max_register_move_cost, ira_may_move_in_cost and
1663 : : ira_may_move_out_cost for each mode. */
1664 : : void
1665 : 551358 : target_ira_int::free_register_move_costs (void)
1666 : : {
1667 : 551358 : int mode, i;
1668 : :
1669 : : /* Reset move_cost and friends, making sure we only free shared
1670 : : table entries once. */
1671 : 72227898 : for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
1672 : 71676540 : if (x_ira_register_move_cost[mode])
1673 : : {
1674 : 591356172 : for (i = 0;
1675 : 600413624 : i < mode && (x_ira_register_move_cost[i]
1676 : : != x_ira_register_move_cost[mode]);
1677 : : i++)
1678 : : ;
1679 : 9057452 : if (i == mode)
1680 : : {
1681 : 5299940 : free (x_ira_register_move_cost[mode]);
1682 : 5299940 : free (x_ira_may_move_in_cost[mode]);
1683 : 5299940 : free (x_ira_may_move_out_cost[mode]);
1684 : : }
1685 : : }
1686 : 551358 : memset (x_ira_register_move_cost, 0, sizeof x_ira_register_move_cost);
1687 : 551358 : memset (x_ira_may_move_in_cost, 0, sizeof x_ira_may_move_in_cost);
1688 : 551358 : memset (x_ira_may_move_out_cost, 0, sizeof x_ira_may_move_out_cost);
1689 : 551358 : last_mode_for_init_move_cost = -1;
1690 : 551358 : }
1691 : :
1692 : 339939 : target_ira_int::~target_ira_int ()
1693 : : {
1694 : 339939 : free_ira_costs ();
1695 : 339939 : free_register_move_costs ();
1696 : 339939 : }
1697 : :
1698 : : /* This is called every time when register related information is
1699 : : changed. */
1700 : : void
1701 : 211419 : ira_init (void)
1702 : : {
1703 : 211419 : this_target_ira_int->free_register_move_costs ();
1704 : 211419 : setup_reg_mode_hard_regset ();
1705 : 211419 : setup_alloc_regs (flag_omit_frame_pointer != 0);
1706 : 211419 : setup_class_subset_and_memory_move_costs ();
1707 : 211419 : setup_reg_class_nregs ();
1708 : 211419 : setup_prohibited_and_exclude_class_mode_regs ();
1709 : 211419 : find_reg_classes ();
1710 : 211419 : clarify_prohibited_class_mode_regs ();
1711 : 211419 : setup_hard_regno_aclass ();
1712 : 211419 : ira_init_costs ();
1713 : 211419 : }
1714 : :
1715 : :
1716 : : #define ira_prohibited_mode_move_regs_initialized_p \
1717 : : (this_target_ira_int->x_ira_prohibited_mode_move_regs_initialized_p)
1718 : :
1719 : : /* Set up IRA_PROHIBITED_MODE_MOVE_REGS. */
1720 : : static void
1721 : 1435841 : setup_prohibited_mode_move_regs (void)
1722 : : {
1723 : 1435841 : int i, j;
1724 : 1435841 : rtx test_reg1, test_reg2, move_pat;
1725 : 1435841 : rtx_insn *move_insn;
1726 : :
1727 : 1435841 : if (ira_prohibited_mode_move_regs_initialized_p)
1728 : : return;
1729 : 209124 : ira_prohibited_mode_move_regs_initialized_p = true;
1730 : 209124 : test_reg1 = gen_rtx_REG (word_mode, LAST_VIRTUAL_REGISTER + 1);
1731 : 209124 : test_reg2 = gen_rtx_REG (word_mode, LAST_VIRTUAL_REGISTER + 2);
1732 : 209124 : move_pat = gen_rtx_SET (test_reg1, test_reg2);
1733 : 209124 : move_insn = gen_rtx_INSN (VOIDmode, 0, 0, 0, move_pat, 0, -1, 0);
1734 : 27604368 : for (i = 0; i < NUM_MACHINE_MODES; i++)
1735 : : {
1736 : 27186120 : SET_HARD_REG_SET (ira_prohibited_mode_move_regs[i]);
1737 : 2528309160 : for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
1738 : : {
1739 : 2501123040 : if (!targetm.hard_regno_mode_ok (j, (machine_mode) i))
1740 : 2088691308 : continue;
1741 : 412431732 : set_mode_and_regno (test_reg1, (machine_mode) i, j);
1742 : 412431732 : set_mode_and_regno (test_reg2, (machine_mode) i, j);
1743 : 412431732 : INSN_CODE (move_insn) = -1;
1744 : 412431732 : recog_memoized (move_insn);
1745 : 412431732 : if (INSN_CODE (move_insn) < 0)
1746 : 195110341 : continue;
1747 : 217321391 : extract_insn (move_insn);
1748 : : /* We don't know whether the move will be in code that is optimized
1749 : : for size or speed, so consider all enabled alternatives. */
1750 : 217321391 : if (! constrain_operands (1, get_enabled_alternatives (move_insn)))
1751 : 1284415 : continue;
1752 : 216036976 : CLEAR_HARD_REG_BIT (ira_prohibited_mode_move_regs[i], j);
1753 : : }
1754 : : }
1755 : : }
1756 : :
1757 : :
1758 : :
1759 : : /* Extract INSN and return the set of alternatives that we should consider.
1760 : : This excludes any alternatives whose constraints are obviously impossible
1761 : : to meet (e.g. because the constraint requires a constant and the operand
1762 : : is nonconstant). It also excludes alternatives that are bound to need
1763 : : a spill or reload, as long as we have other alternatives that match
1764 : : exactly. */
1765 : : alternative_mask
1766 : 99041256 : ira_setup_alts (rtx_insn *insn)
1767 : : {
1768 : 99041256 : int nop, nalt;
1769 : 99041256 : bool curr_swapped;
1770 : 99041256 : const char *p;
1771 : 99041256 : int commutative = -1;
1772 : :
1773 : 99041256 : extract_insn (insn);
1774 : 99041256 : preprocess_constraints (insn);
1775 : 99041256 : alternative_mask preferred = get_preferred_alternatives (insn);
1776 : 99041256 : alternative_mask alts = 0;
1777 : 99041256 : alternative_mask exact_alts = 0;
1778 : : /* Check that the hard reg set is enough for holding all
1779 : : alternatives. It is hard to imagine the situation when the
1780 : : assertion is wrong. */
1781 : 99041256 : ira_assert (recog_data.n_alternatives
1782 : : <= (int) MAX (sizeof (HARD_REG_ELT_TYPE) * CHAR_BIT,
1783 : : FIRST_PSEUDO_REGISTER));
1784 : 290751676 : for (nop = 0; nop < recog_data.n_operands; nop++)
1785 : 203369976 : if (recog_data.constraints[nop][0] == '%')
1786 : : {
1787 : : commutative = nop;
1788 : : break;
1789 : : }
1790 : 99041256 : for (curr_swapped = false;; curr_swapped = true)
1791 : : {
1792 : 1311611391 : for (nalt = 0; nalt < recog_data.n_alternatives; nalt++)
1793 : : {
1794 : 1200910579 : if (!TEST_BIT (preferred, nalt) || TEST_BIT (exact_alts, nalt))
1795 : 399993472 : continue;
1796 : :
1797 : 800917107 : const operand_alternative *op_alt
1798 : 800917107 : = &recog_op_alt[nalt * recog_data.n_operands];
1799 : 800917107 : int this_reject = 0;
1800 : 2286400999 : for (nop = 0; nop < recog_data.n_operands; nop++)
1801 : : {
1802 : 1669013727 : int c, len;
1803 : :
1804 : 1669013727 : this_reject += op_alt[nop].reject;
1805 : :
1806 : 1669013727 : rtx op = recog_data.operand[nop];
1807 : 1669013727 : p = op_alt[nop].constraint;
1808 : 1669013727 : if (*p == 0 || *p == ',')
1809 : 23434290 : continue;
1810 : :
1811 : : bool win_p = false;
1812 : 3339361542 : do
1813 : 3339361542 : switch (c = *p, len = CONSTRAINT_LEN (c, p), c)
1814 : : {
1815 : : case '#':
1816 : : case ',':
1817 : : c = '\0';
1818 : : /* FALLTHRU */
1819 : 700058739 : case '\0':
1820 : 700058739 : len = 0;
1821 : 700058739 : break;
1822 : :
1823 : : case '%':
1824 : : /* The commutative modifier is handled above. */
1825 : : break;
1826 : :
1827 : 71379629 : case '0': case '1': case '2': case '3': case '4':
1828 : 71379629 : case '5': case '6': case '7': case '8': case '9':
1829 : 71379629 : {
1830 : 71379629 : char *end;
1831 : 71379629 : unsigned long dup = strtoul (p, &end, 10);
1832 : 71379629 : rtx other = recog_data.operand[dup];
1833 : 71379629 : len = end - p;
1834 : 1683517 : if (MEM_P (other)
1835 : 71379629 : ? rtx_equal_p (other, op)
1836 : 69696112 : : REG_P (op) || SUBREG_P (op))
1837 : 49560564 : goto op_success;
1838 : 21819065 : win_p = true;
1839 : : }
1840 : 21819065 : break;
1841 : :
1842 : 10301192 : case 'g':
1843 : 10301192 : goto op_success;
1844 : 2539239463 : break;
1845 : :
1846 : 2539239463 : default:
1847 : 2539239463 : {
1848 : 2539239463 : enum constraint_num cn = lookup_constraint (p);
1849 : 2539239463 : rtx mem = NULL;
1850 : 2539239463 : switch (get_constraint_type (cn))
1851 : : {
1852 : 2070849137 : case CT_REGISTER:
1853 : 3260708222 : if (reg_class_for_constraint (cn) != NO_REGS)
1854 : : {
1855 : 1143121473 : if (REG_P (op) || SUBREG_P (op))
1856 : 748498766 : goto op_success;
1857 : : win_p = true;
1858 : : }
1859 : : break;
1860 : :
1861 : 3925355 : case CT_CONST_INT:
1862 : 3925355 : if (CONST_INT_P (op)
1863 : 6440969 : && (insn_const_int_ok_for_constraint
1864 : 2515614 : (INTVAL (op), cn)))
1865 : 1739198 : goto op_success;
1866 : : break;
1867 : :
1868 : 753015 : case CT_ADDRESS:
1869 : 753015 : goto op_success;
1870 : :
1871 : 157418231 : case CT_MEMORY:
1872 : 157418231 : case CT_RELAXED_MEMORY:
1873 : 157418231 : mem = op;
1874 : : /* Fall through. */
1875 : 157418231 : case CT_SPECIAL_MEMORY:
1876 : 157418231 : if (!mem)
1877 : 64093665 : mem = extract_mem_from_operand (op);
1878 : 221511896 : if (MEM_P (mem))
1879 : 66668903 : goto op_success;
1880 : : win_p = true;
1881 : : break;
1882 : :
1883 : 242200060 : case CT_FIXED_FORM:
1884 : 242200060 : if (constraint_satisfied_p (op, cn))
1885 : 67999060 : goto op_success;
1886 : : break;
1887 : : }
1888 : : break;
1889 : : }
1890 : : }
1891 : 2393840844 : while (p += len, c);
1892 : 700058739 : if (!win_p)
1893 : : break;
1894 : : /* We can make the alternative match by spilling a register
1895 : : to memory or loading something into a register. Count a
1896 : : cost of one reload (the equivalent of the '?' constraint). */
1897 : 516528904 : this_reject += 6;
1898 : 1485483892 : op_success:
1899 : 1485483892 : ;
1900 : : }
1901 : :
1902 : 800917107 : if (nop >= recog_data.n_operands)
1903 : : {
1904 : 617387272 : alts |= ALTERNATIVE_BIT (nalt);
1905 : 617387272 : if (this_reject == 0)
1906 : 131066436 : exact_alts |= ALTERNATIVE_BIT (nalt);
1907 : : }
1908 : : }
1909 : 110700812 : if (commutative < 0)
1910 : : break;
1911 : : /* Swap forth and back to avoid changing recog_data. */
1912 : 23319112 : std::swap (recog_data.operand[commutative],
1913 : 23319112 : recog_data.operand[commutative + 1]);
1914 : 23319112 : if (curr_swapped)
1915 : : break;
1916 : : }
1917 : 99041256 : return exact_alts ? exact_alts : alts;
1918 : : }
1919 : :
1920 : : /* Return the number of the output non-early clobber operand which
1921 : : should be the same in any case as operand with number OP_NUM (or
1922 : : negative value if there is no such operand). ALTS is the mask
1923 : : of alternatives that we should consider. SINGLE_INPUT_OP_HAS_CSTR_P
1924 : : should be set in this function, it indicates whether there is only
1925 : : a single input operand which has the matching constraint on the
1926 : : output operand at the position specified in return value. If the
1927 : : pattern allows any one of several input operands holds the matching
1928 : : constraint, it's set as false, one typical case is destructive FMA
1929 : : instruction on target rs6000. Note that for a non-NO_REG preferred
1930 : : register class with no free register move copy, if the parameter
1931 : : PARAM_IRA_CONSIDER_DUP_IN_ALL_ALTS is set to one, this function
1932 : : will check all available alternatives for matching constraints,
1933 : : even if it has found or will find one alternative with non-NO_REG
1934 : : regclass, it can respect more cases with matching constraints. If
1935 : : PARAM_IRA_CONSIDER_DUP_IN_ALL_ALTS is set to zero,
1936 : : SINGLE_INPUT_OP_HAS_CSTR_P is always true, it will stop to find
1937 : : matching constraint relationship once it hits some alternative with
1938 : : some non-NO_REG regclass. */
1939 : : int
1940 : 19586047 : ira_get_dup_out_num (int op_num, alternative_mask alts,
1941 : : bool &single_input_op_has_cstr_p)
1942 : : {
1943 : 19586047 : int curr_alt, c, original;
1944 : 19586047 : bool ignore_p, use_commut_op_p;
1945 : 19586047 : const char *str;
1946 : :
1947 : 19586047 : if (op_num < 0 || recog_data.n_alternatives == 0)
1948 : : return -1;
1949 : : /* We should find duplications only for input operands. */
1950 : 19586047 : if (recog_data.operand_type[op_num] != OP_IN)
1951 : : return -1;
1952 : 14135160 : str = recog_data.constraints[op_num];
1953 : 14135160 : use_commut_op_p = false;
1954 : 14135160 : single_input_op_has_cstr_p = true;
1955 : :
1956 : 14135160 : rtx op = recog_data.operand[op_num];
1957 : 14135160 : int op_regno = reg_or_subregno (op);
1958 : 14135160 : enum reg_class op_pref_cl = reg_preferred_class (op_regno);
1959 : 14135160 : machine_mode op_mode = GET_MODE (op);
1960 : :
1961 : 14135160 : ira_init_register_move_cost_if_necessary (op_mode);
1962 : : /* If the preferred regclass isn't NO_REG, continue to find the matching
1963 : : constraint in all available alternatives with preferred regclass, even
1964 : : if we have found or will find one alternative whose constraint stands
1965 : : for a REG (non-NO_REG) regclass. Note that it would be fine not to
1966 : : respect matching constraint if the register copy is free, so exclude
1967 : : it. */
1968 : 14135160 : bool respect_dup_despite_reg_cstr
1969 : 14135160 : = param_ira_consider_dup_in_all_alts
1970 : 473 : && op_pref_cl != NO_REGS
1971 : 14135629 : && ira_register_move_cost[op_mode][op_pref_cl][op_pref_cl] > 0;
1972 : :
1973 : : /* Record the alternative whose constraint uses the same regclass as the
1974 : : preferred regclass, later if we find one matching constraint for this
1975 : : operand with preferred reclass, we will visit these recorded
1976 : : alternatives to check whether if there is one alternative in which no
1977 : : any INPUT operands have one matching constraint same as our candidate.
1978 : : If yes, it means there is one alternative which is perfectly fine
1979 : : without satisfying this matching constraint. If no, it means in any
1980 : : alternatives there is one other INPUT operand holding this matching
1981 : : constraint, it's fine to respect this matching constraint and further
1982 : : create this constraint copy since it would become harmless once some
1983 : : other takes preference and it's interfered. */
1984 : 16447743 : alternative_mask pref_cl_alts;
1985 : :
1986 : 16447743 : for (;;)
1987 : : {
1988 : 16447743 : pref_cl_alts = 0;
1989 : :
1990 : 16447743 : for (curr_alt = 0, ignore_p = !TEST_BIT (alts, curr_alt),
1991 : 16447743 : original = -1;;)
1992 : : {
1993 : 95800316 : c = *str;
1994 : 95800316 : if (c == '\0')
1995 : : break;
1996 : 91072252 : if (c == '#')
1997 : : ignore_p = true;
1998 : 91072252 : else if (c == ',')
1999 : : {
2000 : 29467044 : curr_alt++;
2001 : 29467044 : ignore_p = !TEST_BIT (alts, curr_alt);
2002 : : }
2003 : 61605208 : else if (! ignore_p)
2004 : 19726181 : switch (c)
2005 : : {
2006 : 934 : case 'g':
2007 : 934 : goto fail;
2008 : 14779207 : default:
2009 : 14779207 : {
2010 : 14779207 : enum constraint_num cn = lookup_constraint (str);
2011 : 14779207 : enum reg_class cl = reg_class_for_constraint (cn);
2012 : 12001379 : if (cl != NO_REGS && !targetm.class_likely_spilled_p (cl))
2013 : : {
2014 : 11717452 : if (respect_dup_despite_reg_cstr)
2015 : : {
2016 : : /* If it's free to move from one preferred class to
2017 : : the one without matching constraint, it doesn't
2018 : : have to respect this constraint with costs. */
2019 : 636 : if (cl != op_pref_cl
2020 : 92 : && (ira_reg_class_intersect[cl][op_pref_cl]
2021 : : != NO_REGS)
2022 : 87 : && (ira_may_move_in_cost[op_mode][op_pref_cl][cl]
2023 : : == 0))
2024 : 71 : goto fail;
2025 : 565 : else if (cl == op_pref_cl)
2026 : 544 : pref_cl_alts |= ALTERNATIVE_BIT (curr_alt);
2027 : : }
2028 : : else
2029 : 11716816 : goto fail;
2030 : : }
2031 : 3062320 : if (constraint_satisfied_p (op, cn))
2032 : 1858 : goto fail;
2033 : : break;
2034 : : }
2035 : :
2036 : 4946040 : case '0': case '1': case '2': case '3': case '4':
2037 : 4946040 : case '5': case '6': case '7': case '8': case '9':
2038 : 4946040 : {
2039 : 4946040 : char *end;
2040 : 4946040 : int n = (int) strtoul (str, &end, 10);
2041 : 4946040 : str = end;
2042 : 4946040 : if (original != -1 && original != n)
2043 : 0 : goto fail;
2044 : 4946040 : gcc_assert (n < recog_data.n_operands);
2045 : 4946040 : if (respect_dup_despite_reg_cstr)
2046 : : {
2047 : 234 : const operand_alternative *op_alt
2048 : 234 : = &recog_op_alt[curr_alt * recog_data.n_operands];
2049 : : /* Only respect the one with preferred rclass, without
2050 : : respect_dup_despite_reg_cstr it's possible to get
2051 : : one whose regclass isn't preferred first before,
2052 : : but it would fail since there should be other
2053 : : alternatives with preferred regclass. */
2054 : 234 : if (op_alt[n].cl == op_pref_cl)
2055 : 4945971 : original = n;
2056 : : }
2057 : : else
2058 : : original = n;
2059 : 4946040 : continue;
2060 : 4946040 : }
2061 : : }
2062 : 74406533 : str += CONSTRAINT_LEN (c, str);
2063 : : }
2064 : 4728064 : if (original == -1)
2065 : 1767651 : goto fail;
2066 : 2960413 : if (recog_data.operand_type[original] == OP_OUT)
2067 : : {
2068 : 2959927 : if (pref_cl_alts == 0)
2069 : : return original;
2070 : : /* Visit these recorded alternatives to check whether
2071 : : there is one alternative in which no any INPUT operands
2072 : : have one matching constraint same as our candidate.
2073 : : Give up this candidate if so. */
2074 : : int nop, nalt;
2075 : 361 : for (nalt = 0; nalt < recog_data.n_alternatives; nalt++)
2076 : : {
2077 : 336 : if (!TEST_BIT (pref_cl_alts, nalt))
2078 : 238 : continue;
2079 : 98 : const operand_alternative *op_alt
2080 : 98 : = &recog_op_alt[nalt * recog_data.n_operands];
2081 : 98 : bool dup_in_other = false;
2082 : 361 : for (nop = 0; nop < recog_data.n_operands; nop++)
2083 : : {
2084 : 307 : if (recog_data.operand_type[nop] != OP_IN)
2085 : 98 : continue;
2086 : 209 : if (nop == op_num)
2087 : 86 : continue;
2088 : 123 : if (op_alt[nop].matches == original)
2089 : : {
2090 : : dup_in_other = true;
2091 : : break;
2092 : : }
2093 : : }
2094 : 98 : if (!dup_in_other)
2095 : : return -1;
2096 : : }
2097 : 25 : single_input_op_has_cstr_p = false;
2098 : 25 : return original;
2099 : : }
2100 : 486 : fail:
2101 : 13487816 : if (use_commut_op_p)
2102 : : break;
2103 : 11940199 : use_commut_op_p = true;
2104 : 11940199 : if (recog_data.constraints[op_num][0] == '%')
2105 : 1000727 : str = recog_data.constraints[op_num + 1];
2106 : 10939472 : else if (op_num > 0 && recog_data.constraints[op_num - 1][0] == '%')
2107 : : str = recog_data.constraints[op_num - 1];
2108 : : else
2109 : : break;
2110 : : }
2111 : : return -1;
2112 : : }
2113 : :
2114 : :
2115 : :
2116 : : /* Search forward to see if the source register of a copy insn dies
2117 : : before either it or the destination register is modified, but don't
2118 : : scan past the end of the basic block. If so, we can replace the
2119 : : source with the destination and let the source die in the copy
2120 : : insn.
2121 : :
2122 : : This will reduce the number of registers live in that range and may
2123 : : enable the destination and the source coalescing, thus often saving
2124 : : one register in addition to a register-register copy. */
2125 : :
2126 : : static void
2127 : 1435841 : decrease_live_ranges_number (void)
2128 : : {
2129 : 1435841 : basic_block bb;
2130 : 1435841 : rtx_insn *insn;
2131 : 1435841 : rtx set, src, dest, dest_death, note;
2132 : 1435841 : rtx_insn *p, *q;
2133 : 1435841 : int sregno, dregno;
2134 : :
2135 : 1435841 : if (! flag_expensive_optimizations)
2136 : : return;
2137 : :
2138 : 933023 : if (ira_dump_file)
2139 : 32 : fprintf (ira_dump_file, "Starting decreasing number of live ranges...\n");
2140 : :
2141 : 10753305 : FOR_EACH_BB_FN (bb, cfun)
2142 : 123118111 : FOR_BB_INSNS (bb, insn)
2143 : : {
2144 : 113297829 : set = single_set (insn);
2145 : 113297829 : if (! set)
2146 : 64378101 : continue;
2147 : 48919728 : src = SET_SRC (set);
2148 : 48919728 : dest = SET_DEST (set);
2149 : 13263888 : if (! REG_P (src) || ! REG_P (dest)
2150 : 57319265 : || find_reg_note (insn, REG_DEAD, src))
2151 : 46295176 : continue;
2152 : 2624552 : sregno = REGNO (src);
2153 : 2624552 : dregno = REGNO (dest);
2154 : :
2155 : : /* We don't want to mess with hard regs if register classes
2156 : : are small. */
2157 : 4829261 : if (sregno == dregno
2158 : 2624516 : || (targetm.small_register_classes_for_mode_p (GET_MODE (src))
2159 : 2624516 : && (sregno < FIRST_PSEUDO_REGISTER
2160 : 2624516 : || dregno < FIRST_PSEUDO_REGISTER))
2161 : : /* We don't see all updates to SP if they are in an
2162 : : auto-inc memory reference, so we must disallow this
2163 : : optimization on them. */
2164 : 419843 : || sregno == STACK_POINTER_REGNUM
2165 : 3044395 : || dregno == STACK_POINTER_REGNUM)
2166 : 2204709 : continue;
2167 : :
2168 : 419843 : dest_death = NULL_RTX;
2169 : :
2170 : 5143119 : for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p))
2171 : : {
2172 : 5139459 : if (! INSN_P (p))
2173 : 876468 : continue;
2174 : 4262991 : if (BLOCK_FOR_INSN (p) != bb)
2175 : : break;
2176 : :
2177 : 7779388 : if (reg_set_p (src, p) || reg_set_p (dest, p)
2178 : : /* If SRC is an asm-declared register, it must not be
2179 : : replaced in any asm. Unfortunately, the REG_EXPR
2180 : : tree for the asm variable may be absent in the SRC
2181 : : rtx, so we can't check the actual register
2182 : : declaration easily (the asm operand will have it,
2183 : : though). To avoid complicating the test for a rare
2184 : : case, we just don't perform register replacement
2185 : : for a hard reg mentioned in an asm. */
2186 : 3852495 : || (sregno < FIRST_PSEUDO_REGISTER
2187 : 0 : && asm_noperands (PATTERN (p)) >= 0
2188 : 0 : && reg_overlap_mentioned_p (src, PATTERN (p)))
2189 : : /* Don't change hard registers used by a call. */
2190 : 3852495 : || (CALL_P (p) && sregno < FIRST_PSEUDO_REGISTER
2191 : 0 : && find_reg_fusage (p, USE, src))
2192 : : /* Don't change a USE of a register. */
2193 : 7754434 : || (GET_CODE (PATTERN (p)) == USE
2194 : 786 : && reg_overlap_mentioned_p (src, XEXP (PATTERN (p), 0))))
2195 : : break;
2196 : :
2197 : : /* See if all of SRC dies in P. This test is slightly
2198 : : more conservative than it needs to be. */
2199 : 3852495 : if ((note = find_regno_note (p, REG_DEAD, sregno))
2200 : 3852495 : && GET_MODE (XEXP (note, 0)) == GET_MODE (src))
2201 : : {
2202 : 5687 : int failed = 0;
2203 : :
2204 : : /* We can do the optimization. Scan forward from INSN
2205 : : again, replacing regs as we go. Set FAILED if a
2206 : : replacement can't be done. In that case, we can't
2207 : : move the death note for SRC. This should be
2208 : : rare. */
2209 : :
2210 : : /* Set to stop at next insn. */
2211 : 5687 : for (q = next_real_insn (insn);
2212 : 34928 : q != next_real_insn (p);
2213 : 29241 : q = next_real_insn (q))
2214 : : {
2215 : 29241 : if (reg_overlap_mentioned_p (src, PATTERN (q)))
2216 : : {
2217 : : /* If SRC is a hard register, we might miss
2218 : : some overlapping registers with
2219 : : validate_replace_rtx, so we would have to
2220 : : undo it. We can't if DEST is present in
2221 : : the insn, so fail in that combination of
2222 : : cases. */
2223 : 6783 : if (sregno < FIRST_PSEUDO_REGISTER
2224 : 6783 : && reg_mentioned_p (dest, PATTERN (q)))
2225 : : failed = 1;
2226 : :
2227 : : /* Attempt to replace all uses. */
2228 : 6783 : else if (!validate_replace_rtx (src, dest, q))
2229 : : failed = 1;
2230 : :
2231 : : /* If this succeeded, but some part of the
2232 : : register is still present, undo the
2233 : : replacement. */
2234 : 6783 : else if (sregno < FIRST_PSEUDO_REGISTER
2235 : 6783 : && reg_overlap_mentioned_p (src, PATTERN (q)))
2236 : : {
2237 : 0 : validate_replace_rtx (dest, src, q);
2238 : 0 : failed = 1;
2239 : : }
2240 : : }
2241 : :
2242 : : /* If DEST dies here, remove the death note and
2243 : : save it for later. Make sure ALL of DEST dies
2244 : : here; again, this is overly conservative. */
2245 : 29241 : if (! dest_death
2246 : 29241 : && (dest_death = find_regno_note (q, REG_DEAD, dregno)))
2247 : : {
2248 : 1 : if (GET_MODE (XEXP (dest_death, 0)) == GET_MODE (dest))
2249 : 1 : remove_note (q, dest_death);
2250 : : else
2251 : : {
2252 : : failed = 1;
2253 : : dest_death = 0;
2254 : : }
2255 : : }
2256 : : }
2257 : :
2258 : 5687 : if (! failed)
2259 : : {
2260 : : /* Move death note of SRC from P to INSN. */
2261 : 5687 : remove_note (p, note);
2262 : 5687 : XEXP (note, 1) = REG_NOTES (insn);
2263 : 5687 : REG_NOTES (insn) = note;
2264 : : }
2265 : :
2266 : : /* DEST is also dead if INSN has a REG_UNUSED note for
2267 : : DEST. */
2268 : 5687 : if (! dest_death
2269 : 5687 : && (dest_death
2270 : 5686 : = find_regno_note (insn, REG_UNUSED, dregno)))
2271 : : {
2272 : 0 : PUT_REG_NOTE_KIND (dest_death, REG_DEAD);
2273 : 0 : remove_note (insn, dest_death);
2274 : : }
2275 : :
2276 : : /* Put death note of DEST on P if we saw it die. */
2277 : 5687 : if (dest_death)
2278 : : {
2279 : 1 : XEXP (dest_death, 1) = REG_NOTES (p);
2280 : 1 : REG_NOTES (p) = dest_death;
2281 : : }
2282 : : break;
2283 : : }
2284 : :
2285 : : /* If SRC is a hard register which is set or killed in
2286 : : some other way, we can't do this optimization. */
2287 : 3846808 : else if (sregno < FIRST_PSEUDO_REGISTER && dead_or_set_p (p, src))
2288 : : break;
2289 : : }
2290 : : }
2291 : : }
2292 : :
2293 : :
2294 : :
2295 : : /* Return nonzero if REGNO is a particularly bad choice for reloading X. */
2296 : : static bool
2297 : 0 : ira_bad_reload_regno_1 (int regno, rtx x)
2298 : : {
2299 : 0 : int x_regno, n, i;
2300 : 0 : ira_allocno_t a;
2301 : 0 : enum reg_class pref;
2302 : :
2303 : : /* We only deal with pseudo regs. */
2304 : 0 : if (! x || GET_CODE (x) != REG)
2305 : : return false;
2306 : :
2307 : 0 : x_regno = REGNO (x);
2308 : 0 : if (x_regno < FIRST_PSEUDO_REGISTER)
2309 : : return false;
2310 : :
2311 : : /* If the pseudo prefers REGNO explicitly, then do not consider
2312 : : REGNO a bad spill choice. */
2313 : 0 : pref = reg_preferred_class (x_regno);
2314 : 0 : if (reg_class_size[pref] == 1)
2315 : 0 : return !TEST_HARD_REG_BIT (reg_class_contents[pref], regno);
2316 : :
2317 : : /* If the pseudo conflicts with REGNO, then we consider REGNO a
2318 : : poor choice for a reload regno. */
2319 : 0 : a = ira_regno_allocno_map[x_regno];
2320 : 0 : n = ALLOCNO_NUM_OBJECTS (a);
2321 : 0 : for (i = 0; i < n; i++)
2322 : : {
2323 : 0 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
2324 : 0 : if (TEST_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno))
2325 : : return true;
2326 : : }
2327 : : return false;
2328 : : }
2329 : :
2330 : : /* Return nonzero if REGNO is a particularly bad choice for reloading
2331 : : IN or OUT. */
2332 : : bool
2333 : 0 : ira_bad_reload_regno (int regno, rtx in, rtx out)
2334 : : {
2335 : 0 : return (ira_bad_reload_regno_1 (regno, in)
2336 : 0 : || ira_bad_reload_regno_1 (regno, out));
2337 : : }
2338 : :
2339 : : /* Add register clobbers from asm statements. */
2340 : : static void
2341 : 1464043 : compute_regs_asm_clobbered (void)
2342 : : {
2343 : 1464043 : basic_block bb;
2344 : :
2345 : 15525544 : FOR_EACH_BB_FN (bb, cfun)
2346 : : {
2347 : 14061501 : rtx_insn *insn;
2348 : 163920013 : FOR_BB_INSNS_REVERSE (bb, insn)
2349 : : {
2350 : 149858512 : df_ref def;
2351 : :
2352 : 149858512 : if (NONDEBUG_INSN_P (insn) && asm_noperands (PATTERN (insn)) >= 0)
2353 : 320760 : FOR_EACH_INSN_DEF (def, insn)
2354 : : {
2355 : 214413 : unsigned int dregno = DF_REF_REGNO (def);
2356 : 214413 : if (HARD_REGISTER_NUM_P (dregno))
2357 : 298376 : add_to_hard_reg_set (&crtl->asm_clobbers,
2358 : 149188 : GET_MODE (DF_REF_REAL_REG (def)),
2359 : : dregno);
2360 : : }
2361 : : }
2362 : : }
2363 : 1464043 : }
2364 : :
2365 : :
2366 : : /* Set up ELIMINABLE_REGSET, IRA_NO_ALLOC_REGS, and
2367 : : REGS_EVER_LIVE. */
2368 : : void
2369 : 1464043 : ira_setup_eliminable_regset (void)
2370 : : {
2371 : 1464043 : int i;
2372 : 1464043 : static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
2373 : 1464043 : int fp_reg_count = hard_regno_nregs (HARD_FRAME_POINTER_REGNUM, Pmode);
2374 : :
2375 : : /* Setup is_leaf as frame_pointer_required may use it. This function
2376 : : is called by sched_init before ira if scheduling is enabled. */
2377 : 1464043 : crtl->is_leaf = leaf_function_p ();
2378 : :
2379 : : /* FIXME: If EXIT_IGNORE_STACK is set, we will not save and restore
2380 : : sp for alloca. So we can't eliminate the frame pointer in that
2381 : : case. At some point, we should improve this by emitting the
2382 : : sp-adjusting insns for this case. */
2383 : 1464043 : frame_pointer_needed
2384 : 2928086 : = (! flag_omit_frame_pointer
2385 : 1022630 : || (cfun->calls_alloca && EXIT_IGNORE_STACK)
2386 : : /* We need the frame pointer to catch stack overflow exceptions if
2387 : : the stack pointer is moving (as for the alloca case just above). */
2388 : 1013802 : || (STACK_CHECK_MOVING_SP
2389 : 1013802 : && flag_stack_check
2390 : 57 : && flag_exceptions
2391 : 20 : && cfun->can_throw_non_call_exceptions)
2392 : 1013798 : || crtl->accesses_prior_frames
2393 : 1010943 : || (SUPPORTS_STACK_ALIGNMENT && crtl->stack_realign_needed)
2394 : 2428366 : || targetm.frame_pointer_required ());
2395 : :
2396 : : /* The chance that FRAME_POINTER_NEEDED is changed from inspecting
2397 : : RTL is very small. So if we use frame pointer for RA and RTL
2398 : : actually prevents this, we will spill pseudos assigned to the
2399 : : frame pointer in LRA. */
2400 : :
2401 : 1464043 : if (frame_pointer_needed)
2402 : 999552 : for (i = 0; i < fp_reg_count; i++)
2403 : 499776 : df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
2404 : :
2405 : 1464043 : ira_no_alloc_regs = no_unit_alloc_regs;
2406 : 1464043 : CLEAR_HARD_REG_SET (eliminable_regset);
2407 : :
2408 : 1464043 : compute_regs_asm_clobbered ();
2409 : :
2410 : : /* Build the regset of all eliminable registers and show we can't
2411 : : use those that we already know won't be eliminated. */
2412 : 7320215 : for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++)
2413 : : {
2414 : 5856172 : bool cannot_elim
2415 : 5856172 : = (! targetm.can_eliminate (eliminables[i].from, eliminables[i].to)
2416 : 5856172 : || (eliminables[i].to == STACK_POINTER_REGNUM && frame_pointer_needed));
2417 : :
2418 : 5856172 : if (!TEST_HARD_REG_BIT (crtl->asm_clobbers, eliminables[i].from))
2419 : : {
2420 : 5856172 : SET_HARD_REG_BIT (eliminable_regset, eliminables[i].from);
2421 : :
2422 : 5856172 : if (cannot_elim)
2423 : 1061710 : SET_HARD_REG_BIT (ira_no_alloc_regs, eliminables[i].from);
2424 : : }
2425 : 0 : else if (cannot_elim)
2426 : 0 : error ("%s cannot be used in %<asm%> here",
2427 : : reg_names[eliminables[i].from]);
2428 : : else
2429 : 0 : df_set_regs_ever_live (eliminables[i].from, true);
2430 : : }
2431 : : if (!HARD_FRAME_POINTER_IS_FRAME_POINTER)
2432 : : {
2433 : 2928086 : for (i = 0; i < fp_reg_count; i++)
2434 : 1464043 : if (global_regs[HARD_FRAME_POINTER_REGNUM + i])
2435 : : /* Nothing to do: the register is already treated as live
2436 : : where appropriate, and cannot be eliminated. */
2437 : : ;
2438 : 1464022 : else if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
2439 : : HARD_FRAME_POINTER_REGNUM + i))
2440 : : {
2441 : 1462739 : SET_HARD_REG_BIT (eliminable_regset,
2442 : : HARD_FRAME_POINTER_REGNUM + i);
2443 : 1462739 : if (frame_pointer_needed)
2444 : 499774 : SET_HARD_REG_BIT (ira_no_alloc_regs,
2445 : : HARD_FRAME_POINTER_REGNUM + i);
2446 : : }
2447 : 1283 : else if (frame_pointer_needed)
2448 : 0 : error ("%s cannot be used in %<asm%> here",
2449 : : reg_names[HARD_FRAME_POINTER_REGNUM + i]);
2450 : : else
2451 : 1283 : df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
2452 : : }
2453 : 1464043 : }
2454 : :
2455 : :
2456 : :
2457 : : /* Vector of substitutions of register numbers,
2458 : : used to map pseudo regs into hardware regs.
2459 : : This is set up as a result of register allocation.
2460 : : Element N is the hard reg assigned to pseudo reg N,
2461 : : or is -1 if no hard reg was assigned.
2462 : : If N is a hard reg number, element N is N. */
2463 : : short *reg_renumber;
2464 : :
2465 : : /* Set up REG_RENUMBER and CALLER_SAVE_NEEDED (used by reload) from
2466 : : the allocation found by IRA. */
2467 : : static void
2468 : 1435841 : setup_reg_renumber (void)
2469 : : {
2470 : 1435841 : int regno, hard_regno;
2471 : 1435841 : ira_allocno_t a;
2472 : 1435841 : ira_allocno_iterator ai;
2473 : :
2474 : 1435841 : caller_save_needed = 0;
2475 : 36656215 : FOR_EACH_ALLOCNO (a, ai)
2476 : : {
2477 : 35220374 : if (ira_use_lra_p && ALLOCNO_CAP_MEMBER (a) != NULL)
2478 : 3556539 : continue;
2479 : : /* There are no caps at this point. */
2480 : 31663835 : ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL);
2481 : 31663835 : if (! ALLOCNO_ASSIGNED_P (a))
2482 : : /* It can happen if A is not referenced but partially anticipated
2483 : : somewhere in a region. */
2484 : 0 : ALLOCNO_ASSIGNED_P (a) = true;
2485 : 31663835 : ira_free_allocno_updated_costs (a);
2486 : 31663835 : hard_regno = ALLOCNO_HARD_REGNO (a);
2487 : 31663835 : regno = ALLOCNO_REGNO (a);
2488 : 31663835 : reg_renumber[regno] = (hard_regno < 0 ? -1 : hard_regno);
2489 : 31663835 : if (hard_regno >= 0)
2490 : : {
2491 : 28588263 : int i, nwords;
2492 : 28588263 : enum reg_class pclass;
2493 : 28588263 : ira_object_t obj;
2494 : :
2495 : 28588263 : pclass = ira_pressure_class_translate[REGNO_REG_CLASS (hard_regno)];
2496 : 28588263 : nwords = ALLOCNO_NUM_OBJECTS (a);
2497 : 58281445 : for (i = 0; i < nwords; i++)
2498 : : {
2499 : 29693182 : obj = ALLOCNO_OBJECT (a, i);
2500 : 29693182 : OBJECT_TOTAL_CONFLICT_HARD_REGS (obj)
2501 : 59386364 : |= ~reg_class_contents[pclass];
2502 : : }
2503 : 28588263 : if (ira_need_caller_save_p (a, hard_regno))
2504 : : {
2505 : 395042 : ira_assert (!optimize || flag_caller_saves
2506 : : || (ALLOCNO_CALLS_CROSSED_NUM (a)
2507 : : == ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a))
2508 : : || regno >= ira_reg_equiv_len
2509 : : || ira_equiv_no_lvalue_p (regno));
2510 : 395042 : caller_save_needed = 1;
2511 : : }
2512 : : }
2513 : : }
2514 : 1435841 : }
2515 : :
2516 : : /* Set up allocno assignment flags for further allocation
2517 : : improvements. */
2518 : : static void
2519 : 0 : setup_allocno_assignment_flags (void)
2520 : : {
2521 : 0 : int hard_regno;
2522 : 0 : ira_allocno_t a;
2523 : 0 : ira_allocno_iterator ai;
2524 : :
2525 : 0 : FOR_EACH_ALLOCNO (a, ai)
2526 : : {
2527 : 0 : if (! ALLOCNO_ASSIGNED_P (a))
2528 : : /* It can happen if A is not referenced but partially anticipated
2529 : : somewhere in a region. */
2530 : 0 : ira_free_allocno_updated_costs (a);
2531 : 0 : hard_regno = ALLOCNO_HARD_REGNO (a);
2532 : : /* Don't assign hard registers to allocnos which are destination
2533 : : of removed store at the end of loop. It has no sense to keep
2534 : : the same value in different hard registers. It is also
2535 : : impossible to assign hard registers correctly to such
2536 : : allocnos because the cost info and info about intersected
2537 : : calls are incorrect for them. */
2538 : 0 : ALLOCNO_ASSIGNED_P (a) = (hard_regno >= 0
2539 : 0 : || ALLOCNO_EMIT_DATA (a)->mem_optimized_dest_p
2540 : 0 : || (ALLOCNO_MEMORY_COST (a)
2541 : 0 : - ALLOCNO_CLASS_COST (a)) < 0);
2542 : 0 : ira_assert
2543 : : (hard_regno < 0
2544 : : || ira_hard_reg_in_set_p (hard_regno, ALLOCNO_MODE (a),
2545 : : reg_class_contents[ALLOCNO_CLASS (a)]));
2546 : : }
2547 : 0 : }
2548 : :
2549 : : /* Evaluate overall allocation cost and the costs for using hard
2550 : : registers and memory for allocnos. */
2551 : : static void
2552 : 1435841 : calculate_allocation_cost (void)
2553 : : {
2554 : 1435841 : int hard_regno, cost;
2555 : 1435841 : ira_allocno_t a;
2556 : 1435841 : ira_allocno_iterator ai;
2557 : :
2558 : 1435841 : ira_overall_cost = ira_reg_cost = ira_mem_cost = 0;
2559 : 36656215 : FOR_EACH_ALLOCNO (a, ai)
2560 : : {
2561 : 35220374 : hard_regno = ALLOCNO_HARD_REGNO (a);
2562 : 35220374 : ira_assert (hard_regno < 0
2563 : : || (ira_hard_reg_in_set_p
2564 : : (hard_regno, ALLOCNO_MODE (a),
2565 : : reg_class_contents[ALLOCNO_CLASS (a)])));
2566 : 35220374 : if (hard_regno < 0)
2567 : : {
2568 : 3465051 : cost = ALLOCNO_MEMORY_COST (a);
2569 : 3465051 : ira_mem_cost += cost;
2570 : : }
2571 : 31755323 : else if (ALLOCNO_HARD_REG_COSTS (a) != NULL)
2572 : : {
2573 : 8380062 : cost = (ALLOCNO_HARD_REG_COSTS (a)
2574 : : [ira_class_hard_reg_index
2575 : 8380062 : [ALLOCNO_CLASS (a)][hard_regno]]);
2576 : 8380062 : ira_reg_cost += cost;
2577 : : }
2578 : : else
2579 : : {
2580 : 23375261 : cost = ALLOCNO_CLASS_COST (a);
2581 : 23375261 : ira_reg_cost += cost;
2582 : : }
2583 : 35220374 : ira_overall_cost += cost;
2584 : : }
2585 : :
2586 : 1435841 : if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
2587 : : {
2588 : 95 : fprintf (ira_dump_file,
2589 : : "+++Costs: overall %" PRId64
2590 : : ", reg %" PRId64
2591 : : ", mem %" PRId64
2592 : : ", ld %" PRId64
2593 : : ", st %" PRId64
2594 : : ", move %" PRId64,
2595 : : ira_overall_cost, ira_reg_cost, ira_mem_cost,
2596 : : ira_load_cost, ira_store_cost, ira_shuffle_cost);
2597 : 95 : fprintf (ira_dump_file, "\n+++ move loops %d, new jumps %d\n",
2598 : : ira_move_loops_num, ira_additional_jumps_num);
2599 : : }
2600 : :
2601 : 1435841 : }
2602 : :
2603 : : #ifdef ENABLE_IRA_CHECKING
2604 : : /* Check the correctness of the allocation. We do need this because
2605 : : of complicated code to transform more one region internal
2606 : : representation into one region representation. */
2607 : : static void
2608 : 0 : check_allocation (void)
2609 : : {
2610 : 0 : ira_allocno_t a;
2611 : 0 : int hard_regno, nregs, conflict_nregs;
2612 : 0 : ira_allocno_iterator ai;
2613 : :
2614 : 0 : FOR_EACH_ALLOCNO (a, ai)
2615 : : {
2616 : 0 : int n = ALLOCNO_NUM_OBJECTS (a);
2617 : 0 : int i;
2618 : :
2619 : 0 : if (ALLOCNO_CAP_MEMBER (a) != NULL
2620 : 0 : || (hard_regno = ALLOCNO_HARD_REGNO (a)) < 0)
2621 : 0 : continue;
2622 : 0 : nregs = hard_regno_nregs (hard_regno, ALLOCNO_MODE (a));
2623 : 0 : if (nregs == 1)
2624 : : /* We allocated a single hard register. */
2625 : : n = 1;
2626 : 0 : else if (n > 1)
2627 : : /* We allocated multiple hard registers, and we will test
2628 : : conflicts in a granularity of single hard regs. */
2629 : 0 : nregs = 1;
2630 : :
2631 : 0 : for (i = 0; i < n; i++)
2632 : : {
2633 : 0 : ira_object_t obj = ALLOCNO_OBJECT (a, i);
2634 : 0 : ira_object_t conflict_obj;
2635 : 0 : ira_object_conflict_iterator oci;
2636 : 0 : int this_regno = hard_regno;
2637 : 0 : if (n > 1)
2638 : : {
2639 : 0 : if (REG_WORDS_BIG_ENDIAN)
2640 : : this_regno += n - i - 1;
2641 : : else
2642 : 0 : this_regno += i;
2643 : : }
2644 : 0 : FOR_EACH_OBJECT_CONFLICT (obj, conflict_obj, oci)
2645 : : {
2646 : 0 : ira_allocno_t conflict_a = OBJECT_ALLOCNO (conflict_obj);
2647 : 0 : int conflict_hard_regno = ALLOCNO_HARD_REGNO (conflict_a);
2648 : 0 : if (conflict_hard_regno < 0)
2649 : 0 : continue;
2650 : 0 : if (ira_soft_conflict (a, conflict_a))
2651 : 0 : continue;
2652 : :
2653 : 0 : conflict_nregs = hard_regno_nregs (conflict_hard_regno,
2654 : 0 : ALLOCNO_MODE (conflict_a));
2655 : :
2656 : 0 : if (ALLOCNO_NUM_OBJECTS (conflict_a) > 1
2657 : 0 : && conflict_nregs == ALLOCNO_NUM_OBJECTS (conflict_a))
2658 : : {
2659 : 0 : if (REG_WORDS_BIG_ENDIAN)
2660 : : conflict_hard_regno += (ALLOCNO_NUM_OBJECTS (conflict_a)
2661 : : - OBJECT_SUBWORD (conflict_obj) - 1);
2662 : : else
2663 : 0 : conflict_hard_regno += OBJECT_SUBWORD (conflict_obj);
2664 : 0 : conflict_nregs = 1;
2665 : : }
2666 : :
2667 : 0 : if ((conflict_hard_regno <= this_regno
2668 : 0 : && this_regno < conflict_hard_regno + conflict_nregs)
2669 : 0 : || (this_regno <= conflict_hard_regno
2670 : 0 : && conflict_hard_regno < this_regno + nregs))
2671 : : {
2672 : 0 : fprintf (stderr, "bad allocation for %d and %d\n",
2673 : : ALLOCNO_REGNO (a), ALLOCNO_REGNO (conflict_a));
2674 : 0 : gcc_unreachable ();
2675 : : }
2676 : : }
2677 : : }
2678 : : }
2679 : 0 : }
2680 : : #endif
2681 : :
2682 : : /* Allocate REG_EQUIV_INIT. Set up it from IRA_REG_EQUIV which should
2683 : : be already calculated. */
2684 : : static void
2685 : 1435841 : setup_reg_equiv_init (void)
2686 : : {
2687 : 1435841 : int i;
2688 : 1435841 : int max_regno = max_reg_num ();
2689 : :
2690 : 198006510 : for (i = 0; i < max_regno; i++)
2691 : 195134828 : reg_equiv_init (i) = ira_reg_equiv[i].init_insns;
2692 : 1435841 : }
2693 : :
2694 : : /* Update equiv regno from movement of FROM_REGNO to TO_REGNO. INSNS
2695 : : are insns which were generated for such movement. It is assumed
2696 : : that FROM_REGNO and TO_REGNO always have the same value at the
2697 : : point of any move containing such registers. This function is used
2698 : : to update equiv info for register shuffles on the region borders
2699 : : and for caller save/restore insns. */
2700 : : void
2701 : 2099761 : ira_update_equiv_info_by_shuffle_insn (int to_regno, int from_regno, rtx_insn *insns)
2702 : : {
2703 : 2099761 : rtx_insn *insn;
2704 : 2099761 : rtx x, note;
2705 : :
2706 : 2099761 : if (! ira_reg_equiv[from_regno].defined_p
2707 : 2099761 : && (! ira_reg_equiv[to_regno].defined_p
2708 : 1099 : || ((x = ira_reg_equiv[to_regno].memory) != NULL_RTX
2709 : 1099 : && ! MEM_READONLY_P (x))))
2710 : : return;
2711 : 34402 : insn = insns;
2712 : 34402 : if (NEXT_INSN (insn) != NULL_RTX)
2713 : : {
2714 : 0 : if (! ira_reg_equiv[to_regno].defined_p)
2715 : : {
2716 : 0 : ira_assert (ira_reg_equiv[to_regno].init_insns == NULL_RTX);
2717 : : return;
2718 : : }
2719 : 0 : ira_reg_equiv[to_regno].defined_p = false;
2720 : 0 : ira_reg_equiv[to_regno].caller_save_p = false;
2721 : 0 : ira_reg_equiv[to_regno].memory
2722 : 0 : = ira_reg_equiv[to_regno].constant
2723 : 0 : = ira_reg_equiv[to_regno].invariant
2724 : 0 : = ira_reg_equiv[to_regno].init_insns = NULL;
2725 : 0 : if (internal_flag_ira_verbose > 3 && ira_dump_file != NULL)
2726 : 0 : fprintf (ira_dump_file,
2727 : : " Invalidating equiv info for reg %d\n", to_regno);
2728 : 0 : return;
2729 : : }
2730 : : /* It is possible that FROM_REGNO still has no equivalence because
2731 : : in shuffles to_regno<-from_regno and from_regno<-to_regno the 2nd
2732 : : insn was not processed yet. */
2733 : 34402 : if (ira_reg_equiv[from_regno].defined_p)
2734 : : {
2735 : 34402 : ira_reg_equiv[to_regno].defined_p = true;
2736 : 34402 : if ((x = ira_reg_equiv[from_regno].memory) != NULL_RTX)
2737 : : {
2738 : 34167 : ira_assert (ira_reg_equiv[from_regno].invariant == NULL_RTX
2739 : : && ira_reg_equiv[from_regno].constant == NULL_RTX);
2740 : 34167 : ira_assert (ira_reg_equiv[to_regno].memory == NULL_RTX
2741 : : || rtx_equal_p (ira_reg_equiv[to_regno].memory, x));
2742 : 34167 : ira_reg_equiv[to_regno].memory = x;
2743 : 34167 : if (! MEM_READONLY_P (x))
2744 : : /* We don't add the insn to insn init list because memory
2745 : : equivalence is just to say what memory is better to use
2746 : : when the pseudo is spilled. */
2747 : : return;
2748 : : }
2749 : 235 : else if ((x = ira_reg_equiv[from_regno].constant) != NULL_RTX)
2750 : : {
2751 : 120 : ira_assert (ira_reg_equiv[from_regno].invariant == NULL_RTX);
2752 : 120 : ira_assert (ira_reg_equiv[to_regno].constant == NULL_RTX
2753 : : || rtx_equal_p (ira_reg_equiv[to_regno].constant, x));
2754 : 120 : ira_reg_equiv[to_regno].constant = x;
2755 : : }
2756 : : else
2757 : : {
2758 : 115 : x = ira_reg_equiv[from_regno].invariant;
2759 : 115 : ira_assert (x != NULL_RTX);
2760 : 115 : ira_assert (ira_reg_equiv[to_regno].invariant == NULL_RTX
2761 : : || rtx_equal_p (ira_reg_equiv[to_regno].invariant, x));
2762 : 115 : ira_reg_equiv[to_regno].invariant = x;
2763 : : }
2764 : 265 : if (find_reg_note (insn, REG_EQUIV, x) == NULL_RTX)
2765 : : {
2766 : 265 : note = set_unique_reg_note (insn, REG_EQUIV, copy_rtx (x));
2767 : 265 : gcc_assert (note != NULL_RTX);
2768 : 265 : if (internal_flag_ira_verbose > 3 && ira_dump_file != NULL)
2769 : : {
2770 : 0 : fprintf (ira_dump_file,
2771 : : " Adding equiv note to insn %u for reg %d ",
2772 : 0 : INSN_UID (insn), to_regno);
2773 : 0 : dump_value_slim (ira_dump_file, x, 1);
2774 : 0 : fprintf (ira_dump_file, "\n");
2775 : : }
2776 : : }
2777 : : }
2778 : 265 : ira_reg_equiv[to_regno].init_insns
2779 : 530 : = gen_rtx_INSN_LIST (VOIDmode, insn,
2780 : 265 : ira_reg_equiv[to_regno].init_insns);
2781 : 265 : if (internal_flag_ira_verbose > 3 && ira_dump_file != NULL)
2782 : 0 : fprintf (ira_dump_file,
2783 : : " Adding equiv init move insn %u to reg %d\n",
2784 : 0 : INSN_UID (insn), to_regno);
2785 : : }
2786 : :
2787 : : /* Fix values of array REG_EQUIV_INIT after live range splitting done
2788 : : by IRA. */
2789 : : static void
2790 : 2017140 : fix_reg_equiv_init (void)
2791 : : {
2792 : 2017140 : int max_regno = max_reg_num ();
2793 : 2017140 : int i, new_regno, max;
2794 : 2017140 : rtx set;
2795 : 2017140 : rtx_insn_list *x, *next, *prev;
2796 : 2017140 : rtx_insn *insn;
2797 : :
2798 : 2017140 : if (max_regno_before_ira < max_regno)
2799 : : {
2800 : 492613 : max = vec_safe_length (reg_equivs);
2801 : 492613 : grow_reg_equivs ();
2802 : 46195492 : for (i = FIRST_PSEUDO_REGISTER; i < max; i++)
2803 : 45702879 : for (prev = NULL, x = reg_equiv_init (i);
2804 : 50011017 : x != NULL_RTX;
2805 : : x = next)
2806 : : {
2807 : 4308138 : next = x->next ();
2808 : 4308138 : insn = x->insn ();
2809 : 4308138 : set = single_set (insn);
2810 : 4308138 : ira_assert (set != NULL_RTX
2811 : : && (REG_P (SET_DEST (set)) || REG_P (SET_SRC (set))));
2812 : 4308138 : if (REG_P (SET_DEST (set))
2813 : 4308138 : && ((int) REGNO (SET_DEST (set)) == i
2814 : 0 : || (int) ORIGINAL_REGNO (SET_DEST (set)) == i))
2815 : : new_regno = REGNO (SET_DEST (set));
2816 : 443150 : else if (REG_P (SET_SRC (set))
2817 : 443150 : && ((int) REGNO (SET_SRC (set)) == i
2818 : 0 : || (int) ORIGINAL_REGNO (SET_SRC (set)) == i))
2819 : : new_regno = REGNO (SET_SRC (set));
2820 : : else
2821 : 0 : gcc_unreachable ();
2822 : 4308138 : if (new_regno == i)
2823 : : prev = x;
2824 : : else
2825 : : {
2826 : : /* Remove the wrong list element. */
2827 : 0 : if (prev == NULL_RTX)
2828 : 0 : reg_equiv_init (i) = next;
2829 : : else
2830 : 0 : XEXP (prev, 1) = next;
2831 : 0 : XEXP (x, 1) = reg_equiv_init (new_regno);
2832 : 0 : reg_equiv_init (new_regno) = x;
2833 : : }
2834 : : }
2835 : : }
2836 : 2017140 : }
2837 : :
2838 : : #ifdef ENABLE_IRA_CHECKING
2839 : : /* Print redundant memory-memory copies. */
2840 : : static void
2841 : 1008570 : print_redundant_copies (void)
2842 : : {
2843 : 1008570 : int hard_regno;
2844 : 1008570 : ira_allocno_t a;
2845 : 1008570 : ira_copy_t cp, next_cp;
2846 : 1008570 : ira_allocno_iterator ai;
2847 : :
2848 : 24967091 : FOR_EACH_ALLOCNO (a, ai)
2849 : : {
2850 : 23958521 : if (ALLOCNO_CAP_MEMBER (a) != NULL)
2851 : : /* It is a cap. */
2852 : 3556539 : continue;
2853 : 20401982 : hard_regno = ALLOCNO_HARD_REGNO (a);
2854 : 20401982 : if (hard_regno >= 0)
2855 : 17416318 : continue;
2856 : 3841949 : for (cp = ALLOCNO_COPIES (a); cp != NULL; cp = next_cp)
2857 : 856285 : if (cp->first == a)
2858 : 328460 : next_cp = cp->next_first_allocno_copy;
2859 : : else
2860 : : {
2861 : 527825 : next_cp = cp->next_second_allocno_copy;
2862 : 527825 : if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL
2863 : 1 : && cp->insn != NULL_RTX
2864 : 0 : && ALLOCNO_HARD_REGNO (cp->first) == hard_regno)
2865 : 0 : fprintf (ira_dump_file,
2866 : : " Redundant move from %d(freq %d):%d\n",
2867 : 0 : INSN_UID (cp->insn), cp->freq, hard_regno);
2868 : : }
2869 : : }
2870 : 1008570 : }
2871 : : #endif
2872 : :
2873 : : /* Setup preferred and alternative classes for new pseudo-registers
2874 : : created by IRA starting with START. */
2875 : : static void
2876 : 1043472 : setup_preferred_alternate_classes_for_new_pseudos (int start)
2877 : : {
2878 : 1043472 : int i, old_regno;
2879 : 1043472 : int max_regno = max_reg_num ();
2880 : :
2881 : 2193566 : for (i = start; i < max_regno; i++)
2882 : : {
2883 : 1150094 : old_regno = ORIGINAL_REGNO (regno_reg_rtx[i]);
2884 : 1150094 : ira_assert (i != old_regno);
2885 : 1150094 : setup_reg_classes (i, reg_preferred_class (old_regno),
2886 : : reg_alternate_class (old_regno),
2887 : : reg_allocno_class (old_regno));
2888 : 1150094 : if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
2889 : 0 : fprintf (ira_dump_file,
2890 : : " New r%d: setting preferred %s, alternative %s\n",
2891 : 0 : i, reg_class_names[reg_preferred_class (old_regno)],
2892 : 0 : reg_class_names[reg_alternate_class (old_regno)]);
2893 : : }
2894 : 1043472 : }
2895 : :
2896 : :
2897 : : /* The number of entries allocated in reg_info. */
2898 : : static int allocated_reg_info_size;
2899 : :
2900 : : /* Regional allocation can create new pseudo-registers. This function
2901 : : expands some arrays for pseudo-registers. */
2902 : : static void
2903 : 1043472 : expand_reg_info (void)
2904 : : {
2905 : 1043472 : int i;
2906 : 1043472 : int size = max_reg_num ();
2907 : :
2908 : 1043472 : resize_reg_info ();
2909 : 2193566 : for (i = allocated_reg_info_size; i < size; i++)
2910 : 1150094 : setup_reg_classes (i, GENERAL_REGS, ALL_REGS, GENERAL_REGS);
2911 : 1043472 : setup_preferred_alternate_classes_for_new_pseudos (allocated_reg_info_size);
2912 : 1043472 : allocated_reg_info_size = size;
2913 : 1043472 : }
2914 : :
2915 : : /* Return TRUE if there is too high register pressure in the function.
2916 : : It is used to decide when stack slot sharing is worth to do. */
2917 : : static bool
2918 : 1435841 : too_high_register_pressure_p (void)
2919 : : {
2920 : 1435841 : int i;
2921 : 1435841 : enum reg_class pclass;
2922 : :
2923 : 7218350 : for (i = 0; i < ira_pressure_classes_num; i++)
2924 : : {
2925 : 5782511 : pclass = ira_pressure_classes[i];
2926 : 5782511 : if (ira_loop_tree_root->reg_pressure[pclass] > 10000)
2927 : : return true;
2928 : : }
2929 : : return false;
2930 : : }
2931 : :
2932 : :
2933 : :
2934 : : /* Indicate that hard register number FROM was eliminated and replaced with
2935 : : an offset from hard register number TO. The status of hard registers live
2936 : : at the start of a basic block is updated by replacing a use of FROM with
2937 : : a use of TO. */
2938 : :
2939 : : void
2940 : 0 : mark_elimination (int from, int to)
2941 : : {
2942 : 0 : basic_block bb;
2943 : 0 : bitmap r;
2944 : :
2945 : 0 : FOR_EACH_BB_FN (bb, cfun)
2946 : : {
2947 : 0 : r = DF_LR_IN (bb);
2948 : 0 : if (bitmap_bit_p (r, from))
2949 : : {
2950 : 0 : bitmap_clear_bit (r, from);
2951 : 0 : bitmap_set_bit (r, to);
2952 : : }
2953 : 0 : if (! df_live)
2954 : 0 : continue;
2955 : 0 : r = DF_LIVE_IN (bb);
2956 : 0 : if (bitmap_bit_p (r, from))
2957 : : {
2958 : 0 : bitmap_clear_bit (r, from);
2959 : 0 : bitmap_set_bit (r, to);
2960 : : }
2961 : : }
2962 : 0 : }
2963 : :
2964 : :
2965 : :
2966 : : /* The length of the following array. */
2967 : : int ira_reg_equiv_len;
2968 : :
2969 : : /* Info about equiv. info for each register. */
2970 : : struct ira_reg_equiv_s *ira_reg_equiv;
2971 : :
2972 : : /* Expand ira_reg_equiv if necessary. */
2973 : : void
2974 : 11208863 : ira_expand_reg_equiv (void)
2975 : : {
2976 : 11208863 : int old = ira_reg_equiv_len;
2977 : :
2978 : 11208863 : if (ira_reg_equiv_len > max_reg_num ())
2979 : : return;
2980 : 1438869 : ira_reg_equiv_len = max_reg_num () * 3 / 2 + 1;
2981 : 1438869 : ira_reg_equiv
2982 : 2877738 : = (struct ira_reg_equiv_s *) xrealloc (ira_reg_equiv,
2983 : 1438869 : ira_reg_equiv_len
2984 : : * sizeof (struct ira_reg_equiv_s));
2985 : 1438869 : gcc_assert (old < ira_reg_equiv_len);
2986 : 1438869 : memset (ira_reg_equiv + old, 0,
2987 : 1438869 : sizeof (struct ira_reg_equiv_s) * (ira_reg_equiv_len - old));
2988 : : }
2989 : :
2990 : : static void
2991 : 1435841 : init_reg_equiv (void)
2992 : : {
2993 : 1435841 : ira_reg_equiv_len = 0;
2994 : 1435841 : ira_reg_equiv = NULL;
2995 : 0 : ira_expand_reg_equiv ();
2996 : 0 : }
2997 : :
2998 : : static void
2999 : 1435841 : finish_reg_equiv (void)
3000 : : {
3001 : 1435841 : free (ira_reg_equiv);
3002 : 0 : }
3003 : :
3004 : :
3005 : :
3006 : : struct equivalence
3007 : : {
3008 : : /* Set when a REG_EQUIV note is found or created. Use to
3009 : : keep track of what memory accesses might be created later,
3010 : : e.g. by reload. */
3011 : : rtx replacement;
3012 : : rtx *src_p;
3013 : :
3014 : : /* The list of each instruction which initializes this register.
3015 : :
3016 : : NULL indicates we know nothing about this register's equivalence
3017 : : properties.
3018 : :
3019 : : An INSN_LIST with a NULL insn indicates this pseudo is already
3020 : : known to not have a valid equivalence. */
3021 : : rtx_insn_list *init_insns;
3022 : :
3023 : : /* Loop depth is used to recognize equivalences which appear
3024 : : to be present within the same loop (or in an inner loop). */
3025 : : short loop_depth;
3026 : : /* Nonzero if this had a preexisting REG_EQUIV note. */
3027 : : unsigned char is_arg_equivalence : 1;
3028 : : /* Set when an attempt should be made to replace a register
3029 : : with the associated src_p entry. */
3030 : : unsigned char replace : 1;
3031 : : /* Set if this register has no known equivalence. */
3032 : : unsigned char no_equiv : 1;
3033 : : /* Set if this register is mentioned in a paradoxical subreg. */
3034 : : unsigned char pdx_subregs : 1;
3035 : : };
3036 : :
3037 : : /* reg_equiv[N] (where N is a pseudo reg number) is the equivalence
3038 : : structure for that register. */
3039 : : static struct equivalence *reg_equiv;
3040 : :
3041 : : /* Used for communication between the following two functions. */
3042 : : struct equiv_mem_data
3043 : : {
3044 : : /* A MEM that we wish to ensure remains unchanged. */
3045 : : rtx equiv_mem;
3046 : :
3047 : : /* Set true if EQUIV_MEM is modified. */
3048 : : bool equiv_mem_modified;
3049 : : };
3050 : :
3051 : : /* If EQUIV_MEM is modified by modifying DEST, indicate that it is modified.
3052 : : Called via note_stores. */
3053 : : static void
3054 : 12638829 : validate_equiv_mem_from_store (rtx dest, const_rtx set ATTRIBUTE_UNUSED,
3055 : : void *data)
3056 : : {
3057 : 12638829 : struct equiv_mem_data *info = (struct equiv_mem_data *) data;
3058 : :
3059 : 12638829 : if ((REG_P (dest)
3060 : 9495908 : && reg_overlap_mentioned_p (dest, info->equiv_mem))
3061 : 22120205 : || (MEM_P (dest)
3062 : 3112905 : && anti_dependence (info->equiv_mem, dest)))
3063 : 202298 : info->equiv_mem_modified = true;
3064 : 12638829 : }
3065 : :
3066 : : static bool equiv_init_varies_p (rtx x);
3067 : :
3068 : : enum valid_equiv { valid_none, valid_combine, valid_reload };
3069 : :
3070 : : /* Verify that no store between START and the death of REG invalidates
3071 : : MEMREF. MEMREF is invalidated by modifying a register used in MEMREF,
3072 : : by storing into an overlapping memory location, or with a non-const
3073 : : CALL_INSN.
3074 : :
3075 : : Return VALID_RELOAD if MEMREF remains valid for both reload and
3076 : : combine_and_move insns, VALID_COMBINE if only valid for
3077 : : combine_and_move_insns, and VALID_NONE otherwise. */
3078 : : static enum valid_equiv
3079 : 3630531 : validate_equiv_mem (rtx_insn *start, rtx reg, rtx memref)
3080 : : {
3081 : 3630531 : rtx_insn *insn;
3082 : 3630531 : rtx note;
3083 : 3630531 : struct equiv_mem_data info = { memref, false };
3084 : 3630531 : enum valid_equiv ret = valid_reload;
3085 : :
3086 : : /* If the memory reference has side effects or is volatile, it isn't a
3087 : : valid equivalence. */
3088 : 3630531 : if (side_effects_p (memref))
3089 : : return valid_none;
3090 : :
3091 : 18957876 : for (insn = start; insn; insn = NEXT_INSN (insn))
3092 : : {
3093 : 18957682 : if (!INSN_P (insn))
3094 : 1354321 : continue;
3095 : :
3096 : 17603361 : if (find_reg_note (insn, REG_DEAD, reg))
3097 : : return ret;
3098 : :
3099 : 15020049 : if (CALL_P (insn))
3100 : : {
3101 : : /* We can combine a reg def from one insn into a reg use in
3102 : : another over a call if the memory is readonly or the call
3103 : : const/pure. However, we can't set reg_equiv notes up for
3104 : : reload over any call. The problem is the equivalent form
3105 : : may reference a pseudo which gets assigned a call
3106 : : clobbered hard reg. When we later replace REG with its
3107 : : equivalent form, the value in the call-clobbered reg has
3108 : : been changed and all hell breaks loose. */
3109 : 91337 : ret = valid_combine;
3110 : 91337 : if (!MEM_READONLY_P (memref)
3111 : 91337 : && (!RTL_CONST_OR_PURE_CALL_P (insn)
3112 : 8449 : || equiv_init_varies_p (XEXP (memref, 0))))
3113 : 85105 : return valid_none;
3114 : : }
3115 : :
3116 : 14934944 : note_stores (insn, validate_equiv_mem_from_store, &info);
3117 : 14934944 : if (info.equiv_mem_modified)
3118 : : return valid_none;
3119 : :
3120 : : /* If a register mentioned in MEMREF is modified via an
3121 : : auto-increment, we lose the equivalence. Do the same if one
3122 : : dies; although we could extend the life, it doesn't seem worth
3123 : : the trouble. */
3124 : :
3125 : 20687713 : for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
3126 : 6529159 : if ((REG_NOTE_KIND (note) == REG_INC
3127 : 6529159 : || REG_NOTE_KIND (note) == REG_DEAD)
3128 : 4955068 : && REG_P (XEXP (note, 0))
3129 : 11484227 : && reg_overlap_mentioned_p (XEXP (note, 0), memref))
3130 : : return valid_none;
3131 : : }
3132 : :
3133 : : return valid_none;
3134 : : }
3135 : :
3136 : : /* Returns false if X is known to be invariant. */
3137 : : static bool
3138 : 892469 : equiv_init_varies_p (rtx x)
3139 : : {
3140 : 892469 : RTX_CODE code = GET_CODE (x);
3141 : 892469 : int i;
3142 : 892469 : const char *fmt;
3143 : :
3144 : 892469 : switch (code)
3145 : : {
3146 : 240703 : case MEM:
3147 : 240703 : return !MEM_READONLY_P (x) || equiv_init_varies_p (XEXP (x, 0));
3148 : :
3149 : : case CONST:
3150 : : CASE_CONST_ANY:
3151 : : case SYMBOL_REF:
3152 : : case LABEL_REF:
3153 : : return false;
3154 : :
3155 : 188063 : case REG:
3156 : 188063 : return reg_equiv[REGNO (x)].replace == 0 && rtx_varies_p (x, 0);
3157 : :
3158 : 0 : case ASM_OPERANDS:
3159 : 0 : if (MEM_VOLATILE_P (x))
3160 : : return true;
3161 : :
3162 : : /* Fall through. */
3163 : :
3164 : 162767 : default:
3165 : 162767 : break;
3166 : : }
3167 : :
3168 : 162767 : fmt = GET_RTX_FORMAT (code);
3169 : 386317 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3170 : 249271 : if (fmt[i] == 'e')
3171 : : {
3172 : 247590 : if (equiv_init_varies_p (XEXP (x, i)))
3173 : : return true;
3174 : : }
3175 : 1681 : else if (fmt[i] == 'E')
3176 : : {
3177 : : int j;
3178 : 3779 : for (j = 0; j < XVECLEN (x, i); j++)
3179 : 3414 : if (equiv_init_varies_p (XVECEXP (x, i, j)))
3180 : : return true;
3181 : : }
3182 : :
3183 : : return false;
3184 : : }
3185 : :
3186 : : /* Returns true if X (used to initialize register REGNO) is movable.
3187 : : X is only movable if the registers it uses have equivalent initializations
3188 : : which appear to be within the same loop (or in an inner loop) and movable
3189 : : or if they are not candidates for local_alloc and don't vary. */
3190 : : static bool
3191 : 10203794 : equiv_init_movable_p (rtx x, int regno)
3192 : : {
3193 : 13088033 : int i, j;
3194 : 13088033 : const char *fmt;
3195 : 13088033 : enum rtx_code code = GET_CODE (x);
3196 : :
3197 : 13088033 : switch (code)
3198 : : {
3199 : 2884239 : case SET:
3200 : 2884239 : return equiv_init_movable_p (SET_SRC (x), regno);
3201 : :
3202 : : case CLOBBER:
3203 : : return false;
3204 : :
3205 : : case PRE_INC:
3206 : : case PRE_DEC:
3207 : : case POST_INC:
3208 : : case POST_DEC:
3209 : : case PRE_MODIFY:
3210 : : case POST_MODIFY:
3211 : : return false;
3212 : :
3213 : 1738486 : case REG:
3214 : 1738486 : return ((reg_equiv[REGNO (x)].loop_depth >= reg_equiv[regno].loop_depth
3215 : 1304024 : && reg_equiv[REGNO (x)].replace)
3216 : 2940466 : || (REG_BASIC_BLOCK (REGNO (x)) < NUM_FIXED_BLOCKS
3217 : 1519618 : && ! rtx_varies_p (x, 0)));
3218 : :
3219 : : case UNSPEC_VOLATILE:
3220 : : return false;
3221 : :
3222 : 0 : case ASM_OPERANDS:
3223 : 0 : if (MEM_VOLATILE_P (x))
3224 : : return false;
3225 : :
3226 : : /* Fall through. */
3227 : :
3228 : 7846847 : default:
3229 : 7846847 : break;
3230 : : }
3231 : :
3232 : 7846847 : fmt = GET_RTX_FORMAT (code);
3233 : 18580993 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3234 : 12594270 : switch (fmt[i])
3235 : : {
3236 : 5734588 : case 'e':
3237 : 5734588 : if (! equiv_init_movable_p (XEXP (x, i), regno))
3238 : : return false;
3239 : : break;
3240 : 758070 : case 'E':
3241 : 1106115 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3242 : 966506 : if (! equiv_init_movable_p (XVECEXP (x, i, j), regno))
3243 : : return false;
3244 : : break;
3245 : : }
3246 : :
3247 : : return true;
3248 : : }
3249 : :
3250 : : static bool memref_referenced_p (rtx memref, rtx x, bool read_p);
3251 : :
3252 : : /* Auxiliary function for memref_referenced_p. Process setting X for
3253 : : MEMREF store. */
3254 : : static bool
3255 : 638217 : process_set_for_memref_referenced_p (rtx memref, rtx x)
3256 : : {
3257 : : /* If we are setting a MEM, it doesn't count (its address does), but any
3258 : : other SET_DEST that has a MEM in it is referencing the MEM. */
3259 : 638217 : if (MEM_P (x))
3260 : : {
3261 : 526875 : if (memref_referenced_p (memref, XEXP (x, 0), true))
3262 : : return true;
3263 : : }
3264 : 111342 : else if (memref_referenced_p (memref, x, false))
3265 : : return true;
3266 : :
3267 : : return false;
3268 : : }
3269 : :
3270 : : /* TRUE if X references a memory location (as a read if READ_P) that
3271 : : would be affected by a store to MEMREF. */
3272 : : static bool
3273 : 3044508 : memref_referenced_p (rtx memref, rtx x, bool read_p)
3274 : : {
3275 : 3044508 : int i, j;
3276 : 3044508 : const char *fmt;
3277 : 3044508 : enum rtx_code code = GET_CODE (x);
3278 : :
3279 : 3044508 : switch (code)
3280 : : {
3281 : : case CONST:
3282 : : case LABEL_REF:
3283 : : case SYMBOL_REF:
3284 : : CASE_CONST_ANY:
3285 : : case PC:
3286 : : case HIGH:
3287 : : case LO_SUM:
3288 : : return false;
3289 : :
3290 : 1229489 : case REG:
3291 : 1229489 : return (reg_equiv[REGNO (x)].replacement
3292 : 1285182 : && memref_referenced_p (memref,
3293 : 55693 : reg_equiv[REGNO (x)].replacement, read_p));
3294 : :
3295 : 78945 : case MEM:
3296 : : /* Memory X might have another effective type than MEMREF. */
3297 : 78945 : if (read_p || true_dependence (memref, VOIDmode, x))
3298 : 71593 : return true;
3299 : : break;
3300 : :
3301 : 623484 : case SET:
3302 : 623484 : if (process_set_for_memref_referenced_p (memref, SET_DEST (x)))
3303 : : return true;
3304 : :
3305 : 607763 : return memref_referenced_p (memref, SET_SRC (x), true);
3306 : :
3307 : 14733 : case CLOBBER:
3308 : 14733 : if (process_set_for_memref_referenced_p (memref, XEXP (x, 0)))
3309 : : return true;
3310 : :
3311 : : return false;
3312 : :
3313 : 0 : case PRE_DEC:
3314 : 0 : case POST_DEC:
3315 : 0 : case PRE_INC:
3316 : 0 : case POST_INC:
3317 : 0 : if (process_set_for_memref_referenced_p (memref, XEXP (x, 0)))
3318 : : return true;
3319 : :
3320 : 0 : return memref_referenced_p (memref, XEXP (x, 0), true);
3321 : :
3322 : 0 : case POST_MODIFY:
3323 : 0 : case PRE_MODIFY:
3324 : : /* op0 = op0 + op1 */
3325 : 0 : if (process_set_for_memref_referenced_p (memref, XEXP (x, 0)))
3326 : : return true;
3327 : :
3328 : 0 : if (memref_referenced_p (memref, XEXP (x, 0), true))
3329 : : return true;
3330 : :
3331 : 0 : return memref_referenced_p (memref, XEXP (x, 1), true);
3332 : :
3333 : : default:
3334 : : break;
3335 : : }
3336 : :
3337 : 575176 : fmt = GET_RTX_FORMAT (code);
3338 : 1659646 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3339 : 1114604 : switch (fmt[i])
3340 : : {
3341 : 1083117 : case 'e':
3342 : 1083117 : if (memref_referenced_p (memref, XEXP (x, i), read_p))
3343 : : return true;
3344 : : break;
3345 : 18256 : case 'E':
3346 : 51897 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3347 : 36444 : if (memref_referenced_p (memref, XVECEXP (x, i, j), read_p))
3348 : : return true;
3349 : : break;
3350 : : }
3351 : :
3352 : : return false;
3353 : : }
3354 : :
3355 : : /* TRUE if some insn in the range (START, END] references a memory location
3356 : : that would be affected by a store to MEMREF.
3357 : :
3358 : : Callers should not call this routine if START is after END in the
3359 : : RTL chain. */
3360 : :
3361 : : static bool
3362 : 512358 : memref_used_between_p (rtx memref, rtx_insn *start, rtx_insn *end)
3363 : : {
3364 : 512358 : rtx_insn *insn;
3365 : :
3366 : 1614292 : for (insn = NEXT_INSN (start);
3367 : 3213088 : insn && insn != NEXT_INSN (end);
3368 : 1101934 : insn = NEXT_INSN (insn))
3369 : : {
3370 : 1173527 : if (!NONDEBUG_INSN_P (insn))
3371 : 550253 : continue;
3372 : :
3373 : 623274 : if (memref_referenced_p (memref, PATTERN (insn), false))
3374 : : return true;
3375 : :
3376 : : /* Nonconst functions may access memory. */
3377 : 551681 : if (CALL_P (insn) && (! RTL_CONST_CALL_P (insn)))
3378 : : return true;
3379 : : }
3380 : :
3381 : 440765 : gcc_assert (insn == NEXT_INSN (end));
3382 : : return false;
3383 : : }
3384 : :
3385 : : /* Mark REG as having no known equivalence.
3386 : : Some instructions might have been processed before and furnished
3387 : : with REG_EQUIV notes for this register; these notes will have to be
3388 : : removed.
3389 : : STORE is the piece of RTL that does the non-constant / conflicting
3390 : : assignment - a SET, CLOBBER or REG_INC note. It is currently not used,
3391 : : but needs to be there because this function is called from note_stores. */
3392 : : static void
3393 : 48740702 : no_equiv (rtx reg, const_rtx store ATTRIBUTE_UNUSED,
3394 : : void *data ATTRIBUTE_UNUSED)
3395 : : {
3396 : 48740702 : int regno;
3397 : 48740702 : rtx_insn_list *list;
3398 : :
3399 : 48740702 : if (!REG_P (reg))
3400 : : return;
3401 : 34019192 : regno = REGNO (reg);
3402 : 34019192 : reg_equiv[regno].no_equiv = 1;
3403 : 34019192 : list = reg_equiv[regno].init_insns;
3404 : 61820024 : if (list && list->insn () == NULL)
3405 : : return;
3406 : 7009056 : reg_equiv[regno].init_insns = gen_rtx_INSN_LIST (VOIDmode, NULL_RTX, NULL);
3407 : 7009056 : reg_equiv[regno].replacement = NULL_RTX;
3408 : : /* This doesn't matter for equivalences made for argument registers, we
3409 : : should keep their initialization insns. */
3410 : 7009056 : if (reg_equiv[regno].is_arg_equivalence)
3411 : : return;
3412 : 7004615 : ira_reg_equiv[regno].defined_p = false;
3413 : 7004615 : ira_reg_equiv[regno].caller_save_p = false;
3414 : 7004615 : ira_reg_equiv[regno].init_insns = NULL;
3415 : 7852807 : for (; list; list = list->next ())
3416 : : {
3417 : 848192 : rtx_insn *insn = list->insn ();
3418 : 848192 : remove_note (insn, find_reg_note (insn, REG_EQUIV, NULL_RTX));
3419 : : }
3420 : : }
3421 : :
3422 : : /* Check whether the SUBREG is a paradoxical subreg and set the result
3423 : : in PDX_SUBREGS. */
3424 : :
3425 : : static void
3426 : 80473501 : set_paradoxical_subreg (rtx_insn *insn)
3427 : : {
3428 : 80473501 : subrtx_iterator::array_type array;
3429 : 508783307 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
3430 : : {
3431 : 428309806 : const_rtx subreg = *iter;
3432 : 428309806 : if (GET_CODE (subreg) == SUBREG)
3433 : : {
3434 : 2911493 : const_rtx reg = SUBREG_REG (subreg);
3435 : 2911493 : if (REG_P (reg) && paradoxical_subreg_p (subreg))
3436 : 843124 : reg_equiv[REGNO (reg)].pdx_subregs = true;
3437 : : }
3438 : : }
3439 : 80473501 : }
3440 : :
3441 : : /* In DEBUG_INSN location adjust REGs from CLEARED_REGS bitmap to the
3442 : : equivalent replacement. */
3443 : :
3444 : : static rtx
3445 : 33709151 : adjust_cleared_regs (rtx loc, const_rtx old_rtx ATTRIBUTE_UNUSED, void *data)
3446 : : {
3447 : 33709151 : if (REG_P (loc))
3448 : : {
3449 : 5329997 : bitmap cleared_regs = (bitmap) data;
3450 : 5329997 : if (bitmap_bit_p (cleared_regs, REGNO (loc)))
3451 : 29654 : return simplify_replace_fn_rtx (copy_rtx (*reg_equiv[REGNO (loc)].src_p),
3452 : 29654 : NULL_RTX, adjust_cleared_regs, data);
3453 : : }
3454 : : return NULL_RTX;
3455 : : }
3456 : :
3457 : : /* Given register REGNO is set only once, return true if the defining
3458 : : insn dominates all uses. */
3459 : :
3460 : : static bool
3461 : 47914 : def_dominates_uses (int regno)
3462 : : {
3463 : 47914 : df_ref def = DF_REG_DEF_CHAIN (regno);
3464 : :
3465 : 47914 : struct df_insn_info *def_info = DF_REF_INSN_INFO (def);
3466 : : /* If this is an artificial def (eh handler regs, hard frame pointer
3467 : : for non-local goto, regs defined on function entry) then def_info
3468 : : is NULL and the reg is always live before any use. We might
3469 : : reasonably return true in that case, but since the only call
3470 : : of this function is currently here in ira.cc when we are looking
3471 : : at a defining insn we can't have an artificial def as that would
3472 : : bump DF_REG_DEF_COUNT. */
3473 : 47914 : gcc_assert (DF_REG_DEF_COUNT (regno) == 1 && def_info != NULL);
3474 : :
3475 : 47914 : rtx_insn *def_insn = DF_REF_INSN (def);
3476 : 47914 : basic_block def_bb = BLOCK_FOR_INSN (def_insn);
3477 : :
3478 : 47914 : for (df_ref use = DF_REG_USE_CHAIN (regno);
3479 : 137587 : use;
3480 : 89673 : use = DF_REF_NEXT_REG (use))
3481 : : {
3482 : 89674 : struct df_insn_info *use_info = DF_REF_INSN_INFO (use);
3483 : : /* Only check real uses, not artificial ones. */
3484 : 89674 : if (use_info)
3485 : : {
3486 : 89674 : rtx_insn *use_insn = DF_REF_INSN (use);
3487 : 89674 : if (!DEBUG_INSN_P (use_insn))
3488 : : {
3489 : 89381 : basic_block use_bb = BLOCK_FOR_INSN (use_insn);
3490 : 89381 : if (use_bb != def_bb
3491 : 89381 : ? !dominated_by_p (CDI_DOMINATORS, use_bb, def_bb)
3492 : 52787 : : DF_INSN_INFO_LUID (use_info) < DF_INSN_INFO_LUID (def_info))
3493 : : return false;
3494 : : }
3495 : : }
3496 : : }
3497 : : return true;
3498 : : }
3499 : :
3500 : : /* Scan the instructions before update_equiv_regs. Record which registers
3501 : : are referenced as paradoxical subregs. Also check for cases in which
3502 : : the current function needs to save a register that one of its call
3503 : : instructions clobbers.
3504 : :
3505 : : These things are logically unrelated, but it's more efficient to do
3506 : : them together. */
3507 : :
3508 : : static void
3509 : 1435841 : update_equiv_regs_prescan (void)
3510 : : {
3511 : 1435841 : basic_block bb;
3512 : 1435841 : rtx_insn *insn;
3513 : 1435841 : function_abi_aggregator callee_abis;
3514 : :
3515 : 15175131 : FOR_EACH_BB_FN (bb, cfun)
3516 : 161563478 : FOR_BB_INSNS (bb, insn)
3517 : 147824188 : if (NONDEBUG_INSN_P (insn))
3518 : : {
3519 : 80473501 : set_paradoxical_subreg (insn);
3520 : 80473501 : if (CALL_P (insn))
3521 : 5787589 : callee_abis.note_callee_abi (insn_callee_abi (insn));
3522 : : }
3523 : :
3524 : 1435841 : HARD_REG_SET extra_caller_saves = callee_abis.caller_save_regs (*crtl->abi);
3525 : 2871682 : if (!hard_reg_set_empty_p (extra_caller_saves))
3526 : 0 : for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
3527 : 0 : if (TEST_HARD_REG_BIT (extra_caller_saves, regno))
3528 : 0 : df_set_regs_ever_live (regno, true);
3529 : 1435841 : }
3530 : :
3531 : : /* Find registers that are equivalent to a single value throughout the
3532 : : compilation (either because they can be referenced in memory or are
3533 : : set once from a single constant). Lower their priority for a
3534 : : register.
3535 : :
3536 : : If such a register is only referenced once, try substituting its
3537 : : value into the using insn. If it succeeds, we can eliminate the
3538 : : register completely.
3539 : :
3540 : : Initialize init_insns in ira_reg_equiv array. */
3541 : : static void
3542 : 1435841 : update_equiv_regs (void)
3543 : : {
3544 : 1435841 : rtx_insn *insn;
3545 : 1435841 : basic_block bb;
3546 : :
3547 : : /* Scan the insns and find which registers have equivalences. Do this
3548 : : in a separate scan of the insns because (due to -fcse-follow-jumps)
3549 : : a register can be set below its use. */
3550 : 1435841 : bitmap setjmp_crosses = regstat_get_setjmp_crosses ();
3551 : 15175131 : FOR_EACH_BB_FN (bb, cfun)
3552 : : {
3553 : 13739290 : int loop_depth = bb_loop_depth (bb);
3554 : :
3555 : 161563478 : for (insn = BB_HEAD (bb);
3556 : 161563478 : insn != NEXT_INSN (BB_END (bb));
3557 : 147824188 : insn = NEXT_INSN (insn))
3558 : : {
3559 : 147824188 : rtx note;
3560 : 147824188 : rtx set;
3561 : 147824188 : rtx dest, src;
3562 : 147824188 : int regno;
3563 : :
3564 : 147824188 : if (! INSN_P (insn))
3565 : 25277499 : continue;
3566 : :
3567 : 203249789 : for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
3568 : 80703100 : if (REG_NOTE_KIND (note) == REG_INC)
3569 : 0 : no_equiv (XEXP (note, 0), note, NULL);
3570 : :
3571 : 122546689 : set = single_set (insn);
3572 : :
3573 : : /* If this insn contains more (or less) than a single SET,
3574 : : only mark all destinations as having no known equivalence. */
3575 : 172672004 : if (set == NULL_RTX
3576 : 122546689 : || side_effects_p (SET_SRC (set)))
3577 : : {
3578 : 50125315 : note_pattern_stores (PATTERN (insn), no_equiv, NULL);
3579 : 50125315 : continue;
3580 : : }
3581 : 72421374 : else if (GET_CODE (PATTERN (insn)) == PARALLEL)
3582 : : {
3583 : 10184815 : int i;
3584 : :
3585 : 30824357 : for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
3586 : : {
3587 : 20639542 : rtx part = XVECEXP (PATTERN (insn), 0, i);
3588 : 20639542 : if (part != set)
3589 : 10454727 : note_pattern_stores (part, no_equiv, NULL);
3590 : : }
3591 : : }
3592 : :
3593 : 72421374 : dest = SET_DEST (set);
3594 : 72421374 : src = SET_SRC (set);
3595 : :
3596 : : /* See if this is setting up the equivalence between an argument
3597 : : register and its stack slot. */
3598 : 72421374 : note = find_reg_note (insn, REG_EQUIV, NULL_RTX);
3599 : 72421374 : if (note)
3600 : : {
3601 : 227081 : gcc_assert (REG_P (dest));
3602 : 227081 : regno = REGNO (dest);
3603 : :
3604 : : /* Note that we don't want to clear init_insns in
3605 : : ira_reg_equiv even if there are multiple sets of this
3606 : : register. */
3607 : 227081 : reg_equiv[regno].is_arg_equivalence = 1;
3608 : :
3609 : : /* The insn result can have equivalence memory although
3610 : : the equivalence is not set up by the insn. We add
3611 : : this insn to init insns as it is a flag for now that
3612 : : regno has an equivalence. We will remove the insn
3613 : : from init insn list later. */
3614 : 227081 : if (rtx_equal_p (src, XEXP (note, 0)) || MEM_P (XEXP (note, 0)))
3615 : 227081 : ira_reg_equiv[regno].init_insns
3616 : 227081 : = gen_rtx_INSN_LIST (VOIDmode, insn,
3617 : 227081 : ira_reg_equiv[regno].init_insns);
3618 : :
3619 : : /* Continue normally in case this is a candidate for
3620 : : replacements. */
3621 : : }
3622 : :
3623 : 72421374 : if (!optimize)
3624 : 22419412 : continue;
3625 : :
3626 : : /* We only handle the case of a pseudo register being set
3627 : : once, or always to the same value. */
3628 : : /* ??? The mn10200 port breaks if we add equivalences for
3629 : : values that need an ADDRESS_REGS register and set them equivalent
3630 : : to a MEM of a pseudo. The actual problem is in the over-conservative
3631 : : handling of INPADDR_ADDRESS / INPUT_ADDRESS / INPUT triples in
3632 : : calculate_needs, but we traditionally work around this problem
3633 : : here by rejecting equivalences when the destination is in a register
3634 : : that's likely spilled. This is fragile, of course, since the
3635 : : preferred class of a pseudo depends on all instructions that set
3636 : : or use it. */
3637 : :
3638 : 82588765 : if (!REG_P (dest)
3639 : 34920245 : || (regno = REGNO (dest)) < FIRST_PSEUDO_REGISTER
3640 : 19927358 : || (reg_equiv[regno].init_insns
3641 : 3357771 : && reg_equiv[regno].init_insns->insn () == NULL)
3642 : 67417184 : || (targetm.class_likely_spilled_p (reg_preferred_class (regno))
3643 : 420 : && MEM_P (src) && ! reg_equiv[regno].is_arg_equivalence))
3644 : : {
3645 : : /* This might be setting a SUBREG of a pseudo, a pseudo that is
3646 : : also set somewhere else to a constant. */
3647 : 32586803 : note_pattern_stores (set, no_equiv, NULL);
3648 : 32586803 : continue;
3649 : : }
3650 : :
3651 : : /* Don't set reg mentioned in a paradoxical subreg
3652 : : equivalent to a mem. */
3653 : 17415159 : if (MEM_P (src) && reg_equiv[regno].pdx_subregs)
3654 : : {
3655 : 13201 : note_pattern_stores (set, no_equiv, NULL);
3656 : 13201 : continue;
3657 : : }
3658 : :
3659 : 17401958 : note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
3660 : :
3661 : : /* cse sometimes generates function invariants, but doesn't put a
3662 : : REG_EQUAL note on the insn. Since this note would be redundant,
3663 : : there's no point creating it earlier than here. */
3664 : 17401958 : if (! note && ! rtx_varies_p (src, 0))
3665 : 2729054 : note = set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src));
3666 : :
3667 : : /* Don't bother considering a REG_EQUAL note containing an EXPR_LIST
3668 : : since it represents a function call. */
3669 : 17401958 : if (note && GET_CODE (XEXP (note, 0)) == EXPR_LIST)
3670 : 13676743 : note = NULL_RTX;
3671 : :
3672 : 17401958 : if (DF_REG_DEF_COUNT (regno) != 1)
3673 : : {
3674 : 2835178 : bool equal_p = true;
3675 : 2835178 : rtx_insn_list *list;
3676 : :
3677 : : /* If we have already processed this pseudo and determined it
3678 : : cannot have an equivalence, then honor that decision. */
3679 : 2835178 : if (reg_equiv[regno].no_equiv)
3680 : 0 : continue;
3681 : :
3682 : 4545123 : if (! note
3683 : 1154511 : || rtx_varies_p (XEXP (note, 0), 0)
3684 : 3960415 : || (reg_equiv[regno].replacement
3685 : 4 : && ! rtx_equal_p (XEXP (note, 0),
3686 : : reg_equiv[regno].replacement)))
3687 : : {
3688 : 1709945 : no_equiv (dest, set, NULL);
3689 : 1709945 : continue;
3690 : : }
3691 : :
3692 : 1125233 : list = reg_equiv[regno].init_insns;
3693 : 2843174 : for (; list; list = list->next ())
3694 : : {
3695 : 1804327 : rtx note_tmp;
3696 : 1804327 : rtx_insn *insn_tmp;
3697 : :
3698 : 1804327 : insn_tmp = list->insn ();
3699 : 1804327 : note_tmp = find_reg_note (insn_tmp, REG_EQUAL, NULL_RTX);
3700 : 1804327 : gcc_assert (note_tmp);
3701 : 1804327 : if (! rtx_equal_p (XEXP (note, 0), XEXP (note_tmp, 0)))
3702 : : {
3703 : : equal_p = false;
3704 : : break;
3705 : : }
3706 : : }
3707 : :
3708 : 1125233 : if (! equal_p)
3709 : : {
3710 : 86386 : no_equiv (dest, set, NULL);
3711 : 86386 : continue;
3712 : : }
3713 : : }
3714 : :
3715 : : /* Record this insn as initializing this register. */
3716 : 15605627 : reg_equiv[regno].init_insns
3717 : 15605627 : = gen_rtx_INSN_LIST (VOIDmode, insn, reg_equiv[regno].init_insns);
3718 : :
3719 : : /* If this register is known to be equal to a constant, record that
3720 : : it is always equivalent to the constant.
3721 : : Note that it is possible to have a register use before
3722 : : the def in loops (see gcc.c-torture/execute/pr79286.c)
3723 : : where the reg is undefined on first use. If the def insn
3724 : : won't trap we can use it as an equivalence, effectively
3725 : : choosing the "undefined" value for the reg to be the
3726 : : same as the value set by the def. */
3727 : 15605627 : if (DF_REG_DEF_COUNT (regno) == 1
3728 : 14566780 : && note
3729 : 2570704 : && !rtx_varies_p (XEXP (note, 0), 0)
3730 : 17789789 : && (!may_trap_or_fault_p (XEXP (note, 0))
3731 : 47914 : || def_dominates_uses (regno)))
3732 : : {
3733 : 2184161 : rtx note_value = XEXP (note, 0);
3734 : 2184161 : remove_note (insn, note);
3735 : 2184161 : set_unique_reg_note (insn, REG_EQUIV, note_value);
3736 : : }
3737 : :
3738 : : /* If this insn introduces a "constant" register, decrease the priority
3739 : : of that register. Record this insn if the register is only used once
3740 : : more and the equivalence value is the same as our source.
3741 : :
3742 : : The latter condition is checked for two reasons: First, it is an
3743 : : indication that it may be more efficient to actually emit the insn
3744 : : as written (if no registers are available, reload will substitute
3745 : : the equivalence). Secondly, it avoids problems with any registers
3746 : : dying in this insn whose death notes would be missed.
3747 : :
3748 : : If we don't have a REG_EQUIV note, see if this insn is loading
3749 : : a register used only in one basic block from a MEM. If so, and the
3750 : : MEM remains unchanged for the life of the register, add a REG_EQUIV
3751 : : note. */
3752 : 15605627 : note = find_reg_note (insn, REG_EQUIV, NULL_RTX);
3753 : :
3754 : 15605627 : rtx replacement = NULL_RTX;
3755 : 15605627 : if (note)
3756 : 2404651 : replacement = XEXP (note, 0);
3757 : 13200976 : else if (REG_BASIC_BLOCK (regno) >= NUM_FIXED_BLOCKS
3758 : 9491113 : && MEM_P (SET_SRC (set)))
3759 : : {
3760 : 2762891 : enum valid_equiv validity;
3761 : 2762891 : validity = validate_equiv_mem (insn, dest, SET_SRC (set));
3762 : 2762891 : if (validity != valid_none)
3763 : : {
3764 : 2070693 : replacement = copy_rtx (SET_SRC (set));
3765 : 2070693 : if (validity == valid_reload)
3766 : : {
3767 : 2069882 : note = set_unique_reg_note (insn, REG_EQUIV, replacement);
3768 : : }
3769 : 811 : else if (ira_use_lra_p)
3770 : : {
3771 : : /* We still can use this equivalence for caller save
3772 : : optimization in LRA. Mark this. */
3773 : 811 : ira_reg_equiv[regno].caller_save_p = true;
3774 : 811 : ira_reg_equiv[regno].init_insns
3775 : 811 : = gen_rtx_INSN_LIST (VOIDmode, insn,
3776 : 811 : ira_reg_equiv[regno].init_insns);
3777 : : }
3778 : : }
3779 : : }
3780 : :
3781 : : /* If we haven't done so, record for reload that this is an
3782 : : equivalencing insn. */
3783 : 15605627 : if (note && !reg_equiv[regno].is_arg_equivalence)
3784 : 4254043 : ira_reg_equiv[regno].init_insns
3785 : 4254043 : = gen_rtx_INSN_LIST (VOIDmode, insn,
3786 : 4254043 : ira_reg_equiv[regno].init_insns);
3787 : :
3788 : 15605627 : if (replacement)
3789 : : {
3790 : 4475344 : reg_equiv[regno].replacement = replacement;
3791 : 4475344 : reg_equiv[regno].src_p = &SET_SRC (set);
3792 : 4475344 : reg_equiv[regno].loop_depth = (short) loop_depth;
3793 : :
3794 : : /* Don't mess with things live during setjmp. */
3795 : 4475344 : if (optimize && !bitmap_bit_p (setjmp_crosses, regno))
3796 : : {
3797 : : /* If the register is referenced exactly twice, meaning it is
3798 : : set once and used once, indicate that the reference may be
3799 : : replaced by the equivalence we computed above. Do this
3800 : : even if the register is only used in one block so that
3801 : : dependencies can be handled where the last register is
3802 : : used in a different block (i.e. HIGH / LO_SUM sequences)
3803 : : and to reduce the number of registers alive across
3804 : : calls. */
3805 : :
3806 : 4475303 : if (REG_N_REFS (regno) == 2
3807 : 3535049 : && (rtx_equal_p (replacement, src)
3808 : 392317 : || ! equiv_init_varies_p (src))
3809 : 3502700 : && NONJUMP_INSN_P (insn)
3810 : 7978003 : && equiv_init_movable_p (PATTERN (insn), regno))
3811 : 2186144 : reg_equiv[regno].replace = 1;
3812 : : }
3813 : : }
3814 : : }
3815 : : }
3816 : 1435841 : }
3817 : :
3818 : : /* For insns that set a MEM to the contents of a REG that is only used
3819 : : in a single basic block, see if the register is always equivalent
3820 : : to that memory location and if moving the store from INSN to the
3821 : : insn that sets REG is safe. If so, put a REG_EQUIV note on the
3822 : : initializing insn. */
3823 : : static void
3824 : 933022 : add_store_equivs (void)
3825 : : {
3826 : 933022 : auto_sbitmap seen_insns (get_max_uid () + 1);
3827 : 933022 : bitmap_clear (seen_insns);
3828 : :
3829 : 117565464 : for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
3830 : : {
3831 : 116632442 : rtx set, src, dest;
3832 : 116632442 : unsigned regno;
3833 : 116632442 : rtx_insn *init_insn;
3834 : :
3835 : 116632442 : bitmap_set_bit (seen_insns, INSN_UID (insn));
3836 : :
3837 : 116632442 : if (! INSN_P (insn))
3838 : 22528716 : continue;
3839 : :
3840 : 94103726 : set = single_set (insn);
3841 : 94103726 : if (! set)
3842 : 45427565 : continue;
3843 : :
3844 : 48676161 : dest = SET_DEST (set);
3845 : 48676161 : src = SET_SRC (set);
3846 : :
3847 : : /* Don't add a REG_EQUIV note if the insn already has one. The existing
3848 : : REG_EQUIV is likely more useful than the one we are adding. */
3849 : 7198671 : if (MEM_P (dest) && REG_P (src)
3850 : 4802982 : && (regno = REGNO (src)) >= FIRST_PSEUDO_REGISTER
3851 : 4739425 : && REG_BASIC_BLOCK (regno) >= NUM_FIXED_BLOCKS
3852 : 2770150 : && DF_REG_DEF_COUNT (regno) == 1
3853 : 2702347 : && ! reg_equiv[regno].pdx_subregs
3854 : 2556873 : && reg_equiv[regno].init_insns != NULL
3855 : 2556873 : && (init_insn = reg_equiv[regno].init_insns->insn ()) != 0
3856 : 2538190 : && bitmap_bit_p (seen_insns, INSN_UID (init_insn))
3857 : 2538190 : && ! find_reg_note (init_insn, REG_EQUIV, NULL_RTX)
3858 : 867640 : && validate_equiv_mem (init_insn, src, dest) == valid_reload
3859 : 512358 : && ! memref_used_between_p (dest, init_insn, insn)
3860 : : /* Attaching a REG_EQUIV note will fail if INIT_INSN has
3861 : : multiple sets. */
3862 : 49116926 : && set_unique_reg_note (init_insn, REG_EQUIV, copy_rtx (dest)))
3863 : : {
3864 : : /* This insn makes the equivalence, not the one initializing
3865 : : the register. */
3866 : 440375 : ira_reg_equiv[regno].init_insns
3867 : 440375 : = gen_rtx_INSN_LIST (VOIDmode, insn, NULL_RTX);
3868 : 440375 : df_notes_rescan (init_insn);
3869 : 440375 : if (dump_file)
3870 : 88 : fprintf (dump_file,
3871 : : "Adding REG_EQUIV to insn %d for source of insn %d\n",
3872 : 88 : INSN_UID (init_insn),
3873 : 88 : INSN_UID (insn));
3874 : : }
3875 : : }
3876 : 933022 : }
3877 : :
3878 : : /* Scan all regs killed in an insn to see if any of them are registers
3879 : : only used that once. If so, see if we can replace the reference
3880 : : with the equivalent form. If we can, delete the initializing
3881 : : reference and this register will go away. If we can't replace the
3882 : : reference, and the initializing reference is within the same loop
3883 : : (or in an inner loop), then move the register initialization just
3884 : : before the use, so that they are in the same basic block. */
3885 : : static void
3886 : 1008502 : combine_and_move_insns (void)
3887 : : {
3888 : 1008502 : auto_bitmap cleared_regs;
3889 : 1008502 : int max = max_reg_num ();
3890 : :
3891 : 49382204 : for (int regno = FIRST_PSEUDO_REGISTER; regno < max; regno++)
3892 : : {
3893 : 48373702 : if (!reg_equiv[regno].replace)
3894 : 46187772 : continue;
3895 : :
3896 : 2185930 : rtx_insn *use_insn = 0;
3897 : 2185930 : for (df_ref use = DF_REG_USE_CHAIN (regno);
3898 : 4404081 : use;
3899 : 2218151 : use = DF_REF_NEXT_REG (use))
3900 : 2218151 : if (DF_REF_INSN_INFO (use))
3901 : : {
3902 : 2218151 : if (DEBUG_INSN_P (DF_REF_INSN (use)))
3903 : 32221 : continue;
3904 : 2185930 : gcc_assert (!use_insn);
3905 : : use_insn = DF_REF_INSN (use);
3906 : : }
3907 : 2185930 : gcc_assert (use_insn);
3908 : :
3909 : : /* Don't substitute into jumps. indirect_jump_optimize does
3910 : : this for anything we are prepared to handle. */
3911 : 2185930 : if (JUMP_P (use_insn))
3912 : 392 : continue;
3913 : :
3914 : : /* Also don't substitute into a conditional trap insn -- it can become
3915 : : an unconditional trap, and that is a flow control insn. */
3916 : 2185538 : if (GET_CODE (PATTERN (use_insn)) == TRAP_IF)
3917 : 0 : continue;
3918 : :
3919 : 2185538 : df_ref def = DF_REG_DEF_CHAIN (regno);
3920 : 2185538 : gcc_assert (DF_REG_DEF_COUNT (regno) == 1 && DF_REF_INSN_INFO (def));
3921 : 2185538 : rtx_insn *def_insn = DF_REF_INSN (def);
3922 : :
3923 : : /* We may not move instructions that can throw, since that
3924 : : changes basic block boundaries and we are not prepared to
3925 : : adjust the CFG to match. */
3926 : 2185538 : if (can_throw_internal (def_insn))
3927 : 0 : continue;
3928 : :
3929 : : /* Instructions with multiple sets can only be moved if DF analysis is
3930 : : performed for all of the registers set. See PR91052. */
3931 : 2185538 : if (multiple_sets (def_insn))
3932 : 0 : continue;
3933 : :
3934 : 2185538 : basic_block use_bb = BLOCK_FOR_INSN (use_insn);
3935 : 2185538 : basic_block def_bb = BLOCK_FOR_INSN (def_insn);
3936 : 2185538 : if (bb_loop_depth (use_bb) > bb_loop_depth (def_bb))
3937 : 138618 : continue;
3938 : :
3939 : 2046920 : if (asm_noperands (PATTERN (def_insn)) < 0
3940 : 4093840 : && validate_replace_rtx (regno_reg_rtx[regno],
3941 : 2046920 : *reg_equiv[regno].src_p, use_insn))
3942 : : {
3943 : 361821 : rtx link;
3944 : : /* Append the REG_DEAD notes from def_insn. */
3945 : 724508 : for (rtx *p = ®_NOTES (def_insn); (link = *p) != 0; )
3946 : : {
3947 : 362687 : if (REG_NOTE_KIND (XEXP (link, 0)) == REG_DEAD)
3948 : : {
3949 : 0 : *p = XEXP (link, 1);
3950 : 0 : XEXP (link, 1) = REG_NOTES (use_insn);
3951 : 0 : REG_NOTES (use_insn) = link;
3952 : : }
3953 : : else
3954 : 362687 : p = &XEXP (link, 1);
3955 : : }
3956 : :
3957 : 361821 : remove_death (regno, use_insn);
3958 : 361821 : SET_REG_N_REFS (regno, 0);
3959 : 361821 : REG_FREQ (regno) = 0;
3960 : 361821 : df_ref use;
3961 : 433868 : FOR_EACH_INSN_USE (use, def_insn)
3962 : : {
3963 : 72047 : unsigned int use_regno = DF_REF_REGNO (use);
3964 : 72047 : if (!HARD_REGISTER_NUM_P (use_regno))
3965 : 1271 : reg_equiv[use_regno].replace = 0;
3966 : : }
3967 : :
3968 : 361821 : delete_insn (def_insn);
3969 : :
3970 : 361821 : reg_equiv[regno].init_insns = NULL;
3971 : 361821 : ira_reg_equiv[regno].init_insns = NULL;
3972 : 361821 : bitmap_set_bit (cleared_regs, regno);
3973 : : }
3974 : :
3975 : : /* Move the initialization of the register to just before
3976 : : USE_INSN. Update the flow information. */
3977 : 1685099 : else if (prev_nondebug_insn (use_insn) != def_insn)
3978 : : {
3979 : 326693 : rtx_insn *new_insn;
3980 : :
3981 : 326693 : new_insn = emit_insn_before (PATTERN (def_insn), use_insn);
3982 : 326693 : REG_NOTES (new_insn) = REG_NOTES (def_insn);
3983 : 326693 : REG_NOTES (def_insn) = 0;
3984 : : /* Rescan it to process the notes. */
3985 : 326693 : df_insn_rescan (new_insn);
3986 : :
3987 : : /* Make sure this insn is recognized before reload begins,
3988 : : otherwise eliminate_regs_in_insn will die. */
3989 : 326693 : INSN_CODE (new_insn) = INSN_CODE (def_insn);
3990 : :
3991 : 326693 : delete_insn (def_insn);
3992 : :
3993 : 326693 : XEXP (reg_equiv[regno].init_insns, 0) = new_insn;
3994 : :
3995 : 326693 : REG_BASIC_BLOCK (regno) = use_bb->index;
3996 : 326693 : REG_N_CALLS_CROSSED (regno) = 0;
3997 : :
3998 : 326693 : if (use_insn == BB_HEAD (use_bb))
3999 : 0 : BB_HEAD (use_bb) = new_insn;
4000 : :
4001 : : /* We know regno dies in use_insn, but inside a loop
4002 : : REG_DEAD notes might be missing when def_insn was in
4003 : : another basic block. However, when we move def_insn into
4004 : : this bb we'll definitely get a REG_DEAD note and reload
4005 : : will see the death. It's possible that update_equiv_regs
4006 : : set up an equivalence referencing regno for a reg set by
4007 : : use_insn, when regno was seen as non-local. Now that
4008 : : regno is local to this block, and dies, such an
4009 : : equivalence is invalid. */
4010 : 326693 : if (find_reg_note (use_insn, REG_EQUIV, regno_reg_rtx[regno]))
4011 : : {
4012 : 0 : rtx set = single_set (use_insn);
4013 : 0 : if (set && REG_P (SET_DEST (set)))
4014 : 0 : no_equiv (SET_DEST (set), set, NULL);
4015 : : }
4016 : :
4017 : 326693 : ira_reg_equiv[regno].init_insns
4018 : 326693 : = gen_rtx_INSN_LIST (VOIDmode, new_insn, NULL_RTX);
4019 : 326693 : bitmap_set_bit (cleared_regs, regno);
4020 : : }
4021 : : }
4022 : :
4023 : 1008502 : if (!bitmap_empty_p (cleared_regs))
4024 : : {
4025 : 217786 : basic_block bb;
4026 : :
4027 : 5476132 : FOR_EACH_BB_FN (bb, cfun)
4028 : : {
4029 : 10516692 : bitmap_and_compl_into (DF_LR_IN (bb), cleared_regs);
4030 : 10516692 : bitmap_and_compl_into (DF_LR_OUT (bb), cleared_regs);
4031 : 5258346 : if (!df_live)
4032 : 5258346 : continue;
4033 : 0 : bitmap_and_compl_into (DF_LIVE_IN (bb), cleared_regs);
4034 : 0 : bitmap_and_compl_into (DF_LIVE_OUT (bb), cleared_regs);
4035 : : }
4036 : :
4037 : : /* Last pass - adjust debug insns referencing cleared regs. */
4038 : 217786 : if (MAY_HAVE_DEBUG_BIND_INSNS)
4039 : 54710336 : for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
4040 : 54589190 : if (DEBUG_BIND_INSN_P (insn))
4041 : : {
4042 : 18422988 : rtx old_loc = INSN_VAR_LOCATION_LOC (insn);
4043 : 18422988 : INSN_VAR_LOCATION_LOC (insn)
4044 : 36845976 : = simplify_replace_fn_rtx (old_loc, NULL_RTX,
4045 : : adjust_cleared_regs,
4046 : 18422988 : (void *) cleared_regs);
4047 : 18422988 : if (old_loc != INSN_VAR_LOCATION_LOC (insn))
4048 : 29317 : df_insn_rescan (insn);
4049 : : }
4050 : : }
4051 : 1008502 : }
4052 : :
4053 : : /* A pass over indirect jumps, converting simple cases to direct jumps.
4054 : : Combine does this optimization too, but only within a basic block. */
4055 : : static void
4056 : 1435841 : indirect_jump_optimize (void)
4057 : : {
4058 : 1435841 : basic_block bb;
4059 : 1435841 : bool rebuild_p = false;
4060 : :
4061 : 15175133 : FOR_EACH_BB_REVERSE_FN (bb, cfun)
4062 : : {
4063 : 13739292 : rtx_insn *insn = BB_END (bb);
4064 : 19174802 : if (!JUMP_P (insn)
4065 : 13739292 : || find_reg_note (insn, REG_NON_LOCAL_GOTO, NULL_RTX))
4066 : 5435510 : continue;
4067 : :
4068 : 8303782 : rtx x = pc_set (insn);
4069 : 8303782 : if (!x || !REG_P (SET_SRC (x)))
4070 : 8302525 : continue;
4071 : :
4072 : 1257 : int regno = REGNO (SET_SRC (x));
4073 : 1257 : if (DF_REG_DEF_COUNT (regno) == 1)
4074 : : {
4075 : 1146 : df_ref def = DF_REG_DEF_CHAIN (regno);
4076 : 1146 : if (!DF_REF_IS_ARTIFICIAL (def))
4077 : : {
4078 : 1146 : rtx_insn *def_insn = DF_REF_INSN (def);
4079 : 1146 : rtx lab = NULL_RTX;
4080 : 1146 : rtx set = single_set (def_insn);
4081 : 1146 : if (set && GET_CODE (SET_SRC (set)) == LABEL_REF)
4082 : : lab = SET_SRC (set);
4083 : : else
4084 : : {
4085 : 1145 : rtx eqnote = find_reg_note (def_insn, REG_EQUAL, NULL_RTX);
4086 : 1145 : if (eqnote && GET_CODE (XEXP (eqnote, 0)) == LABEL_REF)
4087 : : lab = XEXP (eqnote, 0);
4088 : : }
4089 : 1 : if (lab && validate_replace_rtx (SET_SRC (x), lab, insn))
4090 : : rebuild_p = true;
4091 : : }
4092 : : }
4093 : : }
4094 : :
4095 : 1435841 : if (rebuild_p)
4096 : : {
4097 : 1 : timevar_push (TV_JUMP);
4098 : 1 : rebuild_jump_labels (get_insns ());
4099 : 1 : if (purge_all_dead_edges ())
4100 : 1 : delete_unreachable_blocks ();
4101 : 1 : timevar_pop (TV_JUMP);
4102 : : }
4103 : 1435841 : }
4104 : :
4105 : : /* Set up fields memory, constant, and invariant from init_insns in
4106 : : the structures of array ira_reg_equiv. */
4107 : : static void
4108 : 1435841 : setup_reg_equiv (void)
4109 : : {
4110 : 1435841 : int i;
4111 : 1435841 : rtx_insn_list *elem, *prev_elem, *next_elem;
4112 : 1435841 : rtx_insn *insn;
4113 : 1435841 : rtx set, x;
4114 : :
4115 : 162923138 : for (i = FIRST_PSEUDO_REGISTER; i < ira_reg_equiv_len; i++)
4116 : 161487297 : for (prev_elem = NULL, elem = ira_reg_equiv[i].init_insns;
4117 : 165829195 : elem;
4118 : : prev_elem = elem, elem = next_elem)
4119 : : {
4120 : 4558222 : next_elem = elem->next ();
4121 : 4558222 : insn = elem->insn ();
4122 : 4558222 : set = single_set (insn);
4123 : :
4124 : : /* Init insns can set up equivalence when the reg is a destination or
4125 : : a source (in this case the destination is memory). */
4126 : 4558222 : if (set != 0 && (REG_P (SET_DEST (set)) || REG_P (SET_SRC (set))))
4127 : : {
4128 : 4558222 : if ((x = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != NULL)
4129 : : {
4130 : 4117118 : x = XEXP (x, 0);
4131 : 4117118 : if (REG_P (SET_DEST (set))
4132 : 4117118 : && REGNO (SET_DEST (set)) == (unsigned int) i
4133 : 8234236 : && ! rtx_equal_p (SET_SRC (set), x) && MEM_P (x))
4134 : : {
4135 : : /* This insn reporting the equivalence but
4136 : : actually not setting it. Remove it from the
4137 : : list. */
4138 : 30537 : if (prev_elem == NULL)
4139 : 30537 : ira_reg_equiv[i].init_insns = next_elem;
4140 : : else
4141 : 0 : XEXP (prev_elem, 1) = next_elem;
4142 : : elem = prev_elem;
4143 : : }
4144 : : }
4145 : 441104 : else if (REG_P (SET_DEST (set))
4146 : 441104 : && REGNO (SET_DEST (set)) == (unsigned int) i)
4147 : 729 : x = SET_SRC (set);
4148 : : else
4149 : : {
4150 : 440375 : gcc_assert (REG_P (SET_SRC (set))
4151 : : && REGNO (SET_SRC (set)) == (unsigned int) i);
4152 : : x = SET_DEST (set);
4153 : : }
4154 : 4558222 : if (! function_invariant_p (x)
4155 : 1874117 : || ! flag_pic
4156 : : /* A function invariant is often CONSTANT_P but may
4157 : : include a register. We promise to only pass
4158 : : CONSTANT_P objects to LEGITIMATE_PIC_OPERAND_P. */
4159 : 4776365 : || (CONSTANT_P (x) && LEGITIMATE_PIC_OPERAND_P (x)))
4160 : : {
4161 : : /* It can happen that a REG_EQUIV note contains a MEM
4162 : : that is not a legitimate memory operand. As later
4163 : : stages of reload assume that all addresses found in
4164 : : the lra_regno_equiv_* arrays were originally
4165 : : legitimate, we ignore such REG_EQUIV notes. */
4166 : 4419767 : if (memory_operand (x, VOIDmode))
4167 : : {
4168 : 2606711 : ira_reg_equiv[i].defined_p = !ira_reg_equiv[i].caller_save_p;
4169 : 2606711 : ira_reg_equiv[i].memory = x;
4170 : 2606711 : continue;
4171 : : }
4172 : 1813056 : else if (function_invariant_p (x))
4173 : : {
4174 : 1735662 : machine_mode mode;
4175 : :
4176 : 1735662 : mode = GET_MODE (SET_DEST (set));
4177 : 1735662 : if (GET_CODE (x) == PLUS
4178 : 986479 : || x == frame_pointer_rtx || x == arg_pointer_rtx)
4179 : : /* This is PLUS of frame pointer and a constant,
4180 : : or fp, or argp. */
4181 : 750008 : ira_reg_equiv[i].invariant = x;
4182 : 985654 : else if (targetm.legitimate_constant_p (mode, x))
4183 : 730553 : ira_reg_equiv[i].constant = x;
4184 : : else
4185 : : {
4186 : 255101 : ira_reg_equiv[i].memory = force_const_mem (mode, x);
4187 : 255101 : if (ira_reg_equiv[i].memory == NULL_RTX)
4188 : : {
4189 : 475 : ira_reg_equiv[i].defined_p = false;
4190 : 475 : ira_reg_equiv[i].caller_save_p = false;
4191 : 475 : ira_reg_equiv[i].init_insns = NULL;
4192 : 475 : break;
4193 : : }
4194 : : }
4195 : 1735187 : ira_reg_equiv[i].defined_p = true;
4196 : 1735187 : continue;
4197 : 1735187 : }
4198 : : }
4199 : : }
4200 : 215849 : ira_reg_equiv[i].defined_p = false;
4201 : 215849 : ira_reg_equiv[i].caller_save_p = false;
4202 : 215849 : ira_reg_equiv[i].init_insns = NULL;
4203 : 215849 : break;
4204 : : }
4205 : 1435841 : }
4206 : :
4207 : :
4208 : :
4209 : : /* Print chain C to FILE. */
4210 : : static void
4211 : 0 : print_insn_chain (FILE *file, class insn_chain *c)
4212 : : {
4213 : 0 : fprintf (file, "insn=%d, ", INSN_UID (c->insn));
4214 : 0 : bitmap_print (file, &c->live_throughout, "live_throughout: ", ", ");
4215 : 0 : bitmap_print (file, &c->dead_or_set, "dead_or_set: ", "\n");
4216 : 0 : }
4217 : :
4218 : :
4219 : : /* Print all reload_insn_chains to FILE. */
4220 : : static void
4221 : 0 : print_insn_chains (FILE *file)
4222 : : {
4223 : 0 : class insn_chain *c;
4224 : 0 : for (c = reload_insn_chain; c ; c = c->next)
4225 : 0 : print_insn_chain (file, c);
4226 : 0 : }
4227 : :
4228 : : /* Return true if pseudo REGNO should be added to set live_throughout
4229 : : or dead_or_set of the insn chains for reload consideration. */
4230 : : static bool
4231 : 0 : pseudo_for_reload_consideration_p (int regno)
4232 : : {
4233 : : /* Consider spilled pseudos too for IRA because they still have a
4234 : : chance to get hard-registers in the reload when IRA is used. */
4235 : 0 : return (reg_renumber[regno] >= 0 || ira_conflicts_p);
4236 : : }
4237 : :
4238 : : /* Return true if we can track the individual bytes of subreg X.
4239 : : When returning true, set *OUTER_SIZE to the number of bytes in
4240 : : X itself, *INNER_SIZE to the number of bytes in the inner register
4241 : : and *START to the offset of the first byte. */
4242 : : static bool
4243 : 0 : get_subreg_tracking_sizes (rtx x, HOST_WIDE_INT *outer_size,
4244 : : HOST_WIDE_INT *inner_size, HOST_WIDE_INT *start)
4245 : : {
4246 : 0 : rtx reg = regno_reg_rtx[REGNO (SUBREG_REG (x))];
4247 : 0 : return (GET_MODE_SIZE (GET_MODE (x)).is_constant (outer_size)
4248 : 0 : && GET_MODE_SIZE (GET_MODE (reg)).is_constant (inner_size)
4249 : 0 : && SUBREG_BYTE (x).is_constant (start));
4250 : : }
4251 : :
4252 : : /* Init LIVE_SUBREGS[ALLOCNUM] and LIVE_SUBREGS_USED[ALLOCNUM] for
4253 : : a register with SIZE bytes, making the register live if INIT_VALUE. */
4254 : : static void
4255 : 0 : init_live_subregs (bool init_value, sbitmap *live_subregs,
4256 : : bitmap live_subregs_used, int allocnum, int size)
4257 : : {
4258 : 0 : gcc_assert (size > 0);
4259 : :
4260 : : /* Been there, done that. */
4261 : 0 : if (bitmap_bit_p (live_subregs_used, allocnum))
4262 : : return;
4263 : :
4264 : : /* Create a new one. */
4265 : 0 : if (live_subregs[allocnum] == NULL)
4266 : 0 : live_subregs[allocnum] = sbitmap_alloc (size);
4267 : :
4268 : : /* If the entire reg was live before blasting into subregs, we need
4269 : : to init all of the subregs to ones else init to 0. */
4270 : 0 : if (init_value)
4271 : 0 : bitmap_ones (live_subregs[allocnum]);
4272 : : else
4273 : 0 : bitmap_clear (live_subregs[allocnum]);
4274 : :
4275 : 0 : bitmap_set_bit (live_subregs_used, allocnum);
4276 : : }
4277 : :
4278 : : /* Walk the insns of the current function and build reload_insn_chain,
4279 : : and record register life information. */
4280 : : static void
4281 : 0 : build_insn_chain (void)
4282 : : {
4283 : 0 : unsigned int i;
4284 : 0 : class insn_chain **p = &reload_insn_chain;
4285 : 0 : basic_block bb;
4286 : 0 : class insn_chain *c = NULL;
4287 : 0 : class insn_chain *next = NULL;
4288 : 0 : auto_bitmap live_relevant_regs;
4289 : 0 : auto_bitmap elim_regset;
4290 : : /* live_subregs is a vector used to keep accurate information about
4291 : : which hardregs are live in multiword pseudos. live_subregs and
4292 : : live_subregs_used are indexed by pseudo number. The live_subreg
4293 : : entry for a particular pseudo is only used if the corresponding
4294 : : element is non zero in live_subregs_used. The sbitmap size of
4295 : : live_subreg[allocno] is number of bytes that the pseudo can
4296 : : occupy. */
4297 : 0 : sbitmap *live_subregs = XCNEWVEC (sbitmap, max_regno);
4298 : 0 : auto_bitmap live_subregs_used;
4299 : :
4300 : 0 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4301 : 0 : if (TEST_HARD_REG_BIT (eliminable_regset, i))
4302 : 0 : bitmap_set_bit (elim_regset, i);
4303 : 0 : FOR_EACH_BB_REVERSE_FN (bb, cfun)
4304 : : {
4305 : 0 : bitmap_iterator bi;
4306 : 0 : rtx_insn *insn;
4307 : :
4308 : 0 : CLEAR_REG_SET (live_relevant_regs);
4309 : 0 : bitmap_clear (live_subregs_used);
4310 : :
4311 : 0 : EXECUTE_IF_SET_IN_BITMAP (df_get_live_out (bb), 0, i, bi)
4312 : : {
4313 : 0 : if (i >= FIRST_PSEUDO_REGISTER)
4314 : : break;
4315 : 0 : bitmap_set_bit (live_relevant_regs, i);
4316 : : }
4317 : :
4318 : 0 : EXECUTE_IF_SET_IN_BITMAP (df_get_live_out (bb),
4319 : : FIRST_PSEUDO_REGISTER, i, bi)
4320 : : {
4321 : 0 : if (pseudo_for_reload_consideration_p (i))
4322 : 0 : bitmap_set_bit (live_relevant_regs, i);
4323 : : }
4324 : :
4325 : 0 : FOR_BB_INSNS_REVERSE (bb, insn)
4326 : : {
4327 : 0 : if (!NOTE_P (insn) && !BARRIER_P (insn))
4328 : : {
4329 : 0 : struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
4330 : 0 : df_ref def, use;
4331 : :
4332 : 0 : c = new_insn_chain ();
4333 : 0 : c->next = next;
4334 : 0 : next = c;
4335 : 0 : *p = c;
4336 : 0 : p = &c->prev;
4337 : :
4338 : 0 : c->insn = insn;
4339 : 0 : c->block = bb->index;
4340 : :
4341 : 0 : if (NONDEBUG_INSN_P (insn))
4342 : 0 : FOR_EACH_INSN_INFO_DEF (def, insn_info)
4343 : : {
4344 : 0 : unsigned int regno = DF_REF_REGNO (def);
4345 : :
4346 : : /* Ignore may clobbers because these are generated
4347 : : from calls. However, every other kind of def is
4348 : : added to dead_or_set. */
4349 : 0 : if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
4350 : : {
4351 : 0 : if (regno < FIRST_PSEUDO_REGISTER)
4352 : : {
4353 : 0 : if (!fixed_regs[regno])
4354 : 0 : bitmap_set_bit (&c->dead_or_set, regno);
4355 : : }
4356 : 0 : else if (pseudo_for_reload_consideration_p (regno))
4357 : 0 : bitmap_set_bit (&c->dead_or_set, regno);
4358 : : }
4359 : :
4360 : 0 : if ((regno < FIRST_PSEUDO_REGISTER
4361 : 0 : || reg_renumber[regno] >= 0
4362 : 0 : || ira_conflicts_p)
4363 : 0 : && (!DF_REF_FLAGS_IS_SET (def, DF_REF_CONDITIONAL)))
4364 : : {
4365 : 0 : rtx reg = DF_REF_REG (def);
4366 : 0 : HOST_WIDE_INT outer_size, inner_size, start;
4367 : :
4368 : : /* We can usually track the liveness of individual
4369 : : bytes within a subreg. The only exceptions are
4370 : : subregs wrapped in ZERO_EXTRACTs and subregs whose
4371 : : size is not known; in those cases we need to be
4372 : : conservative and treat the definition as a partial
4373 : : definition of the full register rather than a full
4374 : : definition of a specific part of the register. */
4375 : 0 : if (GET_CODE (reg) == SUBREG
4376 : 0 : && !DF_REF_FLAGS_IS_SET (def, DF_REF_ZERO_EXTRACT)
4377 : 0 : && get_subreg_tracking_sizes (reg, &outer_size,
4378 : : &inner_size, &start))
4379 : : {
4380 : 0 : HOST_WIDE_INT last = start + outer_size;
4381 : :
4382 : 0 : init_live_subregs
4383 : 0 : (bitmap_bit_p (live_relevant_regs, regno),
4384 : : live_subregs, live_subregs_used, regno,
4385 : : inner_size);
4386 : :
4387 : 0 : if (!DF_REF_FLAGS_IS_SET
4388 : : (def, DF_REF_STRICT_LOW_PART))
4389 : : {
4390 : : /* Expand the range to cover entire words.
4391 : : Bytes added here are "don't care". */
4392 : 0 : start
4393 : 0 : = start / UNITS_PER_WORD * UNITS_PER_WORD;
4394 : 0 : last = ((last + UNITS_PER_WORD - 1)
4395 : 0 : / UNITS_PER_WORD * UNITS_PER_WORD);
4396 : : }
4397 : :
4398 : : /* Ignore the paradoxical bits. */
4399 : 0 : if (last > SBITMAP_SIZE (live_subregs[regno]))
4400 : : last = SBITMAP_SIZE (live_subregs[regno]);
4401 : :
4402 : 0 : while (start < last)
4403 : : {
4404 : 0 : bitmap_clear_bit (live_subregs[regno], start);
4405 : 0 : start++;
4406 : : }
4407 : :
4408 : 0 : if (bitmap_empty_p (live_subregs[regno]))
4409 : : {
4410 : 0 : bitmap_clear_bit (live_subregs_used, regno);
4411 : 0 : bitmap_clear_bit (live_relevant_regs, regno);
4412 : : }
4413 : : else
4414 : : /* Set live_relevant_regs here because
4415 : : that bit has to be true to get us to
4416 : : look at the live_subregs fields. */
4417 : 0 : bitmap_set_bit (live_relevant_regs, regno);
4418 : : }
4419 : : else
4420 : : {
4421 : : /* DF_REF_PARTIAL is generated for
4422 : : subregs, STRICT_LOW_PART, and
4423 : : ZERO_EXTRACT. We handle the subreg
4424 : : case above so here we have to keep from
4425 : : modeling the def as a killing def. */
4426 : 0 : if (!DF_REF_FLAGS_IS_SET (def, DF_REF_PARTIAL))
4427 : : {
4428 : 0 : bitmap_clear_bit (live_subregs_used, regno);
4429 : 0 : bitmap_clear_bit (live_relevant_regs, regno);
4430 : : }
4431 : : }
4432 : : }
4433 : : }
4434 : :
4435 : 0 : bitmap_and_compl_into (live_relevant_regs, elim_regset);
4436 : 0 : bitmap_copy (&c->live_throughout, live_relevant_regs);
4437 : :
4438 : 0 : if (NONDEBUG_INSN_P (insn))
4439 : 0 : FOR_EACH_INSN_INFO_USE (use, insn_info)
4440 : : {
4441 : 0 : unsigned int regno = DF_REF_REGNO (use);
4442 : 0 : rtx reg = DF_REF_REG (use);
4443 : :
4444 : : /* DF_REF_READ_WRITE on a use means that this use
4445 : : is fabricated from a def that is a partial set
4446 : : to a multiword reg. Here, we only model the
4447 : : subreg case that is not wrapped in ZERO_EXTRACT
4448 : : precisely so we do not need to look at the
4449 : : fabricated use. */
4450 : 0 : if (DF_REF_FLAGS_IS_SET (use, DF_REF_READ_WRITE)
4451 : 0 : && !DF_REF_FLAGS_IS_SET (use, DF_REF_ZERO_EXTRACT)
4452 : 0 : && DF_REF_FLAGS_IS_SET (use, DF_REF_SUBREG))
4453 : 0 : continue;
4454 : :
4455 : : /* Add the last use of each var to dead_or_set. */
4456 : 0 : if (!bitmap_bit_p (live_relevant_regs, regno))
4457 : : {
4458 : 0 : if (regno < FIRST_PSEUDO_REGISTER)
4459 : : {
4460 : 0 : if (!fixed_regs[regno])
4461 : 0 : bitmap_set_bit (&c->dead_or_set, regno);
4462 : : }
4463 : 0 : else if (pseudo_for_reload_consideration_p (regno))
4464 : 0 : bitmap_set_bit (&c->dead_or_set, regno);
4465 : : }
4466 : :
4467 : 0 : if (regno < FIRST_PSEUDO_REGISTER
4468 : 0 : || pseudo_for_reload_consideration_p (regno))
4469 : : {
4470 : 0 : HOST_WIDE_INT outer_size, inner_size, start;
4471 : 0 : if (GET_CODE (reg) == SUBREG
4472 : 0 : && !DF_REF_FLAGS_IS_SET (use,
4473 : : DF_REF_SIGN_EXTRACT
4474 : : | DF_REF_ZERO_EXTRACT)
4475 : 0 : && get_subreg_tracking_sizes (reg, &outer_size,
4476 : : &inner_size, &start))
4477 : : {
4478 : 0 : HOST_WIDE_INT last = start + outer_size;
4479 : :
4480 : 0 : init_live_subregs
4481 : 0 : (bitmap_bit_p (live_relevant_regs, regno),
4482 : : live_subregs, live_subregs_used, regno,
4483 : : inner_size);
4484 : :
4485 : : /* Ignore the paradoxical bits. */
4486 : 0 : if (last > SBITMAP_SIZE (live_subregs[regno]))
4487 : : last = SBITMAP_SIZE (live_subregs[regno]);
4488 : :
4489 : 0 : while (start < last)
4490 : : {
4491 : 0 : bitmap_set_bit (live_subregs[regno], start);
4492 : 0 : start++;
4493 : : }
4494 : : }
4495 : : else
4496 : : /* Resetting the live_subregs_used is
4497 : : effectively saying do not use the subregs
4498 : : because we are reading the whole
4499 : : pseudo. */
4500 : 0 : bitmap_clear_bit (live_subregs_used, regno);
4501 : 0 : bitmap_set_bit (live_relevant_regs, regno);
4502 : : }
4503 : : }
4504 : : }
4505 : : }
4506 : :
4507 : : /* FIXME!! The following code is a disaster. Reload needs to see the
4508 : : labels and jump tables that are just hanging out in between
4509 : : the basic blocks. See pr33676. */
4510 : 0 : insn = BB_HEAD (bb);
4511 : :
4512 : : /* Skip over the barriers and cruft. */
4513 : 0 : while (insn && (BARRIER_P (insn) || NOTE_P (insn)
4514 : 0 : || BLOCK_FOR_INSN (insn) == bb))
4515 : 0 : insn = PREV_INSN (insn);
4516 : :
4517 : : /* While we add anything except barriers and notes, the focus is
4518 : : to get the labels and jump tables into the
4519 : : reload_insn_chain. */
4520 : 0 : while (insn)
4521 : : {
4522 : 0 : if (!NOTE_P (insn) && !BARRIER_P (insn))
4523 : : {
4524 : 0 : if (BLOCK_FOR_INSN (insn))
4525 : : break;
4526 : :
4527 : 0 : c = new_insn_chain ();
4528 : 0 : c->next = next;
4529 : 0 : next = c;
4530 : 0 : *p = c;
4531 : 0 : p = &c->prev;
4532 : :
4533 : : /* The block makes no sense here, but it is what the old
4534 : : code did. */
4535 : 0 : c->block = bb->index;
4536 : 0 : c->insn = insn;
4537 : 0 : bitmap_copy (&c->live_throughout, live_relevant_regs);
4538 : : }
4539 : 0 : insn = PREV_INSN (insn);
4540 : : }
4541 : : }
4542 : :
4543 : 0 : reload_insn_chain = c;
4544 : 0 : *p = NULL;
4545 : :
4546 : 0 : for (i = 0; i < (unsigned int) max_regno; i++)
4547 : 0 : if (live_subregs[i] != NULL)
4548 : 0 : sbitmap_free (live_subregs[i]);
4549 : 0 : free (live_subregs);
4550 : :
4551 : 0 : if (dump_file)
4552 : 0 : print_insn_chains (dump_file);
4553 : 0 : }
4554 : :
4555 : : /* Examine the rtx found in *LOC, which is read or written to as determined
4556 : : by TYPE. Return false if we find a reason why an insn containing this
4557 : : rtx should not be moved (such as accesses to non-constant memory), true
4558 : : otherwise. */
4559 : : static bool
4560 : 6496782 : rtx_moveable_p (rtx *loc, enum op_type type)
4561 : : {
4562 : 6503618 : const char *fmt;
4563 : 6503618 : rtx x = *loc;
4564 : 6503618 : int i, j;
4565 : :
4566 : 6503618 : enum rtx_code code = GET_CODE (x);
4567 : 6503618 : switch (code)
4568 : : {
4569 : : case CONST:
4570 : : CASE_CONST_ANY:
4571 : : case SYMBOL_REF:
4572 : : case LABEL_REF:
4573 : : return true;
4574 : :
4575 : 0 : case PC:
4576 : 0 : return type == OP_IN;
4577 : :
4578 : 2316920 : case REG:
4579 : 2316920 : if (x == frame_pointer_rtx)
4580 : : return true;
4581 : 2315470 : if (HARD_REGISTER_P (x))
4582 : : return false;
4583 : :
4584 : : return true;
4585 : :
4586 : 582173 : case MEM:
4587 : 582173 : if (type == OP_IN && MEM_READONLY_P (x))
4588 : 6766 : return rtx_moveable_p (&XEXP (x, 0), OP_IN);
4589 : : return false;
4590 : :
4591 : 2009767 : case SET:
4592 : 2009767 : return (rtx_moveable_p (&SET_SRC (x), OP_IN)
4593 : 2009767 : && rtx_moveable_p (&SET_DEST (x), OP_OUT));
4594 : :
4595 : 5 : case STRICT_LOW_PART:
4596 : 5 : return rtx_moveable_p (&XEXP (x, 0), OP_OUT);
4597 : :
4598 : 632 : case ZERO_EXTRACT:
4599 : 632 : case SIGN_EXTRACT:
4600 : 632 : return (rtx_moveable_p (&XEXP (x, 0), type)
4601 : 632 : && rtx_moveable_p (&XEXP (x, 1), OP_IN)
4602 : 1264 : && rtx_moveable_p (&XEXP (x, 2), OP_IN));
4603 : :
4604 : 65 : case CLOBBER:
4605 : 65 : return rtx_moveable_p (&SET_DEST (x), OP_OUT);
4606 : :
4607 : : case UNSPEC_VOLATILE:
4608 : : /* It is a bad idea to consider insns with such rtl
4609 : : as moveable ones. The insn scheduler also considers them as barrier
4610 : : for a reason. */
4611 : : return false;
4612 : :
4613 : 0 : case ASM_OPERANDS:
4614 : : /* The same is true for volatile asm: it has unknown side effects, it
4615 : : cannot be moved at will. */
4616 : 0 : if (MEM_VOLATILE_P (x))
4617 : : return false;
4618 : :
4619 : 1058216 : default:
4620 : 1058216 : break;
4621 : : }
4622 : :
4623 : 1058216 : fmt = GET_RTX_FORMAT (code);
4624 : 2742311 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4625 : : {
4626 : 1839561 : if (fmt[i] == 'e')
4627 : : {
4628 : 1439492 : if (!rtx_moveable_p (&XEXP (x, i), type))
4629 : : return false;
4630 : : }
4631 : 400069 : else if (fmt[i] == 'E')
4632 : 525361 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
4633 : : {
4634 : 405535 : if (!rtx_moveable_p (&XVECEXP (x, i, j), type))
4635 : : return false;
4636 : : }
4637 : : }
4638 : : return true;
4639 : : }
4640 : :
4641 : : /* A wrapper around dominated_by_p, which uses the information in UID_LUID
4642 : : to give dominance relationships between two insns I1 and I2. */
4643 : : static bool
4644 : 19735023 : insn_dominated_by_p (rtx i1, rtx i2, int *uid_luid)
4645 : : {
4646 : 19735023 : basic_block bb1 = BLOCK_FOR_INSN (i1);
4647 : 19735023 : basic_block bb2 = BLOCK_FOR_INSN (i2);
4648 : :
4649 : 19735023 : if (bb1 == bb2)
4650 : 10646877 : return uid_luid[INSN_UID (i2)] < uid_luid[INSN_UID (i1)];
4651 : 9088146 : return dominated_by_p (CDI_DOMINATORS, bb1, bb2);
4652 : : }
4653 : :
4654 : : /* Record the range of register numbers added by find_moveable_pseudos. */
4655 : : int first_moveable_pseudo, last_moveable_pseudo;
4656 : :
4657 : : /* These two vectors hold data for every register added by
4658 : : find_movable_pseudos, with index 0 holding data for the
4659 : : first_moveable_pseudo. */
4660 : : /* The original home register. */
4661 : : static vec<rtx> pseudo_replaced_reg;
4662 : :
4663 : : /* Look for instances where we have an instruction that is known to increase
4664 : : register pressure, and whose result is not used immediately. If it is
4665 : : possible to move the instruction downwards to just before its first use,
4666 : : split its lifetime into two ranges. We create a new pseudo to compute the
4667 : : value, and emit a move instruction just before the first use. If, after
4668 : : register allocation, the new pseudo remains unallocated, the function
4669 : : move_unallocated_pseudos then deletes the move instruction and places
4670 : : the computation just before the first use.
4671 : :
4672 : : Such a move is safe and profitable if all the input registers remain live
4673 : : and unchanged between the original computation and its first use. In such
4674 : : a situation, the computation is known to increase register pressure, and
4675 : : moving it is known to at least not worsen it.
4676 : :
4677 : : We restrict moves to only those cases where a register remains unallocated,
4678 : : in order to avoid interfering too much with the instruction schedule. As
4679 : : an exception, we may move insns which only modify their input register
4680 : : (typically induction variables), as this increases the freedom for our
4681 : : intended transformation, and does not limit the second instruction
4682 : : scheduler pass. */
4683 : :
4684 : : static void
4685 : 1008570 : find_moveable_pseudos (void)
4686 : : {
4687 : 1008570 : unsigned i;
4688 : 1008570 : int max_regs = max_reg_num ();
4689 : 1008570 : int max_uid = get_max_uid ();
4690 : 1008570 : basic_block bb;
4691 : 1008570 : int *uid_luid = XNEWVEC (int, max_uid);
4692 : 1008570 : rtx_insn **closest_uses = XNEWVEC (rtx_insn *, max_regs);
4693 : : /* A set of registers which are live but not modified throughout a block. */
4694 : 1008570 : bitmap_head *bb_transp_live = XNEWVEC (bitmap_head,
4695 : : last_basic_block_for_fn (cfun));
4696 : : /* A set of registers which only exist in a given basic block. */
4697 : 1008570 : bitmap_head *bb_local = XNEWVEC (bitmap_head,
4698 : : last_basic_block_for_fn (cfun));
4699 : : /* A set of registers which are set once, in an instruction that can be
4700 : : moved freely downwards, but are otherwise transparent to a block. */
4701 : 1008570 : bitmap_head *bb_moveable_reg_sets = XNEWVEC (bitmap_head,
4702 : : last_basic_block_for_fn (cfun));
4703 : 1008570 : auto_bitmap live, used, set, interesting, unusable_as_input;
4704 : 1008570 : bitmap_iterator bi;
4705 : :
4706 : 1008570 : first_moveable_pseudo = max_regs;
4707 : 1008570 : pseudo_replaced_reg.release ();
4708 : 1008570 : pseudo_replaced_reg.safe_grow_cleared (max_regs, true);
4709 : :
4710 : 1008570 : df_analyze ();
4711 : 1008570 : calculate_dominance_info (CDI_DOMINATORS);
4712 : :
4713 : 1008570 : i = 0;
4714 : 11378215 : FOR_EACH_BB_FN (bb, cfun)
4715 : : {
4716 : 10369645 : rtx_insn *insn;
4717 : 10369645 : bitmap transp = bb_transp_live + bb->index;
4718 : 10369645 : bitmap moveable = bb_moveable_reg_sets + bb->index;
4719 : 10369645 : bitmap local = bb_local + bb->index;
4720 : :
4721 : 10369645 : bitmap_initialize (local, 0);
4722 : 10369645 : bitmap_initialize (transp, 0);
4723 : 10369645 : bitmap_initialize (moveable, 0);
4724 : 10369645 : bitmap_copy (live, df_get_live_out (bb));
4725 : 10369645 : bitmap_and_into (live, df_get_live_in (bb));
4726 : 10369645 : bitmap_copy (transp, live);
4727 : 10369645 : bitmap_clear (moveable);
4728 : 10369645 : bitmap_clear (live);
4729 : 10369645 : bitmap_clear (used);
4730 : 10369645 : bitmap_clear (set);
4731 : 128213048 : FOR_BB_INSNS (bb, insn)
4732 : 117843403 : if (NONDEBUG_INSN_P (insn))
4733 : : {
4734 : 55766656 : df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
4735 : 55766656 : df_ref def, use;
4736 : :
4737 : 55766656 : uid_luid[INSN_UID (insn)] = i++;
4738 : :
4739 : 55766656 : def = df_single_def (insn_info);
4740 : 55766656 : use = df_single_use (insn_info);
4741 : 55766656 : if (use
4742 : 55766656 : && def
4743 : 18373290 : && DF_REF_REGNO (use) == DF_REF_REGNO (def)
4744 : 597755 : && !bitmap_bit_p (set, DF_REF_REGNO (use))
4745 : 55841637 : && rtx_moveable_p (&PATTERN (insn), OP_IN))
4746 : : {
4747 : 31099 : unsigned regno = DF_REF_REGNO (use);
4748 : 31099 : bitmap_set_bit (moveable, regno);
4749 : 31099 : bitmap_set_bit (set, regno);
4750 : 31099 : bitmap_set_bit (used, regno);
4751 : 31099 : bitmap_clear_bit (transp, regno);
4752 : 31099 : continue;
4753 : 31099 : }
4754 : 123717690 : FOR_EACH_INSN_INFO_USE (use, insn_info)
4755 : : {
4756 : 67982133 : unsigned regno = DF_REF_REGNO (use);
4757 : 67982133 : bitmap_set_bit (used, regno);
4758 : 67982133 : if (bitmap_clear_bit (moveable, regno))
4759 : 15934 : bitmap_clear_bit (transp, regno);
4760 : : }
4761 : :
4762 : 467325022 : FOR_EACH_INSN_INFO_DEF (def, insn_info)
4763 : : {
4764 : 411589465 : unsigned regno = DF_REF_REGNO (def);
4765 : 411589465 : bitmap_set_bit (set, regno);
4766 : 411589465 : bitmap_clear_bit (transp, regno);
4767 : 411589465 : bitmap_clear_bit (moveable, regno);
4768 : : }
4769 : : }
4770 : : }
4771 : :
4772 : 11378215 : FOR_EACH_BB_FN (bb, cfun)
4773 : : {
4774 : 10369645 : bitmap local = bb_local + bb->index;
4775 : 10369645 : rtx_insn *insn;
4776 : :
4777 : 128213048 : FOR_BB_INSNS (bb, insn)
4778 : 117843403 : if (NONDEBUG_INSN_P (insn))
4779 : : {
4780 : 55766656 : df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
4781 : 55766656 : rtx_insn *def_insn;
4782 : 55766656 : rtx closest_use, note;
4783 : 55766656 : df_ref def, use;
4784 : 55766656 : unsigned regno;
4785 : 55766656 : bool all_dominated, all_local;
4786 : 55766656 : machine_mode mode;
4787 : :
4788 : 55766656 : def = df_single_def (insn_info);
4789 : : /* There must be exactly one def in this insn. */
4790 : 30680054 : if (!def || !single_set (insn))
4791 : 25166066 : continue;
4792 : : /* This must be the only definition of the reg. We also limit
4793 : : which modes we deal with so that we can assume we can generate
4794 : : move instructions. */
4795 : 30600590 : regno = DF_REF_REGNO (def);
4796 : 30600590 : mode = GET_MODE (DF_REF_REG (def));
4797 : 30600590 : if (DF_REG_DEF_COUNT (regno) != 1
4798 : 11590380 : || !DF_REF_INSN_INFO (def)
4799 : 11590380 : || HARD_REGISTER_NUM_P (regno)
4800 : 11559801 : || DF_REG_EQ_USE_COUNT (regno) > 0
4801 : 11064808 : || (!INTEGRAL_MODE_P (mode)
4802 : : && !FLOAT_MODE_P (mode)
4803 : : && !OPAQUE_MODE_P (mode)))
4804 : 19535782 : continue;
4805 : 11064808 : def_insn = DF_REF_INSN (def);
4806 : :
4807 : 18751661 : for (note = REG_NOTES (def_insn); note; note = XEXP (note, 1))
4808 : 10120279 : if (REG_NOTE_KIND (note) == REG_EQUIV && MEM_P (XEXP (note, 0)))
4809 : : break;
4810 : :
4811 : 11064808 : if (note)
4812 : : {
4813 : 2433426 : if (dump_file)
4814 : 68 : fprintf (dump_file, "Ignoring reg %d, has equiv memory\n",
4815 : : regno);
4816 : 2433426 : bitmap_set_bit (unusable_as_input, regno);
4817 : 2433426 : continue;
4818 : : }
4819 : :
4820 : 8631382 : use = DF_REG_USE_CHAIN (regno);
4821 : 8631382 : all_dominated = true;
4822 : 8631382 : all_local = true;
4823 : 8631382 : closest_use = NULL_RTX;
4824 : 24897538 : for (; use; use = DF_REF_NEXT_REG (use))
4825 : : {
4826 : 16266156 : rtx_insn *insn;
4827 : 16266156 : if (!DF_REF_INSN_INFO (use))
4828 : : {
4829 : : all_dominated = false;
4830 : : all_local = false;
4831 : : break;
4832 : : }
4833 : 16266156 : insn = DF_REF_INSN (use);
4834 : 16266156 : if (DEBUG_INSN_P (insn))
4835 : 1915620 : continue;
4836 : 14350536 : if (BLOCK_FOR_INSN (insn) != BLOCK_FOR_INSN (def_insn))
4837 : 5510959 : all_local = false;
4838 : 14350536 : if (!insn_dominated_by_p (insn, def_insn, uid_luid))
4839 : 8917 : all_dominated = false;
4840 : 14350536 : if (closest_use != insn && closest_use != const0_rtx)
4841 : : {
4842 : 12735874 : if (closest_use == NULL_RTX)
4843 : : closest_use = insn;
4844 : 4162905 : else if (insn_dominated_by_p (closest_use, insn, uid_luid))
4845 : : closest_use = insn;
4846 : 1221582 : else if (!insn_dominated_by_p (insn, closest_use, uid_luid))
4847 : 571218 : closest_use = const0_rtx;
4848 : : }
4849 : : }
4850 : 8631382 : if (!all_dominated)
4851 : : {
4852 : 4546 : if (dump_file)
4853 : 0 : fprintf (dump_file, "Reg %d not all uses dominated by set\n",
4854 : : regno);
4855 : 4546 : continue;
4856 : : }
4857 : 8626836 : if (all_local)
4858 : 6235810 : bitmap_set_bit (local, regno);
4859 : 8057272 : if (closest_use == const0_rtx || closest_use == NULL
4860 : 16625695 : || next_nonnote_nondebug_insn (def_insn) == closest_use)
4861 : : {
4862 : 5442338 : if (dump_file)
4863 : 93 : fprintf (dump_file, "Reg %d uninteresting%s\n", regno,
4864 : 93 : closest_use == const0_rtx || closest_use == NULL
4865 : : ? " (no unique first use)" : "");
4866 : 5442338 : continue;
4867 : : }
4868 : :
4869 : 3184498 : bitmap_set_bit (interesting, regno);
4870 : : /* If we get here, we know closest_use is a non-NULL insn
4871 : : (as opposed to const_0_rtx). */
4872 : 3184498 : closest_uses[regno] = as_a <rtx_insn *> (closest_use);
4873 : :
4874 : 3184498 : if (dump_file && (all_local || all_dominated))
4875 : : {
4876 : 78 : fprintf (dump_file, "Reg %u:", regno);
4877 : 78 : if (all_local)
4878 : 14 : fprintf (dump_file, " local to bb %d", bb->index);
4879 : 78 : if (all_dominated)
4880 : 78 : fprintf (dump_file, " def dominates all uses");
4881 : 78 : if (closest_use != const0_rtx)
4882 : 78 : fprintf (dump_file, " has unique first use");
4883 : 78 : fputs ("\n", dump_file);
4884 : : }
4885 : : }
4886 : : }
4887 : :
4888 : 4193068 : EXECUTE_IF_SET_IN_BITMAP (interesting, 0, i, bi)
4889 : : {
4890 : 3184498 : df_ref def = DF_REG_DEF_CHAIN (i);
4891 : 3184498 : rtx_insn *def_insn = DF_REF_INSN (def);
4892 : 3184498 : basic_block def_block = BLOCK_FOR_INSN (def_insn);
4893 : 3184498 : bitmap def_bb_local = bb_local + def_block->index;
4894 : 3184498 : bitmap def_bb_moveable = bb_moveable_reg_sets + def_block->index;
4895 : 3184498 : bitmap def_bb_transp = bb_transp_live + def_block->index;
4896 : 3184498 : bool local_to_bb_p = bitmap_bit_p (def_bb_local, i);
4897 : 3184498 : rtx_insn *use_insn = closest_uses[i];
4898 : 3184498 : df_ref use;
4899 : 3184498 : bool all_ok = true;
4900 : 3184498 : bool all_transp = true;
4901 : :
4902 : 3184498 : if (!REG_P (DF_REF_REG (def)))
4903 : 40381 : continue;
4904 : :
4905 : 3144117 : if (!local_to_bb_p)
4906 : : {
4907 : 1162164 : if (dump_file)
4908 : 64 : fprintf (dump_file, "Reg %u not local to one basic block\n",
4909 : : i);
4910 : 1162164 : continue;
4911 : : }
4912 : 1981953 : if (reg_equiv_init (i) != NULL_RTX)
4913 : : {
4914 : 47135 : if (dump_file)
4915 : 0 : fprintf (dump_file, "Ignoring reg %u with equiv init insn\n",
4916 : : i);
4917 : 47135 : continue;
4918 : : }
4919 : 1934818 : if (!rtx_moveable_p (&PATTERN (def_insn), OP_IN))
4920 : : {
4921 : 1349216 : if (dump_file)
4922 : 14 : fprintf (dump_file, "Found def insn %d for %d to be not moveable\n",
4923 : 14 : INSN_UID (def_insn), i);
4924 : 1349216 : continue;
4925 : : }
4926 : 585602 : if (dump_file)
4927 : 0 : fprintf (dump_file, "Examining insn %d, def for %d\n",
4928 : 0 : INSN_UID (def_insn), i);
4929 : 1316361 : FOR_EACH_INSN_USE (use, def_insn)
4930 : : {
4931 : 789791 : unsigned regno = DF_REF_REGNO (use);
4932 : 789791 : if (bitmap_bit_p (unusable_as_input, regno))
4933 : : {
4934 : 59032 : all_ok = false;
4935 : 59032 : if (dump_file)
4936 : 0 : fprintf (dump_file, " found unusable input reg %u.\n", regno);
4937 : : break;
4938 : : }
4939 : 730759 : if (!bitmap_bit_p (def_bb_transp, regno))
4940 : : {
4941 : 681177 : if (bitmap_bit_p (def_bb_moveable, regno)
4942 : 681177 : && !control_flow_insn_p (use_insn))
4943 : : {
4944 : 22 : if (modified_between_p (DF_REF_REG (use), def_insn, use_insn))
4945 : : {
4946 : 0 : rtx_insn *x = NEXT_INSN (def_insn);
4947 : 0 : while (!modified_in_p (DF_REF_REG (use), x))
4948 : : {
4949 : 0 : gcc_assert (x != use_insn);
4950 : 0 : x = NEXT_INSN (x);
4951 : : }
4952 : 0 : if (dump_file)
4953 : 0 : fprintf (dump_file, " input reg %u modified but insn %d moveable\n",
4954 : 0 : regno, INSN_UID (x));
4955 : 0 : emit_insn_after (PATTERN (x), use_insn);
4956 : 0 : set_insn_deleted (x);
4957 : : }
4958 : : else
4959 : : {
4960 : 22 : if (dump_file)
4961 : 0 : fprintf (dump_file, " input reg %u modified between def and use\n",
4962 : : regno);
4963 : : all_transp = false;
4964 : : }
4965 : : }
4966 : : else
4967 : : all_transp = false;
4968 : : }
4969 : : }
4970 : 0 : if (!all_ok)
4971 : 59032 : continue;
4972 : 526570 : if (!dbg_cnt (ira_move))
4973 : : break;
4974 : 526570 : if (dump_file)
4975 : 0 : fprintf (dump_file, " all ok%s\n", all_transp ? " and transp" : "");
4976 : :
4977 : 526570 : if (all_transp)
4978 : : {
4979 : 13353 : rtx def_reg = DF_REF_REG (def);
4980 : 13353 : rtx newreg = ira_create_new_reg (def_reg);
4981 : 13353 : if (validate_change (def_insn, DF_REF_REAL_LOC (def), newreg, 0))
4982 : : {
4983 : 13353 : unsigned nregno = REGNO (newreg);
4984 : 13353 : emit_insn_before (gen_move_insn (def_reg, newreg), use_insn);
4985 : 13353 : nregno -= max_regs;
4986 : 13353 : pseudo_replaced_reg[nregno] = def_reg;
4987 : : }
4988 : : }
4989 : : }
4990 : :
4991 : 11378215 : FOR_EACH_BB_FN (bb, cfun)
4992 : : {
4993 : 10369645 : bitmap_clear (bb_local + bb->index);
4994 : 10369645 : bitmap_clear (bb_transp_live + bb->index);
4995 : 10369645 : bitmap_clear (bb_moveable_reg_sets + bb->index);
4996 : : }
4997 : 1008570 : free (uid_luid);
4998 : 1008570 : free (closest_uses);
4999 : 1008570 : free (bb_local);
5000 : 1008570 : free (bb_transp_live);
5001 : 1008570 : free (bb_moveable_reg_sets);
5002 : :
5003 : 1008570 : last_moveable_pseudo = max_reg_num ();
5004 : :
5005 : 1008570 : fix_reg_equiv_init ();
5006 : 1008570 : expand_reg_info ();
5007 : 1008570 : regstat_free_n_sets_and_refs ();
5008 : 1008570 : regstat_free_ri ();
5009 : 1008570 : regstat_init_n_sets_and_refs ();
5010 : 1008570 : regstat_compute_ri ();
5011 : 1008570 : free_dominance_info (CDI_DOMINATORS);
5012 : 1008570 : }
5013 : :
5014 : : /* If SET pattern SET is an assignment from a hard register to a pseudo which
5015 : : is live at CALL_DOM (if non-NULL, otherwise this check is omitted), return
5016 : : the destination. Otherwise return NULL. */
5017 : :
5018 : : static rtx
5019 : 2048294 : interesting_dest_for_shprep_1 (rtx set, basic_block call_dom)
5020 : : {
5021 : 2048294 : rtx src = SET_SRC (set);
5022 : 2048294 : rtx dest = SET_DEST (set);
5023 : 678459 : if (!REG_P (src) || !HARD_REGISTER_P (src)
5024 : 539930 : || !REG_P (dest) || HARD_REGISTER_P (dest)
5025 : 2569491 : || (call_dom && !bitmap_bit_p (df_get_live_in (call_dom), REGNO (dest))))
5026 : 1613526 : return NULL;
5027 : : return dest;
5028 : : }
5029 : :
5030 : : /* If insn is interesting for parameter range-splitting shrink-wrapping
5031 : : preparation, i.e. it is a single set from a hard register to a pseudo, which
5032 : : is live at CALL_DOM (if non-NULL, otherwise this check is omitted), or a
5033 : : parallel statement with only one such statement, return the destination.
5034 : : Otherwise return NULL. */
5035 : :
5036 : : static rtx
5037 : 4204443 : interesting_dest_for_shprep (rtx_insn *insn, basic_block call_dom)
5038 : : {
5039 : 4204443 : if (!INSN_P (insn))
5040 : : return NULL;
5041 : 3353158 : rtx pat = PATTERN (insn);
5042 : 3353158 : if (GET_CODE (pat) == SET)
5043 : 1811642 : return interesting_dest_for_shprep_1 (pat, call_dom);
5044 : :
5045 : 1541516 : if (GET_CODE (pat) != PARALLEL)
5046 : : return NULL;
5047 : : rtx ret = NULL;
5048 : 615596 : for (int i = 0; i < XVECLEN (pat, 0); i++)
5049 : : {
5050 : 417664 : rtx sub = XVECEXP (pat, 0, i);
5051 : 417664 : if (GET_CODE (sub) == USE || GET_CODE (sub) == CLOBBER)
5052 : 174321 : continue;
5053 : 243343 : if (GET_CODE (sub) != SET
5054 : 243343 : || side_effects_p (sub))
5055 : 6691 : return NULL;
5056 : 236652 : rtx dest = interesting_dest_for_shprep_1 (sub, call_dom);
5057 : 236652 : if (dest && ret)
5058 : : return NULL;
5059 : 236652 : if (dest)
5060 : 410973 : ret = dest;
5061 : : }
5062 : : return ret;
5063 : : }
5064 : :
5065 : : /* Split live ranges of pseudos that are loaded from hard registers in the
5066 : : first BB in a BB that dominates all non-sibling call if such a BB can be
5067 : : found and is not in a loop. Return true if the function has made any
5068 : : changes. */
5069 : :
5070 : : static bool
5071 : 1008570 : split_live_ranges_for_shrink_wrap (void)
5072 : : {
5073 : 1008570 : basic_block bb, call_dom = NULL;
5074 : 1008570 : basic_block first = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
5075 : 1008570 : rtx_insn *insn, *last_interesting_insn = NULL;
5076 : 1008570 : auto_bitmap need_new, reachable;
5077 : 1008570 : vec<basic_block> queue;
5078 : :
5079 : 1008570 : if (!SHRINK_WRAPPING_ENABLED)
5080 : 128 : return false;
5081 : :
5082 : 1008442 : queue.create (n_basic_blocks_for_fn (cfun));
5083 : :
5084 : 7123727 : FOR_EACH_BB_FN (bb, cfun)
5085 : 69119518 : FOR_BB_INSNS (bb, insn)
5086 : 64331844 : if (CALL_P (insn) && !SIBLING_CALL_P (insn))
5087 : : {
5088 : 1722602 : if (bb == first)
5089 : : {
5090 : 394991 : queue.release ();
5091 : 394991 : return false;
5092 : : }
5093 : :
5094 : 1327611 : bitmap_set_bit (need_new, bb->index);
5095 : 1327611 : bitmap_set_bit (reachable, bb->index);
5096 : 1327611 : queue.quick_push (bb);
5097 : 1327611 : break;
5098 : : }
5099 : :
5100 : 613451 : if (queue.is_empty ())
5101 : : {
5102 : 364827 : queue.release ();
5103 : 364827 : return false;
5104 : : }
5105 : :
5106 : 3988561 : while (!queue.is_empty ())
5107 : : {
5108 : 3739937 : edge e;
5109 : 3739937 : edge_iterator ei;
5110 : :
5111 : 3739937 : bb = queue.pop ();
5112 : 8961202 : FOR_EACH_EDGE (e, ei, bb->succs)
5113 : 5221265 : if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)
5114 : 5221265 : && bitmap_set_bit (reachable, e->dest->index))
5115 : 2412326 : queue.quick_push (e->dest);
5116 : : }
5117 : 248624 : queue.release ();
5118 : :
5119 : 3772084 : FOR_BB_INSNS (first, insn)
5120 : : {
5121 : 3523728 : rtx dest = interesting_dest_for_shprep (insn, NULL);
5122 : 3523728 : if (!dest)
5123 : 3141023 : continue;
5124 : :
5125 : 382705 : if (DF_REG_DEF_COUNT (REGNO (dest)) > 1)
5126 : : return false;
5127 : :
5128 : 382437 : for (df_ref use = DF_REG_USE_CHAIN (REGNO(dest));
5129 : 2592539 : use;
5130 : 2210102 : use = DF_REF_NEXT_REG (use))
5131 : : {
5132 : 2210102 : int ubbi = DF_REF_BB (use)->index;
5133 : :
5134 : : /* Only non debug insns should be taken into account. */
5135 : 2210102 : if (NONDEBUG_INSN_P (DF_REF_INSN (use))
5136 : 2210102 : && bitmap_bit_p (reachable, ubbi))
5137 : 1058720 : bitmap_set_bit (need_new, ubbi);
5138 : : }
5139 : : last_interesting_insn = insn;
5140 : : }
5141 : :
5142 : 248356 : if (!last_interesting_insn)
5143 : : return false;
5144 : :
5145 : 176812 : call_dom = nearest_common_dominator_for_set (CDI_DOMINATORS, need_new);
5146 : 176812 : if (call_dom == first)
5147 : : return false;
5148 : :
5149 : 92245 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
5150 : 206678 : while (bb_loop_depth (call_dom) > 0)
5151 : 22188 : call_dom = get_immediate_dominator (CDI_DOMINATORS, call_dom);
5152 : 92245 : loop_optimizer_finalize ();
5153 : :
5154 : 92245 : if (call_dom == first)
5155 : : return false;
5156 : :
5157 : 80335 : calculate_dominance_info (CDI_POST_DOMINATORS);
5158 : 80335 : if (dominated_by_p (CDI_POST_DOMINATORS, first, call_dom))
5159 : : {
5160 : 7324 : free_dominance_info (CDI_POST_DOMINATORS);
5161 : 7324 : return false;
5162 : : }
5163 : 73011 : free_dominance_info (CDI_POST_DOMINATORS);
5164 : :
5165 : 73011 : if (dump_file)
5166 : 2 : fprintf (dump_file, "Will split live ranges of parameters at BB %i\n",
5167 : : call_dom->index);
5168 : :
5169 : 73011 : bool ret = false;
5170 : 731901 : FOR_BB_INSNS (first, insn)
5171 : : {
5172 : 680715 : rtx dest = interesting_dest_for_shprep (insn, call_dom);
5173 : 680715 : if (!dest || dest == pic_offset_table_rtx)
5174 : 628652 : continue;
5175 : :
5176 : 52063 : bool need_newreg = false;
5177 : 52063 : df_ref use, next;
5178 : 65842 : for (use = DF_REG_USE_CHAIN (REGNO (dest)); use; use = next)
5179 : : {
5180 : 65765 : rtx_insn *uin = DF_REF_INSN (use);
5181 : 65765 : next = DF_REF_NEXT_REG (use);
5182 : :
5183 : 65765 : if (DEBUG_INSN_P (uin))
5184 : 472 : continue;
5185 : :
5186 : 65293 : basic_block ubb = BLOCK_FOR_INSN (uin);
5187 : 65293 : if (ubb == call_dom
5188 : 65293 : || dominated_by_p (CDI_DOMINATORS, ubb, call_dom))
5189 : : {
5190 : : need_newreg = true;
5191 : : break;
5192 : : }
5193 : : }
5194 : :
5195 : 52063 : if (need_newreg)
5196 : : {
5197 : 51986 : rtx newreg = ira_create_new_reg (dest);
5198 : :
5199 : 390182 : for (use = DF_REG_USE_CHAIN (REGNO (dest)); use; use = next)
5200 : : {
5201 : 338196 : rtx_insn *uin = DF_REF_INSN (use);
5202 : 338196 : next = DF_REF_NEXT_REG (use);
5203 : :
5204 : 338196 : basic_block ubb = BLOCK_FOR_INSN (uin);
5205 : 338196 : if (ubb == call_dom
5206 : 338196 : || dominated_by_p (CDI_DOMINATORS, ubb, call_dom))
5207 : 246841 : validate_change (uin, DF_REF_REAL_LOC (use), newreg, true);
5208 : : }
5209 : :
5210 : 51986 : rtx_insn *new_move = gen_move_insn (newreg, dest);
5211 : 51986 : emit_insn_after (new_move, bb_note (call_dom));
5212 : 51986 : if (dump_file)
5213 : : {
5214 : 2 : fprintf (dump_file, "Split live-range of register ");
5215 : 2 : print_rtl_single (dump_file, dest);
5216 : : }
5217 : : ret = true;
5218 : : }
5219 : :
5220 : 52063 : if (insn == last_interesting_insn)
5221 : : break;
5222 : : }
5223 : 73011 : apply_change_group ();
5224 : 73011 : return ret;
5225 : 1008570 : }
5226 : :
5227 : : /* Perform the second half of the transformation started in
5228 : : find_moveable_pseudos. We look for instances where the newly introduced
5229 : : pseudo remains unallocated, and remove it by moving the definition to
5230 : : just before its use, replacing the move instruction generated by
5231 : : find_moveable_pseudos. */
5232 : : static void
5233 : 1008570 : move_unallocated_pseudos (void)
5234 : : {
5235 : 1008570 : int i;
5236 : 1021923 : for (i = first_moveable_pseudo; i < last_moveable_pseudo; i++)
5237 : 13353 : if (reg_renumber[i] < 0)
5238 : : {
5239 : 3345 : int idx = i - first_moveable_pseudo;
5240 : 3345 : rtx other_reg = pseudo_replaced_reg[idx];
5241 : : /* The iterating range [first_moveable_pseudo, last_moveable_pseudo)
5242 : : covers every new pseudo created in find_moveable_pseudos,
5243 : : regardless of the validation with it is successful or not.
5244 : : So we need to skip the pseudos which were used in those failed
5245 : : validations to avoid unexpected DF info and consequent ICE.
5246 : : We only set pseudo_replaced_reg[] when the validation is successful
5247 : : in find_moveable_pseudos, it's enough to check it here. */
5248 : 3345 : if (!other_reg)
5249 : 0 : continue;
5250 : 3345 : rtx_insn *def_insn = DF_REF_INSN (DF_REG_DEF_CHAIN (i));
5251 : : /* The use must follow all definitions of OTHER_REG, so we can
5252 : : insert the new definition immediately after any of them. */
5253 : 3345 : df_ref other_def = DF_REG_DEF_CHAIN (REGNO (other_reg));
5254 : 3345 : rtx_insn *move_insn = DF_REF_INSN (other_def);
5255 : 3345 : rtx_insn *newinsn = emit_insn_after (PATTERN (def_insn), move_insn);
5256 : 3345 : rtx set;
5257 : 3345 : int success;
5258 : :
5259 : 3345 : if (dump_file)
5260 : 0 : fprintf (dump_file, "moving def of %d (insn %d now) ",
5261 : 0 : REGNO (other_reg), INSN_UID (def_insn));
5262 : :
5263 : 3345 : delete_insn (move_insn);
5264 : 6690 : while ((other_def = DF_REG_DEF_CHAIN (REGNO (other_reg))))
5265 : 0 : delete_insn (DF_REF_INSN (other_def));
5266 : 3345 : delete_insn (def_insn);
5267 : :
5268 : 3345 : set = single_set (newinsn);
5269 : 3345 : success = validate_change (newinsn, &SET_DEST (set), other_reg, 0);
5270 : 3345 : gcc_assert (success);
5271 : 3345 : if (dump_file)
5272 : 0 : fprintf (dump_file, " %d) rather than keep unallocated replacement %d\n",
5273 : 0 : INSN_UID (newinsn), i);
5274 : 3345 : SET_REG_N_REFS (i, 0);
5275 : : }
5276 : :
5277 : 1008570 : first_moveable_pseudo = last_moveable_pseudo = 0;
5278 : 1008570 : }
5279 : :
5280 : :
5281 : :
5282 : : /* Code dealing with scratches (changing them onto
5283 : : pseudos and restoring them from the pseudos).
5284 : :
5285 : : We change scratches into pseudos at the beginning of IRA to
5286 : : simplify dealing with them (conflicts, hard register assignments).
5287 : :
5288 : : If the pseudo denoting scratch was spilled it means that we do not
5289 : : need a hard register for it. Such pseudos are transformed back to
5290 : : scratches at the end of LRA. */
5291 : :
5292 : : /* Description of location of a former scratch operand. */
5293 : : struct sloc
5294 : : {
5295 : : rtx_insn *insn; /* Insn where the scratch was. */
5296 : : int nop; /* Number of the operand which was a scratch. */
5297 : : unsigned regno; /* regno gnerated instead of scratch */
5298 : : int icode; /* Original icode from which scratch was removed. */
5299 : : };
5300 : :
5301 : : typedef struct sloc *sloc_t;
5302 : :
5303 : : /* Locations of the former scratches. */
5304 : : static vec<sloc_t> scratches;
5305 : :
5306 : : /* Bitmap of scratch regnos. */
5307 : : static bitmap_head scratch_bitmap;
5308 : :
5309 : : /* Bitmap of scratch operands. */
5310 : : static bitmap_head scratch_operand_bitmap;
5311 : :
5312 : : /* Return true if pseudo REGNO is made of SCRATCH. */
5313 : : bool
5314 : 354766908 : ira_former_scratch_p (int regno)
5315 : : {
5316 : 354766908 : return bitmap_bit_p (&scratch_bitmap, regno);
5317 : : }
5318 : :
5319 : : /* Return true if the operand NOP of INSN is a former scratch. */
5320 : : bool
5321 : 0 : ira_former_scratch_operand_p (rtx_insn *insn, int nop)
5322 : : {
5323 : 0 : return bitmap_bit_p (&scratch_operand_bitmap,
5324 : 0 : INSN_UID (insn) * MAX_RECOG_OPERANDS + nop) != 0;
5325 : : }
5326 : :
5327 : : /* Register operand NOP in INSN as a former scratch. It will be
5328 : : changed to scratch back, if it is necessary, at the LRA end. */
5329 : : void
5330 : 93502 : ira_register_new_scratch_op (rtx_insn *insn, int nop, int icode)
5331 : : {
5332 : 93502 : rtx op = *recog_data.operand_loc[nop];
5333 : 93502 : sloc_t loc = XNEW (struct sloc);
5334 : 93502 : ira_assert (REG_P (op));
5335 : 93502 : loc->insn = insn;
5336 : 93502 : loc->nop = nop;
5337 : 93502 : loc->regno = REGNO (op);
5338 : 93502 : loc->icode = icode;
5339 : 93502 : scratches.safe_push (loc);
5340 : 93502 : bitmap_set_bit (&scratch_bitmap, REGNO (op));
5341 : 187004 : bitmap_set_bit (&scratch_operand_bitmap,
5342 : 93502 : INSN_UID (insn) * MAX_RECOG_OPERANDS + nop);
5343 : 93502 : add_reg_note (insn, REG_UNUSED, op);
5344 : 93502 : }
5345 : :
5346 : : /* Return true if string STR contains constraint 'X'. */
5347 : : static bool
5348 : 93502 : contains_X_constraint_p (const char *str)
5349 : : {
5350 : 93502 : int c;
5351 : :
5352 : 343191 : while ((c = *str))
5353 : : {
5354 : 258564 : str += CONSTRAINT_LEN (c, str);
5355 : 258564 : if (c == 'X') return true;
5356 : : }
5357 : : return false;
5358 : : }
5359 : :
5360 : : /* Change INSN's scratches into pseudos and save their location.
5361 : : Return true if we changed any scratch. */
5362 : : bool
5363 : 253969828 : ira_remove_insn_scratches (rtx_insn *insn, bool all_p, FILE *dump_file,
5364 : : rtx (*get_reg) (rtx original))
5365 : : {
5366 : 253969828 : int i;
5367 : 253969828 : bool insn_changed_p;
5368 : 253969828 : rtx reg, *loc;
5369 : :
5370 : 253969828 : extract_insn (insn);
5371 : 253969828 : insn_changed_p = false;
5372 : 870398054 : for (i = 0; i < recog_data.n_operands; i++)
5373 : : {
5374 : 362458398 : loc = recog_data.operand_loc[i];
5375 : 362458398 : if (GET_CODE (*loc) == SCRATCH && GET_MODE (*loc) != VOIDmode)
5376 : : {
5377 : 102377 : if (! all_p && contains_X_constraint_p (recog_data.constraints[i]))
5378 : 8875 : continue;
5379 : 93502 : insn_changed_p = true;
5380 : 93502 : *loc = reg = get_reg (*loc);
5381 : 93502 : ira_register_new_scratch_op (insn, i, INSN_CODE (insn));
5382 : 93502 : if (ira_dump_file != NULL)
5383 : 0 : fprintf (dump_file,
5384 : : "Removing SCRATCH to p%u in insn #%u (nop %d)\n",
5385 : 0 : REGNO (reg), INSN_UID (insn), i);
5386 : : }
5387 : : }
5388 : 253969828 : return insn_changed_p;
5389 : : }
5390 : :
5391 : : /* Return new register of the same mode as ORIGINAL. Used in
5392 : : remove_scratches. */
5393 : : static rtx
5394 : 84627 : get_scratch_reg (rtx original)
5395 : : {
5396 : 84627 : return gen_reg_rtx (GET_MODE (original));
5397 : : }
5398 : :
5399 : : /* Change scratches into pseudos and save their location. Return true
5400 : : if we changed any scratch. */
5401 : : static bool
5402 : 1435841 : remove_scratches (void)
5403 : : {
5404 : 1435841 : bool change_p = false;
5405 : 1435841 : basic_block bb;
5406 : 1435841 : rtx_insn *insn;
5407 : :
5408 : 1435841 : scratches.create (get_max_uid ());
5409 : 1435841 : bitmap_initialize (&scratch_bitmap, ®_obstack);
5410 : 1435841 : bitmap_initialize (&scratch_operand_bitmap, ®_obstack);
5411 : 15175131 : FOR_EACH_BB_FN (bb, cfun)
5412 : 161201657 : FOR_BB_INSNS (bb, insn)
5413 : 147462367 : if (INSN_P (insn)
5414 : 147462367 : && ira_remove_insn_scratches (insn, false, ira_dump_file, get_scratch_reg))
5415 : : {
5416 : : /* Because we might use DF, we need to keep DF info up to date. */
5417 : 83448 : df_insn_rescan (insn);
5418 : 83448 : change_p = true;
5419 : : }
5420 : 1435841 : return change_p;
5421 : : }
5422 : :
5423 : : /* Changes pseudos created by function remove_scratches onto scratches. */
5424 : : void
5425 : 1435841 : ira_restore_scratches (FILE *dump_file)
5426 : : {
5427 : 1435841 : int regno, n;
5428 : 1435841 : unsigned i;
5429 : 1435841 : rtx *op_loc;
5430 : 1435841 : sloc_t loc;
5431 : :
5432 : 1529343 : for (i = 0; scratches.iterate (i, &loc); i++)
5433 : : {
5434 : : /* Ignore already deleted insns. */
5435 : 93502 : if (NOTE_P (loc->insn)
5436 : 0 : && NOTE_KIND (loc->insn) == NOTE_INSN_DELETED)
5437 : 0 : continue;
5438 : 93502 : extract_insn (loc->insn);
5439 : 93502 : if (loc->icode != INSN_CODE (loc->insn))
5440 : : {
5441 : : /* The icode doesn't match, which means the insn has been modified
5442 : : (e.g. register elimination). The scratch cannot be restored. */
5443 : 0 : continue;
5444 : : }
5445 : 93502 : op_loc = recog_data.operand_loc[loc->nop];
5446 : 93502 : if (REG_P (*op_loc)
5447 : 93502 : && ((regno = REGNO (*op_loc)) >= FIRST_PSEUDO_REGISTER)
5448 : 187004 : && reg_renumber[regno] < 0)
5449 : : {
5450 : : /* It should be only case when scratch register with chosen
5451 : : constraint 'X' did not get memory or hard register. */
5452 : 5309 : ira_assert (ira_former_scratch_p (regno));
5453 : 5309 : *op_loc = gen_rtx_SCRATCH (GET_MODE (*op_loc));
5454 : 5309 : for (n = 0; n < recog_data.n_dups; n++)
5455 : 0 : *recog_data.dup_loc[n]
5456 : 0 : = *recog_data.operand_loc[(int) recog_data.dup_num[n]];
5457 : 5309 : if (dump_file != NULL)
5458 : 0 : fprintf (dump_file, "Restoring SCRATCH in insn #%u(nop %d)\n",
5459 : 0 : INSN_UID (loc->insn), loc->nop);
5460 : : }
5461 : : }
5462 : 1529343 : for (i = 0; scratches.iterate (i, &loc); i++)
5463 : 93502 : free (loc);
5464 : 1435841 : scratches.release ();
5465 : 1435841 : bitmap_clear (&scratch_bitmap);
5466 : 1435841 : bitmap_clear (&scratch_operand_bitmap);
5467 : 1435841 : }
5468 : :
5469 : :
5470 : :
5471 : : /* If the backend knows where to allocate pseudos for hard
5472 : : register initial values, register these allocations now. */
5473 : : static void
5474 : 1435841 : allocate_initial_values (void)
5475 : : {
5476 : 1435841 : if (targetm.allocate_initial_value)
5477 : : {
5478 : : rtx hreg, preg, x;
5479 : : int i, regno;
5480 : :
5481 : 0 : for (i = 0; HARD_REGISTER_NUM_P (i); i++)
5482 : : {
5483 : 0 : if (! initial_value_entry (i, &hreg, &preg))
5484 : : break;
5485 : :
5486 : 0 : x = targetm.allocate_initial_value (hreg);
5487 : 0 : regno = REGNO (preg);
5488 : 0 : if (x && REG_N_SETS (regno) <= 1)
5489 : : {
5490 : 0 : if (MEM_P (x))
5491 : 0 : reg_equiv_memory_loc (regno) = x;
5492 : : else
5493 : : {
5494 : 0 : basic_block bb;
5495 : 0 : int new_regno;
5496 : :
5497 : 0 : gcc_assert (REG_P (x));
5498 : 0 : new_regno = REGNO (x);
5499 : 0 : reg_renumber[regno] = new_regno;
5500 : : /* Poke the regno right into regno_reg_rtx so that even
5501 : : fixed regs are accepted. */
5502 : 0 : SET_REGNO (preg, new_regno);
5503 : : /* Update global register liveness information. */
5504 : 0 : FOR_EACH_BB_FN (bb, cfun)
5505 : : {
5506 : 0 : if (REGNO_REG_SET_P (df_get_live_in (bb), regno))
5507 : 0 : SET_REGNO_REG_SET (df_get_live_in (bb), new_regno);
5508 : 0 : if (REGNO_REG_SET_P (df_get_live_out (bb), regno))
5509 : 0 : SET_REGNO_REG_SET (df_get_live_out (bb), new_regno);
5510 : : }
5511 : : }
5512 : : }
5513 : : }
5514 : :
5515 : 0 : gcc_checking_assert (! initial_value_entry (FIRST_PSEUDO_REGISTER,
5516 : : &hreg, &preg));
5517 : : }
5518 : 1435841 : }
5519 : :
5520 : :
5521 : :
5522 : :
5523 : : /* True when we use LRA instead of reload pass for the current
5524 : : function. */
5525 : : bool ira_use_lra_p;
5526 : :
5527 : : /* True if we have allocno conflicts. It is false for non-optimized
5528 : : mode or when the conflict table is too big. */
5529 : : bool ira_conflicts_p;
5530 : :
5531 : : /* Saved between IRA and reload. */
5532 : : static int saved_flag_ira_share_spill_slots;
5533 : :
5534 : : /* Set to true while in IRA. */
5535 : : bool ira_in_progress = false;
5536 : :
5537 : : /* Set up array ira_hard_regno_nrefs. */
5538 : : static void
5539 : 1435841 : setup_hard_regno_nrefs (void)
5540 : : {
5541 : 1435841 : int i;
5542 : :
5543 : 133533213 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
5544 : : {
5545 : 132097372 : ira_hard_regno_nrefs[i] = 0;
5546 : 132097372 : for (df_ref use = DF_REG_USE_CHAIN (i);
5547 : 242710425 : use != NULL;
5548 : 110613053 : use = DF_REF_NEXT_REG (use))
5549 : 110613053 : if (DF_REF_CLASS (use) != DF_REF_ARTIFICIAL
5550 : 50547929 : && !(DF_REF_INSN_INFO (use) && DEBUG_INSN_P (DF_REF_INSN (use))))
5551 : 47676947 : ira_hard_regno_nrefs[i]++;
5552 : 132097372 : for (df_ref def = DF_REG_DEF_CHAIN (i);
5553 : 665029176 : def != NULL;
5554 : 532931804 : def = DF_REF_NEXT_REG (def))
5555 : 532931804 : if (DF_REF_CLASS (def) != DF_REF_ARTIFICIAL
5556 : 506266685 : && !(DF_REF_INSN_INFO (def) && DEBUG_INSN_P (DF_REF_INSN (def))))
5557 : 506266685 : ira_hard_regno_nrefs[i]++;
5558 : : }
5559 : 1435841 : }
5560 : :
5561 : : /* This is the main entry of IRA. */
5562 : : static void
5563 : 1435841 : ira (FILE *f)
5564 : : {
5565 : 1435841 : bool loops_p;
5566 : 1435841 : int ira_max_point_before_emit;
5567 : 1435841 : bool saved_flag_caller_saves = flag_caller_saves;
5568 : 1435841 : enum ira_region saved_flag_ira_region = flag_ira_region;
5569 : 1435841 : basic_block bb;
5570 : 1435841 : edge_iterator ei;
5571 : 1435841 : edge e;
5572 : 1435841 : bool output_jump_reload_p = false;
5573 : :
5574 : 1435841 : setup_hard_regno_nrefs ();
5575 : 1435841 : if (ira_use_lra_p)
5576 : : {
5577 : : /* First put potential jump output reloads on the output edges
5578 : : as USE which will be removed at the end of LRA. The major
5579 : : goal is actually to create BBs for critical edges for LRA and
5580 : : populate them later by live info. In LRA it will be
5581 : : difficult to do this. */
5582 : 15175122 : FOR_EACH_BB_FN (bb, cfun)
5583 : : {
5584 : 13739281 : rtx_insn *end = BB_END (bb);
5585 : 13739281 : if (!JUMP_P (end))
5586 : 5434623 : continue;
5587 : 8304658 : extract_insn (end);
5588 : 22470435 : for (int i = 0; i < recog_data.n_operands; i++)
5589 : 14165921 : if (recog_data.operand_type[i] != OP_IN)
5590 : : {
5591 : 144 : bool skip_p = false;
5592 : 494 : FOR_EACH_EDGE (e, ei, bb->succs)
5593 : 711 : if (EDGE_CRITICAL_P (e)
5594 : 11 : && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)
5595 : 361 : && (e->flags & EDGE_ABNORMAL))
5596 : : {
5597 : : skip_p = true;
5598 : : break;
5599 : : }
5600 : 144 : if (skip_p)
5601 : : break;
5602 : 144 : output_jump_reload_p = true;
5603 : 494 : FOR_EACH_EDGE (e, ei, bb->succs)
5604 : 711 : if (EDGE_CRITICAL_P (e)
5605 : 361 : && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
5606 : : {
5607 : 11 : start_sequence ();
5608 : : /* We need to put some no-op insn here. We can
5609 : : not put a note as commit_edges insertion will
5610 : : fail. */
5611 : 11 : emit_insn (gen_rtx_USE (VOIDmode, const1_rtx));
5612 : 11 : rtx_insn *insns = get_insns ();
5613 : 11 : end_sequence ();
5614 : 11 : insert_insn_on_edge (insns, e);
5615 : : }
5616 : : break;
5617 : : }
5618 : : }
5619 : 1435841 : if (output_jump_reload_p)
5620 : 138 : commit_edge_insertions ();
5621 : : }
5622 : :
5623 : 1435841 : if (flag_ira_verbose < 10)
5624 : : {
5625 : 1435841 : internal_flag_ira_verbose = flag_ira_verbose;
5626 : 1435841 : ira_dump_file = f;
5627 : : }
5628 : : else
5629 : : {
5630 : 0 : internal_flag_ira_verbose = flag_ira_verbose - 10;
5631 : 0 : ira_dump_file = stderr;
5632 : : }
5633 : :
5634 : 1435841 : clear_bb_flags ();
5635 : :
5636 : : /* Determine if the current function is a leaf before running IRA
5637 : : since this can impact optimizations done by the prologue and
5638 : : epilogue thus changing register elimination offsets.
5639 : : Other target callbacks may use crtl->is_leaf too, including
5640 : : SHRINK_WRAPPING_ENABLED, so initialize as early as possible. */
5641 : 1435841 : crtl->is_leaf = leaf_function_p ();
5642 : :
5643 : : /* Perform target specific PIC register initialization. */
5644 : 1435841 : targetm.init_pic_reg ();
5645 : :
5646 : 1435841 : ira_conflicts_p = optimize > 0;
5647 : :
5648 : : /* Determine the number of pseudos actually requiring coloring. */
5649 : 1435841 : unsigned int num_used_regs = 0;
5650 : 64326753 : for (unsigned int i = FIRST_PSEUDO_REGISTER; i < DF_REG_SIZE (df); i++)
5651 : 62890912 : if (DF_REG_DEF_COUNT (i) || DF_REG_USE_COUNT (i))
5652 : 28940841 : num_used_regs++;
5653 : :
5654 : : /* If there are too many pseudos and/or basic blocks (e.g. 10K pseudos and
5655 : : 10K blocks or 100K pseudos and 1K blocks) or we have too many function
5656 : : insns, we will use simplified and faster algorithms in LRA. */
5657 : 1435841 : lra_simple_p
5658 : 1435841 : = (ira_use_lra_p
5659 : 1435841 : && (num_used_regs >= (1U << 26) / last_basic_block_for_fn (cfun)
5660 : : /* max uid is a good evaluation of the number of insns as most
5661 : : optimizations are done on tree-SSA level. */
5662 : 1435836 : || ((uint64_t) get_max_uid ()
5663 : 1435836 : > (uint64_t) param_ira_simple_lra_insn_threshold * 1000)));
5664 : :
5665 : 1435841 : if (lra_simple_p)
5666 : : {
5667 : : /* It permits to skip live range splitting in LRA. */
5668 : 5 : flag_caller_saves = false;
5669 : : /* There is no sense to do regional allocation when we use
5670 : : simplified LRA. */
5671 : 5 : flag_ira_region = IRA_REGION_ONE;
5672 : 5 : ira_conflicts_p = false;
5673 : : }
5674 : :
5675 : : #ifndef IRA_NO_OBSTACK
5676 : : gcc_obstack_init (&ira_obstack);
5677 : : #endif
5678 : 1435841 : bitmap_obstack_initialize (&ira_bitmap_obstack);
5679 : :
5680 : : /* LRA uses its own infrastructure to handle caller save registers. */
5681 : 1435841 : if (flag_caller_saves && !ira_use_lra_p)
5682 : 0 : init_caller_save ();
5683 : :
5684 : 1435841 : setup_prohibited_mode_move_regs ();
5685 : 1435841 : decrease_live_ranges_number ();
5686 : 1435841 : df_note_add_problem ();
5687 : :
5688 : : /* DF_LIVE can't be used in the register allocator, too many other
5689 : : parts of the compiler depend on using the "classic" liveness
5690 : : interpretation of the DF_LR problem. See PR38711.
5691 : : Remove the problem, so that we don't spend time updating it in
5692 : : any of the df_analyze() calls during IRA/LRA. */
5693 : 1435841 : if (optimize > 1)
5694 : 933044 : df_remove_problem (df_live);
5695 : 1435841 : gcc_checking_assert (df_live == NULL);
5696 : :
5697 : 1435841 : if (flag_checking)
5698 : 1435821 : df->changeable_flags |= DF_VERIFY_SCHEDULED;
5699 : :
5700 : 1435841 : df_analyze ();
5701 : :
5702 : 1435841 : init_reg_equiv ();
5703 : 1435841 : if (ira_conflicts_p)
5704 : : {
5705 : 1008570 : calculate_dominance_info (CDI_DOMINATORS);
5706 : :
5707 : 1008570 : if (split_live_ranges_for_shrink_wrap ())
5708 : 25077 : df_analyze ();
5709 : :
5710 : 1008570 : free_dominance_info (CDI_DOMINATORS);
5711 : : }
5712 : :
5713 : 1435841 : df_clear_flags (DF_NO_INSN_RESCAN);
5714 : :
5715 : 1435841 : indirect_jump_optimize ();
5716 : 1435841 : if (delete_trivially_dead_insns (get_insns (), max_reg_num ()))
5717 : 5325 : df_analyze ();
5718 : :
5719 : 1435841 : regstat_init_n_sets_and_refs ();
5720 : 1435841 : regstat_compute_ri ();
5721 : :
5722 : : /* If we are not optimizing, then this is the only place before
5723 : : register allocation where dataflow is done. And that is needed
5724 : : to generate these warnings. */
5725 : 1435841 : if (warn_clobbered)
5726 : 134074 : generate_setjmp_warnings ();
5727 : :
5728 : : /* update_equiv_regs can use reg classes of pseudos and they are set up in
5729 : : register pressure sensitive scheduling and loop invariant motion and in
5730 : : live range shrinking. This info can become obsolete if we add new pseudos
5731 : : since the last set up. Recalculate it again if the new pseudos were
5732 : : added. */
5733 : 1435841 : if (resize_reg_info () && (flag_sched_pressure || flag_live_range_shrinkage
5734 : 1435731 : || flag_ira_loop_pressure))
5735 : 43 : ira_set_pseudo_classes (true, ira_dump_file);
5736 : :
5737 : 1435841 : init_alias_analysis ();
5738 : 1435841 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
5739 : 1435841 : reg_equiv = XCNEWVEC (struct equivalence, max_reg_num ());
5740 : 1435841 : update_equiv_regs_prescan ();
5741 : 1435841 : update_equiv_regs ();
5742 : :
5743 : : /* Don't move insns if live range shrinkage or register
5744 : : pressure-sensitive scheduling were done because it will not
5745 : : improve allocation but likely worsen insn scheduling. */
5746 : 1435841 : if (optimize
5747 : 1008570 : && !flag_live_range_shrinkage
5748 : 1008539 : && !(flag_sched_pressure && flag_schedule_insns))
5749 : 1008502 : combine_and_move_insns ();
5750 : :
5751 : : /* Gather additional equivalences with memory. */
5752 : 1435841 : if (optimize && flag_expensive_optimizations)
5753 : 933022 : add_store_equivs ();
5754 : :
5755 : 1435841 : loop_optimizer_finalize ();
5756 : 1435841 : free_dominance_info (CDI_DOMINATORS);
5757 : 1435841 : end_alias_analysis ();
5758 : 1435841 : free (reg_equiv);
5759 : :
5760 : : /* Once max_regno changes, we need to free and re-init/re-compute
5761 : : some data structures like regstat_n_sets_and_refs and reg_info_p. */
5762 : 1507970 : auto regstat_recompute_for_max_regno = []() {
5763 : 72129 : regstat_free_n_sets_and_refs ();
5764 : 72129 : regstat_free_ri ();
5765 : 72129 : regstat_init_n_sets_and_refs ();
5766 : 72129 : regstat_compute_ri ();
5767 : 72129 : resize_reg_info ();
5768 : 72129 : };
5769 : :
5770 : 1435841 : int max_regno_before_rm = max_reg_num ();
5771 : 1435841 : if (ira_use_lra_p && remove_scratches ())
5772 : : {
5773 : 37620 : ira_expand_reg_equiv ();
5774 : : /* For now remove_scatches is supposed to create pseudos when it
5775 : : succeeds, assert this happens all the time. Once it doesn't
5776 : : hold, we should guard the regstat recompute for the case
5777 : : max_regno changes. */
5778 : 37620 : gcc_assert (max_regno_before_rm != max_reg_num ());
5779 : 37620 : regstat_recompute_for_max_regno ();
5780 : : }
5781 : :
5782 : 1435841 : setup_reg_equiv ();
5783 : 1435841 : grow_reg_equivs ();
5784 : 1435841 : setup_reg_equiv_init ();
5785 : :
5786 : 1435841 : allocated_reg_info_size = max_reg_num ();
5787 : :
5788 : : /* It is not worth to do such improvement when we use a simple
5789 : : allocation because of -O0 usage or because the function is too
5790 : : big. */
5791 : 1435841 : if (ira_conflicts_p)
5792 : 1008570 : find_moveable_pseudos ();
5793 : :
5794 : 1435841 : max_regno_before_ira = max_reg_num ();
5795 : 1435841 : ira_setup_eliminable_regset ();
5796 : :
5797 : 1435841 : ira_overall_cost = ira_reg_cost = ira_mem_cost = 0;
5798 : 1435841 : ira_load_cost = ira_store_cost = ira_shuffle_cost = 0;
5799 : 1435841 : ira_move_loops_num = ira_additional_jumps_num = 0;
5800 : :
5801 : 1435841 : ira_assert (current_loops == NULL);
5802 : 1435841 : if (flag_ira_region == IRA_REGION_ALL || flag_ira_region == IRA_REGION_MIXED)
5803 : 965587 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS | LOOPS_HAVE_RECORDED_EXITS);
5804 : :
5805 : 1435841 : if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
5806 : 95 : fprintf (ira_dump_file, "Building IRA IR\n");
5807 : 1435841 : loops_p = ira_build ();
5808 : :
5809 : 1435841 : ira_assert (ira_conflicts_p || !loops_p);
5810 : :
5811 : 1435841 : saved_flag_ira_share_spill_slots = flag_ira_share_spill_slots;
5812 : 1435841 : if (too_high_register_pressure_p () || cfun->calls_setjmp)
5813 : : /* It is just wasting compiler's time to pack spilled pseudos into
5814 : : stack slots in this case -- prohibit it. We also do this if
5815 : : there is setjmp call because a variable not modified between
5816 : : setjmp and longjmp the compiler is required to preserve its
5817 : : value and sharing slots does not guarantee it. */
5818 : 1267 : flag_ira_share_spill_slots = false;
5819 : :
5820 : 1435841 : ira_color ();
5821 : :
5822 : 1435841 : ira_max_point_before_emit = ira_max_point;
5823 : :
5824 : 1435841 : ira_initiate_emit_data ();
5825 : :
5826 : 1435841 : ira_emit (loops_p);
5827 : :
5828 : 1435841 : max_regno = max_reg_num ();
5829 : 1435841 : if (ira_conflicts_p)
5830 : : {
5831 : 1008570 : if (! loops_p)
5832 : : {
5833 : 973668 : if (! ira_use_lra_p)
5834 : 0 : ira_initiate_assign ();
5835 : : }
5836 : : else
5837 : : {
5838 : 34902 : expand_reg_info ();
5839 : :
5840 : 34902 : if (ira_use_lra_p)
5841 : : {
5842 : 34902 : ira_allocno_t a;
5843 : 34902 : ira_allocno_iterator ai;
5844 : :
5845 : 11190828 : FOR_EACH_ALLOCNO (a, ai)
5846 : : {
5847 : 11121024 : int old_regno = ALLOCNO_REGNO (a);
5848 : 11121024 : int new_regno = REGNO (ALLOCNO_EMIT_DATA (a)->reg);
5849 : :
5850 : 11121024 : ALLOCNO_REGNO (a) = new_regno;
5851 : :
5852 : 11121024 : if (old_regno != new_regno)
5853 : 1244126 : setup_reg_classes (new_regno, reg_preferred_class (old_regno),
5854 : : reg_alternate_class (old_regno),
5855 : : reg_allocno_class (old_regno));
5856 : : }
5857 : : }
5858 : : else
5859 : : {
5860 : 0 : if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
5861 : 0 : fprintf (ira_dump_file, "Flattening IR\n");
5862 : 0 : ira_flattening (max_regno_before_ira, ira_max_point_before_emit);
5863 : : }
5864 : : /* New insns were generated: add notes and recalculate live
5865 : : info. */
5866 : 34902 : df_analyze ();
5867 : :
5868 : : /* ??? Rebuild the loop tree, but why? Does the loop tree
5869 : : change if new insns were generated? Can that be handled
5870 : : by updating the loop tree incrementally? */
5871 : 34902 : loop_optimizer_finalize ();
5872 : 34902 : free_dominance_info (CDI_DOMINATORS);
5873 : 34902 : loop_optimizer_init (AVOID_CFG_MODIFICATIONS
5874 : : | LOOPS_HAVE_RECORDED_EXITS);
5875 : :
5876 : 34902 : if (! ira_use_lra_p)
5877 : : {
5878 : 0 : setup_allocno_assignment_flags ();
5879 : 0 : ira_initiate_assign ();
5880 : 0 : ira_reassign_conflict_allocnos (max_regno);
5881 : : }
5882 : : }
5883 : : }
5884 : :
5885 : 1435841 : ira_finish_emit_data ();
5886 : :
5887 : 1435841 : setup_reg_renumber ();
5888 : :
5889 : 1435841 : calculate_allocation_cost ();
5890 : :
5891 : : #ifdef ENABLE_IRA_CHECKING
5892 : 1435841 : if (ira_conflicts_p && ! ira_use_lra_p)
5893 : : /* Opposite to reload pass, LRA does not use any conflict info
5894 : : from IRA. We don't rebuild conflict info for LRA (through
5895 : : ira_flattening call) and cannot use the check here. We could
5896 : : rebuild this info for LRA in the check mode but there is a risk
5897 : : that code generated with the check and without it will be a bit
5898 : : different. Calling ira_flattening in any mode would be a
5899 : : wasting CPU time. So do not check the allocation for LRA. */
5900 : 0 : check_allocation ();
5901 : : #endif
5902 : :
5903 : 1435841 : if (max_regno != max_regno_before_ira)
5904 : 34509 : regstat_recompute_for_max_regno ();
5905 : :
5906 : 1435841 : overall_cost_before = ira_overall_cost;
5907 : 1435841 : if (! ira_conflicts_p)
5908 : 427271 : grow_reg_equivs ();
5909 : : else
5910 : : {
5911 : 1008570 : fix_reg_equiv_init ();
5912 : :
5913 : : #ifdef ENABLE_IRA_CHECKING
5914 : 1008570 : print_redundant_copies ();
5915 : : #endif
5916 : 1008570 : if (! ira_use_lra_p)
5917 : : {
5918 : 0 : ira_spilled_reg_stack_slots_num = 0;
5919 : 0 : ira_spilled_reg_stack_slots
5920 : 0 : = ((class ira_spilled_reg_stack_slot *)
5921 : 0 : ira_allocate (max_regno
5922 : : * sizeof (class ira_spilled_reg_stack_slot)));
5923 : 0 : memset ((void *)ira_spilled_reg_stack_slots, 0,
5924 : 0 : max_regno * sizeof (class ira_spilled_reg_stack_slot));
5925 : : }
5926 : : }
5927 : 1435841 : allocate_initial_values ();
5928 : :
5929 : : /* See comment for find_moveable_pseudos call. */
5930 : 1435841 : if (ira_conflicts_p)
5931 : 1008570 : move_unallocated_pseudos ();
5932 : :
5933 : : /* Restore original values. */
5934 : 1435841 : if (lra_simple_p)
5935 : : {
5936 : 5 : flag_caller_saves = saved_flag_caller_saves;
5937 : 5 : flag_ira_region = saved_flag_ira_region;
5938 : : }
5939 : 1435841 : }
5940 : :
5941 : : /* Modify asm goto to avoid further trouble with this insn. We can
5942 : : not replace the insn by USE as in other asm insns as we still
5943 : : need to keep CFG consistency. */
5944 : : void
5945 : 6 : ira_nullify_asm_goto (rtx_insn *insn)
5946 : : {
5947 : 6 : ira_assert (JUMP_P (insn) && INSN_CODE (insn) < 0);
5948 : 6 : rtx tmp = extract_asm_operands (PATTERN (insn));
5949 : 6 : PATTERN (insn) = gen_rtx_ASM_OPERANDS (VOIDmode, ggc_strdup (""), "", 0,
5950 : : rtvec_alloc (0),
5951 : : rtvec_alloc (0),
5952 : : ASM_OPERANDS_LABEL_VEC (tmp),
5953 : : ASM_OPERANDS_SOURCE_LOCATION(tmp));
5954 : 6 : }
5955 : :
5956 : : static void
5957 : 1435841 : do_reload (void)
5958 : : {
5959 : 1435841 : basic_block bb;
5960 : 1435841 : bool need_dce;
5961 : 1435841 : unsigned pic_offset_table_regno = INVALID_REGNUM;
5962 : :
5963 : 1435841 : if (flag_ira_verbose < 10)
5964 : 1435841 : ira_dump_file = dump_file;
5965 : :
5966 : : /* If pic_offset_table_rtx is a pseudo register, then keep it so
5967 : : after reload to avoid possible wrong usages of hard reg assigned
5968 : : to it. */
5969 : 1435841 : if (pic_offset_table_rtx
5970 : 1435841 : && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
5971 : : pic_offset_table_regno = REGNO (pic_offset_table_rtx);
5972 : :
5973 : 1435841 : timevar_push (TV_RELOAD);
5974 : 1435841 : if (ira_use_lra_p)
5975 : : {
5976 : 1435841 : if (current_loops != NULL)
5977 : : {
5978 : 965587 : loop_optimizer_finalize ();
5979 : 965587 : free_dominance_info (CDI_DOMINATORS);
5980 : : }
5981 : 18138545 : FOR_ALL_BB_FN (bb, cfun)
5982 : 16702704 : bb->loop_father = NULL;
5983 : 1435841 : current_loops = NULL;
5984 : :
5985 : 1435841 : ira_destroy ();
5986 : :
5987 : 1435841 : lra (ira_dump_file, internal_flag_ira_verbose);
5988 : : /* ???!!! Move it before lra () when we use ira_reg_equiv in
5989 : : LRA. */
5990 : 1435841 : vec_free (reg_equivs);
5991 : 1435841 : reg_equivs = NULL;
5992 : 1435841 : need_dce = false;
5993 : : }
5994 : : else
5995 : : {
5996 : 0 : df_set_flags (DF_NO_INSN_RESCAN);
5997 : 0 : build_insn_chain ();
5998 : :
5999 : 0 : need_dce = reload (get_insns (), ira_conflicts_p);
6000 : : }
6001 : :
6002 : 1435841 : timevar_pop (TV_RELOAD);
6003 : :
6004 : 1435841 : timevar_push (TV_IRA);
6005 : :
6006 : 1435841 : if (ira_conflicts_p && ! ira_use_lra_p)
6007 : : {
6008 : 0 : ira_free (ira_spilled_reg_stack_slots);
6009 : 0 : ira_finish_assign ();
6010 : : }
6011 : :
6012 : 1435841 : if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL
6013 : 96 : && overall_cost_before != ira_overall_cost)
6014 : 0 : fprintf (ira_dump_file, "+++Overall after reload %" PRId64 "\n",
6015 : : ira_overall_cost);
6016 : :
6017 : 1435841 : flag_ira_share_spill_slots = saved_flag_ira_share_spill_slots;
6018 : :
6019 : 1435841 : if (! ira_use_lra_p)
6020 : : {
6021 : 0 : ira_destroy ();
6022 : 0 : if (current_loops != NULL)
6023 : : {
6024 : 0 : loop_optimizer_finalize ();
6025 : 0 : free_dominance_info (CDI_DOMINATORS);
6026 : : }
6027 : 0 : FOR_ALL_BB_FN (bb, cfun)
6028 : 0 : bb->loop_father = NULL;
6029 : 0 : current_loops = NULL;
6030 : :
6031 : 0 : regstat_free_ri ();
6032 : 0 : regstat_free_n_sets_and_refs ();
6033 : : }
6034 : :
6035 : 1435841 : if (optimize)
6036 : 1008570 : cleanup_cfg (CLEANUP_EXPENSIVE);
6037 : :
6038 : 1435841 : finish_reg_equiv ();
6039 : :
6040 : 1435841 : bitmap_obstack_release (&ira_bitmap_obstack);
6041 : : #ifndef IRA_NO_OBSTACK
6042 : : obstack_free (&ira_obstack, NULL);
6043 : : #endif
6044 : :
6045 : : /* The code after the reload has changed so much that at this point
6046 : : we might as well just rescan everything. Note that
6047 : : df_rescan_all_insns is not going to help here because it does not
6048 : : touch the artificial uses and defs. */
6049 : 1435841 : df_finish_pass (true);
6050 : 1435841 : df_scan_alloc (NULL);
6051 : 1435841 : df_scan_blocks ();
6052 : :
6053 : 1435841 : if (optimize > 1)
6054 : : {
6055 : 933044 : df_live_add_problem ();
6056 : 933044 : df_live_set_all_dirty ();
6057 : : }
6058 : :
6059 : 1435841 : if (optimize)
6060 : 1008570 : df_analyze ();
6061 : :
6062 : 1435841 : if (need_dce && optimize)
6063 : 0 : run_fast_dce ();
6064 : :
6065 : : /* Diagnose uses of the hard frame pointer when it is used as a global
6066 : : register. Often we can get away with letting the user appropriate
6067 : : the frame pointer, but we should let them know when code generation
6068 : : makes that impossible. */
6069 : 1435841 : if (global_regs[HARD_FRAME_POINTER_REGNUM] && frame_pointer_needed)
6070 : : {
6071 : 2 : tree decl = global_regs_decl[HARD_FRAME_POINTER_REGNUM];
6072 : 2 : error_at (DECL_SOURCE_LOCATION (current_function_decl),
6073 : : "frame pointer required, but reserved");
6074 : 2 : inform (DECL_SOURCE_LOCATION (decl), "for %qD", decl);
6075 : : }
6076 : :
6077 : : /* If we are doing generic stack checking, give a warning if this
6078 : : function's frame size is larger than we expect. */
6079 : 1435841 : if (flag_stack_check == GENERIC_STACK_CHECK)
6080 : : {
6081 : 40 : poly_int64 size = get_frame_size () + STACK_CHECK_FIXED_FRAME_SIZE;
6082 : :
6083 : 3720 : for (int i = 0; i < FIRST_PSEUDO_REGISTER; i++)
6084 : 3680 : if (df_regs_ever_live_p (i)
6085 : 230 : && !fixed_regs[i]
6086 : 3846 : && !crtl->abi->clobbers_full_reg_p (i))
6087 : 81 : size += UNITS_PER_WORD;
6088 : :
6089 : 40 : if (constant_lower_bound (size) > STACK_CHECK_MAX_FRAME_SIZE)
6090 : 1 : warning (0, "frame size too large for reliable stack checking");
6091 : : }
6092 : :
6093 : 1435841 : if (pic_offset_table_regno != INVALID_REGNUM)
6094 : 39633 : pic_offset_table_rtx = gen_rtx_REG (Pmode, pic_offset_table_regno);
6095 : :
6096 : 1435841 : timevar_pop (TV_IRA);
6097 : 1435841 : }
6098 : :
6099 : : /* Run the integrated register allocator. */
6100 : :
6101 : : namespace {
6102 : :
6103 : : const pass_data pass_data_ira =
6104 : : {
6105 : : RTL_PASS, /* type */
6106 : : "ira", /* name */
6107 : : OPTGROUP_NONE, /* optinfo_flags */
6108 : : TV_IRA, /* tv_id */
6109 : : 0, /* properties_required */
6110 : : 0, /* properties_provided */
6111 : : 0, /* properties_destroyed */
6112 : : 0, /* todo_flags_start */
6113 : : TODO_do_not_ggc_collect, /* todo_flags_finish */
6114 : : };
6115 : :
6116 : : class pass_ira : public rtl_opt_pass
6117 : : {
6118 : : public:
6119 : 283157 : pass_ira (gcc::context *ctxt)
6120 : 566314 : : rtl_opt_pass (pass_data_ira, ctxt)
6121 : : {}
6122 : :
6123 : : /* opt_pass methods: */
6124 : 1435849 : bool gate (function *) final override
6125 : : {
6126 : 1435849 : return !targetm.no_register_allocation;
6127 : : }
6128 : 1435841 : unsigned int execute (function *) final override
6129 : : {
6130 : 1435841 : ira_in_progress = true;
6131 : 1435841 : ira (dump_file);
6132 : 1435841 : ira_in_progress = false;
6133 : 1435841 : return 0;
6134 : : }
6135 : :
6136 : : }; // class pass_ira
6137 : :
6138 : : } // anon namespace
6139 : :
6140 : : rtl_opt_pass *
6141 : 283157 : make_pass_ira (gcc::context *ctxt)
6142 : : {
6143 : 283157 : return new pass_ira (ctxt);
6144 : : }
6145 : :
6146 : : namespace {
6147 : :
6148 : : const pass_data pass_data_reload =
6149 : : {
6150 : : RTL_PASS, /* type */
6151 : : "reload", /* name */
6152 : : OPTGROUP_NONE, /* optinfo_flags */
6153 : : TV_RELOAD, /* tv_id */
6154 : : 0, /* properties_required */
6155 : : 0, /* properties_provided */
6156 : : 0, /* properties_destroyed */
6157 : : 0, /* todo_flags_start */
6158 : : 0, /* todo_flags_finish */
6159 : : };
6160 : :
6161 : : class pass_reload : public rtl_opt_pass
6162 : : {
6163 : : public:
6164 : 283157 : pass_reload (gcc::context *ctxt)
6165 : 566314 : : rtl_opt_pass (pass_data_reload, ctxt)
6166 : : {}
6167 : :
6168 : : /* opt_pass methods: */
6169 : 1435849 : bool gate (function *) final override
6170 : : {
6171 : 1435849 : return !targetm.no_register_allocation;
6172 : : }
6173 : 1435841 : unsigned int execute (function *) final override
6174 : : {
6175 : 1435841 : do_reload ();
6176 : 1435841 : return 0;
6177 : : }
6178 : :
6179 : : }; // class pass_reload
6180 : :
6181 : : } // anon namespace
6182 : :
6183 : : rtl_opt_pass *
6184 : 283157 : make_pass_reload (gcc::context *ctxt)
6185 : : {
6186 : 283157 : return new pass_reload (ctxt);
6187 : : }
|