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